29 const auto& conditions{
35 std::vector<ldmx::HcalHit> double_hcal_rec_hits;
38 std::map<ldmx::HcalID, std::vector<ldmx::HcalHit>> hits_by_id;
39 for (
auto const& hit : hcal_rec_hits) {
40 ldmx::HcalID id(hit.getSection(), hit.getLayer(), hit.getStrip());
42 auto idh = hits_by_id.find(
id);
43 if (idh == hits_by_id.end()) {
44 hits_by_id[id] = std::vector<ldmx::HcalHit>(1, hit);
46 idh->second.push_back(hit);
53 std::map<ldmx::HcalID, std::pair<int, int>> indices_by_id;
54 for (
auto const& hcal_bar : hits_by_id) {
55 auto id = hcal_bar.first;
57 std::pair<int, int> indices(-1, -1);
59 while (i_hit < hcal_bar.second.size()) {
60 auto hit = hcal_bar.second.at(i_hit);
65 indices.second = i_hit;
68 indices.first = i_hit;
72 indices_by_id[id] = indices;
76 for (
auto const& hcal_bar : hits_by_id) {
77 auto id = hcal_bar.first;
80 auto position = hcal_geometry.getStripCenterPosition(
id);
81 const auto orientation{hcal_geometry.getScintillatorOrientation(
id)};
82 int orientation_int =
static_cast<int>(orientation);
85 if (!hcal_geometry.isDoubleEnded(
id.section()))
continue;
88 auto indices = indices_by_id[id];
89 if (indices.first == -1 || indices.second == -1) {
90 ldmx_log(warn) <<
"Couldn't find both ends of the bar "
91 <<
" for HcalID section " <<
static_cast<int>(
id.section())
92 <<
" layer " <<
id.layer() <<
" strip " <<
id.strip();
97 auto hit_pos_end = hcal_bar.second.at(indices.first);
98 auto hit_neg_end = hcal_bar.second.at(indices.second);
102 hit_pos_end.getLayer(), hit_pos_end.getStrip(),
103 hit_pos_end.getEnd());
105 hit_neg_end.getLayer(), hit_neg_end.getStrip(),
106 hit_neg_end.getEnd());
107 double mean_shift = conditions.toaCalib(digi_id_neg.
raw(), 1);
109 double pos_time = hit_pos_end.getTime();
110 double neg_time = hit_neg_end.getTime();
111 if (pos_time != 0 && neg_time != 0) {
112 neg_time = neg_time - mean_shift;
117 double v = 299.792 / 1.6;
118 double hit_time_diff = pos_time - neg_time;
120 ldmx_log(trace) <<
"\n new hit ";
121 ldmx_log(trace) <<
"strip " <<
id.strip() <<
" layer_ " <<
id.layer()
122 <<
"center position X = " << position.X()
123 <<
" Y =" << position.Y() <<
" Z = " << position.Z();
124 ldmx_log(trace) <<
"hittime pos_ " << pos_time <<
"neg " << neg_time
125 <<
" bar sign " <<
" diff " << hit_time_diff;
127 int position_bar_sign = hit_time_diff > 0 ? 1 : -1;
128 double position_unchanged = 0;
129 double position_bar = position_bar_sign * fabs(hit_time_diff) * v / 2;
131 if (hcal_geometry.hasExplicitLayout()) {
132 const double half_length{hcal_geometry.getScintillatorLength(
id) / 2};
133 position_bar = std::clamp(position_bar, -half_length, half_length);
136 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
137 position_unchanged = position.X();
138 position.SetX(hcal_geometry.hasExplicitLayout()
139 ? position_unchanged + position_bar
142 position_unchanged = position.Y();
143 position.SetY(hcal_geometry.hasExplicitLayout()
144 ? position_unchanged + position_bar
147 ldmx_log(trace) <<
"position unchanged " << position_unchanged
148 <<
" orientation = " << orientation_int;
149 ldmx_log(trace) <<
"newposition X = " << position.X()
150 <<
" Y = " << position.Y() <<
" Z = " << position.Z();
153 [[maybe_unused]]
double hit_time =
154 (hit_pos_end.getTime() + hit_neg_end.getTime());
157 double num_mips_equivalent =
158 (hit_pos_end.getAmplitude() + hit_neg_end.getAmplitude());
159 double p_es = (hit_pos_end.getPE() + hit_neg_end.getPE());
160 double reconstructed_energy =
165 rec_hit.
setID(
id.raw());
173 rec_hit.
setMinPE(std::min(hit_pos_end.getPE(), hit_neg_end.getPE()));
177 rec_hit.
setToaPos(hit_pos_end.getTime());
178 rec_hit.
setToaNeg(hit_neg_end.getTime());
180 rec_hit.
setTime(hit_time_diff);
181 rec_hit.
setTimeDiff(hit_pos_end.getTime() - hit_neg_end.getTime());
183 double_hcal_rec_hits.push_back(rec_hit);