Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions EventFiltering/Zorro.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,67 @@

#include "Zorro.h"

#include <algorithm>
#include <map>

#include "TList.h"

#include "CCDB/BasicCCDBManager.h"
#include "CommonDataFormat/InteractionRecord.h"

using o2::InteractionRecord;

void Zorro::populateHistRegistry(o2::framework::HistogramRegistry& histRegistry, std::string prefix)
namespace
{
int findBin(TH1* hist, const std::string& label)
{ // Find bin by label, avoiding the axis extention from the native ROOT implementation
for (int iBin{1}; iBin <= hist->GetNbinsX(); ++iBin) {
if (label == hist->GetXaxis()->GetBinLabel(iBin)) {
return iBin;
}
}
return -1;
}
} // namespace

void Zorro::populateHistRegistry(o2::framework::HistogramRegistry& histRegistry, int runNumber, std::string prefix)
{
TList* list = histRegistry.getListOfHistograms();
if (mSelections && list->FindObject((std::to_string(mRunNumber) + "/" + prefix + "Selections").data()) == nullptr) {
mAnalysedTriggers = histRegistry.add<TH1>((std::to_string(mRunNumber) + "/" + prefix + "AnalysedTriggers").data(), "", o2::framework::HistType::kTH1D, {{mSelections->GetNbinsX() - 2, -0.5, mSelections->GetNbinsX() - 2.5}});
if (mRunNumberHistos == runNumber) {
return;
}
mRunNumberHistos = runNumber;
if (mSelections) {
mAnalysedTriggers = histRegistry.add<TH1>((std::to_string(mRunNumberHistos) + "/" + prefix + "AnalysedTriggers").data(), "", o2::framework::HistType::kTH1D, {{mSelections->GetNbinsX() - 2, -0.5, mSelections->GetNbinsX() - 2.5}});
for (int iBin{2}; iBin < mSelections->GetNbinsX(); ++iBin) { // Exclude first and last bins as they are total number of analysed and selected events, respectively
mAnalysedTriggers->GetXaxis()->SetBinLabel(iBin - 1, mSelections->GetXaxis()->GetBinLabel(iBin));
}
std::shared_ptr<TH1> selections = histRegistry.add<TH1>((std::to_string(mRunNumber) + "/" + prefix + "Selections").data(), "", o2::framework::HistType::kTH1D, {{mSelections->GetNbinsX(), -0.5, static_cast<double>(mSelections->GetNbinsX() - 0.5)}});
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)}});
for (int iBin{1}; iBin <= mSelections->GetNbinsX(); ++iBin) {
selections->GetXaxis()->SetBinLabel(iBin, mSelections->GetXaxis()->GetBinLabel(iBin));
selections->SetBinContent(iBin, mSelections->GetBinContent(iBin));
selections->SetBinError(iBin, mSelections->GetBinError(iBin));
}
}
if (mScalers && list->FindObject((std::to_string(mRunNumber) + "/" + prefix + "Scalers").data()) == nullptr) {
std::shared_ptr<TH1> scalers = histRegistry.add<TH1>((std::to_string(mRunNumber) + "/" + prefix + "Scalers").data(), "", o2::framework::HistType::kTH1D, {{mScalers->GetNbinsX(), -0.5, static_cast<double>(mScalers->GetNbinsX() - 0.5)}});
if (mScalers) {
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)}});
for (int iBin{1}; iBin <= mScalers->GetNbinsX(); ++iBin) {
scalers->GetXaxis()->SetBinLabel(iBin, mScalers->GetXaxis()->GetBinLabel(iBin));
scalers->SetBinContent(iBin, mScalers->GetBinContent(iBin));
scalers->SetBinError(iBin, mScalers->GetBinError(iBin));
}
}
if (mInspectedTVX && list->FindObject((std::to_string(mRunNumber) + "/" + prefix + "InspectedTVX").data()) == nullptr) {
std::shared_ptr<TH1> inspectedTVX = histRegistry.add<TH1>((std::to_string(mRunNumber) + "/" + prefix + "InspectedTVX").data(), "", o2::framework::HistType::kTH1D, {{mInspectedTVX->GetNbinsX(), -0.5, static_cast<double>(mInspectedTVX->GetNbinsX() - 0.5)}});
if (mInspectedTVX) {
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)}});
for (int iBin{1}; iBin <= mInspectedTVX->GetNbinsX(); ++iBin) {
inspectedTVX->GetXaxis()->SetBinLabel(iBin, mInspectedTVX->GetXaxis()->GetBinLabel(iBin));
inspectedTVX->SetBinContent(iBin, mInspectedTVX->GetBinContent(iBin));
inspectedTVX->SetBinError(iBin, mInspectedTVX->GetBinError(iBin));
}
}
if (mTOIs.size()) {
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)}});
for (size_t i{0}; i < mTOIs.size(); ++i) {
mAnalysedTriggersOfInterest->GetXaxis()->SetBinLabel(i + 1, mTOIs[i].data());
}
}
}

