27 const auto& conditions{
33 std::vector<ldmx::HcalHit> double_hcal_rec_hits;
36 std::map<ldmx::HcalID, std::vector<ldmx::HcalHit>> hits_by_id;
37 for (
auto const& hit : hcal_rec_hits) {
38 ldmx::HcalID id(hit.getSection(), hit.getLayer(), hit.getStrip());
40 auto idh = hits_by_id.find(
id);
41 if (idh == hits_by_id.end()) {
42 hits_by_id[id] = std::vector<ldmx::HcalHit>(1, hit);
44 idh->second.push_back(hit);
51 std::map<ldmx::HcalID, std::pair<int, int>> indices_by_id;
52 for (
auto const& hcal_bar : hits_by_id) {
53 auto id = hcal_bar.first;
55 std::pair<int, int> indices(-1, -1);
57 while (i_hit < hcal_bar.second.size()) {
58 auto hit = hcal_bar.second.at(i_hit);
63 indices.second = i_hit;
66 indices.first = i_hit;
70 indices_by_id[id] = indices;
74 for (
auto const& hcal_bar : hits_by_id) {
75 auto id = hcal_bar.first;
78 auto position = hcal_geometry.getStripCenterPosition(
id);
79 const auto orientation{hcal_geometry.getScintillatorOrientation(
id)};
80 int orientation_int =
static_cast<int>(orientation);
83 if (
id.section() != ldmx::HcalID::HcalSection::BACK)
continue;
86 auto indices = indices_by_id[id];
87 if (indices.first == -1 || indices.second == -1) {
88 ldmx_log(warn) <<
"Couldn't find both ends of the bar "
89 <<
" for HcalID section " <<
static_cast<int>(
id.section())
90 <<
" layer " <<
id.layer() <<
" strip " <<
id.strip();
95 auto hit_pos_end = hcal_bar.second.at(indices.first);
96 auto hit_neg_end = hcal_bar.second.at(indices.second);
100 hit_pos_end.getLayer(), hit_pos_end.getStrip(),
101 hit_pos_end.getEnd());
103 hit_neg_end.getLayer(), hit_neg_end.getStrip(),
104 hit_neg_end.getEnd());
105 double mean_shift = conditions.toaCalib(digi_id_neg.
raw(), 1);
107 double pos_time = hit_pos_end.getTime();
108 double neg_time = hit_neg_end.getTime();
109 if (pos_time != 0 && neg_time != 0) {
110 neg_time = neg_time - mean_shift;
115 double v = 299.792 / 1.6;
116 double hit_time_diff = pos_time - neg_time;
118 ldmx_log(trace) <<
"\n new hit ";
119 ldmx_log(trace) <<
"strip " <<
id.strip() <<
" layer_ " <<
id.layer()
120 <<
"center position X = " << position.X()
121 <<
" Y =" << position.Y() <<
" Z = " << position.Z();
122 ldmx_log(trace) <<
"hittime pos_ " << pos_time <<
"neg " << neg_time
123 <<
" bar sign " <<
" diff " << hit_time_diff;
125 int position_bar_sign = hit_time_diff > 0 ? 1 : -1;
126 double position_unchanged = 0;
127 double position_bar = position_bar_sign * fabs(hit_time_diff) * v / 2;
129 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
130 position_unchanged = position.X();
131 position.SetX(position_bar);
133 position_unchanged = position.Y();
134 position.SetY(position_bar);
136 ldmx_log(trace) <<
"position unchanged " << position_unchanged
137 <<
" orientation = " << orientation_int;
138 ldmx_log(trace) <<
"newposition X = " << position.X()
139 <<
" Y = " << position.Y() <<
" Z = " << position.Z();
142 [[maybe_unused]]
double hit_time =
143 (hit_pos_end.getTime() + hit_neg_end.getTime());
146 double num_mips_equivalent =
147 (hit_pos_end.getAmplitude() + hit_neg_end.getAmplitude());
148 double p_es = (hit_pos_end.getPE() + hit_neg_end.getPE());
149 double reconstructed_energy =
154 rec_hit.
setID(
id.raw());
162 rec_hit.
setMinPE(std::min(hit_pos_end.getPE(), hit_neg_end.getPE()));
166 rec_hit.
setToaPos(hit_pos_end.getTime());
167 rec_hit.
setToaNeg(hit_neg_end.getTime());
169 rec_hit.
setTime(hit_time_diff);
170 rec_hit.
setTimeDiff(hit_pos_end.getTime() - hit_neg_end.getTime());
172 double_hcal_rec_hits.push_back(rec_hit);