From 7d102a26041af65e58889340ce198224a04c7b8f Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Fri, 20 Feb 2026 18:17:05 +0100 Subject: [PATCH] move DeadTimeCorrection to PRunBase. Make ADDRUN part in PrepareData more readable. --- src/classes/PRunBase.cpp | 49 +++++++++++++++++++++++++++++++++ src/classes/PRunSingleHisto.cpp | 22 ++++++++++++--- src/include/PRunBase.h | 8 ++++++ 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/classes/PRunBase.cpp b/src/classes/PRunBase.cpp index 60191ac8e..ece1090cd 100644 --- a/src/classes/PRunBase.cpp +++ b/src/classes/PRunBase.cpp @@ -159,6 +159,55 @@ PRunBase::~PRunBase() fFuncValues.clear(); } +//-------------------------------------------------------------------------- +// DeadTimeCorrection (protected) +//-------------------------------------------------------------------------- +/** + * \brief carry out dead time correction + * + * \param histos histograms to be corrected + * \param histoNo histogram numbers + */ +void PRunBase::DeadTimeCorrection(std::vector &histos, PUIntVector &histoNo) +{ + PRawRunData* runData = fRawData->GetRunData(*fRunInfo->GetRunName()); + + if (!runData->DeadTimeCorrectionReady()) + return; + + + // check if a dead time correction has to be done + // first check the global block + TString dtcg = fMsrInfo->GetMsrGlobal()->GetDeadTimeCorrection(); + Int_t dtcg_tag = 0; // 0=no, 1=file, 2=estimate + if (dtcg.Contains("file", TString::kIgnoreCase)) { + dtcg_tag = 1; + } else if (dtcg.Contains("estimate", TString::kIgnoreCase)) { + dtcg_tag = 2; + } + // now check each run + TString dtcr{"no"}; + Bool_t needToCheck{true}; + for (UInt_t i=0; iGetDeadTimeCorrection(); + if (dtcr.Contains("file", TString::kIgnoreCase) || (dtcg_tag != 0)) { + if (runData->DeadTimeCorrectionReady()) { + needToCheck = false; + // Dead time correction: n_true = n_obs / (1 - n_obs * t_dt / (good_frames * dt)) + Double_t n_true; + Int_t gf = runData->GetNumberOfGoodFrames(); + std::vector t_dt = runData->GetDeadTimeParam(); + for (UInt_t j=0; j run: deadtime correction: " << dtcr.Data() << ", global: " << dtcg_tag << std::endl; + } + } +} //-------------------------------------------------------------------------- // SetFitRange (public) diff --git a/src/classes/PRunSingleHisto.cpp b/src/classes/PRunSingleHisto.cpp index 3bf6271f8..ebe601ea6 100644 --- a/src/classes/PRunSingleHisto.cpp +++ b/src/classes/PRunSingleHisto.cpp @@ -1069,10 +1069,16 @@ Bool_t PRunSingleHisto::PrepareData() forward[i] = *runData->GetDataBin(histoNo[i]); } + // check if a dead time correction has to be done + // this will be done automatically in the function itself, which also + // checks in the global and run section + DeadTimeCorrection(forward, histoNo); + // check if there are runs to be added to the current one if (fRunInfo->GetRunNameSize() > 1) { // runs to be added present PRawRunData *addRunData; - for (UInt_t i=1; iGetRunNameSize(); i++) { + std::vector addForward; + for (UInt_t i=1; iGetRunNameSize(); i++) { // loop over all ADDRUN's // get run to be added to the main one addRunData = fRawData->GetRunData(*fRunInfo->GetRunName(i)); @@ -1082,15 +1088,23 @@ Bool_t PRunSingleHisto::PrepareData() return false; } + addForward.clear(); + addForward.resize(histoNo.size()); // resize to number of groups + for (UInt_t j=0; jGetDataBin(histoNo[j])->size()); + addForward[j] = *addRunData->GetDataBin(histoNo[j]); + } + DeadTimeCorrection(addForward, histoNo); + // add forward run UInt_t addRunSize; for (UInt_t k=0; kGetDataBin(histoNo[k])->size(); - for (UInt_t j=0; jGetDataBin(histoNo[k])->size(); j++) { // loop over the bin indices + addRunSize = addForward[k].size(); + for (UInt_t j=0; j(j)+static_cast(fAddT0s[i-1][k])-static_cast(fT0s[k]) >= 0) && (j+static_cast(fAddT0s[i-1][k])-static_cast(fT0s[k]) < addRunSize)) { - forward[k][j] += addRunData->GetDataBin(histoNo[k])->at(j+static_cast(fAddT0s[i-1][k])-static_cast(fT0s[k])); + forward[k][j] += addForward[k][j+static_cast(fAddT0s[i-1][k])-static_cast(fT0s[k])]; } } } diff --git a/src/include/PRunBase.h b/src/include/PRunBase.h index 0408bf061..d915ec224 100644 --- a/src/include/PRunBase.h +++ b/src/include/PRunBase.h @@ -315,6 +315,14 @@ class PRunBase */ virtual Bool_t PrepareData() = 0; + /** + * \brief carry out dead time correction + * + * \param histos histograms to be corrected + * \param histoNo histogram numbers + */ + virtual void DeadTimeCorrection(std::vector &histos, PUIntVector &histoNo); + /** * \brief Calculates Kaiser window FIR filter coefficients for RRF smoothing. *