Skip to content

Commit bb29ae9

Browse files
authored
ctpdev: lumi per run added to fetcher (#13945)
* dev: lumi calcalation in fetcher * clang
1 parent e9a4718 commit bb29ae9

File tree

7 files changed

+238
-25
lines changed

7 files changed

+238
-25
lines changed

DataFormats/Detectors/CTP/include/DataFormatsCTP/CTPRateFetcher.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ class CTPRateFetcher
3333
void setupRun(int runNumber, o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, bool initScalers);
3434
void updateScalers(ctp::CTPRunScalers& scalers);
3535
int getRates(std::array<double, 3>& rates, o2::ccdb::BasicCCDBManager* ccdb, int runNumber, const std::string sourceName); // rates at start,stop and middle of the run
36-
void setOrbit(bool orb) { mOrbit = orb; }
37-
void setOutsideLimits(bool qc) { mOutsideLimits = qc; }
36+
double getLumi(o2::ccdb::BasicCCDBManager* ccdb, int runNumber, const std::string sourceName, int puCorr = 0); // total lumi for a run
37+
double getLumiNoPuCorr(const std::string& classname, int type = 1);
38+
double getLumiWPuCorr(const std::string& classname, int type = 1);
39+
void setOrbit(bool orb) { mOrbit = orb; } // use orbit instead of time
40+
void setOutsideLimits(bool qc) { mOutsideLimits = qc; } // return first/last rate of time outside of run
3841

3942
private:
4043
double fetchCTPratesInputs(uint64_t timeStamp, int input);
4144
double fetchCTPratesClasses(uint64_t timeStamp, const std::string& className, int inputType = 1);
4245
double fetchCTPratesInputsNoPuCorr(uint64_t timeStamp, int input);
4346
double fetchCTPratesClassesNoPuCorr(uint64_t timeStamp, const std::string& className, int inputType = 1);
44-
47+
double getLumi(const std::string& classname, int type = 1, int puCorr = 0);
4548
double pileUpCorrection(double rate);
4649
int mRunNumber = -1;
4750
bool mOutsideLimits = 0;

DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class CTPRunScalers
143143
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l1After - mScalerRecordO2[0].scalers[i].l1After,
144144
};
145145
}
146+
/// retrieves integral - same interface as getRate, no pileup correction
147+
uint64_t getLumiNoPuCorr(int classindex, int type) const;
148+
/// retrieves vector of counters - same interface as getRate, needed for
149+
std::vector<std::pair<double_t, double_t>> getRatesForIndex(int classindex, int type) const;
146150
/// retrieves time boundaries of this scaler object from O2 scalers
147151
std::pair<unsigned long, unsigned long> getTimeLimit() const
148152
{

DataFormats/Detectors/CTP/src/CTPRateFetcher.cxx

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ double CTPRateFetcher::fetchNoPuCorr(o2::ccdb::BasicCCDBManager* ccdb, uint64_t
4141
if (runNumber < 534202) {
4242
return fetchCTPratesClassesNoPuCorr(timeStamp, "minbias_TVX_L0", 3); // 2022
4343
} else {
44-
double_t ret = fetchCTPratesClassesNoPuCorr(timeStamp, "CMTVX-B-NOPF");
44+
double ret = fetchCTPratesClassesNoPuCorr(timeStamp, "CMTVX-B-NOPF");
4545
if (ret == -2.) {
4646
LOG(info) << "Trying different class";
4747
ret = fetchCTPratesClassesNoPuCorr(timeStamp, "CMTVX-NONE");
@@ -77,6 +77,94 @@ int CTPRateFetcher::getRates(std::array<double, 3>& rates, o2::ccdb::BasicCCDBMa
7777
rates[2] = rateM;
7878
return 0;
7979
}
80+
double CTPRateFetcher::getLumiNoPuCorr(const std::string& classname, int type)
81+
{
82+
if (classname == "zncinp") {
83+
return mScalers.getLumiNoPuCorr(26, 7);
84+
}
85+
std::vector<ctp::CTPClass>& ctpcls = mConfig.getCTPClasses();
86+
std::vector<int> clslist = mConfig.getTriggerClassList();
87+
int classIndex = -1;
88+
for (size_t i = 0; i < clslist.size(); i++) {
89+
if (ctpcls[i].name.find(classname) != std::string::npos) {
90+
classIndex = i;
91+
break;
92+
}
93+
}
94+
if (classIndex == -1) {
95+
LOG(warn) << "Trigger class " << classname << " not found in CTPConfiguration";
96+
return -1;
97+
}
98+
return mScalers.getLumiNoPuCorr(classIndex, type);
99+
}
100+
double CTPRateFetcher::getLumiWPuCorr(const std::string& classname, int type)
101+
{
102+
std::vector<std::pair<double, double>> scals;
103+
if (classname == "zncinp") {
104+
scals = mScalers.getRatesForIndex(26, 7);
105+
} else {
106+
std::vector<ctp::CTPClass>& ctpcls = mConfig.getCTPClasses();
107+
std::vector<int> clslist = mConfig.getTriggerClassList();
108+
int classIndex = -1;
109+
for (size_t i = 0; i < clslist.size(); i++) {
110+
if (ctpcls[i].name.find(classname) != std::string::npos) {
111+
classIndex = i;
112+
break;
113+
}
114+
}
115+
if (classIndex == -1) {
116+
LOG(warn) << "Trigger class " << classname << " not found in CTPConfiguration";
117+
return -1;
118+
}
119+
scals = mScalers.getRatesForIndex(classIndex, type);
120+
}
121+
double lumi = 0;
122+
for (auto const& ss : scals) {
123+
// std::cout << ss.first << " " << ss.second << " " << pileUpCorrection(ss.first/ss.second) << std::endl;
124+
lumi += pileUpCorrection(ss.first / ss.second) * ss.second;
125+
}
126+
return lumi;
127+
}
128+
double CTPRateFetcher::getLumi(const std::string& classname, int type, int puCorr)
129+
{
130+
if (puCorr) {
131+
return getLumiWPuCorr(classname, type);
132+
} else {
133+
return getLumiNoPuCorr(classname, type);
134+
}
135+
}
136+
137+
double CTPRateFetcher::getLumi(o2::ccdb::BasicCCDBManager* ccdb, int runNumber, const std::string sourceName, int puCorr)
138+
{
139+
// setupRun(runNumber, ccdb, timeStamp, 1);
140+
if (sourceName.find("ZNC") != std::string::npos) {
141+
if (runNumber < 544448) {
142+
return getLumi("zncinp", 1, puCorr) / (sourceName.find("hadronic") != std::string::npos ? 28. : 1.);
143+
} else {
144+
return getLumi("C1ZNC-B-NOPF-CRU", 6, puCorr) / (sourceName.find("hadronic") != std::string::npos ? 28. : 1.);
145+
}
146+
} else if (sourceName == "T0CE") {
147+
return getLumi("CMTVXTCE-B-NOPF", 1, puCorr);
148+
} else if (sourceName == "T0SC") {
149+
return getLumi("CMTVXTSC-B-NOPF", 1, puCorr);
150+
} else if (sourceName == "T0VTX") {
151+
if (runNumber < 534202) {
152+
return getLumi("minbias_TVX_L0", 3, puCorr); // 2022
153+
} else {
154+
double ret = getLumi("CMTVX-B-NOPF", 1, puCorr);
155+
if (ret == -1.) {
156+
LOG(info) << "Trying different class";
157+
ret = getLumi("CMTVX-NONE", 1, puCorr);
158+
if (ret < 0) {
159+
LOG(fatal) << "None of the classes used for lumi found";
160+
}
161+
}
162+
return ret;
163+
}
164+
}
165+
LOG(error) << "CTP Lumi for " << sourceName << " not available";
166+
return 0;
167+
}
80168
//
81169
double CTPRateFetcher::fetchCTPratesClasses(uint64_t timeStamp, const std::string& className, int inputType)
82170
{

DataFormats/Detectors/CTP/src/Scalers.cxx

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,77 @@ void CTPRunScalers::printLMBRateVsT() const
657657
}
658658
}
659659
}
660-
660+
//
661+
uint64_t CTPRunScalers::getLumiNoPuCorr(int classindex, int type) const
662+
{
663+
if (type < 7) {
664+
const auto s0 = mScalerRecordO2[0].scalers[classindex];
665+
const auto s1 = mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[classindex];
666+
switch (type) {
667+
case 1:
668+
return (s1.lmBefore - s0.lmBefore);
669+
case 2:
670+
return (s1.lmAfter - s0.lmAfter);
671+
case 3:
672+
return (s1.l0Before - s0.l0Before);
673+
case 4:
674+
return (s1.l0After - s0.l0After);
675+
case 5:
676+
return (s1.l1Before - s0.l1Before);
677+
case 6:
678+
return (s1.l1After - s0.l1After);
679+
default:
680+
LOG(error) << "Wrong type:" << type;
681+
return -1; // wrong type
682+
}
683+
} else if (type == 7) {
684+
auto s0 = mScalerRecordO2[0].scalersInps[classindex]; // type CTPScalerO2*
685+
auto s1 = mScalerRecordO2[mScalerRecordO2.size() - 1].scalersInps[classindex];
686+
return (s1 - s0);
687+
} else {
688+
LOG(error) << "Wrong type:" << type;
689+
return -1; // wrong type
690+
}
691+
};
692+
//
693+
std::vector<std::pair<double_t, double_t>> CTPRunScalers::getRatesForIndex(int classindex, int type) const
694+
{
695+
std::vector<std::pair<double_t, double_t>> scals;
696+
for (int i = 0; i < mScalerRecordO2.size() - 1; i++) {
697+
double_t diff = 0;
698+
// double_t timeDiff = mScalerRecordO2[i + 1].epochTime - mScalerRecordO2[i].epochTime;
699+
double_t timeDiff = (mScalerRecordO2[i + 1].intRecord.orbit - mScalerRecordO2[i].intRecord.orbit) * o2::constants::lhc::LHCOrbitMUS / 1.e6;
700+
if (type < 7) {
701+
const auto s0 = mScalerRecordO2[i].scalers[classindex];
702+
const auto s1 = mScalerRecordO2[i + 1].scalers[classindex];
703+
if (type == 1) {
704+
diff = s1.lmBefore - s0.lmBefore;
705+
} else if (type == 2) {
706+
diff = s1.lmAfter - s0.lmAfter;
707+
} else if (type == 3) {
708+
diff = s1.l0Before - s0.l0Before;
709+
} else if (type == 4) {
710+
diff = s1.l0After - s0.l0After;
711+
} else if (type == 5) {
712+
diff = s1.l1Before - s0.l1Before;
713+
} else if (type == 6) {
714+
diff = s1.l1After - s0.l1After;
715+
} else {
716+
LOG(error) << "Wrong type:" << type;
717+
return scals; // wrong type
718+
}
719+
} else if (type == 7) {
720+
auto s0 = mScalerRecordO2[i].scalersInps[classindex]; // type CTPScalerO2*
721+
auto s1 = mScalerRecordO2[i + 1].scalersInps[classindex];
722+
diff = s1 - s0;
723+
} else {
724+
LOG(error) << "Wrong type:" << type;
725+
return scals; // wrong type
726+
}
727+
scals.emplace_back(std::pair<double_t, double_t>{diff, timeDiff});
728+
}
729+
return scals;
730+
};
661731
// returns the pair of global (levelled) interaction rate, as well as instantaneous interpolated
662732
// rate in Hz at a certain orbit number within the run
663733
// type - 7 : inputs

Detectors/CTP/macro/GetRates.C

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,44 @@
1212
#if !defined(__CLING__) || defined(__ROOTCLING__)
1313
#include <CCDB/BasicCCDBManager.h>
1414
#include <DataFormatsCTP/Configuration.h>
15-
#include <DataFormatsCTP/CTPRateFetcher.h>
15+
#include "CTPWorkflowScalers/ctpCCDBManager.h"
16+
#include "Framework/Logger.h"
1617
#endif
1718
using namespace o2::ctp;
1819

19-
void TestFetcher(int runNumber = 535087)
20+
void GetRates(int run = 559617)
2021
{
21-
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
22-
std::pair<int64_t, int64_t> pp = ccdb.getRunDuration(runNumber);
23-
long ts = pp.first + 60;
24-
std::cout << "Run duration:" << pp.first << " " << pp.second << std::endl;
25-
// Opening run
26-
CTPRateFetcher fetcher;
27-
fetcher.setupRun(runNumber, &ccdb, ts, 1);
22+
uint64_t inputmaskCum = 0, classmackCum = 0;
23+
int ntrigSel = 0;
24+
25+
auto& cmb = o2::ccdb::BasicCCDBManager::instance();
26+
auto ctpcfg = cmb.getSpecificForRun<o2::ctp::CTPConfiguration>("CTP/Config/Config", run);
27+
if (!ctpcfg) {
28+
LOGP(error, "Can not get config for run {}", run);
29+
return;
30+
}
31+
CTPConfiguration ctpconfig;
32+
ctpconfig.loadConfigurationRun3(ctpcfg->getConfigString());
33+
ctpconfig.printStream(std::cout);
34+
auto& triggerclasses = ctpconfig.getCTPClasses();
35+
LOGP(info, "Found {} trigger classes", triggerclasses.size());
36+
int indexInList = 0;
37+
for (const auto& trgclass : triggerclasses) {
38+
uint64_t inputmask = 0;
39+
if (trgclass.descriptor != nullptr) {
40+
inputmask = trgclass.descriptor->getInputsMask();
41+
// LOGP(info, "inputmask: {:#x}", inputmask);
42+
}
43+
trgclass.printStream(std::cout);
44+
// std::cout << indexInList << ": " << trgclass.name << ", input mask 0x" << std::hex << inputmask << ", class mask 0x" << trgclass.classMask << std::dec << std::endl;
45+
indexInList++;
46+
if (trgclass.cluster->getClusterDetNames().find("TRD") != std::string::npos || trgclass.cluster->getClusterDetNames().find("trd") != std::string::npos) {
47+
LOGP(info, "Found TRD trigger cluster, class mask: {:#x}, input mask: {:#x}", trgclass.classMask, inputmask);
48+
inputmaskCum |= inputmask;
49+
classmackCum |= trgclass.classMask;
50+
ntrigSel++;
51+
}
52+
}
53+
54+
LOGP(info, "Found {} triggers with TRD: classMasks: {:#x} inputMasks: {:#x}", ntrigSel, classmackCum, inputmaskCum);
2855
}

Detectors/CTP/macro/PlotPbLumi.C

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
#include "CCDB/BasicCCDBManager.h"
2121
#include "DataFormatsCTP/Scalers.h"
2222
#include "DataFormatsCTP/Configuration.h"
23+
#include "DataFormatsParameters/GRPLHCIFData.h"
24+
#include "TGraph.h"
25+
#include "TMath.h"
26+
#include "TCanvas.h"
27+
#include "TStyle.h"
2328
#include <string>
2429
#include <map>
2530
#include <iostream>

Detectors/CTP/macro/TestGetRates.C

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,33 @@
1616
#endif
1717
using namespace o2::ctp;
1818

19-
void TestGetRates(int runNumber = 557251)
19+
void TestGetRates(int runN = 0)
2020
{
21+
std::vector<int> runs;
22+
std::vector<std::string> codes = {"T0VTX", "T0VTX", "ZNChadronic", "ZNChadronic", "T0VTX"};
23+
if (runN == 0) {
24+
runs = {529066, 539218, 544013, 544518, 557251};
25+
} else {
26+
runs.push_back(runN);
27+
}
2128
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
22-
// Opening run
23-
std::pair<int64_t, int64_t> pp = ccdb.getRunDuration(runNumber);
24-
long ts = pp.first + 60;
25-
std::cout << "Run duration:" << pp.first << " " << pp.second << std::endl;
26-
CTPRateFetcher fetcher;
27-
fetcher.setupRun(runNumber, &ccdb, ts, 1);
28-
fetcher.setOrbit(1);
29-
std::array<double, 3> rates;
30-
fetcher.getRates(rates, &ccdb, runNumber, "T0VTX");
31-
std::cout << "Start:" << rates[0] << " End:" << rates[1] << " Middle:" << rates[2] << std::endl;
29+
int i = 0;
30+
for (auto const& runNumber : runs) {
31+
// Opening run
32+
std::pair<int64_t, int64_t> pp = ccdb.getRunDuration(runNumber);
33+
long ts = pp.first + 60;
34+
// std::cout << "Run duration:" << pp.first << " " << pp.second << std::endl;
35+
std::cout << "===> RUN:" << runNumber << " duration:" << (pp.second - pp.first) / 1000. << std::endl;
36+
37+
CTPRateFetcher fetcher;
38+
fetcher.setupRun(runNumber, &ccdb, ts, 1);
39+
fetcher.setOrbit(1);
40+
std::array<double, 3> rates;
41+
fetcher.getRates(rates, &ccdb, runNumber, codes[i]);
42+
std::cout << "Start:" << rates[0] << " End:" << rates[1] << " Middle:" << rates[2] << " code:" << codes[i] << std::endl;
43+
double lumi1 = fetcher.getLumi(&ccdb, runNumber, codes[i], 0);
44+
double lumi2 = fetcher.getLumi(&ccdb, runNumber, codes[i], 1);
45+
std::cout << " Lumi NO pile up corr:" << lumi1 << " Lumi with pile upcorr:" << lumi2 << " code:" << codes[i] << std::endl;
46+
i++;
47+
}
3248
}

0 commit comments

Comments
 (0)