![Logo](../../ATLAS-Logo-Square-Blue-RGB.png) |
ATLAS Offline Software
|
Go to the documentation of this file.
3 #include "TLinearFitter.h"
7 const auto zeroVector = [](std::vector<float>&
v){
v.assign(
v.size(), 0); };
8 const auto zeroVectorVector = [](std::vector<std::vector<float>>&
vv){
for (std::vector<float>&
v :
vv)
v.assign(
v.size(), 0); };
15 m_msgFunc_p(std::move(messageFunc_p)),
18 m_nColumns(
config.nColumns),
19 m_nChannels(m_nRows*m_nColumns),
21 m_nBaselineSamples(
config.nBaselineSamples),
22 m_endSignalSample(
config.endSignalSample),
23 m_pulse2ndDerivThresh(
config.pulse2ndDerivThresh),
24 m_postPulseFracThresh(
config.postPulseFracThresh),
25 m_goodPulseSampleStart(
config.goodPulseSampleStart),
26 m_goodPulseSampleStop(
config.goodPulseSampleStop),
27 m_nominalBaseline(
config.nominalBaseline),
28 m_pileupBaselineSumThresh(
config.pileupBaselineSumThresh),
29 m_pileupBaselineStdDevThresh(
config.pileupBaselineStdDevThresh),
30 m_nNegativesAllowed(
config.nNegativesAllowed),
31 m_AdcOverflow(
config.AdcOverflow),
32 m_outputCalibFactors(calibFactors),
33 m_chFadcData(m_nChannels, std::
vector<
float>(m_nSamples, 0)),
34 m_chCorrectedFadcData(m_nChannels, std::
vector<
float>(m_nSamples, 0)),
35 m_chMaxSample(m_nChannels, 0),
36 m_chSumAdc(m_nChannels, 0),
37 m_chSumAdcCalib(m_nChannels, 0),
38 m_chMaxAdc(m_nChannels, 0),
39 m_chMaxAdcCalib(m_nChannels, 0),
40 m_chPileupFrac(m_nChannels, 0),
41 m_chBaseline(m_nChannels, 0),
42 m_chPileupExpFitParams(m_nChannels, std::
vector<
float>(2, 0)),
43 m_chPileupStretchedExpFitParams(m_nChannels, std::
vector<
float>(3, 0)),
44 m_chPileupExpFitParamErrs(m_nChannels, std::
vector<
float>(2, 0)),
45 m_chPileupStretchedExpFitParamErrs(m_nChannels, std::
vector<
float>(3, 0)),
46 m_chPileupFuncType(m_nChannels, false),
49 m_chExpPileupMSE(m_nChannels, 0),
50 m_ch2ndOrderStretchedExpPileupMSE(m_nChannels, 0),
51 m_chStatus(m_nChannels)
56 "RPDDataAnalyzer::RPDDataAnalyzer: received incorrect number of channels in calibration factors ("
74 (*m_msgFunc_p)(
ZDCMsg::Fatal,
"RPDDataAnalyzer::loadChannelData: received incorrect number of samples in FADC data");
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;
150 prePulseSize = secondDiff;
153 goodPulseSize = secondDiff;
156 postPulseSize = secondDiff;
161 bool hasPrePulse = prePulseSample;
162 bool hasGoodPulse = goodPulseSample;
163 bool hasPostPulse = postPulseSample;
168 if (hasGoodPulse && hasPostPulse && postPulseSize/goodPulseSize <=
m_postPulseFracThresh) hasPostPulse =
false;
170 bool hasNoPulse = !hasPrePulse && !hasGoodPulse && !hasPostPulse;
176 return !hasPrePulse && !hasPostPulse;
198 TLinearFitter
fitter(1,
"1 ++ x");
200 for (
auto const& [
sample,
y] : pileupFitPoints) {
205 (*m_msgFunc_p)(
ZDCMsg::Warn,
"RPDDataAnalyzer::doPileupExpFit: there was an error while evaluating TLinearFitter!");
215 if (
fitter.GetParameter(1) >= 0) {
216 (*m_msgFunc_p)(
ZDCMsg::Debug,
"RPDDataAnalyzer::doPileupExpFit: p1 is " +
std::to_string(
fitter.GetParameter(1)) +
" > 0 -> there is exponential growth in fit function!");
229 TLinearFitter
fitter(1,
"1 ++ (x + 4)**(0.5) ++ (x + 4)**(-0.5)");
231 for (
auto const& [
sample,
y] : pileupFitPoints) {
236 (*m_msgFunc_p)(
ZDCMsg::Warn,
"RPDDataAnalyzer::doPileupStretchedExpFit: there was an error while evaluating TLinearFitter!");
248 if (
fitter.GetParameter(1) >= 0) {
249 (*m_msgFunc_p)(
ZDCMsg::Debug,
"RPDDataAnalyzer::doPileupStretchedExpFit: p1 is " +
std::to_string(
fitter.GetParameter(1)) +
" > 0 -> there is exponential growth in fit function!");
253 if (
fitter.GetParameter(2)/
fitter.GetParameter(1) - 4 > 0) {
254 (*m_msgFunc_p)(
ZDCMsg::Debug,
"RPDDataAnalyzer::doPileupStretchedExpFit: 1st deriv max occurs at sample " +
std::to_string(
fitter.GetParameter(1)) +
" > 0 -> fit probably looks like a pulse (and not like pileup)");
266 unsigned int nNegatives = 0;
278 float nominalBaselineSubtrSum = 0;
280 std::vector<std::pair<unsigned int, float>> pileupFitPoints;
284 nominalBaselineSubtrSum += adcBaselineSubtr;
285 if (adcBaselineSubtr > 0) {
287 pileupFitPoints.emplace_back(
sample, adcBaselineSubtr);
324 if (stretchedExpFitSuccess) {
364 float maxAdc = -std::numeric_limits<float>::infinity();
365 unsigned int maxSample = 0;
388 float signalRangeAdcSum = 0;
398 std::function<
float(
unsigned int)> pileupFunc;
407 float totalAdcSum = 0;
408 float pileupTotalAdcSum = 0;
411 pileupTotalAdcSum += pileupFunc(
sample);
413 if (totalAdcSum > 0) {
592 return static_cast<unsigned int>(
m_sideStatus.to_ulong());
void analyzeData()
Analyze RPD data.
const ShapeFitter * fitter
std::vector< std::vector< float > > m_chPileupStretchedExpFitParamErrs
parameter errors for pileup exponential fit (if pileup was detected and fit did not fail); per channe...
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...
@ PileupStretchedExpPulseLikeBit
std::vector< float > m_chSumAdc
sample of max of RPD data in signal range after pileup subtraction; per channel
@ InsufficientPileupFitPointsBit
float getChMaxAdc(unsigned int channel) const
Get max of RPD data in signal range after baseline and pileup subtraction.
std::vector< float > m_chMaxAdcCalib
max of RPD data in signal range after baseline and pileup subtraction; per channel
float m_pileupBaselineSumThresh
The global nominal baseline; used when pileup is detected.
unsigned int m_nNegativesAllowed
Baseline standard deviations less than this number indicate there is not pileup.
std::vector< std::vector< float > > m_chPileupStretchedExpFitParams
parameters for pileup exponential fit (if pileup was detected and fit did not fail): exp( [0] + [1]*s...
void calculateMaxSampleMaxAdc(unsigned int channel)
Calculate max ADC and max sample.
unsigned int getChStatus(unsigned int channel) const
Get status word for channel.
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...
std::vector< float > m_chSumAdcCalib
sum of RPD data in signal range after baseline and pileup subtraction; per channel
std::vector< float > m_chBaseline
OOT pileup sum as a fraction of non-pileup sum in entire window (0 if no OOT pileup,...
void reset()
Reset all member variables to default values.
std::bitset< 32 > m_sideStatus
status bits per channel
std::vector< float > m_outputCalibFactors
ADC values greater than or equal to this number are considered overflow.
std::vector< std::vector< float > > m_chPileupExpFitParams
baseline used in baseline subtraction; per channel
float getChMaxAdcCalib(unsigned int channel) const
Get max of RPD data in signal range after baseline and pileup subtraction, with output calibration fa...
unsigned int getChMaxSample(unsigned int channel) const
Get sample of max of RPD data in signal range after pileup subtraction.
std::vector< float > 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.
float getChSumAdc(unsigned int channel) const
Get sum of RPD data in signal range after baseline and pileup subtraction.
RPDDataAnalyzer(ZDCMsg::MessageFunctionPtr messageFunc_p, const std::string &tag, const RPDConfig &config, std::vector< float > const &calibFactors)
float getChSumAdcCalib(unsigned int channel) const
Get sum of RPD data in signal range after baseline and pileup subtraction, with output calibration fa...
void loadChannelData(unsigned int channel, const std::vector< uint16_t > &FadcData)
Load a single channel's FADC data into member variable.
std::vector< std::vector< float > > m_chCorrectedFadcData
raw RPD data; index channel then sample
@ PileupStretchedExpGrowthBit
const auto zeroPileupFuncVector
unsigned int m_AdcOverflow
Maximum number of negative ADC values after baseline and pileup subtraction allowed in signal range.
float getChPileupStretchedExpFitMSE(unsigned int channel) const
Get mean squared error of pileup stretched exponential fit in baseline samples (if pileup was detecte...
std::vector< float > m_chExpPileupMSE
pileup stretched exponential fit function (if pileup was detected and fit did not fail); per channel
std::vector< float > m_chMaxAdc
sum of RPD data in signal range after baseline and pileup subtraction, with output calibration factor...
void calculateSumAdc(unsigned int channel)
Calculate sum ADC and if there is pileup, calculate fractional pileup.
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.
std::vector< float > m_ch2ndOrderStretchedExpPileupMSE
mean squared error of pileup exponential fit in baseline samples (if pileup was detected and fit did ...
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).
const auto zeroPileupFunc
std::vector< bool > m_chPileupFuncType
parameter errors for pileup stretched exponential fit (if pileup was detected and fit did not fail); ...
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...
unsigned int m_goodPulseSampleStop
Pulses before this sample are considered pre-pulses.
float getChPileupExpFitMSE(unsigned int channel) const
Get mean squared error of pileup exponential fit in baseline samples (if pileup was detected and fit ...
void setSideStatusBits()
Set side status bits according to channel status bits.
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...
unsigned int m_nChannelsLoaded
bool checkOverflow(unsigned int channel)
Check for overflow and set relevant status bit.
@ PileupStretchedExpFitFailBit
const auto zeroVectorVector
unsigned int m_endSignalSample
Number of baseline samples; the sample equal to this number is the start of signal region.
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] + [...
std::vector< std::vector< float > > m_chPileupExpFitParamErrs
parameters for pileup stretched exponential fit (if pileup was detected and fit did not fail): exp( [...
float m_postPulseFracThresh
Second differences less than or equal to this number indicate a pulse.
std::string to_string(const DetectorType &type)
std::vector< std::function< float(unsigned int)> > m_ch2ndOrderStretchedExpPileupFuncs
pileup exponential fit function (if pileup was detected and fit did not fail); per channel
std::shared_ptr< MessageFunction > MessageFunctionPtr
float m_pulse2ndDerivThresh
Samples before (not including) this sample are the signal region; nSamples goes to end of window.
std::vector< std::bitset< 32 > > m_chStatus
mean squared error of pileup stretched exponential fit in baseline samples (if pileup was detected an...
unsigned int getSideStatus() const
Get status word for side.
bool doBaselinePileupSubtraction(unsigned int channel)
Determine if there is pileup, subtract baseline and pileup, and set relevant status bits.
float m_pileupBaselineStdDevThresh
Baseline sums less than this number indicate there is not pileup.
std::vector< float > m_chMaxSample
RPD data with baseline and pileup subtracted; index channel then sample.
unsigned int m_nominalBaseline
Pulses after this sample are considered post-pulses.
std::vector< std::vector< float > > m_chFadcData
multiplicative calibration factors to apply to output, e.g., max and sum ADC; per channel
static unsigned constexpr int s_minPileupFitPoints
status bits for side
unsigned int m_nBaselineSamples
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,...
bool checkPulses(unsigned int channel)
Calculate 2nd difference, identify pulses, and set relevant status bits.
float getChBaseline(unsigned int channel) const
Get baseline used in baseline subtraction.
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::vector< std::function< float(unsigned int)> > m_chExpPileupFuncs
true when stretched exponential is used, false if exponential is used for pileup subtraction (if pile...
@ PileupBadStretchedExpSubtrBit