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

#include <xAODtoHepMCTool.h>

Inheritance diagram for xAODtoHepMCTool:
Collaboration diagram for xAODtoHepMCTool:

Public Member Functions

 xAODtoHepMCTool (const std::string &name)
virtual ~xAODtoHepMCTool ()
virtual StatusCode initialize () override
 Dummy implementation of the initialisation function.
StatusCode finalize () override
std::vector< HepMC::GenEvent > getHepMCEvents (const xAOD::TruthEventContainer *xTruthEventContainer, const xAOD::EventInfo *eventInfo) const override
virtual void print () const
 Print the state of the tool.
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
Additional helper functions, not directly mimicking Athena
template<class T>
const T * getProperty (const std::string &name) const
 Get one of the tool's properties.
const std::string & msg_level_name () const __attribute__((deprecated))
 A deprecated function for getting the message level's name.
const std::string & getName (const void *ptr) const
 Get the name of an object that is / should be in the event store.
SG::sgkey_t getKey (const void *ptr) const
 Get the (hashed) key of an object that is in the event store.

Protected Member Functions

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.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

HepMC::GenEvent createHepMCEvent (const xAOD::TruthEvent *xEvt, const xAOD::EventInfo *eventInfo) const
HepMC::GenVertexPtr vertexHelper (const xAOD::TruthVertex *, std::map< const xAOD::TruthVertex *, HepMC::GenVertexPtr > &, bool &) const
HepMC::GenParticlePtr createHepMCParticle (const xAOD::TruthParticle *) const
HepMC::GenVertexPtr createHepMCVertex (const xAOD::TruthVertex *) const
void printxAODEvent (const xAOD::TruthEvent *event, const xAOD::EventInfo *eventInfo) const
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

Gaudi::Property< float > m_momFac
 Input container key (job property)
Gaudi::Property< float > m_lenFac
Gaudi::Property< bool > m_signalOnly
Gaudi::Property< int > m_maxCount
std::atomic< int > m_evtCount {}
 Counters.
std::atomic< int > m_badSuggest {}
int m_noProdVtx {}
int m_badBeams {}
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 22 of file xAODtoHepMCTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

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

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ xAODtoHepMCTool()

xAODtoHepMCTool::xAODtoHepMCTool ( const std::string & name)

Definition at line 11 of file xAODtoHepMCTool.cxx.

12 : asg::AsgTool(name)
13{
14}

◆ ~xAODtoHepMCTool()

virtual xAODtoHepMCTool::~xAODtoHepMCTool ( )
inlinevirtual

Definition at line 26 of file xAODtoHepMCTool.h.

26{ };

Member Function Documentation

◆ createHepMCEvent()

HepMC::GenEvent xAODtoHepMCTool::createHepMCEvent ( const xAOD::TruthEvent * xEvt,
const xAOD::EventInfo * eventInfo ) const
private

EVENT LEVEL

Avoid double deletion

Definition at line 90 of file xAODtoHepMCTool.cxx.

