ATLAS Offline Software
TruthClassDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "TruthClassDecoratorAlg.h"
12 #include "safeDecorator.h"
13 
14 
15 TruthClassDecoratorAlg::TruthClassDecoratorAlg(const std::string& name, ISvcLocator* pSvcLocator) :
16  AthReentrantAlgorithm(name,pSvcLocator)
17 {
18 }
19 
22  ATH_CHECK(m_truthClassifier.retrieve());
23  ATH_CHECK( m_truthSelectionTool.retrieve( EnableTool { not m_truthSelectionTool.name().empty() } ) );
25 
26  std::vector<std::string> decor_names(kNDecorators);
27  decor_names[kDecorTruthType]="truthType";
28  decor_names[kDecorTruthOrigin]="truthOrigin";
29  IDPVM::createDecoratorKeys(*this, m_truthParticleName, m_prefix.value(), decor_names, m_decor);
30  assert( m_decor.size() == kNDecorators);
31  return StatusCode::SUCCESS;
32 }
33 
36  return StatusCode::SUCCESS;
37 }
38 
39 
40 // to migrate to AthReentrantAlgorithm later
42 TruthClassDecoratorAlg::execute(const EventContext &ctx) const {
44  if ((not ptruth.isValid())) {
45  return StatusCode::FAILURE;
46  }
47 
48  std::vector< SG::WriteDecorHandle<xAOD::TruthParticleContainer,int> >
49  int_decor( IDPVM::createDecorators<xAOD::TruthParticleContainer,int>(m_decor, ctx) );
50 
51  if (m_truthSelectionTool.get()) {
52  for (const xAOD::TruthParticle *truth_particle : *ptruth) {
53  if (not m_truthSelectionTool->accept(truth_particle)) continue;
54  if (not decorateTruth(*truth_particle, int_decor) ) return StatusCode::FAILURE;
55  }
56  }
57  else {
58  for (const xAOD::TruthParticle *truth_particle : *ptruth) {
59  if (not decorateTruth(*truth_particle, int_decor) ) return StatusCode::FAILURE;
60  }
61  }
62  return StatusCode::SUCCESS;
63 }
64 
65 bool
67  std::vector< SG::WriteDecorHandle<xAOD::TruthParticleContainer,int> > &int_decor) const {
68  bool success(false);
69 
70  if (not m_truthClassifier.empty()) {
71  auto truthClass = m_truthClassifier->particleTruthClassifier(&particle);
72  int type = static_cast<int>(truthClass.first);
73  int origin = static_cast<int>(truthClass.second);
74  int_decor[kDecorTruthType](particle) = type;
75  int_decor[kDecorTruthOrigin](particle) = origin;
76  success = true;
77  }
78  return success;
79 }
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
TruthClassDecoratorAlg::m_truthParticleName
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
TruthParticle container's name needed to create decorators.
Definition: TruthClassDecoratorAlg.h:47
TruthClassDecoratorAlg::TruthClassDecoratorAlg
TruthClassDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TruthClassDecoratorAlg.cxx:15
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TruthClassDecoratorAlg::kDecorTruthType
@ kDecorTruthType
Definition: TruthClassDecoratorAlg.h:53
safeDecorator.h
TruthClassDecoratorAlg::decorateTruth
bool decorateTruth(const xAOD::TruthParticle &particle, std::vector< SG::WriteDecorHandle< xAOD::TruthParticleContainer, int > > &int_decor) const
Definition: TruthClassDecoratorAlg.cxx:66
TruthClassDecoratorAlg::kDecorTruthOrigin
@ kDecorTruthOrigin
Definition: TruthClassDecoratorAlg.h:54
TruthClassDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TruthClassDecoratorAlg.cxx:42
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TruthClassDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: TruthClassDecoratorAlg.cxx:21
TruthClassDecoratorAlg::kNDecorators
@ kNDecorators
Definition: TruthClassDecoratorAlg.h:55
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TruthClassDecoratorAlg::m_truthClassifier
PublicToolHandle< IMCTruthClassifier > m_truthClassifier
Definition: TruthClassDecoratorAlg.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TruthClassDecoratorAlg.h
TruthClassDecoratorAlg::m_decor
std::vector< SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > > m_decor
Definition: TruthClassDecoratorAlg.h:57
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IDPVM::createDecoratorKeys
void createDecoratorKeys(T_Parent &parent, const SG::ReadHandleKey< T_Cont > &container_key, const std::string &prefix, const std::vector< std::string > &decor_names, std::vector< SG::WriteDecorHandleKey< T_Cont > > &decor_out)
Definition: safeDecorator.h:125
TruthClassDecoratorAlg::finalize
virtual StatusCode finalize() override
Definition: TruthClassDecoratorAlg.cxx:35
TruthClassDecoratorAlg::m_truthSelectionTool
PublicToolHandle< IAthSelectionTool > m_truthSelectionTool
Definition: TruthClassDecoratorAlg.h:43
TruthClassDecoratorAlg::m_prefix
Gaudi::Property< std::string > m_prefix
Definition: TruthClassDecoratorAlg.h:50