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{
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 int orientation_int = static_cast<int>(orientation);
74
75 // skip non-double-ended layers
76 if (id.section() != ldmx::HcalID::HcalSection::BACK) continue;
77
78 // get two hits to reconstruct
79 auto hitPosEnd = hcalBar.second.at(indicesByID[id].first);
80 auto hitNegEnd = hcalBar.second.at(indicesByID[id].second);
81
82 // update TOA hit with negative end with mean shift
83 ldmx::HcalDigiID digi_id_pos(hitPosEnd.getSection(), hitPosEnd.getLayer(),
84 hitPosEnd.getStrip(), hitPosEnd.getEnd());
85 ldmx::HcalDigiID digi_id_neg(hitNegEnd.getSection(), hitNegEnd.getLayer(),
86 hitNegEnd.getStrip(), hitNegEnd.getEnd());
87 double mean_shift = conditions.toaCalib(digi_id_neg.raw(), 1);
88
89 double pos_time = hitPosEnd.getTime();
90 double neg_time = hitNegEnd.getTime();
91 if (pos_time != 0 || neg_time != 0) {
92 neg_time = neg_time - mean_shift;
93 }
94
95 // update position in strip according to time measurement
96 double v =
97 299.792 / 1.6; // velocity of light in polystyrene, n = 1.6 = c/v
98 double hitTimeDiff = pos_time - neg_time;
99
100 // std::cout << "\n new hit " << std::endl;
101 // std::cout << "strip " << id.strip() << " layer " << id.layer() << "
102 // center position " << position.X() << " " << position.Y() << " " <<
103 // position.Z() << std::endl; std::cout << "hittime pos " << pos_time << "
104 // neg " << neg_time << " bar sign " << " diff " << hitTimeDiff <<
105 // std::endl;
106
107 int position_bar_sign = hitTimeDiff > 0 ? 1 : -1;
108 double position_unchanged = 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 position.SetX(position_bar);
114 } else {
115 position_unchanged = position.Y();
116 position.SetY(position_bar);
117 }
118 // std::cout << "position unchanged " << position_unchanged << " orientation
119 // " << orientation_int << std::endl; std::cout << "newposition " <<
120 // position.X() << " " << position.Y() << " " << position.Z() << std::endl;
121
122 // TODO: switch unique hit time for this pulse
123 [[maybe_unused]] double hitTime =
124 (hitPosEnd.getTime() + hitNegEnd.getTime());
125
126 // amplitude and PEs
127 double num_mips_equivalent =
128 (hitPosEnd.getAmplitude() + hitNegEnd.getAmplitude());
129 double PEs = (hitPosEnd.getPE() + hitNegEnd.getPE());
130 double reconstructed_energy =
131 num_mips_equivalent * pe_per_mip_ * mip_energy_;
132
133 // reconstructed Hit
134 ldmx::HcalHit recHit;
135 recHit.setID(id.raw());
136 recHit.setXPos(position.X());
137 recHit.setYPos(position.Y());
138 recHit.setZPos(position.Z());
139 recHit.setSection(id.section());
140 recHit.setStrip(id.strip());
141 recHit.setLayer(id.layer());
142 recHit.setPE(PEs);
143 recHit.setMinPE(std::min(hitPosEnd.getPE(), hitNegEnd.getPE()));
144 recHit.setAmplitude(num_mips_equivalent);
145 recHit.setAmplitudePos(hitPosEnd.getAmplitude());
146 recHit.setAmplitudeNeg(hitNegEnd.getAmplitude());
147 recHit.setToaPos(hitPosEnd.getTime());
148 recHit.setToaNeg(hitNegEnd.getTime());
149 recHit.setEnergy(reconstructed_energy);
150 recHit.setTime(hitTimeDiff);
151 recHit.setTimeDiff(hitPosEnd.getTime() - hitNegEnd.getTime());
152 recHit.setPositionUnchanged(position_unchanged, orientation_int);
153 doubleHcalRecHits.push_back(recHit);
154 }
155
156 // add collection to event bus
157 event.add(rec_coll_name_, doubleHcalRecHits);
158}
159
160} // namespace hcal
161DECLARE_PRODUCER_NS(hcal, HcalDoubleEndRecProducer);
#define DECLARE_PRODUCER_NS(NS, 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
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