91{
92
94 HepMC::GenEvent genEvt;
95 #ifdef HEPMC3
96 genEvt.set_units(HepMC3::Units::MEV, HepMC3::Units::MM);
97 #endif
98
99 long long int evtNum = eventInfo->eventNumber();
100 genEvt.set_event_number(evtNum);
101 ATH_MSG_DEBUG("Start createHepMCEvent for event " << evtNum);
102
103 //Weights
104 #ifndef XAOD_STANDALONE
105 const std::vector<float> weights = xEvt->weights();
106 std::map<std::string, int> weightNameMap;
107 if (AthAnalysisHelper::retrieveMetadata("/Generation/Parameters","HepMCWeightNames", weightNameMap).isFailure()) {
108 ATH_MSG_DEBUG("Couldn't find meta-data for weight names.");
109 }
110 #ifdef HEPMC3
111 std::shared_ptr<HepMC3::GenRunInfo> runinfo = std::make_shared<HepMC3::GenRunInfo>();
112 genEvt.set_run_info(std::move(runinfo));
113 std::vector<std::string> wnames;
114 wnames.reserve(weights.size());
115 for (int idx = 0; idx < int(weights.size()); ++idx) {
116 for (const auto& it : weightNameMap) {
117 if (it.second == idx) {
118 wnames.push_back(it.first);
119 break;
120 }
121 }
122 }
123 genEvt.run_info()->set_weight_names(wnames);
124 for ( std::vector<float>::const_iterator wgt = weights.begin(); wgt != weights.end(); ++wgt ) {
125 genEvt.weights().push_back(*wgt);
126 }
127 #else
128 if (weightNameMap.size()) {
129 HepMC::WeightContainer& wc = genEvt.weights();
130 wc.clear();
131 for (int idx = 0; idx < int(weights.size()); ++idx) {
132 for (const auto& it : weightNameMap) {
133 if (it.second == idx) {
134 wc[ it.first ] = weights[idx];
135 break;
136 }
137 }
138 }
139 }
140 else {
141 for ( std::vector<float>::const_iterator wgt = weights.begin(); wgt != weights.end(); ++wgt ) {
142 genEvt.weights().push_back(*wgt);
143 }
144 }
145 #endif
146 #endif
147
148 // PARTICLES AND VERTICES
149 // Map of existing vertices - needed for the tree linking
150 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> vertexMap;
151
152 // Loop over all of the particles in the event, call particle builder
153 for (auto tlink : xEvt->truthParticleLinks()) {
154 if (!tlink.isValid()) { continue; }
155 const xAOD::TruthParticle *xPart = *tlink;
156
157 // sanity check
158 if (xPart == nullptr) {
159 ATH_MSG_WARNING("xAOD TruthParticle is equal to NULL. This should not happen!");
160 continue;
161 }
162
163 if (!xPart->hasProdVtx() && !xPart->hasDecayVtx()) {
164 ATH_MSG_WARNING("xAOD particle with no vertices, uniqueID = " << HepMC::uniqueID(xPart));
165 continue;
166 }
167
168 // skip particles which are Geant4 secondaries
169 if (HepMC::is_simulation_particle(xPart)) { continue; }
170
171 // Create GenParticle
172 // presumably the GenEvent takes ownership of this, but creating a unique_ptr here as that will only happen if there's an associated vertex
173#ifdef HEPMC3
174 auto hepmcParticle = createHepMCParticle(xPart);
175#else
176 std::unique_ptr<HepMC::GenParticle> hepmcParticle(createHepMCParticle(xPart));
177#endif
178
179 // Get the production and decay vertices
180 if (xPart->hasProdVtx()) {
181 const xAOD::TruthVertex *xAODProdVtx = xPart->prodVtx();
182 // skip production vertices which are Geant4 secondaries
183 if (HepMC::is_simulation_vertex(xAODProdVtx)) { continue; }
184 bool prodVtxSeenBefore(false); // is this new?
185 auto hepmcProdVtx = vertexHelper(xAODProdVtx, vertexMap, prodVtxSeenBefore);
186 // Set the decay/production links
187#ifdef HEPMC3
188 hepmcProdVtx->add_particle_out(hepmcParticle);
189#else
190 hepmcProdVtx->add_particle_out(hepmcParticle.get());
191#endif
192 // Insert into Event
193 if (!prodVtxSeenBefore) {
194 genEvt.add_vertex(std::move(hepmcProdVtx));
195 }
196 }
197 else {
198 ATH_MSG_VERBOSE("No production vertex found for particle " << HepMC::uniqueID(xPart));
199 }
200
201 if (xPart->hasDecayVtx()) {
202 const xAOD::TruthVertex *xAODDecayVtx = xPart->decayVtx();
203 // skip decay vertices which are Geant4 secondaries
204 if (HepMC::is_simulation_vertex(xAODDecayVtx)) {
206#ifndef HEPMC3
207 if (xPart->hasProdVtx()) { (void)hepmcParticle.release(); }
208#endif
209 continue;
210 }
211 bool decayVtxSeenBefore(false); // is this new?
212 auto hepmcDecayVtx = vertexHelper(xAODDecayVtx, vertexMap, decayVtxSeenBefore);
213 // Set the decay/production links
214#ifdef HEPMC3
215 hepmcDecayVtx->add_particle_in(std::move(hepmcParticle));
216#else
217 hepmcDecayVtx->add_particle_in(hepmcParticle.get());
218#endif
219 // Insert into Event
220 if (!decayVtxSeenBefore) {
221 genEvt.add_vertex(std::move(hepmcDecayVtx));
222 }
223 }
224#ifndef HEPMC3
225 (void)hepmcParticle.release();
226#endif
227
228 } // end of particle loop
229
230 return genEvt;
231}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static std::string retrieveMetadata(const std::string &folder, const std::string &key, const ServiceHandle< StoreGateSvc > &inputMetaStore)
method that always returns as a string you can use from, e.g, pyROOT with evt = ROOT....
uint64_t eventNumber() const
The current event's event number.
const TruthParticleLinks_t & truthParticleLinks() const
Get all the truth particles.
const std::vector< float > & weights() const
Const access to the weights vector.
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
bool hasProdVtx() const
Check for a production vertex on this particle.
bool hasDecayVtx() const
Check for a decay vertex on this particle.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
HepMC::GenVertexPtr vertexHelper(const xAOD::TruthVertex *, std::map< const xAOD::TruthVertex *, HepMC::GenVertexPtr > &, bool &) const
HepMC::GenParticlePtr createHepMCParticle(const xAOD::TruthParticle *) const
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (TODO migrate to be based on status).
int uniqueID(const T &p)
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ createHepMCParticle()

