From 260569dccad8f245aff193d306875573972b4f4c Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi <averbyts@cern.ch> Date: Wed, 10 Feb 2021 11:28:30 +0100 Subject: [PATCH 1/2] Migrate TruthD3pMaker to HepMC3 --- .../src/GenParticleGetterTool.cxx | 40 ++++++++++++++-- .../src/GenVertexGetterTool.cxx | 46 +++++++++++++++++-- .../TruthD3PDMaker/src/GenVertexGetterTool.h | 7 +++ .../src/GenVertexParticleAssociationTool.cxx | 17 +++++++ .../src/GenVertexParticleAssociationTool.h | 4 +- ...ruthParticleGenParticleAssociationTool.cxx | 8 ++++ 6 files changed, 114 insertions(+), 8 deletions(-) diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenParticleGetterTool.cxx b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenParticleGetterTool.cxx index d164ab793208..b6d63b38c5d3 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenParticleGetterTool.cxx +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenParticleGetterTool.cxx @@ -86,12 +86,45 @@ namespace D3PD { const void* GenParticleGetterTool::nextUntyped() { - if( m_evtItr == m_evtEnd ) return 0; + if( m_evtItr == m_evtEnd ) return nullptr; +#ifdef HEPMC3 +//AV: Untyped is a bad idea for smart pointers. // Check if this GenEvent passes our selection cuts: if( ! m_selector->pass( *m_evtItr, m_mcColl ) ) { ++m_evtItr; - if( m_evtItr == m_evtEnd ) return 0; + if( m_evtItr == m_evtEnd ) return nullptr; + m_partItr = ( *m_evtItr )->particles().begin(); + m_partEnd = ( *m_evtItr )->particles().end(); + return nextUntyped(); + } + + // Check if there are no more particles in this GenEvent: + if( m_partItr == m_partEnd ) { + ++m_evtItr; + if( m_evtItr == m_evtEnd ) return nullptr; + + m_partItr = ( *m_evtItr )->particles().begin(); + m_partEnd = ( *m_evtItr )->particles().end(); + return nextUntyped(); + } + + // Check if this GenParticle passes our selection: + if( ! m_selector->pass( *m_partItr, m_mcColl ) ) { + ++m_partItr; + return nextUntyped(); + } + + // I just like to write this part our verbosely... + HepMC::ConstGenParticlePtr part = *m_partItr; + ++m_partItr; + + return part.get(); +#else + // Check if this GenEvent passes our selection cuts: + if( ! m_selector->pass( *m_evtItr, m_mcColl ) ) { + ++m_evtItr; + if( m_evtItr == m_evtEnd ) return nullptr; m_partItr = ( *m_evtItr )->particles_begin(); m_partEnd = ( *m_evtItr )->particles_end(); return nextUntyped(); @@ -100,7 +133,7 @@ namespace D3PD { // Check if there are no more particles in this GenEvent: if( m_partItr == m_partEnd ) { ++m_evtItr; - if( m_evtItr == m_evtEnd ) return 0; + if( m_evtItr == m_evtEnd ) return nullptr; m_partItr = ( *m_evtItr )->particles_begin(); m_partEnd = ( *m_evtItr )->particles_end(); @@ -118,6 +151,7 @@ namespace D3PD { ++m_partItr; return part; +#endif } const std::type_info& GenParticleGetterTool::elementTypeinfo() const { diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexGetterTool.cxx b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexGetterTool.cxx index f9c4df34ccdc..9a3fc864f3da 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexGetterTool.cxx +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexGetterTool.cxx @@ -72,9 +72,13 @@ namespace D3PD { m_vtxItr = m_vtxEnd; return StatusCode::SUCCESS; } - +#ifdef HEPMC3 + m_vtxItr = ( *m_evtItr )->vertices().begin(); + m_vtxEnd = ( *m_evtItr )->vertices().end(); +#else m_vtxItr = ( *m_evtItr )->vertices_begin(); m_vtxEnd = ( *m_evtItr )->vertices_end(); +#endif return StatusCode::SUCCESS; } @@ -83,10 +87,41 @@ namespace D3PD { if( m_evtItr == m_evtEnd ) return nullptr; +#ifdef HEPMC3 // Check if this GenEvent passes our selection cuts: if( ! m_selector->pass( *m_evtItr, m_mcColl ) ) { ++m_evtItr; - if( m_evtItr == m_evtEnd ) return 0; + if( m_evtItr == m_evtEnd ) return nullptr; + m_vtxItr = ( *m_evtItr )->vertices().begin(); + m_vtxEnd = ( *m_evtItr )->vertices().end(); + return nextUntyped(); + } + + // Check if there are no more vertices in this GenEvent: + if( m_vtxEnd == m_vtxItr ){ + ++m_evtItr; + if( m_evtItr == m_evtEnd ) return nullptr; + + m_vtxItr = ( *m_evtItr )->vertices().begin(); + m_vtxEnd = ( *m_evtItr )->vertices().end(); + return nextUntyped(); + } + + if( ! m_selector->pass( *m_vtxItr, m_mcColl ) ) { + ++m_vtxItr; + return nextUntyped(); + } + + // I just like to write this part our verbosely... + HepMC::ConstGenVertexPtr vtx = *m_vtxItr; + ++m_vtxItr; + + return vtx.get(); +#else + // Check if this GenEvent passes our selection cuts: + if( ! m_selector->pass( *m_evtItr, m_mcColl ) ) { + ++m_evtItr; + if( m_evtItr == m_evtEnd ) return nullptr; m_vtxItr = ( *m_evtItr )->vertices_begin(); m_vtxEnd = ( *m_evtItr )->vertices_end(); return nextUntyped(); @@ -95,7 +130,7 @@ namespace D3PD { // Check if there are no more vertices in this GenEvent: if( m_vtxEnd == m_vtxItr ){ ++m_evtItr; - if( m_evtItr == m_evtEnd ) return 0; + if( m_evtItr == m_evtEnd ) return nullptr; m_vtxItr = ( *m_evtItr )->vertices_begin(); m_vtxEnd = ( *m_evtItr )->vertices_end(); @@ -112,11 +147,16 @@ namespace D3PD { ++m_vtxItr; return vtx; +#endif } const std::type_info& GenVertexGetterTool::elementTypeinfo() const { +#ifdef HEPMC3 + return typeid( HepMC::GenVertexPtr ); +#else return typeid( HepMC::GenVertex ); +#endif } } // namespace D3PD diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexGetterTool.h b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexGetterTool.h index e5a798106a3d..3e55c690dec0 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexGetterTool.h +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexGetterTool.h @@ -66,11 +66,18 @@ namespace D3PD { McEventCollection::const_iterator m_evtItr; /// Iterator pointing at the last GenEvent object McEventCollection::const_iterator m_evtEnd; +#ifdef HEPMC3 + /// Iterator pointing at the current GenVertex object + std::vector<HepMC::ConstGenVertexPtr>::const_iterator m_vtxItr; + /// Iterator pointing at the lst GenVertex object + std::vector<HepMC::ConstGenVertexPtr>::const_iterator m_vtxEnd; +#else /// Iterator pointing at the current GenVertex object HepMC::GenEvent::vertex_const_iterator m_vtxItr; /// Iterator pointing at the lst GenVertex object HepMC::GenEvent::vertex_const_iterator m_vtxEnd; +#endif /// Tool used to select "good" GenVertex objects ToolHandle< IGenObjectsFilterTool > m_selector; diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.cxx b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.cxx index 66084b2c3470..da1d968464b5 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.cxx +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.cxx @@ -20,6 +20,16 @@ namespace D3PD { StatusCode GenVertexParticleAssociationTool::reset( const HepMC::GenVertex& p ) { +#ifdef HEPMC3 + if( m_inParticles ) { + m_partItr = p.particles_in().begin(); + m_partEnd = p.particles_in().end(); + return StatusCode::SUCCESS; + } + + m_partItr = p.particles_out().begin(); + m_partEnd = p.particles_out().end(); +#else if( m_inParticles ) { m_partItr = p.particles_in_const_begin(); m_partEnd = p.particles_in_const_end(); @@ -28,9 +38,15 @@ namespace D3PD { m_partItr = p.particles_out_const_begin(); m_partEnd = p.particles_out_const_end(); +#endif return StatusCode::SUCCESS; } +#ifdef HEPMC3 +const HepMC::GenParticle* GenVertexParticleAssociationTool::next() { +return nullptr; +} +#else const HepMC::GenParticle* GenVertexParticleAssociationTool::next() { if( m_partItr == m_partEnd ) return 0; @@ -41,5 +57,6 @@ namespace D3PD { return part; } +#endif } // namespace D3PD diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.h b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.h index dd2dbe587d37..971dbfe478a9 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.h +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.h @@ -66,9 +66,9 @@ namespace D3PD { private: /// Iterator pointing at the current particle - std::vector< HepMC::GenParticle* >::const_iterator m_partItr; + std::vector< HepMC::ConstGenParticlePtr >::const_iterator m_partItr; /// Iterator pointing at the last particle - std::vector< HepMC::GenParticle* >::const_iterator m_partEnd; + std::vector< HepMC::ConstGenParticlePtr >::const_iterator m_partEnd; /// Associate the incoming particles of the vertex bool m_inParticles; diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/TruthParticleGenParticleAssociationTool.cxx b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/TruthParticleGenParticleAssociationTool.cxx index 843e7f949f68..7ae36a4b2642 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/TruthParticleGenParticleAssociationTool.cxx +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/TruthParticleGenParticleAssociationTool.cxx @@ -39,11 +39,19 @@ TruthParticleGenParticleAssociationTool::TruthParticleGenParticleAssociationTool * * Return the target of the association, or 0. */ +#ifdef HEPMC3 +const HepMC::GenParticle* +TruthParticleGenParticleAssociationTool::get (const TruthParticle& p) +{ +return p.genParticle().get(); +} +#else const HepMC::GenParticle* TruthParticleGenParticleAssociationTool::get (const TruthParticle& p) { return p.genParticle(); } +#endif } // namespace D3PD -- GitLab From 92f0d7d7b5a813ca5bf79a43f9c2e43be1b22b01 Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi <andrii.verbytskyi@cern.ch> Date: Wed, 10 Feb 2021 13:19:44 +0000 Subject: [PATCH 2/2] Update GenVertexParticleAssociationTool.h --- .../TruthD3PDMaker/src/GenVertexParticleAssociationTool.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.h b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.h index 971dbfe478a9..ae5d26dd5535 100644 --- a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.h +++ b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenVertexParticleAssociationTool.h @@ -65,11 +65,17 @@ namespace D3PD { const HepMC::GenParticle* next(); private: +#ifdef HEPMC3 /// Iterator pointing at the current particle std::vector< HepMC::ConstGenParticlePtr >::const_iterator m_partItr; /// Iterator pointing at the last particle std::vector< HepMC::ConstGenParticlePtr >::const_iterator m_partEnd; - +#else + /// Iterator pointing at the current particle + HepMC::GenVertex::particles_in_const_iterator m_partItr; + /// Iterator pointing at the last particle + HepMC::GenVertex::particles_in_const_iterator m_partEnd; +#endif /// Associate the incoming particles of the vertex bool m_inParticles; -- GitLab