Skip to content

Commit 031dfa6

Browse files
authored
Merge f044f6f into sapling-pr-archive-ktf
2 parents 4f7f784 + f044f6f commit 031dfa6

File tree

81 files changed

+4246
-580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+4246
-580
lines changed

Common/SimConfig/include/SimConfig/SimConfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ enum class SimFieldMode {
3737
enum class VertexMode {
3838
kNoVertex = 0, // no vertexing should be applied in the generator
3939
kDiamondParam = 1, // Diamond param will influence vertexing
40-
kCCDB = 2 // vertex should be taken from CCDB (Calib/MeanVertex object)
40+
kCCDB = 2, // vertex should be taken from CCDB (Calib/MeanVertex object)
41+
kCollCxt = 3 // vertex should be taken from collision context
4142
};
4243

4344
enum class TimeStampMode {

Common/SimConfig/src/SimConfig.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,11 @@ bool SimConfig::parseVertexModeString(std::string const& vertexstring, VertexMod
391391
} else if (vertexstring == "kCCDB") {
392392
mode = VertexMode::kCCDB;
393393
return true;
394+
} else if (vertexstring == "kCollContext") {
395+
mode = VertexMode::kCollCxt;
396+
return true;
394397
}
395-
LOG(error) << "Vertex mode must be one of kNoVertex, kDiamondParam, kCCDB";
398+
LOG(error) << "Vertex mode must be one of kNoVertex, kDiamondParam, kCCDB, kCollContext";
396399
return false;
397400
}
398401

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

DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class CalibdEdxCorrection
9191

9292
void clear();
9393

94-
void writeToFile(std::string_view fileName, std::string_view objName = "CalibdEdxCorrection") const;
95-
void loadFromFile(std::string_view fileName, std::string_view objName = "CalibdEdxCorrection");
94+
void writeToFile(std::string_view fileName, std::string_view objName = "ccdb_object") const;
95+
void loadFromFile(std::string_view fileName, std::string_view objName = "ccdb_object");
9696

9797
/// \param outFileName name of the output file
9898
void dumpToTree(const char* outFileName = "calib_dedx.root") const;

DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <string_view>
1616

1717
// o2 includes
18+
#include "Framework/Logger.h"
1819
#include "DataFormatsTPC/Defs.h"
1920
#include "CommonUtils/TreeStreamRedirector.h"
2021

@@ -39,15 +40,27 @@ void CalibdEdxCorrection::clear()
3940
void CalibdEdxCorrection::writeToFile(std::string_view fileName, std::string_view objName) const
4041
{
4142
std::unique_ptr<TFile> file(TFile::Open(fileName.data(), "recreate"));
43+
if (!file) {
44+
LOGP(error, "Failed to open file {} for writing", fileName.data());
45+
return;
46+
}
47+
4248
file->WriteObject(this, objName.data());
4349
}
4450

4551
void CalibdEdxCorrection::loadFromFile(std::string_view fileName, std::string_view objName)
4652
{
4753
std::unique_ptr<TFile> file(TFile::Open(fileName.data()));
54+
if (!file || file->IsZombie()) {
55+
LOGP(error, "Failed to open file {}", fileName.data());
56+
return;
57+
}
58+
4859
auto tmp = file->Get<CalibdEdxCorrection>(objName.data());
4960
if (tmp != nullptr) {
5061
*this = *tmp;
62+
} else {
63+
LOGP(error, "Failed to load object with name {} from file {}", objName.data(), fileName.data());
5164
}
5265
}
5366

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>

0 commit comments

Comments
 (0)