forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqgTreeCreator.cxx
More file actions
205 lines (173 loc) · 5.68 KB
/
qgTreeCreator.cxx
File metadata and controls
205 lines (173 loc) · 5.68 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
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
// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 "PWGJE/DataModel/Jet.h"
#include "PWGJE/DataModel/JetMatching.h"
#include "Common/Core/RecoDecay.h"
#include "Common/DataModel/MCTruthContainer.h"
#include "Common/DataModel/TrackSelectionTables.h"
#include "Framework/AnalysisTask.h"
#include "Framework/Configurable.h"
#include "Framework/HistogramRegistry.h"
#include "Framework/runDataProcessing.h"
#include <cmath>
using namespace o2;
using namespace o2::framework;
namespace
{
constexpr int kGluon = 21;
constexpr int kQuarkMin = 1;
constexpr int kQuarkMax = 6;
float deltaR(float eta1, float phi1, float eta2, float phi2)
{
const float deta = eta1 - eta2;
const float dphi = RecoDecay::constrainAngle(phi1 - phi2);
return std::sqrt(deta * deta + dphi * dphi);
}
} // namespace
namespace o2::aod
{
DECLARE_SOA_COLUMN(JetPt, jetPt, float);
DECLARE_SOA_COLUMN(JetEta, jetEta, float);
DECLARE_SOA_COLUMN(JetPhi, jetPhi, float);
DECLARE_SOA_COLUMN(NConst, nConst, int);
DECLARE_SOA_COLUMN(Girth, girth, float);
DECLARE_SOA_COLUMN(PTD, pTD, float);
DECLARE_SOA_COLUMN(MatchDeltaR, matchDeltaR, float);
DECLARE_SOA_COLUMN(PtResponse, ptResponse, float);
DECLARE_SOA_COLUMN(QGLabel, qgLabel, int);
DECLARE_SOA_TABLE(QGJetTable, "AOD", "QGJET",
JetPt,
JetEta,
JetPhi,
NConst,
Girth,
PTD,
MatchDeltaR,
PtResponse,
QGLabel);
} // namespace o2::aod
//------------------------------------------------
// find initiating parton by ancestry
//------------------------------------------------
int getInitiatingParton(auto const& particle,
aod::McParticles const& mcParticles)
{
auto p = particle;
int pdg = p.pdgCode();
while (p.has_mothers()) {
auto mothers = p.mothers_as<aod::McParticles>();
if (mothers.size() == 0) {
break;
}
auto mom = mothers.iteratorAt(0);
const int mpdg = mom.pdgCode();
if (std::abs(mpdg) == kGluon ||
(std::abs(mpdg) >= kQuarkMin && std::abs(mpdg) <= kQuarkMax)) {
pdg = mpdg;
}
p = mom;
}
return pdg;
}
//------------------------------------------------
// main task
//------------------------------------------------
struct QGTreeCreator {
Configurable<float> jetPtMin{"jetPtMin", 10.f};
Configurable<float> maxMatchDeltaR{"maxMatchDeltaR", 0.3f};
Produces<aod::QGJetTable> qgjets;
void process(aod::ChargedMCDetectorLevelJets const& recoJets,
aod::ChargedMCParticleLevelJets const& truthJets,
aod::ChargedMCDetectorLevelJetsMatchedToChargedMCParticleLevelJets const& matches,
aod::McParticles const& mcParticles)
{
for (auto const& jet : recoJets) {
if (jet.pt() < jetPtMin) {
continue;
}
//----------------------------------
// compute jet observables
//----------------------------------
int nconst = 0;
float sumPt = 0;
float sumPt2 = 0;
float sumPtDr = 0;
for (auto const& c : jet.tracks_as<aod::ChargedMCDetectorLevelJetConstituent>()) {
float pt = c.pt();
float dr = deltaR(c.eta(), c.phi(), jet.eta(), jet.phi());
nconst++;
sumPt += pt;
sumPt2 += pt * pt;
sumPtDr += pt * dr;
}
float girth = sumPt > 0 ? sumPtDr / sumPt : -1;
float ptd = sumPt > 0 ? std::sqrt(sumPt2) / sumPt : -1;
//------------------------------------------------
// matching
//------------------------------------------------
float matchDr = -1;
float ptResp = -1;
int qg = -1;
for (auto const& match : matches) {
if (match.chargedMCDetectorLevelJetId() != jet.globalIndex()) {
continue;
}
auto truthJet = truthJets.iteratorAt(
match.chargedMCParticleLevelJetId());
matchDr = deltaR(jet.eta(), jet.phi(),
truthJet.eta(), truthJet.phi());
if (matchDr > maxMatchDeltaR) {
continue;
}
ptResp = jet.pt() / truthJet.pt();
//----------------------------------
// find initiating parton
//----------------------------------
float maxPt = -1;
int pdg = 0;
for (auto const& tc :
truthJet.tracks_as<aod::ChargedMCParticleLevelJetConstituent>()) {
if (!tc.has_mcParticle()) {
continue;
}
auto mc = tc.mcParticle();
if (tc.pt() > maxPt) {
maxPt = tc.pt();
pdg = getInitiatingParton(mc, mcParticles);
}
}
//----------------------------------
// assign q/g label
//----------------------------------
if (std::abs(pdg) == kGluon) {
qg = 1;
} else if (std::abs(pdg) >= kQuarkMin && std::abs(pdg) <= kQuarkMax) {
qg = 0;
}
break;
}
qgjets(jet.pt(),
jet.eta(),
jet.phi(),
nconst,
girth,
ptd,
matchDr,
ptResp,
qg);
}
}
};
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
return WorkflowSpec{
adaptAnalysisTask<QGTreeCreator>(cfgc)};
}