ATLAS Offline Software
Loading...
Searching...
No Matches
GenAodValidationTool Class Reference

#include <GenAodValidationTool.h>

Inheritance diagram for GenAodValidationTool:
Collaboration diagram for GenAodValidationTool:

Public Member Functions

 GenAodValidationTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor with parameters:
virtual ~GenAodValidationTool ()
 Destructor:
StatusCode initialize ()
 Athena Algorithm's Hooks.
StatusCode execute ()
StatusCode finalize ()
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Inline methods:

Protected Types

typedef ToolHandle< IIOHepMcToolHepMcTool_t
 shorthand for lazy people (good coders are lazy people, aren't they ?)

Protected Member Functions

 GenAodValidationTool ()
 Default constructor:
virtual StatusCode initializeTool ()
 Non-const methods:
virtual StatusCode finalizeTool ()
virtual StatusCode executeTool ()
 Main method to perform the validation.
virtual StatusCode executeTool (const McEventCollection *refMcEvents, const McEventCollection *checkMcEvents)
 Main method to perform the validation:
virtual StatusCode executeTool (const HepMC::GenEvent *refMcEvents, const HepMC::GenEvent *checkMcEvents)
 Main method to perform the validation (directly onto the GenEvents):
bool compareVtx (const HepMC::ConstGenVertexPtr &vtx1, const HepMC::ConstGenVertexPtr &vtx2) const
 Check that 2 given vertices are the same:
bool compareParts (const HepMC::ConstGenParticlePtr &p1, const HepMC::ConstGenParticlePtr &p2) const
 Check that 2 given particles are the same:
StatusCode setupHepMcWriterTools ()
 Request pointers to the HepMcWriterTools to be able to write out HepMC::GenEvent for further comparison (off-framework)
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Protected Attributes

StringProperty m_refMcEventsName
 Location of the reference McEventCollection.
StringProperty m_checkMcEventsName
 Location of the 'to-be-validated' McEventCollection.
StringProperty m_hardVtxOutFileName
 Name of the output text file which will contain the hard-scattering vertices.
std::ofstream * m_outFile
 Pointer to the output text file containing hard-scattering vertices.
HepMcTool_t m_refMcEventWriter
 Tool to write the reference HepMC::GenEvent into a dedicated file.
HepMcTool_t m_checkMcEventWriter
 Tool to write the 'to-be-checked' HepMC::GenEvent into a dedicated file.
unsigned int m_nAnalysedEvents
 Counter of analysed events.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 31 of file GenAodValidationTool.h.

Member Typedef Documentation

◆ HepMcTool_t

typedef ToolHandle<IIOHepMcTool> GenAodValidationTool::HepMcTool_t
protected

shorthand for lazy people (good coders are lazy people, aren't they ?)

Definition at line 135 of file GenAodValidationTool.h.

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ GenAodValidationTool() [1/2]

GenAodValidationTool::GenAodValidationTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor with parameters:

Public methods:

Constructors

Definition at line 41 of file GenAodValidationTool.cxx.

43 :
44 TruthParticleValidationBaseTool( type, name, parent ),
45 m_outFile( nullptr )
46{
47 //
48 // Property declaration
49 //
50
51 declareProperty( "RefMcEvents",
52 m_refMcEventsName = "TruthEvent",
53 "StoreGate location of the reference McEventCollection" );
54
55 declareProperty( "CheckMcEvents",
56 m_checkMcEventsName = "GEN_AOD",
57 "Location of the 'to-be-validated' McEventCollection" );
58
59 declareProperty( "HardScatteringVtxOutputFile",
60 m_hardVtxOutFileName = "hepmc.hard.vtx.txt",
61 "Name of the output text file which will contain the "
62 "hard-scattering vertices" );
63
64 declareProperty( "RefHepMcWriterTool",
65 m_refMcEventWriter = HepMcTool_t( "HepMcWriterTool",
66 this ),
67 "Tool to write the reference HepMC::GenEvent into a dedicated file" );
68
69 declareProperty( "CheckHepMcWriterTool",
70 m_checkMcEventWriter = HepMcTool_t( "HepMcWriterTool",
71 this ),
72 "Tool to write the \"to-be-checked\" HepMC::GenEvent "
73 "into a dedicated file" );
74
75}
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ToolHandle< IIOHepMcTool > HepMcTool_t
shorthand for lazy people (good coders are lazy people, aren't they ?)
StringProperty m_hardVtxOutFileName
Name of the output text file which will contain the hard-scattering vertices.
HepMcTool_t m_checkMcEventWriter
Tool to write the 'to-be-checked' HepMC::GenEvent into a dedicated file.
StringProperty m_checkMcEventsName
Location of the 'to-be-validated' McEventCollection.
std::ofstream * m_outFile
Pointer to the output text file containing hard-scattering vertices.
StringProperty m_refMcEventsName
Location of the reference McEventCollection.
HepMcTool_t m_refMcEventWriter
Tool to write the reference HepMC::GenEvent into a dedicated file.
TruthParticleValidationBaseTool()
Default constructor:

◆ ~GenAodValidationTool()

GenAodValidationTool::~GenAodValidationTool ( )
virtual

Destructor:

Destructor.

Definition at line 79 of file GenAodValidationTool.cxx.

80{
81 ATH_MSG_DEBUG("Calling destructor");
82
83 if ( m_outFile ) {
84 m_outFile->close();
85 delete m_outFile;
86 m_outFile = nullptr;
87 }
88
89}
#define ATH_MSG_DEBUG(x)

◆ GenAodValidationTool() [2/2]

GenAodValidationTool::GenAodValidationTool ( )
protected

Default constructor:

Member Function Documentation

◆ compareParts()

bool GenAodValidationTool::compareParts ( const HepMC::ConstGenParticlePtr & p1,
const HepMC::ConstGenParticlePtr & p2 ) const
protected

Check that 2 given particles are the same:

  • 4-mom
  • id
  • status
  • flow
  • polarization

Definition at line 406 of file GenAodValidationTool.cxx.

407{
408 if ( !p1 || !p2 ) {
409 ATH_MSG_ERROR("One of particles is a NULL pointer !!" << endmsg
410 << " p1: " << p1 << endmsg
411 << " p2: " << p2);
412 return false;
413 }
414
415 if ( HepMC::barcode(p1) != HepMC::barcode(p2) ) {
416 return false;
417 }
418
419 const HepMC::FourVector hlv1 = p1->momentum();
420 const int id1 = p1->pdg_id();
421 const int status1 = p1->status();
422 auto flow1 = HepMC::flow(p1);
423 auto pol1 = HepMC::polarization(p1);
424
425 const HepMC::FourVector hlv2 = p2->momentum();
426 const int id2 = p2->pdg_id();
427 const int status2 = p2->status();
428 auto flow2 = HepMC::flow(p2);
429 auto pol2 = HepMC::polarization(p2);
430
431 const bool isOK = ( hlv1 == hlv2 &&
432 id1 == id2 &&
433 status1 == status2 &&
434 flow1 == flow2 &&
435 pol1 == pol2 );
436
437
438 if ( !isOK ) {
440 ("=============================" << endmsg
441 << "\thlv: " << std::boolalpha << (hlv1 == hlv2 ) << endmsg
442 << "\tid: " << std::boolalpha << (id1 == id2 ) << endmsg
443 << "\tstatus: " << std::boolalpha << (status1 == status2) << endmsg
444 << "\tflow: " << std::boolalpha << (flow1 == flow2 ) << endmsg
445 << "\tpolar: " << std::boolalpha << (pol1 == pol2 ) << endmsg
446 << "=============================");
447 }
448
449 return isOK;
450}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
HWIdentifier id2
int barcode(const T *p)
Definition Barcode.h:16
Polarization polarization(const T &a)
int flow(const T &a, int i)
Definition Flow.h:51

◆ compareVtx()

bool GenAodValidationTool::compareVtx ( const HepMC::ConstGenVertexPtr & vtx1,
const HepMC::ConstGenVertexPtr & vtx2 ) const
protected

Check that 2 given vertices are the same:

  • check same number of branches
  • check same particles (4-mom + id + status)

Definition at line 310 of file GenAodValidationTool.cxx.

311{
312 if ( !vtx1 || !vtx2 ) {
313 ATH_MSG_ERROR("One of vertices is a NULL pointer !!" << endmsg
314 << " vtx1: " << vtx1 << endmsg
315 << " vtx2: " << vtx2);
316 return false;
317 }
318
319#ifdef HEPMC3
320 auto inVtx1 = vtx1->particles_in();
321 auto inVtx2 = vtx2->particles_in();
322 if (inVtx1.size() != inVtx2.size()) {
323 ATH_MSG_ERROR("Not the same number of branches !!" << endmsg << " in: " << inVtx1.size() << "\t" << inVtx2.size());
324 return false;
325 }
326 std::sort(inVtx1.begin(), inVtx1.end(), [](auto& a, auto& b) -> bool{return a->momentum().pz() > b->momentum().pz(); });
327 std::sort(inVtx2.begin(), inVtx2.end(), [](auto& a, auto& b) -> bool{return a->momentum().pz() > b->momentum().pz(); });
328 for (size_t i=0; i<inVtx1.size(); ++i){
329 if ( compareParts( inVtx1.at(i), inVtx2.at(i) ) ) continue;
330 ATH_MSG_ERROR("In-going particles are NOT matching !!");
331 return false;
332 }
333 auto outVtx1 = vtx1->particles_out();
334 auto outVtx2 = vtx2->particles_out();
335 if (outVtx1.size() != outVtx2.size()) {
336 ATH_MSG_ERROR("Not the same number of branches !!" << endmsg << " out: " << outVtx1.size() << "\t" << outVtx2.size());
337 return false;
338 }
339 std::sort(outVtx1.begin(), outVtx1.end(), [](auto& a, auto& b) -> bool{return a->momentum().pz() > b->momentum().pz(); });
340 std::sort(outVtx2.begin(), outVtx2.end(), [](auto& a, auto& b) -> bool{return a->momentum().pz() > b->momentum().pz(); });
341 for (size_t i=0; i<outVtx1.size(); ++i){
342 if ( compareParts( outVtx1.at(i), outVtx2.at(i) ) ) continue;
343 ATH_MSG_ERROR("Out-going particles are NOT matchiutg !!");
344 return false;
345 }
346#else
347 const int inVtx1 = vtx1->particles_in_size();
348 const int inVtx2 = vtx2->particles_in_size();
349
350 const int outVtx1 = vtx1->particles_out_size();
351 const int outVtx2 = vtx2->particles_out_size();
352
353 if ( inVtx1 != inVtx2 || outVtx1 != outVtx2 ) {
354 ATH_MSG_ERROR("Not the same number of branches !!" << endmsg
355 << " in: " << inVtx1 << "\t" << inVtx2 << endmsg
356 << " out: " << outVtx1 << "\t" << outVtx2);
357 return false;
358 }
359
360 for ( HepMC::GenVertex::particles_in_const_iterator inPart1 = vtx1->particles_in_const_begin();
361 inPart1 != vtx1->particles_in_const_end();
362 ++inPart1 ) {
363 bool inParticleOK = false;
364 for ( HepMC::GenVertex::particles_in_const_iterator inPart2 = vtx2->particles_in_const_begin();
365 inPart2 != vtx2->particles_in_const_end();
366 ++inPart2 ) {
367 if ( compareParts( *inPart1, *inPart2 ) ) {
368 inParticleOK = true;
369 break;
370 }
371 } //> end loop over in-part2
372
373 if ( !inParticleOK ) {
374 ATH_MSG_ERROR("In-going particles are NOT matching !!");
375 return false;
376 }
377
378 }//> end loop over in-part1
379
380
381 for ( HepMC::GenVertex::particles_out_const_iterator outPart1 = vtx1->particles_out_const_begin();
382 outPart1 != vtx1->particles_out_const_end();
383 ++outPart1 ) {
384 bool outParticleOK = false;
385 for ( HepMC::GenVertex::particles_out_const_iterator outPart2 = vtx2->particles_out_const_begin();
386 outPart2 != vtx2->particles_out_const_end();
387 ++outPart2 ) {
388 if ( compareParts( *outPart1, *outPart2 ) ) {
389 outParticleOK = true;
390 break;
391 }
392 } //> end loop over out-part2
393
394 if ( !outParticleOK ) {
395 ATH_MSG_ERROR("Out-going particles are NOT matching !!");
396 return false;
397 }
398
399 }//> end loop over out-part1
400#endif
401
402 return true;
403}
static Double_t a
bool compareParts(const HepMC::ConstGenParticlePtr &p1, const HepMC::ConstGenParticlePtr &p2) const
Check that 2 given particles are the same:
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

StatusCode TruthParticleValidationBaseTool::execute ( )
virtualinherited

Implements ITruthParticleValidationTool.

Definition at line 78 of file TruthParticleValidationBaseTool.cxx.

79{
81 return executeTool();
82}
unsigned int m_nAnalysedEvents
Counter of analysed events.
virtual StatusCode executeTool()=0
Main method to perform the validation.

◆ executeTool() [1/3]

StatusCode GenAodValidationTool::executeTool ( )
protectedvirtual

Main method to perform the validation.

Just a wrapper around the more API-detailed method.

Implements TruthParticleValidationBaseTool.

Definition at line 132 of file GenAodValidationTool.cxx.

133{
134 // retrieve reference McEventCollection
135 const McEventCollection * refMcEvents = nullptr;
136 if ( evtStore()->retrieve( refMcEvents, m_refMcEventsName ).isFailure() ||
137 nullptr == refMcEvents ) {
138 ATH_MSG_ERROR("Could not retrieve reference McEventCollection at ["
139 << m_refMcEventsName << "] !!");
140 return StatusCode::FAILURE;
141 } else {
142 ATH_MSG_VERBOSE("Successfully retrieved reference McEventCollection at ["
143 << m_refMcEventsName << "]");
144
145 if ( !m_refMcEventWriter ||
146 m_refMcEventWriter->execute().isFailure() ) {
147 ATH_MSG_WARNING("Failed to write the reference GenEvent !!");
148 }
149 }
150
151 // retrieve checking McEventCollection
152 const McEventCollection * checkMcEvents = nullptr;
153 if ( evtStore()->retrieve(checkMcEvents, m_checkMcEventsName).isFailure() ||
154 nullptr == checkMcEvents ) {
155 ATH_MSG_ERROR("Could not retrieve 'to-be-validated' McEventCollection at ["
156 << m_checkMcEventsName << "] !!");
157 return StatusCode::FAILURE;
158 } else {
160 ("Successfully retrieved 'to-be-validated' McEventCollection at ["
161 << m_checkMcEventsName << "]");
162
163 if ( !m_checkMcEventWriter ||
164 m_checkMcEventWriter->execute().isFailure() ) {
165 ATH_MSG_WARNING("Failed to write the reference GenEvent !!");
166 }
167 }
168
169 return executeTool( refMcEvents, checkMcEvents );
170}
#define ATH_MSG_VERBOSE(x)
ServiceHandle< StoreGateSvc > & evtStore()
virtual StatusCode executeTool()
Main method to perform the validation.
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ executeTool() [2/3]

StatusCode GenAodValidationTool::executeTool ( const HepMC::GenEvent * refMcEvents,
const HepMC::GenEvent * checkMcEvents )
protectedvirtual

Main method to perform the validation (directly onto the GenEvents):

  • check that each vertex is identical to the original one
  • check that missing particles are not there for a good reason

Definition at line 209 of file GenAodValidationTool.cxx.

211{
212 if ( nullptr == refMcEvts ) {
213 ATH_MSG_ERROR("NULL pointer to reference HepMC::GenEvent !!");
214 return StatusCode::FAILURE;
215 }
216
217 if ( nullptr == checkMcEvts ) {
218 ATH_MSG_ERROR("NULL pointer to the 'to-be-validated' HepMC::GenEvent !!");
219 return StatusCode::FAILURE;
220 }
221
222 const unsigned int evtNbr = refMcEvts->event_number();
223 (*m_outFile) << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
224 << std::endl
225 << "Event: " << evtNbr
226 << std::endl;
227
228#ifdef HEPMC3
229 std::map<int,int> ref_bc_to_id;
230 const auto& refvertices = refMcEvts->vertices();
231 for ( const auto& vtx: refvertices) {
232 // AV: this algorthm is not very correct
233 int partonsin = 0;
234 int showerout = 0;
235 for (auto& p: vtx->particles_in()) if (MC::isQuark(p) || MC::isGluon(p)) partonsin++;
236 for (auto& p: vtx->particles_out()) if (p->pdg_id() == 91||p->pdg_id() == 92||p->pdg_id() == 94) showerout++;
237 if ( partonsin >= 2 && showerout == 0 ) {
238 ref_bc_to_id[HepMC::barcode(vtx)] = vtx->id();
239 }
240 }
241 std::map<int,int> che_bc_to_id;
242 const auto& chevertices = checkMcEvts->vertices();
243 for (const auto& checkVtx: chevertices) {
244 che_bc_to_id[HepMC::barcode(checkVtx)] = checkVtx->id();
245 }
246 std::set<int> allbarcodes;
247 for (const auto &[bc,id]: ref_bc_to_id) allbarcodes.insert(bc);
248 for (const auto &[bc,id]: che_bc_to_id) allbarcodes.insert(bc);
249 for (const auto &bc: allbarcodes){
250 auto ref_it = ref_bc_to_id.find(bc);
251 auto che_it = che_bc_to_id.find(bc);
252 if (ref_it == ref_bc_to_id.end()) {ATH_MSG_WARNING("In Event [" << evtNbr << "]: got null ref-vertex (barcode: " << bc << ")"); continue; }
253 if (che_it == che_bc_to_id.end()) {ATH_MSG_WARNING("Output GenEvent is missing the selected HardScattering Vtx !!"<< " (" << bc << ")"); continue; }
254 if (-ref_it->second > int(refvertices.size()) ) { continue; }
255 if (-che_it->second > int(chevertices.size()) ) { continue; }
256 const auto& refvtx = refvertices[-ref_it->second-1];
257 const auto& chevtx = chevertices[-che_it->second-1];
258 (*m_outFile) << refvtx << std::endl;
259 (*m_outFile) << chevtx << std::endl;
260 (*m_outFile) << "---------" << std::endl;
261 if ( !compareVtx( refvtx, chevtx ) ) {
262 ATH_MSG_WARNING("Selected HardScattering vertices are NOT the same !!"<< " at Event [" << evtNbr << "]"<< " refVtx = " << refvtx<<" chevtx = " << chevtx);
263 }
264 }
265 (*m_outFile) << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
266#else
267 std::set<int> ref_bc;
268 for ( auto vtxIt = refMcEvts->vertices_begin(); vtxIt != refMcEvts->vertices_end(); ++vtxIt ) {
269 auto vtx =*vtxIt;
270 int partonsin = 0;
271 int showerout = 0;
272#ifdef HEPMC3
273 for (auto p = vtx->particles_in_begin();p!=vtx->particles_in_end();++p ) if (MC::isQuark(*p) || MC::isGluon(*p)) partonsin++;
274#else
275 for (auto p = vtx->particles_in_const_begin();p!=vtx->particles_in_const_end();++p ) if (MC::isQuark(*p) || MC::isGluon(*p)) partonsin++;
276#endif
277 for (auto& p : *vtx) if (p->pdg_id() == 91||p->pdg_id() == 92||p->pdg_id() == 94) showerout++;
278 if ( partonsin >= 2 && showerout == 0 ) {
279 ref_bc.insert(vtx->barcode());
280 }
281 }
282 std::set<int> che_bc;
283 for ( auto vtxIt = checkMcEvts->vertices_begin(); vtxIt != checkMcEvts->vertices_end(); ++vtxIt ) {
284 auto vtx =*vtxIt;
285 che_bc.insert(vtx->barcode());
286 }
287 std::set<int> allbarcodes;
288 for (const auto &bc: ref_bc) allbarcodes.insert(bc);
289 for (const auto &bc: che_bc) allbarcodes.insert(bc);
290 for (const auto &bc: allbarcodes){
291 auto ref_it = ref_bc.find(bc);
292 auto che_it = che_bc.find(bc);
293 if (ref_it == ref_bc.end()) {ATH_MSG_WARNING("In Event [" << evtNbr << "]: got null ref-vertex (barcode: " << bc << ")"); continue; }
294 if (che_it == che_bc.end()) {ATH_MSG_WARNING("Output GenEvent is missing the selected HardScattering Vtx !!"<< " (" << bc << ")"); continue; }
295 const auto refvtx = refMcEvts->barcode_to_vertex(bc);
296 const auto chevtx = checkMcEvts->barcode_to_vertex(bc);
297 (*m_outFile) << refvtx << std::endl;
298 (*m_outFile) << chevtx << std::endl;
299 (*m_outFile) << "---------" << std::endl;
300 if ( !compareVtx( refvtx, chevtx ) ) {
301 ATH_MSG_WARNING("Selected HardScattering vertices are NOT the same !!"<< " at Event [" << evtNbr << "]"<< " refVtx = " << refvtx<<" chevtx = " << chevtx);
302 }
303 }
304 (*m_outFile) << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
305#endif
306
307 return StatusCode::SUCCESS;
308}
bool compareVtx(const HepMC::ConstGenVertexPtr &vtx1, const HepMC::ConstGenVertexPtr &vtx2) const
Check that 2 given vertices are the same:
bool isQuark(const T &p)
PDG rule 2: Quarks and leptons are numbered consecutively starting from 1 and 11 respectively; to do ...
bool isGluon(const T &p)

◆ executeTool() [3/3]

StatusCode GenAodValidationTool::executeTool ( const McEventCollection * refMcEvents,
const McEventCollection * checkMcEvents )
protectedvirtual

Main method to perform the validation:

  • check that each vertex is identical to the original one
  • check that missing particles are not there for a good reason

Definition at line 173 of file GenAodValidationTool.cxx.

175{
176 if ( nullptr == refMcEvents ) {
177 ATH_MSG_ERROR("NULL pointer to reference McEventCollection !!");
178 return StatusCode::FAILURE;
179 }
180
181 if ( nullptr == checkMcEvents ) {
182 ATH_MSG_ERROR("NULL pointer to the 'to-be-validated' McEventCollection !!");
183 return StatusCode::FAILURE;
184 }
185
186 if ( refMcEvents->size() != checkMcEvents->size() ) {
187 ATH_MSG_ERROR("McEventCollections to be compared don't have the same size !"
188 << endmsg
189 << "Ref: " << refMcEvents->size() << endmsg
190 << "Current: " << checkMcEvents->size());
191 }
192
193 const unsigned int nMaxEvts = std::min( refMcEvents->size(),
194 checkMcEvents->size() );
195 for ( unsigned int iEvt = 0; iEvt != nMaxEvts; ++iEvt ) {
196
197 if ( executeTool( (*refMcEvents)[iEvt],
198 (*checkMcEvents)[iEvt] ).isFailure() ) {
199 ATH_MSG_WARNING("Could not VALIDATE this event ["
200 << (*refMcEvents)[iEvt]->event_number()
201 << "] !!");
202 }
203 }
204
205 return StatusCode::SUCCESS;
206}
size_type size() const noexcept
Returns the number of elements in the collection.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ finalize()

StatusCode TruthParticleValidationBaseTool::finalize ( )
virtualinherited

Implements ITruthParticleValidationTool.

Definition at line 64 of file TruthParticleValidationBaseTool.cxx.

65{
66 ATH_MSG_INFO("Finalizing " << name() << "...");
67 ATH_MSG_INFO("Analysed [" << m_nAnalysedEvents << "] events.");
68
69 // Give the concrete (derived) tool a chance to finalize itself
70 if ( finalizeTool().isFailure() ) {
71 ATH_MSG_ERROR("Could not finalize concrete tool !");
72 return StatusCode::FAILURE;
73 }
74
75 return StatusCode::SUCCESS;
76}
#define ATH_MSG_INFO(x)

◆ finalizeTool()

StatusCode GenAodValidationTool::finalizeTool ( )
protectedvirtual

Reimplemented from TruthParticleValidationBaseTool.

Definition at line 125 of file GenAodValidationTool.cxx.

126{
127 ATH_MSG_INFO("Finalizing " << name() << "...");
128
129 return StatusCode::SUCCESS;
130}

◆ initialize()

StatusCode TruthParticleValidationBaseTool::initialize ( )
virtualinherited

Athena Algorithm's Hooks.

Implements ITruthParticleValidationTool.

Definition at line 49 of file TruthParticleValidationBaseTool.cxx.

50{
51 ATH_MSG_INFO("Initializing " << name() << "...");
52
53 // Give the concrete (derived) tool a chance to initialize itself
54 if ( initializeTool().isFailure() ) {
55 ATH_MSG_ERROR("Could not initialize concrete tool !");
56 return StatusCode::FAILURE;
57 }
58
59 // initializing the event counter
61 return StatusCode::SUCCESS;
62}
virtual StatusCode initializeTool()
I/O operators.

◆ initializeTool()

StatusCode GenAodValidationTool::initializeTool ( )
protectedvirtual

Non-const methods:

Reimplemented from TruthParticleValidationBaseTool.

Definition at line 96 of file GenAodValidationTool.cxx.

97{
98 ATH_MSG_INFO("Initializing " << name() << "...");
99
100 if ( m_outFile ) {
101 delete m_outFile;
102 m_outFile = nullptr;
103 }
104 m_outFile = new std::ofstream( m_hardVtxOutFileName.value().c_str(),
105 std::ios::trunc );
106 if ( !m_outFile || !m_outFile->is_open() || m_outFile->bad() ) {
107 ATH_MSG_ERROR("Could not open output Hard-Scattering vertices file at : "
108 << m_hardVtxOutFileName.value());
109 if ( m_outFile ) {
110 delete m_outFile;
111 m_outFile = nullptr;
112 }
113 return StatusCode::FAILURE;
114 }
115
116 // retrieve and configure HepMC writer tools
117 if ( setupHepMcWriterTools().isFailure() ) {
118 ATH_MSG_ERROR("Could not configure the HepMC::GenEvent writer tools !!");
119 return StatusCode::FAILURE;
120 }
121
122 return StatusCode::SUCCESS;
123}
StatusCode setupHepMcWriterTools()
Request pointers to the HepMcWriterTools to be able to write out HepMC::GenEvent for further comparis...

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ interfaceID()

const InterfaceID & ITruthParticleValidationTool::interfaceID ( )
inlinestaticinherited

Inline methods:

Definition at line 65 of file ITruthParticleValidationTool.h.

66{
68}
static const InterfaceID IID_ITruthParticleValidationTool("ITruthParticleValidationTool", 1, 0)

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ setupHepMcWriterTools()

StatusCode GenAodValidationTool::setupHepMcWriterTools ( )
protected

Request pointers to the HepMcWriterTools to be able to write out HepMC::GenEvent for further comparison (off-framework)

Definition at line 452 of file GenAodValidationTool.cxx.

453{
454 ATH_CHECK( m_refMcEventWriter.retrieve() );
455 ATH_CHECK( m_checkMcEventWriter.retrieve() );
456
457 // now we configure the tools
458 SmartIF<IProperty> prop{m_refMcEventWriter.get()};
459 ATH_CHECK( prop.isValid() );
460 ATH_CHECK( prop->setProperty("McEvents", m_refMcEventsName.value()) );
461
462 prop = m_checkMcEventWriter.get();
463 ATH_CHECK( prop.isValid() );
464 ATH_CHECK( prop->setProperty("McEvents", m_checkMcEventsName.value()) );
465
466 return StatusCode::SUCCESS;
467}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_checkMcEventsName

StringProperty GenAodValidationTool::m_checkMcEventsName
protected

Location of the 'to-be-validated' McEventCollection.

Definition at line 122 of file GenAodValidationTool.h.

◆ m_checkMcEventWriter

HepMcTool_t GenAodValidationTool::m_checkMcEventWriter
protected

Tool to write the 'to-be-checked' HepMC::GenEvent into a dedicated file.

Definition at line 143 of file GenAodValidationTool.h.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_hardVtxOutFileName

StringProperty GenAodValidationTool::m_hardVtxOutFileName
protected

Name of the output text file which will contain the hard-scattering vertices.

Default = "hepmc.hard.vtx.txt"

Definition at line 127 of file GenAodValidationTool.h.

◆ m_nAnalysedEvents

unsigned int TruthParticleValidationBaseTool::m_nAnalysedEvents
protectedinherited

Counter of analysed events.

Definition at line 75 of file TruthParticleValidationBaseTool.h.

◆ m_outFile

std::ofstream* GenAodValidationTool::m_outFile
protected

Pointer to the output text file containing hard-scattering vertices.

Definition at line 131 of file GenAodValidationTool.h.

◆ m_refMcEventsName

StringProperty GenAodValidationTool::m_refMcEventsName
protected

Location of the reference McEventCollection.

Definition at line 118 of file GenAodValidationTool.h.

◆ m_refMcEventWriter

HepMcTool_t GenAodValidationTool::m_refMcEventWriter
protected

Tool to write the reference HepMC::GenEvent into a dedicated file.

Definition at line 139 of file GenAodValidationTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: