-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathhistograms.cxx
More file actions
110 lines (95 loc) · 3.28 KB
/
histograms.cxx
File metadata and controls
110 lines (95 loc) · 3.28 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
108
109
110
// 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.
#include "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
#include "Framework/AnalysisDataModel.h"
#include <TH1F.h>
#include <cmath>
using namespace o2;
using namespace o2::framework;
using namespace o2::framework::expressions;
// This is a very simple example showing how to create an histogram
// FIXME: this should really inherit from AnalysisTask but
// we need GCC 7.4+ for that
struct ATask {
OutputObj<TH1F> phiH{TH1F("phi", "phi", 100, 0., 2. * M_PI)};
OutputObj<TH1F> etaH{TH1F("eta", "eta", 102, -2.01, 2.01)};
void process(aod::Tracks const& tracks)
{
for (auto& track : tracks) {
phiH->Fill(track.phi());
etaH->Fill(track.eta());
}
}
};
struct BTask {
OutputObj<TH2F> etaphiH{TH2F("etaphi", "etaphi", 100, 0., 2. * M_PI, 102, -2.01, 2.01)};
// Create a configurable which can be used inside the process method.
Configurable<float> phiCut{"phiCut", 6.29f, "A cut on phi"};
void process(aod::Tracks const& tracks)
{
for (auto& track : tracks) {
// FIXME: this is until we have configurables which
// can be used in expressions.
if (track.phi() < phiCut) {
etaphiH->Fill(track.phi(), track.eta());
}
}
}
};
struct CTask {
// needs to be initialized with a label or an obj
// when adding an object to OutputObj later, the object name will be
// *reset* to OutputObj label - needed for correct placement in the output file
OutputObj<TH1F> ptH{TH1F("pt", "pt", 100, -0.01, 10.01)};
OutputObj<TH1F> trZ{"trZ", OutputObjHandlingPolicy::QAObject};
Configurable<float> pTCut{"pTCut", 0.5f, "Lower pT limit"};
Filter ptfilter = aod::track::pt > pTCut;
void init(InitContext const&)
{
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) {
ptH->Fill(track.pt());
trZ->Fill(track.z());
}
}
};
struct DTask {
OutputObj<TList> list{"list"};
void init(InitContext const&)
{
list.setObject(new TList);
list->Add(new TH1F("pHist", "", 100, 0, 10));
list->Add(new TH1F("etaHist", "", 102, -2.01, 2.01));
}
void process(aod::Track const& track)
{
auto pHist = dynamic_cast<TH1F*>(list->At(0));
auto etaHist = dynamic_cast<TH1F*>(list->At(1));
pHist->Fill(track.p());
etaHist->Fill(track.eta());
}
};
WorkflowSpec defineDataProcessing(ConfigContext const&)
{
return WorkflowSpec{
adaptAnalysisTask<ATask>("eta-and-phi-histograms"),
adaptAnalysisTask<BTask>("etaphi-histogram"),
adaptAnalysisTask<CTask>("pt-histogram"),
adaptAnalysisTask<DTask>("output-wrapper"),
};
}