|
ATLAS Offline Software
|
Go to the documentation of this file.
7 #include "TLinearFitter.h"
25 std::vector<float>
const& calibFactors
26 ) : m_msgFunc_p(std::move(messageFunc_p)),
27 m_tag(std::move(
tag)),
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)
44 "RPDDataAnalyzer::RPDDataAnalyzer: received incorrect number of channels in calibration factors ("
74 "RPDDataAnalyzer::loadChannelData: received incorrect number of samples "
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 auto pFitter = std::make_unique<TLinearFitter>(1,
"1 ++ x");
200 for (
auto const& [
sample,
y] : pileupFitPoints) {
204 if (pFitter->Eval()) {
205 (*m_msgFunc_p)(
ZDCMsg::Warn,
"RPDDataAnalyzer::doPileupExpFit: there was an error while evaluating TLinearFitter!");
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!");
229 auto pFitter = std::make_unique<TLinearFitter>(1,
"1 ++ (x + 4)**(0.5) ++ (x + 4)**(-0.5)");
231 for (
auto const& [
sample,
y] : pileupFitPoints) {
235 if (pFitter->Eval()) {
236 (*m_msgFunc_p)(
ZDCMsg::Warn,
"RPDDataAnalyzer::doPileupStretchedExpFit: there was an error while evaluating TLinearFitter!");
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));};
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!");
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)");
270 unsigned int nNegatives = 0;
282 float nominalBaselineSubtrSum = 0;
284 std::vector<std::pair<unsigned int, float>> pileupFitPoints;
288 nominalBaselineSubtrSum += adcBaselineSubtr;
289 if (adcBaselineSubtr > 0) {
291 pileupFitPoints.emplace_back(
sample, adcBaselineSubtr);
328 if (stretchedExpFitSuccess) {
369 float maxAdc = -std::numeric_limits<float>::infinity();
370 unsigned int maxSample = 0;
393 float signalRangeAdcSum = 0;
403 std::function<
float(
unsigned int)> pileupFunc;
415 float totalAdcSum = 0;
416 float pileupTotalAdcSum = 0;
419 pileupTotalAdcSum += pileupFunc(
sample);
421 if (totalAdcSum > 0) {
600 return static_cast<unsigned int>(
m_sideStatus.to_ulong());
unsigned int m_nChannelsLoaded
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
unsigned int m_nBaselineSamples
std::array< std::vector< float >, s_nChannels > m_chCorrectedFadcData
raw RPD data; index channel then sample
unsigned int getChMaxSample(unsigned int channel) const
Get sample of max of RPD data in signal range after pileup subtraction.
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
float m_nominalBaseline
Pulses after this sample are considered post-pulses.
unsigned int m_goodPulseSampleStop
Pulses before this sample are considered pre-pulses.
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...
@ PileupBadStretchedExpSubtrBit
bool doBaselinePileupSubtraction(unsigned int channel)
Determine if there is pileup, subtract baseline and pileup, and set relevant status bits.
void analyzeData()
Analyze RPD data.
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( [...
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 getChBaseline(unsigned int channel) const
Get baseline used in baseline subtraction.
std::array< float, s_nChannels > m_chMaxAdcCalib
max of RPD data in signal range after baseline and pileup subtraction; per channel
float getChPileupExpFitMSE(unsigned int channel) const
Get mean squared error of pileup exponential fit in baseline samples (if pileup was detected and fit ...
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.
bool checkPulses(unsigned int channel)
Calculate 2nd difference, identify pulses, and set relevant status bits.
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
void calculateMaxSampleMaxAdc(unsigned int channel)
Calculate max ADC and max sample.
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...
float getChPileupStretchedExpFitMSE(unsigned int channel) const
Get mean squared error of pileup stretched exponential fit in baseline samples (if pileup was detecte...
float getChSumAdc(unsigned int channel) const
Get sum of RPD data in signal range after baseline and pileup subtraction.
unsigned int m_AdcOverflow
Maximum number of negative ADC values after baseline and pileup subtraction allowed in signal range.
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...
RPDDataAnalyzer(ZDCMsg::MessageFunctionPtr messageFunc_p, std::string tag, RPDConfig const &config, std::vector< float > const &calibFactors)
std::array< std::vector< float >, s_nChannels > 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...
void reset()
Reset all member variables to default values.
std::bitset< N_STATUS_BITS > m_sideStatus
status bits per channel
static unsigned constexpr int s_minPileupFitPoints
status bits for side
float m_pileupBaselineSumThresh
The global nominal baseline; used when pileup is detected.
std::array< std::function< float(unsigned int)>, s_nChannels > m_chExpPileupFuncs
enum indicating type of pileup fit function; per channel
float m_postPulseFracThresh
Second differences less than or equal to this number indicate a pulse.
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_ch2ndOrderStretchedExpPileupMSE
mean squared error of pileup exponential fit in baseline samples (if pileup was detected and fit did ...
std::array< float, s_nChannels > m_outputCalibFactors
ADC values greater than or equal to this number are considered overflow.
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,...
unsigned int getSideStatus() const
Get status word for side.
std::array< float, s_nChannels > m_chPileupFrac
max of RPD data in signal range after baseline and pileup subtraction, with output calibration factor...
void fill(H5::Group &out_file, size_t iterations)
unsigned int countSignalRangeNegatives(std::vector< float > const &values) const
Calculate the number of negative values in signal range.
unsigned int getChStatus(unsigned int channel) const
Get status word for channel.
void setSideStatusBits()
Set side status bits according to channel status bits.
std::string to_string(const DetectorType &type)
std::array< float, s_nChannels > m_chSumAdcCalib
sum of RPD data in signal range after baseline and pileup subtraction; per channel
std::shared_ptr< MessageFunction > MessageFunctionPtr
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] + [...
void loadChannelData(unsigned int channel, const std::vector< uint16_t > &FadcData)
Load a single channel's FADC data into member variable.
bool checkOverflow(unsigned int channel)
Check for overflow and set relevant status bit.
static unsigned constexpr int s_nChannels
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_chExpPileupMSE
pileup stretched exponential fit function (if pileup was detected and fit did not fail); per channel
@ InsufficientPileupFitPointsBit
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...
void calculateSumAdc(unsigned int channel)
Calculate sum ADC and if there is pileup, calculate fractional pileup.
std::array< PileupFitFuncType, s_nChannels > m_chPileupFuncType
parameter errors for pileup stretched exponential fit (if pileup was detected and fit did not fail); ...
float getChSumAdcCalib(unsigned int channel) const
Get sum of RPD data in signal range after baseline and pileup subtraction, with output calibration fa...
@ PileupStretchedExpFitFailBit
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).
std::array< float, s_nChannels > m_chSumAdc
sample of max of RPD data in signal range after pileup subtraction; per channel
void helpResetFuncs(std::span< std::function< float(unsigned int)>> v)
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...
@ PileupStretchedExpPulseLikeBit
float m_pileupBaselineStdDevThresh
Baseline sums less than this number indicate there is not pileup.
@ PileupStretchedExpGrowthBit
std::array< unsigned int, s_nChannels > m_chMaxSample
RPD data with baseline and pileup subtracted; index channel then sample.
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...
unsigned int nullPileupFunc(unsigned int)
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,...
constexpr int pow(int base, int exp) noexcept
float m_pulse2ndDerivThresh
Samples before (not including) this sample are the signal region; nSamples goes to end of window.
std::array< float, s_nChannels > m_chMaxAdc
sum of RPD data in signal range after baseline and pileup subtraction, with output calibration factor...
void helpZero(Range &v) requires(std
float getChMaxAdc(unsigned int channel) const
Get max of RPD data in signal range after baseline and pileup subtraction.
@ SecondOrderStretchedExp