Skip to content

Commit 41aa7c3

Browse files
committed
Allow reconstruction of subset PVs
Macro selectPVIRFrames.C writes out IRFrames for found selected PVs. Steer reading and selection of pushed ITS/MFT data via "--ir-frames-files irFrames.root --ir-frames-extra-margin 594 --its-select-ir-frames " Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 597254c commit 41aa7c3

10 files changed

Lines changed: 117 additions & 25 deletions

File tree

Common/Utils/include/CommonUtils/IRFrameSelector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class IRFrameSelector
3939
}
4040

4141
void clear();
42-
size_t loadIRFrames(const std::string& fname);
42+
size_t loadIRFrames(const std::string& fname, size_t margin = 0);
4343
void applyMargins(size_t bwd, size_t fwd, long shift, bool removeOverlaps = true);
4444
void print(bool lst = false) const;
4545

Common/Utils/src/IRFrameSelector.cxx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ long IRFrameSelector::check(o2::dataformats::IRFrame fr, size_t bwd, size_t fwd)
100100
return ans;
101101
}
102102

103-
size_t IRFrameSelector::loadIRFrames(const std::string& fname)
103+
size_t IRFrameSelector::loadIRFrames(const std::string& fname, size_t margin)
104104
{
105105
// read IRFrames to filter from the file
106106
std::unique_ptr<TFile> tfl(TFile::Open(fname.c_str()));
@@ -155,15 +155,14 @@ size_t IRFrameSelector::loadIRFrames(const std::string& fname)
155155
toBeSorted = true;
156156
}
157157
}
158-
158+
if (!done) {
159+
LOGP(fatal, "Did not find neither tree nor vector of IRFrames in {}", fname);
160+
}
159161
if (toBeSorted) {
160162
LOGP(info, "Sorting {} IRFrames", mOwnList.size());
161163
std::sort(mOwnList.begin(), mOwnList.end(), [](const auto& a, const auto& b) { return a.getMin() < b.getMin(); });
162164
}
163-
if (!true) {
164-
LOGP(fatal, "Did not find neither tree nor vector of IRFrames in {}", fname);
165-
}
166-
setSelectedIRFrames(mOwnList);
165+
setSelectedIRFrames(mOwnList, margin, margin);
167166
return mOwnList.size();
168167
}
169168

