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.getParameter<double>("pe_per_mip");
13 mip_energy_ = p.getParameter<double>("mip_energy");
14 clock_cycle_ = p.getParameter<double>("clock_cycle");
15}
16
18 const auto& hcalGeometry = getCondition<ldmx::HcalGeometry>(
20
21 const auto& conditions{
22 getCondition<HcalReconConditions>(HcalReconConditions::CONDITIONS_NAME)};
23
24 auto hcalRecHits = event.getCollection<ldmx::HcalHit>(coll_name_, pass_name_);
25
26 std::vector<ldmx::HcalHit> doubleHcalRecHits;
27
28 // group hcal rechits by the same HcalID
29 std::map<ldmx::HcalID, std::vector<ldmx::HcalHit>> hitsByID;
30 for (auto const& hit : hcalRecHits) {
31 ldmx::HcalID id(hit.getSection(), hit.getLayer(), hit.getStrip());
32
33 auto idh = hitsByID.find(id);
34 if (idh == hitsByID.end()) {
35 hitsByID[id] = std::vector<ldmx::HcalHit>(1, hit);
36 } else {
37 idh->second.push_back(hit);
38 }
39 }
40
41 // make pairs of hcal rechits indices that belong to the same pulse
42 // @TODO: for now we just take the first two indices that have opposite-ends
43 // we do not cover the case where two hits come separated in time
44 std::map<ldmx::HcalID, std::pair<int, int>> indicesByID;
45 for (auto const& hcalBar : hitsByID) {
46 auto id = hcalBar.first;
47
48 std::pair<int, int> indices(-1, -1);
49 int iHit = 0;
50 while (iHit < hcalBar.second.size()) {
51 auto hit = hcalBar.second.at(iHit);
52
53 ldmx::HcalDigiID digi_id(hit.getSection(), hit.getLayer(), hit.getStrip(),
54 hit.getEnd());
55 if (digi_id.isNegativeEnd() && indices.second == -1) {
56 indices.second = iHit;
57 }
58 if (!digi_id.isNegativeEnd() && indices.first == -1) {
59 indices.first = iHit;
60 }
61 iHit++;
62 }
63 indicesByID[id] = indices;
64 }
65
66 // reconstruct double-ended hits
67 for (auto const& hcalBar : hitsByID) {
68 auto id = hcalBar.first;
69
70 // get bar position from geometry
71 auto position = hcalGeometry.getStripCenterPosition(id);
72 const auto orientation{hcalGeometry.getScintillatorOrientation(id)};
73
74 // skip non-double-ended layers
75 if (id.section() != ldmx::HcalID::HcalSection::BACK) continue;
76
77 // get two hits to reconstruct
78 auto hitPosEnd = hcalBar.second.at(indicesByID[id].first);
79 auto hitNegEnd = hcalBar.second.at(indicesByID[id].second);
80
81 // update TOA hit with negative end with mean shift
82 ldmx::HcalDigiID digi_id_pos(hitPosEnd.getSection(), hitPosEnd.getLayer(),
83 hitPosEnd.getStrip(), hitPosEnd.getEnd());
84 ldmx::HcalDigiID digi_id_neg(hitNegEnd.getSection(), hitNegEnd.getLayer(),
85 hitNegEnd.getStrip(), hitNegEnd.getEnd());
86 double mean_shift = conditions.toaCalib(digi_id_neg.raw(), 1);
87
88 double pos_time = hitPosEnd.getTime();
89 double neg_time = hitNegEnd.getTime();
90 if (pos_time != 0 || neg_time != 0) {
91 neg_time = neg_time - mean_shift;
92 }
93
94 // update position in strip according to time measurement
95 double v =
96 299.792 / 1.6; // velocity of light in polystyrene, n = 1.6 = c/v
97 double hitTimeDiff = pos_time - neg_time;
98
99 // std::cout << "\n new hit " << std::endl;
100 // std::cout << "strip " << id.strip() << " layer " << id.layer() << "
101 // center position " << position.X() << " " << position.Y() << " " <<
102 // position.Z() << std::endl; std::cout << "hittime pos " << pos_time << "
103 // neg " << neg_time << " bar sign " << " diff " << hitTimeDiff <<
104 // std::endl;
105
106 int position_bar_sign = hitTimeDiff > 0 ? 1 : -1;
107 double position_unchanged = 0;
108 int isX = 0;
109 double position_bar = position_bar_sign * fabs(hitTimeDiff) * v / 2;
110 if (orientation ==
111 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
112 position_unchanged = position.X();
113 isX = 1;
114 position.SetX(position_bar);
115 } else {
116 position_unchanged = position.Y();
117 isX = 0;
118 position.SetY(position_bar);
119 }
120 // std::cout << "position unchanged " << position_unchanged << " isx " <<
121 // isX << std::endl; std::cout << "newposition " << position.X() << " " <<
122 // position.Y() << " " << position.Z() << std::endl;
123
124 // TODO: switch unique hit time for this pulse
125 [[maybe_unused]] double hitTime =
126 (hitPosEnd.getTime() + hitNegEnd.getTime());
127
128 // amplitude and PEs
129 double num_mips_equivalent =
130 (hitPosEnd.getAmplitude() + hitNegEnd.getAmplitude());
131 double PEs = (hitPosEnd.getPE() + hitNegEnd.getPE());
132 double reconstructed_energy =
133 num_mips_equivalent * pe_per_mip_ * mip_energy_;
134
135 // reconstructed Hit
136 ldmx::HcalHit recHit;
137 recHit.setID(id.raw());
138 recHit.setXPos(position.X());
139 recHit.setYPos(position.Y());
140 recHit.setZPos(position.Z());
141 recHit.setSection(id.section());
142 recHit.setStrip(id.strip());
143 recHit.setLayer(id.layer());
144 recHit.setPE(PEs);
145 recHit.setMinPE(std::min(hitPosEnd.getPE(), hitNegEnd.getPE()));
146 recHit.setAmplitude(num_mips_equivalent);
147 recHit.setAmplitudePos(hitPosEnd.getAmplitude());
148 recHit.setAmplitudeNeg(hitNegEnd.getAmplitude());
149 recHit.setToaPos(hitPosEnd.getTime());
150 recHit.setToaNeg(hitNegEnd.getTime());
151 recHit.setEnergy(reconstructed_energy);
152 recHit.setTime(hitTimeDiff);
153 recHit.setTimeDiff(hitPosEnd.getTime() - hitNegEnd.getTime());
154 recHit.setPositionUnchanged(position_unchanged, isX);
155 doubleHcalRecHits.push_back(recHit);
156 }
157
158 // add collection to event bus
159 event.add(rec_coll_name_, doubleHcalRecHits);
160}
161
162} // namespace hcal
163DECLARE_PRODUCER_NS(hcal, HcalDoubleEndRecProducer);
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Implements an event buffer system for storing event data.
Definition Event.h:41
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
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:23
void setSection(int section)
Set the section for this hit.
Definition HcalHit.h:132
void setToaNeg(double toaNeg)
Set toa of the negative end.
Definition HcalHit.h:174
void setTimeDiff(double timeDiff)
Set time difference (uncorrected)
Definition HcalHit.h:162
void setMinPE(float minpe)
Set the minimum number of photoelectrons estimated for this hit.
Definition HcalHit.h:126
void setToaPos(double toaPos)
Set toa of the positive end.
Definition HcalHit.h:168
void setAmplitudeNeg(double amplitudeNeg)
Set amplitude of the negative end.
Definition HcalHit.h:186
void setStrip(int strip)
Set the strip for this hit.
Definition HcalHit.h:144
void setPositionUnchanged(double position, int isX)
Set original position.
Definition HcalHit.h:191
void setAmplitudePos(double amplitudePos)
Set amplitude of the positive end.
Definition HcalHit.h:180
void setLayer(int layer)
Set the layer for this hit.
Definition HcalHit.h:138
void setPE(float pe)
Set the number of photoelectrons estimated for this hit.
Definition HcalHit.h:119
Implements detector ids for HCal subdetector.
Definition HcalID.h:19