ATLAS Offline Software
Loading...
Searching...
No Matches
McAodTupleWriterTool Class Reference

#include <McAodTupleWriterTool.h>

Inheritance diagram for McAodTupleWriterTool:
Collaboration diagram for McAodTupleWriterTool:

Classes

struct  McAodParticles
 A simple representation of a TruthParticle. More...

Public Member Functions

 McAodTupleWriterTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor with parameters:
virtual ~McAodTupleWriterTool ()
 Destructor:
StatusCode initialize ()
 Athena Algorithm's Hooks.
StatusCode execute ()
StatusCode finalize ()
StatusCode write (const TruthParticleContainer *mcAod)
 Process the TruthParticleContainer through the I/O backend.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Inline methods:

Protected Member Functions

 McAodTupleWriterTool ()
 Default constructor:
void setupBackend (Gaudi::Details::PropertyBase &outputFileName)
 Method to configure the back-end to write out the HepMC::GenEvent.
void bookTuple ()
 book the tuple
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Protected Attributes

McAodParticles m_particles {}
 our cached particles
ServiceHandle< ITHistSvc > m_tupleSvc
 Pointer to @ ITHistSvc.
StringProperty m_truthParticlesName
 Location of the TruthParticleContainer to be written out.
StringProperty m_outputFileName
 Name of the output tuple file.
StringProperty m_outputStreamName
 Name of the output tuple stream.
TTree * m_tuple
 cached pointer to the tuple

Static Protected Attributes

static const int s_nMax = 2000
 maximum number of particles per event

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 31 of file McAodTupleWriterTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ McAodTupleWriterTool() [1/2]

McAodTupleWriterTool::McAodTupleWriterTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor with parameters:

Public methods:

Constructors

Definition at line 35 of file McAodTupleWriterTool.cxx.

37 :
38 AthAlgTool( type, name, parent ),
39 m_tupleSvc ( "THistSvc", name ),
40 m_tuple ( nullptr )
41{
42 //
43 // Property declaration
44 //
45
46 declareProperty( "Output",
47 m_outputFileName = "mcaod.root",
48 "Name of the output file which will contain the McAod "
49 "tuple. Ex: mcaod.root" );
51 this );
52
53 declareProperty( "OutputStream",
54 m_outputStreamName = "mcaod",
55 "Name of the stream which will contain the McAod tuple. "
56 "Ex: mcaod" );
57
58 declareProperty( "TruthParticles",
59 m_truthParticlesName = "GEN_EVENT",
60 "Input location of the TruthParticleContainer to write "
61 "out." );
62
63 declareInterface<IIOMcAodTool>(this);
64}
AthAlgTool()
Default constructor:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
TTree * m_tuple
cached pointer to the tuple
StringProperty m_outputStreamName
Name of the output tuple stream.
StringProperty m_outputFileName
Name of the output tuple file.
ServiceHandle< ITHistSvc > m_tupleSvc
Pointer to @ ITHistSvc.
StringProperty m_truthParticlesName
Location of the TruthParticleContainer to be written out.
void setupBackend(Gaudi::Details::PropertyBase &outputFileName)
Method to configure the back-end to write out the HepMC::GenEvent.

◆ ~McAodTupleWriterTool()

McAodTupleWriterTool::~McAodTupleWriterTool ( )
virtual

Destructor:

Destructor.

Definition at line 68 of file McAodTupleWriterTool.cxx.

69{
70 ATH_MSG_DEBUG("Calling destructor");
71
72}
#define ATH_MSG_DEBUG(x)

◆ McAodTupleWriterTool() [2/2]

McAodTupleWriterTool::McAodTupleWriterTool ( )
protected

Default constructor:

Member Function Documentation

◆ bookTuple()

void McAodTupleWriterTool::bookTuple ( )
protected

book the tuple

Definition at line 212 of file McAodTupleWriterTool.cxx.

