ATLAS Offline Software
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",
51  m_valTools,
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 
69 {}
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 
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 
115  ATH_MSG_INFO
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 
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
McAodValidationAlg::finalize
virtual StatusCode finalize()
Definition: McAodValidationAlg.cxx:95
McAodValidationAlg::m_valTools
IValidationTools_t m_valTools
Validation tools to be ran on the events.
Definition: McAodValidationAlg.h:64
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TruthParticleContainer.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
McAodValidationAlg.h
TruthParticle
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticle.h:58
TruthParticleContainer
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:42
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
mc
Definition: mc.PG_single_nu_valid.py:1
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArG4FSStartPointFilter.rand
rand
Definition: LArG4FSStartPointFilter.py:80
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
McAodValidationAlg::~McAodValidationAlg
virtual ~McAodValidationAlg()
Destructor:
Definition: McAodValidationAlg.cxx:68
McAodValidationAlg::McAodValidationAlg
McAodValidationAlg()
Default constructor:
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
McAodValidationAlg::m_seed
unsigned int m_seed
Random generator seed.
Definition: McAodValidationAlg.h:74
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
McAodValidationAlg::initialize
virtual StatusCode initialize()
Athena Algorithm's Hooks.
Definition: McAodValidationAlg.cxx:73
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IParticleContainer.h
ITruthParticleValidationTool.h
McAodValidationAlg::execute
virtual StatusCode execute()
Definition: McAodValidationAlg.cxx:121
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
McAodValidationAlg::m_truthParticlesName
StringProperty m_truthParticlesName
Location of the TruthParticleContainer to read.
Definition: McAodValidationAlg.h:69