ATLAS Offline Software
PhysicsAnalysis
AnalysisCommon
ParticleJetTools
Root
CopyFlavorLabelTruthParticles.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
ParticleJetTools/CopyFlavorLabelTruthParticles.h
"
6
#include "
xAODTruth/TruthParticleContainer.h
"
7
#include "
xAODTruth/TruthParticleAuxContainer.h
"
8
#include "
xAODTruth/TruthEventContainer.h
"
9
#include "
AthContainers/ConstDataVector.h
"
10
#include "
TruthUtils/HepMCHelpers.h
"
11
12
using namespace
std;
13
14
15
CopyFlavorLabelTruthParticles::CopyFlavorLabelTruthParticles
(
const
std::string&
name
)
16
:
CopyTruthParticles
(
name
)
17
{
18
declareProperty
(
"ParticleType"
,
m_ptype
=
"BHadronsFinal"
,
"Sort of particles to pick: BHadronsFinal | BHadronsInitial | BQuarksFinal | CHadronsFinal | CHadronsInitial | CQuarksFinal | TausFinal"
);
19
}
20
21
22
// Unnamed namespace for helpers: only visible to this compilation unit
23
namespace
{
24
inline
bool
isBQuark(
const
xAOD::TruthParticle
*
tp
) {
return
(abs(
tp
->pdgId()) == MC::BQUARK); }
25
inline
bool
isCQuark(
const
xAOD::TruthParticle
*
tp
) {
return
(abs(
tp
->pdgId()) == MC::CQUARK); }
26
inline
bool
isBHadron(
const
xAOD::TruthParticle
*
tp
) {
return
MC::isBottomHadron
(
tp
->pdgId()); }
27
inline
bool
isCHadron(
const
xAOD::TruthParticle
*
tp
) {
return
MC::isCharmHadron
(
tp
->pdgId()); }
28
inline
bool
isTau
(
const
xAOD::TruthParticle
*
tp
) {
return
MC::isTau
(
tp
->pdgId()); }
29
30
template
<
typename
FN>
31
inline
bool
isFinalWith(
const
xAOD::TruthParticle
*
tp
,
const
FN&
f
) {
32
if
(!
f
(
tp
))
return
false
;
33
if
(!
tp
->hasDecayVtx())
return
false
;
34
for
(
unsigned
int
i
= 0;
i
<
tp
->decayVtx()->nOutgoingParticles(); ++
i
) {
35
if
(
tp
->decayVtx()->outgoingParticle(
i
)==
nullptr
)
continue
;
36
if
(
f
(
tp
->decayVtx()->outgoingParticle(
i
)))
return
false
;
37
}
38
return
true
;
39
}
40
41
template
<
typename
FN>
42
inline
bool
isInitialWith(
const
xAOD::TruthParticle
*
tp
,
const
FN&
f
) {
43
if
(!
f
(
tp
))
return
false
;
44
if
(!
tp
->hasProdVtx())
return
false
;
45
for
(
unsigned
int
i
= 0;
i
<
tp
->prodVtx()->nIncomingParticles(); ++
i
) {
46
if
(
tp
->prodVtx()->incomingParticle(
i
)==
nullptr
)
continue
;
47
if
(
f
(
tp
->prodVtx()->incomingParticle(
i
)))
return
false
;
48
}
49
return
true
;
50
}
51
}
52
53
54
bool
CopyFlavorLabelTruthParticles::classify
(
const
xAOD::TruthParticle
*
tp
)
const
{
55
// Cut on particle type
56
if
(
tp
==
nullptr
){
57
return
false
;
58
}
59
if
(
m_ptype
==
"BHadronsFinal"
) {
60
//ATH_MSG_DEBUG("Selecting in BHadronsFinal mode");
61
return
isFinalWith(
tp
, isBHadron);
62
}
else
if
(
m_ptype
==
"BHadronsInitial"
) {
63
//ATH_MSG_DEBUG("Selecting in BHadronsInitial mode");
64
return
isInitialWith(
tp
, isBHadron);
65
}
else
if
(
m_ptype
==
"BQuarksFinal"
) {
66
//ATH_MSG_DEBUG("Selecting in BQuarksFinal mode");
67
return
isFinalWith(
tp
, isBQuark);
68
}
else
if
(
m_ptype
==
"CHadronsFinal"
) {
69
//ATH_MSG_DEBUG("Selecting in CHadronsFinal mode");
70
return
isFinalWith(
tp
, isCHadron);
71
}
else
if
(
m_ptype
==
"CHadronsInitial"
) {
72
//ATH_MSG_DEBUG("Selecting in CHadronsInitial mode");
73
return
isInitialWith(
tp
, isCHadron);
74
}
else
if
(
m_ptype
==
"CQuarksFinal"
) {
75
//ATH_MSG_DEBUG("Selecting in CQuarksFinal mode");
76
return
isFinalWith(
tp
, isCQuark);
77
}
else
if
(
m_ptype
==
"TausFinal"
) {
78
//ATH_MSG_DEBUG("Selecting in TausFinal mode");
79
return
isFinalWith(
tp
,
isTau
);
80
}
81
throw
std::runtime_error(
"Requested unknown particle classification type: "
+
m_ptype
);
82
return
false
;
83
}
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition:
AthCommonDataStore.h:145
TruthParticleContainer.h
CopyFlavorLabelTruthParticles::m_ptype
std::string m_ptype
Particle selection mode.
Definition:
CopyFlavorLabelTruthParticles.h:25
ParticleTest.tp
tp
Definition:
ParticleTest.py:25
isBottomHadron
bool isBottomHadron(const T &p)
Definition:
AtlasPID.h:680
TruthParticleAuxContainer.h
CopyFlavorLabelTruthParticles::classify
bool classify(const xAOD::TruthParticle *tp) const
Classifier function(s)
Definition:
CopyFlavorLabelTruthParticles.cxx:54
lumiFormat.i
int i
Definition:
lumiFormat.py:85
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition:
TruthParticle_v1.h:37
hist_file_dump.f
f
Definition:
hist_file_dump.py:135
isTau
bool isTau(const T &p)
Definition:
AtlasPID.h:173
name
std::string name
Definition:
Control/AthContainers/Root/debug.cxx:228
CopyFlavorLabelTruthParticles.h
isCharmHadron
bool isCharmHadron(const T &p)
Definition:
AtlasPID.h:679
CopyTruthParticles
Definition:
CopyTruthParticles.h:18
CopyFlavorLabelTruthParticles::CopyFlavorLabelTruthParticles
CopyFlavorLabelTruthParticles(const std::string &name)
Constructor.
Definition:
CopyFlavorLabelTruthParticles.cxx:15
TruthEventContainer.h
HepMCHelpers.h
Generated on Sun Dec 22 2024 21:08:37 for ATLAS Offline Software by
1.8.18