ATLAS Offline Software
Loading...
Searching...
No Matches
McAodValidationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 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// STL includes
13#include <cstdlib> // for random numbers
14#include <stdexcept>
15
16// FrameWork includes
17#include "Gaudi/Property.h"
18
19// CLHEP includes
20#include "CLHEP/Units/SystemOfUnits.h"
21
22// NavFourMom includes
24
25// McParticleKernel includes
27
28// McParticleEvent includes
30
31// McParticleAlgs includes
32#include "McAodValidationAlg.h"
33
37
41 ISvcLocator* pSvcLocator ) :
42 AthAlgorithm( name, pSvcLocator ),
43 m_valTools ( this )
44{
45 //
46 // Property declaration
47 //
48 //declareProperty( "Property", m_nProperty );
49
50 declareProperty( "ValidationTools",
52 "List of validation tools to be ran on the events" );
53 // defaults
54 m_valTools.push_back( "GenAodValidationTool/GenAodValidation" );
55 m_valTools.push_back( "SpclMcValidationTool/SpclMcValidation" );
56
57 declareProperty( "TruthParticles",
58 m_truthParticlesName = "SpclMC",
59 "Name of the TruthParticleContainer to be read" );
60
61 declareProperty( "Seed",
62 m_seed = 12345678,
63 "Seed for the STL random generator" );
64}
65
70
74{
75 ATH_MSG_INFO ("Initializing " << name() << "...");
76
77 // initializing pseudo-random generator with the seed
79 ("Initializing pseudo-random generator..."
80 << endmsg
81 << "\tseed= " << m_seed);
82 std::srand( m_seed );
83
84 // retrieve the list of validation tools
85 if ( !m_valTools.retrieve().isSuccess() ) {
87 ("Could not retrieve McAod validation tools !!" << endmsg
88 << " [" << m_valTools << "]");
89 return StatusCode::FAILURE;
90 }
91
92 return StatusCode::SUCCESS;
93}
94
96{
97 ATH_MSG_INFO ("Finalizing " << name() << "...");
98
100 ("==> Finalizing validation AlgTools (" << m_valTools.size() << ")...");
101
102 for ( IValidationTools_t::iterator
103 iTool = m_valTools.begin(),
104 iEnd = m_valTools.end();
105 iTool != iEnd;
106 ++iTool ) {
107 ATH_MSG_INFO ("-> finalizing [" << iTool->typeAndName() << "]:");
108 if ( (*iTool)->finalize().isFailure() ) {
110 ("Could not finalize validation tool ["
111 << iTool->typeAndName() << "] !!");
112 }
113 }
114
116 ("==> Finalizing validation AlgTools (" << m_valTools.size()
117 << ")... [DONE]");
118 return StatusCode::SUCCESS;
119}
120
122{
123 ATH_MSG_DEBUG ("Executing " << name() << "...");
124
125 const double random = std::rand() * 1.;
126 ATH_MSG_DEBUG ("Random= " << random);
127
128 const TruthParticleContainer * mcParts = 0;
129 if ( evtStore()->retrieve( mcParts, m_truthParticlesName ).isFailure() ||
130 0 == mcParts ) {
132 ("Could not retrieve the TruthParticleContainer at ["
133 << m_truthParticlesName << "] !!");
134 return StatusCode::FAILURE;
135 }
136
137 // test the symLink feature
138 {
139 const DataVector<INavigable4Momentum> * inav4mom = 0;
140 if ( evtStore()->retrieve( inav4mom, m_truthParticlesName ).isFailure() ||
141 0 == inav4mom ) {
143 ("Could not retrieve the (auto-symlinked) DV<INav4Mom> at ["
144 << m_truthParticlesName << "] !!");
145 } else {
147 ("Successfully exercised the auto-symlink feature "\
148 "with [DV<INavigable4MomentumCollection>]");
149 }
150 }
151
152 // test the symLink feature
153 {
154 const DataVector<IParticle> * ipc = 0;
155 if ( evtStore()->retrieve( ipc, m_truthParticlesName ).isFailure() ||
156 0 == ipc ) {
158 ("Could not retrieve the (auto-symlinked) DV<IP> at ["
159 << m_truthParticlesName << "] !!");
160 } else {
162 ("Successfully exercised the auto-symlink feature with [DV<IParticle>]");
163 }
164 }
165
166 // test the symLink feature
167 {
168 const IParticleContainer * ipc = 0;
169 if ( evtStore()->retrieve( ipc, m_truthParticlesName ).isFailure() ||
170 0 == ipc ) {
172 ("Could not retrieve the (auto-symlinked) IPC at ["
173 << m_truthParticlesName << "] !!");
174 } else {
176 ("Successfully exercised the auto-symlink feature "\
177 "with [IParticleContainer]");
178 }
179 }
180
181 double eneSum = 0.;
182 for ( TruthParticleContainer::const_iterator itr = mcParts->begin();
183 itr != mcParts->end();
184 ++itr ) {
185 const TruthParticle * mc = *itr;
186 eneSum += mc->e();
187 }
188 ATH_MSG_DEBUG ("Sum Ene= " << (eneSum * (1./CLHEP::GeV)));
189
190 bool validationIsOK = true;
191 ATH_MSG_DEBUG ("Checking the event with the validation AlgTools...");
192
193 for ( IValidationTools_t::iterator
194 iTool = m_valTools.begin(),
195 iEnd = m_valTools.end();
196 iTool != iEnd;
197 ++iTool ) {
198 ATH_MSG_DEBUG ("\tvalidation with [" << iTool->typeAndName() << "]...");
199 if ( !(*iTool)->execute().isSuccess() ) {
201 ("Event FAILED validation criteria of ["
202 << iTool->typeAndName() << "] !!");
203 validationIsOK = false;
204 }
205 }
206
207 if ( !validationIsOK ) {
208 ATH_MSG_ERROR ("Event did not pass the validation !!");
209 return StatusCode::FAILURE;
210 }
211
212 return StatusCode::SUCCESS;
213}
214
#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 StatusCode initialize()
Athena Algorithm's Hooks.
virtual ~McAodValidationAlg()
Destructor:
unsigned int m_seed
Random generator seed.
virtual StatusCode finalize()
IValidationTools_t m_valTools
Validation tools to be ran on the events.
McAodValidationAlg()
Default constructor:
virtual StatusCode execute()
StringProperty m_truthParticlesName
Location of the TruthParticleContainer to read.