ATLAS Offline Software
Loading...
Searching...
No Matches
SpclMcValidationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// SpclMcValidationTool.cxx
7// Implementation file for class SpclMcValidationTool
8// Author: S.Binet<binet@cern.ch>
10
11
12// FrameWork includes
13
15
16// McParticleEvent includes
18
19// McParticleKernel includes
21
22// McParticleTools includes
24
28
32 const std::string& name,
33 const IInterface* parent ) :
35{
36 //
37 // Property declaration
38 //
39 declareProperty( "McEvents",
40 m_mcEventsName = "GEN_AOD",
41 "Name of the reference McEventCollection" );
42
43 declareProperty( "TruthParticles",
44 m_truthParticlesName = "SpclMC",
45 "Name of the 'to-be-validated' TruthParticleContainer" );
46
47 declareProperty( "McAodWriterTool",
48 m_mcAodWriterTool = McAodTool_t( "McAodWriterTool", this ),
49 "Tool to write the TruthParticleContainer into a "
50 "dedicated file" );
51}
52
59
63
65{
66 ATH_MSG_INFO("Initializing " << name() << "...");
67 // retrieve and configure McAod writer tool
68 if ( setupMcAodWriterTool().isFailure() ) {
69 ATH_MSG_ERROR("Could not configure the McAod writer tools !!");
70 return StatusCode::FAILURE;
71 }
72
73 return StatusCode::SUCCESS;
74}
75
77{
78 ATH_MSG_INFO("Finalizing " << name() << "...");
79 return StatusCode::SUCCESS;
80}
81
83{
84 // retrieve McEventCollection
85 const McEventCollection * mcEvents = nullptr;
86 if ( evtStore()->retrieve( mcEvents, m_mcEventsName ).isFailure() ||
87 nullptr == mcEvents ) {
88 ATH_MSG_ERROR("Could not retrieve McEventCollection at ["
89 << m_mcEventsName << "] !!");
90 return StatusCode::FAILURE;
91 } else {
92 ATH_MSG_VERBOSE("Successfully retrieved McEventCollection at ["
93 << m_mcEventsName << "]");
94 }
95
96 // retrieve TruthParticleContainer
97 const TruthParticleContainer * mcParts = nullptr;
98 if ( evtStore()->retrieve( mcParts, m_truthParticlesName ).isFailure() ||
99 nullptr == mcParts ) {
100 ATH_MSG_ERROR("Could not retrieve TruthParticleContainer at ["
101 << m_truthParticlesName << "] !!");
102 return StatusCode::FAILURE;
103 } else {
104 ATH_MSG_VERBOSE("Successfully TruthParticleContainer at ["
105 << m_truthParticlesName << "]");
106 }
107
108 return executeTool( mcEvents, mcParts );
109}
110
111StatusCode
113 const TruthParticleContainer* mcParts )
114{
115 if ( nullptr == mcEvents ) {
116 ATH_MSG_ERROR("NULL pointer to reference McEventCollection !!");
117 return StatusCode::FAILURE;
118 }
119
120 if ( nullptr == mcParts ) {
121 ATH_MSG_ERROR("NULL pointer to the 'to-be-validated' "\
122 "TruthParticleContainer !!");
123 return StatusCode::FAILURE;
124 }
125
126 if ( mcEvents->empty() ) {
127 ATH_MSG_WARNING("Empty McEventCollection !");
128 return mcParts->empty() ? StatusCode::SUCCESS : StatusCode::FAILURE;
129 }
130
131 const HepMC::GenEvent * genEvt = (*mcEvents)[0];
132 if ( nullptr == genEvt ) {
133 ATH_MSG_ERROR("NULL pointer to reference GenEvent !!");
134 return StatusCode::FAILURE;
135 }
136
137 int particles_size=genEvt->particles_size();
138 if ( static_cast<int>( mcParts->size() ) != particles_size ) {
139 ATH_MSG_ERROR("TruthParticleContainer and McEventCollection don't have "\
140 "the same number of particles !!" << endmsg
141 << "\tTruthParticleContainer: " << mcParts->size() << endmsg
142 << "\tHepMC::GenEvent: " << particles_size);
143 return StatusCode::FAILURE;
144 }
145
146 if ( !m_mcAodWriterTool->execute().isSuccess() ) {
147 ATH_MSG_WARNING("Could NOT write out the TruthParticleContainer through the IIOMcAodTool !!");
148 }
149
150 const TruthParticleContainer::const_iterator itrEnd = mcParts->end();
151 for ( TruthParticleContainer::const_iterator itrPart = mcParts->begin();
152 itrPart != itrEnd;
153 ++itrPart ) {
154 const TruthParticle * mc = *itrPart;
155 auto hepMc = mc->genParticle();
156
157 if ( hepMc->momentum() != HepMC::FourVector(mc->hlv().x(),mc->hlv().y(),mc->hlv().z(),mc->hlv().t()) ) {
158 ATH_MSG_ERROR("TruthParticle and GenParticle-link don't have same 4-mom !!");
159 return StatusCode::FAILURE;
160 }
161
162 auto genPart = HepMC::barcode_to_particle(genEvt,HepMC::barcode(hepMc));
163
164 if ( hepMc->momentum() != genPart->momentum() ) {
165 ATH_MSG_ERROR("GenParticle-link and GenParticle from McEvtColl "\
166 "don't have same 4-mom !!");
167 return StatusCode::FAILURE;
168 }
169
170
171 }
172 return StatusCode::SUCCESS;
173}
174
176{
177 if ( !m_mcAodWriterTool.retrieve().isSuccess() ) {
178 ATH_MSG_ERROR("Creation of algTool ["
179 << m_mcAodWriterTool.type() << "/"
180 //<< m_mcAodWriterTool.name()
181 << "] FAILED !");
182 return StatusCode::FAILURE;
183 }
184
185 // now we configure the tools
186 StringProperty prop( "TruthParticles", m_truthParticlesName.value() );
187 if ( m_mcAodWriterTool->setProperty( prop ).isFailure() ) {
188 ATH_MSG_ERROR("Could not set property [" << prop.name() << "] for tool ["
189 << m_mcAodWriterTool.type() << "/"
190 //<< m_mcAodWriterTool.name()
191 << "] !!");
192 return StatusCode::FAILURE;
193 }
194 return StatusCode::SUCCESS;
195}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
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.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual StatusCode executeTool()
Main method to perform the validation.
StringProperty m_mcEventsName
Location of the reference McEventCollection.
virtual ~SpclMcValidationTool()
Destructor:
McAodTool_t m_mcAodWriterTool
Tool to write the TruthParticleContainer into a dedicated file.
SpclMcValidationTool()
Default constructor:
StatusCode setupMcAodWriterTool()
Request pointers to the IIOMcAodTool to be able to write out TruthParticleContainer for further compa...
ToolHandle< IIOMcAodTool > McAodTool_t
StringProperty m_truthParticlesName
Location of the 'to-be-validated' TruthParticleContainer.
virtual StatusCode finalizeTool()
virtual StatusCode initializeTool()
Non-const methods:
TruthParticleValidationBaseTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
GenParticle * barcode_to_particle(const GenEvent *e, int id)
Definition GenEvent.h:630
int barcode(const T *p)
Definition Barcode.h:16