From 3579bdb3a593cd96696e3c8ef764b7bc0d06bcd8 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Wed, 20 Aug 2025 10:43:18 +0200 Subject: [PATCH 1/6] Tutorials: simplify and update filters tutorial --- Tutorials/src/filters.cxx | 89 ++++++++++----------------------------- 1 file changed, 22 insertions(+), 67 deletions(-) diff --git a/Tutorials/src/filters.cxx b/Tutorials/src/filters.cxx index a3c590b8bfd..214b121fdc3 100644 --- a/Tutorials/src/filters.cxx +++ b/Tutorials/src/filters.cxx @@ -16,49 +16,12 @@ #include "Framework/runDataProcessing.h" #include "Framework/AnalysisTask.h" -namespace o2::aod -{ -namespace etaphi -{ -DECLARE_SOA_COLUMN(NPhi, nphi, float); -DECLARE_SOA_EXPRESSION_COLUMN(CosPhi, cosphi, float, - ncos(aod::etaphi::nphi)); -} // namespace etaphi -namespace track -{ -DECLARE_SOA_EXPRESSION_COLUMN(SPt, spt, float, - nabs(aod::track::sigma1Pt / aod::track::signed1Pt)); -} -DECLARE_SOA_TABLE(TPhi, "AOD", "TPHI", - etaphi::NPhi); -DECLARE_SOA_EXTENDED_TABLE_USER(EPhi, TPhi, "EPHI", - aod::etaphi::CosPhi); -using etracks = soa::Join; -DECLARE_SOA_EXTENDED_TABLE_USER(MTracks, etracks, "MTRACK", - aod::track::SPt); -} // namespace o2::aod - using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; -// production of table o2::aod::TPhi -struct ProduceTPhi { - Produces tphi; - void process(aod::Tracks const& tracks) - { - for (auto& track : tracks) { - tphi(track.phi()); - } - } -}; - // Apply filters on Collisions, Tracks, and TPhi -struct SpawnExtendedTables { - // spawn the extended tables - Spawns ephi; - Spawns mtrk; - +struct FilteringDemo { Configurable ptlow{"ptlow", 0.5f, ""}; Configurable ptup{"ptup", 2.0f, ""}; Filter ptFilter_a = aod::track::pt > ptlow; @@ -68,42 +31,37 @@ struct SpawnExtendedTables { Configurable etaup{"etaup", 1.0f, ""}; Filter etafilter = (aod::track::eta < etaup) && (aod::track::eta > etalow); - float philow = 1.0f; - float phiup = 2.0f; - Filter phifilter = (aod::etaphi::nphi < phiup) && (aod::etaphi::nphi > philow); + Configurable philow{"phiLow", 1.0f, "Phi lower limit"}; + Configurable phiup{"phiUp", 2.0f, "Phi upper limit"}; Configurable vtxZ{"vtxZ", 10.f, ""}; Filter posZfilter = nabs(aod::collision::posZ) < vtxZ; - Filter bitwiseFilter = (o2::aod::track::flags & static_cast(o2::aod::track::TPCrefit)) != 0u; + Filter bitwiseFilter = (aod::track::flags & static_cast(o2::aod::track::PVContributor)) == static_cast(o2::aod::track::PVContributor); - // process only collisions and tracks which pass all defined filter criteria - void process(soa::Filtered::iterator const& collision, soa::Filtered> const& tracks) - { - LOGF(info, "Collision: %d [N = %d out of %d], -%.1f < %.3f < %.1f", - collision.globalIndex(), tracks.size(), tracks.tableSize(), (float)vtxZ, collision.posZ(), (float)vtxZ); - for (auto& track : tracks) { - LOGF(info, "id = %d; eta: %.3f < %.3f < %.3f; phi: %.3f < %.3f < %.3f; pt: %.3f < %.3f < %.3f", - track.collisionId(), (float)etalow, track.eta(), (float)etaup, philow, track.nphi(), phiup, (float)ptlow, track.pt(), (float)ptup); - } - } -}; + // it is now possible to set filters as strings + // note that column designators need the full prefix, i.e. o2::aod:: + // configurables can be used with ncfg(type, value, name) + // where value is the default value + // name is the full name in JSON, with prefix if there is any + Configurable extraFilter{"extra-filter","(o2::aod::track::phi < ncfg(float,2.0,phiUp)) && (o2::aod::track::phi > ncfg(float,1.0,phiLow))","extra filter string"}; + Filter extraF; -struct ConsumeExtendedTables { - void process(aod::Collision const&, soa::Join const& tracks) + void init(InitContext&) { - for (auto& track : tracks) { - LOGF(info, "%.3f == %.3f", track.cosphi(), std::cos(track.phi())); + if (!extraFilter->empty()) { + // string-based filters need to be assigned in init() + extraF = Parser::parse(extraFilter); } } -}; -// tracks which are not tracklets -struct FilterTracks { - Filter notTracklet = aod::track::trackType != static_cast(aod::track::TrackTypeEnum::Run2Tracklet); - void process(aod::Collision const&, soa::Filtered const& tracks) + // process only collisions and tracks which pass all defined filter criteria + void process(soa::Filtered::iterator const& collision, soa::Filtered> const& tracks) { + LOGF(info, "Collision: %d [N = %d out of %d], -%.1f < %.3f < %.1f", + collision.globalIndex(), tracks.size(), tracks.tableSize(), (float)vtxZ, collision.posZ(), (float)vtxZ); for (auto& track : tracks) { - LOGF(info, "%.3f == %.3f", track.spt(), std::abs(track.sigma1Pt() / track.signed1Pt())); + LOGP(info, "id = {}; eta: {} < {} < {}; phi: {} < {} < {}; pt: {} < {} < {}", + track.collisionId(), (float)etalow, track.eta(), (float)etaup, (float)philow, track.phi(), (float)phiup, (float)ptlow, track.pt(), (float)ptup); } } }; @@ -111,9 +69,6 @@ struct FilterTracks { WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { return WorkflowSpec{ - adaptAnalysisTask(cfgc), - adaptAnalysisTask(cfgc), - adaptAnalysisTask(cfgc), - adaptAnalysisTask(cfgc), + adaptAnalysisTask(cfgc) }; } From ece90f4b3c38dfaac9c81cda82f4784263f43a67 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Wed, 20 Aug 2025 10:52:25 +0200 Subject: [PATCH 2/6] linter nitpicks --- Tutorials/src/filters.cxx | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Tutorials/src/filters.cxx b/Tutorials/src/filters.cxx index 214b121fdc3..eb538f6589e 100644 --- a/Tutorials/src/filters.cxx +++ b/Tutorials/src/filters.cxx @@ -10,8 +10,8 @@ // or submit itself to any jurisdiction. /// /// \brief Filters are used to select specific rows of a table. -/// \author -/// \since +/// \author Anton Alkin (anton.alkin@cern.ch) +/// \file filters.cxx #include "Framework/runDataProcessing.h" #include "Framework/AnalysisTask.h" @@ -21,18 +21,18 @@ using namespace o2::framework; using namespace o2::framework::expressions; // Apply filters on Collisions, Tracks, and TPhi -struct FilteringDemo { - Configurable ptlow{"ptlow", 0.5f, ""}; - Configurable ptup{"ptup", 2.0f, ""}; - Filter ptFilter_a = aod::track::pt > ptlow; - Filter ptFilter_b = aod::track::pt < ptup; +struct Filters { + Configurable ptLow{"ptLow", 0.5f, ""}; + Configurable ptUp{"ptUp", 2.0f, ""}; + Filter ptFilterA = aod::track::pt > ptLow; + Filter ptFilterB = aod::track::pt < ptUp; - Configurable etalow{"etalow", -1.0f, ""}; - Configurable etaup{"etaup", 1.0f, ""}; - Filter etafilter = (aod::track::eta < etaup) && (aod::track::eta > etalow); + Configurable etaLow{"etaLow", -1.0f, ""}; + Configurable etaUp{"etaUp", 1.0f, ""}; + Filter etafilter = (aod::track::eta < etaUp) && (aod::track::eta > etaLow); - Configurable philow{"phiLow", 1.0f, "Phi lower limit"}; - Configurable phiup{"phiUp", 2.0f, "Phi upper limit"}; + Configurable phiLow{"phiLow", 1.0f, "Phi lower limit"}; + Configurable phiUp{"phiUp", 2.0f, "Phi upper limit"}; Configurable vtxZ{"vtxZ", 10.f, ""}; Filter posZfilter = nabs(aod::collision::posZ) < vtxZ; @@ -43,7 +43,7 @@ struct FilteringDemo { // configurables can be used with ncfg(type, value, name) // where value is the default value // name is the full name in JSON, with prefix if there is any - Configurable extraFilter{"extra-filter","(o2::aod::track::phi < ncfg(float,2.0,phiUp)) && (o2::aod::track::phi > ncfg(float,1.0,phiLow))","extra filter string"}; + Configurable extraFilter{"extraFilter","(o2::aod::track::phi < ncfg(float,2.0,phiUp)) && (o2::aod::track::phi > ncfg(float,1.0,phiLow))","extra filter string"}; Filter extraF; void init(InitContext&) @@ -59,9 +59,9 @@ struct FilteringDemo { { LOGF(info, "Collision: %d [N = %d out of %d], -%.1f < %.3f < %.1f", collision.globalIndex(), tracks.size(), tracks.tableSize(), (float)vtxZ, collision.posZ(), (float)vtxZ); - for (auto& track : tracks) { + for (auto const& track : tracks) { LOGP(info, "id = {}; eta: {} < {} < {}; phi: {} < {} < {}; pt: {} < {} < {}", - track.collisionId(), (float)etalow, track.eta(), (float)etaup, (float)philow, track.phi(), (float)phiup, (float)ptlow, track.pt(), (float)ptup); + track.collisionId(), (float)etaLow, track.eta(), (float)etaUp, (float)phiLow, track.phi(), (float)phiUp, (float)ptLow, track.pt(), (float)ptUp); } } }; @@ -69,6 +69,6 @@ struct FilteringDemo { WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { return WorkflowSpec{ - adaptAnalysisTask(cfgc) + adaptAnalysisTask(cfgc) }; } From 00fe9a633317b5f98f5df7a90af4347e28adc675 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Wed, 20 Aug 2025 10:56:15 +0200 Subject: [PATCH 3/6] clang-format --- Tutorials/src/filters.cxx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Tutorials/src/filters.cxx b/Tutorials/src/filters.cxx index eb538f6589e..af9c084b5aa 100644 --- a/Tutorials/src/filters.cxx +++ b/Tutorials/src/filters.cxx @@ -43,7 +43,7 @@ struct Filters { // configurables can be used with ncfg(type, value, name) // where value is the default value // name is the full name in JSON, with prefix if there is any - Configurable extraFilter{"extraFilter","(o2::aod::track::phi < ncfg(float,2.0,phiUp)) && (o2::aod::track::phi > ncfg(float,1.0,phiLow))","extra filter string"}; + Configurable extraFilter{"extraFilter", "(o2::aod::track::phi < ncfg(float,2.0,phiUp)) && (o2::aod::track::phi > ncfg(float,1.0,phiLow))", "extra filter string"}; Filter extraF; void init(InitContext&) @@ -68,7 +68,5 @@ struct Filters { WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { - return WorkflowSpec{ - adaptAnalysisTask(cfgc) - }; + return {adaptAnalysisTask(cfgc)}; } From cb8c13698e3e1c87d0534bf600995435212e1d29 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Wed, 20 Aug 2025 11:02:08 +0200 Subject: [PATCH 4/6] megalinter complaints --- Tutorials/src/filters.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tutorials/src/filters.cxx b/Tutorials/src/filters.cxx index af9c084b5aa..ecd3edf113d 100644 --- a/Tutorials/src/filters.cxx +++ b/Tutorials/src/filters.cxx @@ -13,6 +13,8 @@ /// \author Anton Alkin (anton.alkin@cern.ch) /// \file filters.cxx +#include + #include "Framework/runDataProcessing.h" #include "Framework/AnalysisTask.h" From 318bacf112ee1c09c05bff212eba6c654d5714c3 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Wed, 20 Aug 2025 11:05:24 +0200 Subject: [PATCH 5/6] what --- Tutorials/src/filters.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tutorials/src/filters.cxx b/Tutorials/src/filters.cxx index ecd3edf113d..a7e4c50851d 100644 --- a/Tutorials/src/filters.cxx +++ b/Tutorials/src/filters.cxx @@ -13,11 +13,11 @@ /// \author Anton Alkin (anton.alkin@cern.ch) /// \file filters.cxx -#include - #include "Framework/runDataProcessing.h" #include "Framework/AnalysisTask.h" +#include + using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; From 125beec87a062412d21b5af36b6d7b9fff39ba2a Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Wed, 20 Aug 2025 11:06:54 +0200 Subject: [PATCH 6/6] what 2 --- Tutorials/src/filters.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tutorials/src/filters.cxx b/Tutorials/src/filters.cxx index a7e4c50851d..7411db8b7ab 100644 --- a/Tutorials/src/filters.cxx +++ b/Tutorials/src/filters.cxx @@ -13,8 +13,8 @@ /// \author Anton Alkin (anton.alkin@cern.ch) /// \file filters.cxx -#include "Framework/runDataProcessing.h" #include "Framework/AnalysisTask.h" +#include "Framework/runDataProcessing.h" #include