ATLAS Offline Software
Loading...
Searching...
No Matches
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
11
12using namespace std;
13
14
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
23namespace {
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
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}
bool isTau(const T &p)
Definition AtlasPID.h:208
DataVector adapter that acts like it holds const pointers.
ATLAS-specific HepMC functions.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::string m_ptype
Particle selection mode.
CopyFlavorLabelTruthParticles(const std::string &name)
Constructor.
bool classify(const xAOD::TruthParticle *tp) const
Classifier function(s)
CopyTruthParticles(const std::string &name)
Constructor.
bool isCharmHadron(const T &p)
static const int CQUARK
bool isBottomHadron(const T &p)
static const int BQUARK
bool isTau(const T &p)
STL namespace.
TruthParticle_v1 TruthParticle
Typedef to implementation.