ATLAS Offline Software
SoftElectronTruthDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
8 
11 
13 
16 
17 #include "xAODTruth/TruthVertex.h"
19 
21 
22 namespace FlavorTagDiscriminants {
23 
25  const std::string& name, ISvcLocator* loc )
26  : AthReentrantAlgorithm(name, loc) {}
27 
29  ATH_MSG_DEBUG( "Initializing " << name() << "... " );
30 
31  // Initialize Container keys
32  ATH_MSG_DEBUG( "Initializing containers:" );
34 
36 
37  // Initialise accessors
38  m_acc_origin_label = "TruthParticles." + m_acc_origin_label.key();
39  m_acc_type_label = "TruthParticles." + m_acc_type_label.key();
40  m_acc_source_label = "TruthParticles." + m_acc_source_label.key();
41  m_acc_vertex_index = "TruthParticles." + m_acc_vertex_index.key();
42  m_acc_parent_uniqueID = "TruthParticles." + m_acc_parent_uniqueID.key();
48 
49  // Initialise decorators
62 
63  return StatusCode::SUCCESS;
64  }
65 
66  StatusCode SoftElectronTruthDecoratorAlg::execute(const EventContext& ctx) const {
67  ATH_MSG_DEBUG( "Executing " << name() << "... " );
68 
70 
71  // read collections
73  ATH_CHECK( electrons.isValid() );
74  ATH_MSG_DEBUG( "Retrieved " << electrons->size() << " electrons..." );
75 
76  // instantiate accessors
78  RDH acc_origin_label(m_acc_origin_label, ctx);
79  RDH acc_type_label(m_acc_type_label, ctx);
80  RDH acc_source_label(m_acc_source_label, ctx);
81  RDH acc_vertex_index(m_acc_vertex_index, ctx);
82  RDH acc_parent_uniqueID(m_acc_parent_uniqueID, ctx);
83 
84  // instantiate decorators
86  WDH dec_origin_label(m_dec_origin_label, ctx);
87  WDH dec_type_label(m_dec_type_label, ctx);
88  WDH dec_source_label(m_dec_source_label, ctx);
89  WDH dec_vertex_index(m_dec_vertex_index, ctx);
90  WDH dec_uniqueID(m_dec_uniqueID, ctx);
91  WDH dec_parent_uniqueID(m_dec_parent_uniqueID, ctx);
92 
93  std::vector<const xAOD::Electron*> el_vector(electrons->begin(), electrons->end());
94  for ( const auto& electron : el_vector ) {
95 
96  // get the linked truth particle
97  const auto truth_link = m_truthParticleLink(*electron);
98 
99  if (!truth_link || !truth_link.isValid()) {
100  // if the truth link is broken, assume PU
101  dec_origin_label(*electron) = InDet::ExclusiveOrigin::Pileup;
104  dec_vertex_index(*electron) = -2;
105  dec_uniqueID(*electron) = HepMC::UNDEFINED_ID;
106  dec_parent_uniqueID(*electron) = HepMC::UNDEFINED_ID;
107  } else {
108  const auto *truth = *truth_link;
109  int electron_type = m_classifierParticleType(*truth);
110 
111  if (m_valid_types.count(electron_type)) {
112  dec_origin_label(*electron) = acc_origin_label(*truth);
113  }
114  else {
115  dec_origin_label(*electron) = InDet::ExclusiveOrigin::Fake;
116  }
117 
118  dec_vertex_index(*electron) = acc_vertex_index(*truth);
119  dec_type_label(*electron) = acc_type_label(*truth);
120  dec_source_label(*electron) = acc_source_label(*truth);
121  dec_uniqueID(*electron) = HepMC::uniqueID(truth);
122  dec_parent_uniqueID(*electron) = acc_parent_uniqueID(*truth);
123  }
124  }
125  return StatusCode::SUCCESS;
126  }
127 }
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::SoftElectronTruthDecoratorAlg
SoftElectronTruthDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SoftElectronTruthDecoratorAlg.cxx:24
FlavorTagDiscriminants
Definition: DL2.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TruthVertexContainer.h
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_vertex_index
WDHK m_dec_vertex_index
Definition: SoftElectronTruthDecoratorAlg.h:67
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: SoftElectronTruthDecoratorAlg.cxx:66
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_valid_types
const std::set< int > m_valid_types
Definition: SoftElectronTruthDecoratorAlg.h:84
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_origin_label
RDHK m_acc_origin_label
Definition: SoftElectronTruthDecoratorAlg.h:40
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_vertex_index
RDHK m_acc_vertex_index
Definition: SoftElectronTruthDecoratorAlg.h:49
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_source_label
WDHK m_dec_source_label
Definition: SoftElectronTruthDecoratorAlg.h:64
TruthDecoratorHelpers.h
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_origin_label
WDHK m_dec_origin_label
Definition: SoftElectronTruthDecoratorAlg.h:58
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_ElectronContainerKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
Definition: SoftElectronTruthDecoratorAlg.h:34
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
InDet::ExclusiveOrigin::Pileup
@ Pileup
Definition: InDetTrackTruthOriginDefs.h:161
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_parent_uniqueID
RDHK m_acc_parent_uniqueID
Definition: SoftElectronTruthDecoratorAlg.h:52
EgammaxAODHelpers.h
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
ElectronContainer.h
SG::ReadDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_parent_uniqueID
WDHK m_dec_parent_uniqueID
Definition: SoftElectronTruthDecoratorAlg.h:73
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::ElectronContainer
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/ElectronContainer.h:17
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:56
TruthVertex.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
MagicNumbers.h
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_type_label
WDHK m_dec_type_label
Definition: SoftElectronTruthDecoratorAlg.h:61
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_source_label
RDHK m_acc_source_label
Definition: SoftElectronTruthDecoratorAlg.h:46
InDetTrackTruthOriginDefs.h
FlavorTagDiscriminants::TruthDecoratorHelpers::TruthType::NoTruth
@ NoTruth
Definition: TruthDecoratorHelpers.h:17
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
InDet::ExclusiveOrigin::Fake
@ Fake
Definition: InDetTrackTruthOriginDefs.h:162
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_uniqueID
WDHK m_dec_uniqueID
Definition: SoftElectronTruthDecoratorAlg.h:70
ReadDecorHandle.h
Handle class for reading a decoration on an object.
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_type_label
RDHK m_acc_type_label
Definition: SoftElectronTruthDecoratorAlg.h:43
TRT_PAI_gasdata::EC
const float EC[NC]
Energy levels for Carbon.
Definition: TRT_PAI_gasdata.h:241
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: SoftElectronTruthDecoratorAlg.cxx:28
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_truthParticleLink
Acc< ElementLink< xAOD::TruthParticleContainer > > m_truthParticleLink
Definition: SoftElectronTruthDecoratorAlg.h:89
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_classifierParticleType
Acc< unsigned int > m_classifierParticleType
Definition: SoftElectronTruthDecoratorAlg.h:88
SoftElectronTruthDecoratorAlg.h