Detectors/CTF/workflow/include/CTFWorkflow/CTFReaderSpec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct CTFReaderInp {
3232
std::string remoteRegex{};
3333
std::string metricChannel{};
3434
std::string fileIRFrames{};
35+
uint32_t selectIRFramesExtraBCMargin = 0;
3536
std::string fileRunTimeSpans{};
3637
std::string dictOpt{};
3738
std::vector<int> ctfIDs{};

Detectors/CTF/workflow/src/CTFReaderSpec.cxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,9 @@ void CTFReaderSpec::init(InitContext& ic)
177177
mFileFetcher->setFailThreshold(ic.options().get<float>("fetch-failure-threshold"));
178178
mFileFetcher->start();
179179
if (!mInput.fileIRFrames.empty()) {
180-
mIRFrameSelector.loadIRFrames(mInput.fileIRFrames);
181-
const auto& hbfu = o2::raw::HBFUtils::Instance();
182-
mTFLength = hbfu.nHBFPerTF;
183-
LOGP(info, "IRFrames will be selected from {}, assumed TF length: {} HBF", mInput.fileIRFrames, mTFLength);
180+
mIRFrameSelector.loadIRFrames(mInput.fileIRFrames, mInput.selectIRFramesExtraBCMargin);
181+
mTFLength = o2::raw::HBFUtils::Instance().nHBFPerTF;
182+
LOGP(info, "IRFrames will be selected from {} with {} margin, assumed TF length: {} HBF", mInput.fileIRFrames, mInput.selectIRFramesExtraBCMargin, mTFLength);
184183
mIFRamesOut = true;
185184
}
186185
if (!mInput.fileRunTimeSpans.empty()) {

Detectors/CTF/workflow/src/ctf-reader-workflow.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
7070
options.push_back(ConfigParamSpec{"ctf-data-subspec", VariantType::Int, 0, {"subspec to use for decoded CTF messages (use non-0 if CTF writer will be attached downstream)"}});
7171
options.push_back(ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}});
7272
options.push_back(ConfigParamSpec{"ir-frames-files", VariantType::String, "", {"If non empty, inject selected IRFrames from this file"}});
73+
options.push_back(ConfigParamSpec{"ir-frames-extra-margin", VariantType::UInt32, uint32_t(0), {"Impose additional FWD/BWD BC margin on selected IRFrames"}});
7374
options.push_back(ConfigParamSpec{"run-time-span-file", VariantType::String, "", {"If non empty, inject selected IRFrames from this text file (run, min/max orbit or unix time)"}});
7475
options.push_back(ConfigParamSpec{"skip-skimmed-out-tf", VariantType::Bool, false, {"Do not process TFs with empty IR-Frame coverage"}});
7576
options.push_back(ConfigParamSpec{"invert-irframe-selection", VariantType::Bool, false, {"Select only frames mentioned in ir-frames-file (skip-skimmed-out-tf applied to TF not selected!)"}});
7677
//
7778
options.push_back(ConfigParamSpec{"its-digits", VariantType::Bool, false, {"convert ITS clusters to digits"}});
79+
options.push_back(ConfigParamSpec{"its-select-ir-frames", VariantType::Bool, false, {"select ITS rofs matching ITFrames"}});
7880
options.push_back(ConfigParamSpec{"mft-digits", VariantType::Bool, false, {"convert MFT clusters to digits"}});
81+
options.push_back(ConfigParamSpec{"mft-select-ir-frames", VariantType::Bool, false, {"select ITS rofs matching ITFrames"}});
7982
//
8083
options.push_back(ConfigParamSpec{"emcal-decoded-subspec", VariantType::Int, 0, {"subspec to use for decoded EMCAL data"}});
8184
//
@@ -134,6 +137,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
134137
ctfInput.sup0xccdb = !configcontext.options().get<bool>("send-diststf-0xccdb");
135138
ctfInput.minSHM = std::stoul(configcontext.options().get<std::string>("timeframes-shm-limit"));
136139
ctfInput.fileIRFrames = configcontext.options().get<std::string>("ir-frames-files");
140+
ctfInput.selectIRFramesExtraBCMargin = configcontext.options().get<uint32_t>("ir-frames-extra-margin");
137141
ctfInput.fileRunTimeSpans = configcontext.options().get<std::string>("run-time-span-file");
138142
ctfInput.skipSkimmedOutTF = configcontext.options().get<bool>("skip-skimmed-out-tf");
139143
ctfInput.invertIRFramesSelection = configcontext.options().get<bool>("invert-irframe-selection");
@@ -145,7 +149,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
145149
if (rateLimitingIPCID > -1 && !chanFmt.empty()) {
146150
ctfInput.metricChannel = fmt::format(fmt::runtime(chanFmt), o2::framework::ChannelSpecHelpers::defaultIPCFolder(), rateLimitingIPCID);
147151
}
148-
if (!ctfInput.fileRunTimeSpans.empty()) {
152+
if (!ctfInput.fileRunTimeSpans.empty() || !ctfInput.fileIRFrames.empty()) {
149153
ctfInput.skipSkimmedOutTF = true;
150154
}
151155
if (!ctfInput.fileIRFrames.empty() && !ctfInput.fileRunTimeSpans.empty()) {
@@ -190,11 +194,11 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
190194
// add decoders for all allowed detectors.
191195
if (ctfInput.detMask[DetID::ITS]) {
192196
bool doStag = o2::itsmft::DPLAlpideParamInitializer::isITSStaggeringEnabled(configcontext);
193-
addSpecs(o2::itsmft::getITSEntropyDecoderSpec(verbosity, doStag, configcontext.options().get<bool>("its-digits"), ctfInput.subspec, ctfInput.dictOpt));
197+
addSpecs(o2::itsmft::getITSEntropyDecoderSpec(verbosity, doStag, configcontext.options().get<bool>("its-digits"), configcontext.options().get<bool>("its-select-ir-frames"), ctfInput.subspec, ctfInput.dictOpt));
194198
}
195199
if (ctfInput.detMask[DetID::MFT]) {
196200
bool doStag = o2::itsmft::DPLAlpideParamInitializer::isMFTStaggeringEnabled(configcontext);
197-
addSpecs(o2::itsmft::getMFTEntropyDecoderSpec(verbosity, doStag, configcontext.options().get<bool>("mft-digits"), ctfInput.subspec, ctfInput.dictOpt));
201+
addSpecs(o2::itsmft::getMFTEntropyDecoderSpec(verbosity, doStag, configcontext.options().get<bool>("mft-digits"), configcontext.options().get<bool>("mft-select-ir-frames"), ctfInput.subspec, ctfInput.dictOpt));
198202
}
199203
if (ctfInput.detMask[DetID::TPC]) {
200204
addSpecs(o2::tpc::getEntropyDecoderSpec(verbosity, ctfInput.subspec, ctfInput.dictOpt));

Detectors/GlobalTracking/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ if (OpenMP_CXX_FOUND)
7474
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)
7575
target_link_libraries(${targetName} PRIVATE OpenMP::OpenMP_CXX)
7676
endif()
77+
78+
add_subdirectory(macros)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2019-2026 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+
o2_add_test_root_macro(selectPVIRFrames.C
13+
PUBLIC_LINK_LIBRARIES O2::GlobalTracking
14+
LABELS glo)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2019-2026 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+
/// \file selectPVIRFrames.C
13+
/// \brief Macro to select IRFrames for specific vertices
14+
15+
#if !defined(__CLING__) || defined(__ROOTCLING__)
16+
#include <algorithm>>
17+
#include <vector>
18+
19+
#include <TFile.h>
20+
#include <TTree.h>
21+
22+
#include "ReconstructionDataFormats/PrimaryVertex.h"
23+
#include "CommonDataFormat/IRFrame.h"
24+
#endif
25+
26+
void selectPVIRFrames(const char* fName = "o2_primary_vertex.root")
27+
{
28+
auto fPVs = TFile::Open(fName);
29+
TTree* tPVs = (TTree*)fPVs->Get("o2sim");
30+
std::vector<o2::dataformats::PrimaryVertex> pvArr, *pvArrPtr{&pvArr};
31+
tPVs->SetBranchAddress("PrimaryVertex", &pvArrPtr);
32+
std::vector<o2::dataformats::IRFrame> irFrames;
33+
for (Long64_t iEntry{0}; tPVs->LoadTree(iEntry) >= 0; ++iEntry) {
34+
tPVs->GetEntry(iEntry);
35+
for (const auto& pv : pvArr) {
36+
// make selection of pvs
37+
if (pv.getNContributors() > 3000) {
38+
irFrames.emplace_back(pv.getIRMin(), pv.getIRMax());
39+
}
40+
}
41+
}
42+
// sort to make sure they are in the correct order
43+
std::sort(irFrames.begin(), irFrames.end(), [](const auto& a, const auto& b) { return a.getMin() < b.getMin(); });
44+
printf("Selected %zu irFrames\n", irFrames.size());
45+
auto fIRFrames = TFile::Open("irFrames.root", "RECREATE");
46+
fIRFrames->WriteObjectAny(&irFrames, "std::vector<o2::dataformats::IRFrame>", "irframes");
47+
fIRFrames->Close();
48+
}

Detectors/ITSMFT/common/workflow/include/ITSMFTWorkflow/EntropyDecoderSpec.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template <int N>
3333
class EntropyDecoderSpec : public o2::framework::Task
3434
{
3535
public:
36-
EntropyDecoderSpec(int verbosity, bool doStag, bool getDigits = false, const std::string& ctfdictOpt = "none");
36+
EntropyDecoderSpec(int verbosity, bool doStag, bool selectIRFrames, bool getDigits = false, const std::string& ctfdictOpt = "none");
3737
~EntropyDecoderSpec() override = default;
3838
void init(o2::framework::InitContext& ic) final;
3939
void run(o2::framework::ProcessingContext& pc) final;
@@ -51,6 +51,7 @@ class EntropyDecoderSpec : public o2::framework::Task
5151
const NoiseMap* mNoiseMap = nullptr;
5252
LookUp mPattIdConverter;
5353
bool mDoStaggering{false};
54+
bool mSelectIRFrames{false};
5455
bool mGetDigits{false};
5556
bool mMaskNoise{false};
5657
bool mUseClusterDictionary{true};
@@ -60,8 +61,8 @@ class EntropyDecoderSpec : public o2::framework::Task
6061
};
6162

6263
/// create a processor spec
63-
framework::DataProcessorSpec getITSEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, unsigned int sspec, const std::string& ctfdictOpt);
64-
framework::DataProcessorSpec getMFTEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, unsigned int sspec, const std::string& ctfdictOpt);
64+
framework::DataProcessorSpec getITSEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, bool selectIRFrames, unsigned int sspec, const std::string& ctfdictOpt);
65+
framework::DataProcessorSpec getMFTEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, bool selectIRFrames, unsigned int sspec, const std::string& ctfdictOpt);
6566

