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

#include <SpclMcValidationTool.h>

Inheritance diagram for SpclMcValidationTool:
Collaboration diagram for SpclMcValidationTool:

Public Member Functions

 SpclMcValidationTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor with parameters:
virtual ~SpclMcValidationTool ()
 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< IIOMcAodToolMcAodTool_t

Protected Member Functions

 SpclMcValidationTool ()
 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 TruthParticleContainer *mcParts)
 Main method to perform the validation:
StatusCode setupMcAodWriterTool ()
 Request pointers to the IIOMcAodTool to be able to write out TruthParticleContainer 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_mcEventsName
 Location of the reference McEventCollection.
StringProperty m_truthParticlesName
 Location of the 'to-be-validated' TruthParticleContainer.
McAodTool_t m_mcAodWriterTool
 Tool to write the TruthParticleContainer 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 27 of file SpclMcValidationTool.h.

Member Typedef Documentation

◆ McAodTool_t

typedef ToolHandle<IIOMcAodTool> SpclMcValidationTool::McAodTool_t
protected

Definition at line 95 of file SpclMcValidationTool.h.

◆ StoreGateSvc_t

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

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ SpclMcValidationTool() [1/2]

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

Constructor with parameters:

Public methods:

Constructors

Definition at line 31 of file SpclMcValidationTool.cxx.

33 :
34 TruthParticleValidationBaseTool( type, name, 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}
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
StringProperty m_mcEventsName
Location of the reference McEventCollection.
McAodTool_t m_mcAodWriterTool
Tool to write the TruthParticleContainer into a dedicated file.
ToolHandle< IIOMcAodTool > McAodTool_t
StringProperty m_truthParticlesName
Location of the 'to-be-validated' TruthParticleContainer.
TruthParticleValidationBaseTool()
Default constructor:

◆ ~SpclMcValidationTool()

SpclMcValidationTool::~SpclMcValidationTool ( )
virtual

Destructor:

Destructor.

Definition at line 55 of file SpclMcValidationTool.cxx.

56{
57 ATH_MSG_DEBUG("Calling destructor");
58}
#define ATH_MSG_DEBUG(x)

◆ SpclMcValidationTool() [2/2]

SpclMcValidationTool::SpclMcValidationTool ( )
protected

Default constructor:

Member Function Documentation

◆ 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/2]

StatusCode SpclMcValidationTool::executeTool ( )
protectedvirtual

Main method to perform the validation.

Just a wrapper around the more API-detailed method.

Implements TruthParticleValidationBaseTool.

Definition at line 82 of file SpclMcValidationTool.cxx.

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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
Athena::TPCnvVers::Current TruthParticleContainer
ServiceHandle< StoreGateSvc > & evtStore()
virtual StatusCode executeTool()
Main method to perform the validation.
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ executeTool() [2/2]

StatusCode SpclMcValidationTool::executeTool ( const McEventCollection * refMcEvents,
const TruthParticleContainer * mcParts )
protectedvirtual

Main method to perform the validation:

  • check that each vertex is identical to the original one

Definition at line 112 of file SpclMcValidationTool.cxx.

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}
#define endmsg
#define ATH_MSG_WARNING(x)
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.
GenParticle * barcode_to_particle(const GenEvent *e, int id)
Definition GenEvent.h:630
int barcode(const T *p)
Definition Barcode.h:16
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ 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 SpclMcValidationTool::finalizeTool ( )
protectedvirtual

Reimplemented from TruthParticleValidationBaseTool.

Definition at line 76 of file SpclMcValidationTool.cxx.

77{
78 ATH_MSG_INFO("Finalizing " << name() << "...");
79 return StatusCode::SUCCESS;
80}

◆ 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 SpclMcValidationTool::initializeTool ( )
protectedvirtual

Non-const methods:

Reimplemented from TruthParticleValidationBaseTool.

Definition at line 64 of file SpclMcValidationTool.cxx.

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}
StatusCode setupMcAodWriterTool()
Request pointers to the IIOMcAodTool to be able to write out TruthParticleContainer for further compa...

◆ 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 }

◆ setupMcAodWriterTool()

StatusCode SpclMcValidationTool::setupMcAodWriterTool ( )
protected

Request pointers to the IIOMcAodTool to be able to write out TruthParticleContainer for further comparison (off-framework)

Definition at line 175 of file SpclMcValidationTool.cxx.

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}

◆ 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_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_mcAodWriterTool

McAodTool_t SpclMcValidationTool::m_mcAodWriterTool
protected

Tool to write the TruthParticleContainer into a dedicated file.

Definition at line 99 of file SpclMcValidationTool.h.

◆ m_mcEventsName

StringProperty SpclMcValidationTool::m_mcEventsName
protected

Location of the reference McEventCollection.

Definition at line 89 of file SpclMcValidationTool.h.

◆ m_nAnalysedEvents

unsigned int TruthParticleValidationBaseTool::m_nAnalysedEvents
protectedinherited

Counter of analysed events.

Definition at line 75 of file TruthParticleValidationBaseTool.h.

◆ m_truthParticlesName

StringProperty SpclMcValidationTool::m_truthParticlesName
protected

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

Definition at line 93 of file SpclMcValidationTool.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: