ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
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
136void 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
174void 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}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
BooleanProperty m_doFiltering
Switch to build or not a filtered McEventCollection.
virtual StatusCode finalize()
virtual ~TruthParticleBuilder()
Destructor:
ToolHandle< ITruthParticleCnvTool > CnvTool_t
BooleanProperty m_doTruthParticles
Switch to build or not the TruthParticleContainer from the filtered GenEvent.
CnvTool_t m_cnvTool
Pointer to the converter algtool which will create a TruthParticleContainer from the filtered McEvent...
TruthParticleBuilder()
Default constructor:
FilterTool_t m_filterTool
Pointer to the filter algtool (which will create the filtered McEventCollection)
virtual StatusCode execute()
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...
ToolHandle< ITruthParticleFilterTool > FilterTool_t
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...
virtual StatusCode initialize()
Athena Algorithm's Hooks.