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 // get two hits_ to reconstruct
80 auto hit_pos_end = hcal_bar.second.at(indices_by_id[id].first);
81 auto hit_neg_end = hcal_bar.second.at(indices_by_id[id].second);
82
83 // update TOA hit with negative end with mean shift
84 ldmx::HcalDigiID digi_id_pos(hit_pos_end.getSection(),
85 hit_pos_end.getLayer(), hit_pos_end.getStrip(),
86 hit_pos_end.getEnd());
87 ldmx::HcalDigiID digi_id_neg(hit_neg_end.getSection(),
88 hit_neg_end.getLayer(), hit_neg_end.getStrip(),
89 hit_neg_end.getEnd());
90 double mean_shift = conditions.toaCalib(digi_id_neg.raw(), 1);
91
92 double pos_time = hit_pos_end.getTime();
93 double neg_time = hit_neg_end.getTime();
94 if (pos_time != 0 || neg_time != 0) {
95 neg_time = neg_time - mean_shift;
96 }
97
98 // update position in strip according to time measurement
99 // velocity of light in polystyrene, n = 1.6 = c/v
100 double v = 299.792 / 1.6;
101 double hit_time_diff = pos_time - neg_time;
102
103 ldmx_log(trace) << "\n new hit ";
104 ldmx_log(trace) << "strip " << id.strip() << " layer_ " << id.layer()
105 << "center position X = " << position.X()
106 << " Y =" << position.Y() << " Z = " << position.Z();
107 ldmx_log(trace) << "hittime pos_ " << pos_time << "neg " << neg_time
108 << " bar sign " << " diff " << hit_time_diff;
109
110 int position_bar_sign = hit_time_diff > 0 ? 1 : -1;
111 double position_unchanged = 0;
112 double position_bar = position_bar_sign * fabs(hit_time_diff) * v / 2;
113 if (orientation ==
114 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
115 position_unchanged = position.X();
116 position.SetX(position_bar);
117 } else {
118 position_unchanged = position.Y();
119 position.SetY(position_bar);
120 }
121 ldmx_log(trace) << "position unchanged " << position_unchanged
122 << " orientation = " << orientation_int;
123 ldmx_log(trace) << "newposition X = " << position.X()
124 << " Y = " << position.Y() << " Z = " << position.Z();
125
126 // TODO: switch unique hit time for this pulse
127 [[maybe_unused]] double hit_time =
128 (hit_pos_end.getTime() + hit_neg_end.getTime());
129
130 // amplitude and PEs
131 double num_mips_equivalent =
132 (hit_pos_end.getAmplitude() + hit_neg_end.getAmplitude());
133 double p_es = (hit_pos_end.getPE() + hit_neg_end.getPE());
134 double reconstructed_energy =
135 num_mips_equivalent * pe_per_mip_ * mip_energy_;
136
137 // reconstructed Hit
138 ldmx::HcalHit rec_hit;
139 rec_hit.setID(id.raw());
140 rec_hit.setXPos(position.X());
141 rec_hit.setYPos(position.Y());
142 rec_hit.setZPos(position.Z());
143 rec_hit.setSection(id.section());
144 rec_hit.setStrip(id.strip());
145 rec_hit.setLayer(id.layer());
146 rec_hit.setPE(p_es);
147 rec_hit.setMinPE(std::min(hit_pos_end.getPE(), hit_neg_end.getPE()));
148 rec_hit.setAmplitude(num_mips_equivalent);
149 rec_hit.setAmplitudePos(hit_pos_end.getAmplitude());
150 rec_hit.setAmplitudeNeg(hit_neg_end.getAmplitude());
151 rec_hit.setToaPos(hit_pos_end.getTime());
152 rec_hit.setToaNeg(hit_neg_end.getTime());
153 rec_hit.setEnergy(reconstructed_energy);
154 rec_hit.setTime(hit_time_diff);
155 rec_hit.setTimeDiff(hit_pos_end.getTime() - hit_neg_end.getTime());
156 rec_hit.setPositionUnchanged(position_unchanged, orientation_int);
157 double_hcal_rec_hits.push_back(rec_hit);
158 }
159
160 // add collection to event bus
161 event.add(rec_coll_name_, double_hcal_rec_hits);
162}
163
164} // 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