HepMC::GenParticlePtr xAODtoHepMCTool::createHepMCParticle ( const xAOD::TruthParticle * particle) const
private

Definition at line 259 of file xAODtoHepMCTool.cxx.

260{
261 ATH_MSG_VERBOSE("Creating GenParticle for uniqueID " << HepMC::uniqueID(particle));
262 const HepMC::FourVector fourVec(m_momFac * particle->px(), m_momFac * particle->py(), m_momFac * particle->pz(), m_momFac * particle->e());
263 auto hepmcParticle = HepMC::newGenParticlePtr(fourVec, particle->pdgId(), particle->status());
264 hepmcParticle->set_generated_mass(m_momFac * particle->m());
265 return hepmcParticle;
266}
Gaudi::Property< float > m_momFac
Input container key (job property)
GenParticlePtr newGenParticlePtr(const HepMC::FourVector &mom=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), int pid=0, int status=0)
Definition GenParticle.h:39
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses

◆ createHepMCVertex()

HepMC::GenVertexPtr xAODtoHepMCTool::createHepMCVertex ( const xAOD::TruthVertex * vertex) const
private

Definition at line 269 of file xAODtoHepMCTool.cxx.

270{
271 ATH_MSG_VERBOSE("Creating GenVertex for uniqueID " << HepMC::uniqueID(vertex));
272 HepMC::FourVector prod_pos(m_lenFac * vertex->x(), m_lenFac * vertex->y(), m_lenFac * vertex->z(), m_lenFac * vertex->t());
273 auto genVertex = HepMC::newGenVertexPtr(prod_pos);
274 return genVertex;
275}
Gaudi::Property< float > m_lenFac
GenVertexPtr newGenVertexPtr(const HepMC::FourVector &pos=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), const int i=0)
Definition GenVertex.h:64

◆ 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 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

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

◆ 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 xAODtoHepMCTool::finalize ( )
overridevirtual

Implements IxAODtoHepMCTool.

Definition at line 23 of file xAODtoHepMCTool.cxx.

