5#include "Framework/Exception/Exception.h"
9EventReadoutProducer::EventReadoutProducer(
const std::string &name,
11 : Producer(name, process) {}
13void EventReadoutProducer::configure(
16 inputCollection_ = parameters.
getParameter<std::string>(
"input_collection");
17 inputPassName_ = parameters.
getParameter<std::string>(
"input_pass_name");
18 outputCollection_ = parameters.
getParameter<std::string>(
"output_collection");
19 nPedSamples_ = parameters.
getParameter<
int>(
"number_pedestal_samples");
21 fiberToShift_ = parameters.
getParameter<
int>(
"fiber_to_shift");
24 ldmx_log(debug) <<
"In configure, got parameters:"
25 <<
"\noutput_collection = " << outputCollection_
26 <<
"\ninput_collection = " << inputCollection_
27 <<
"\ninput_pass_name = " << inputPassName_
28 <<
"\nnumber_pedestal_samples = " << nPedSamples_
29 <<
"\ntime_shift = " << timeShift_
30 <<
"\nfiber_to_shift = " << fiberToShift_
31 <<
"\nverbose = " << verbose_;
39 inputCollection_, inputPassName_)};
41 std::vector<trigscint::EventReadout> channelReadoutEvents;
42 for (
const auto &digi : digis) {
45 auto tdc{digi.getTDC()};
58 std::vector<float> charge;
59 std::vector<float> chargeErr;
66 for (
auto &val : adc) {
67 float Q = qie.
ADC2Q(val);
69 chargeErr.push_back(qie.
QErr(Q));
76 ldmx_log(debug) <<
"got adc value " << val <<
" and charge "
78 if (iS < nPedSamples_) earlyPed += Q;
81 outEvent.
setQ(charge);
83 earlyPed /= nPedSamples_;
92 if (verbose_) ldmx_log(debug) <<
"going into oscillations check ";
93 std::vector<float> chargeCheck = {NULL};
97 for (
int i = 3; i < charge.size() - 4; i++) {
98 float maxSamp = minCharge;
99 for (
int iQ = 0; iQ < 4; iQ++) {
101 if (charge[i + iQ] > maxSamp) maxSamp = charge[i + iQ];
103 if (verbose_) ldmx_log(debug) <<
"got max charge " << maxSamp;
104 for (
int iQ = 0; iQ < 4;
107 chargeCheck.push_back(charge[i + iQ] / maxSamp);
114 std::sort(charge.begin(), charge.end());
115 int pedLength = (int)charge.size() /
119 for (
int i = pedOffset; i < 2 * pedLength + pedOffset;
123 ped /= 2 * pedLength;
125 float medQ = charge[(int)charge.size() / 2];
126 float minQ = charge[0];
127 float maxQ = charge[charge.size() - 1];
146 for (
int i = pedOffset; i < 2 * pedLength + pedOffset; i++) {
147 diffSq += (charge[i] - ped) * (charge[i] - ped);
149 diffSq /= 2 * pedLength;
153 uint flagOscillation = 0;
155 if (maxQ > minCharge) {
158 for (
int i = 0; i < chargeCheck.size() - 4; i++) {
159 if (chargeCheck[i] ==
167 int lastMatchSample = 0;
169 bool doBreak =
false;
170 for (
int i = maxID; i < chargeCheck.size() - 4; i++) {
172 ldmx_log(debug) <<
"Checking how many matching groups of four we can "
173 "find, starting at index "
176 for (
int iQ = 0; iQ < 4; iQ++) {
180 <<
"Comparing " << chargeCheck[i + iQ] <<
" (sample " << i + iQ
181 <<
") to " << chargeCheck[i + 4 + iQ] <<
" (sample "
182 << i + 4 + iQ <<
"), ratio is "
183 << chargeCheck[i + iQ] / chargeCheck[i + 4 + iQ];
186 if (fabs(chargeCheck[i + iQ] / chargeCheck[i + 4 + iQ] - 1) <
189 (chargeCheck[i + 4 + iQ] < 0.01 &&
190 fabs(chargeCheck[i + iQ] / chargeCheck[i + 4 + iQ]) <
193 lastMatchSample = i + iQ;
197 <<
"Oscillation check for channel " << digi.getChanID()
198 <<
" breaking at time sample " << i + iQ;
207 ldmx_log(debug) <<
"Current lastMatchSample " << lastMatchSample;
208 if (lastMatchSample - maxID >=
223 int quartLength = (int)charge.size() / 4;
224 for (
int i = 4 * quartLength - 2; i >= 3 * quartLength;
226 if (charge[i] / maxQ > 0.66) nHigh++;
232 uint flagSpike = (maxQ / outEvent.
getTotQ() > 0.95) ||
233 (charge[charge.size() - 2] / maxQ <
237 (ped > 15 || nHigh >= 5);
261 uint flag = flagSpike + 2 * flagPlateau + 4 * flagLongPulse +
262 8 * flagOscillation + 16 * flagNoise;
264 <<
"Got quality flag " << flag
265 <<
" made up of (spike/plateau/long pulse/oscillation/noise) "
266 << flagSpike <<
"+" << flagPlateau <<
"+" << flagLongPulse <<
"+"
267 << flagOscillation <<
"+" << flagNoise;
272 ldmx_log(debug) <<
"In event " <<
event.getEventHeader().getEventNumber()
275 " fC, noise = " << outEvent.
getNoise() <<
" fC for channel "
278 channelReadoutEvents.push_back(outEvent);
283 event.add(outputCollection_, channelReadoutEvents);
284 ldmx_log(debug) <<
"\n";
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that builds linearized full event readout.
Implements an event buffer system for storing event data.
Class which represents the process under execution.
Class encapsulating parameters for configuring a processor.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
This class represents the linearised QIE output from the trigger scintillator, in charge (fC).
void setMedQ(const float medQ)
Set channel (linearized, charge-equiv) median charge.
void setFiberNb(const int fiberNb)
Set channel readout fiber number.
void setTimeOffset(const int timeOffset)
Set channel readout itme offset (in units of samples)
float getPedestal() const
Get the pedestal.
void setMinQ(const float minQ)
Set channel (linearized, charge-equiv) minimum charge.
void setQError(const std::vector< float > qErr)
Store charge quantization errors of all time samples.
void setNoise(const float noise)
Set channel (linearized, charge-equiv) noise.
float getNoise() const
Get the channel noise.
void setTotQ(const float totQ)
Set channel (linearized, charge-equiv) average charge.
float getTotQ() const
Get the channel totQ.
void setQualityFlag(const uint flag)
Set channel data quality flag.
void setPedestal(const float pedestal)
Set channel (linearized.
void setAvgQ(const float avgQ)
Set channel (linearized, charge-equiv) average charge.
void setMaxQ(const float maxQ)
Set channel (linearized, charge-equiv) maximum charge.
int getFiberNb() const
Get the channel fiberNb.
void setQ(const std::vector< float > q)
Store charges of all time samples.
void setEarlyPedestal(const float earlyPed)
Set channel (linearized.
class for simulating QIE chip output
float QErr(float Q)
Quantization error.
float ADC2Q(int ADC)
Converting ADC back to charge.
class for storing QIE output
std::vector< int > getADC() const
Get ADCs of all time samples.
void setTDC(const std::vector< int > tdc)
Store tdcs of all time samples.
void setChanID(const int chanid)
Store the channel ID.
void setTimeSinceSpill(const uint32_t timeSpill)
Store the event time since spill counter.
int getChanID() const
Get channel ID.
void setElecID(const int elecid)
Store the electronics ID.
void setADC(const std::vector< int > adc)
Store adcs of all time samples.