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 indices = indices_by_id[id];
81 if (indices.first == -1 || indices.second == -1) {
82 ldmx_log(warn) <<
"Couldn't find both ends of the bar "
83 <<
" for HcalID section " <<
static_cast<int>(
id.section())
84 <<
" layer " <<
id.layer() <<
" strip " <<
id.strip();
89 auto hit_pos_end = hcal_bar.second.at(indices.first);
90 auto hit_neg_end = hcal_bar.second.at(indices.second);
94 hit_pos_end.getLayer(), hit_pos_end.getStrip(),
95 hit_pos_end.getEnd());
97 hit_neg_end.getLayer(), hit_neg_end.getStrip(),
98 hit_neg_end.getEnd());
99 double mean_shift = conditions.toaCalib(digi_id_neg.
raw(), 1);
101 double pos_time = hit_pos_end.getTime();
102 double neg_time = hit_neg_end.getTime();
103 if (pos_time != 0 && neg_time != 0) {
104 neg_time = neg_time - mean_shift;
109 double v = 299.792 / 1.6;
110 double hit_time_diff = pos_time - neg_time;
112 ldmx_log(trace) <<
"\n new hit ";
113 ldmx_log(trace) <<
"strip " <<
id.strip() <<
" layer_ " <<
id.layer()
114 <<
"center position X = " << position.X()
115 <<
" Y =" << position.Y() <<
" Z = " << position.Z();
116 ldmx_log(trace) <<
"hittime pos_ " << pos_time <<
"neg " << neg_time
117 <<
" bar sign " <<
" diff " << hit_time_diff;
119 int position_bar_sign = hit_time_diff > 0 ? 1 : -1;
120 double position_unchanged = 0;
121 double position_bar = position_bar_sign * fabs(hit_time_diff) * v / 2;
123 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
124 position_unchanged = position.X();
125 position.SetX(position_bar);
127 position_unchanged = position.Y();
128 position.SetY(position_bar);
130 ldmx_log(trace) <<
"position unchanged " << position_unchanged
131 <<
" orientation = " << orientation_int;
132 ldmx_log(trace) <<
"newposition X = " << position.X()
133 <<
" Y = " << position.Y() <<
" Z = " << position.Z();
136 [[maybe_unused]]
double hit_time =
137 (hit_pos_end.getTime() + hit_neg_end.getTime());
140 double num_mips_equivalent =
141 (hit_pos_end.getAmplitude() + hit_neg_end.getAmplitude());
142 double p_es = (hit_pos_end.getPE() + hit_neg_end.getPE());
143 double reconstructed_energy =
148 rec_hit.
setID(
id.raw());
156 rec_hit.
setMinPE(std::min(hit_pos_end.getPE(), hit_neg_end.getPE()));
160 rec_hit.
setToaPos(hit_pos_end.getTime());
161 rec_hit.
setToaNeg(hit_neg_end.getTime());
163 rec_hit.
setTime(hit_time_diff);
164 rec_hit.
setTimeDiff(hit_pos_end.getTime() - hit_neg_end.getTime());
166 double_hcal_rec_hits.push_back(rec_hit);