-
Notifications
You must be signed in to change notification settings - Fork 1
/
simplehist.cxx
293 lines (259 loc) · 11.2 KB
/
simplehist.cxx
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
#include <CCDB/BasicCCDBManager.h>
#include "AnalysisDataModel/PID/PIDResponse.h"
#include "AnalysisDataModel/PID/PIDTOF.h"
#include "AnalysisDataModel/TrackSelectionTables.h"
#include <iostream>
using namespace o2;
using namespace o2::framework;
using namespace o2::framework::expressions;
struct TPCvsMomentum {
static constexpr std::string_view sigvsp[6] = {"TpcVsMomentumPr", "TpcVsMomentumKa", "TpcVsMomentumPi", "TofVsMomentumPr", "TofVsMomentumKa", "TofVsMomentumPi"};
HistogramRegistry registry {
"registry",
{
{"TpcVsMomentumPr", "TpcVsMomentumPr;p GeV/c^2; TPC signal", {HistType::kTH2F, {{500, 0, 10}, {500, 0, 6000}}}},
{"TpcVsMomentumKa", "TpcVsMomentumKa;p GeV/c^2; TPC signal", {HistType::kTH2F, {{500, 0, 10}, {500, 0, 4000}}}},
{"TpcVsMomentumPi", "TpcVsMomentumPi;p GeV/c^2; TPC signal", {HistType::kTH2F, {{500, 0, 10}, {500, 0, 1000}}}},
{"TofVsMomentumPr", "TofVsMomentumPr;p GeV/c^2; TOF signal", {HistType::kTH2F, {{500, 0, 10}, {500, 0, 100000}}}},
{"TofVsMomentumKa", "TofVsMomentumKa;p GeV/c^2; TOF signal", {HistType::kTH2F, {{500, 0, 10}, {500, 0, 100000}}}},
{"TofVsMomentumPi", "TofVsMomentumPi;p GeV/c^2; TOF signal", {HistType::kTH2F, {{500, 0, 10}, {500, 0, 100000}}}}
}
};
Configurable<float> nsigmacut{"nsigmacut", 3, "Value of the Nsigma cut"};
// i - 0 for proton, 1 for kaon, 2 for pion
// j - 0 for TPC, 1 for TOF
template <std::size_t i, std::size_t j, typename T>
void fillParticleHistos(const T& track, const float nsigma[])
{
if (track.pt() < 0.5)
{
if (abs(nsigma[i]) < nsigmacut.value)
{
if (j == 0)
registry.fill(HIST(sigvsp[i]), track.p(), track.tpcSignal());
else if (j == 1)
registry.fill(HIST(sigvsp[i+3]), track.p(), track.tofSignal()); // i+3 to fill TofVsMomentum hists
}
} else if ((track.pt() >= 0.5) && ((i == 1) || (i == 2)))
{
if (sqrt(pow(nsigma[i], 2) + pow(nsigma[i+3],2)) < nsigmacut.value) // square root of tpcSignal^2 + tofSignal^2
{
if (j == 0)
registry.fill(HIST(sigvsp[i]), track.p(), track.tpcSignal());
else if (j == 1)
registry.fill(HIST(sigvsp[i+3]), track.p(), track.tofSignal());
}
} else if ((track.pt() >= 0.8) || (i == 0))
{
if (sqrt(pow(nsigma[i], 2) + pow(nsigma[i+3],2)) < nsigmacut.value) // square root of tpcSignal^2 + tofSignal^2
{
if (j == 0)
registry.fill(HIST(sigvsp[i]), track.p(), track.tpcSignal());
else if (j == 1)
registry.fill(HIST(sigvsp[i+3]), track.p(), track.tofSignal());
}
}
}
using myTracks = soa::Join<aod::Tracks, aod::TracksExtra, aod::pidTPCPr, aod::pidTPCPi, aod::pidTPCKa, aod::pidTOFPr, aod::pidTOFPi, aod::pidTOFKa>::iterator;
void process(myTracks const& track)
{
const float nsigma[6] = {track.tpcNSigmaPr(), track.tpcNSigmaKa(), track.tpcNSigmaPi(),
track.tofNSigmaPr(), track.tofNSigmaKa(), track.tofNSigmaPi()};
// first number in < > - 0 for
// second - 0 for TPC, 1 for TOF
fillParticleHistos<0, 0>(track, nsigma);
fillParticleHistos<1, 0>(track, nsigma);
fillParticleHistos<2, 0>(track, nsigma);
fillParticleHistos<0, 1>(track, nsigma);
fillParticleHistos<1, 1>(track, nsigma);
fillParticleHistos<2, 1>(track, nsigma);
}
};
struct PHist{
static constexpr std::string_view hname[3] = {"PrPt", "PiPt", "KaPt"};
HistogramRegistry registry{
"registry",
{{"PrPt", "ProtonPt; pT GeV/c", {HistType::kTH1F, {{1000, 0, 5}}}},
{"PiPt", "PionPt; pT GeV/c", {HistType::kTH1F, {{1000, 0, 5}}}},
{"KaPt", "KaonPt; pT GeV/c", {HistType::kTH1F, {{1000, 0, 5}}}}}
};
Configurable<float> nsigmacut{"nsigmacut", 3, "Value of the Nsigma cut"};
template <std::size_t i, typename T>
void fillParticleHistos(const T& track, const float nsigma[])
{
if (track.pt() < 0.5)
{
if (abs(nsigma[i]) < nsigmacut.value)
{
registry.fill(HIST(hname[i]),track.pt());
}
} else if ((track.pt() >= 0.5) && ((i == 1) || (i == 2)))
{ // for pions and kaons
if (sqrt(pow(nsigma[i], 2) + pow(nsigma[i+3],2)) < nsigmacut.value) // square root of tpcSignal^2 + tofSignal^2
{
registry.fill(HIST(hname[i]),track.pt());
}
} else if ((track.pt() >= 0.5) && (i == 0))
{ // for protons with pt 0.5 <= 0.8
if (abs(nsigma[i]) < nsigmacut.value)
{
registry.fill(HIST(hname[i]),track.pt());
}
} else if ((track.pt() >= 0.8) && (i == 0))
{ // only for protons
if (sqrt(pow(nsigma[i], 2) + pow(nsigma[i+3],2)) < nsigmacut.value) // square root of tpcSignal^2 + tofSignal^2
{
registry.fill(HIST(hname[i]), track.pt());
}
}
}
using myTracks = soa::Join<aod::Tracks, aod::TracksExtra, aod::pidTPCPr, aod::pidTPCPi, aod::pidTPCKa, aod::pidTOFPr, aod::pidTOFPi, aod::pidTOFKa>::iterator;
void process(myTracks const& track)
{
const float nsigma[6] = {track.tpcNSigmaPr(), track.tpcNSigmaKa(), track.tpcNSigmaPi(),
track.tofNSigmaPr(), track.tofNSigmaKa(), track.tofNSigmaPi()};
// i == 0 for Protons, 1 for Kaons, 2 for Pions
fillParticleHistos<0,myTracks>(track, nsigma);
fillParticleHistos<1, myTracks>(track, nsigma);
fillParticleHistos<2, myTracks>(track, nsigma);
}
};
struct showNSigma {
using myTracks = soa::Join<aod::Tracks, aod::TracksExtra, aod::pidTPCPr, aod::pidTPCPi, aod::pidTPCKa, aod::pidTOFPr, aod::pidTOFPi, aod::pidTOFKa>;
void process(myTracks const& tracks)
{
std::ofstream f;
f.open("nSigma.txt");
for (auto& track : tracks) {
f << track.tpcNSigmaPi() << "\t" << track.tpcNSigmaKa() << "\t" << track.tpcNSigmaPr() << "\t" << track.tofNSigmaPi() << "\t" << track.tofNSigmaKa() << "\t" <<track.tofNSigmaPr() << std::endl;
}
f.close();
}
};
struct showPDG {
using myTracks = soa::Join<aod::Tracks, aod::TracksExtra, aod::McParticles>;
void process(myTracks const& tracks)
{
for (auto& track : tracks)
{
std::cout << track.pdgCode() << std::endl;
}
}
};
struct showPDGHist {
using myTracks = soa::Join<aod::Tracks, aod::TracksExtra, aod::McParticles>;
HistogramRegistry registry{
"registry",
{{"PDG", "PDG; pT", {HistType::kTH1F, {{5000, -4000, 4000}}}}}
};
void process(myTracks const& tracks)
{
for (auto& track : tracks)
{
std::cout << track.pdgCode() << std::endl;
registry.get<TH1>(HIST("PDG"))-> Fill(track.pdgCode());
}
}
};
struct PDGPi {
HistogramRegistry registry {
"registry",
{
{"PDGPi", "PDGPi;p GeV/c; PDG", {HistType::kTH2F, {{500, 0, 10}, {8001, -4000.5, 4000.5}}}}
}
};
Configurable<float> nsigmacut{"nsigmacut", 3, "Value of the Nsigma cut"};
using BigTracksMC = soa::Join<aod::FullTracks, aod::pidTPCPi, aod::pidTOFPi, aod::McTrackLabels>;
void process(BigTracksMC const& tracks, aod::McParticles const& mctracks)
{
for (const auto& track : tracks) {
const float nsigma[2] = {track.tpcNSigmaPi(), track.tofNSigmaPi()};
const auto mcParticle = track.mcParticle();
if (track.pt() < 0.5) {
if( (abs(nsigma[1]) < nsigmacut.value) || (abs(nsigma[0])<nsigmacut.value ) )
registry.fill(HIST("PDGPi"), track.p(), mcParticle.pdgCode());
} else if (track.pt() >= 0.5)
{
if (sqrt(pow(nsigma[0], 2) + pow(nsigma[1],2)) < nsigmacut.value) // square root of tpcSignal^2 + tofSignal^2
registry.fill(HIST("PDGPi"), track.p(), mcParticle.pdgCode());
}
}
}
};
struct PDGKa {
HistogramRegistry registry {
"registry",
{
{"PDGKa", "PDGKa;p GeV/c; PDG", {HistType::kTH2F, {{500, 0, 10}, {8001, -4000.5, 4000.5}}}}
}
};
Configurable<float> nsigmacut{"nsigmacut", 3, "Value of the Nsigma cut"};
using BigTracksMC = soa::Join<aod::FullTracks, aod::pidTPCKa, aod::pidTOFKa, aod::McTrackLabels>;
void process(BigTracksMC const& tracks, aod::McParticles const& mctracks)
{
for (const auto& track : tracks) {
const float nsigma[2] = {track.tpcNSigmaKa(), track.tofNSigmaKa()};
const auto mcParticle = track.mcParticle();
if (track.pt() < 0.5) {
if( (abs(nsigma[1]) < nsigmacut.value) || (abs(nsigma[0])<nsigmacut.value ) )
registry.fill(HIST("PDGKa"), track.p(), mcParticle.pdgCode());
} else if (track.pt() >= 0.5)
{
if (sqrt(pow(nsigma[0], 2) + pow(nsigma[1],2)) < nsigmacut.value) // square root of tpcSignal^2 + tofSignal^2
registry.fill(HIST("PDGKa"), track.p(), mcParticle.pdgCode());
}
}
}
};
struct PDGPr {
HistogramRegistry registry {
"registry",
{
{"PDGPr", "PDGPr;p GeV/c; PDG", {HistType::kTH2F, {{500, 0, 10}, {8001, -4000.5, 4000.5}}}}
}
};
Configurable<float> nsigmacut{"nsigmacut", 3, "Value of the Nsigma cut"};
using BigTracksMC = soa::Join<aod::FullTracks, aod::pidTPCPr, aod::pidTOFPr, aod::McTrackLabels>;
void process(BigTracksMC const& tracks, aod::McParticles const& mctracks)
{
for (const auto& track : tracks) {
const float nsigma[2] = {track.tpcNSigmaPr(), track.tofNSigmaPr()};
const auto mcParticle = track.mcParticle();
if (track.pt() < 0.5) {
if( (abs(nsigma[1]) < nsigmacut.value) || (abs(nsigma[0])<nsigmacut.value ) )
registry.fill(HIST("PDGPr"), track.p(), mcParticle.pdgCode());
} else if ((track.pt() >= 0.5))
{ // for protons with pt 0.5 <= 0.8
if ( (abs(nsigma[1]) < nsigmacut.value) || (abs(nsigma[0])<nsigmacut.value ) )
{
registry.fill(HIST("PDGPr"),track.pt(), mcParticle.pdgCode());
}
} else if ((track.pt() >= 0.8))
{ // only for protons
if (sqrt(pow(nsigma[0], 2) + pow(nsigma[1],2)) < nsigmacut.value) // square root of tpcSignal^2 + tofSignal^2
{
registry.fill(HIST("PDGPr"), track.pt(), mcParticle.pdgCode());
}
}
}
}
};
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
return WorkflowSpec{
// adaptAnalysisTask<TPCvsMomentum>(cfgc),
adaptAnalysisTask<PHist>(cfgc),
// adaptAnalysisTask<showPDGHist>(cfgc),
// adaptAnalysisTask<PDGHadrons>(cfgc),
adaptAnalysisTask<PDGPi>(cfgc),
adaptAnalysisTask<PDGKa>(cfgc),
adaptAnalysisTask<PDGPr>(cfgc),
// adaptAnalysisTask<showNSigma>(cfgc),
// adaptAnalysisTask<showPDG>(cfgc),
// adaptAnalysisTask<TofPt>(cfgc),
// adaptAnalysisTask<TpcPt>(cfgc),
// adaptAnalysisTask<CombinedPt>(cfgc),
};
}