-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathhistograms.cxx
More file actions
107 lines (91 loc) · 3.29 KB
/
histograms.cxx
File metadata and controls
107 lines (91 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \brief Both tasks, ATask and BTask create two histograms. But whereas in
/// the first case (ATask) the histograms are not saved to file, this
/// happens automatically if OutputObj<TH1F> is used to create a
/// histogram. By default the histogram is saved to file
/// AnalysisResults.root. HistogramRegistry is yet an other possibility
/// to deal with histograms. See tutorial example histogramRegistery.cxx
/// for details.
/// \author
/// \since
#include "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
using namespace o2;
using namespace o2::framework;
using namespace o2::framework::expressions;
struct RootHistograms {
// normal creation of a histogram
TH1F* phiHA = new TH1F("phiA", "phiA", 100, 0., 2. * M_PI);
TH1F* etaHA = new TH1F("etaA", "etaA", 102, -2.01, 2.01);
void process(aod::Tracks const& tracks)
{
for (auto& track : tracks) {
phiHA->Fill(track.phi());
etaHA->Fill(track.eta());
}
}
};
struct OutputObjects {
// histogram created with OutputObj<TH1F>
OutputObj<TH1F> phiB{TH1F("phiB", "phiB", 100, 0., 2. * M_PI), OutputObjHandlingPolicy::QAObject};
OutputObj<TH2F> etaptB{TH2F("etaptB", "etaptB", 102, -2.01, 2.01, 100, 0.0, 5.0), OutputObjHandlingPolicy::AnalysisObject};
void process(aod::Tracks const& tracks)
{
for (auto& track : tracks) {
phiB->Fill(track.phi());
etaptB->Fill(track.eta(), track.pt());
}
}
};
struct OutputObjSet {
// incomplete definition of an OutputObj
OutputObj<TH1F> trZ{"trZ", OutputObjHandlingPolicy::QAObject};
Filter ptfilter = aod::track::pt > 0.5f;
void init(InitContext const&)
{
// complete the definition of the OutputObj
trZ.setObject(new TH1F("Z", "Z", 100, -10., 10.));
// other options:
// TH1F* t = new TH1F(); trZ.setObject(t); <- resets content!
// TH1F t(); trZ.setObject(t) <- makes a copy
// trZ.setObject({"Z","Z",100,-10.,10.}); <- creates new
}
void process(soa::Filtered<aod::Tracks> const& tracks)
{
for (auto& track : tracks) {
trZ->Fill(track.z());
}
}
};
struct HistRegistry {
// histogram defined with HistogramRegistry
HistogramRegistry registry{
"registry",
{{"phiC", "phiC", {HistType::kTH1F, {{100, 0., 2. * M_PI}}}},
{"etaptC", "etaptC", {HistType::kTH2F, {{102, -2.01, 2.01}, {100, 0.0, 5.0}}}}}};
void process(aod::Tracks const& tracks)
{
for (auto& track : tracks) {
registry.get<TH1>(HIST("phiC"))->Fill(track.phi());
registry.get<TH2>(HIST("etaptC"))->Fill(track.eta(), track.pt());
}
}
};
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
return WorkflowSpec{
adaptAnalysisTask<RootHistograms>(cfgc),
adaptAnalysisTask<OutputObjects>(cfgc),
adaptAnalysisTask<OutputObjSet>(cfgc),
adaptAnalysisTask<HistRegistry>(cfgc),
};
}