ATLAS Offline Software
MCTCDecorationAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
10 
12 
13 
14 namespace CP
15 {
16 
18  MCTCDecorationAlg (const std::string& name,
19  ISvcLocator* pSvcLocator)
20  : AnaAlgorithm (name, pSvcLocator)
21  {
22  }
23 
24 
26  initialize ()
27  {
28  if (m_classificationDecoration.empty())
29  {
30  ANA_MSG_ERROR("Classification decoration name needs to be set");
31  return StatusCode::FAILURE;
32  }
33 
34  m_classificationAccessor = std::make_unique<SG::AuxElement::ConstAccessor<unsigned int> > (m_classificationDecoration);
35 
36  if (!m_isPromptDecoration.empty())
37  {
38  m_isPromptDecorator = std::make_unique<SG::AuxElement::Decorator<int> > (m_isPromptDecoration);
39  }
40  if (!m_fromHadronDecoration.empty())
41  {
42  m_fromHadronDecorator = std::make_unique<SG::AuxElement::Decorator<int> > (m_fromHadronDecoration);
43  }
44  if (!m_fromBSMDecoration.empty())
45  {
46  m_fromBSMDecorator = std::make_unique<SG::AuxElement::Decorator<int> > (m_fromBSMDecoration);
47  }
48  if (!m_fromTauDecoration.empty())
49  {
50  m_fromTauDecorator = std::make_unique<SG::AuxElement::Decorator<int> > (m_fromTauDecoration);
51  }
52 
56 
57  return StatusCode::SUCCESS;
58  }
59 
60 
62  execute ()
63  {
64  for (const auto& sys : m_systematicsList.systematicsVector())
65  {
68  for (const xAOD::IParticle *particle : *particles)
69  {
71  {
72  // Check if xAOD::TruthParticle or if not if it has the TruthParticleLink
73  const xAOD::TruthParticle *truthParticle
74  = dynamic_cast<const xAOD::TruthParticle *> (particle);
75  if (truthParticle == nullptr)
76  {
77  // need to find the truth particle
79  }
80 
81  // run only on leptons
82  if (truthParticle != nullptr && truthParticle->isLepton() && (truthParticle->status() == 1 || truthParticle->status() == 2))
83  {
84  unsigned int result{};
85  if (m_classificationAccessor->isAvailable(*truthParticle))
86  {
87  result = (*m_classificationAccessor)(*truthParticle);
88  }
89  else
90  {
91  ANA_MSG_ERROR ("MCTC Classification decoration not available.");
92  return StatusCode::FAILURE;
93  }
94 
95  std::bitset<MCTruthPartClassifier::MCTC_bits::totalBits> bitset(result);
96  if (m_isPromptDecorator != nullptr)
97  {
98  (*m_isPromptDecorator)(*particle) = MCTruthPartClassifier::isPrompt(result, true) ? 1 : 0; // also accept 'unknown' with -1
99  }
100  if (m_fromHadronDecorator != nullptr)
101  {
102  (*m_fromHadronDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::hadron);
103  }
104  if (m_fromBSMDecorator != nullptr)
105  {
106  (*m_fromBSMDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::frombsm);
107  }
108  if (m_fromTauDecorator != nullptr)
109  {
110  (*m_fromTauDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::Tau);
111  }
112  continue;
113  }
114  }
115 
116  // defaults
117  if (m_isPromptDecorator != nullptr)
118  {
119  (*m_isPromptDecorator)(*particle) = -1;
120  }
121  if (m_fromHadronDecorator != nullptr)
122  {
123  (*m_fromHadronDecorator)(*particle) = -1;
124  }
125  if (m_fromBSMDecorator != nullptr)
126  {
127  (*m_fromBSMDecorator)(*particle) = -1;
128  }
129  if (m_fromTauDecorator != nullptr)
130  {
131  (*m_fromTauDecorator)(*particle) = -1;
132  }
133  }
134  }
135 
136  return StatusCode::SUCCESS;
137  }
138 
139 } // namespace CP
CP::MCTCDecorationAlg::m_isPromptDecorator
std::unique_ptr< const SG::AuxElement::Decorator< int > > m_isPromptDecorator
the decorator for m_isPromptDecoration
Definition: MCTCDecorationAlg.h:68
CP::MCTCDecorationAlg::m_preselection
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Definition: MCTCDecorationAlg.h:51
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
MCTruthPartClassifier::frombsm
@ frombsm
Definition: TruthClassifiers.h:148
get_generator_info.result
result
Definition: get_generator_info.py:21
MCTruthPartClassifier::hadron
@ hadron
Definition: TruthClassifiers.h:148
TruthClassifiers.h
CP::MCTCDecorationAlg::m_particlesHandle
SysReadHandle< xAOD::IParticleContainer > m_particlesHandle
the particle collection we run on
Definition: MCTCDecorationAlg.h:46
CP::MCTCDecorationAlg::m_fromBSMDecoration
Gaudi::Property< std::string > m_fromBSMDecoration
the decoration for the BSM origin
Definition: MCTCDecorationAlg.h:80
CP::MCTCDecorationAlg::m_fromBSMDecorator
std::unique_ptr< const SG::AuxElement::Decorator< int > > m_fromBSMDecorator
the decorator for m_fromBSMDecoration
Definition: MCTCDecorationAlg.h:84
MCTCDecorationAlg.h
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
CP::MCTCDecorationAlg::m_fromTauDecoration
Gaudi::Property< std::string > m_fromTauDecoration
the decoration for the tau origin
Definition: MCTCDecorationAlg.h:88
CP::MCTCDecorationAlg::MCTCDecorationAlg
MCTCDecorationAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: MCTCDecorationAlg.cxx:18
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAODTruthHelpers.h
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
xAOD::TruthParticle_v1::isLepton
bool isLepton() const
Whether the particle is a lepton.
CP::MCTCDecorationAlg::execute
virtual StatusCode execute() override
Definition: MCTCDecorationAlg.cxx:62
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
CP::SysReadSelectionHandle::getBool
bool getBool(const SG::AuxElement &element, const CP::SystematicSet &sys) const
get the selection as a bool
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
CP::MCTCDecorationAlg::m_fromHadronDecorator
std::unique_ptr< const SG::AuxElement::Decorator< int > > m_fromHadronDecorator
the decorator for m_fromHadDecoration
Definition: MCTCDecorationAlg.h:76
CP::MCTCDecorationAlg::m_fromHadronDecoration
Gaudi::Property< std::string > m_fromHadronDecoration
the decoration for the hadronic origin
Definition: MCTCDecorationAlg.h:72
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CP::MCTCDecorationAlg::m_classificationAccessor
std::unique_ptr< const SG::AuxElement::ConstAccessor< unsigned int > > m_classificationAccessor
the accessor for m_classificationDecoration
Definition: MCTCDecorationAlg.h:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::TruthHelpers::getTruthParticle
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any)
Definition: xAODTruthHelpers.cxx:25
CP::MCTCDecorationAlg::m_isPromptDecoration
Gaudi::Property< std::string > m_isPromptDecoration
the decoration for the promptness
Definition: MCTCDecorationAlg.h:64
xAOD::TruthParticle_v1::status
int status() const
Status code.
CP::MCTCDecorationAlg::initialize
virtual StatusCode initialize() override
Definition: MCTCDecorationAlg.cxx:26
CP::MCTCDecorationAlg::m_fromTauDecorator
std::unique_ptr< const SG::AuxElement::Decorator< int > > m_fromTauDecorator
the decorator for m_fromTauDecoration
Definition: MCTCDecorationAlg.h:92
MCTruthPartClassifier::isPrompt
int isPrompt(const unsigned int classify, bool allow_prompt_tau_decays=true)
Definition: TruthClassifiers.h:180
CP::SysReadSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysReadSelectionHandle.cxx:34
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
CP::MCTCDecorationAlg::m_classificationDecoration
Gaudi::Property< std::string > m_classificationDecoration
the decoration for the MCTC classification bitmask
Definition: MCTCDecorationAlg.h:56
TruthParticle.h
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CP::MCTCDecorationAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: MCTCDecorationAlg.h:42