LDMX Software
HcalDoubleEndRecProducer.cxx
1#include "Hcal/HcalDoubleEndRecProducer.h"
2
3namespace hcal {
4
6 pass_name_ = p.getParameter("pass_name", pass_name_);
7 coll_name_ = p.getParameter("coll_name", coll_name_);
8
9 rec_pass_name_ = p.getParameter("rec_pass_name", pass_name_);
10 rec_coll_name_ = p.getParameter("rec_coll_name", coll_name_);
11
12 pe_per_mip_ = p.get<double>("pe_per_mip");
13 mip_energy_ = p.get<double>("mip_energy");
14 clock_cycle_ = p.get<double>("clock_cycle");
15}
16
18 const auto& hcal_geometry = getCondition<ldmx::HcalGeometry>(
20
21 const auto& conditions{
23
24 auto hcal_rec_hits =
25 event.getCollection<ldmx::HcalHit>(coll_name_, pass_name_);
26
27 std::vector<ldmx::HcalHit> double_hcal_rec_hits;
28
29 // group hcal rechits by the same HcalID
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());
33
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);
37 } else {
38 idh->second.push_back(hit);
39 }
40 }
41
42 // make pairs of hcal rechits indices that belong to the same pulse
43 // @TODO: for now we just take the first two indices that have opposite-ends
44 // we do not cover the case where two hits_ come separated in time
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;
48
49 std::pair<int, int> indices(-1, -1);
50 int i_hit = 0;
51 while (i_hit < hcal_bar.second.size()) {
52 auto hit = hcal_bar.second.at(i_hit);
53
54 ldmx::HcalDigiID digi_id(hit.getSection(), hit.getLayer(), hit.getStrip(),
55 hit.getEnd());
56 if (digi_id.isNegativeEnd() && indices.second == -1) {
57 indices.second = i_hit;
58 }
59 if (!digi_id.isNegativeEnd() && indices.first == -1) {
60 indices.first = i_hit;
61 }
62 i_hit++;
63 }
64 indices_by_id[id] = indices;
65 }
66
67 // reconstruct double-ended hits_
68 for (auto const& hcal_bar : hits_by_id) {
69 auto id = hcal_bar.first;
70
71 // get bar position from geometry
72 auto position = hcal_geometry.getStripCenterPosition(id);
73 const auto orientation{hcal_geometry.getScintillatorOrientation(id)};
74 int orientation_int = static_cast<int>(orientation);
75
76 // skip non-double-ended layers
77 if (id.section() != ldmx::HcalID::HcalSection::BACK) continue;
78
79 // skip if we couldn't find both ends of the bar
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();
85 continue;
86 }
87
88 // get two hits_ to reconstruct
89 auto hit_pos_end = hcal_bar.second.at(indices.first);
90 auto hit_neg_end = hcal_bar.second.at(indices.second);
91
92 // update TOA hit with negative end with mean shift
93 ldmx::HcalDigiID digi_id_pos(hit_pos_end.getSection(),
94 hit_pos_end.getLayer(), hit_pos_end.getStrip(),
95 hit_pos_end.getEnd());
96 ldmx::HcalDigiID digi_id_neg(hit_neg_end.getSection(),
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);
100
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;
105 }
106
107 // update position in strip according to time measurement
108 // velocity of light in polystyrene, n = 1.6 = c/v
109 double v = 299.792 / 1.6;
110 double hit_time_diff = pos_time - neg_time;
111
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;
118
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;
122 if (orientation ==
123 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
124 position_unchanged = position.X();
125 position.SetX(position_bar);
126 } else {
127 position_unchanged = position.Y();
128 position.SetY(position_bar);
129 }
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();
134
135 // TODO: switch unique hit time for this pulse
136 [[maybe_unused]] double hit_time =
137 (hit_pos_end.getTime() + hit_neg_end.getTime());
138
139 // amplitude and PEs
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 =
144 num_mips_equivalent * pe_per_mip_ * mip_energy_;
145
146 // reconstructed Hit
147 ldmx::HcalHit rec_hit;
148 rec_hit.setID(id.raw());
149 rec_hit.setXPos(position.X());
150 rec_hit.setYPos(position.Y());
151 rec_hit.setZPos(position.Z());
152 rec_hit.setSection(id.section());
153 rec_hit.setStrip(id.strip());
154 rec_hit.setLayer(id.layer());
155 rec_hit.setPE(p_es);
156 rec_hit.setMinPE(std::min(hit_pos_end.getPE(), hit_neg_end.getPE()));
157 rec_hit.setAmplitude(num_mips_equivalent);
158 rec_hit.setAmplitudePos(hit_pos_end.getAmplitude());
159 rec_hit.setAmplitudeNeg(hit_neg_end.getAmplitude());
160 rec_hit.setToaPos(hit_pos_end.getTime());
161 rec_hit.setToaNeg(hit_neg_end.getTime());
162 rec_hit.setEnergy(reconstructed_energy);
163 rec_hit.setTime(hit_time_diff);
164 rec_hit.setTimeDiff(hit_pos_end.getTime() - hit_neg_end.getTime());
165 rec_hit.setPositionUnchanged(position_unchanged, orientation_int);
166 double_hcal_rec_hits.push_back(rec_hit);
167 }
168
169 // add collection to event bus
170 event.add(rec_coll_name_, double_hcal_rec_hits);
171}
172
173} // namespace hcal
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
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:42
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
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:68
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