ATLAS Offline Software
TruthClassificationDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TruthClassificationDecorator.cxx
7 // Decorates truth particles with the output of the MCTruthClassifier
8 
11 #include "StoreGate/ReadHandle.h"
15 #include <vector>
16 #include <string>
17 
18 // Constructor
20  const std::string& n,
21  const IInterface* p ) :
22 AthAlgTool(t,n,p),
23 m_ntotpart(0),
24 m_classifier("MCTruthClassifier/MCTruthClassifier")
25 {
26  declareInterface<DerivationFramework::IAugmentationTool>(this);
27  declareProperty("MCTruthClassifier", m_classifier);
28 }
29 
30 // Destructor
32 }
33 
34 // Athena initialize and finalize
36 {
37  ATH_MSG_VERBOSE("initialize() ...");
38  ATH_CHECK(m_classifier.retrieve());
39 
40  ATH_CHECK( m_particlesKey.initialize() );
41  ATH_MSG_INFO("Decorating " << m_particlesKey.key() << " with classification information");
42 
43  // Decorators
44  ATH_CHECK(m_linkDecoratorKey.initialize());
45  ATH_CHECK(m_originDecoratorKey.initialize());
46  ATH_CHECK(m_typeDecoratorKey.initialize());
47  ATH_CHECK(m_outcomeDecoratorKey.initialize());
48  ATH_CHECK(m_classificationDecoratorKey.initialize());
49 
50  return StatusCode::SUCCESS;
51 }
52 
54 {
55  ATH_MSG_VERBOSE("finalize() ...");
56  ATH_MSG_INFO("Processed and decorated "<< m_ntotpart <<" truth particles");
57  return StatusCode::SUCCESS;
58 }
59 
60 // Selection and collection creation
62 {
63 
64  // Event context for multi-threading
65  const EventContext& ctx = Gaudi::Hive::currentContext();
66 
67  // Retrieve truth collections
68  SG::ReadHandle<xAOD::TruthParticleContainer> truthParticles(m_particlesKey,ctx);
69  if (!truthParticles.isValid()) {
70  ATH_MSG_ERROR("Couldn't retrieve TruthParticle collection with name " << m_particlesKey);
71  return StatusCode::FAILURE;
72  }
73 
74  unsigned int nParticles = truthParticles->size();
75  m_ntotpart += nParticles;
76 
77  // Set up decorators
79  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> originDecorator(m_originDecoratorKey, ctx);
80  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> typeDecorator(m_typeDecoratorKey, ctx);
81  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> outcomeDecorator(m_outcomeDecoratorKey, ctx);
82  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> classificationDecorator(m_classificationDecoratorKey, ctx);
83 
84  for (unsigned int i=0; i<nParticles; ++i) {
86  std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin> classification =
87  m_classifier->particleTruthClassifier((*truthParticles)[i], &info);
88  unsigned int particleOutCome = info.particleOutCome;
89  unsigned int result = (unsigned int)( (*truthParticles)[i] ? std::get<0>(MCTruthPartClassifier::defOrigOfParticle((*truthParticles)[i])) : 0 );
90  unsigned int particleType = classification.first;
91  unsigned int particleOrigin = classification.second;
92  typeDecorator(*((*truthParticles)[i])) = particleType;
93  originDecorator(*((*truthParticles)[i])) = particleOrigin;
94  outcomeDecorator(*((*truthParticles)[i])) = particleOutCome;
95 
96  classificationDecorator(*((*truthParticles)[i])) = result;
97  }
98 
99  return StatusCode::SUCCESS;
100 }
101 
grepfile.info
info
Definition: grepfile.py:38
TruthClassificationDecorator.h
get_generator_info.result
result
Definition: get_generator_info.py:21
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TruthParticleContainer.h
DerivationFramework::TruthClassificationDecorator::TruthClassificationDecorator
TruthClassificationDecorator(const std::string &t, const std::string &n, const IInterface *p)
Definition: TruthClassificationDecorator.cxx:19
MCTruthPartClassifier::defOrigOfParticle
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
Definition: TruthClassifiers.h:151
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::TruthClassificationDecorator::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: TruthClassificationDecorator.cxx:61
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::TruthClassificationDecorator::initialize
StatusCode initialize()
Definition: TruthClassificationDecorator.cxx:35
DerivationFramework::TruthClassificationDecorator::finalize
StatusCode finalize()
Definition: TruthClassificationDecorator.cxx:53
particleType
Definition: particleType.h:29
TruthParticleAuxContainer.h
IMCTruthClassifier.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DerivationFramework::TruthClassificationDecorator::m_classifier
ToolHandle< IMCTruthClassifier > m_classifier
Definition: TruthClassificationDecorator.h:44
DerivationFramework::TruthClassificationDecorator::~TruthClassificationDecorator
~TruthClassificationDecorator()
Definition: TruthClassificationDecorator.cxx:31
ReadHandle.h
Handle class for reading from StoreGate.
AthAlgTool
Definition: AthAlgTool.h:26
MCTruthPartClassifier::Info
Definition: IMCTruthClassifier.h:49
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.