21 const auto& conditions{
27 std::vector<ldmx::HcalHit> double_hcal_rec_hits;
30 std::map<ldmx::HcalID, std::vector<ldmx::HcalHit>> hits_by_id;
31 for (
auto const& hit : hcal_rec_hits) {
32 ldmx::HcalID id(hit.getSection(), hit.getLayer(), hit.getStrip());
34 auto idh = hits_by_id.find(
id);
35 if (idh == hits_by_id.end()) {
36 hits_by_id[id] = std::vector<ldmx::HcalHit>(1, hit);
38 idh->second.push_back(hit);
45 std::map<ldmx::HcalID, std::pair<int, int>> indices_by_id;
46 for (
auto const& hcal_bar : hits_by_id) {
47 auto id = hcal_bar.first;
49 std::pair<int, int> indices(-1, -1);
51 while (i_hit < hcal_bar.second.size()) {
52 auto hit = hcal_bar.second.at(i_hit);
57 indices.second = i_hit;
60 indices.first = i_hit;
64 indices_by_id[id] = indices;
68 for (
auto const& hcal_bar : hits_by_id) {
69 auto id = hcal_bar.first;
72 auto position = hcal_geometry.getStripCenterPosition(
id);
73 const auto orientation{hcal_geometry.getScintillatorOrientation(
id)};
74 int orientation_int =
static_cast<int>(orientation);
77 if (
id.section() != ldmx::HcalID::HcalSection::BACK)
continue;
80 auto hit_pos_end = hcal_bar.second.at(indices_by_id[
id].first);
81 auto hit_neg_end = hcal_bar.second.at(indices_by_id[
id].second);
85 hit_pos_end.getLayer(), hit_pos_end.getStrip(),
86 hit_pos_end.getEnd());
88 hit_neg_end.getLayer(), hit_neg_end.getStrip(),
89 hit_neg_end.getEnd());
90 double mean_shift = conditions.toaCalib(digi_id_neg.
raw(), 1);
92 double pos_time = hit_pos_end.getTime();
93 double neg_time = hit_neg_end.getTime();
94 if (pos_time != 0 || neg_time != 0) {
95 neg_time = neg_time - mean_shift;
100 double v = 299.792 / 1.6;
101 double hit_time_diff = pos_time - neg_time;
103 ldmx_log(trace) <<
"\n new hit ";
104 ldmx_log(trace) <<
"strip " <<
id.strip() <<
" layer_ " <<
id.layer()
105 <<
"center position X = " << position.X()
106 <<
" Y =" << position.Y() <<
" Z = " << position.Z();
107 ldmx_log(trace) <<
"hittime pos_ " << pos_time <<
"neg " << neg_time
108 <<
" bar sign " <<
" diff " << hit_time_diff;
110 int position_bar_sign = hit_time_diff > 0 ? 1 : -1;
111 double position_unchanged = 0;
112 double position_bar = position_bar_sign * fabs(hit_time_diff) * v / 2;
114 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
115 position_unchanged = position.X();
116 position.SetX(position_bar);
118 position_unchanged = position.Y();
119 position.SetY(position_bar);
121 ldmx_log(trace) <<
"position unchanged " << position_unchanged
122 <<
" orientation = " << orientation_int;
123 ldmx_log(trace) <<
"newposition X = " << position.X()
124 <<
" Y = " << position.Y() <<
" Z = " << position.Z();
127 [[maybe_unused]]
double hit_time =
128 (hit_pos_end.getTime() + hit_neg_end.getTime());
131 double num_mips_equivalent =
132 (hit_pos_end.getAmplitude() + hit_neg_end.getAmplitude());
133 double p_es = (hit_pos_end.getPE() + hit_neg_end.getPE());
134 double reconstructed_energy =
139 rec_hit.
setID(
id.raw());
147 rec_hit.
setMinPE(std::min(hit_pos_end.getPE(), hit_neg_end.getPE()));
151 rec_hit.
setToaPos(hit_pos_end.getTime());
152 rec_hit.
setToaNeg(hit_neg_end.getTime());
154 rec_hit.
setTime(hit_time_diff);
155 rec_hit.
setTimeDiff(hit_pos_end.getTime() - hit_neg_end.getTime());
157 double_hcal_rec_hits.push_back(rec_hit);