Skip to content

Commit 3579bdb

Browse files
committed
Tutorials: simplify and update filters tutorial
1 parent f7f3381 commit 3579bdb

File tree

1 file changed

+22
-67
lines changed

1 file changed

+22
-67
lines changed

Tutorials/src/filters.cxx

Lines changed: 22 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,12 @@
1616
#include "Framework/runDataProcessing.h"
1717
#include "Framework/AnalysisTask.h"
1818

19-
namespace o2::aod
20-
{
21-
namespace etaphi
22-
{
23-
DECLARE_SOA_COLUMN(NPhi, nphi, float);
24-
DECLARE_SOA_EXPRESSION_COLUMN(CosPhi, cosphi, float,
25-
ncos(aod::etaphi::nphi));
26-
} // namespace etaphi
27-
namespace track
28-
{
29-
DECLARE_SOA_EXPRESSION_COLUMN(SPt, spt, float,
30-
nabs(aod::track::sigma1Pt / aod::track::signed1Pt));
31-
}
32-
DECLARE_SOA_TABLE(TPhi, "AOD", "TPHI",
33-
etaphi::NPhi);
34-
DECLARE_SOA_EXTENDED_TABLE_USER(EPhi, TPhi, "EPHI",
35-
aod::etaphi::CosPhi);
36-
using etracks = soa::Join<aod::Tracks, aod::TracksCov>;
37-
DECLARE_SOA_EXTENDED_TABLE_USER(MTracks, etracks, "MTRACK",
38-
aod::track::SPt);
39-
} // namespace o2::aod
40-
4119
using namespace o2;
4220
using namespace o2::framework;
4321
using namespace o2::framework::expressions;
4422

45-
// production of table o2::aod::TPhi
46-
struct ProduceTPhi {
47-
Produces<aod::TPhi> tphi;
48-
void process(aod::Tracks const& tracks)
49-
{
50-
for (auto& track : tracks) {
51-
tphi(track.phi());
52-
}
53-
}
54-
};
55-
5623
// Apply filters on Collisions, Tracks, and TPhi
57-
struct SpawnExtendedTables {
58-
// spawn the extended tables
59-
Spawns<aod::EPhi> ephi;
60-
Spawns<aod::MTracks> mtrk;
61-
24+
struct FilteringDemo {
6225
Configurable<float> ptlow{"ptlow", 0.5f, ""};
6326
Configurable<float> ptup{"ptup", 2.0f, ""};
6427
Filter ptFilter_a = aod::track::pt > ptlow;
@@ -68,52 +31,44 @@ struct SpawnExtendedTables {
6831
Configurable<float> etaup{"etaup", 1.0f, ""};
6932
Filter etafilter = (aod::track::eta < etaup) && (aod::track::eta > etalow);
7033

71-
float philow = 1.0f;
72-
float phiup = 2.0f;
73-
Filter phifilter = (aod::etaphi::nphi < phiup) && (aod::etaphi::nphi > philow);
34+
Configurable<float> philow{"phiLow", 1.0f, "Phi lower limit"};
35+
Configurable<float> phiup{"phiUp", 2.0f, "Phi upper limit"};
7436

7537
Configurable<float> vtxZ{"vtxZ", 10.f, ""};
7638
Filter posZfilter = nabs(aod::collision::posZ) < vtxZ;
77-
Filter bitwiseFilter = (o2::aod::track::flags & static_cast<uint32_t>(o2::aod::track::TPCrefit)) != 0u;
39+
Filter bitwiseFilter = (aod::track::flags & static_cast<uint32_t>(o2::aod::track::PVContributor)) == static_cast<uint32_t>(o2::aod::track::PVContributor);
7840

79-
// process only collisions and tracks which pass all defined filter criteria
80-
void process(soa::Filtered<aod::Collisions>::iterator const& collision, soa::Filtered<soa::Join<aod::Tracks, aod::TPhi>> const& tracks)
81-
{
82-
LOGF(info, "Collision: %d [N = %d out of %d], -%.1f < %.3f < %.1f",
83-
collision.globalIndex(), tracks.size(), tracks.tableSize(), (float)vtxZ, collision.posZ(), (float)vtxZ);
84-
for (auto& track : tracks) {
85-
LOGF(info, "id = %d; eta: %.3f < %.3f < %.3f; phi: %.3f < %.3f < %.3f; pt: %.3f < %.3f < %.3f",
86-
track.collisionId(), (float)etalow, track.eta(), (float)etaup, philow, track.nphi(), phiup, (float)ptlow, track.pt(), (float)ptup);
87-
}
88-
}
89-
};
41+
// it is now possible to set filters as strings
42+
// note that column designators need the full prefix, i.e. o2::aod::
43+
// configurables can be used with ncfg(type, value, name)
44+
// where value is the default value
45+
// name is the full name in JSON, with prefix if there is any
46+
Configurable<std::string> extraFilter{"extra-filter","(o2::aod::track::phi < ncfg(float,2.0,phiUp)) && (o2::aod::track::phi > ncfg(float,1.0,phiLow))","extra filter string"};
47+
Filter extraF;
9048

91-
struct ConsumeExtendedTables {
92-
void process(aod::Collision const&, soa::Join<aod::Tracks, aod::EPhi> const& tracks)
49+
void init(InitContext&)
9350
{
94-
for (auto& track : tracks) {
95-
LOGF(info, "%.3f == %.3f", track.cosphi(), std::cos(track.phi()));
51+
if (!extraFilter->empty()) {
52+
// string-based filters need to be assigned in init()
53+
extraF = Parser::parse(extraFilter);
9654
}
9755
}
98-
};
9956

100-
// tracks which are not tracklets
101-
struct FilterTracks {
102-
Filter notTracklet = aod::track::trackType != static_cast<uint8_t>(aod::track::TrackTypeEnum::Run2Tracklet);
103-
void process(aod::Collision const&, soa::Filtered<aod::MTracks> const& tracks)
57+
// process only collisions and tracks which pass all defined filter criteria
58+
void process(soa::Filtered<aod::Collisions>::iterator const& collision, soa::Filtered<soa::Join<aod::TracksIU, aod::TracksExtra>> const& tracks)
10459
{
60+
LOGF(info, "Collision: %d [N = %d out of %d], -%.1f < %.3f < %.1f",
61+
collision.globalIndex(), tracks.size(), tracks.tableSize(), (float)vtxZ, collision.posZ(), (float)vtxZ);
10562
for (auto& track : tracks) {
106-
LOGF(info, "%.3f == %.3f", track.spt(), std::abs(track.sigma1Pt() / track.signed1Pt()));
63+
LOGP(info, "id = {}; eta: {} < {} < {}; phi: {} < {} < {}; pt: {} < {} < {}",
64+
track.collisionId(), (float)etalow, track.eta(), (float)etaup, (float)philow, track.phi(), (float)phiup, (float)ptlow, track.pt(), (float)ptup);
10765
}
10866
}
10967
};
11068

11169
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
11270
{
11371
return WorkflowSpec{
114-
adaptAnalysisTask<ProduceTPhi>(cfgc),
115-
adaptAnalysisTask<SpawnExtendedTables>(cfgc),
116-
adaptAnalysisTask<ConsumeExtendedTables>(cfgc),
117-
adaptAnalysisTask<FilterTracks>(cfgc),
72+
adaptAnalysisTask<FilteringDemo>(cfgc)
11873
};
11974
}

0 commit comments

Comments
 (0)