24{
25 ATH_MSG_INFO("==============================================================");
26 ATH_MSG_INFO("========== xAOD -> HepMC Tool :: Run Summary ==========");
27 ATH_MSG_INFO("==============================================================");
28 if (m_noProdVtx)
29 {
30 ATH_MSG_INFO("Number of events that have a missing production vertex = " << m_noProdVtx);
31 }
32 else
33 {
34 ATH_MSG_INFO("No missing production vertices");
35 }
36 if (m_badBeams)
37 {
38 ATH_MSG_INFO("Number events with improperly defined beamparticles = " << m_badBeams);
39 ATH_MSG_INFO("Inconsistencies with the beam particles storage in the event record!");
40 ATH_MSG_INFO("... check xAOD::TruthEvent record ...");
41 }
42 else
43 {
44 ATH_MSG_INFO("No events with undefined beams.");
45 }
46 ATH_MSG_INFO("==============================================================");
47 ATH_MSG_INFO("=================== End Run Summary ===================");
48 ATH_MSG_INFO("==============================================================");
49 return StatusCode::SUCCESS;
50}
#define ATH_MSG_INFO(x)

◆ getHepMCEvents()

std::vector< HepMC::GenEvent > xAODtoHepMCTool::getHepMCEvents ( const xAOD::TruthEventContainer * xTruthEventContainer,
const xAOD::EventInfo * eventInfo ) const
overridevirtual

Implements IxAODtoHepMCTool.

Definition at line 52 of file xAODtoHepMCTool.cxx.

53{
54 ++m_evtCount;
55 bool doPrint = m_evtCount < m_maxCount;
56 // CREATE HEPMC EVENT COLLECTION
57 std::vector<HepMC::GenEvent> mcEventCollection;
58 // Loop over xAOD truth container
59 // Signal event is always first, followed by pileup events
60 ATH_MSG_DEBUG("Start event loop");
61 for (const xAOD::TruthEvent *xAODEvent : *xTruthEventContainer)
62 {
63 if (doPrint)
64 ATH_MSG_DEBUG("XXX Printing xAOD Event");
65 if (doPrint)
66 printxAODEvent(xAODEvent, eventInfo);
67 // Create GenEvent for each xAOD truth event
68 ATH_MSG_DEBUG("Create new GenEvent");
69 HepMC::GenEvent&& hepmcEvent = createHepMCEvent(xAODEvent, eventInfo);
70 #ifdef HEPMC3
71 std::shared_ptr<HepMC3::GenRunInfo> runinfo = std::make_shared<HepMC3::GenRunInfo>(*(hepmcEvent.run_info().get()));
72 #endif
73 //possibly print info, before moving the object
74 if (doPrint){
75 ATH_MSG_DEBUG("XXX Printing HepMC Event");
76 HepMC::Print::line(std::cout, hepmcEvent);
77 }
78 // Insert into McEventCollection
79 mcEventCollection.push_back(std::move(hepmcEvent));
80 #ifdef HEPMC3
81 mcEventCollection[mcEventCollection.size()-1].set_run_info(std::move(runinfo));
82 #endif
83 // Quit if signal only
84 if (m_signalOnly)
85 break;
86 }
87 return mcEventCollection;
88}
std::atomic< int > m_evtCount
Counters.
HepMC::GenEvent createHepMCEvent(const xAOD::TruthEvent *xEvt, const xAOD::EventInfo *eventInfo) const
Gaudi::Property< bool > m_signalOnly
void printxAODEvent(const xAOD::TruthEvent *event, const xAOD::EventInfo *eventInfo) const
Gaudi::Property< int > m_maxCount
void line(std::ostream &os, const GenEvent &e)
Definition GenEvent.h:677
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition TruthEvent.h:17

◆ getKey()

SG::sgkey_t asg::AsgTool::getKey ( const void * ptr) const
inherited

Get the (hashed) key of an object that is in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the SG::sgkey_t key for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getName
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The hashed key of the object in the store. If not found, an invalid (zero) key.

Definition at line 119 of file AsgTool.cxx.

