Skip to content

Commit 1f2f492

Browse files
mpuccioalibuild
andauthored
Introducing a new util to get the OTS bits (ZORRO) (#6087)
* Introducing a new util to get the OTS bits (ZORRO) * Add copyright notice * Please consider the following formatting changes (#6088) --------- Co-authored-by: ALICE Builder <alibuild@users.noreply.github.com>
1 parent 8f80629 commit 1f2f492

File tree

7 files changed

+285
-5
lines changed

7 files changed

+285
-5
lines changed

EventFiltering/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,11 @@ o2physics_add_dpl_workflow(lf-f1proton-filter
101101
SOURCES PWGLF/filterf1proton.cxx
102102
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DetectorsBase
103103
COMPONENT_NAME Analysis)
104+
105+
o2physics_add_library(EventFilteringUtils
106+
SOURCES Zorro.cxx
107+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore)
108+
109+
o2physics_target_root_dictionary(EventFilteringUtils
110+
HEADERS Zorro.h
111+
LINKDEF EventFilteringUtilsLinkDef.h)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#pragma link off all globals;
13+
#pragma link off all classes;
14+
#pragma link off all functions;
15+
16+
#pragma link C++ class std::vector < std::array < uint64_t, 2>> + ;

EventFiltering/Zorro.cxx

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
//
12+
13+
#include "Zorro.h"
14+
15+
#include <map>
16+
17+
#include "TH1D.h"
18+
19+
#include "CCDB/BasicCCDBManager.h"
20+
#include "CommonDataFormat/InteractionRecord.h"
21+
22+
using o2::InteractionRecord;
23+
24+
std::vector<int> Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber, uint64_t timestamp, std::string tois, int bcRange)
25+
{
26+
if (mRunNumber == runNumber) {
27+
return mTOIidx;
28+
}
29+
mCCDB = ccdb;
30+
mRunNumber = runNumber;
31+
mBCtolerance = bcRange;
32+
std::map<std::string, std::string> metadata;
33+
metadata["runNumber"] = std::to_string(runNumber);
34+
mScalers = mCCDB->getSpecific<TH1D>(mBaseCCDBPath + "FilterCounters", timestamp, metadata);
35+
mSelections = mCCDB->getSpecific<TH1D>(mBaseCCDBPath + "SelectionCounters", timestamp, metadata);
36+
mInspectedTVX = mCCDB->getSpecific<TH1D>(mBaseCCDBPath + "InspectedTVX", timestamp, metadata);
37+
auto selectedBCs = mCCDB->getSpecific<std::vector<std::array<uint64_t, 2>>>(mBaseCCDBPath + "SelectedBCs", timestamp, metadata);
38+
mBCranges.clear();
39+
for (auto bc : *selectedBCs) {
40+
mBCranges.emplace_back(InteractionRecord::long2IR(std::min(bc[0], bc[1])), InteractionRecord::long2IR(std::max(bc[0], bc[1])));
41+
}
42+
std::sort(mBCranges.begin(), mBCranges.end(), [](const auto& a, const auto& b) { return a.getMin() < b.getMin(); });
43+
44+
mSelectionBitMask = mCCDB->getSpecific<std::vector<std::array<uint64_t, 2>>>(mBaseCCDBPath + "SelectionBitMask", timestamp, metadata);
45+
mFilterBitMask = mCCDB->getSpecific<std::vector<std::array<uint64_t, 2>>>(mBaseCCDBPath + "FilterBitMask", timestamp, metadata);
46+
47+
mLastBCglobalId = 0;
48+
mLastSelectedIdx = 0;
49+
mTOIs.clear();
50+
mTOIidx.clear();
51+
size_t pos = 0;
52+
while ((pos = tois.find(",")) != std::string::npos) {
53+
std::string token = tois.substr(0, pos);
54+
// Trim leading and trailing whitespaces from the token
55+
token.erase(0, token.find_first_not_of(" "));
56+
token.erase(token.find_last_not_of(" ") + 1);
57+
int bin = mScalers->GetXaxis()->FindBin(token.c_str()) - 2;
58+
mTOIs.push_back(token);
59+
mTOIidx.push_back(bin);
60+
tois.erase(0, pos + 1);
61+
}
62+
mTOIcounts.resize(mTOIs.size(), 0);
63+
return mTOIidx;
64+
}
65+
66+
std::bitset<128> Zorro::fetch(uint64_t bcGlobalId, uint64_t tolerance)
67+
{
68+
std::bitset<128> result;
69+
o2::dataformats::IRFrame bcFrame{InteractionRecord::long2IR(bcGlobalId) - tolerance, InteractionRecord::long2IR(bcGlobalId) + tolerance};
70+
if (bcGlobalId < mLastBCglobalId) {
71+
mLastSelectedIdx = 0;
72+
}
73+
for (size_t i = mLastSelectedIdx; i < mBCranges.size(); i++) {
74+
if (!bcFrame.getOverlap(mBCranges[i]).isZeroLength()) {
75+
for (int iMask{0}; iMask < 2; ++iMask) {
76+
for (int iTOI{0}; iTOI < 64; ++iTOI) {
77+
result.set(iMask * 64 + iTOI, mFilterBitMask->at(i)[iMask] & (1ull << iTOI));
78+
}
79+
}
80+
mLastSelectedIdx = i;
81+
return result;
82+
}
83+
}
84+
return result;
85+
}
86+
87+
bool Zorro::isSelected(uint64_t bcGlobalId, uint64_t tolerance)
88+
{
89+
int lastSelectedIdx = mLastSelectedIdx;
90+
std::bitset<128> result = fetch(bcGlobalId, tolerance);
91+
for (size_t i{0}; i < mTOIidx.size(); ++i) {
92+
if (mTOIidx[i] < 0) {
93+
continue;
94+
} else if (result.test(mTOIidx[i])) {
95+
mTOIcounts[i] += (lastSelectedIdx != mLastSelectedIdx); /// Avoid double counting
96+
return true;
97+
}
98+
}
99+
return false;
100+
}

EventFiltering/Zorro.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
//
12+
// Zero Obstacles Results Retriever for Offline trigger selections
13+
14+
#ifndef EVENTFILTERING_ZORRO_H_
15+
#define EVENTFILTERING_ZORRO_H_
16+
17+
#include <bitset>
18+
#include <string>
19+
#include <vector>
20+
21+
#include "CommonDataFormat/IRFrame.h"
22+
23+
class TH1D;
24+
namespace o2
25+
{
26+
namespace ccdb
27+
{
28+
class BasicCCDBManager;
29+
};
30+
}; // namespace o2
31+
32+
class Zorro
33+
{
34+
public:
35+
Zorro() = default;
36+
std::vector<int> initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber, uint64_t timestamp, std::string tois, int bcTolerance = 500);
37+
std::bitset<128> fetch(uint64_t bcGlobalId, uint64_t tolerance = 100);
38+
bool isSelected(uint64_t bcGlobalId, uint64_t tolerance = 100);
39+
40+
std::vector<int> getTOIcounters() const { return mTOIcounts; }
41+
42+
void setCCDBpath(std::string path) { mBaseCCDBPath = path; }
43+
void setBaseCCDBPath(std::string path) { mBaseCCDBPath = path; }
44+
void setBCtolerance(int tolerance) { mBCtolerance = tolerance; }
45+
46+
private:
47+
std::string mBaseCCDBPath = "Users/m/mpuccio/EventFiltering/OTS/";
48+
int mRunNumber = 0;
49+
int mBCtolerance = 100;
50+
uint64_t mLastBCglobalId = 0;
51+
uint64_t mLastSelectedIdx = 0;
52+
TH1D* mScalers = nullptr;
53+
TH1D* mSelections = nullptr;
54+
TH1D* mInspectedTVX = nullptr;
55+
std::vector<o2::dataformats::IRFrame> mBCranges;
56+
std::vector<std::array<uint64_t, 2>>* mFilterBitMask = nullptr;
57+
std::vector<std::array<uint64_t, 2>>* mSelectionBitMask = nullptr;
58+
std::vector<std::string> mTOIs;
59+
std::vector<int> mTOIidx;
60+
std::vector<int> mTOIcounts;
61+
o2::ccdb::BasicCCDBManager* mCCDB = nullptr;
62+
};
63+
64+
#endif // EVENTFILTERING_ZORRO_H_
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
//
12+
13+
#include <fstream>
14+
#include <iostream>
15+
#include <vector>
16+
#include <string>
17+
#include <map>
18+
#include <array>
19+
20+
#include <ROOT/RDataFrame.hxx>
21+
#include "TFile.h"
22+
#include "TKey.h"
23+
#include "TH1.h"
24+
25+
#include "CCDB/BasicCCDBManager.h"
26+
27+
const std::string kBaseCCDBPath = "Users/m/mpuccio/EventFiltering/OTS/";
28+
29+
#pragma link C++ class std::vector < std::array < uint64_t, 2>> + ;
30+
31+
void uploadOTSobjects(std::string inputList)
32+
{
33+
o2::ccdb::CcdbApi api;
34+
api.init("http://alice-ccdb.cern.ch");
35+
36+
std::ifstream file(inputList.data());
37+
std::string path;
38+
std::map<std::string, std::string> metadata;
39+
while (std::getline(file, path)) {
40+
auto pos = path.find("/5") + 1; /// in the path at some point there is the run number
41+
const std::string runString = path.substr(pos, 6);
42+
std::cout << "Processing run " << runString << std::endl;
43+
const int runNumber = std::stoi(runString);
44+
metadata["runNumber"] = runString;
45+
std::pair<int64_t, int64_t> duration = o2::ccdb::BasicCCDBManager::getRunDuration(api, runNumber);
46+
duration.first -= 10000; // subtract 3 minutes from the run start
47+
duration.second += 180000; // add 3 minutes to the run duration
48+
TFile scalersFile((path + "AnalysisResults_fullrun.root").data(), "READ");
49+
TH1* scalers = (TH1*)scalersFile.Get("central-event-filter-task/scalers/mScalers");
50+
TH1* filters = (TH1*)scalersFile.Get("central-event-filter-task/scalers/mFiltered");
51+
api.storeAsTFile(scalers, kBaseCCDBPath + "FilterCounters", metadata, duration.first, duration.second);
52+
api.storeAsTFile(filters, kBaseCCDBPath + "SelectionCounters", metadata, duration.first, duration.second);
53+
TH1* hCounterTVX = (TH1*)scalersFile.Get("bc-selection-task/hCounterTVX");
54+
api.storeAsTFile(hCounterTVX, kBaseCCDBPath + "InspectedTVX", metadata, duration.first, duration.second);
55+
56+
std::vector<std::array<uint64_t, 2>> bcRanges, filterBitMask, selectionBitMask;
57+
TFile bcRangesFile((path + "bcRanges_fullrun.root").data(), "READ");
58+
TKey* key;
59+
auto klst = bcRangesFile.GetListOfKeys();
60+
TIter nextkey(klst);
61+
while ((key = (TKey*)nextkey())) {
62+
std::string kcl(key->GetClassName());
63+
if (kcl == "TDirectoryFile") {
64+
ROOT::RDataFrame bcRangesFrame(std::string(key->GetName()) + "/selectedBC", &bcRangesFile);
65+
auto bcAO2D = bcRangesFrame.Take<uint64_t>("bcAO2D");
66+
auto bcEvSel = bcRangesFrame.Take<uint64_t>("bcEvSel");
67+
auto selMask = bcRangesFrame.Take<uint64_t>("selMask");
68+
auto triMask = bcRangesFrame.Take<uint64_t>("triMask");
69+
for (size_t i = 0; i < bcAO2D->size(); i++) {
70+
bcRanges.push_back({bcAO2D->at(i), bcEvSel->at(i)});
71+
filterBitMask.push_back({bcAO2D->at(i), 0ull});
72+
selectionBitMask.push_back({bcAO2D->at(i), 0ull});
73+
}
74+
}
75+
}
76+
api.storeAsTFileAny(&bcRanges, kBaseCCDBPath + "SelectedBCs", metadata, duration.first, duration.second);
77+
api.storeAsTFileAny(&filterBitMask, kBaseCCDBPath + "FilterBitMasks", metadata, duration.first, duration.second);
78+
api.storeAsTFileAny(&selectionBitMask, kBaseCCDBPath + "SelectionBitMasks", metadata, duration.first, duration.second);
79+
}
80+
}

PWGLF/TableProducer/Nuspex/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ o2physics_add_dpl_workflow(lithium4analysis
5151

5252
o2physics_add_dpl_workflow(nuclei-spectra
5353
SOURCES nucleiSpectra.cxx
54-
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DetectorsBase
54+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DetectorsBase O2Physics::EventFilteringUtils
5555
COMPONENT_NAME Analysis)
5656

5757
o2physics_add_dpl_workflow(spectra-derived

PWGLF/TableProducer/Nuspex/nucleiSpectra.cxx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "Common/Core/PID/PIDTOF.h"
3636
#include "Common/TableProducer/PID/pidTOFBase.h"
3737
#include "Common/Core/EventPlaneHelper.h"
38-
#include "PWGLF/DataModel/EPCalibrationTables.h"
3938
#include "Common/DataModel/Qvectors.h"
4039

4140
#include "DataFormatsParameters/GRPMagField.h"
@@ -44,6 +43,8 @@
4443
#include "DetectorsBase/GeometryManager.h"
4544
#include "DetectorsBase/Propagator.h"
4645

46+
#include "EventFiltering/Zorro.h"
47+
4748
#include "Framework/AnalysisDataModel.h"
4849
#include "Framework/AnalysisTask.h"
4950
#include "Framework/ASoAHelpers.h"
@@ -52,6 +53,7 @@
5253

5354
#include "ReconstructionDataFormats/Track.h"
5455

56+
#include "PWGLF/DataModel/EPCalibrationTables.h"
5557
#include "PWGLF/DataModel/LFSlimNucleiTables.h"
5658

5759
#include "TRandom3.h"
@@ -211,6 +213,7 @@ struct nucleiSpectra {
211213
Produces<o2::aod::NucleiTableMC> nucleiTableMC;
212214
Produces<o2::aod::NucleiTableFlow> nucleiTableFlow;
213215
Service<o2::ccdb::BasicCCDBManager> ccdb;
216+
Zorro zorro;
214217

215218
Configurable<bool> cfgCompensatePIDinTracking{"cfgCompensatePIDinTracking", false, "If true, divide tpcInnerParam by the electric charge"};
216219

@@ -254,6 +257,8 @@ struct nucleiSpectra {
254257
ConfigurableAxis cfgNITSClusBins{"cfgNITSClusBins", {3, 4.5, 7.5}, "N ITS clusters binning"};
255258
ConfigurableAxis cfgNTPCClusBins{"cfgNTPCClusBins", {3, 89.5, 159.5}, "N TPC clusters binning"};
256259

260+
Configurable<bool> cfgSkimmedProcessing{"cfgSkimmedProcessing", false, "Skimmed dataset processing"};
261+
257262
// CCDB options
258263
Configurable<int> cfgMaterialCorrection{"cfgMaterialCorrection", static_cast<int>(o2::base::Propagator::MatCorrType::USEMatCorrLUT), "Type of material correction"};
259264
Configurable<std::string> cfgCCDBurl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
@@ -308,7 +313,7 @@ struct nucleiSpectra {
308313

309314
float computeEventPlane(float y, float x)
310315
{
311-
return 0.5 * TMath::ATan2(y, x);
316+
return 0.5 * std::atan2(y, x);
312317
}
313318

314319
template <class collision_t>
@@ -322,6 +327,9 @@ struct nucleiSpectra {
322327
if (mRunNumber == bc.runNumber()) {
323328
return;
324329
}
330+
if (cfgSkimmedProcessing) {
331+
zorro.initCCDB(ccdb.service, bc.runNumber(), bc.timestamp(), "fHe3");
332+
}
325333
auto timestamp = bc.timestamp();
326334
mRunNumber = bc.runNumber();
327335

@@ -548,13 +556,13 @@ struct nucleiSpectra {
548556
if (cfgFlowHist->get(iS) && doprocessDataFlow) {
549557
if constexpr (std::is_same<Tcoll, CollWithEP>::value) {
550558
auto deltaPhiInRange = getPhiInRange(fvector.phi() - collision.psiFT0C());
551-
auto v2 = TMath::Cos(2.0 * deltaPhiInRange);
559+
auto v2 = std::cos(2.0 * deltaPhiInRange);
552560
nuclei::hFlowHists[iC][iS]->Fill(collision.centFT0C(), fvector.pt(), nSigma[0][iS], tofMass, v2, track.itsNCls(), track.tpcNClsFound(), track.hasTRD());
553561
}
554562
} else if (cfgFlowHist->get(iS) && doprocessDataFlowAlternative) {
555563
if constexpr (std::is_same<Tcoll, CollWithQvec>::value) {
556564
auto deltaPhiInRange = getPhiInRange(fvector.phi() - computeEventPlane(collision.qvecFT0CIm(), collision.qvecFT0CRe()));
557-
auto v2 = TMath::Cos(2.0 * deltaPhiInRange);
565+
auto v2 = std::cos(2.0 * deltaPhiInRange);
558566
nuclei::hFlowHists[iC][iS]->Fill(collision.centFT0C(), fvector.pt(), nSigma[0][iS], tofMass, v2, track.itsNCls(), track.tpcNClsFound(), track.hasTRD());
559567
}
560568
}
@@ -617,6 +625,10 @@ struct nucleiSpectra {
617625
if (!eventSelection(collision)) {
618626
return;
619627
}
628+
if (cfgSkimmedProcessing) {
629+
zorro.isSelected(collision.bc_as<aod::BCsWithTimestamps>().globalBC()); /// Just let Zorro do the accounting
630+
}
631+
620632
fillDataInfo(collision, tracks);
621633
for (auto& c : nuclei::candidates) {
622634
nucleiTable(c.pt, c.eta, c.phi, c.tpcInnerParam, c.beta, c.zVertex, c.DCAxy, c.DCAz, c.TPCsignal, c.ITSchi2, c.TPCchi2, c.flags, c.TPCfindableCls, c.TPCcrossedRows, c.ITSclsMap, c.TPCnCls, c.clusterSizesITS);

0 commit comments

Comments
 (0)