LDMX Software
HcalDoubleEndRecProducer.cxx
1#include "Hcal/HcalDoubleEndRecProducer.h"
2
3#include "DetDescr/HcalDigiID.h"
5#include "DetDescr/HcalID.h"
7#include "Hcal/HcalReconConditions.h"
8
9namespace hcal {
10
12 pass_name_ = p.getParameter("pass_name", pass_name_);
13 coll_name_ = p.getParameter("coll_name", coll_name_);
14
15 rec_pass_name_ = p.getParameter("rec_pass_name", pass_name_);
16 rec_coll_name_ = p.getParameter("rec_coll_name", coll_name_);
17
18 pe_per_mip_ = p.get<double>("pe_per_mip");
19 mip_energy_ = p.get<double>("mip_energy");
20 clock_cycle_ = p.get<double>("clock_cycle");
21}
22
24 const auto& hcal_geometry = getCondition<ldmx::HcalGeometry>(
26
27 const auto& conditions{
29
30 auto hcal_rec_hits =
31 event.getCollection<ldmx::HcalHit>(coll_name_, pass_name_);
32
33 std::vector<ldmx::HcalHit> double_hcal_rec_hits;
34
35 // group hcal rechits by the same HcalID
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());
39
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);
43 } else {
44 idh->second.push_back(hit);
45 }
46 }
47
48 // make pairs of hcal rechits indices that belong to the same pulse
49 // @TODO: for now we just take the first two indices that have opposite-ends
50 // we do not cover the case where two hits_ come separated in time
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;
54
55 std::pair<int, int> indices(-1, -1);
56 int i_hit = 0;
57 while (i_hit < hcal_bar.second.size()) {
58 auto hit = hcal_bar.second.at(i_hit);
59
60 ldmx::HcalDigiID digi_id(hit.getSection(), hit.getLayer(), hit.getStrip(),
61 hit.getEnd());
62 if (digi_id.isNegativeEnd() && indices.second == -1) {
63 indices.second = i_hit;
64 }
65 if (!digi_id.isNegativeEnd() && indices.first == -1) {
66 indices.first = i_hit;
67 }
68 i_hit++;
69 }
70 indices_by_id[id] = indices;
71 }
72
73 // reconstruct double-ended hits_
74 for (auto const& hcal_bar : hits_by_id) {
75 auto id = hcal_bar.first;
76
77 // get bar position from geometry
78 auto position = hcal_geometry.getStripCenterPosition(id);
79 const auto orientation{hcal_geometry.getScintillatorOrientation(id)};
80 int orientation_int = static_cast<int>(orientation);
81
82 // skip non-double-ended layers
83 if (id.section() != ldmx::HcalID::HcalSection::BACK) continue;
84
85 // skip if we couldn't find both ends of the bar
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();
91 continue;
92 }
93
94 // get two hits_ to reconstruct
95 auto hit_pos_end = hcal_bar.second.at(indices.first);
96 auto hit_neg_end = hcal_bar.second.at(indices.second);
97
98 // update TOA hit with negative end with mean shift
99 ldmx::HcalDigiID digi_id_pos(hit_pos_end.getSection(),
100 hit_pos_end.getLayer(), hit_pos_end.getStrip(),
101 hit_pos_end.getEnd());
102 ldmx::HcalDigiID digi_id_neg(hit_neg_end.getSection(),
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);
106
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;
111 }
112
113 // update position in strip according to time measurement
114 // velocity of light in polystyrene, n = 1.6 = c/v
115 double v = 299.792 / 1.6;
116 double hit_time_diff = pos_time - neg_time;
117
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;
124
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;
128 if (orientation ==
129 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
130 position_unchanged = position.X();
131 position.SetX(position_bar);
132 } else {
133 position_unchanged = position.Y();
134 position.SetY(position_bar);
135 }
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();
140
141 // TODO: switch unique hit time for this pulse
142 [[maybe_unused]] double hit_time =
143 (hit_pos_end.getTime() + hit_neg_end.getTime());
144
145 // amplitude and PEs
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 =
150 num_mips_equivalent * pe_per_mip_ * mip_energy_;
151
152 // reconstructed Hit
153 ldmx::HcalHit rec_hit;
154 rec_hit.setID(id.raw());
155 rec_hit.setXPos(position.X());
156 rec_hit.setYPos(position.Y());
157 rec_hit.setZPos(position.Z());
158 rec_hit.setSection(id.section());
159 rec_hit.setStrip(id.strip());
160 rec_hit.setLayer(id.layer());
161 rec_hit.setPE(p_es);
162 rec_hit.setMinPE(std::min(hit_pos_end.getPE(), hit_neg_end.getPE()));
163 rec_hit.setAmplitude(num_mips_equivalent);
164 rec_hit.setAmplitudePos(hit_pos_end.getAmplitude());
165 rec_hit.setAmplitudeNeg(hit_neg_end.getAmplitude());
166 rec_hit.setToaPos(hit_pos_end.getTime());
167 rec_hit.setToaNeg(hit_neg_end.getTime());
168 rec_hit.setEnergy(reconstructed_energy);
169 rec_hit.setTime(hit_time_diff);
170 rec_hit.setTimeDiff(hit_pos_end.getTime() - hit_neg_end.getTime());
171 rec_hit.setPositionUnchanged(position_unchanged, orientation_int);
172 double_hcal_rec_hits.push_back(rec_hit);
173 }
174
175 // add collection to event bus
176 event.add(rec_coll_name_, double_hcal_rec_hits);
177}
178
179} // 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