6667
} // namespace itsmft
6768
} // namespace o2

Detectors/ITSMFT/common/workflow/src/EntropyDecoderSpec.cxx

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ std::string EntropyDecoderSpec<N>::getBinding(const std::string& name, int spec)
3737
}
3838

3939
template <int N>
40-
EntropyDecoderSpec<N>::EntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, const std::string& ctfdictOpt)
41-
: mCTFCoder(o2::ctf::CTFCoderBase::OpType::Decoder, doStag, ctfdictOpt), mDoStaggering(doStag), mGetDigits(getDigits)
40+
EntropyDecoderSpec<N>::EntropyDecoderSpec(int verbosity, bool doStag, bool selectIRFrames, bool getDigits, const std::string& ctfdictOpt)
41+
: mCTFCoder(o2::ctf::CTFCoderBase::OpType::Decoder, doStag, ctfdictOpt), mDoStaggering(doStag), mSelectIRFrames(selectIRFrames), mGetDigits(getDigits)
4242
{
4343
mTimer.Stop();
4444
mTimer.Reset();
@@ -96,6 +96,27 @@ void EntropyDecoderSpec<N>::run(ProcessingContext& pc)
9696
}
9797
ndigcl += compcl.size();
9898
}
99+
if (mSelectIRFrames) {
100+
int nSelected{0};
101+
/// mask ROF entries not matching with selected IRFrames
102+
auto irFrames = pc.inputs().get<std::vector<o2::dataformats::IRFrame>>("selIRFrames");
103+
for (auto& rof : rofs) {
104+
bool masked = true;
105+
for (const auto& irFrame : irFrames) {
106+
const auto irStart = rof.getBCData(), irEnd = irStart + DPLAlpideParam<N>::Instance().getROFLengthInBC(iLayer);
107+
o2::dataformats::IRFrame irROF(irStart, irEnd);
108+
if (irFrame.isOutside(irROF) == o2::dataformats::IRFrame::Relation::Inside) {
109+
++nSelected;
110+
masked = false;
111+
break;
112+
}
113+
}
114+
if (masked) {
115+
rof.setNEntries(0);
116+
}
117+
}
118+
LOGP(info, "Selected {} out of {} rofs", nSelected, rofs.size());
119+
}
99120
}
100121
pc.outputs().snapshot({nm + "ctfrep", 0}, iosize);
101122
mTimer.Stop();
@@ -149,7 +170,7 @@ void EntropyDecoderSpec<N>::finaliseCCDB(o2::framework::ConcreteDataMatcher& mat
149170
}
150171

