ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
TruthParticleID
McParticleTools
src
McAodTupleWriterTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// McAodTupleWriterTool.cxx
7
// Implementation file for class McAodTupleWriterTool
8
// Author: S.Binet<binet@cern.ch>
10
11
12
// STL includes
13
//#include <sstream>
14
15
// FrameWork includes
16
#include "GaudiKernel/ITHistSvc.h"
17
#include "Gaudi/Property.h"
18
#include "GaudiKernel/GaudiException.h"
19
20
// ROOT includes
21
#include "TTree.h"
22
23
// McParticleEvent includes
24
#include "
McParticleEvent/TruthParticleContainer.h
"
25
26
// McParticleTools includes
27
#include "
McAodTupleWriterTool.h
"
28
32
35
McAodTupleWriterTool::McAodTupleWriterTool
(
const
std::string&
type
,
36
const
std::string& name,
37
const
IInterface* parent ) :
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"
);
50
m_outputFileName
.declareUpdateHandler( &
McAodTupleWriterTool::setupBackend
,
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
}
65
68
McAodTupleWriterTool::~McAodTupleWriterTool
()
69
{
70
ATH_MSG_DEBUG
(
"Calling destructor"
);
71
72
}
73
76
StatusCode
McAodTupleWriterTool::initialize
()
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
92
setupBackend
(
m_outputFileName
);
93
94
// book tuple
95
bookTuple
();
96
97
return
StatusCode::SUCCESS;
98
}
99
100
StatusCode
McAodTupleWriterTool::finalize
()
101
{
102
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
103
return
StatusCode::SUCCESS;
104
}
105
106
StatusCode
McAodTupleWriterTool::execute
()
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
}
125
129
133
134
StatusCode
McAodTupleWriterTool::write
(
const
TruthParticleContainer
*
mc
)
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
}
166
170
174
178
179
void
McAodTupleWriterTool::setupBackend
( Gaudi::Details::PropertyBase&
/*m_outputFileName*/
)
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
}
211
212
void
McAodTupleWriterTool::bookTuple
()
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
}
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
McAodTupleWriterTool.h
TruthParticleContainer.h
outputFileName
static const std::string outputFileName
Definition
ProduceDummyStripCabling.cxx:17
AthAlgTool::AthAlgTool
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Definition
AthAlgTool.cxx:16
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
McAodTupleWriterTool::write
StatusCode write(const TruthParticleContainer *mcAod)
Process the TruthParticleContainer through the I/O backend.
Definition
McAodTupleWriterTool.cxx:134
McAodTupleWriterTool::~McAodTupleWriterTool
virtual ~McAodTupleWriterTool()
Destructor:
Definition
McAodTupleWriterTool.cxx:68
McAodTupleWriterTool::m_particles
McAodParticles m_particles
our cached particles
Definition
McAodTupleWriterTool.h:116
McAodTupleWriterTool::m_tuple
TTree * m_tuple
cached pointer to the tuple
Definition
McAodTupleWriterTool.h:132
McAodTupleWriterTool::execute
StatusCode execute()
Definition
McAodTupleWriterTool.cxx:106
McAodTupleWriterTool::McAodTupleWriterTool
McAodTupleWriterTool()
Default constructor:
McAodTupleWriterTool::finalize
StatusCode finalize()
Definition
McAodTupleWriterTool.cxx:100
McAodTupleWriterTool::m_outputStreamName
StringProperty m_outputStreamName
Name of the output tuple stream.
Definition
McAodTupleWriterTool.h:129
McAodTupleWriterTool::s_nMax
static const int s_nMax
maximum number of particles per event
Definition
McAodTupleWriterTool.h:92
McAodTupleWriterTool::m_outputFileName
StringProperty m_outputFileName
Name of the output tuple file.
Definition
McAodTupleWriterTool.h:126
McAodTupleWriterTool::m_tupleSvc
ServiceHandle< ITHistSvc > m_tupleSvc
Pointer to @ ITHistSvc.
Definition
McAodTupleWriterTool.h:119
McAodTupleWriterTool::m_truthParticlesName
StringProperty m_truthParticlesName
Location of the TruthParticleContainer to be written out.
Definition
McAodTupleWriterTool.h:123
McAodTupleWriterTool::setupBackend
void setupBackend(Gaudi::Details::PropertyBase &outputFileName)
Method to configure the back-end to write out the HepMC::GenEvent.
Definition
McAodTupleWriterTool.cxx:179
McAodTupleWriterTool::bookTuple
void bookTuple()
book the tuple
Definition
McAodTupleWriterTool.cxx:212
McAodTupleWriterTool::initialize
StatusCode initialize()
Athena Algorithm's Hooks.
Definition
McAodTupleWriterTool.cxx:76
TruthParticleContainer
Definition
PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:42
TruthParticle
(HepMC) Monte Carlo particle.
Definition
PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticle.h:58
TruthParticleParameters
Definition
TruthParticleParamDefs.h:17
TruthParticleParameters::etcone40
@ etcone40
Definition
TruthParticleParamDefs.h:24
TruthParticleParameters::etcone
@ etcone
Definition
TruthParticleParamDefs.h:25
TruthParticleParameters::etcone70
@ etcone70
Definition
TruthParticleParamDefs.h:28
TruthParticleParameters::etcone10
@ etcone10
Definition
TruthParticleParamDefs.h:21
TruthParticleParameters::etcone60
@ etcone60
Definition
TruthParticleParamDefs.h:27
TruthParticleParameters::etcone20
@ etcone20
Definition
TruthParticleParamDefs.h:22
TruthParticleParameters::etcone30
@ etcone30
Definition
TruthParticleParamDefs.h:23
TruthParticleParameters::etcone50
@ etcone50
Definition
TruthParticleParamDefs.h:26
mc
Definition
mc.Ep4_simple_OO.py:1
type
Generated on
for ATLAS Offline Software by
1.17.0