ATLAS Offline Software
SoftElectronTruthDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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_barcode = "TruthParticles." + m_acc_parent_barcode.key(); // FIXME barcode-based
47  ATH_CHECK( m_acc_parent_barcode.initialize() ); // FIXME barcode-based
48 
49  // Initialise decorators
54  m_dec_barcode = m_ElectronContainerKey.key() + "." + m_dec_barcode.key(); // FIXME barcode-based
55  m_dec_parent_barcode = m_ElectronContainerKey.key() + "." + m_dec_parent_barcode.key(); // FIXME barcode-based
60  ATH_CHECK( m_dec_barcode.initialize() ); // FIXME barcode-based
61  ATH_CHECK( m_dec_parent_barcode.initialize() ); // FIXME barcode-based
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_barcode(m_acc_parent_barcode, ctx); // FIXME barcode-based
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_barcode(m_dec_barcode, ctx); // FIXME barcode-based
91  WDH dec_parent_barcode(m_dec_parent_barcode, ctx); // FIXME barcode-based
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_barcode(*electron) = HepMC::UNDEFINED_ID;
106  dec_parent_barcode(*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_barcode(*electron) = HepMC::barcode(truth); // FIXME barcode-based
122  dec_parent_barcode(*electron) = acc_parent_barcode(*truth); // FIXME barcode-based
123  }
124  }
125  return StatusCode::SUCCESS;
126  }
127 }
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::SoftElectronTruthDecoratorAlg
SoftElectronTruthDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SoftElectronTruthDecoratorAlg.cxx:24
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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_dec_barcode
WDHK m_dec_barcode
Definition: SoftElectronTruthDecoratorAlg.h:70
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:83
InDet::ExclusiveOrigin::Pileup
@ Pileup
Definition: InDetTrackTruthOriginDefs.h:161
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
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
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.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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:55
TruthVertex.h
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_parent_barcode
WDHK m_dec_parent_barcode
Definition: SoftElectronTruthDecoratorAlg.h:73
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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.
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_parent_barcode
RDHK m_acc_parent_barcode
Definition: SoftElectronTruthDecoratorAlg.h:52
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
InDet::ExclusiveOrigin::Fake
@ Fake
Definition: InDetTrackTruthOriginDefs.h:162
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