21 auto triggerRate =
fetchNoPuCorr(ccdb, timeStamp, runNumber, sourceName);
22 if (triggerRate >= 0) {
23 return pileUpCorrection(triggerRate);
29 setupRun(runNumber, ccdb, timeStamp, 1);
30 if (sourceName.find(
"ZNC") != std::string::npos) {
31 if (runNumber < 544448) {
32 return fetchCTPratesInputsNoPuCorr(timeStamp, 25) / (sourceName.find(
"hadronic") != std::string::npos ? 28. : 1.);
34 return fetchCTPratesClassesNoPuCorr(timeStamp,
"C1ZNC-B-NOPF-CRU", 6) / (sourceName.find(
"hadronic") != std::string::npos ? 28. : 1.);
36 }
else if (sourceName ==
"T0CE") {
37 return fetchCTPratesClassesNoPuCorr(timeStamp,
"CMTVXTCE-B-NOPF");
38 }
else if (sourceName ==
"T0SC") {
39 return fetchCTPratesClassesNoPuCorr(timeStamp,
"CMTVXTSC-B-NOPF");
40 }
else if (sourceName ==
"T0VTX") {
41 if (runNumber < 534202) {
42 return fetchCTPratesClassesNoPuCorr(timeStamp,
"minbias_TVX_L0", 3);
44 double ret = fetchCTPratesClassesNoPuCorr(timeStamp,
"CMTVX-B-NOPF");
46 LOG(info) <<
"Trying different class";
47 ret = fetchCTPratesClassesNoPuCorr(timeStamp,
"CMTVX-NONE");
49 LOG(error) <<
"None of the classes used for lumi found";
56 LOG(error) <<
"CTP rate for " << sourceName <<
" not available";
72 double rate0 =
fetch(ccdb, orbitlimits.first, mRunNumber, sourceName);
73 double rateLast =
fetch(ccdb, orbitlimits.second, mRunNumber, sourceName);
74 double rateM =
fetch(ccdb, (orbitlimits.first + orbitlimits.second) / 2, mRunNumber, sourceName);
83 if (classname ==
"zncinp") {
89 for (
size_t i = 0;
i < clslist.size();
i++) {
90 if (ctpcls[
i].
name.find(classname) != std::string::npos) {
95 if (classIndex == -1) {
96 LOG(warn) <<
"Trigger class " << classname <<
" not found in CTPConfiguration";
103 std::vector<std::pair<double, double>> scals;
104 if (classname ==
"zncinp") {
107 std::vector<ctp::CTPClass>& ctpcls = mConfig.
getCTPClasses();
110 for (
size_t i = 0;
i < clslist.size();
i++) {
111 if (ctpcls[
i].
name.find(classname) != std::string::npos) {
116 if (classIndex == -1) {
117 LOG(warn) <<
"Trigger class " << classname <<
" not found in CTPConfiguration";
123 for (
auto const& ss : scals) {
125 lumi += pileUpCorrection(ss.first / ss.second) * ss.second;
141 if (sourceName.find(
"ZNC") != std::string::npos) {
142 if (runNumber < 544448) {
143 return getLumi(
"zncinp", 1, puCorr) / (sourceName.find(
"hadronic") != std::string::npos ? 28. : 1.);
145 return getLumi(
"C1ZNC-B-NOPF-CRU", 6, puCorr) / (sourceName.find(
"hadronic") != std::string::npos ? 28. : 1.);
147 }
else if (sourceName ==
"T0CE") {
148 return getLumi(
"CMTVXTCE-B-NOPF", 1, puCorr);
149 }
else if (sourceName ==
"T0SC") {
150 return getLumi(
"CMTVXTSC-B-NOPF", 1, puCorr);
151 }
else if (sourceName ==
"T0VTX") {
152 if (runNumber < 534202) {
153 return getLumi(
"minbias_TVX_L0", 3, puCorr);
155 double ret =
getLumi(
"CMTVX-B-NOPF", 1, puCorr);
157 LOG(info) <<
"Trying different class";
158 ret =
getLumi(
"CMTVX-NONE", 1, puCorr);
160 LOG(fatal) <<
"None of the classes used for lumi found";
166 LOG(error) <<
"CTP Lumi for " << sourceName <<
" not available";
170double CTPRateFetcher::fetchCTPratesClasses(uint64_t timeStamp,
const std::string& className,
int inputType)
172 auto triggerRate = fetchCTPratesClassesNoPuCorr(timeStamp, className, inputType);
173 if (triggerRate >= 0) {
174 return pileUpCorrection(triggerRate);
178double CTPRateFetcher::fetchCTPratesClassesNoPuCorr(uint64_t timeStamp,
const std::string& className,
int inputType)
180 std::vector<ctp::CTPClass>& ctpcls = mConfig.
getCTPClasses();
183 for (
size_t i = 0;
i < clslist.size();
i++) {
184 if (ctpcls[
i].
name.find(className) != std::string::npos) {
189 if (classIndex == -1) {
190 LOG(warn) <<
"Trigger class " << className <<
" not found in CTPConfiguration";
194 auto rate{mScalers.
getRate((uint32_t)timeStamp, classIndex, inputType, mOutsideLimits)};
197 auto rate{mScalers.
getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, mOutsideLimits)};
201double CTPRateFetcher::fetchCTPratesInputs(uint64_t timeStamp,
int input)
204 if (recs[0].scalersInps.size() == 48) {
206 return pileUpCorrection(mScalers.
getRate((uint32_t)timeStamp, input, 7, mOutsideLimits).second);
208 return pileUpCorrection(mScalers.
getRateGivenT(timeStamp * 1.e-3, input, 7, mOutsideLimits).second);
211 LOG(error) <<
"Inputs not available";
215double CTPRateFetcher::fetchCTPratesInputsNoPuCorr(uint64_t timeStamp,
int input)
218 if (recs[0].scalersInps.size() == 48) {
220 return mScalers.
getRate((uint32_t)timeStamp, input, 7, mOutsideLimits).second;
222 return mScalers.
getRateGivenT(timeStamp * 1.e-3, input, 7, mOutsideLimits).second;
225 LOG(error) <<
"Inputs not available";
230double CTPRateFetcher::pileUpCorrection(
double triggerRate)
233 LOG(fatal) <<
"No filling" << std::endl;
237 double nbc = bcs.size();
239 double mu = -std::log(1 - nTriggersPerFilledBC);
245 if (runNumber == mRunNumber) {
248 mRunNumber = runNumber;
249 LOG(info) <<
"Setting up CTP scalers for run " << mRunNumber <<
" and timestamp : " << timeStamp;
251 if (ptrLHCIFdata ==
nullptr) {
252 LOG(error) <<
"GRPLHCIFData not in database, timestamp:" << timeStamp;
255 mLHCIFdata = *ptrLHCIFdata;
256 std::map<string, string> metadata;
259 if (ptrConfig ==
nullptr) {
260 LOG(error) <<
"CTPRunConfig not in database, timestamp:" << timeStamp;
263 mConfig = *ptrConfig;
267 mScalers = *ptrScalers;
270 LOG(error) <<
"CTPRunScalers not in database, timestamp:" << timeStamp;
Header to collect LHC related constants.
std::vector< int > getFilledBCs(int dir=-1) const
T * getSpecific(std::string const &path, long timestamp=-1, MD metaData=MD())
retrieve an object of type T from CCDB as stored under path, timestamp and metaData
std::vector< CTPClass > & getCTPClasses()
std::vector< int > getTriggerClassList() const
int getRates(std::array< double, 3 > &rates, o2::ccdb::BasicCCDBManager *ccdb, int runNumber, const std::string sourceName)
double getLumiWPuCorr(const std::string &classname, int type=1)
double getLumi(o2::ccdb::BasicCCDBManager *ccdb, int runNumber, const std::string sourceName, int puCorr=0)
void setupRun(int runNumber, o2::ccdb::BasicCCDBManager *ccdb, uint64_t timeStamp, bool initScalers)
double fetchNoPuCorr(o2::ccdb::BasicCCDBManager *ccdb, uint64_t timeStamp, int runNumber, const std::string sourceName)
double getLumiNoPuCorr(const std::string &classname, int type=1)
void updateScalers(ctp::CTPRunScalers &scalers)
double fetch(o2::ccdb::BasicCCDBManager *ccdb, uint64_t timeStamp, int runNumber, const std::string sourceName)
uint64_t getLumiNoPuCorr(int classindex, int type) const
retrieves integral - same interface as getRate, no pileup correction
std::pair< double, double > getRate(uint32_t orbit, int classindex, int type, bool qc=0) const
std::pair< double, double > getRateGivenT(double timestamp, int classindex, int type, bool qc=0) const
same with absolute timestamp (not orbit) as argument
std::pair< unsigned long, unsigned long > getOrbitLimit() const
retrieves orbit boundaries of this scaler object from O2
std::vector< CTPScalerRecordO2 > & getScalerRecordO2()
std::vector< std::pair< double_t, double_t > > getRatesForIndex(int classindex, int type) const
retrieves vector of counters - same interface as getRate, needed for
const o2::BunchFilling & getBunchFilling() const
int32_t getFillNumber() const
GLuint const GLchar * name
GLint GLint GLsizei GLint GLenum GLenum type
GLuint GLsizei const GLenum * rates
constexpr double LHCRevFreq
std::string to_string(gsl::span< T, Size > span)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"