ATLAS Offline Software
Loading...
Searching...
No Matches
RPDDataAnalyzer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ZDCANALYSIS_RPDDATAANALYZER_H
6#define ZDCANALYSIS_RPDDATAANALYZER_H
7
8#include <string>
9#include <vector>
10#include <functional>
11#include <bitset>
12
13#include "ZdcAnalysis/ZDCMsg.h"
14#include "ZdcUtils/RPDUtils.h"
15
16
17namespace ZDC {
18
33
35 public:
36 enum {
37 ValidBit = 0, // analysis and output are valid
38 OutOfTimePileupBit = 1, // OOT detected, pileup subtraction attempted
39 OverflowBit = 2, // overflow detected => invalid
40 PrePulseBit = 3, // pulse detected before expected range => invalid
41 PostPulseBit = 4, // pulse detected after expected range => invalid
42 NoPulseBit = 5, // no pulse detected => invalid
43 BadAvgBaselineSubtrBit = 6, // subtraction of avg. of baseline samples yielded too many negatives => invalid
44 InsufficientPileupFitPointsBit = 7, // baseline samples indicate pileup, but there are not enough points to perform fit -> nominal baseline used without pileup subtraction
45 PileupStretchedExpFitFailBit = 8, // fit to stretched exponential failed -> fallback to exponential fit
46 PileupStretchedExpGrowthBit = 9, // fit to stretched exponential does not decay -> fallback to exponential fit
47 PileupBadStretchedExpSubtrBit = 10, // subtraction of stretched exponential fit yielded too many negatives -> fallback to exponential fit
48 PileupExpFitFailBit = 11, // fit to exponential failed => invalid IF stretched exponential fit is also bad
49 PileupExpGrowthBit = 12, // fit to exponential does not decay => invalid IF stretched exponential fit is also bad
50 PileupBadExpSubtrBit = 13, // subtraction of stretched exponential yielded too many negatives => invalid IF stretched exponential fit is also bad
51 PileupStretchedExpPulseLikeBit = 14, // fit to stretched exponential probably looks more like a pulse than pileup
53 };
57
58 RPDDataAnalyzer(ZDCMsg::MessageFunctionPtr messageFunc_p, std::string tag, RPDConfig const& config, std::vector<float> const& calibFactors);
59 virtual ~RPDDataAnalyzer() = default;
60 // this class is not intended to be copied or moved
65
66 void loadChannelData(unsigned int channel, const std::vector<uint16_t>& FadcData);
67 void analyzeData();
68
69 unsigned int getChMaxSample(unsigned int channel) const;
70 float getChSumAdc(unsigned int channel) const;
71 float getChSumAdcCalib(unsigned int channel) const;
72 float getChMaxAdc(unsigned int channel) const;
73 float getChMaxAdcCalib(unsigned int channel) const;
74 float getChPileupFrac(unsigned int channel) const;
75 float getChBaseline(unsigned int channel) const;
76 const std::vector<float>& getChPileupExpFitParams(unsigned int channel) const;
77 const std::vector<float>& getChPileupStretchedExpFitParams(unsigned int channel) const;
78 const std::vector<float>& getChPileupExpFitParamErrs(unsigned int channel) const;
79 const std::vector<float>& getChPileupStretchedExpFitParamErrs(unsigned int channel) const;
80 float getChPileupExpFitMSE(unsigned int channel) const;
81 float getChPileupStretchedExpFitMSE(unsigned int channel) const;
82
83 unsigned int getChStatus(unsigned int channel) const;
84 unsigned int getSideStatus() const;
85
86 void reset();
87
88 private:
89 bool checkOverflow(unsigned int channel);
90 bool checkPulses(unsigned int channel);
91 unsigned int countSignalRangeNegatives(std::vector<float> const& values) const;
92 bool doBaselinePileupSubtraction(unsigned int channel);
93 void calculateMaxSampleMaxAdc(unsigned int channel);
94 void calculateSumAdc(unsigned int channel);
95
96 void setSideStatusBits();
97
98 bool doPileupExpFit(unsigned int channel, std::vector<std::pair<unsigned int, float>> const& pileupFitPoints);
99 bool doPileupStretchedExpFit(unsigned int channel, std::vector<std::pair<unsigned int, float>> const& pileupFitPoints);
100 float calculateBaselineSamplesMSE(unsigned int channel, std::function<float(unsigned int)> const& fit) const;
101
103 std::string m_tag;
104
105 static unsigned int constexpr s_nChannels = RPDUtils::nChannels; // for convenience
106
107 unsigned int m_nChannelsLoaded = 0;
108 unsigned int m_nSamples;
109 unsigned int m_nBaselineSamples;
110 unsigned int m_endSignalSample;
118 unsigned int m_nNegativesAllowed;
119 unsigned int m_AdcOverflow;
120 std::array<float, s_nChannels> m_outputCalibFactors {};
121
122 std::array<std::vector<uint16_t>, s_nChannels> m_chFADCData;
123 std::array<std::vector<float>, s_nChannels> m_chCorrectedFadcData;
124 std::array<unsigned int, s_nChannels> m_chMaxSample {};
125 std::array<float, s_nChannels> m_chSumAdc {};
126 std::array<float, s_nChannels> m_chSumAdcCalib {};
127 std::array<float, s_nChannels> m_chMaxAdc {};
128 std::array<float, s_nChannels> m_chMaxAdcCalib {};
129 std::array<float, s_nChannels> m_chPileupFrac {};
130 std::array<float, s_nChannels> m_chBaseline {};
131 std::array<std::vector<float>, s_nChannels> m_chPileupExpFitParams;
132 std::array<std::vector<float>, s_nChannels> m_chPileupStretchedExpFitParams;
133 std::array<std::vector<float>, s_nChannels> m_chPileupExpFitParamErrs;
134 std::array<std::vector<float>, s_nChannels> m_chPileupStretchedExpFitParamErrs;
135 std::array<PileupFitFuncType, s_nChannels> m_chPileupFuncType {};
136 std::array<std::function<float(unsigned int)>, s_nChannels> m_chExpPileupFuncs;
137 std::array<std::function<float(unsigned int)>, s_nChannels> m_ch2ndOrderStretchedExpPileupFuncs;
138 std::array<float, s_nChannels> m_chExpPileupMSE {};
139 std::array<float, s_nChannels> m_ch2ndOrderStretchedExpPileupMSE {};
140 std::array<std::bitset<N_STATUS_BITS>, s_nChannels> m_chStatus;
141 std::bitset<N_STATUS_BITS> m_sideStatus;
142
149 static unsigned int constexpr s_minPileupFitPoints = 3;
150};
151
152} // namespace ZDC
153
154#endif
float m_pulse2ndDerivThresh
Samples before (not including) this sample are the signal region; nSamples goes to end of window.
unsigned int m_goodPulseSampleStop
Pulses before this sample are considered pre-pulses.
unsigned int m_nBaselineSamples
void reset()
Reset all member variables to default values.
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,...
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...
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] + [...
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...
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,...
std::array< float, s_nChannels > m_chSumAdc
sample of max of RPD data in signal range after pileup subtraction; per channel
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...
std::array< float, s_nChannels > m_ch2ndOrderStretchedExpPileupMSE
mean squared error of pileup exponential fit in baseline samples (if pileup was detected and fit did ...
std::array< float, s_nChannels > m_chSumAdcCalib
sum of RPD data in signal range after baseline and pileup subtraction; per channel
RPDDataAnalyzer(RPDDataAnalyzer &&)=delete
bool checkPulses(unsigned int channel)
Calculate 2nd difference, identify pulses, and set relevant status bits.
float m_pileupBaselineSumThresh
The global nominal baseline; used when pileup is detected.
std::array< float, s_nChannels > m_outputCalibFactors
ADC values greater than or equal to this number are considered overflow.
void analyzeData()
Analyze RPD data.
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...
std::array< std::vector< float >, s_nChannels > m_chCorrectedFadcData
raw RPD data; index channel then sample
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...
float getChMaxAdcCalib(unsigned int channel) const
Get max of RPD data in signal range after baseline and pileup subtraction, with output calibration fa...
bool doBaselinePileupSubtraction(unsigned int channel)
Determine if there is pileup, subtract baseline and pileup, and set relevant status bits.
bool checkOverflow(unsigned int channel)
Check for overflow and set relevant status bit.
unsigned int getChMaxSample(unsigned int channel) const
Get sample of max of RPD data in signal range after pileup subtraction.
float m_nominalBaseline
Pulses after this sample are considered post-pulses.
std::array< float, s_nChannels > m_chPileupFrac
max of RPD data in signal range after baseline and pileup subtraction, with output calibration factor...
unsigned int countSignalRangeNegatives(std::vector< float > const &values) const
Calculate the number of negative values in signal range.
ZDCMsg::MessageFunctionPtr m_msgFunc_p
void calculateMaxSampleMaxAdc(unsigned int channel)
Calculate max ADC and max sample.
float getChPileupStretchedExpFitMSE(unsigned int channel) const
Get mean squared error of pileup stretched exponential fit in baseline samples (if pileup was detecte...
static unsigned int constexpr s_minPileupFitPoints
status bits for side
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.
virtual ~RPDDataAnalyzer()=default
void calculateSumAdc(unsigned int channel)
Calculate sum ADC and if there is pileup, calculate fractional pileup.
std::bitset< N_STATUS_BITS > m_sideStatus
status bits per channel
RPDDataAnalyzer(RPDDataAnalyzer const &)=delete
std::array< float, s_nChannels > m_chMaxAdcCalib
max of RPD data in signal range after baseline and pileup subtraction; per channel
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.
std::array< float, s_nChannels > m_chExpPileupMSE
pileup stretched exponential fit function (if pileup was detected and fit did not fail); per channel
unsigned int m_nChannelsLoaded
void loadChannelData(unsigned int channel, const std::vector< uint16_t > &FadcData)
Load a single channel's FADC data into member variable.
unsigned int getSideStatus() const
Get status word for side.
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...
float getChPileupExpFitMSE(unsigned int channel) const
Get mean squared error of pileup exponential fit in baseline samples (if pileup was detected and fit ...
float getChMaxAdc(unsigned int channel) const
Get max of RPD data in signal range after baseline and pileup subtraction.
std::array< std::vector< float >, s_nChannels > m_chPileupExpFitParams
baseline used in baseline subtraction; per channel
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).
RPDDataAnalyzer & operator=(RPDDataAnalyzer &&)=delete
unsigned int m_endSignalSample
Number of baseline samples; the sample equal to this number is the start of signal region.
std::array< float, s_nChannels > m_chMaxAdc
sum of RPD data in signal range after baseline and pileup subtraction, with output calibration factor...
unsigned int m_nNegativesAllowed
Baseline standard deviations less than this number indicate there is not pileup.
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
RPDDataAnalyzer(ZDCMsg::MessageFunctionPtr messageFunc_p, std::string tag, RPDConfig const &config, std::vector< float > const &calibFactors)
void setSideStatusBits()
Set side status bits according to channel status bits.
float m_pileupBaselineStdDevThresh
Baseline sums less than this number indicate there is not pileup.
static unsigned int constexpr s_nChannels
float getChSumAdcCalib(unsigned int channel) const
Get sum of RPD data in signal range after baseline and pileup subtraction, with output calibration fa...
unsigned int m_AdcOverflow
Maximum number of negative ADC values after baseline and pileup subtraction allowed in signal range.
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( [...
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
unsigned int getChStatus(unsigned int channel) const
Get status word for channel.
float getChSumAdc(unsigned int channel) const
Get sum of RPD data in signal range after baseline and pileup subtraction.
std::array< unsigned int, s_nChannels > m_chMaxSample
RPD data with baseline and pileup subtracted; index channel then sample.
RPDDataAnalyzer & operator=(RPDDataAnalyzer const &)=delete
float getChBaseline(unsigned int channel) const
Get baseline used in baseline subtraction.
float m_postPulseFracThresh
Second differences less than or equal to this number indicate a pulse.
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...
std::array< std::function< float(unsigned int)>, s_nChannels > m_chExpPileupFuncs
enum indicating type of pileup fit function; per channel
std::array< PileupFitFuncType, s_nChannels > m_chPileupFuncType
parameter errors for pileup stretched exponential fit (if pileup was detected and fit did not fail); ...
unsigned int constexpr nChannels
Definition RPDUtils.h:23
std::shared_ptr< MessageFunction > MessageFunctionPtr
Definition ZDCMsg.h:14
unsigned int goodPulseSampleStop
unsigned int nBaselineSamples
unsigned int endSignalSample
float pileupBaselineStdDevThresh
unsigned int nSamples
unsigned int nNegativesAllowed
unsigned int ADCOverflow
unsigned int goodPulseSampleStart
float pileupBaselineSumThresh