ATLAS Offline Software
TruthParticleBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TruthParticleBuilder.cxx
7 // Implementation file for class TruthParticleBuilder
8 // Author: S.Binet<binet@cern.ch>
10 
11 
12 // STL includes
13 
14 // FrameWork includes
15 #include "Gaudi/Property.h"
16 
17 // McParticleKernel includes
20 
21 // McParticleAlgs includes
22 #include "TruthParticleBuilder.h"
23 
27 
31  ISvcLocator* pSvcLocator ) :
32  AthAlgorithm ( name, pSvcLocator )
33 {
34  //
35  // Property declaration
36  //
37  //declareProperty( "Property", m_nProperty );
38 
39  std::string descr = "";
40 // descr += "Fully qualified name ('[class name]/[instance name]') of the ";
41 // descr += "AlgTool to be ran to create a filtered McEventCollection\n";
42 // descr += "ex: \"EtaPtFilterTool/EtaPtFilterTool\"";
43 // declareProperty( "Filter",
44 // m_filterName = "EtaPtFilterTool",
45 // descr );
46 // m_filterName.declareUpdateHandler( &TruthParticleBuilder::setupFilterTool,
47 // this );
48 
49  descr = "Pointer to the filter algtool (which will create the filtered ";
50  descr += "McEventCollection)";
51  declareProperty( "FilterTool",
52  m_filterTool = FilterTool_t( "EtaPtFilterTool",
53  this ),
54  descr );
55 
56  descr = "Pointer to the converter algtool which will create a ";
57  descr += "TruthParticleContainer from the filtered McEventCollection";
58  declareProperty( "CnvTool",
59  m_cnvTool = CnvTool_t( "TruthParticleCnvTool",
60  this ),
61  descr );
62 
63  // switches
64  descr = "Switch to build or not a filtered McEventCollection";
65  declareProperty( "DoFiltering",
66  m_doFiltering = true,
67  descr );
69  this );
70 
71  descr = "Switch to build or not the TruthParticleContainer from the ";
72  descr += "filtered GenEvent";
73  declareProperty( "DoTruthParticles",
74  m_doTruthParticles = true,
75  descr );
77  this );
78 }
79 
83 {}
84 
88 {
89  ATH_MSG_INFO ("Initializing " << name() << "...");
90 
91  // setup the filter tool
93 
94  // setup the converter tool
96 
97  return StatusCode::SUCCESS;
98 }
99 
101 {
102  ATH_MSG_INFO ("Finalizing " << name() << "...");
103  return StatusCode::SUCCESS;
104 }
105 
107 {
108  ATH_MSG_DEBUG ("Executing " << name() << "...");
109 
110  // create a new McEventCollection (AOD) from an old one (ex:ESD)
111  // apply some filtering criterion (if any)
112  if ( m_doFiltering &&
113  !m_filterTool->execute().isSuccess() ) {
115  ("Could not build the AOD McEventCollection ! [algtool="
116  << m_filterTool.type() << "]");
117  return StatusCode::SUCCESS;
118  }
119 
120  // create a TruthParticleContainer from a McEventCollection
121  if ( m_doTruthParticles &&
122  !m_cnvTool->execute().isSuccess() ) {
124  ("Could not convert the AOD McEventCollection into "\
125  "a TruthParticleContainer !");
126  return StatusCode::SUCCESS;
127  }
128 
129  return StatusCode::SUCCESS;
130 }
131 
135 
136 void TruthParticleBuilder::setupFilterTool( Gaudi::Details::PropertyBase& /*doFiltering*/ )
137 {
138  if ( m_doFiltering ) {
139 
140  if ( !m_filterTool.retrieve().isSuccess() ) {
142  ("Could not retrieve algTool ITruthParticleFilterTool ["
143  << m_filterTool.type() << "/"
144  //<< m_filterTool.name()
145  << "] !!");
146  throw std::runtime_error("Could not setup FilterTool property !");
147  } else {
149  ("Retrieved and configured algTool ["
150  << m_filterTool.type() << "/"
151  //<< m_filterTool.name()
152  << "]");
153  }
154  } else {
155  if ( !m_filterTool.release().isSuccess() ) {
157  ("Could not release algTool ITruthParticleFilterTool ["
158  << m_filterTool.type() << "/"
159  //<< m_filterTool.name()
160  << "] !!"
161  << endmsg
162  << "Memory won't be freed until ::finalize()...");
163  } else {
165  ("Released algTool [" << m_filterTool.type() << "/"
166  //<< m_filterTool.name()
167  << "]");
168  }
169  }
170 
171  return;
172 }
173 
174 void TruthParticleBuilder::setupCnvTool( Gaudi::Details::PropertyBase& /*doTruthParticles*/ )
175 {
176  if ( m_doTruthParticles ) {
177 
178  if ( !m_cnvTool.retrieve().isSuccess() ) {
180  ("Could not retrieve algTool ITruthParticleCnvTool ["
181  << m_cnvTool.type() << "/"
182  //<< m_cnvTool.name()
183  << "] !!");
184  throw std::runtime_error("Could not setup CnvTool property !");
185  } else {
187  ("Retrieved and configured algTool [" << m_cnvTool.type() << "/"
188  //<< m_cnvTool.name()
189  << "]");
190  }
191 
192  } else {
193  if ( !m_cnvTool.release().isSuccess() ) {
195  ("Could not release algTool ITruthParticleCnvTool ["
196  << m_cnvTool.type() << "/"
197  //<< m_cnvTool.name()
198  << "] !!"
199  << endmsg
200  << "Memory won't be freed until ::finalize()...");
201  } else {
203  ("Released algTool [" << m_cnvTool.type() << "/"
204  //<< m_cnvTool.name()
205  << "]");
206  }
207  }
208 
209  return;
210 }
TruthParticleBuilder::m_doTruthParticles
BooleanProperty m_doTruthParticles
Switch to build or not the TruthParticleContainer from the filtered GenEvent.
Definition: TruthParticleBuilder.h:91
ITruthParticleCnvTool.h
TruthParticleBuilder::m_doFiltering
BooleanProperty m_doFiltering
Switch to build or not a filtered McEventCollection.
Definition: TruthParticleBuilder.h:86
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TruthParticleBuilder::m_filterTool
FilterTool_t m_filterTool
Pointer to the filter algtool (which will create the filtered McEventCollection)
Definition: TruthParticleBuilder.h:76
TruthParticleBuilder::~TruthParticleBuilder
virtual ~TruthParticleBuilder()
Destructor:
Definition: TruthParticleBuilder.cxx:82
TruthParticleBuilder::execute
virtual StatusCode execute()
Definition: TruthParticleBuilder.cxx:106
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TruthParticleBuilder::setupFilterTool
void setupFilterTool(Gaudi::Details::PropertyBase &doFiltering)
Call-back method to configure the filter tool if needed (this is defined by the state of the "DoFilte...
Definition: TruthParticleBuilder.cxx:136
TruthParticleBuilder::finalize
virtual StatusCode finalize()
Definition: TruthParticleBuilder.cxx:100
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
TruthParticleBuilder::CnvTool_t
ToolHandle< ITruthParticleCnvTool > CnvTool_t
Definition: TruthParticleBuilder.h:78
python.TransformConfig.descr
descr
print "%s.properties()" % self.__name__
Definition: TransformConfig.py:360
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TruthParticleBuilder::m_cnvTool
CnvTool_t m_cnvTool
Pointer to the converter algtool which will create a TruthParticleContainer from the filtered McEvent...
Definition: TruthParticleBuilder.h:82
TruthParticleBuilder::FilterTool_t
ToolHandle< ITruthParticleFilterTool > FilterTool_t
Definition: TruthParticleBuilder.h:72
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TruthParticleBuilder::setupCnvTool
void setupCnvTool(Gaudi::Details::PropertyBase &doTruthParticles)
Call-back method to configure the converter tool if needed (this is defined by the state of the "DoTr...
Definition: TruthParticleBuilder.cxx:174
ITruthParticleFilterTool.h
TruthParticleBuilder::initialize
virtual StatusCode initialize()
Athena Algorithm's Hooks.
Definition: TruthParticleBuilder.cxx:87
TruthParticleBuilder::TruthParticleBuilder
TruthParticleBuilder()
Default constructor:
TruthParticleBuilder.h