std::vector<int> Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber, uint64_t timestamp, std::string tois, int bcRange)
Expand Down Expand Up @@ -85,12 +106,16 @@ std::vector<int> Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber
// Trim leading and trailing whitespaces from the token
token.erase(0, token.find_first_not_of(" "));
token.erase(token.find_last_not_of(" ") + 1);
int bin = mScalers->GetXaxis()->FindBin(token.c_str()) - 2;
int bin = findBin(mSelections, token) - 2;
mTOIs.push_back(token);
mTOIidx.push_back(bin);
tois = tois.erase(0, pos + 1);
}
mTOIcounts.resize(mTOIs.size(), 0);
LOGF(info, "Zorro initialized for run %d, triggers of interest:", runNumber);
for (size_t i{0}; i < mTOIs.size(); ++i) {
LOGF(info, ">>> %s : %i", mTOIs[i].data(), mTOIidx[i]);
}
return mTOIidx;
}

Expand Down Expand Up @@ -134,6 +159,9 @@ bool Zorro::isSelected(uint64_t bcGlobalId, uint64_t tolerance)
continue;
} else if (mLastResult.test(mTOIidx[i])) {
mTOIcounts[i] += (lastSelectedIdx != mLastSelectedIdx); /// Avoid double counting
if (mAnalysedTriggersOfInterest && lastSelectedIdx != mLastSelectedIdx) {
mAnalysedTriggersOfInterest->Fill(i);
}
return true;
}
}
Expand Down
5 changes: 4 additions & 1 deletion EventFiltering/Zorro.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define EVENTFILTERING_ZORRO_H_

#include <bitset>
#include <memory>
#include <string>
#include <vector>

Expand Down Expand Up @@ -43,7 +44,7 @@ class Zorro
std::bitset<128> fetch(uint64_t bcGlobalId, uint64_t tolerance = 100);
bool isSelected(uint64_t bcGlobalId, uint64_t tolerance = 100);

void populateHistRegistry(o2::framework::HistogramRegistry& histRegistry, std::string prefix = "");
void populateHistRegistry(o2::framework::HistogramRegistry& histRegistry, int runNumber, std::string prefix = "");

TH1D* getScalers() const { return mScalers; }
TH1D* getSelections() const { return mSelections; }
Expand All @@ -58,13 +59,15 @@ class Zorro
private:
std::string mBaseCCDBPath = "Users/m/mpuccio/EventFiltering/OTS/";
int mRunNumber = 0;
int mRunNumberHistos = 0;
int mBCtolerance = 100;
uint64_t mLastBCglobalId = 0;
uint64_t mLastSelectedIdx = 0;
TH1D* mScalers = nullptr;
TH1D* mSelections = nullptr;
TH1D* mInspectedTVX = nullptr;
std::shared_ptr<TH1> mAnalysedTriggers;
std::shared_ptr<TH1> mAnalysedTriggersOfInterest;
std::bitset<128> mLastResult;
std::vector<o2::dataformats::IRFrame> mBCranges;
std::vector<ZorroHelper>* mZorroHelpers = nullptr;
Expand Down