Skip to content

Commit b5236e5

Browse files
authored
Improve histo handling for multi-run analyses (#7064)
1 parent 0666fa3 commit b5236e5

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

EventFiltering/Zorro.cxx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <algorithm>
1616
#include <map>
1717

18+
#include <TList.h>
19+
1820
#include "CCDB/BasicCCDBManager.h"
1921
#include "CommonDataFormat/InteractionRecord.h"
2022

@@ -35,44 +37,56 @@ int findBin(TH1* hist, const std::string& label)
3537

3638
void Zorro::populateHistRegistry(o2::framework::HistogramRegistry& histRegistry, int runNumber, std::string prefix)
3739
{
38-
if (mRunNumberHistos == runNumber) {
40+
int runId{-1};
41+
for (size_t i{0}; i < mRunNumberHistos.size(); ++i) {
42+
if (mRunNumberHistos[i] == runNumber) {
43+
runId = i;
44+
break;
45+
}
46+
}
47+
if (runId > -1) {
48+
/// Support jobs running on non-continuous run numbers
49+
mAnalysedTriggers = mAnalysedTriggersList[runId];
50+
mAnalysedTriggersOfInterest = mAnalysedTriggersOfInterestList[runId];
3951
return;
4052
}
41-
mRunNumberHistos = runNumber;
4253
if (mSelections) {
43-
mAnalysedTriggers = histRegistry.add<TH1>((std::to_string(mRunNumberHistos) + "/" + prefix + "AnalysedTriggers").data(), "", o2::framework::HistType::kTH1D, {{mSelections->GetNbinsX() - 2, -0.5, mSelections->GetNbinsX() - 2.5}});
54+
mAnalysedTriggers = histRegistry.add<TH1>((std::to_string(runNumber) + "/" + prefix + "AnalysedTriggers").data(), "", o2::framework::HistType::kTH1D, {{mSelections->GetNbinsX() - 2, -0.5, mSelections->GetNbinsX() - 2.5}}).get();
4455
for (int iBin{2}; iBin < mSelections->GetNbinsX(); ++iBin) { // Exclude first and last bins as they are total number of analysed and selected events, respectively
4556
mAnalysedTriggers->GetXaxis()->SetBinLabel(iBin - 1, mSelections->GetXaxis()->GetBinLabel(iBin));
4657
}
47-
std::shared_ptr<TH1> selections = histRegistry.add<TH1>((std::to_string(mRunNumberHistos) + "/" + prefix + "Selections").data(), "", o2::framework::HistType::kTH1D, {{mSelections->GetNbinsX(), -0.5, static_cast<double>(mSelections->GetNbinsX() - 0.5)}});
58+
std::shared_ptr<TH1> selections = histRegistry.add<TH1>((std::to_string(runNumber) + "/" + prefix + "Selections").data(), "", o2::framework::HistType::kTH1D, {{mSelections->GetNbinsX(), -0.5, static_cast<double>(mSelections->GetNbinsX() - 0.5)}});
4859
for (int iBin{1}; iBin <= mSelections->GetNbinsX(); ++iBin) {
4960
selections->GetXaxis()->SetBinLabel(iBin, mSelections->GetXaxis()->GetBinLabel(iBin));
5061
selections->SetBinContent(iBin, mSelections->GetBinContent(iBin));
5162
selections->SetBinError(iBin, mSelections->GetBinError(iBin));
5263
}
5364
}
5465
if (mScalers) {
55-
std::shared_ptr<TH1> scalers = histRegistry.add<TH1>((std::to_string(mRunNumberHistos) + "/" + prefix + "Scalers").data(), "", o2::framework::HistType::kTH1D, {{mScalers->GetNbinsX(), -0.5, static_cast<double>(mScalers->GetNbinsX() - 0.5)}});
66+
std::shared_ptr<TH1> scalers = histRegistry.add<TH1>((std::to_string(runNumber) + "/" + prefix + "Scalers").data(), "", o2::framework::HistType::kTH1D, {{mScalers->GetNbinsX(), -0.5, static_cast<double>(mScalers->GetNbinsX() - 0.5)}});
5667
for (int iBin{1}; iBin <= mScalers->GetNbinsX(); ++iBin) {
5768
scalers->GetXaxis()->SetBinLabel(iBin, mScalers->GetXaxis()->GetBinLabel(iBin));
5869
scalers->SetBinContent(iBin, mScalers->GetBinContent(iBin));
5970
scalers->SetBinError(iBin, mScalers->GetBinError(iBin));
6071
}
6172
}
6273
if (mInspectedTVX) {
63-
std::shared_ptr<TH1> inspectedTVX = histRegistry.add<TH1>((std::to_string(mRunNumberHistos) + "/" + prefix + "InspectedTVX").data(), "", o2::framework::HistType::kTH1D, {{mInspectedTVX->GetNbinsX(), -0.5, static_cast<double>(mInspectedTVX->GetNbinsX() - 0.5)}});
74+
std::shared_ptr<TH1> inspectedTVX = histRegistry.add<TH1>((std::to_string(runNumber) + "/" + prefix + "InspectedTVX").data(), "", o2::framework::HistType::kTH1D, {{mInspectedTVX->GetNbinsX(), -0.5, static_cast<double>(mInspectedTVX->GetNbinsX() - 0.5)}});
6475
for (int iBin{1}; iBin <= mInspectedTVX->GetNbinsX(); ++iBin) {
6576
inspectedTVX->GetXaxis()->SetBinLabel(iBin, mInspectedTVX->GetXaxis()->GetBinLabel(iBin));
6677
inspectedTVX->SetBinContent(iBin, mInspectedTVX->GetBinContent(iBin));
6778
inspectedTVX->SetBinError(iBin, mInspectedTVX->GetBinError(iBin));
6879
}
6980
}
7081
if (mTOIs.size()) {
71-
mAnalysedTriggersOfInterest = histRegistry.add<TH1>((std::to_string(mRunNumberHistos) + "/" + prefix + "AnalysedTriggersOfInterest").data(), "", o2::framework::HistType::kTH1D, {{static_cast<int>(mTOIs.size()), -0.5, static_cast<double>(mTOIs.size() - 0.5)}});
82+
mAnalysedTriggersOfInterest = histRegistry.add<TH1>((std::to_string(runNumber) + "/" + prefix + "AnalysedTriggersOfInterest").data(), "", o2::framework::HistType::kTH1D, {{static_cast<int>(mTOIs.size()), -0.5, static_cast<double>(mTOIs.size() - 0.5)}}).get();
7283
for (size_t i{0}; i < mTOIs.size(); ++i) {
7384
mAnalysedTriggersOfInterest->GetXaxis()->SetBinLabel(i + 1, mTOIs[i].data());
7485
}
7586
}
87+
mAnalysedTriggersList.push_back(mAnalysedTriggers);
88+
mAnalysedTriggersOfInterestList.push_back(mAnalysedTriggersOfInterest);
89+
mRunNumberHistos.push_back(runNumber);
7690
}
7791

7892
std::vector<int> Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber, uint64_t timestamp, std::string tois, int bcRange)
@@ -91,9 +105,11 @@ std::vector<int> Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber
91105
mZorroHelpers = mCCDB->getSpecific<std::vector<ZorroHelper>>(mBaseCCDBPath + "ZorroHelpers", timestamp, metadata);
92106
std::sort(mZorroHelpers->begin(), mZorroHelpers->end(), [](const auto& a, const auto& b) { return std::min(a.bcAOD, a.bcEvSel) < std::min(b.bcAOD, b.bcEvSel); });
93107
mBCranges.clear();
108+
mAccountedBCranges.clear();
94109
for (auto helper : *mZorroHelpers) {
95110
mBCranges.emplace_back(InteractionRecord::long2IR(std::min(helper.bcAOD, helper.bcEvSel)), InteractionRecord::long2IR(std::max(helper.bcAOD, helper.bcEvSel)));
96111
}
112+
mAccountedBCranges.resize(mBCranges.size(), false);
97113

98114
mLastBCglobalId = 0;
99115
mLastSelectedIdx = 0;
@@ -121,27 +137,27 @@ std::vector<int> Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber
121137

122138
std::bitset<128> Zorro::fetch(uint64_t bcGlobalId, uint64_t tolerance)
123139
{
124-
uint64_t lastSelectedIdx = mLastSelectedIdx;
125140
mLastResult.reset();
126141
o2::dataformats::IRFrame bcFrame{InteractionRecord::long2IR(bcGlobalId) - tolerance, InteractionRecord::long2IR(bcGlobalId) + tolerance};
127-
if (bcGlobalId < mLastBCglobalId) {
142+
if (bcGlobalId < mLastBCglobalId) { /// Handle the possible discontinuity in the BC processed by the analyses
128143
mLastSelectedIdx = 0;
129144
}
145+
uint64_t lastSelectedIdx = mLastSelectedIdx;
130146
mLastBCglobalId = bcGlobalId;
131147
for (size_t i = mLastSelectedIdx; i < mBCranges.size(); i++) {
132148
if (!mBCranges[i].isOutside(bcFrame)) {
133149
for (int iMask{0}; iMask < 2; ++iMask) {
134150
for (int iTOI{0}; iTOI < 64; ++iTOI) {
135151
if (mZorroHelpers->at(i).selMask[iMask] & (1ull << iTOI)) {
136152
mLastResult.set(iMask * 64 + iTOI, 1);
137-
if (mAnalysedTriggers && i != lastSelectedIdx) {
153+
if (mAnalysedTriggers && !mAccountedBCranges[i]) {
138154
mAnalysedTriggers->Fill(iMask * 64 + iTOI);
139155
}
140156
}
141157
}
142158
}
143-
mLastSelectedIdx = i;
144-
return mLastResult;
159+
mAccountedBCranges[i] = true;
160+
mLastSelectedIdx = mLastSelectedIdx == lastSelectedIdx-- ? i : mLastSelectedIdx; /// Decrease lastSelectedIdx to make sure this check is valid only in its first instance
145161
} else if (mBCranges[i].getMax() < bcFrame.getMin()) {
146162
mLastSelectedIdx = i;
147163
} else if (mBCranges[i].getMin() > bcFrame.getMax()) {

EventFiltering/Zorro.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,21 @@ class Zorro
5959
private:
6060
std::string mBaseCCDBPath = "Users/m/mpuccio/EventFiltering/OTS/";
6161
int mRunNumber = 0;
62-
int mRunNumberHistos = 0;
62+
TH1* mAnalysedTriggers; /// Accounting for all triggers in the current run
63+
TH1* mAnalysedTriggersOfInterest; /// Accounting for triggers of interest in the current run
64+
65+
std::vector<int> mRunNumberHistos;
66+
std::vector<TH1*> mAnalysedTriggersList; /// Per run histograms
67+
std::vector<TH1*> mAnalysedTriggersOfInterestList; /// Per run histograms
68+
6369
int mBCtolerance = 100;
6470
uint64_t mLastBCglobalId = 0;
6571
uint64_t mLastSelectedIdx = 0;
6672
TH1D* mScalers = nullptr;
6773
TH1D* mSelections = nullptr;
6874
TH1D* mInspectedTVX = nullptr;
69-
std::shared_ptr<TH1> mAnalysedTriggers;
70-
std::shared_ptr<TH1> mAnalysedTriggersOfInterest;
7175
std::bitset<128> mLastResult;
76+
std::vector<bool> mAccountedBCranges; /// Avoid double accounting of inspected BC ranges
7277
std::vector<o2::dataformats::IRFrame> mBCranges;
7378
std::vector<ZorroHelper>* mZorroHelpers = nullptr;
7479
std::vector<std::string> mTOIs;

0 commit comments

Comments
 (0)