move DeadTimeCorrection to PRunBase. Make ADDRUN part in PrepareData more readable.

This commit is contained in:
2026-02-20 18:17:05 +01:00
parent 811b47cf41
commit 7d102a2604
3 changed files with 75 additions and 4 deletions

View File

@@ -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<PDoubleVector> &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; i<histoNo.size(); i++) {
dtcr = fRunInfo->GetDeadTimeCorrection();
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<float> t_dt = runData->GetDeadTimeParam();
for (UInt_t j=0; j<histos[i].size(); j++) {
n_true = histos[i][j] / (1.0 - histos[i][j] * t_dt[histoNo[i]] / (gf * fTimeResolution));
histos[i][j] = n_true;
}
}
}
if ((dtcr.Contains("estimate", TString::kIgnoreCase) || (dtcg_tag != 0)) && needToCheck) {
std::cerr << "as35> run: deadtime correction: " << dtcr.Data() << ", global: " << dtcg_tag << std::endl;
}
}
}
//--------------------------------------------------------------------------
// SetFitRange (public)

View File

@@ -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; i<fRunInfo->GetRunNameSize(); i++) {
std::vector<PDoubleVector> addForward;
for (UInt_t i=1; i<fRunInfo->GetRunNameSize(); 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; j<histoNo.size(); j++) {
addForward[j].resize(addRunData->GetDataBin(histoNo[j])->size());
addForward[j] = *addRunData->GetDataBin(histoNo[j]);
}
DeadTimeCorrection(addForward, histoNo);
// add forward run
UInt_t addRunSize;
for (UInt_t k=0; k<histoNo.size(); k++) { // fill each group
addRunSize = addRunData->GetDataBin(histoNo[k])->size();
for (UInt_t j=0; j<addRunData->GetDataBin(histoNo[k])->size(); j++) { // loop over the bin indices
addRunSize = addForward[k].size();
for (UInt_t j=0; j<addRunSize; j++) { // loop over the bin indices
// make sure that the index stays in the proper range
if ((static_cast<Int_t>(j)+static_cast<Int_t>(fAddT0s[i-1][k])-static_cast<Int_t>(fT0s[k]) >= 0) &&
(j+static_cast<Int_t>(fAddT0s[i-1][k])-static_cast<Int_t>(fT0s[k]) < addRunSize)) {
forward[k][j] += addRunData->GetDataBin(histoNo[k])->at(j+static_cast<Int_t>(fAddT0s[i-1][k])-static_cast<Int_t>(fT0s[k]));
forward[k][j] += addForward[k][j+static_cast<Int_t>(fAddT0s[i-1][k])-static_cast<Int_t>(fT0s[k])];
}
}
}

View File

@@ -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<PDoubleVector> &histos, PUIntVector &histoNo);
/**
* \brief Calculates Kaiser window FIR filter coefficients for RRF smoothing.
*