ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
TruthParticleID
McParticleAlgs
src
McAodValidationAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// McAodValidationAlg.cxx
7
// Implementation file for class McAodValidationAlg
8
// Author: S.Binet<binet@cern.ch>
10
11
12
// FrameWork includes
13
#include "Gaudi/Property.h"
14
15
// CLHEP includes
16
#include "CLHEP/Units/SystemOfUnits.h"
17
18
// NavFourMom includes
19
#include "
NavFourMom/IParticleContainer.h
"
20
21
// McParticleKernel includes
22
#include "
McParticleKernel/ITruthParticleValidationTool.h
"
23
24
// McParticleEvent includes
25
#include "
McParticleEvent/TruthParticleContainer.h
"
26
27
// McParticleAlgs includes
28
#include "
McAodValidationAlg.h
"
29
30
// STL includes
31
#include <cstdlib>
// for random numbers
32
#include <stdexcept>
33
34
38
41
McAodValidationAlg::McAodValidationAlg
(
const
std::string& name,
42
ISvcLocator* pSvcLocator ) :
43
AthAlgorithm
( name, pSvcLocator ),
44
m_valTools
( this )
45
{
46
//
47
// Property declaration
48
//
49
//declareProperty( "Property", m_nProperty );
50
51
declareProperty
(
"ValidationTools"
,
52
m_valTools
,
53
"List of validation tools to be ran on the events"
);
54
// defaults
55
m_valTools
.push_back(
"GenAodValidationTool/GenAodValidation"
);
56
m_valTools
.push_back(
"SpclMcValidationTool/SpclMcValidation"
);
57
58
declareProperty
(
"TruthParticles"
,
59
m_truthParticlesName
=
"SpclMC"
,
60
"Name of the TruthParticleContainer to be read"
);
61
62
declareProperty
(
"Seed"
,
63
m_seed
= 12345678,
64
"Seed for the STL random generator"
);
65
}
66
69
McAodValidationAlg::~McAodValidationAlg
()
70
{}
71
74
StatusCode
McAodValidationAlg::initialize
()
75
{
76
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
);
77
78
// initializing pseudo-random generator with the seed
79
ATH_MSG_INFO
80
(
"Initializing pseudo-random generator..."
81
<<
endmsg
82
<<
"\tseed= "
<<
m_seed
);
83
std::srand(
m_seed
);
84
85
// retrieve the list of validation tools
86
if
( !
m_valTools
.retrieve().isSuccess() ) {
87
ATH_MSG_ERROR
88
(
"Could not retrieve McAod validation tools !!"
<<
endmsg
89
<<
" ["
<<
m_valTools
<<
"]"
);
90
return
StatusCode::FAILURE;
91
}
92
93
return
StatusCode::SUCCESS;
94
}
95
96
StatusCode
McAodValidationAlg::finalize
()
97
{
98
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
99
100
ATH_MSG_INFO
101
(
"==> Finalizing validation AlgTools ("
<<
m_valTools
.size() <<
")..."
);
102
103
for
( IValidationTools_t::iterator
104
iTool =
m_valTools
.begin(),
105
iEnd =
m_valTools
.end();
106
iTool != iEnd;
107
++iTool ) {
108
ATH_MSG_INFO
(
"-> finalizing ["
<< iTool->typeAndName() <<
"]:"
);
109
if
( (*iTool)->finalize().isFailure() ) {
110
ATH_MSG_WARNING
111
(
"Could not finalize validation tool ["
112
<< iTool->typeAndName() <<
"] !!"
);
113
}
114
}
115
116
ATH_MSG_INFO
117
(
"==> Finalizing validation AlgTools ("
<<
m_valTools
.size()
118
<<
")... [DONE]"
);
119
return
StatusCode::SUCCESS;
120
}
121
122
StatusCode
McAodValidationAlg::execute
(
const
EventContext&
/*ctx*/
)
123
{
124
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
125
//we don't care this is not crypto-strength random number generator
126
//coverity[dont_call]
127
const
double
random = std::rand() * 1.;
128
ATH_MSG_DEBUG
(
"Random= "
<< random);
129
130
const
TruthParticleContainer
* mcParts = 0;
131
if
(
evtStore
()->retrieve( mcParts,
m_truthParticlesName
).isFailure() ||
132
0 == mcParts ) {
133
ATH_MSG_ERROR
134
(
"Could not retrieve the TruthParticleContainer at ["
135
<<
m_truthParticlesName
<<
"] !!"
);
136
return
StatusCode::FAILURE;
137
}
138
139
// test the symLink feature
140
{
141
const
DataVector<INavigable4Momentum>
* inav4mom = 0;
142
if
(
evtStore
()->retrieve( inav4mom,
m_truthParticlesName
).isFailure() ||
143
0 == inav4mom ) {
144
ATH_MSG_ERROR
145
(
"Could not retrieve the (auto-symlinked) DV<INav4Mom> at ["
146
<<
m_truthParticlesName
<<
"] !!"
);
147
}
else
{
148
ATH_MSG_DEBUG
149
(
"Successfully exercised the auto-symlink feature "
\
150
"with [DV<INavigable4MomentumCollection>]"
);
151
}
152
}
153
154
// test the symLink feature
155
{
156
const
DataVector<IParticle>
* ipc = 0;
157
if
(
evtStore
()->retrieve( ipc,
m_truthParticlesName
).isFailure() ||
158
0 == ipc ) {
159
ATH_MSG_ERROR
160
(
"Could not retrieve the (auto-symlinked) DV<IP> at ["
161
<<
m_truthParticlesName
<<
"] !!"
);
162
}
else
{
163
ATH_MSG_DEBUG
164
(
"Successfully exercised the auto-symlink feature with [DV<IParticle>]"
);
165
}
166
}
167
168
// test the symLink feature
169
{
170
const
IParticleContainer
* ipc = 0;
171
if
(
evtStore
()->retrieve( ipc,
m_truthParticlesName
).isFailure() ||
172
0 == ipc ) {
173
ATH_MSG_ERROR
174
(
"Could not retrieve the (auto-symlinked) IPC at ["
175
<<
m_truthParticlesName
<<
"] !!"
);
176
}
else
{
177
ATH_MSG_DEBUG
178
(
"Successfully exercised the auto-symlink feature "
\
179
"with [IParticleContainer]"
);
180
}
181
}
182
183
double
eneSum = 0.;
184
for
(
TruthParticleContainer::const_iterator
itr = mcParts->
begin
();
185
itr != mcParts->
end
();
186
++itr ) {
187
const
TruthParticle
*
mc
= *itr;
188
eneSum +=
mc
->e();
189
}
190
ATH_MSG_DEBUG
(
"Sum Ene= "
<< (eneSum * (1./CLHEP::GeV)));
191
192
bool
validationIsOK =
true
;
193
ATH_MSG_DEBUG
(
"Checking the event with the validation AlgTools..."
);
194
195
for
( IValidationTools_t::iterator
196
iTool =
m_valTools
.begin(),
197
iEnd =
m_valTools
.end();
198
iTool != iEnd;
199
++iTool ) {
200
ATH_MSG_DEBUG
(
"\tvalidation with ["
<< iTool->typeAndName() <<
"]..."
);
201
if
( !(*iTool)->execute().isSuccess() ) {
202
ATH_MSG_WARNING
203
(
"Event FAILED validation criteria of ["
204
<< iTool->typeAndName() <<
"] !!"
);
205
validationIsOK =
false
;
206
}
207
}
208
209
if
( !validationIsOK ) {
210
ATH_MSG_ERROR
(
"Event did not pass the validation !!"
);
211
return
StatusCode::FAILURE;
212
}
213
214
return
StatusCode::SUCCESS;
215
}
216
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
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
ITruthParticleValidationTool.h
McAodValidationAlg.h
IParticleContainer.h
IParticleContainer
DataVector< IParticle > IParticleContainer
Definition
NavFourMom/NavFourMom/IParticleContainer.h:29
TruthParticleContainer.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
DataVector
Derived DataVector<T>.
Definition
DataVector.h:795
DataVector< TruthParticle >::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Definition
DataVector.h:838
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
McAodValidationAlg::~McAodValidationAlg
virtual ~McAodValidationAlg()
Destructor:
Definition
McAodValidationAlg.cxx:69
McAodValidationAlg::m_seed
unsigned int m_seed
Random generator seed.
Definition
McAodValidationAlg.h:70
McAodValidationAlg::m_valTools
IValidationTools_t m_valTools
Validation tools to be ran on the events.
Definition
McAodValidationAlg.h:60
McAodValidationAlg::McAodValidationAlg
McAodValidationAlg()
Default constructor:
McAodValidationAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
McAodValidationAlg.cxx:122
McAodValidationAlg::finalize
virtual StatusCode finalize() override
Definition
McAodValidationAlg.cxx:96
McAodValidationAlg::initialize
virtual StatusCode initialize() override
Athena Algorithm's Hooks.
Definition
McAodValidationAlg.cxx:74
McAodValidationAlg::m_truthParticlesName
StringProperty m_truthParticlesName
Location of the TruthParticleContainer to read.
Definition
McAodValidationAlg.h:65
TruthParticleContainer
Definition
PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:42
TruthParticle
(HepMC) Monte Carlo particle.
Definition
PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticle.h:58
mc
Definition
mc.Ep4_simple_OO.py:1
Generated on
for ATLAS Offline Software by
1.17.0