213{
214 delete m_tuple;
215 const std::string streamName = m_outputStreamName.value();
216 TTree* t = new TTree("mcaod","McAod validation tuple");
217 if ( !m_tupleSvc->regTree( "/" + streamName + "/mcaod", t ).isSuccess() ) {
218 ATH_MSG_ERROR("Could not register McAod validation tuple !!");
219 delete t; t = nullptr;
220 throw GaudiException( "Could not register McAod validation tuple !!",
221 name(),
222 StatusCode::FAILURE );
223 }
224
225 // booking branches
226 t->Branch( "nParts", &m_particles.m_nParticles, "nParts/i" );
227
228 t->Branch( "px", m_particles.m_px.data(), "px[nParts]/D" );
229 t->Branch( "py", m_particles.m_py.data(), "py[nParts]/D" );
230 t->Branch( "pz", m_particles.m_pz.data(), "pz[nParts]/D" );
231 t->Branch( "m", m_particles.m_m.data(), "m[nParts]/D" );
232 t->Branch( "e", m_particles.m_ene.data(), "e[nParts]/D" );
233
234 t->Branch( "pdgId", m_particles.m_pdgId.data(), "pdgId[nParts]/I" );
235 t->Branch( "sc", m_particles.m_status.data(), "sc[nParts]/I" );
236 t->Branch( "bc", m_particles.m_barcode.data(), "bc[nParts]/I" );
237
238 t->Branch( "etcone10", m_particles.m_etcone10.data(), "etcone10[nParts]/D" );
239 t->Branch( "etcone20", m_particles.m_etcone20.data(), "etcone20[nParts]/D" );
240 t->Branch( "etcone30", m_particles.m_etcone30.data(), "etcone30[nParts]/D" );
241 t->Branch( "etcone40", m_particles.m_etcone40.data(), "etcone40[nParts]/D" );
242 t->Branch( "etcone45", m_particles.m_etcone45.data(), "etcone45[nParts]/D" );
243 t->Branch( "etcone50", m_particles.m_etcone50.data(), "etcone50[nParts]/D" );
244 t->Branch( "etcone60", m_particles.m_etcone60.data(), "etcone60[nParts]/D" );
245 t->Branch( "etcone70", m_particles.m_etcone70.data(), "etcone70[nParts]/D" );
246
247 m_tuple = t;
248}
#define ATH_MSG_ERROR(x)
McAodParticles m_particles
our cached particles

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

StatusCode McAodTupleWriterTool::execute ( )
virtual

Implements IIOMcAodTool.

Definition at line 106 of file McAodTupleWriterTool.cxx.

107{
108 // retrieve the TruthParticleContainer
109 const TruthParticleContainer * mc = nullptr;
110 if ( evtStore()->retrieve( mc, m_truthParticlesName ).isFailure() ||
111 nullptr == mc ) {
112 ATH_MSG_ERROR("Could not retrieve a TruthParticleContainer at ["
113 << m_truthParticlesName << "] !!");
114 return StatusCode::FAILURE;
115 }
116
117 if ( mc->empty() ) {
118 ATH_MSG_WARNING("TruthParticleContainer at [" << m_truthParticlesName
119 << "] is EMPTY !!");
120 return StatusCode::FAILURE;
121 }
122
123 return write(mc);
124}
#define ATH_MSG_WARNING(x)
Athena::TPCnvVers::Current TruthParticleContainer
ServiceHandle< StoreGateSvc > & evtStore()
StatusCode write(const TruthParticleContainer *mcAod)
Process the TruthParticleContainer through the I/O backend.
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ finalize()

StatusCode McAodTupleWriterTool::finalize ( )
virtual

Implements IIOMcAodTool.

Definition at line 100 of file McAodTupleWriterTool.cxx.

101{
102 ATH_MSG_INFO("Finalizing " << name() << "...");
103 return StatusCode::SUCCESS;
104}
#define ATH_MSG_INFO(x)

◆ initialize()

StatusCode McAodTupleWriterTool::initialize ( )
virtual

Athena Algorithm's Hooks.

Implements IIOMcAodTool.

Definition at line 76 of file McAodTupleWriterTool.cxx.

77{
78 ATH_MSG_INFO("Initializing " << name() << "...");
79 // Get pointer to StoreGateSvc and cache it :
80 if ( !evtStore().retrieve().isSuccess() ) {
81 ATH_MSG_ERROR("Unable to retrieve pointer to StoreGateSvc");
82 return StatusCode::FAILURE;
83 }
84
85 // Get pointer to ITHistSvc and cache it :
86 if ( !m_tupleSvc.retrieve().isSuccess() ) {
87 ATH_MSG_ERROR("Unable to retrieve pointer to ITHistSvc");
88 return StatusCode::FAILURE;
89 }
90
91 // setup backend
93
94 // book tuple
95 bookTuple();
96
97 return StatusCode::SUCCESS;
98}
void bookTuple()
book the tuple

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ interfaceID()

const InterfaceID & IIOMcAodTool::interfaceID ( )
inlinestaticinherited

Inline methods:

Definition at line 59 of file IIOMcAodTool.h.

60{
61 return IID_IIOMcAodTool;
62}
static const InterfaceID IID_IIOMcAodTool("IIOMcAodTool", 1, 0)

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ setupBackend()

void McAodTupleWriterTool::setupBackend ( Gaudi::Details::PropertyBase & outputFileName)
protected

Method to configure the back-end to write out the HepMC::GenEvent.

Protected methods:

Const methods: Non-const methods:

Definition at line 179 of file McAodTupleWriterTool.cxx.

180{
181 if ( m_tupleSvc.retrieve().isFailure() ) {
182 ATH_MSG_ERROR("Could not retrieve THistSvc handle !!");
183 throw GaudiException( "Could not retrieve THistSvc",
184 name(),
185 StatusCode::FAILURE );
186 }
187
188 SmartIF<IProperty> tSvc(m_tupleSvc.get());
189 const std::string streamName = m_outputStreamName.value();
190
191 const std::string propName = "Output";
192 StringArrayProperty outputFileName;
193 outputFileName.assign( tSvc->getProperty( propName ) );
194 std::vector<std::string> updatedProp( outputFileName.value() );
195 updatedProp.push_back
196 ( streamName+" DATAFILE='"+m_outputFileName.value()+"' "
197 "TYP='ROOT' "
198 "OPT='RECREATE'"
199 );
200 outputFileName.set( updatedProp );
201 outputFileName.setName( std::move(propName) );
202 if ( !tSvc->setProperty( outputFileName ).isSuccess() ) {
203 ATH_MSG_ERROR("Could not configure the THistSvc's output filename ["
204 << m_outputFileName.value() << "] !!");
205 throw GaudiException( "Could not configure THistSvc output file !!",
206 name(),
207 StatusCode::FAILURE );
208 }
209
210 }
static const std::string outputFileName

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

◆ write()

StatusCode McAodTupleWriterTool::write ( const TruthParticleContainer * mc)

Process the TruthParticleContainer through the I/O backend.

Const methods:

Non-const methods:

Definition at line 134 of file McAodTupleWriterTool.cxx.

135{
136 m_particles.m_nParticles = std::min<std::size_t>( s_nMax, mc->size() );
137 for ( std::size_t i = 0; i != m_particles.m_nParticles; ++i ) {
138 const TruthParticle * p = (*mc)[i];
139 m_particles.m_px [i] = p->px();
140 m_particles.m_py [i] = p->py();
141 m_particles.m_pz [i] = p->pz();
142 m_particles.m_m [i] = p->m();
143 m_particles.m_ene[i] = p->e();
144
145 m_particles.m_pdgId[i] = p->pdgId();
146 m_particles.m_status[i] = p->status();
147 m_particles.m_barcode[i] = p->barcode();
148
149 using namespace TruthParticleParameters;
150
151 m_particles.m_etcone10[i] = p->etIsol(etcone10);
152 m_particles.m_etcone20[i] = p->etIsol(etcone20);
153 m_particles.m_etcone30[i] = p->etIsol(etcone30);
154 m_particles.m_etcone40[i] = p->etIsol(etcone40);
155 m_particles.m_etcone45[i] = p->etIsol(etcone );
156 m_particles.m_etcone50[i] = p->etIsol(etcone50);
157 m_particles.m_etcone60[i] = p->etIsol(etcone60);
158 m_particles.m_etcone70[i] = p->etIsol(etcone70);
159 }
160
161 // commit event
162 m_tuple->Fill();
163
164 return StatusCode::SUCCESS;
165}
static const int s_nMax
maximum number of particles per event
TruthParticle_v1 TruthParticle
Typedef to implementation.

Member Data Documentation

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_outputFileName

StringProperty McAodTupleWriterTool::m_outputFileName
protected

Name of the output tuple file.

Definition at line 126 of file McAodTupleWriterTool.h.

◆ m_outputStreamName

StringProperty McAodTupleWriterTool::m_outputStreamName
protected

Name of the output tuple stream.

Definition at line 129 of file McAodTupleWriterTool.h.

◆ m_particles

McAodParticles McAodTupleWriterTool::m_particles {}
protected

our cached particles

Definition at line 116 of file McAodTupleWriterTool.h.

116{};

◆ m_truthParticlesName

StringProperty McAodTupleWriterTool::m_truthParticlesName
protected

Location of the TruthParticleContainer to be written out.

Definition at line 123 of file McAodTupleWriterTool.h.

◆ m_tuple

TTree* McAodTupleWriterTool::m_tuple
protected

cached pointer to the tuple

Definition at line 132 of file McAodTupleWriterTool.h.

◆ m_tupleSvc

ServiceHandle<ITHistSvc> McAodTupleWriterTool::m_tupleSvc
protected

Pointer to @ ITHistSvc.

Definition at line 119 of file McAodTupleWriterTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.

◆ s_nMax

const int McAodTupleWriterTool::s_nMax = 2000
staticprotected

maximum number of particles per event

Definition at line 92 of file McAodTupleWriterTool.h.


The documentation for this class was generated from the following files: