diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenParticleGetterTool.cxx b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/GenParticleGetterTool.cxx index d164ab793208c3723bc51ec6f97b83bccb423827..b6d63b38c5d36452cca89f3d8ae20bc03919d8de 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 f9c4df34ccdc88de4d69c406ed131cd612d70d2c..9a3fc864f3da0f9646cab41fb986a7a231d1de18 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 e5a798106a3d0a2daf9af02d4c97fa68be5b4cfc..3e55c690dec04a506ba8de0fbc91402cbef2bee9 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 66084b2c34701353839e96324d9c33e7fb140e45..da1d968464b5400058ad51e9d0e50b4374a5ffd3 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 dd2dbe587d3721bfa80b35678765fb5a1bb7ef27..ae5d26dd55359e8150be3d13f6b7a95ff7f51473 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::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; +#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; diff --git a/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/TruthParticleGenParticleAssociationTool.cxx b/PhysicsAnalysis/D3PDMaker/TruthD3PDMaker/src/TruthParticleGenParticleAssociationTool.cxx index 843e7f949f6892327ff4e652a78a30482358ddab..7ae36a4b26425a82ac84e9fa006a0ee2616a3360 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