ATLAS Offline Software
Loading...
Searching...
No Matches
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
20
21// McParticleKernel includes
23
24// McParticleEvent includes
26
27// McParticleAlgs includes
28#include "McAodValidationAlg.h"
29
30// STL includes
31#include <cstdlib> // for random numbers
32#include <stdexcept>
33
34
38
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",
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
71
75{
76 ATH_MSG_INFO ("Initializing " << name() << "...");
77
78 // initializing pseudo-random generator with the seed
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() ) {
88 ("Could not retrieve McAod validation tools !!" << endmsg
89 << " [" << m_valTools << "]");
90 return StatusCode::FAILURE;
91 }
92
93 return StatusCode::SUCCESS;
94}
95
97{
98 ATH_MSG_INFO ("Finalizing " << name() << "...");
99
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() ) {
111 ("Could not finalize validation tool ["
112 << iTool->typeAndName() << "] !!");
113 }
114 }
115
117 ("==> Finalizing validation AlgTools (" << m_valTools.size()
118 << ")... [DONE]");
119 return StatusCode::SUCCESS;
120}
121
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 ) {
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 ) {
145 ("Could not retrieve the (auto-symlinked) DV<INav4Mom> at ["
146 << m_truthParticlesName << "] !!");
147 } else {
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 ) {
160 ("Could not retrieve the (auto-symlinked) DV<IP> at ["
161 << m_truthParticlesName << "] !!");
162 } else {
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 ) {
174 ("Could not retrieve the (auto-symlinked) IPC at ["
175 << m_truthParticlesName << "] !!");
176 } else {
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() ) {
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
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
DataVector< IParticle > IParticleContainer
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
virtual ~McAodValidationAlg()
Destructor:
unsigned int m_seed
Random generator seed.
IValidationTools_t m_valTools
Validation tools to be ran on the events.
McAodValidationAlg()
Default constructor:
virtual StatusCode finalize() override
virtual StatusCode initialize() override
Athena Algorithm's Hooks.
virtual StatusCode execute() override
StringProperty m_truthParticlesName
Location of the TruthParticleContainer to read.