LDMX Software
HcalSingleEndRecProducer.cxx
1#include "Hcal/HcalSingleEndRecProducer.h"
2
3#include "DetDescr/HcalDigiID.h"
5#include "DetDescr/HcalID.h"
7#include "Hcal/HcalReconConditions.h"
8
9namespace hcal {
10
11std::tuple<double, double, int> HcalSingleEndRecProducer::extractMeasurements(
12 const ldmx::HgcrocDigiCollection::HgcrocDigi& digi, double pedestal,
13 double bx_shift) {
14 // sum_adc = total of all but first in-time adc measurements
15 double sum_adc{0};
16 // sum_tot = total of all tot measurements
17 int sum_tot{0};
18 // first, get time of arrival w.r.t to start BX
19 int toa_sample{0}, toa_startbx{0};
20 // get the correction for the wrong BX assignment
21 // TODO: Currently not used anywhere
22 [[maybe_unused]] int bx_to_time{0};
23 // and figure out sample of maximum amplitude
24 // TODO: Currently not used anywhere
25 [[maybe_unused]] int max_sample{0};
26 double max_meas{0};
27 for (std::size_t i_sample{0}; i_sample < digi.size(); i_sample++) {
28 // adc logic
29 if (i_sample > 0) sum_adc += (digi.at(i_sample).adcT() - pedestal);
30
31 // tot logic
32 sum_tot += digi.at(i_sample).tot();
33
34 // toa logic
35 if (digi.at(i_sample).toa() > 0) {
36 if (digi.at(i_sample).toa() >= bx_shift) {
37 toa_sample = i_sample;
38 } else {
39 toa_sample = i_sample + 1;
40 }
41
42 // sum toa in given bx - given that multiple bx may be associated with the
43 // TOA measurement
44 toa_startbx += digi.at(i_sample).toa() * (clock_cycle_ / 1024) +
45 (clock_cycle_ * toa_sample);
46 }
47
48 if (digi.at(i_sample).adcT() - pedestal > max_meas) {
49 max_meas = digi.at(i_sample).adcT() - pedestal;
50 max_sample = i_sample;
51 }
52 }
53 // get toa
54 double toa = toa_startbx;
55
56 // get toa w.r.t the peak
57 // double toa = (max_sample - toa_sample) * clock_cycle_ - toa_startbx;
58 // get toa w.r.t the SOI
59 // toa += ((int)isoi_ - max_sample) * clock_cycle_;
60
61 return std::make_tuple(toa, sum_adc, sum_tot);
62}
63
65 pass_name_ = p.getParameter("pass_name", pass_name_);
66 coll_name_ = p.getParameter("coll_name", coll_name_);
67
68 rec_pass_name_ = p.getParameter("rec_pass_name", rec_pass_name_);
69 rec_coll_name_ = p.getParameter("rec_coll_name", rec_coll_name_);
70
71 pe_per_mip_ = p.get<double>("pe_per_mip");
72 mip_energy_ = p.get<double>("mip_energy");
73 clock_cycle_ = p.get<double>("clock_cycle");
74}
75
77 const auto& hcal_geometry = getCondition<ldmx::HcalGeometry>(
79
80 const auto& conditions{
82
83 auto hcal_digis =
85
86 std::vector<ldmx::HcalHit> hcal_rec_hits;
87
88 isoi_ = hcal_digis.getSampleOfInterestIndex();
89
90 for (auto const& digi : hcal_digis) {
91 ldmx::HcalDigiID id_digi(digi.id());
92 ldmx::HcalID id(id_digi.section(), id_digi.layer(), id_digi.strip());
93
94 // amplitude/TOT reconstruction
95 double num_mips_equivalent{0};
96 auto [toa, sum_adc, sum_tot] =
97 extractMeasurements(digi, conditions.adcPedestal(digi.id()),
98 conditions.toaCalib(digi.id(), 0));
99 auto is_adc = conditions.isAdc(digi.id(), sum_tot);
100 if (is_adc) {
101 double adc_calib = sum_adc / conditions.adcGain(digi.id(), 0);
102 num_mips_equivalent = adc_calib;
103 } else {
104 double tot_calib = conditions.linearize(digi.id(), sum_tot);
105 num_mips_equivalent = tot_calib / conditions.adcGain(digi.id(), 0);
106 }
107 int p_es = num_mips_equivalent * pe_per_mip_;
108 double reconstructed_energy =
109 num_mips_equivalent * pe_per_mip_ * mip_energy_;
110
111 // time reconstruction
112 double hit_time = toa;
113
114 // position single ended (taken directly from geometry)
115 auto position = hcal_geometry.getStripCenterPosition(id);
116
117 // reconstructed Hit
118 ldmx::HcalHit rec_hit;
119 rec_hit.setID(id.raw());
120 rec_hit.setXPos(position.X());
121 rec_hit.setYPos(position.Y());
122 rec_hit.setZPos(position.Z());
123 rec_hit.setSection(id.section());
124 rec_hit.setStrip(id.strip());
125 rec_hit.setLayer(id.layer());
126 rec_hit.setEnd(id_digi.end());
127 rec_hit.setPE(p_es);
128 rec_hit.setMinPE(p_es);
129 rec_hit.setAmplitude(num_mips_equivalent);
130 rec_hit.setEnergy(reconstructed_energy);
131 rec_hit.setTime(hit_time);
132 rec_hit.setIsADC(is_adc);
133 hcal_rec_hits.push_back(rec_hit);
134 }
135
136 // add collection to event bus
137 event.add(rec_coll_name_, hcal_rec_hits);
138}
139
140} // namespace hcal
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that translates HCal ID into positions of strip hits.
Class that stores Stores reconstructed hit information from the HCAL.
Class that defines an HCal sensitive detector.
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:40
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
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::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::tuple< double, double, int > extractMeasurements(const ldmx::HgcrocDigiCollection::HgcrocDigi &digi, double pedestal, double bx_shift)
extract toa, sum adc, and sum tot from the input raw digi
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:24
void setSection(int section)
Set the section for this hit.
Definition HcalHit.h:166
void setEnd(int end)
Set the end (0 neg, 1 pos_ side).
Definition HcalHit.h:184
void setIsADC(int isADC)
Set if the hit is reconstructed using ADC.
Definition HcalHit.h:190
void setMinPE(float minpe)
Set the minimum number of photoelectrons estimated for this hit.
Definition HcalHit.h:160
void setStrip(int strip)
Set the strip for this hit.
Definition HcalHit.h:178
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
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 adcT() 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.