LDMX Software
HcalSingleEndRecProducer.cxx
1#include "Hcal/HcalSingleEndRecProducer.h"
2namespace hcal {
3
4std::tuple<double, double, int> HcalSingleEndRecProducer::extract_measurements(
5 const ldmx::HgcrocDigiCollection::HgcrocDigi& digi, double pedestal,
6 double bx_shift) {
7 // sum_adc = total of all but first in-time adc measurements
8 double sum_adc{0};
9 // sum_tot = total of all tot measurements
10 int sum_tot{0};
11 // first, get time of arrival w.r.t to start BX
12 int toa_sample{0}, toa_startbx{0};
13 // get the correction for the wrong BX assignment
14 // TODO: Currently not used anywhere
15 [[maybe_unused]] int bx_to_time{0};
16 // and figure out sample of maximum amplitude
17 // TODO: Currently not used anywhere
18 [[maybe_unused]] int max_sample{0};
19 double max_meas{0};
20 for (std::size_t i_sample{0}; i_sample < digi.size(); i_sample++) {
21 // adc logic
22 if (i_sample > 0) sum_adc += (digi.at(i_sample).adc_t() - pedestal);
23
24 // tot logic
25 sum_tot += digi.at(i_sample).tot();
26
27 // toa logic
28 if (digi.at(i_sample).toa() > 0) {
29 if (digi.at(i_sample).toa() >= bx_shift) {
30 toa_sample = i_sample;
31 } else {
32 toa_sample = i_sample + 1;
33 }
34
35 // sum toa in given bx - given that multiple bx may be associated with the
36 // TOA measurement
37 toa_startbx += digi.at(i_sample).toa() * (clock_cycle_ / 1024) +
38 (clock_cycle_ * toa_sample);
39 }
40
41 if (digi.at(i_sample).adc_t() - pedestal > max_meas) {
42 max_meas = digi.at(i_sample).adc_t() - pedestal;
43 max_sample = i_sample;
44 }
45 }
46 // get toa
47 double toa = toa_startbx;
48
49 // get toa w.r.t the peak
50 // double toa = (max_sample - toa_sample) * clock_cycle_ - toa_startbx;
51 // get toa w.r.t the SOI
52 // toa += ((int)isoi_ - max_sample) * clock_cycle_;
53
54 return std::make_tuple(toa, sum_adc, sum_tot);
55}
56
58 pass_name_ = p.getParameter("pass_name", pass_name_);
59 coll_name_ = p.getParameter("coll_name", coll_name_);
60
61 rec_pass_name_ = p.getParameter("rec_pass_name", rec_pass_name_);
62 rec_coll_name_ = p.getParameter("rec_coll_name", rec_coll_name_);
63
64 pe_per_mip_ = p.getParameter<double>("pe_per_mip");
65 mip_energy_ = p.getParameter<double>("mip_energy");
66 clock_cycle_ = p.getParameter<double>("clock_cycle");
67}
68
70 const auto& hcalGeometry = getCondition<ldmx::HcalGeometry>(
72
73 const auto& conditions{
74 getCondition<HcalReconConditions>(HcalReconConditions::CONDITIONS_NAME)};
75
76 auto hcalDigis =
78
79 std::vector<ldmx::HcalHit> hcalRecHits;
80
81 isoi_ = hcalDigis.getSampleOfInterestIndex();
82
83 for (auto const& digi : hcalDigis) {
84 ldmx::HcalDigiID id_digi(digi.id());
85 ldmx::HcalID id(id_digi.section(), id_digi.layer(), id_digi.strip());
86
87 // amplitude/TOT reconstruction
88 double num_mips_equivalent{0};
89 auto [toa, sum_adc, sum_tot] =
90 extract_measurements(digi, conditions.adcPedestal(digi.id()),
91 conditions.toaCalib(digi.id(), 0));
92 auto is_adc = conditions.is_adc(digi.id(), sum_tot);
93 if (is_adc) {
94 double adc_calib = sum_adc / conditions.adcGain(digi.id(), 0);
95 num_mips_equivalent = adc_calib;
96 } else {
97 double tot_calib = conditions.linearize(digi.id(), sum_tot);
98 num_mips_equivalent = tot_calib / conditions.adcGain(digi.id(), 0);
99 }
100 int PEs = num_mips_equivalent * pe_per_mip_;
101 double reconstructed_energy =
102 num_mips_equivalent * pe_per_mip_ * mip_energy_;
103
104 // time reconstruction
105 double hitTime = toa;
106
107 // position single ended (taken directly from geometry)
108 auto position = hcalGeometry.getStripCenterPosition(id);
109
110 // reconstructed Hit
111 ldmx::HcalHit recHit;
112 recHit.setID(id.raw());
113 recHit.setXPos(position.X());
114 recHit.setYPos(position.Y());
115 recHit.setZPos(position.Z());
116 recHit.setSection(id.section());
117 recHit.setStrip(id.strip());
118 recHit.setLayer(id.layer());
119 recHit.setEnd(id_digi.end());
120 recHit.setPE(PEs);
121 recHit.setMinPE(PEs);
122 recHit.setAmplitude(num_mips_equivalent);
123 recHit.setEnergy(reconstructed_energy);
124 recHit.setTime(hitTime);
125 recHit.setIsADC(is_adc);
126 hcalRecHits.push_back(recHit);
127 }
128
129 // add collection to event bus
130 event.add(rec_coll_name_, hcalRecHits);
131}
132
133} // namespace hcal
134DECLARE_PRODUCER_NS(hcal, HcalSingleEndRecProducer);
#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
static const std::string CONDITIONS_NAME
the name of the HcalReconConditions table (must match python registration name)
double mip_energy_
energy per MIP [MeV]
double pe_per_mip_
number of PEs per MIP
std::tuple< double, double, int > extract_measurements(const ldmx::HgcrocDigiCollection::HgcrocDigi &digi, double pedestal, double bx_shift)
extract toa, sum adc, and sum tot from the input raw digi
std::string pass_name_
name of pass of digis to use
void produce(framework::Event &event) override
Process the event and put new data products into it.
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
std::string coll_name_
name of digis to reconstruct
unsigned int isoi_
sample of interest index
double clock_cycle_
length of clock cycle [ns]
std::string rec_pass_name_
name of pass of rechits to use
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].
Extension of HcalAbstractID providing access to HCal digi information.
Definition HcalDigiID.h:13
int strip() const
Get the value of the 'strip' field from the ID.
Definition HcalDigiID.h:99
int section() const
Get the value of the 'section' field from the ID.
Definition HcalDigiID.h:75
int layer() const
Get the value of the layer field from the ID.
Definition HcalDigiID.h:81
int end() const
Get the value of the 'end' field from the ID.
Definition HcalDigiID.h:105
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 setEnd(int end)
Set the end (0 neg, 1 pos side).
Definition HcalHit.h:150
void setIsADC(int isADC)
Set if the hit is reconstructed using ADC.
Definition HcalHit.h:156
void setMinPE(float minpe)
Set the minimum number of photoelectrons estimated for this hit.
Definition HcalHit.h:126
void setStrip(int strip)
Set the strip for this hit.
Definition HcalHit.h:144
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
One DIGI signal coming from the HGC ROC.
HgcrocDigiCollection::Sample at(unsigned int i_sample) const
get the sample at a specific index in the digi
int adc_t() const
Get the ADC measurement from this sample.
int tot() const
Get the TOT measurement from this sample.
int toa() const
Get the Time Of Arrival of this sample which is always the third position in all readout modes.
Represents a collection of the digi hits readout by an HGCROC.
unsigned int getSampleOfInterestIndex() const
Get index of sample of interest.