ATLAS Offline Software
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 
24 StatusCode RootTruthParticleCnvTool::execute(const EventContext&) const { abort(); }
25 
28  const unsigned int genEventIndex,
29  TruthParticleContainer * container,
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 
132  abort(); }
133 StatusCode RootTruthParticleCnvTool::setProperty( const std::string&, const Gaudi::Details::PropertyBase& ) { abort(); }
134 StatusCode RootTruthParticleCnvTool::setPropertyRepr( const std::string&, const std::string& ){ abort(); }
135 StatusCode RootTruthParticleCnvTool::getProperty( Gaudi::Details::PropertyBase* ) const { abort(); }
136 const Gaudi::Details::PropertyBase&
137 RootTruthParticleCnvTool::getProperty( std::string_view ) const{ abort(); }
139  std::string& ) const {
140  abort(); }
141 const std::vector< Gaudi::Details::PropertyBase* >&
143 bool RootTruthParticleCnvTool::hasProperty( std::string_view ) const {
144  abort(); }
145 
146 //
148 
150 //
151 // Implementation of the IAlgTool function(s)
152 //
153 
154 const std::string& RootTruthParticleCnvTool::type() const { abort(); }
155 const IInterface* RootTruthParticleCnvTool::parent() const { abort(); }
171  abort(); }
172 
173 //
175 
177 //
178 // Implementation of the INamedInterface function(s)
179 //
180 
181 const std::string& RootTruthParticleCnvTool::name() const{abort();}
182 
183 //
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
RootTruthParticleCnvTool::sysRestart
virtual StatusCode sysRestart() override
Definition: RootTruthParticleCnvTool.cxx:164
RootTruthParticleCnvTool::restart
virtual StatusCode restart() override
Definition: RootTruthParticleCnvTool.cxx:163
RootTruthParticleCnvTool::convert
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...
Definition: RootTruthParticleCnvTool.cxx:27
RootTruthParticleCnvTool::name
virtual const std::string & name() const override
Definition: RootTruthParticleCnvTool.cxx:181
TruthParticleContainer::setEtIsolations
void setEtIsolations(const ElementLink< TruthEtIsolationsContainer > &etIsolations)
Setup the persistent pointer toward the TruthEtIsolations.
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:307
ParticleImpl::pdgId
virtual int pdgId() const
Return enum indicating particle id the enum file is available in Event/EventKernel/PdtPdg....
Definition: ParticleImpl.h:738
RootTruthParticleCnvTool::reinitialize
virtual StatusCode reinitialize() override
Definition: RootTruthParticleCnvTool.cxx:159
RootTruthParticleCnvTool::FSMState
virtual Gaudi::StateMachine::State FSMState() const override
Definition: RootTruthParticleCnvTool.cxx:170
TruthParticleContainer.h
TruthEtIsolationsContainer
Definition: TruthEtIsolationsContainer.h:26
RootTruthParticleCnvTool::parent
virtual const IInterface * parent() const override
Definition: RootTruthParticleCnvTool.cxx:155
TruthParticle
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticle.h:58
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
RootTruthParticleCnvTool::setPropertyRepr
virtual StatusCode setPropertyRepr(const std::string &n, const std::string &r) override
Definition: RootTruthParticleCnvTool.cxx:134
RootTruthParticleCnvTool::stop
virtual StatusCode stop() override
Definition: RootTruthParticleCnvTool.cxx:165
TruthParticle::genParticle
HepMC::ConstGenParticlePtr genParticle() const
Retrieve the GenParticle this TruthParticle has been made from (if any)
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticle.h:279
TruthParticleContainer
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:42
TruthParticle::setGenEventIndex
void setGenEventIndex(size_t index)
set the GenEvent index
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticle.h:338
RootTruthParticleCnvTool::start
virtual StatusCode start() override
Definition: RootTruthParticleCnvTool.cxx:161
RootTruthParticleCnvTool::getProperty
virtual StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
Definition: RootTruthParticleCnvTool.cxx:135
McEventCollection.h
ITruthParticleVisitor
Definition: ITruthParticleVisitor.h:30
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
MuonR4::State
CalibratedSpacePoint::State State
Definition: SpacePointCalibrator.cxx:24
RootTruthParticleCnvTool::terminate
virtual StatusCode terminate() override
Definition: RootTruthParticleCnvTool.cxx:169
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
RootTruthParticleCnvTool::sysStop
virtual StatusCode sysStop() override
Definition: RootTruthParticleCnvTool.cxx:166
TruthParticleContainer::setGenEvent
void setGenEvent(const ElementLink< McEventCollection > &genEvent)
Setup the persistent pointer toward the HepMC::GenEvent this TruthParticleContainer is proxying.
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:290
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
RootTruthParticleCnvTool::configure
virtual StatusCode configure() override
Definition: RootTruthParticleCnvTool.cxx:156
DataVector::clear
void clear()
Erase all the elements in the collection.
TruthParticle.h
TruthParticleContainer::Map_t
std::unordered_map< long, const TruthParticle * > Map_t
barcode to TruthParticle dictionary
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:59
charge
double charge(const T &p)
Definition: AtlasPID.h:538
RootTruthParticleCnvTool::type
virtual const std::string & type() const override
Definition: RootTruthParticleCnvTool.cxx:154
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
RootTruthParticleCnvTool::chargeFromPdgId
double chargeFromPdgId(int pdgId) const
Helper method to get the charge of a particle given its PDG Id.
Definition: RootTruthParticleCnvTool.cxx:120
RootTruthParticleCnvTool::finalize
virtual StatusCode finalize() override
Definition: RootTruthParticleCnvTool.cxx:167
RootTruthParticleCnvTool::sysFinalize
virtual StatusCode sysFinalize() override
Definition: RootTruthParticleCnvTool.cxx:168
RootTruthParticleCnvTool::getProperties
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const override
Definition: RootTruthParticleCnvTool.cxx:142
TruthParticleContainer::setParticles
void setParticles(const Map_t &parts)
Setup the dictionary of barcodes-to-TruthParticle.
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:323
TruthParticleContainer::genEventName
const std::string & genEventName() const
Retrieve the name (StoreGate location) of the HepMC::GenEvent this TruthParticleContainer is proxying...
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:249
ITruthParticleVisitor::visit
virtual void visit(TruthParticle *truthParticle) const =0
The method to visit a TruthParticle to apply further modifications to the instance at hand.
RootTruthParticleCnvTool::sysReinitialize
virtual StatusCode sysReinitialize() override
Definition: RootTruthParticleCnvTool.cxx:160
RootTruthParticleCnvTool::execute
virtual StatusCode execute() const override
A hook for Athena algorithms.
Definition: RootTruthParticleCnvTool.cxx:23
RootTruthParticleCnvTool.h
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
RootTruthParticleCnvTool::initialize
virtual StatusCode initialize() override
Definition: RootTruthParticleCnvTool.cxx:157
RootTruthParticleCnvTool::sysInitialize
virtual StatusCode sysInitialize() override
Definition: RootTruthParticleCnvTool.cxx:158
RootTruthParticleCnvTool::hasProperty
virtual bool hasProperty(std::string_view name) const override
Definition: RootTruthParticleCnvTool.cxx:143
RootTruthParticleCnvTool::setProperty
virtual StatusCode setProperty(const std::string &s) override
Definition: RootTruthParticleCnvTool.cxx:131
TruthParticle::setCharge
void setCharge(const ChargeType charge)
Set the charge of this TruthParticle.
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticle.h:327
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
RootTruthParticleCnvTool::sysStart
virtual StatusCode sysStart() override
Definition: RootTruthParticleCnvTool.cxx:162
HepMCHelpers.h