119 {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::TEvent, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
ServiceHandle< StoreGateSvc > & evtStore()

◆ getName()

const std::string & asg::AsgTool::getName ( const void * ptr) const
inherited

Get the name of an object that is / should be in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the std::string name for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getKey
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The string name of the object in the store. If not found, an empty string.

Definition at line 106 of file AsgTool.cxx.

106 {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::TEvent, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }

◆ getProperty()

template<class T>
const T * asg::AsgTool::getProperty ( const std::string & name) const
inherited

Get one of the tool's properties.

◆ initialize()

StatusCode xAODtoHepMCTool::initialize ( void )
overridevirtual

Dummy implementation of the initialisation function.

It's here to allow the dual-use tools to skip defining an initialisation function. Since many are doing so...

Reimplemented from asg::AsgTool.

Definition at line 16 of file xAODtoHepMCTool.cxx.

17{
18 ATH_MSG_INFO("Initializing xAODtoHepMCTool " << name() << "...");
19 ATH_MSG_INFO("SignalOnly = " << m_signalOnly);
20 return StatusCode::SUCCESS;
21}

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

◆ msg()

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

Definition at line 24 of file AthCommonMsg.h.

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

◆ msg_level_name()

const std::string & asg::AsgTool::msg_level_name ( ) const
inherited

A deprecated function for getting the message level's name.

Instead of using this, weirdly named function, user code should get the string name of the current minimum message level (in case they really need it...), with:

MSG::name( msg().level() )

This function's name doesn't follow the ATLAS coding rules, and as such will be removed in the not too distant future.

Returns
The string name of the current minimum message level that's printed

Definition at line 101 of file AsgTool.cxx.

101 {
102
103 return MSG::name( msg().level() );
104 }
MsgStream & msg() const
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19

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

◆ print()

◆ printxAODEvent()

void xAODtoHepMCTool::printxAODEvent ( const xAOD::TruthEvent * event,
const xAOD::EventInfo * eventInfo ) const
private

Definition at line 279 of file xAODtoHepMCTool.cxx.

280{
281
282 std::vector<int> uidPars;
283 std::vector<int> uidKids;
284
285 long long int evtNum = eventInfo->eventNumber();
286
287 std::cout << "======================================================================================" << std::endl;
288 std::cout << "xAODTruth Event " << evtNum << std::endl;
289 std::cout << " UniqueID PDG Id Status px(GeV) py(GeV) pz(GeV) E(GeV) Parent: Decay" << std::endl;
290 std::cout << " -----------------------------------------------------------------------------------" << std::endl;
291
292 int nPart = event->nTruthParticles();
293 std::ios oldState(nullptr);
294 oldState.copyfmt(std::cout); //save ostream format
295 for (int i = 0; i < nPart; ++i)
296 {
297 const xAOD::TruthParticle *part = event->truthParticle(i);
298 if (part == nullptr) continue;
299 if (HepMC::generations(part) > 0) continue;
300 int id = part->pdgId();
301 if (id != 25) continue;
302 int stat = part->status();
303 float px = part->px() / 1000.;
304 float py = part->py() / 1000.;
305 float pz = part->pz() / 1000.;
306 float e = part->e() / 1000.;
307 uidPars.clear();
308 uidKids.clear();
309
310 if (part->hasProdVtx())
311 {
312 const xAOD::TruthVertex *pvtx = part->prodVtx();
313 if (pvtx)
314 uidPars.push_back(HepMC::uniqueID(pvtx));
315 }
316
317 if (part->hasDecayVtx())
318 {
319 const xAOD::TruthVertex *dvtx = part->decayVtx();
320 if (dvtx)
321 uidKids.push_back(HepMC::uniqueID(dvtx));
322 }
323
324
325 std::cout << std::setw(10) << HepMC::uniqueID(part) << std::setw(12) << id
326 << std::setw(8) << stat
327 << std::setprecision(2) << std::fixed
328 << std::setw(10) << px << std::setw(10) << py
329 << std::setw(10) << pz << std::setw(10) << e << " ";
330 std::cout << "P: ";
331 for (unsigned int k = 0; k < uidPars.size(); ++k)
332 {
333 std::cout << uidPars[k] << " ";
334 }
335 std::cout << " D: ";
336 for (unsigned int k = 0; k < uidKids.size(); ++k)
337 {
338 std::cout << uidKids[k] << " ";
339 }
340 std::cout << std::endl;
341 }
342 std::cout << "======================================================================================" << std::endl;
343 std::cout.copyfmt(oldState);//restore ostream format
344}
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...

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

◆ 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

◆ vertexHelper()

HepMC::GenVertexPtr xAODtoHepMCTool::vertexHelper ( const xAOD::TruthVertex * xaodVertex,
std::map< const xAOD::TruthVertex *, HepMC::GenVertexPtr > & vertexMap,
bool & seenBefore ) const
private

Definition at line 235 of file xAODtoHepMCTool.cxx.

238{
239
240 HepMC::GenVertexPtr hepmcVertex;
241 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr>::iterator vMapItr;
242 vMapItr = vertexMap.find(xaodVertex);
243 // Vertex seen before?
244 if (vMapItr != vertexMap.end()) {
245 // YES: use the HepMC::Vertex already in the map
246 hepmcVertex = (*vMapItr).second;
247 seenBefore = true;
248 }
249 else {
250 // NO: create a new HepMC::Vertex
251 vertexMap[xaodVertex] = createHepMCVertex(xaodVertex);
252 hepmcVertex = vertexMap[xaodVertex];
253 seenBefore = false;
254 }
255 return hepmcVertex;
256}
HepMC::GenVertexPtr createHepMCVertex(const xAOD::TruthVertex *) const
HepMC::GenVertex * GenVertexPtr
Definition GenVertex.h:59

Member Data Documentation

◆ m_badBeams

int xAODtoHepMCTool::m_badBeams {}
private

Definition at line 60 of file xAODtoHepMCTool.h.

60{};

◆ m_badSuggest

std::atomic<int> xAODtoHepMCTool::m_badSuggest {}
mutableprivate

Definition at line 58 of file xAODtoHepMCTool.h.

58{};

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

std::atomic<int> xAODtoHepMCTool::m_evtCount {}
mutableprivate

Counters.

Definition at line 57 of file xAODtoHepMCTool.h.

57{};

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

Gaudi::Property<float> xAODtoHepMCTool::m_lenFac
private
Initial value:
{
this, "LengthFactor", 1.0,
"Scale factor to be applied to truth lengths to convert from mm, e.g. 0.01 to go to cm"}

Definition at line 46 of file xAODtoHepMCTool.h.

46 {
47 this, "LengthFactor", 1.0,
48 "Scale factor to be applied to truth lengths to convert from mm, e.g. 0.01 to go to cm"};

◆ m_maxCount

Gaudi::Property<int> xAODtoHepMCTool::m_maxCount
private
Initial value:
{
this, "PrintNevents", 0,
"Maximum number of events to print out"}

Definition at line 52 of file xAODtoHepMCTool.h.

52 {
53 this, "PrintNevents", 0,
54 "Maximum number of events to print out"};

◆ m_momFac

Gaudi::Property<float> xAODtoHepMCTool::m_momFac
private
Initial value:
{
this, "MomentFactor", 0.001,
"Scale factor to be applied to truth energy and momenta to convert from MeV, e.g. 0.001 to go to GeV"}

Input container key (job property)

Definition at line 43 of file xAODtoHepMCTool.h.

43 {
44 this, "MomentFactor", 0.001,
45 "Scale factor to be applied to truth energy and momenta to convert from MeV, e.g. 0.001 to go to GeV"};

◆ m_noProdVtx

int xAODtoHepMCTool::m_noProdVtx {}
private

Definition at line 59 of file xAODtoHepMCTool.h.

59{};

◆ m_signalOnly

Gaudi::Property<bool> xAODtoHepMCTool::m_signalOnly
private
Initial value:
{
this, "SignalOnly", true,
"Convert only the signal event (true), or all events found"}

Definition at line 49 of file xAODtoHepMCTool.h.

49 {
50 this, "SignalOnly", true,
51 "Convert only the signal event (true), or all events found"};

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