forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJetCandidateUtilities.h
More file actions
397 lines (367 loc) · 14 KB
/
Copy pathJetCandidateUtilities.h
File metadata and controls
397 lines (367 loc) · 14 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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// Copyright 2019-2020 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.
/// \file JetCandidateUtilities.h
/// \brief Jet candidate related utilities
///
/// \author Nima Zardoshti <nima.zardoshti@cern.ch>
#ifndef PWGJE_CORE_JETCANDIDATEUTILITIES_H_
#define PWGJE_CORE_JETCANDIDATEUTILITIES_H_
#include "PWGJE/Core/JetDQUtilities.h"
#include "PWGJE/Core/JetHFUtilities.h"
#include "PWGJE/Core/JetV0Utilities.h"
#include <cstdint>
#include <type_traits>
namespace jetcandidateutilities
{
/**
* returns true if the candidate is from a candidate table
* * @param candidate candidate that is being checked
*/
template <typename T>
constexpr bool isCandidate()
{
if constexpr (jethfutilities::isHFCandidate<T>()) {
return true;
} else if constexpr (jetv0utilities::isV0Candidate<T>()) {
return true;
} else if constexpr (jetdqutilities::isDielectronCandidate<T>()) {
return true;
} else {
return false;
}
}
/**
* returns true if the candidate is from a MC candidate table
* * @param candidate candidate that is being checked
*/
template <typename T>
constexpr bool isMcCandidate()
{
if constexpr (jethfutilities::isHFMcCandidate<T>()) {
return true;
} else if constexpr (jetv0utilities::isV0McCandidate<T>()) {
return true;
} else if constexpr (jetdqutilities::isDielectronMcCandidate<T>()) {
return true;
} else {
return false;
}
}
/**
* returns true if the table type is a candidate table
*/
template <typename T>
constexpr bool isCandidateTable()
{
if constexpr (jethfutilities::isHFTable<T>()) {
return true;
} else if constexpr (jetv0utilities::isV0Table<T>()) {
return true;
} else if constexpr (jetdqutilities::isDielectronTable<T>()) {
return true;
} else {
return false;
}
}
/**
* returns true if the table type is a candidate table
*/
template <typename T>
constexpr bool isCandidateMcTable()
{
if constexpr (jethfutilities::isHFMcTable<T>()) {
return true;
} else if constexpr (jetv0utilities::isV0McTable<T>()) {
return true;
} else if constexpr (jetdqutilities::isDielectronMcTable<T>()) {
return true;
} else {
return false;
}
}
/**
* returns true if the candidate is matched to a reconstructed level candidate with the correct decay
* * @param candidate candidate that is being checked
*/
template <typename T>
constexpr bool isMatchedCandidate(T const& candidate)
{
if constexpr (jethfutilities::isHFCandidate<T>() || jethfutilities::isHFMcCandidate<T>()) {
return jethfutilities::isMatchedHFCandidate(candidate);
} else if constexpr (jetdqutilities::isDielectronCandidate<T>() || jetdqutilities::isDielectronMcCandidate<T>()) {
return jetdqutilities::isMatchedDielectronCandidate(candidate);
} else {
return false;
}
}
/**
* returns true if the track is a daughter of the candidate
*
* @param track track that is being checked
* @param candidate candidate that is being checked
* @param tracks the track table
*/
template <typename T, typename U, typename V>
bool isDaughterTrack(T& track, U& candidate, V const& tracks)
{
if constexpr (jethfutilities::isHFCandidate<U>()) {
return jethfutilities::isHFDaughterTrack(track, candidate, tracks);
} else if constexpr (jetv0utilities::isV0Candidate<U>()) {
return jetv0utilities::isV0DaughterTrack(track, candidate, tracks);
} else if constexpr (jetdqutilities::isDielectronCandidate<U>()) {
return jetdqutilities::isDielectronDaughterTrack(track, candidate, tracks);
} else {
return false;
}
}
/**
* returns true if the particle has any daughters with the given global index
*
* @param candidate mother hf particle that is being checked
* @param globalIndex global index of potnetial daughter particle
*/
template <typename T>
bool isDaughterParticle(const T& particle, int globalIndex)
{
if (!particle.has_daughters()) {
return false;
}
for (auto daughter : particle.template daughters_as<typename std::decay_t<T>::parent_t>()) {
if (daughter.globalIndex() == globalIndex) {
return true;
}
if (isDaughterParticle(daughter, globalIndex)) {
return true;
}
}
return false;
}
/**
* returns the index of the JMcParticle matched to the candidate
*
* @param candidate hf candidate that is being checked
* @param tracks track table
* @param particles particle table
*/
template <typename T, typename U, typename V>
auto matchedParticleId(const T& candidate, const U& tracks, const V& particles)
{
if constexpr (jethfutilities::isHFCandidate<T>()) {
return jethfutilities::matchedHFParticleId(candidate, tracks, particles);
} else if constexpr (jetv0utilities::isV0Candidate<T>()) {
return jetv0utilities::matchedV0ParticleId(candidate, tracks, particles);
} else if constexpr (jetdqutilities::isDielectronCandidate<T>()) {
return jetdqutilities::matchedDielectronParticleId(candidate, tracks, particles);
} else {
return -1;
}
}
/**
* returns the JMcParticle matched to the candidate
*
* @param candidate hf candidate that is being checked
* @param tracks track table
* @param particles particle table
*/
template <typename T, typename U, typename V>
auto matchedParticle(const T& candidate, const U& tracks, const V& particles)
{
if constexpr (jethfutilities::isHFCandidate<T>()) {
return jethfutilities::matchedHFParticle(candidate, tracks, particles);
} else if constexpr (jetv0utilities::isV0Candidate<T>()) {
return jetv0utilities::matchedV0Particle(candidate, tracks, particles);
} else if constexpr (jetdqutilities::isDielectronCandidate<T>()) {
return jetdqutilities::matchedDielectronParticle(candidate, tracks, particles);
} else {
return jethfutilities::matchedHFParticle(candidate, tracks, particles); // this is a dummy output which should never be triggered
}
}
/**
* returns a slice of the table depending on the index of the candidate
*
* @param candidate candidate that is being checked
* @param table the table to be sliced
*/
template <typename T, typename U, typename V, typename M, typename N, typename O, typename P, typename Q, typename R, typename S, typename A>
auto slicedPerCandidate(T const& table, U const& candidate, V const& perD0Candidate, M const& perDplusCandidate, N const& perDsCandidate, O const& perDstarCandidate, P const& perLcCandidate, Q const& perB0Candidate, R const& perBplusCandidate, S const& perXicToXiPiPiCandidate, A const& perDielectronCandidate)
{
if constexpr (jethfutilities::isHFCandidate<U>()) {
return jethfutilities::slicedPerHFCandidate(table, candidate, perD0Candidate, perDplusCandidate, perDsCandidate, perDstarCandidate, perLcCandidate, perB0Candidate, perBplusCandidate, perXicToXiPiPiCandidate);
} else if constexpr (jetdqutilities::isDielectronCandidate<U>()) {
return jetdqutilities::slicedPerDielectronCandidate(table, candidate, perDielectronCandidate);
} else {
return table;
}
}
/**
* returns a slice of the table depending on the index of the candidate
* @param CandidateTable candidtae table type
* @param jet jet that the slice is based on
* @param table the table to be sliced
*/
template <typename CandidateTable, typename T, typename U, typename V, typename M, typename N, typename O, typename P, typename Q, typename R, typename S, typename A>
auto slicedPerJet(T const& table, U const& jet, V const& perD0Jet, M const& perDplusJet, N const& perDsJet, O const& perDstarJet, P const& perLcJet, Q const& perB0Jet, R const& perBplusJet, S const& perXicToXiPiPiJet, A const& perDielectronJet)
{
if constexpr (jethfutilities::isHFTable<CandidateTable>() || jethfutilities::isHFMcTable<CandidateTable>()) {
return jethfutilities::slicedPerHFJet<CandidateTable>(table, jet, perD0Jet, perDplusJet, perDsJet, perDstarJet, perLcJet, perB0Jet, perBplusJet, perXicToXiPiPiJet);
} else if constexpr (jetdqutilities::isDielectronTable<CandidateTable>() || jetdqutilities::isDielectronMcTable<CandidateTable>()) {
return jetdqutilities::slicedPerDielectronJet<CandidateTable>(table, jet, perDielectronJet);
} else {
return table;
}
}
/**
* returns the candidate collision Id of candidate based on type of candidate
*
* @param candidate candidate that is being checked
*/
template <typename T>
int getCandidateCollisionId(T const& candidate)
{
if constexpr (jethfutilities::isHFCandidate<T>()) {
return jethfutilities::getHFCandidateCollisionId(candidate);
} else if constexpr (jetdqutilities::isDielectronCandidate<T>()) {
return jetdqutilities::getDielectronCandidateCollisionId(candidate);
} else {
return -1;
}
}
/**
* returns the candidate Mc collision Id of candidate based on type of candidate
*
* @param candidate candidate that is being checked
*/
template <typename T>
int getMcCandidateCollisionId(T const& candidate)
{
if constexpr (jethfutilities::isHFMcCandidate<T>()) {
return jethfutilities::getHFMcCandidateCollisionId(candidate);
} else if constexpr (jetdqutilities::isDielectronMcCandidate<T>()) {
return jetdqutilities::getDielectronMcCandidateCollisionId(candidate);
} else {
return -1;
}
}
/**
* returns the PDG of the candidate based on Table
*
* @param candidate candidate that is being checked
*/
template <typename T>
int getCandidatePDG(T const& candidate)
{
if constexpr (jethfutilities::isHFCandidate<T>() || jethfutilities::isHFMcCandidate<T>()) {
return jethfutilities::getHFCandidatePDG(candidate);
} else if constexpr (jetdqutilities::isDielectronCandidate<T>() || jetdqutilities::isDielectronMcCandidate<T>()) {
return jetdqutilities::getDielectronCandidatePDG(candidate);
} else {
return 0;
}
}
/**
* returns the PDG of the candidates in the table type
*/
template <typename T>
int getTablePDG()
{
if constexpr (jethfutilities::isHFTable<T>() || jethfutilities::isHFMcTable<T>()) {
return jethfutilities::getHFTablePDG<T>();
} else if constexpr (jetdqutilities::isDielectronTable<T>() || jetdqutilities::isDielectronMcTable<T>()) {
return jetdqutilities::getDielectronTablePDG<T>();
} else {
return 0;
}
}
/**
* returns the pdg mass of the candidate based on Table
*
* @param candidate candidate that is being checked
*/
template <typename T>
float getCandidatePDGMass(T const& candidate)
{
if constexpr (jethfutilities::isHFCandidate<T>() || jethfutilities::isHFMcCandidate<T>()) {
return jethfutilities::getHFCandidatePDGMass(candidate);
} else if constexpr (jetdqutilities::isDielectronCandidate<T>() || jetdqutilities::isDielectronMcCandidate<T>()) {
return jetdqutilities::getDielectronCandidatePDGMass(candidate);
} else {
return -1.0;
}
}
/**
* returns the pdg mass of the candidates in the table type
*
*/
template <typename T>
float getTablePDGMass()
{
if constexpr (jethfutilities::isHFTable<T>() || jethfutilities::isHFMcTable<T>()) {
return jethfutilities::getHFTablePDGMass<T>();
} else if constexpr (jetdqutilities::isDielectronTable<T>() || jetdqutilities::isDielectronMcTable<T>()) {
return jetdqutilities::getDielectronTablePDGMass<T>();
} else {
return -1.0;
}
}
/**
* returns the invariant mass of the candidate based on Table
*
* @param candidate candidate that is being checked
*/
template <typename T>
float getCandidateInvariantMass(T const& candidate)
{
if constexpr (jethfutilities::isHFCandidate<T>()) {
return jethfutilities::getHFCandidateInvariantMass(candidate);
} else if constexpr (jetdqutilities::isDielectronCandidate<T>()) {
return jetdqutilities::getDielectronCandidateInvariantMass(candidate);
} else {
return -1.0;
}
}
template <typename T, typename U, typename V>
void fillCandidateCollisionTable(T const& collision, U const& /*candidates*/, V& CandiateCollisionTable)
{
if constexpr (jethfutilities::isHFTable<U>()) {
jethfutilities::fillHFCollisionTable(collision, CandiateCollisionTable);
} else if constexpr (jetdqutilities::isDielectronTable<U>()) {
jetdqutilities::fillDielectronCollisionTable(collision, CandiateCollisionTable); // if more dilepton tables are added we would need a fillDQCollisionTable
}
}
template <typename T, typename U, typename V>
void fillCandidateMcCollisionTable(T const& mcCollision, U const& /*candidates*/, V& CandiateMcCollisionTable)
{
if constexpr (jethfutilities::isHFMcTable<U>()) {
jethfutilities::fillHFMcCollisionTable(mcCollision, CandiateMcCollisionTable);
} else if constexpr (jetdqutilities::isDielectronMcTable<U>()) {
jetdqutilities::fillDielectronMcCollisionTable(mcCollision, CandiateMcCollisionTable);
}
}
template <bool isMc, typename T, typename U, typename V, typename M, typename N, typename O, typename P, typename Q, typename S>
void fillCandidateTable(T const& candidate, int32_t collisionIndex, U& BaseTable, V& HFParTable, M& HFParETable, N& HFParDaughterTable, O& HFSelectionFlagTable, P& HFMlTable, Q& HFMlDaughterTable, S& HFMCDTable)
{
if constexpr (jethfutilities::isHFCandidate<T>()) {
jethfutilities::fillHFCandidateTable<isMc>(candidate, collisionIndex, BaseTable, HFParTable, HFParETable, HFParDaughterTable, HFSelectionFlagTable, HFMlTable, HFMlDaughterTable, HFMCDTable);
} else if constexpr (jetdqutilities::isDielectronCandidate<T>()) {
jetdqutilities::fillDielectronCandidateTable(candidate, collisionIndex, BaseTable, HFParTable);
}
}
template <typename T, typename U>
void fillCandidateMcTable(T const& candidate, int32_t mcCollisionIndex, U& BaseMcTable)
{
if constexpr (jethfutilities::isHFMcCandidate<T>()) {
jethfutilities::fillHFCandidateMcTable(candidate, mcCollisionIndex, BaseMcTable);
} else if constexpr (jetdqutilities::isDielectronMcCandidate<T>()) {
jetdqutilities::fillDielectronCandidateMcTable(candidate, mcCollisionIndex, BaseMcTable);
}
}
}; // namespace jetcandidateutilities
#endif // PWGJE_CORE_JETCANDIDATEUTILITIES_H_