|
10 | 10 | // or submit itself to any jurisdiction. |
11 | 11 | /// |
12 | 12 | /// \brief Filters are used to select specific rows of a table. |
13 | | -/// \author |
14 | | -/// \since |
| 13 | +/// \author Anton Alkin (anton.alkin@cern.ch) |
| 14 | +/// \file filters.cxx |
15 | 15 |
|
16 | | -#include "Framework/runDataProcessing.h" |
17 | 16 | #include "Framework/AnalysisTask.h" |
| 17 | +#include "Framework/runDataProcessing.h" |
18 | 18 |
|
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 |
| 19 | +#include <string> |
40 | 20 |
|
41 | 21 | using namespace o2; |
42 | 22 | using namespace o2::framework; |
43 | 23 | using namespace o2::framework::expressions; |
44 | 24 |
|
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 | | - |
56 | 25 | // 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 | | - |
62 | | - Configurable<float> ptlow{"ptlow", 0.5f, ""}; |
63 | | - Configurable<float> ptup{"ptup", 2.0f, ""}; |
64 | | - Filter ptFilter_a = aod::track::pt > ptlow; |
65 | | - Filter ptFilter_b = aod::track::pt < ptup; |
| 26 | +struct Filters { |
| 27 | + Configurable<float> ptLow{"ptLow", 0.5f, ""}; |
| 28 | + Configurable<float> ptUp{"ptUp", 2.0f, ""}; |
| 29 | + Filter ptFilterA = aod::track::pt > ptLow; |
| 30 | + Filter ptFilterB = aod::track::pt < ptUp; |
66 | 31 |
|
67 | | - Configurable<float> etalow{"etalow", -1.0f, ""}; |
68 | | - Configurable<float> etaup{"etaup", 1.0f, ""}; |
69 | | - Filter etafilter = (aod::track::eta < etaup) && (aod::track::eta > etalow); |
| 32 | + Configurable<float> etaLow{"etaLow", -1.0f, ""}; |
| 33 | + Configurable<float> etaUp{"etaUp", 1.0f, ""}; |
| 34 | + Filter etafilter = (aod::track::eta < etaUp) && (aod::track::eta > etaLow); |
70 | 35 |
|
71 | | - float philow = 1.0f; |
72 | | - float phiup = 2.0f; |
73 | | - Filter phifilter = (aod::etaphi::nphi < phiup) && (aod::etaphi::nphi > philow); |
| 36 | + Configurable<float> phiLow{"phiLow", 1.0f, "Phi lower limit"}; |
| 37 | + Configurable<float> phiUp{"phiUp", 2.0f, "Phi upper limit"}; |
74 | 38 |
|
75 | 39 | Configurable<float> vtxZ{"vtxZ", 10.f, ""}; |
76 | 40 | Filter posZfilter = nabs(aod::collision::posZ) < vtxZ; |
77 | | - Filter bitwiseFilter = (o2::aod::track::flags & static_cast<uint32_t>(o2::aod::track::TPCrefit)) != 0u; |
| 41 | + Filter bitwiseFilter = (aod::track::flags & static_cast<uint32_t>(o2::aod::track::PVContributor)) == static_cast<uint32_t>(o2::aod::track::PVContributor); |
78 | 42 |
|
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 | | -}; |
| 43 | + // it is now possible to set filters as strings |
| 44 | + // note that column designators need the full prefix, i.e. o2::aod:: |
| 45 | + // configurables can be used with ncfg(type, value, name) |
| 46 | + // where value is the default value |
| 47 | + // name is the full name in JSON, with prefix if there is any |
| 48 | + Configurable<std::string> extraFilter{"extraFilter", "(o2::aod::track::phi < ncfg(float,2.0,phiUp)) && (o2::aod::track::phi > ncfg(float,1.0,phiLow))", "extra filter string"}; |
| 49 | + Filter extraF; |
90 | 50 |
|
91 | | -struct ConsumeExtendedTables { |
92 | | - void process(aod::Collision const&, soa::Join<aod::Tracks, aod::EPhi> const& tracks) |
| 51 | + void init(InitContext&) |
93 | 52 | { |
94 | | - for (auto& track : tracks) { |
95 | | - LOGF(info, "%.3f == %.3f", track.cosphi(), std::cos(track.phi())); |
| 53 | + if (!extraFilter->empty()) { |
| 54 | + // string-based filters need to be assigned in init() |
| 55 | + extraF = Parser::parse(extraFilter); |
96 | 56 | } |
97 | 57 | } |
98 | | -}; |
99 | 58 |
|
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) |
| 59 | + // process only collisions and tracks which pass all defined filter criteria |
| 60 | + void process(soa::Filtered<aod::Collisions>::iterator const& collision, soa::Filtered<soa::Join<aod::TracksIU, aod::TracksExtra>> const& tracks) |
104 | 61 | { |
105 | | - for (auto& track : tracks) { |
106 | | - LOGF(info, "%.3f == %.3f", track.spt(), std::abs(track.sigma1Pt() / track.signed1Pt())); |
| 62 | + LOGF(info, "Collision: %d [N = %d out of %d], -%.1f < %.3f < %.1f", |
| 63 | + collision.globalIndex(), tracks.size(), tracks.tableSize(), (float)vtxZ, collision.posZ(), (float)vtxZ); |
| 64 | + for (auto const& track : tracks) { |
| 65 | + LOGP(info, "id = {}; eta: {} < {} < {}; phi: {} < {} < {}; pt: {} < {} < {}", |
| 66 | + track.collisionId(), (float)etaLow, track.eta(), (float)etaUp, (float)phiLow, track.phi(), (float)phiUp, (float)ptLow, track.pt(), (float)ptUp); |
107 | 67 | } |
108 | 68 | } |
109 | 69 | }; |
110 | 70 |
|
111 | 71 | WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
112 | 72 | { |
113 | | - return WorkflowSpec{ |
114 | | - adaptAnalysisTask<ProduceTPhi>(cfgc), |
115 | | - adaptAnalysisTask<SpawnExtendedTables>(cfgc), |
116 | | - adaptAnalysisTask<ConsumeExtendedTables>(cfgc), |
117 | | - adaptAnalysisTask<FilterTracks>(cfgc), |
118 | | - }; |
| 73 | + return {adaptAnalysisTask<Filters>(cfgc)}; |
119 | 74 | } |
0 commit comments