151172
template <int N>
152-
DataProcessorSpec getEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, unsigned int sspec, const std::string& ctfdictOpt)
173+
DataProcessorSpec getEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, bool selectIRFrames, unsigned int sspec, const std::string& ctfdictOpt)
153174
{
154175
constexpr o2::header::DataOrigin Origin{N == o2::detectors::DetID::ITS ? o2::header::gDataOriginITS : o2::header::gDataOriginMFT};
155176
constexpr o2::detectors::DetID ID{N == o2::detectors::DetID::ITS ? o2::detectors::DetID::ITS : o2::detectors::DetID::MFT};
@@ -181,25 +202,28 @@ DataProcessorSpec getEntropyDecoderSpec(int verbosity, bool doStag, bool getDigi
181202
inputs.emplace_back(std::string{"ctfdict_"} + ID.getName(), Origin, "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec(fmt::format("{}/Calib/CTFDictionaryTree", Origin.as<std::string>())));
182203
}
183204
inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/TriggerOffsets"));
205+
if (selectIRFrames) {
206+
inputs.emplace_back("selIRFrames", "CTF", "SELIRFRAMES", Lifetime::Timeframe);
207+
}
184208

185209
return DataProcessorSpec{
186210
Origin == o2::header::gDataOriginITS ? "its-entropy-decoder" : "mft-entropy-decoder",
187211
inputs,
188212
outputs,
189-
AlgorithmSpec{adaptFromTask<EntropyDecoderSpec<N>>(verbosity, doStag, getDigits, ctfdictOpt)},
213+
AlgorithmSpec{adaptFromTask<EntropyDecoderSpec<N>>(verbosity, doStag, selectIRFrames, getDigits, ctfdictOpt)},
190214
Options{{"mask-noise", VariantType::Bool, false, {"apply noise mask to digits or clusters (involves reclusterization)"}},
191215
{"ignore-cluster-dictionary", VariantType::Bool, false, {"do not use cluster dictionary, always store explicit patterns"}},
192216
{"ans-version", VariantType::String, {"version of ans entropy coder implementation to use"}}}};
193217
}
194218

195-
framework::DataProcessorSpec getITSEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, unsigned int sspec, const std::string& ctfdictOpt)
219+
framework::DataProcessorSpec getITSEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, bool selectIRFrames, unsigned int sspec, const std::string& ctfdictOpt)
196220
{
197-
return getEntropyDecoderSpec<o2::detectors::DetID::ITS>(verbosity, doStag, getDigits, sspec, ctfdictOpt);
221+
return getEntropyDecoderSpec<o2::detectors::DetID::ITS>(verbosity, doStag, getDigits, selectIRFrames, sspec, ctfdictOpt);
198222
}
199223

200-
framework::DataProcessorSpec getMFTEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, unsigned int sspec, const std::string& ctfdictOpt)
224+
framework::DataProcessorSpec getMFTEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, bool selectIRFrames, unsigned int sspec, const std::string& ctfdictOpt)
201225
{
202-
return getEntropyDecoderSpec<o2::detectors::DetID::MFT>(verbosity, doStag, getDigits, sspec, ctfdictOpt);
226+
return getEntropyDecoderSpec<o2::detectors::DetID::MFT>(verbosity, doStag, getDigits, selectIRFrames, sspec, ctfdictOpt);
203227
}
204228

205229
} // namespace itsmft

0 commit comments

Comments
 (0)