ATLAS Offline Software
Loading...
Searching...
No Matches
RootTruthParticleCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include <array>
11#include "TError.h"
12
13
14
15// GeneratorObjects includes
17
19//
20// Implementation of the ITruthParticleCnvTool function(s)
21//
22
23StatusCode RootTruthParticleCnvTool::execute() const { abort(); }
24StatusCode RootTruthParticleCnvTool::execute(const EventContext&) const { abort(); }
25
26StatusCode
28 const unsigned int genEventIndex,
30 const ITruthParticleVisitor* visitor )
31 const
32{
33 container->clear();
34
35 if ( 0 == mcCollection ) {
36 ::Warning ("RootTruthParticleCnvTool",
37 "Null pointer to McEventCollection !");
38 return StatusCode::RECOVERABLE;
39 }
40
41 if ( mcCollection->size() <= genEventIndex ) {
42 ::Warning ("RootTruthParticleCnvTool",
43 "McEventCollection size: %ui; Requested element nbr : %ui !!",
44 // we could use %zd instead of using %ui and casting size_t to
45 // unsigned int, but %zd is not ANSI...
46 (unsigned int)mcCollection->size(),
47 genEventIndex);
48 return StatusCode::RECOVERABLE;
49 }
50
51 const HepMC::GenEvent * evt = (*mcCollection)[genEventIndex];
52 container->setGenEvent( mcCollection, genEventIndex );
53
54 // reserve enough space for the container so we don't have to relocate it
55 container->reserve( evt->particles_size() );
56
59
60 for ( const auto& hepMcPart: *evt) {
61
62 TruthParticle * mcPart = new TruthParticle( hepMcPart, container );
63 container->push_back( mcPart );
64
65 if ( visitor ) {
66 visitor->visit( mcPart );
67 }
68
69 mcPart->setCharge( chargeFromPdgId( mcPart->pdgId() ) );
70 mcPart->setGenEventIndex( genEventIndex);
71
72 if ( hepMcPart != mcPart->genParticle() ) {
73 ::Error ("RootTruthParticleCnvTool",
74 "TruthParticle is not wrapping the GenParticle : %d !!",
75 HepMC::barcode(hepMcPart));
76 }
77 HepMcParticleLink mcLink( HepMC::barcode(hepMcPart), genEventIndex, HepMcParticleLink::IS_POSITION, HepMcParticleLink::IS_BARCODE ); // FIXME barcode-based
78 bcToMcPart[ mcLink.compress() ] = mcPart;
79
80 }//> end loop over particles
81
82 // at this point the whole GenEvent has been proxied.
83 // so we can setup its VectorMap
84 container->setParticles( bcToMcPart );
85
86#if 0
87 // connect the TruthParticleContainer to the container of TruthEtIsolations
88 // if it exists and if we are asked for
89 if ( m_doEtIsolation.value() ) {
90 const std::string& etIsolName
91 = m_isolationTool->etIsolationsName( container->genEventName() );
92 if ( etIsolName.empty() ) {
93 m_msg << MSG::WARNING
94 << "Could not retrieve the name of the TruthEtIsolations container"
95 << endmsg;
96 return StatusCode::RECOVERABLE;
97 }
98
99 const TruthEtIsolationsContainer* etIsols = 0;
100 if ( !m_storeGate->retrieve( etIsols, etIsolName ).isSuccess() ) {
101 m_msg << MSG::WARNING
102 << "Could not retrieve the TruthEtIsolations container at ["
103 << etIsolName << "] !!"
104 << endmsg;
105 return StatusCode::RECOVERABLE;
106 }
107
108 // index of HepMC::GenEvent within the McEventCollection is the same
109 // than the one of the TruthEtIsolations within the TruthEtIsolationsCont.
110 container->setEtIsolations( etIsols, genEventIndex );
111 }
112#endif
113
114 return StatusCode::SUCCESS;
115}
116
117//
119
121{
122 return MC::charge(pdgId);
123}
124
125
127//
128// Implementation of the IProperty function(s)
129//
130
131StatusCode RootTruthParticleCnvTool::setProperty( const std::string& ) {
132 abort(); }
133StatusCode RootTruthParticleCnvTool::setProperty( const std::string&, const Gaudi::Details::PropertyBase& ) { abort(); }
134StatusCode RootTruthParticleCnvTool::setPropertyRepr( const std::string&, const std::string& ){ abort(); }
135StatusCode RootTruthParticleCnvTool::getProperty( Gaudi::Details::PropertyBase* ) const { abort(); }
136const Gaudi::Details::PropertyBase&
137RootTruthParticleCnvTool::getProperty( std::string_view ) const{ abort(); }
138StatusCode RootTruthParticleCnvTool::getProperty( std::string_view,
139 std::string& ) const {
140 abort(); }
141const std::vector< Gaudi::Details::PropertyBase* >&
143bool RootTruthParticleCnvTool::hasProperty( std::string_view ) const {
144 abort(); }
145
146//
148
150//
151// Implementation of the IAlgTool function(s)
152//
153
154const std::string& RootTruthParticleCnvTool::type() const { abort(); }
155const IInterface* RootTruthParticleCnvTool::parent() const { abort(); }
156StatusCode RootTruthParticleCnvTool::configure() { abort(); }
161StatusCode RootTruthParticleCnvTool::start() { abort(); }
162StatusCode RootTruthParticleCnvTool::sysStart() { abort(); }
163StatusCode RootTruthParticleCnvTool::restart() { abort(); }
165StatusCode RootTruthParticleCnvTool::stop() { abort(); }
166StatusCode RootTruthParticleCnvTool::sysStop() { abort(); }
167StatusCode RootTruthParticleCnvTool::finalize() { abort(); }
169StatusCode RootTruthParticleCnvTool::terminate() { abort(); }
170Gaudi::StateMachine::State RootTruthParticleCnvTool::FSMState() const {
171 abort(); }
172
173//
175
177//
178// Implementation of the INamedInterface function(s)
179//
180
181const std::string& RootTruthParticleCnvTool::name() const{abort();}
182
183//
#define endmsg
ATLAS-specific HepMC functions.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual void visit(TruthParticle *truthParticle) const =0
The method to visit a TruthParticle to apply further modifications to the instance at hand.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual int pdgId() const
Return enum indicating particle id the enum file is available in Event/EventKernel/PdtPdg....
virtual StatusCode start() override
virtual bool hasProperty(std::string_view name) const override
virtual StatusCode finalize() override
virtual StatusCode sysReinitialize() override
virtual StatusCode execute() const override
A hook for Athena algorithms.
virtual StatusCode sysRestart() override
virtual StatusCode sysStart() override
virtual const IInterface * parent() const override
virtual StatusCode stop() override
virtual StatusCode reinitialize() override
virtual const std::string & type() const override
virtual StatusCode sysInitialize() override
virtual StatusCode terminate() override
virtual StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
virtual Gaudi::StateMachine::State FSMState() const override
virtual const std::string & name() const override
virtual StatusCode sysFinalize() override
virtual StatusCode restart() override
virtual StatusCode convert(const McEventCollection *mcEvts, const unsigned int genEvtIndex, TruthParticleContainer *mcParts, const ITruthParticleVisitor *visitor) const override
Converts a McEventCollection into an TruthParticleContainer (ie: converts it into an AOD compliant co...
virtual StatusCode sysStop() override
double chargeFromPdgId(int pdgId) const
Helper method to get the charge of a particle given its PDG Id.
virtual StatusCode setPropertyRepr(const std::string &n, const std::string &r) override
virtual StatusCode initialize() override
virtual StatusCode configure() override
virtual StatusCode setProperty(const std::string &s) override
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const override
std::unordered_map< long, const TruthParticle * > Map_t
barcode to TruthParticle dictionary
HepMC::ConstGenParticlePtr genParticle() const
Retrieve the GenParticle this TruthParticle has been made from (if any)
void setCharge(const ChargeType charge)
Set the charge of this TruthParticle.
int barcode(const T *p)
Definition Barcode.h:16
double charge(const T &p)