diff --git a/DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h b/DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h index eacbadbe9bedc..518b3b4f10a69 100644 --- a/DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h +++ b/DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h @@ -128,7 +128,7 @@ class CTPRunScalers std::pair getRate(uint32_t orbit, int classindex, int type) const; /// same with absolute timestamp (not orbit) as argument - std::pair getRateGivenT(double timestamp, int classindex, int type) const; + std::pair getRateGivenT(double timestamp, int classindex, int type, bool qc = 0) const; /// retrieves integral for class std::array getIntegralForClass(int i) const diff --git a/DataFormats/Detectors/CTP/src/CTPRateFetcher.cxx b/DataFormats/Detectors/CTP/src/CTPRateFetcher.cxx index d9fc250bdc2ac..6be4c3b301802 100644 --- a/DataFormats/Detectors/CTP/src/CTPRateFetcher.cxx +++ b/DataFormats/Detectors/CTP/src/CTPRateFetcher.cxx @@ -84,14 +84,14 @@ double CTPRateFetcher::fetchCTPratesClassesNoPuCorr(uint64_t timeStamp, const st LOG(warn) << "Trigger class " << className << " not found in CTPConfiguration"; return -2.; } - auto rate{mScalers.getRateGivenT(timeStamp * 1.e-3, classIndex, inputType)}; + auto rate{mScalers.getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, 1)}; return rate.second; } double CTPRateFetcher::fetchCTPratesInputs(uint64_t timeStamp, int input) { std::vector& recs = mScalers.getScalerRecordO2(); if (recs[0].scalersInps.size() == 48) { - return pileUpCorrection(mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7).second); + return pileUpCorrection(mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, 1).second); } else { LOG(error) << "Inputs not available"; return -1.; @@ -101,7 +101,7 @@ double CTPRateFetcher::fetchCTPratesInputsNoPuCorr(uint64_t timeStamp, int input { std::vector& recs = mScalers.getScalerRecordO2(); if (recs[0].scalersInps.size() == 48) { - return mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7).second; + return mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, 1).second; } else { LOG(error) << "Inputs not available"; return -1.; diff --git a/DataFormats/Detectors/CTP/src/Scalers.cxx b/DataFormats/Detectors/CTP/src/Scalers.cxx index 51242829f4f1e..cd4e12098dba2 100644 --- a/DataFormats/Detectors/CTP/src/Scalers.cxx +++ b/DataFormats/Detectors/CTP/src/Scalers.cxx @@ -723,7 +723,7 @@ std::pair CTPRunScalers::getRate(uint32_t orbit, int classindex, // rate in Hz at a certain orbit number within the run // type - 7 : inputs // type - 1..6 : lmb,lma,l0b,l0a,l1b,l1a -std::pair CTPRunScalers::getRateGivenT(double timestamp, int classindex, int type) const +std::pair CTPRunScalers::getRateGivenT(double timestamp, int classindex, int type, bool qc) const { if (mScalerRecordO2.size() <= 1) { LOG(error) << "not enough data"; @@ -775,12 +775,24 @@ std::pair CTPRunScalers::getRateGivenT(double timestamp, int cla return -1; // wrong type } }; - if (nextindex == 0 || nextindex == mScalerRecordO2.size()) { + if (nextindex == 0) { // orbit is out of bounds - LOG(info) << "query timestamp " << (long)timestamp << " out of bounds; Just returning the global rate"; - return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1); + if (qc == 0) { + LOG(info) << "query timestamp " << (long)timestamp << " before first record; Just returning the global rate"; + return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1); + } else { + LOG(info) << "query timestamp " << (long)timestamp << " before first record; Returning the first rate"; + return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* first rate */ calcRate(0, 1)); + } + } else if (nextindex == mScalerRecordO2.size()) { + if (qc == 0) { + LOG(info) << "query timestamp " << (long)timestamp << " after last record; Just returning the global rate"; + return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1); + } else { + LOG(info) << "query timestamp " << (long)timestamp << " after last record; Returning the last rate"; + return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* last rate */ calcRate(mScalerRecordO2.size() - 2, mScalerRecordO2.size() - 1)); + } } else { - return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ calcRate(nextindex - 1, nextindex)); } return std::make_pair(-1., -1.);