Skip to content

Commit 5835f06

Browse files
authored
DPL Analysis: preliminary work for multiple process() functions (#6019)
1 parent 3aedba1 commit 5835f06

7 files changed

Lines changed: 231 additions & 75 deletions

File tree

Analysis/Tasks/PWGHF/HFDplusToPiKPiCandidateSelector.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,5 @@ struct HFDplusToPiKPiCandidateSelector {
251251
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
252252
{
253253
return WorkflowSpec{
254-
adaptAnalysisTask<HFDplusToPiKPiCandidateSelector>(cfgc, "hf-dplus-topikpi-candidate-selector")};
254+
adaptAnalysisTask<HFDplusToPiKPiCandidateSelector>(cfgc, TaskName{"hf-dplus-topikpi-candidate-selector"})};
255255
}

Analysis/Tutorials/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,9 @@ o2_add_dpl_workflow(multiplicity-event-track-selection
209209
JOB_POOL analysis
210210
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisCore O2::AnalysisDataModel
211211
COMPONENT_NAME AnalysisTutorial)
212+
213+
o2_add_dpl_workflow(multiprocess-example
214+
SOURCES src/multiProcess.cxx
215+
JOB_POOL analysis
216+
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisCore O2::AnalysisDataModel
217+
COMPONENT_NAME AnalysisTutorial)

Analysis/Tutorials/src/histogramsFullTracks.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using namespace o2;
1818
using namespace o2::framework;
1919
using namespace o2::framework::expressions;
2020

21-
struct ATask {
21+
struct EtaAndClsHistograms {
2222
OutputObj<TH2F> etaClsH{TH2F("eta_vs_cls", "#eta vs N_{cls}", 102, -2.01, 2.01, 160, -0.5, 159.5)};
2323

2424
void process(aod::FullTracks const& tracks)
@@ -32,6 +32,6 @@ struct ATask {
3232
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
3333
{
3434
return WorkflowSpec{
35-
adaptAnalysisTask<ATask>(cfgc, TaskName{"eta-and-cls-histograms"}),
35+
adaptAnalysisTask<EtaAndClsHistograms>(cfgc),
3636
};
3737
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
#include "Framework/AnalysisTask.h"
11+
#include "Framework/AnalysisDataModel.h"
12+
#include "AnalysisCore/MC.h"
13+
14+
#include <TH1F.h>
15+
#include <cmath>
16+
17+
using namespace o2;
18+
using namespace o2::framework;
19+
using namespace o2::framework::expressions;
20+
21+
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
22+
{
23+
ConfigParamSpec optionDoMC{"doMC", VariantType::Bool, false, {"Use MC info"}};
24+
workflowOptions.push_back(optionDoMC);
25+
}
26+
27+
#include "Framework/runDataProcessing.h"
28+
29+
namespace
30+
{
31+
inline auto normalize(float a)
32+
{
33+
if (a > M_PI) {
34+
a -= 2 * M_PI;
35+
}
36+
if (a < -M_PI) {
37+
a += 2 * M_PI;
38+
}
39+
return a;
40+
}
41+
} // namespace
42+
43+
// Analysis task with several process functions with different signatures
44+
struct MultipleProcessExample {
45+
HistogramRegistry registry{
46+
"registry",
47+
{
48+
{"etaDiff", ";#eta_{MC} - #eta_{Rec}", {HistType::kTH1F, {{100, -2, 2}}}},
49+
{"phiDiff", ";#phi_{MC} - #phi_{Rec}", {HistType::kTH1F, {{100, -M_PI, M_PI}}}},
50+
{"etaRec", ";#eta_{Rec}", {HistType::kTH1F, {{100, -2, 2}}}},
51+
{"phiRec", ";#phi_{Rec}", {HistType::kTH1F, {{100, 0, 2 * M_PI}}}},
52+
{"etaMC", ";#eta_{MC}", {HistType::kTH1F, {{100, -2, 2}}}},
53+
{"phiMC", ";#phi_{MC}", {HistType::kTH1F, {{100, 0, 2 * M_PI}}}} ///
54+
} ///
55+
};
56+
57+
Filter RecColVtxZ = nabs(aod::collision::posZ) < 10.f;
58+
Filter GenColVtxZ = nabs(aod::mccollision::posZ) < 10.f;
59+
60+
void processRec(soa::Filtered<aod::Collisions>::iterator const& collision, aod::Tracks const& tracks)
61+
{
62+
for (auto& track : tracks) {
63+
registry.fill(HIST("etaRec"), track.eta());
64+
registry.fill(HIST("phiRec"), track.phi());
65+
}
66+
}
67+
68+
void processGen(soa::Filtered<aod::McCollisions>::iterator const& mcCollision, aod::McParticles const& mcParticles)
69+
{
70+
for (auto& particle : mcParticles) {
71+
registry.fill(HIST("etaMC"), particle.eta());
72+
registry.fill(HIST("phiMC"), particle.phi());
73+
}
74+
}
75+
76+
void processResolution(soa::Filtered<soa::Join<aod::Collisions, aod::McCollisionLabels>>::iterator const& collision, soa::Join<aod::Tracks, aod::McTrackLabels> const& tracks, aod::McParticles const& mcParticles, aod::McCollisions const& mcCollisions)
77+
{
78+
LOGF(info, "vtx-z (data) = %f | vtx-z (MC) = %f", collision.posZ(), collision.mcCollision().posZ());
79+
for (auto& track : tracks) {
80+
registry.fill(HIST("etaDiff"), track.mcParticle().eta() - track.eta());
81+
registry.fill(HIST("phiDiff"), normalize(track.mcParticle().phi() - track.phi()));
82+
}
83+
}
84+
};
85+
86+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
87+
{
88+
if (!cfgc.options().get<bool>("doMC")) {
89+
return WorkflowSpec{
90+
// only use rec-level process when MC info is not there
91+
adaptAnalysisTask<MultipleProcessExample>(cfgc, Processes{&MultipleProcessExample::processRec})};
92+
}
93+
return WorkflowSpec{
94+
// use additional process functions when MC info is present
95+
// functions will be executed in the sequence they are listed - allows to use, for example,
96+
// histograms that were filled previously
97+
// produced tables *cannot* be used
98+
// filters will be applied *to all* processes
99+
adaptAnalysisTask<MultipleProcessExample>(cfgc, Processes{&MultipleProcessExample::processRec,
100+
&MultipleProcessExample::processGen,
101+
&MultipleProcessExample::processResolution})};
102+
}

0 commit comments

Comments
 (0)