Skip to content

Commit 82a701d

Browse files
authored
[DPG] Using AggregatedRunInfo in eventSelectionQA (#8735)
1 parent 97f6a6f commit 82a701d

File tree

1 file changed

+57
-68
lines changed

1 file changed

+57
-68
lines changed

DPG/Tasks/AOTEvent/eventSelectionQa.cxx

Lines changed: 57 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#include "map"
12+
#include <map>
13+
#include <vector>
14+
#include <unordered_map>
1315

1416
#include "Framework/runDataProcessing.h"
1517
#include "Framework/AnalysisTask.h"
@@ -21,6 +23,7 @@
2123
#include "CommonDataFormat/BunchFilling.h"
2224
#include "DataFormatsParameters/GRPLHCIFData.h"
2325
#include "DataFormatsParameters/GRPECSObject.h"
26+
#include "DataFormatsParameters/AggregatedRunInfo.h"
2427
#include "TH1F.h"
2528
#include "TH2F.h"
2629

@@ -35,23 +38,23 @@ using FullTracksIU = soa::Join<aod::TracksIU, aod::TracksExtra>;
3538

3639
struct EventSelectionQaTask {
3740
Configurable<bool> isMC{"isMC", 0, "0 - data, 1 - MC"};
38-
Configurable<int> nGlobalBCs{"nGlobalBCs", 100000, "number of global bcs"};
39-
Configurable<double> minOrbitConf{"minOrbit", 0, "minimum orbit"};
40-
Configurable<int> nOrbitsConf{"nOrbits", 10000, "number of orbits"};
41+
Configurable<int32_t> nGlobalBCs{"nGlobalBCs", 100000, "number of global bcs"};
42+
Configurable<int64_t> minOrbitConf{"minOrbit", 0, "minimum orbit"};
43+
Configurable<int32_t> nOrbitsConf{"nOrbits", 10000, "number of orbits"};
4144
Configurable<bool> isLowFlux{"isLowFlux", 1, "1 - low flux (pp, pPb), 0 - high flux (PbPb)"};
4245

43-
uint64_t minGlobalBC = 0;
4446
Service<o2::ccdb::BasicCCDBManager> ccdb;
4547
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
4648
bool* applySelection = NULL;
4749
int nBCsPerOrbit = 3564;
48-
int lastRunNumber = -1;
50+
int lastRun = -1;
4951
int nOrbits = nOrbitsConf;
50-
double minOrbit = minOrbitConf;
51-
int64_t bcSOR = 0; // global bc of the start of the first orbit, setting 0 by default for unanchored MC
52-
int64_t nBCsPerTF = 128 * nBCsPerOrbit; // duration of TF in bcs, should be 128*3564 or 32*3564, setting 128 orbits by default sfor unanchored MC
53-
std::bitset<o2::constants::lhc::LHCMaxBunches> beamPatternA;
54-
std::bitset<o2::constants::lhc::LHCMaxBunches> beamPatternC;
52+
int64_t minOrbit = minOrbitConf;
53+
int64_t minGlobalBC = minOrbit * nBCsPerOrbit;
54+
int64_t bcSOR = 0; // global bc of the start of the first orbit, setting 0 for unanchored MC
55+
int32_t nOrbitsPerTF = 128; // 128 in 2022, 32 in 2023, setting 128 for unanchored MC
56+
int64_t nBCsPerTF = nOrbitsPerTF * nBCsPerOrbit; // duration of TF in bcs
57+
5558
std::bitset<o2::constants::lhc::LHCMaxBunches> bcPatternA;
5659
std::bitset<o2::constants::lhc::LHCMaxBunches> bcPatternC;
5760
std::bitset<o2::constants::lhc::LHCMaxBunches> bcPatternB;
@@ -75,7 +78,7 @@ struct EventSelectionQaTask {
7578

7679
void init(InitContext&)
7780
{
78-
minGlobalBC = uint64_t(minOrbit) * nBCsPerOrbit;
81+
minGlobalBC = minOrbit * nBCsPerOrbit;
7982

8083
// ccdb->setURL("http://ccdb-test.cern.ch:8080");
8184
ccdb->setURL("http://alice-ccdb.cern.ch");
@@ -439,10 +442,11 @@ struct EventSelectionQaTask {
439442
float multT0C = bc.has_ft0() ? bc.ft0().sumAmpC() : -999.f;
440443

441444
if (bc.has_fdd()) {
442-
for (auto amplitude : bc.fdd().chargeA()) {
445+
auto fdd = bc.fdd();
446+
for (auto amplitude : fdd.chargeA()) {
443447
multFDA += amplitude;
444448
}
445-
for (auto amplitude : bc.fdd().chargeC()) {
449+
for (auto amplitude : fdd.chargeC()) {
446450
multFDC += amplitude;
447451
}
448452
}
@@ -523,61 +527,43 @@ struct EventSelectionQaTask {
523527
aod::FT0s const&,
524528
aod::FDDs const&)
525529
{
526-
int runNumber = bcs.iteratorAt(0).runNumber();
527-
uint32_t nOrbitsPerTF = 128; // 128 in 2022, 32 in 2023
528-
if (runNumber != lastRunNumber) {
529-
lastRunNumber = runNumber; // do it only once
530-
int64_t tsSOR = 0;
531-
int64_t tsEOR = 1;
532-
533-
if (runNumber >= 500000) { // access CCDB for data or anchored MC only
534-
int64_t ts = bcs.iteratorAt(0).timestamp();
535-
536-
// access colliding and beam-gas bc patterns
537-
auto grplhcif = ccdb->getForTimeStamp<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", ts);
538-
beamPatternA = grplhcif->getBunchFilling().getBeamPattern(0);
539-
beamPatternC = grplhcif->getBunchFilling().getBeamPattern(1);
530+
int run = bcs.iteratorAt(0).runNumber();
531+
532+
if (run != lastRun) {
533+
lastRun = run;
534+
int64_t tsSOR = 0; // dummy start-of-run timestamp for unanchored MC
535+
int64_t tsEOR = 1; // dummy end-of-run timestamp for unanchored MC
536+
if (run >= 500000) {
537+
auto runInfo = o2::parameters::AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::BasicCCDBManager::instance(), run);
538+
// first bc of the first orbit
539+
bcSOR = runInfo.orbitSOR * o2::constants::lhc::LHCMaxBunches;
540+
// duration of TF in bcs
541+
nBCsPerTF = runInfo.orbitsPerTF * o2::constants::lhc::LHCMaxBunches;
542+
// number of orbits per TF
543+
nOrbitsPerTF = runInfo.orbitsPerTF;
544+
// first orbit
545+
minOrbit = runInfo.orbitSOR;
546+
// total number of orbits
547+
nOrbits = runInfo.orbitEOR - runInfo.orbitSOR;
548+
// start-of-run timestamp
549+
tsSOR = runInfo.sor;
550+
// end-of-run timestamp
551+
tsEOR = runInfo.eor;
552+
553+
// bc patterns
554+
auto grplhcif = ccdb->getForTimeStamp<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", (tsSOR + tsEOR) / 2);
555+
auto beamPatternA = grplhcif->getBunchFilling().getBeamPattern(0);
556+
auto beamPatternC = grplhcif->getBunchFilling().getBeamPattern(1);
540557
bcPatternA = beamPatternA & ~beamPatternC;
541558
bcPatternC = ~beamPatternA & beamPatternC;
542559
bcPatternB = beamPatternA & beamPatternC;
543560

561+
// fill once per DF
544562
for (int i = 0; i < nBCsPerOrbit; i++) {
545-
if (bcPatternA[i]) {
546-
histos.fill(HIST("hBcA"), i);
547-
}
548-
if (bcPatternC[i]) {
549-
histos.fill(HIST("hBcC"), i);
550-
}
551-
if (bcPatternB[i]) {
552-
histos.fill(HIST("hBcB"), i);
553-
}
563+
histos.fill(HIST("hBcA"), i, bcPatternA[i] ? 1. : 0.);
564+
histos.fill(HIST("hBcB"), i, bcPatternB[i] ? 1. : 0.);
565+
histos.fill(HIST("hBcC"), i, bcPatternC[i] ? 1. : 0.);
554566
}
555-
556-
EventSelectionParams* par = ccdb->getForTimeStamp<EventSelectionParams>("EventSelection/EventSelectionParams", ts);
557-
// access orbit-reset timestamp
558-
auto ctpx = ccdb->getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/OrbitReset", ts);
559-
int64_t tsOrbitReset = (*ctpx)[0]; // us
560-
// access TF duration, start-of-run and end-of-run timestamps from ECS GRP
561-
std::map<std::string, std::string> metadata;
562-
metadata["runNumber"] = Form("%d", runNumber);
563-
auto grpecs = ccdb->getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", ts, metadata);
564-
nOrbitsPerTF = grpecs->getNHBFPerTF(); // assuming 1 orbit = 1 HBF; nOrbitsPerTF=128 in 2022, 32 in 2023
565-
tsSOR = grpecs->getTimeStart(); // ms
566-
tsEOR = grpecs->getTimeEnd(); // ms
567-
// calculate SOR and EOR orbits
568-
int64_t orbitSOR = (tsSOR * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;
569-
int64_t orbitEOR = (tsEOR * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;
570-
// adjust to the nearest TF edge
571-
orbitSOR = orbitSOR / nOrbitsPerTF * nOrbitsPerTF + par->fTimeFrameOrbitShift;
572-
orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF + par->fTimeFrameOrbitShift;
573-
// set nOrbits and minOrbit used for orbit-axis binning
574-
nOrbits = orbitEOR - orbitSOR;
575-
minOrbit = orbitSOR;
576-
// first bc of the first orbit (should coincide with TF start)
577-
bcSOR = orbitSOR * o2::constants::lhc::LHCMaxBunches;
578-
// duration of TF in bcs
579-
nBCsPerTF = nOrbitsPerTF * o2::constants::lhc::LHCMaxBunches;
580-
LOGP(info, "tsOrbitReset={} us, SOR = {} ms, EOR = {} ms, orbitSOR = {}, nBCsPerTF = {}", tsOrbitReset, tsSOR, tsEOR, orbitSOR, nBCsPerTF);
581567
}
582568

583569
// create orbit-axis histograms on the fly with binning based on info from GRP if GRP is available
@@ -771,12 +757,14 @@ struct EventSelectionQaTask {
771757
histos.fill(HIST("hGlobalBcFDD"), globalBC - minGlobalBC);
772758
histos.fill(HIST("hOrbitFDD"), orbit - minOrbit);
773759
histos.fill(HIST("hBcFDD"), localBC);
760+
761+
auto fdd = bc.fdd();
774762
float multFDA = 0;
775-
for (auto amplitude : bc.fdd().chargeA()) {
763+
for (auto amplitude : fdd.chargeA()) {
776764
multFDA += amplitude;
777765
}
778766
float multFDC = 0;
779-
for (auto amplitude : bc.fdd().chargeC()) {
767+
for (auto amplitude : fdd.chargeC()) {
780768
multFDC += amplitude;
781769
}
782770
histos.fill(HIST("hMultFDAall"), multFDA);
@@ -829,7 +817,7 @@ struct EventSelectionQaTask {
829817
for (const auto& bc : bcs) {
830818
int64_t globalBC = bc.globalBC();
831819
// skip non-colliding bcs for data and anchored runs
832-
if (runNumber >= 500000 && bcPatternB[globalBC % o2::constants::lhc::LHCMaxBunches] == 0) {
820+
if (run >= 500000 && bcPatternB[globalBC % o2::constants::lhc::LHCMaxBunches] == 0) {
833821
continue;
834822
}
835823
if (bc.selection_bit(kIsBBT0A) || bc.selection_bit(kIsBBT0C)) {
@@ -982,10 +970,11 @@ struct EventSelectionQaTask {
982970
float multFDA = 0;
983971
float multFDC = 0;
984972
if (foundBC.has_fdd()) {
985-
for (auto amplitude : foundBC.fdd().chargeA()) {
973+
auto fdd = foundBC.fdd();
974+
for (auto amplitude : fdd.chargeA()) {
986975
multFDA += amplitude;
987976
}
988-
for (auto amplitude : foundBC.fdd().chargeC()) {
977+
for (auto amplitude : fdd.chargeC()) {
989978
multFDC += amplitude;
990979
}
991980
}

0 commit comments

Comments
 (0)