ATLAS Offline Software
RPDDataAnalyzer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "TLinearFitter.h"
8 #include "TMath.h"
9 #include <limits>
10 
11 namespace ZDC {
12 
13 unsigned int nullPileupFunc(unsigned int /* sample */) {
14  return 0;
15 }
16 
17 void helpResetFuncs(std::span<std::function<float(unsigned int)>> v) {
18  std::fill(v.begin(), v.end(), nullPileupFunc);
19 }
20 
22  ZDCMsg::MessageFunctionPtr messageFunc_p,
23  std::string tag,
24  RPDConfig const& config,
25  std::vector<float> const& calibFactors
26 ) : m_msgFunc_p(std::move(messageFunc_p)),
27  m_tag(std::move(tag)),
28  m_nSamples(config.nSamples),
29  m_nBaselineSamples(config.nBaselineSamples),
30  m_endSignalSample(config.endSignalSample),
31  m_pulse2ndDerivThresh(config.pulse2ndDerivThresh),
32  m_postPulseFracThresh(config.postPulseFracThresh),
33  m_goodPulseSampleStart(config.goodPulseSampleStart),
34  m_goodPulseSampleStop(config.goodPulseSampleStop),
35  m_nominalBaseline(config.nominalBaseline),
36  m_pileupBaselineSumThresh(config.pileupBaselineSumThresh),
37  m_pileupBaselineStdDevThresh(config.pileupBaselineStdDevThresh),
38  m_nNegativesAllowed(config.nNegativesAllowed),
39  m_AdcOverflow(config.ADCOverflow)
40 {
41  if (m_endSignalSample == 0) m_endSignalSample = m_nSamples; // sentinel value 0 -> go to end of waveform
42  if (m_outputCalibFactors.size() != s_nChannels) {
43  (*m_msgFunc_p)(ZDCMsg::Fatal,
44  "RPDDataAnalyzer::RPDDataAnalyzer: received incorrect number of channels in calibration factors ("
46  );
47  }
48  std::copy(calibFactors.begin(), calibFactors.end(), m_outputCalibFactors.data());
49  m_chFADCData.fill(std::vector<uint16_t>(m_nSamples, 0));
50  m_chCorrectedFadcData.fill(std::vector<float>(m_nSamples, 0));
51  m_chPileupExpFitParams.fill(std::vector<float>(2, 0));
52  m_chPileupStretchedExpFitParams.fill(std::vector<float>(3, 0));
53  m_chPileupExpFitParamErrs.fill(std::vector<float>(2, 0));
54  m_chPileupStretchedExpFitParamErrs.fill(std::vector<float>(3, 0));
58 
59  m_sideStatus.reset();
60  m_sideStatus.set(ValidBit, true);
61  for (auto& status : m_chStatus) {
62  status.reset();
63  status.set(ValidBit, true);
64  }
65 }
66 
70 void RPDDataAnalyzer::loadChannelData(unsigned int channel, const std::vector<uint16_t>& FadcData)
71 {
72  if (FadcData.size() != m_nSamples) {
73  (*m_msgFunc_p)(ZDCMsg::Fatal,
74  "RPDDataAnalyzer::loadChannelData: received incorrect number of samples "
75  "in FADC data (" + std::to_string(FadcData.size()) + ", expected " + std::to_string(m_nSamples) + ")"
76  );
77  }
78  m_chFADCData.at(channel) = FadcData;
80 }
81 
86 {
87  // reset status bits; valid bit is true by default
88  m_sideStatus.reset();
89  m_sideStatus.set(ValidBit, true);
90  for (auto& status : m_chStatus) {
91  status.reset();
92  status.set(ValidBit, true);
93  }
94 
102 
105 
108 
109  m_nChannelsLoaded = 0;
117 }
118 
124 {
125  for (unsigned int sample = 0; sample < m_nSamples; sample++) {
126  if (m_chFADCData.at(channel).at(sample) >= m_AdcOverflow) {
127  m_chStatus.at(channel).set(OverflowBit, true);
128  return false; // overflow - not good
129  }
130  }
131  return true; // all good
132 }
133 
140  float prePulseSize = 0;
141  unsigned int prePulseSample = 0;
142  float goodPulseSize = 0;
143  unsigned int goodPulseSample = 0;
144  float postPulseSize = 0;
145  unsigned int postPulseSample = 0;
146  for (unsigned int sample = 1; sample < m_nSamples - 1; sample++) {
147  float const secondDiff = m_chFADCData.at(channel).at(sample + 1) - 2*m_chFADCData.at(channel).at(sample) + m_chFADCData.at(channel).at(sample - 1);
148  if (secondDiff > m_pulse2ndDerivThresh) continue; // no pulse here
149  if (sample < m_goodPulseSampleStart && secondDiff < prePulseSize) {
150  prePulseSize = secondDiff;
151  prePulseSample = sample;
152  } else if (sample >= m_goodPulseSampleStart && sample <= m_goodPulseSampleStop && secondDiff < goodPulseSize) {
153  goodPulseSize = secondDiff;
154  goodPulseSample = sample;
155  } else if (sample > m_goodPulseSampleStop && secondDiff < postPulseSize) {
156  postPulseSize = secondDiff;
157  postPulseSample = sample;
158  }
159  }
160 
161  bool hasPrePulse = prePulseSample;
162  bool hasGoodPulse = goodPulseSample;
163  bool hasPostPulse = postPulseSample;
164 
165  // we need to accomodate side A, which has dips in second derivative after good pulse range
166  // if post-pulses are sufficiently small, we ignore them
167  // we expect these anomolies at ~ sample 11 or 12
168  if (hasGoodPulse && hasPostPulse && postPulseSize/goodPulseSize <= m_postPulseFracThresh) hasPostPulse = false;
169 
170  bool hasNoPulse = !hasPrePulse && !hasGoodPulse && !hasPostPulse;
171 
172  if (hasPrePulse) m_chStatus.at(channel).set(PrePulseBit, true);
173  if (hasPostPulse) m_chStatus.at(channel).set(PostPulseBit, true);
174  if (hasNoPulse) m_chStatus.at(channel).set(NoPulseBit, true);
175 
176  return !hasPrePulse && !hasPostPulse; // true if there is a only good pulse or if there is no pulse
177 }
178 
182 float RPDDataAnalyzer::calculateBaselineSamplesMSE(unsigned int channel, std::function<float(unsigned int)> const& fit) const
183 {
184  float MSE = 0;
185  for (unsigned int sample = 0; sample < m_nBaselineSamples; sample++) {
186  MSE += std::pow(m_chFADCData.at(channel).at(sample) - m_chBaseline.at(channel) - fit(sample), 2);
187  }
188  MSE /= m_nBaselineSamples;
189  return MSE;
190 }
191 
196 bool RPDDataAnalyzer::doPileupExpFit(unsigned int channel, std::vector<std::pair<unsigned int, float>> const& pileupFitPoints)
197 {
198  auto pFitter = std::make_unique<TLinearFitter>(1, "1 ++ x");
199  double x {};
200  for (auto const& [sample, y] : pileupFitPoints) {
201  x = sample;
202  pFitter->AddPoint(&x, std::log(y));
203  }
204  if (pFitter->Eval()) {
205  (*m_msgFunc_p)(ZDCMsg::Warn, "RPDDataAnalyzer::doPileupExpFit: there was an error while evaluating TLinearFitter!");
206  m_chStatus.at(channel).set(PileupExpFitFailBit, true);
207  return false;
208  }
209  m_chPileupExpFitParams.at(channel) = {static_cast<float>(pFitter->GetParameter(0)), static_cast<float>(pFitter->GetParameter(1))};
210  m_chPileupExpFitParamErrs.at(channel) = {static_cast<float>(pFitter->GetParError(0)), static_cast<float>(pFitter->GetParError(1))};
211  m_chExpPileupFuncs.at(channel) = [intercept = pFitter->GetParameter(0), slope = pFitter->GetParameter(1)](unsigned int sample) { return std::exp(intercept + slope*sample); };
213 
214  // check for exponential growth in parameters - we definitely don't want that for a function that describes pileup
215  if (pFitter->GetParameter(1) >= 0) {
216  (*m_msgFunc_p)(ZDCMsg::Debug, "RPDDataAnalyzer::doPileupExpFit: p1 is " + std::to_string(pFitter->GetParameter(1)) + " > 0 -> there is exponential growth in fit function!");
217  m_chStatus.at(channel).set(PileupExpGrowthBit, true);
218  return false;
219  }
220  return true; // all good
221 }
222 
227 bool RPDDataAnalyzer::doPileupStretchedExpFit(unsigned int channel, std::vector<std::pair<unsigned int, float>> const& pileupFitPoints)
228 {
229  auto pFitter = std::make_unique<TLinearFitter>(1, "1 ++ (x + 4)**(0.5) ++ (x + 4)**(-0.5)");
230  double x {};
231  for (auto const& [sample, y] : pileupFitPoints) {
232  x = sample;
233  pFitter->AddPoint(&x, std::log(y));
234  }
235  if (pFitter->Eval()) {
236  (*m_msgFunc_p)(ZDCMsg::Warn, "RPDDataAnalyzer::doPileupStretchedExpFit: there was an error while evaluating TLinearFitter!");
238  return false;
239  }
240  auto getFitParam = [&pFitter](int i){return pFitter->GetParameter(i);};
241  auto fGetFitErr = [&pFitter](int i){return static_cast<float>(pFitter->GetParError(i));};
242  auto fGetFitParam = [&pFitter](int i){return static_cast<float>(pFitter->GetParameter(i));};
243  //
244  m_chPileupStretchedExpFitParams.at(channel) = {fGetFitParam(0), fGetFitParam(1), fGetFitParam(2)};
245  m_chPileupStretchedExpFitParamErrs.at(channel) = {fGetFitErr(0), fGetFitErr(1), fGetFitErr(2)};
246  m_ch2ndOrderStretchedExpPileupFuncs.at(channel) = [p0 = getFitParam(0), p1 = getFitParam(1), p2 = getFitParam(2)](unsigned int sample) {
247  return std::exp(p0 + p1*std::pow(sample + 4, 0.5) + p2*std::pow(sample + 4, -0.5));
248  };
250 
251  // check for exponential growth in parameters - we definitely don't want that for a function that describes pileup
252  if (getFitParam(1) >= 0) {
253  (*m_msgFunc_p)(ZDCMsg::Debug, "RPDDataAnalyzer::doPileupStretchedExpFit: p1 is " + std::to_string(getFitParam(1)) + " > 0 -> there is exponential growth in fit function!");
255  return false;
256  }
257  if (getFitParam(2)/getFitParam(1) - 4 > 0) {
258  (*m_msgFunc_p)(ZDCMsg::Debug, "RPDDataAnalyzer::doPileupStretchedExpFit: 1st deriv max occurs at sample " + std::to_string(getFitParam(1)) + " > 0 -> fit probably looks like a pulse (and not like pileup)");
260  // analysis remains valid (for now)
261  }
262  return true; // all good
263 }
264 
268 unsigned int RPDDataAnalyzer::countSignalRangeNegatives(std::vector<float> const& values) const
269 {
270  unsigned int nNegatives = 0;
271  for (unsigned int sample = m_nBaselineSamples; sample < m_endSignalSample; sample++) {
272  if (values.at(sample) < 0) nNegatives++;
273  }
274  return nNegatives;
275 }
276 
282  float nominalBaselineSubtrSum = 0;
284  std::vector<std::pair<unsigned int, float>> pileupFitPoints;
285  for (unsigned int sample = 0; sample < m_nBaselineSamples; sample++) {
286  float const& adc = m_chFADCData.at(channel).at(sample);
287  float const adcBaselineSubtr = adc - m_nominalBaseline;
288  nominalBaselineSubtrSum += adcBaselineSubtr;
289  if (adcBaselineSubtr > 0) {
290  // this sample is a candidate for pileup fit
291  pileupFitPoints.emplace_back(sample, adcBaselineSubtr);
292  }
293  }
294  float baselineStdDev = TMath::StdDev(m_chFADCData.at(channel).begin(), std::next(m_chFADCData.at(channel).begin(), m_nBaselineSamples));
295 
296  if (nominalBaselineSubtrSum < m_pileupBaselineSumThresh || baselineStdDev < m_pileupBaselineStdDevThresh) {
297  // there is NO pileup, we will trust the average of baseline samples as a good baseline estimate
299  // calculate fadc data with baseline subtracted
300  for (unsigned int sample = 0; sample < m_nSamples; sample++) {
302  }
305  return false;
306  }
307  return true; // all good
308  }
309 
310  // we suspect that there is pileup - use nominal baseline
312 
313  if (pileupFitPoints.size() < s_minPileupFitPoints) {
315  // there are not enough points to do fit, so just use nominal baseline and call it a day
316  for (unsigned int sample = 0; sample < m_nSamples; sample++) {
318  }
319  return true; // all good
320  }
321 
322  // there is OOT pileup in this channel => expect approx. negative exponential in baseline samples
323  m_chStatus.at(channel).set(OutOfTimePileupBit, true);
324  // fit (approximately) to exponential and stretched exponential in baseline samples
325  bool expFitSuccess = doPileupExpFit(channel, pileupFitPoints);
326  bool stretchedExpFitSuccess = doPileupStretchedExpFit(channel, pileupFitPoints);
327 
328  if (stretchedExpFitSuccess) {
329  // calculate fadc data with baseline and pileup contribution subtracted
330  for (unsigned int sample = 0; sample < m_nSamples; sample++) {
332  }
335  // fallback to exponential fit
336  } else {
338  return true; // all good
339  }
340  }
341 
342  if (expFitSuccess) {
343  // calculate fadc data with baseline and pileup contribution subtracted
344  for (unsigned int sample = 0; sample < m_nSamples; sample++) {
346  }
348  m_chStatus.at(channel).set(PileupBadExpSubtrBit, true);
349  return false;
350  }
352  return true; // all good
353  }
354 
355  return false; // both fits are bad...we have no measure of pileup!
356 }
357 
362 {
363  if (m_chStatus.at(channel)[NoPulseBit]) {
364  m_chMaxAdc.at(channel) = 0;
365  m_chMaxAdcCalib.at(channel) = 0;
366  m_chMaxSample.at(channel) = -1;
367  return;
368  }
369  float maxAdc = -std::numeric_limits<float>::infinity();
370  unsigned int maxSample = 0;
371  for (unsigned int sample = m_nBaselineSamples; sample < m_endSignalSample; sample++) {
372  float adc = m_chCorrectedFadcData.at(channel).at(sample);
373  if (adc > maxAdc) {
374  maxAdc = adc;
375  maxSample = sample;
376  }
377  }
378  m_chMaxAdc.at(channel) = maxAdc;
380  m_chMaxSample.at(channel) = maxSample;
381 }
382 
387  if (m_chStatus.at(channel)[NoPulseBit]) {
388  m_chSumAdc.at(channel) = 0;
389  m_chSumAdcCalib.at(channel) = 0;
390  return;
391  }
392  // sum range is after baseline until end of signal
393  float signalRangeAdcSum = 0;
394  for (unsigned int sample = m_nBaselineSamples; sample < m_endSignalSample; sample++) {
395  signalRangeAdcSum += m_chCorrectedFadcData.at(channel).at(sample);
396  }
397  m_chSumAdc.at(channel) = signalRangeAdcSum;
398  m_chSumAdcCalib.at(channel) = signalRangeAdcSum*m_outputCalibFactors.at(channel);
399 
401  // there is pileup in this channel, calculate fraction of baseline-subtracted raw signal
402  // that is pileup (beginning of window until end of signal)
403  std::function<float(unsigned int)> pileupFunc;
404  switch (m_chPileupFuncType.at(channel)) {
407  break;
409  pileupFunc = m_chExpPileupFuncs.at(channel);
410  break;
411  default:
412  break;
413  }
414 
415  float totalAdcSum = 0;
416  float pileupTotalAdcSum = 0;
417  for (unsigned int sample = 0; sample < m_endSignalSample; sample++) {
418  totalAdcSum += m_chFADCData.at(channel).at(sample) - m_nominalBaseline;
419  pileupTotalAdcSum += pileupFunc(sample);
420  }
421  if (totalAdcSum > 0) {
422  m_chPileupFrac.at(channel) = pileupTotalAdcSum/totalAdcSum;
423  } else {
424  // avoid dividing by zero or negative, return sentinel value of -1
425  m_chPileupFrac.at(channel) = -1;
426  }
427  } // else fractional pileup is zero initialized, and this is what we want for no pileup
428 }
429 
434 {
435  for (unsigned int channel = 0; channel < s_nChannels; channel++) {
436  if (!m_chStatus.at(channel)[ValidBit]) m_sideStatus.set(ValidBit, false);
437 
442  if (m_chStatus.at(channel)[NoPulseBit]) m_sideStatus.set(NoPulseBit, true);
452  }
453 }
454 
459 {
461  (*m_msgFunc_p)(ZDCMsg::Warn,
462  "RPDDataAnalyzer::analyzeData: analyzing data with " + std::to_string(m_nChannelsLoaded) + " of "
463  + std::to_string(s_nChannels) + " channels loaded"
464  );
465  }
466  for (unsigned int channel = 0; channel < s_nChannels; channel++) {
467  if (!checkOverflow(channel)) {
468  // there was overflow, stop analysis
469  m_chStatus.at(channel).set(ValidBit, false);
470  continue;
471  }
472  if (!checkPulses(channel)) {
473  // there was a pre-pulse or post-pulse, stop analysis
474  m_chStatus.at(channel).set(ValidBit, false);
475  continue;
476  }
477  // there is either only a good pulse or no pulse
478  // only do baseline and pileup subtraction if there is a pulse!
479  if (!m_chStatus.at(channel)[NoPulseBit] /* there is a pulse -> */ && !doBaselinePileupSubtraction(channel)) {
480  // there was a pulse and a problem with baseline/pileup subtraction, stop analysis
481  m_chStatus.at(channel).set(ValidBit, false);
482  continue;
483  }
486  }
488 }
489 
493 unsigned int RPDDataAnalyzer::getChMaxSample(unsigned int channel) const
494 {
495  return m_chMaxSample.at(channel);
496 }
497 
501 float RPDDataAnalyzer::getChSumAdc(unsigned int channel) const
502 {
503  return m_chSumAdc.at(channel);
504 }
505 
510 {
511  return m_chSumAdcCalib.at(channel);
512 }
513 
517 float RPDDataAnalyzer::getChMaxAdc(unsigned int channel) const
518 {
519  return m_chMaxAdc.at(channel);
520 }
521 
526 {
527  return m_chMaxAdcCalib.at(channel);
528 }
529 
533 float RPDDataAnalyzer::getChPileupFrac(unsigned int channel) const
534 {
535  return m_chPileupFrac.at(channel);
536 }
537 
541 float RPDDataAnalyzer::getChBaseline(unsigned int channel) const {
542  return m_chBaseline.at(channel);
543 }
544 
548 const std::vector<float>& RPDDataAnalyzer::getChPileupExpFitParams(unsigned int channel) const {
549  return m_chPileupExpFitParams.at(channel);
550 }
551 
555 const std::vector<float>& RPDDataAnalyzer::getChPileupStretchedExpFitParams(unsigned int channel) const {
557 }
558 
562 const std::vector<float>& RPDDataAnalyzer::getChPileupExpFitParamErrs(unsigned int channel) const {
564 }
565 
569 const std::vector<float>& RPDDataAnalyzer::getChPileupStretchedExpFitParamErrs(unsigned int channel) const {
571 }
572 
577  return m_chExpPileupMSE.at(channel);
578 }
579 
585 }
586 
590 unsigned int RPDDataAnalyzer::getChStatus(unsigned int channel) const
591 {
592  return static_cast<unsigned int>(m_chStatus.at(channel).to_ulong());
593 }
594 
598 unsigned int RPDDataAnalyzer::getSideStatus() const
599 {
600  return static_cast<unsigned int>(m_sideStatus.to_ulong());
601 }
602 
603 } // namespace ZDC
ZDC::RPDDataAnalyzer::m_nChannelsLoaded
unsigned int m_nChannelsLoaded
Definition: RPDDataAnalyzer.h:110
CxxUtils::span
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
ZDC::RPDDataAnalyzer::m_nBaselineSamples
unsigned int m_nBaselineSamples
Definition: RPDDataAnalyzer.h:112
ZDC::RPDDataAnalyzer::m_chCorrectedFadcData
std::array< std::vector< float >, s_nChannels > m_chCorrectedFadcData
raw RPD data; index channel then sample
Definition: RPDDataAnalyzer.h:126
ZDC::RPDDataAnalyzer::PileupExpGrowthBit
@ PileupExpGrowthBit
Definition: RPDDataAnalyzer.h:52
ZDC::RPDDataAnalyzer::getChMaxSample
unsigned int getChMaxSample(unsigned int channel) const
Get sample of max of RPD data in signal range after pileup subtraction.
Definition: RPDDataAnalyzer.cxx:493
ZDC::RPDDataAnalyzer::m_ch2ndOrderStretchedExpPileupFuncs
std::array< std::function< float(unsigned int)>, s_nChannels > m_ch2ndOrderStretchedExpPileupFuncs
pileup exponential fit function (if pileup was detected and fit did not fail); per channel
Definition: RPDDataAnalyzer.h:140
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
ZDC::RPDDataAnalyzer::m_nominalBaseline
float m_nominalBaseline
Pulses after this sample are considered post-pulses.
Definition: RPDDataAnalyzer.h:118
python.xAODTrackSummaryFiller.StdDev
string StdDev
Definition: xAODTrackSummaryFiller.py:30
ZDCMsg::Warn
@ Warn
Definition: ZDCMsg.h:21
ZDC::RPDDataAnalyzer::m_goodPulseSampleStop
unsigned int m_goodPulseSampleStop
Pulses before this sample are considered pre-pulses.
Definition: RPDDataAnalyzer.h:117
ZDC::RPDDataAnalyzer::m_goodPulseSampleStart
unsigned int m_goodPulseSampleStart
If there is a good pulse and post-pulse and size of post-pulse as a fraction of good pulse is less th...
Definition: RPDDataAnalyzer.h:116
ZDC::RPDDataAnalyzer::PileupBadStretchedExpSubtrBit
@ PileupBadStretchedExpSubtrBit
Definition: RPDDataAnalyzer.h:50
ZDC::RPDDataAnalyzer::doBaselinePileupSubtraction
bool doBaselinePileupSubtraction(unsigned int channel)
Determine if there is pileup, subtract baseline and pileup, and set relevant status bits.
Definition: RPDDataAnalyzer.cxx:281
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
ZDC::RPDDataAnalyzer::OverflowBit
@ OverflowBit
Definition: RPDDataAnalyzer.h:42
ZDC::RPDDataAnalyzer::analyzeData
void analyzeData()
Analyze RPD data.
Definition: RPDDataAnalyzer.cxx:458
ZDC::RPDDataAnalyzer::m_chPileupExpFitParamErrs
std::array< std::vector< float >, s_nChannels > m_chPileupExpFitParamErrs
parameters for pileup stretched exponential fit (if pileup was detected and fit did not fail): exp( [...
Definition: RPDDataAnalyzer.h:136
ZDC::RPDDataAnalyzer::getChPileupStretchedExpFitParams
const std::vector< float > & getChPileupStretchedExpFitParams(unsigned int channel) const
Get parameters for pileup stretched exponential fit (if pileup was detected and fit did not fail): ex...
Definition: RPDDataAnalyzer.cxx:555
ZDC::RPDDataAnalyzer::ValidBit
@ ValidBit
Definition: RPDDataAnalyzer.h:40
ZDC::RPDDataAnalyzer::getChBaseline
float getChBaseline(unsigned int channel) const
Get baseline used in baseline subtraction.
Definition: RPDDataAnalyzer.cxx:541
ZDC::RPDDataAnalyzer::m_chMaxAdcCalib
std::array< float, s_nChannels > m_chMaxAdcCalib
max of RPD data in signal range after baseline and pileup subtraction; per channel
Definition: RPDDataAnalyzer.h:131
ZDC::RPDDataAnalyzer::PrePulseBit
@ PrePulseBit
Definition: RPDDataAnalyzer.h:43
ZDC::RPDDataAnalyzer::getChPileupExpFitMSE
float getChPileupExpFitMSE(unsigned int channel) const
Get mean squared error of pileup exponential fit in baseline samples (if pileup was detected and fit ...
Definition: RPDDataAnalyzer.cxx:576
ZDC::RPDDataAnalyzer::calculateBaselineSamplesMSE
float calculateBaselineSamplesMSE(unsigned int channel, std::function< float(unsigned int)> const &fit) const
Calculate the mean squared error of the fit function in the baseline samples.
Definition: RPDDataAnalyzer.cxx:182
ZDC::RPDDataAnalyzer::checkPulses
bool checkPulses(unsigned int channel)
Calculate 2nd difference, identify pulses, and set relevant status bits.
Definition: RPDDataAnalyzer.cxx:139
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
ZDC::RPDDataAnalyzer::m_nNegativesAllowed
unsigned int m_nNegativesAllowed
Baseline standard deviations less than this number indicate there is not pileup.
Definition: RPDDataAnalyzer.h:121
ZDC::RPDDataAnalyzer::m_chFADCData
std::array< std::vector< uint16_t >, s_nChannels > m_chFADCData
multiplicative calibration factors to apply to output, e.g., max and sum ADC; per channel
Definition: RPDDataAnalyzer.h:125
x
#define x
ZDC::RPDDataAnalyzer::calculateMaxSampleMaxAdc
void calculateMaxSampleMaxAdc(unsigned int channel)
Calculate max ADC and max sample.
Definition: RPDDataAnalyzer.cxx:361
ZDC::RPDDataAnalyzer::m_chPileupStretchedExpFitParams
std::array< std::vector< float >, s_nChannels > m_chPileupStretchedExpFitParams
parameters for pileup exponential fit (if pileup was detected and fit did not fail): exp( [0] + [1]*s...
Definition: RPDDataAnalyzer.h:135
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
ZDC::RPDDataAnalyzer::getChPileupStretchedExpFitMSE
float getChPileupStretchedExpFitMSE(unsigned int channel) const
Get mean squared error of pileup stretched exponential fit in baseline samples (if pileup was detecte...
Definition: RPDDataAnalyzer.cxx:583
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
ZDC::RPDDataAnalyzer::getChSumAdc
float getChSumAdc(unsigned int channel) const
Get sum of RPD data in signal range after baseline and pileup subtraction.
Definition: RPDDataAnalyzer.cxx:501
ZDC::RPDDataAnalyzer::m_AdcOverflow
unsigned int m_AdcOverflow
Maximum number of negative ADC values after baseline and pileup subtraction allowed in signal range.
Definition: RPDDataAnalyzer.h:122
ZDC::RPDDataAnalyzer::getChPileupStretchedExpFitParamErrs
const std::vector< float > & getChPileupStretchedExpFitParamErrs(unsigned int channel) const
Get parameter errors for pileup stretched exponential fit (if pileup was detected and fit did not fai...
Definition: RPDDataAnalyzer.cxx:569
ZDC::RPDDataAnalyzer::RPDDataAnalyzer
RPDDataAnalyzer(ZDCMsg::MessageFunctionPtr messageFunc_p, std::string tag, RPDConfig const &config, std::vector< float > const &calibFactors)
Definition: RPDDataAnalyzer.cxx:21
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
ZDC::RPDDataAnalyzer::m_chPileupExpFitParams
std::array< std::vector< float >, s_nChannels > m_chPileupExpFitParams
baseline used in baseline subtraction; per channel
Definition: RPDDataAnalyzer.h:134
ZDC::RPDDataAnalyzer::getChMaxAdcCalib
float getChMaxAdcCalib(unsigned int channel) const
Get max of RPD data in signal range after baseline and pileup subtraction, with output calibration fa...
Definition: RPDDataAnalyzer.cxx:525
ZDC::RPDDataAnalyzer::NoPulseBit
@ NoPulseBit
Definition: RPDDataAnalyzer.h:45
ZDC::RPDDataAnalyzer::reset
void reset()
Reset all member variables to default values.
Definition: RPDDataAnalyzer.cxx:85
ZDC::RPDDataAnalyzer::m_sideStatus
std::bitset< N_STATUS_BITS > m_sideStatus
status bits per channel
Definition: RPDDataAnalyzer.h:144
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:113
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
ZDC::RPDDataAnalyzer::s_minPileupFitPoints
static unsigned constexpr int s_minPileupFitPoints
status bits for side
Definition: RPDDataAnalyzer.h:152
ZDC::RPDDataAnalyzer::m_pileupBaselineSumThresh
float m_pileupBaselineSumThresh
The global nominal baseline; used when pileup is detected.
Definition: RPDDataAnalyzer.h:119
lumiFormat.i
int i
Definition: lumiFormat.py:85
ZDC::RPDDataAnalyzer::PileupFitFuncType::Exp
@ Exp
ZDC::RPDDataAnalyzer::m_chExpPileupFuncs
std::array< std::function< float(unsigned int)>, s_nChannels > m_chExpPileupFuncs
enum indicating type of pileup fit function; per channel
Definition: RPDDataAnalyzer.h:139
ZDC::RPDDataAnalyzer::PostPulseBit
@ PostPulseBit
Definition: RPDDataAnalyzer.h:44
ZDC::RPDDataAnalyzer::m_postPulseFracThresh
float m_postPulseFracThresh
Second differences less than or equal to this number indicate a pulse.
Definition: RPDDataAnalyzer.h:115
ZDC::RPDDataAnalyzer::doPileupExpFit
bool doPileupExpFit(unsigned int channel, std::vector< std::pair< unsigned int, float >> const &pileupFitPoints)
Perform an exponential fit in baseline-subtracted baseline samples and set relevant status bits.
Definition: RPDDataAnalyzer.cxx:196
ZDC::RPDDataAnalyzer::m_ch2ndOrderStretchedExpPileupMSE
std::array< float, s_nChannels > m_ch2ndOrderStretchedExpPileupMSE
mean squared error of pileup exponential fit in baseline samples (if pileup was detected and fit did ...
Definition: RPDDataAnalyzer.h:142
ZDC::RPDDataAnalyzer::m_outputCalibFactors
std::array< float, s_nChannels > m_outputCalibFactors
ADC values greater than or equal to this number are considered overflow.
Definition: RPDDataAnalyzer.h:123
ZDC::RPDDataAnalyzer::getChPileupFrac
float getChPileupFrac(unsigned int channel) const
Get OOT pileup sum as a fraction of non-pileup sum in entire window (0 if no OOT pileup,...
Definition: RPDDataAnalyzer.cxx:533
ZDC::RPDDataAnalyzer::getSideStatus
unsigned int getSideStatus() const
Get status word for side.
Definition: RPDDataAnalyzer.cxx:598
ZDC::RPDDataAnalyzer::m_chPileupFrac
std::array< float, s_nChannels > m_chPileupFrac
max of RPD data in signal range after baseline and pileup subtraction, with output calibration factor...
Definition: RPDDataAnalyzer.h:132
MuonValidation_CreateResolutionProfiles.fit
def fit(h, emin, emax)
Definition: MuonValidation_CreateResolutionProfiles.py:69
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
ZDC::RPDDataAnalyzer::countSignalRangeNegatives
unsigned int countSignalRangeNegatives(std::vector< float > const &values) const
Calculate the number of negative values in signal range.
Definition: RPDDataAnalyzer.cxx:268
ZDC::RPDDataAnalyzer::getChStatus
unsigned int getChStatus(unsigned int channel) const
Get status word for channel.
Definition: RPDDataAnalyzer.cxx:590
ZDC::RPDDataAnalyzer::setSideStatusBits
void setSideStatusBits()
Set side status bits according to channel status bits.
Definition: RPDDataAnalyzer.cxx:433
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
ZDC::RPDDataAnalyzer::m_chSumAdcCalib
std::array< float, s_nChannels > m_chSumAdcCalib
sum of RPD data in signal range after baseline and pileup subtraction; per channel
Definition: RPDDataAnalyzer.h:129
ZDCMsg::MessageFunctionPtr
std::shared_ptr< MessageFunction > MessageFunctionPtr
Definition: ZDCMsg.h:14
RPDDataAnalyzer.h
ZDC::RPDDataAnalyzer::PileupExpFitFailBit
@ PileupExpFitFailBit
Definition: RPDDataAnalyzer.h:51
ZDC::RPDDataAnalyzer::getChPileupExpFitParams
const std::vector< float > & getChPileupExpFitParams(unsigned int channel) const
Get parameters for pileup exponential fit (if pileup was detected and fit did not fail): exp( [0] + [...
Definition: RPDDataAnalyzer.cxx:548
ZDC::RPDDataAnalyzer::loadChannelData
void loadChannelData(unsigned int channel, const std::vector< uint16_t > &FadcData)
Load a single channel's FADC data into member variable.
Definition: RPDDataAnalyzer.cxx:70
ZDC::RPDDataAnalyzer::checkOverflow
bool checkOverflow(unsigned int channel)
Check for overflow and set relevant status bit.
Definition: RPDDataAnalyzer.cxx:123
ZDC::RPDDataAnalyzer::BadAvgBaselineSubtrBit
@ BadAvgBaselineSubtrBit
Definition: RPDDataAnalyzer.h:46
python.PyAthena.v
v
Definition: PyAthena.py:154
ZDC::RPDDataAnalyzer::s_nChannels
static unsigned constexpr int s_nChannels
Definition: RPDDataAnalyzer.h:108
ZDC::RPDDataAnalyzer::m_endSignalSample
unsigned int m_endSignalSample
Number of baseline samples; the sample equal to this number is the start of signal region.
Definition: RPDDataAnalyzer.h:113
ZDC::RPDDataAnalyzer::m_chExpPileupMSE
std::array< float, s_nChannels > m_chExpPileupMSE
pileup stretched exponential fit function (if pileup was detected and fit did not fail); per channel
Definition: RPDDataAnalyzer.h:141
ZDC::RPDDataAnalyzer::InsufficientPileupFitPointsBit
@ InsufficientPileupFitPointsBit
Definition: RPDDataAnalyzer.h:47
ZDC::RPDDataAnalyzer::doPileupStretchedExpFit
bool doPileupStretchedExpFit(unsigned int channel, std::vector< std::pair< unsigned int, float >> const &pileupFitPoints)
Perform a stretched exponential fit in baseline-subtracted baseline samples and set relevant status b...
Definition: RPDDataAnalyzer.cxx:227
y
#define y
ZDC::RPDDataAnalyzer::calculateSumAdc
void calculateSumAdc(unsigned int channel)
Calculate sum ADC and if there is pileup, calculate fractional pileup.
Definition: RPDDataAnalyzer.cxx:386
ZDC::RPDDataAnalyzer::m_chPileupFuncType
std::array< PileupFitFuncType, s_nChannels > m_chPileupFuncType
parameter errors for pileup stretched exponential fit (if pileup was detected and fit did not fail); ...
Definition: RPDDataAnalyzer.h:138
ZDC::RPDDataAnalyzer::getChSumAdcCalib
float getChSumAdcCalib(unsigned int channel) const
Get sum of RPD data in signal range after baseline and pileup subtraction, with output calibration fa...
Definition: RPDDataAnalyzer.cxx:509
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
ZDC::RPDDataAnalyzer::PileupBadExpSubtrBit
@ PileupBadExpSubtrBit
Definition: RPDDataAnalyzer.h:53
ZDC::RPDDataAnalyzer::PileupStretchedExpFitFailBit
@ PileupStretchedExpFitFailBit
Definition: RPDDataAnalyzer.h:48
ZDC::RPDDataAnalyzer::getChPileupExpFitParamErrs
const std::vector< float > & getChPileupExpFitParamErrs(unsigned int channel) const
Get parameter errors for pileup exponential fit (if pileup was detected and fit did not fail).
Definition: RPDDataAnalyzer.cxx:562
ZDC::RPDDataAnalyzer::m_chSumAdc
std::array< float, s_nChannels > m_chSumAdc
sample of max of RPD data in signal range after pileup subtraction; per channel
Definition: RPDDataAnalyzer.h:128
ZDC::helpResetFuncs
void helpResetFuncs(std::span< std::function< float(unsigned int)>> v)
Definition: RPDDataAnalyzer.cxx:17
ZDC
Definition: RPDAnalysisTool.cxx:12
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ZDC::RPDConfig
Definition: RPDDataAnalyzer.h:22
ZDC::RPDDataAnalyzer::m_chStatus
std::array< std::bitset< N_STATUS_BITS >, s_nChannels > m_chStatus
mean squared error of pileup stretched exponential fit in baseline samples (if pileup was detected an...
Definition: RPDDataAnalyzer.h:143
ZDC::RPDDataAnalyzer::PileupStretchedExpPulseLikeBit
@ PileupStretchedExpPulseLikeBit
Definition: RPDDataAnalyzer.h:54
ZDCMsg::Debug
@ Debug
Definition: ZDCMsg.h:19
ZDCMsg::Fatal
@ Fatal
Definition: ZDCMsg.h:23
ZDC::RPDDataAnalyzer::m_pileupBaselineStdDevThresh
float m_pileupBaselineStdDevThresh
Baseline sums less than this number indicate there is not pileup.
Definition: RPDDataAnalyzer.h:120
LArDigits2NtupleDumper.nSamples
nSamples
Definition: LArDigits2NtupleDumper.py:70
merge.status
status
Definition: merge.py:17
ZDC::RPDDataAnalyzer::PileupStretchedExpGrowthBit
@ PileupStretchedExpGrowthBit
Definition: RPDDataAnalyzer.h:49
calibdata.copy
bool copy
Definition: calibdata.py:27
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
ZDC::RPDDataAnalyzer::m_nSamples
unsigned int m_nSamples
Definition: RPDDataAnalyzer.h:111
ZDC::RPDDataAnalyzer::m_chMaxSample
std::array< unsigned int, s_nChannels > m_chMaxSample
RPD data with baseline and pileup subtracted; index channel then sample.
Definition: RPDDataAnalyzer.h:127
ZDC::RPDDataAnalyzer::m_chPileupStretchedExpFitParamErrs
std::array< std::vector< float >, s_nChannels > m_chPileupStretchedExpFitParamErrs
parameter errors for pileup exponential fit (if pileup was detected and fit did not fail); per channe...
Definition: RPDDataAnalyzer.h:137
ZDC::nullPileupFunc
unsigned int nullPileupFunc(unsigned int)
Definition: RPDDataAnalyzer.cxx:13
ZDC::RPDDataAnalyzer::PileupFitFuncType::None
@ None
ZDC::RPDDataAnalyzer::m_chBaseline
std::array< float, s_nChannels > m_chBaseline
OOT pileup sum as a fraction of non-pileup sum in entire window (0 if no OOT pileup,...
Definition: RPDDataAnalyzer.h:133
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
ZDC::RPDDataAnalyzer::OutOfTimePileupBit
@ OutOfTimePileupBit
Definition: RPDDataAnalyzer.h:41
ZDC::RPDDataAnalyzer::m_pulse2ndDerivThresh
float m_pulse2ndDerivThresh
Samples before (not including) this sample are the signal region; nSamples goes to end of window.
Definition: RPDDataAnalyzer.h:114
readCCLHist.float
float
Definition: readCCLHist.py:83
ZDC::RPDDataAnalyzer::m_chMaxAdc
std::array< float, s_nChannels > m_chMaxAdc
sum of RPD data in signal range after baseline and pileup subtraction, with output calibration factor...
Definition: RPDDataAnalyzer.h:130
LArMonTransforms.Mean
def Mean(inputs)
Definition: LArMonTransforms.py:438
RPDUtils::helpZero
void helpZero(Range &v) requires(std
Definition: RPDUtils.h:27
TRTCalib_cfilter.p0
p0
Definition: TRTCalib_cfilter.py:129
ZDC::RPDDataAnalyzer::getChMaxAdc
float getChMaxAdc(unsigned int channel) const
Get max of RPD data in signal range after baseline and pileup subtraction.
Definition: RPDDataAnalyzer.cxx:517
ZDC::RPDDataAnalyzer::PileupFitFuncType::SecondOrderStretchedExp
@ SecondOrderStretchedExp