LDMX Software
TestBeamHitProducer.cxx
Go to the documentation of this file.
1
9
10#include <cmath>
11
14
15namespace trigscint {
16
17TestBeamHitProducer::TestBeamHitProducer(const std::string& name,
18 framework::Process& process)
19 : Producer(name, process) {}
20
21void TestBeamHitProducer::configure(framework::config::Parameters& parameters) {
22 input_col_ = parameters.get<std::string>("input_collection");
23 output_collection_ = parameters.get<std::string>("output_collection");
24 input_pass_name_ = parameters.get<std::string>("input_pass_name");
25 mip_response_ = parameters.get<std::vector<double> >("MIPresponse");
26 peds_ = parameters.get<std::vector<double> >("pedestals");
27 gain_ = parameters.get<std::vector<double> >("gain");
28
29 start_sample_ = parameters.get<int>("start_sample");
30 pulse_width_ = parameters.get<int>("pulse_width");
31 pulse_width_lyso_ = parameters.get<int>("pulse_width_lyso");
32 n_instrumented_channels_ = parameters.get<int>("n_instrumented_channels");
33 do_clean_hits_ = parameters.get<bool>("do_clean_hits");
34
35 std::cout << " [ TestBeamHitProducer ] In configure(), got parameters "
36 << "\n\t inputCollection = " << input_col_
37 << "\n\t inputPassName = " << input_pass_name_
38 << "\n\t outputCollection = " << output_collection_
39 << "\n\t startSample = " << start_sample_
40 << "\n\t pulseWidth = " << pulse_width_
41 << "\n\t pulseWidthLYSO = " << pulse_width_lyso_
42 << "\n\t gain[0] = " << gain_[0]
43 << "\n\t nInstrumentedChannels = " << n_instrumented_channels_
44 << "\n\t doCleanHits = " << do_clean_hits_
45 << "\n\t pedestals[0] = " << peds_[0]
46 << "\n\t MIPresponse[0] = " << mip_response_[0] << "\t."
47 << std::endl;
48
49 return;
50}
51
52void TestBeamHitProducer::produce(framework::Event& event) {
53 /*
54 hit producer.
55 sum up all charge within a certain time window. could work two ways:
56 - find a time sample above a threshold or where TDC is 0-50 (0-2)
57 * this could allow for finding several pulses per event, just
58 keep sliding along in time
59 -- in that case, record nPulses, startsample, pulsewidth
60 for each hit
61 - use a fixed start sample, and keep summing from there until
62 nSamples is reached or all time samples used
63
64 specifics:
65 - each channel has its own pedestal to subtract. also try using the
66 first 5 samples to establish a threshold in the event. store both
67 - store hit Q and hit PE conversion
68 - for now use the same reconstruction paradigm for LYSO and plastic.
69 two notes though
70 1. LYSO pulse looks wider, and might need wider window. plastic is
71 fine with 5. start by 8 for LYSO (even if for large pulses, sometimes 10
72 seem to be needed). could probe this by correlating plastic and LYSO, and
73 checking if at some amplitude (in plastic), we start cutting off charge in
74 LYSO
75 2. there is a time offset between fibers. need to have a
76 parameter fiber2offset to use for elecID >= 8
77 -- added this as a variable in EventReadout, along with fiber
78 number. so this class doesn't need any detailed knowledge
79
80 variables to write out:
81 - start sample
82 - pulse width
83 - n samples above threshold
84 - nPulses
85 - early pedestal (from first 5)
86 - assumed/average channel pedestal
87 - total Q
88 - ped subtracted total Q
89 - PE value
90 - max amplitude in pulse
91 - store material assumption? isLYSO?
92 */
93
94 float mev_per_mip = 0.3;
95 float pe_per_mip = 100;
96
97 const auto channels{event.getCollection<trigscint::EventReadout>(
98 input_col_, input_pass_name_)};
99
100 int ev_nb = event.getEventNumber();
101 std::vector<trigscint::TestBeamHit> hits;
102 for (auto chan : channels) {
104 int bar = chan.getChanID();
105 // don't run hit reconstruction on junk signal
106 if (bar >= n_instrumented_channels_) continue;
107 int width = pulse_width_;
108 if (bar % 2 == 0) { // LYSO channel: allow for wider pulses
109 width = pulse_width_lyso_; // avoid hardwiring
110 }
111 hit.setPulseWidth(width);
112 hit.setStartSample(start_sample_);
113 float ped = peds_.at(bar); // chan.getPedestal() ;
114 float early_ped = chan.getEarlyPedestal();
115 hit.setPedestal(ped);
116 hit.setEarlyPedestal(early_ped);
117 int is_clean = 0; // false;
118 float threshold = fabs(ped); // 2*fabs(peds_[ bar ]); // or sth
119 if (do_clean_hits_) threshold = 7 * fabs(ped); // stricter cut
120
121 int start_t = start_sample_ + chan.getTimeOffset();
122 float max_q = -999.;
123 int n_samp_above_ped = 0;
124 int n_samp_above_thr = 0;
125 float tot_subtr_q = 0;
126 std::vector<float> q = chan.getQ();
127 // go to the start sample defined for this channel.
128 for (int i_t = start_t; i_t < q.size(); i_t++) {
129 ldmx_log(debug) << "in event " << ev_nb << "; channel " << bar
130 << ", got charge[" << i_t << "] = " << q.at(i_t);
131 // for the defined number of samples, subtract pedestal. if > 0, increment
132 // sample counter.
133 float sub_q = q.at(i_t) -
134 ped; // this might be addition, if ped is negative. should
135 // see this as channel dependence in nSampAbove
136 // once beyond nSamples, want to see how long positive threshold
137 // subtracted tail is --> increment sample counter in any case.
138 if (sub_q > 0) n_samp_above_ped++;
139 if (sub_q > threshold) n_samp_above_thr++;
140 if (i_t - start_t < width) { // we're in the pulse integration window
141 if (sub_q > max_q) // keep track of max Q. this is the pulse amplitude
142 max_q = sub_q; // q.at(iT);
143 if (sub_q > 0)
144 tot_subtr_q +=
145 sub_q; // add positive subtracted Q to total pulse charge.
146 } else if (sub_q < 0 ||
147 q.at(i_t) < 0) // if after the full pulse width, subQ <
148 // pedestal, break. special case to break at
149 // q=0 for cases where ped < 0
150 break;
151 // done
152 } // over time samples
153
154 // first check that hit passes any quality cuts
155 uint flag = chan.getQualityFlag();
156 if (do_clean_hits_) {
157 // int isLongPulse=(nSampAboveThr < 2 || nSampAboveThr >
158 // width + 2);
159 int is_long_pulse =
160 (n_samp_above_thr >
161 width); // the short ones we'll have to single out otherwise (like
162 // spike flag or low Q) or live with
163 flag += 4 * is_long_pulse;
164 if (max_q > 2e5 && n_samp_above_thr < 3 &&
165 flag % 2 == 0) // this was not flagged as a spike but is eerily
166 // narrow and with high Q; flag it as a spike.
167 flag += 1;
168 if (flag == 0) is_clean = 1;
169 }
170
171 float pe = tot_subtr_q * 6250. / gain_[bar];
172 if (pe > 20) // dont't want to intercalibrate the shot noise
173 pe *= mip_response_[bar];
174
175 // set pulse properties like PE and amplitude
176 hit.setSampAbovePed(n_samp_above_ped);
177 hit.setSampAboveThr(n_samp_above_thr);
178 hit.setQ(tot_subtr_q);
179 hit.setAmplitude(max_q);
180 hit.setPE(pe);
181 hit.setHitQuality(is_clean);
182 hit.setQualityFlag(flag);
183 // set bar id. set moduleNB = 0
184 hit.setBarID(bar);
185 hit.setModuleID(0); // test beam
186 // the rest are a little ill-defined for now (PE-energy conversion not
187 // known/different between LYSO and plastic)
188 hit.setTime(-999); // maybe?
189 hit.setBeamEfrac(-1.);
190 hit.setEnergy(hit.getPE() * mev_per_mip / pe_per_mip);
191
192 // add hit
193 hits.push_back(hit);
194 } // over channels
195
196 // at end of event, write the collection of trigger scintillator hits.
197 event.add(output_collection_, hits);
198
199 return;
200}
201
202} // namespace trigscint
203
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that stores full reconstructed (linearized) readout QIE sample from the TS.
Class that builds recHits.
Class that stores full reconstructed (linearized) readout QIE sample from the TS.
Implements an event buffer system for storing event data.
Definition Event.h:40
Class which represents the process under execution.
Definition Process.h:34
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
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].
void setPE(const float PE)
Set hit pe.
void setBarID(const int barID)
Set hit bar ID.
void setBeamEfrac(const float beamEfrac)
Set beam energy fraction of hit.
float getPE() const
Get the hit pe.
void setModuleID(const int moduleID)
Set hit module ID.
This class represents the linearised QIE output from the trigger scintillator, in charge (fC).
Organizes digis into TrigScintHits, based on linearized full event readout from test beam/test stand.
This class represents the linearised QIE output from the trigger scintillator, in charge (fC).
Definition TestBeamHit.h:24
void setQualityFlag(const uint flag)
Set hit data quality flag.
void setHitQuality(const int isClean)
Set whether hit has been checked for and passed quality criteria.
void setSampAbovePed(const int sampAbovePed)
Set number of samples above pedestal in pulse/hit.
void setQ(const float q)
Store total charge.
Definition TestBeamHit.h:73
void setSampAboveThr(const int sampAboveThr)
Set number of samples above threshold in pulse/hit.
void setPulseWidth(const int pulseWidth)
Set width used to integrate pulse/hit (in time samples)
void setPedestal(const float pedestal)
Set channel (linearized.
Definition TestBeamHit.h:51
void setEarlyPedestal(const float earlyPed)
Set channel (linearized.
Definition TestBeamHit.h:63
void setStartSample(const int startSample)
Store total charge.
Definition TestBeamHit.h:96