LDMX Software
HcalDoubleEndRecProducer.cxx
1#include "Hcal/HcalDoubleEndRecProducer.h"
2
3#include <algorithm>
4
5#include "DetDescr/HcalDigiID.h"
7#include "DetDescr/HcalID.h"
9#include "Hcal/HcalReconConditions.h"
10
11namespace hcal {
12
14 pass_name_ = p.getParameter("pass_name", pass_name_);
15 coll_name_ = p.getParameter("coll_name", coll_name_);
16
17 rec_pass_name_ = p.getParameter("rec_pass_name", pass_name_);
18 rec_coll_name_ = p.getParameter("rec_coll_name", coll_name_);
19
20 pe_per_mip_ = p.get<double>("pe_per_mip");
21 mip_energy_ = p.get<double>("mip_energy");
22 clock_cycle_ = p.get<double>("clock_cycle");
23}
24
26 const auto& hcal_geometry = getCondition<ldmx::HcalGeometry>(
28
29 const auto& conditions{
31
32 auto hcal_rec_hits =
33 event.getCollection<ldmx::HcalHit>(coll_name_, pass_name_);
34
35 std::vector<ldmx::HcalHit> double_hcal_rec_hits;
36
37 // group hcal rechits by the same HcalID
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());
41
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);
45 } else {
46 idh->second.push_back(hit);
47 }
48 }
49
50 // make pairs of hcal rechits indices that belong to the same pulse
51 // @TODO: for now we just take the first two indices that have opposite-ends
52 // we do not cover the case where two hits_ come separated in time
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;
56
57 std::pair<int, int> indices(-1, -1);
58 int i_hit = 0;
59 while (i_hit < hcal_bar.second.size()) {
60 auto hit = hcal_bar.second.at(i_hit);
61
62 ldmx::HcalDigiID digi_id(hit.getSection(), hit.getLayer(), hit.getStrip(),
63 hit.getEnd());
64 if (digi_id.isNegativeEnd() && indices.second == -1) {
65 indices.second = i_hit;
66 }
67 if (!digi_id.isNegativeEnd() && indices.first == -1) {
68 indices.first = i_hit;
69 }
70 i_hit++;
71 }
72 indices_by_id[id] = indices;
73 }
74
75 // reconstruct double-ended hits_
76 for (auto const& hcal_bar : hits_by_id) {
77 auto id = hcal_bar.first;
78
79 // get bar position from geometry
80 auto position = hcal_geometry.getStripCenterPosition(id);
81 const auto orientation{hcal_geometry.getScintillatorOrientation(id)};
82 int orientation_int = static_cast<int>(orientation);
83
84 // skip non-double-ended layers
85 if (!hcal_geometry.isDoubleEnded(id.section())) continue;
86
87 // skip if we couldn't find both ends of the bar
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();
93 continue;
94 }
95
96 // get two hits_ to reconstruct
97 auto hit_pos_end = hcal_bar.second.at(indices.first);
98 auto hit_neg_end = hcal_bar.second.at(indices.second);
99
100 // update TOA hit with negative end with mean shift
101 ldmx::HcalDigiID digi_id_pos(hit_pos_end.getSection(),
102 hit_pos_end.getLayer(), hit_pos_end.getStrip(),
103 hit_pos_end.getEnd());
104 ldmx::HcalDigiID digi_id_neg(hit_neg_end.getSection(),
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);
108
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;
113 }
114
115 // update position in strip according to time measurement
116 // velocity of light in polystyrene, n = 1.6 = c/v
117 double v = 299.792 / 1.6;
118 double hit_time_diff = pos_time - neg_time;
119
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;
126
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;
130 // keep the hit on the bar
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);
134 }
135 if (orientation ==
136 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
137 position_unchanged = position.X();
138 position.SetX(hcal_geometry.hasExplicitLayout()
139 ? position_unchanged + position_bar
140 : position_bar);
141 } else {
142 position_unchanged = position.Y();
143 position.SetY(hcal_geometry.hasExplicitLayout()
144 ? position_unchanged + position_bar
145 : position_bar);
146 }
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();
151
152 // TODO: switch unique hit time for this pulse
153 [[maybe_unused]] double hit_time =
154 (hit_pos_end.getTime() + hit_neg_end.getTime());
155
156 // amplitude and PEs
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 =
161 num_mips_equivalent * pe_per_mip_ * mip_energy_;
162
163 // reconstructed Hit
164 ldmx::HcalHit rec_hit;
165 rec_hit.setID(id.raw());
166 rec_hit.setXPos(position.X());
167 rec_hit.setYPos(position.Y());
168 rec_hit.setZPos(position.Z());
169 rec_hit.setSection(id.section());
170 rec_hit.setStrip(id.strip());
171 rec_hit.setLayer(id.layer());
172 rec_hit.setPE(p_es);
173 rec_hit.setMinPE(std::min(hit_pos_end.getPE(), hit_neg_end.getPE()));
174 rec_hit.setAmplitude(num_mips_equivalent);
175 rec_hit.setAmplitudePos(hit_pos_end.getAmplitude());
176 rec_hit.setAmplitudeNeg(hit_neg_end.getAmplitude());
177 rec_hit.setToaPos(hit_pos_end.getTime());
178 rec_hit.setToaNeg(hit_neg_end.getTime());
179 rec_hit.setEnergy(reconstructed_energy);
180 rec_hit.setTime(hit_time_diff);
181 rec_hit.setTimeDiff(hit_pos_end.getTime() - hit_neg_end.getTime());
182 rec_hit.setPositionUnchanged(position_unchanged, orientation_int);
183 double_hcal_rec_hits.push_back(rec_hit);
184 }
185
186 // add collection to event bus
187 event.add(rec_coll_name_, double_hcal_rec_hits);
188}
189
190} // namespace hcal
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that translates HCal ID into positions of strip hits.
Class that stores Stores reconstructed hit information from the HCAL.
Class that defines an HCal sensitive detector.
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
Implements an event buffer system for storing event data.
Definition Event.h:40
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
std::string pass_name_
name of pass of rechits to use
void configure(framework::config::Parameters &p) override
Callback for the EventProcessor to configure itself from the given set of parameters.
std::string rec_coll_name_
name of rechits to reconstruct
void produce(framework::Event &event) override
Process the event and put new data products into it.
std::string rec_pass_name_
name of pass of rechits to reconstruct
double mip_energy_
energy per MIP [MeV]
double pe_per_mip_
number of PEs per MIP
std::string coll_name_
name of rechits to use as input
double clock_cycle_
length of clock cycle [ns]
static const std::string CONDITIONS_NAME
the name of the HcalReconConditions table (must match python registration name)
void setYPos(float ypos)
Set the Y position of the hit [mm].
void setID(int id)
Set the detector ID.
void setZPos(float zpos)
Set the Z position of the hit [mm].
void setXPos(float xpos)
Set the X position of the hit [mm].
void setTime(float time)
Set the time of the hit [ns].
void setAmplitude(float amplitude)
Set the amplitude of the hit, which is proportional to the signal in the calorimeter cell without sam...
void setEnergy(float energy)
Set the calorimetric energy of the hit, corrected for sampling factors [MeV].
RawValue raw() const
Definition DetectorID.h:69
Extension of HcalAbstractID providing access to HCal digi information.
Definition HcalDigiID.h:13
bool isNegativeEnd() const
Get whether the 'end' field from the ID is negative.
Definition HcalDigiID.h:111
static constexpr const char * CONDITIONS_OBJECT_NAME
Conditions object: The name of the python configuration calling this class (Hcal/python/HcalGeometry....
Stores reconstructed hit information from the HCAL.
Definition HcalHit.h:24
void setSection(int section)
Set the section for this hit.
Definition HcalHit.h:166
void setPositionUnchanged(double position, int orientation)
Set original position.
Definition HcalHit.h:225
void setToaNeg(double toaNeg)
Set toa of the negative end.
Definition HcalHit.h:208
void setTimeDiff(double timeDiff)
Set time difference (uncorrected)
Definition HcalHit.h:196
void setMinPE(float minpe)
Set the minimum number of photoelectrons estimated for this hit.
Definition HcalHit.h:160
void setToaPos(double toaPos)
Set toa of the positive end.
Definition HcalHit.h:202
void setAmplitudeNeg(double amplitudeNeg)
Set amplitude of the negative end.
Definition HcalHit.h:220
void setStrip(int strip)
Set the strip for this hit.
Definition HcalHit.h:178
void setAmplitudePos(double amplitudePos)
Set amplitude of the positive end.
Definition HcalHit.h:214
void setLayer(int layer)
Set the layer for this hit.
Definition HcalHit.h:172
void setPE(float pe)
Set the number of photoelectrons estimated for this hit.
Definition HcalHit.h:153
Implements detector ids for HCal subdetector.
Definition HcalID.h:19