diff --git a/PhysicsAnalysis/TruthParticleID/McParticleTools/src/SpclMcValidationTool.cxx b/PhysicsAnalysis/TruthParticleID/McParticleTools/src/SpclMcValidationTool.cxx index 22aaea78e70970b51db28113d648e98f93271c07..2bf794a86ecfbaf6e3c102ab77368fe7f6ac43da 100755 --- a/PhysicsAnalysis/TruthParticleID/McParticleTools/src/SpclMcValidationTool.cxx +++ b/PhysicsAnalysis/TruthParticleID/McParticleTools/src/SpclMcValidationTool.cxx @@ -59,22 +59,6 @@ SpclMcValidationTool::~SpclMcValidationTool() ATH_MSG_DEBUG("Calling destructor"); } -/////////////////////////////////////////////////////////////////// -/// Const methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -/// Non-const methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -/// Protected methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -/// Const methods: -/////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// /// Non-const methods: /////////////////////////////////////////////////////////////////// @@ -152,17 +136,21 @@ SpclMcValidationTool::executeTool( const McEventCollection* mcEvents, return StatusCode::FAILURE; } - if ( static_cast<int>( mcParts->size() ) != genEvt->particles_size() ) { +#ifdef HEPMC3 + int particles_size=genEvt->particles().size(); +#else + int particles_size=genEvt->particles_size(); +#endif + if ( static_cast<int>( mcParts->size() ) != particles_size ) { ATH_MSG_ERROR("TruthParticleContainer and McEventCollection don't have "\ "the same number of particles !!" << endmsg << "\tTruthParticleContainer: " << mcParts->size() << endmsg - << "\tHepMC::GenEvent: " << genEvt->particles_size()); + << "\tHepMC::GenEvent: " << particles_size); return StatusCode::FAILURE; } if ( !m_mcAodWriterTool->execute().isSuccess() ) { - ATH_MSG_WARNING("Could NOT write out the TruthParticleContainer through "\ - "the IIOMcAodTool !!"); + ATH_MSG_WARNING("Could NOT write out the TruthParticleContainer through the IIOMcAodTool !!"); } const TruthParticleContainer::const_iterator itrEnd = mcParts->end(); @@ -170,15 +158,14 @@ SpclMcValidationTool::executeTool( const McEventCollection* mcEvents, itrPart != itrEnd; ++itrPart ) { const TruthParticle * mc = *itrPart; - const HepMC::GenParticle * hepMc = mc->genParticle(); + auto hepMc = mc->genParticle(); if ( hepMc->momentum() != mc->hlv() ) { - ATH_MSG_ERROR("TruthParticle and GenParticle-link don't have "\ - "same 4-mom !!"); + ATH_MSG_ERROR("TruthParticle and GenParticle-link don't have same 4-mom !!"); return StatusCode::FAILURE; } - const HepMC::GenParticle * genPart = genEvt->barcode_to_particle(hepMc->barcode()); + auto genPart = HepMC::barcode_to_particle(genEvt,HepMC::barcode(hepMc)); if ( hepMc->momentum() != genPart->momentum() ) { ATH_MSG_ERROR("GenParticle-link and GenParticle from McEvtColl "\ diff --git a/PhysicsAnalysis/TruthParticleID/McParticleTools/src/TruthIsolationTool.cxx b/PhysicsAnalysis/TruthParticleID/McParticleTools/src/TruthIsolationTool.cxx index 53a362fc8814d3abb9d62034f80ca4fbf81b0828..38ae770fc6d8793af2bbae72409809c070b37ad8 100755 --- a/PhysicsAnalysis/TruthParticleID/McParticleTools/src/TruthIsolationTool.cxx +++ b/PhysicsAnalysis/TruthParticleID/McParticleTools/src/TruthIsolationTool.cxx @@ -39,7 +39,7 @@ namespace { { return HepLorentzVector( v.x(), v.y(), v.z(), v.t() ); } } -typedef std::list<const HepMC::GenParticle*> GenParticles_t; +typedef std::list<HepMC::ConstGenParticlePtr> GenParticles_t; TruthIsolationTool::TruthIsolationTool( const std::string& type, const std::string& name, @@ -199,33 +199,25 @@ TruthIsolationTool::buildEtIsolations( const std::string& mcEvtName, // create a reduced list of particles GenParticles_t particles; - for ( HepMC::GenEvent::particle_const_iterator - i = genEvt->particles_begin(), - iEnd = genEvt->particles_end(); - i != iEnd; - ++i ) { - if ( isStable(*i) && isInteracting(*i) ) { - particles.push_back( *i ); + for ( auto i: *genEvt) { + if ( isStable(i) && isInteracting(i) ) { + particles.push_back( i ); } } - for ( HepMC::GenEvent::particle_const_iterator - i = genEvt->particles_begin(), - iEnd = genEvt->particles_end(); - i != iEnd; - ++i ) { - const HepMC::FourVector hlv = (*i)->momentum(); - const int ida = std::abs((*i)->pdg_id()); - const int sta = (*i)->status(); + for ( auto i: *genEvt) { + const HepMC::FourVector hlv = i->momentum(); + const int ida = std::abs(i->pdg_id()); + const int sta = i->status(); const double pt = hlv.perp(); // Compute isolation only for photon, electron, muon or tau. // Not for documentation particle const bool doComputeIso = ( ( ida == 22 && pt > m_ptGamMin ) || ida == 11 || ida == 13 || ida == 15 ) && - sta != 3 && isInteracting(*i); + sta != 3 && isInteracting(i); if ( doComputeIso ) { - computeIso( particles, *i, etIsols, partSel ); + computeIso( particles, i, etIsols, partSel ); } } @@ -234,7 +226,7 @@ TruthIsolationTool::buildEtIsolations( const std::string& mcEvtName, void TruthIsolationTool::computeIso( const GenParticles_t& particles, - const HepMC::GenParticle* part, + HepMC::ConstGenParticlePtr part, TruthEtIsolations& etIsolations, ITruthIsolationTool::ParticleSelect partSel ) { @@ -252,7 +244,7 @@ TruthIsolationTool::computeIso( const GenParticles_t& particles, iEnd = particles.end(); i != iEnd; ++i ) { - if ( (*i)->barcode() == part->barcode() ) { + if ( HepMC::barcode(*i) == HepMC::barcode(part) ) { continue; } if( partSel == ITruthIsolationTool::UseChargedOnly ) { @@ -279,17 +271,14 @@ TruthIsolationTool::computeIso( const GenParticles_t& particles, double pyv = 0.*GeV; auto decVtx = part->end_vertex(); if (ida == 15 && decVtx) { - HepMC::GenVertex::particle_iterator child = decVtx->particles_begin(HepMC::children); - HepMC::GenVertex::particle_iterator childE = decVtx->particles_end(HepMC::children); - for (; child != childE; ++child) { - if ( isInteracting(*child) ) { + for (auto child: *decVtx) { + if ( isInteracting(child) ) { if( partSel == ITruthIsolationTool::UseChargedOnly ) { - double particleCharge = McUtils::chargeFromPdgId((*child)->pdg_id(), - m_pdt); + double particleCharge = McUtils::chargeFromPdgId(child->pdg_id(),m_pdt); if( std::abs(particleCharge)<1.e-2 ) continue; } - const HepMC::FourVector childHlv = (*child)->momentum(); + const HepMC::FourVector childHlv = child->momentum(); pxv += childHlv.px(); pyv += childHlv.py(); } diff --git a/Simulation/G4Atlas/G4AtlasTests/src/TruthTestTool.cxx b/Simulation/G4Atlas/G4AtlasTests/src/TruthTestTool.cxx index f1f82ef25a047c7dd9f383eb2601a0ff91c698c3..a5dac7b791caa2292e377df2d7dd6a2a152d0c1b 100644 --- a/Simulation/G4Atlas/G4AtlasTests/src/TruthTestTool.cxx +++ b/Simulation/G4Atlas/G4AtlasTests/src/TruthTestTool.cxx @@ -159,7 +159,11 @@ StatusCode TruthTestTool::processEvent() if (currentGenEventIter!=mcCollection->end() ) { { auto vtx = HepMC::signal_process_vertex(*currentGenEventIter); +#ifdef HEPMC3 + if (!vtx && (*currentGenEventIter)->vertices().size()>0) vtx=((*currentGenEventIter)->vertices()).front(); +#else if (!vtx && (*currentGenEventIter)->vertices_size()>0) vtx=*((*currentGenEventIter)->vertices_begin()); +#endif if ( vtx ) { m_x_vert->Fill( vtx->position().x() ); @@ -171,18 +175,23 @@ StatusCode TruthTestTool::processEvent() int nvtx=0; int nvtx_sec=0; float mx=0.,my=0.,mz=0.; - for (HepMC::GenEvent::vertex_const_iterator vtx=(*currentGenEventIter)->vertices_begin(); - vtx!=(*currentGenEventIter)->vertices_end();++vtx) { - - double x = (*vtx)->position().x(); - double y = (*vtx)->position().y(); - double z = (*vtx)->position().z(); - double r = sqrt(x*x+y*y); +#ifdef HEPMC3 + for (auto vtx: (*currentGenEventIter)->vertices()) { +#else + for (HepMC::GenEvent::vertex_const_iterator vtxit=(*currentGenEventIter)->vertices_begin(); + vtxit!=(*currentGenEventIter)->vertices_end();++vtxit) { + auto vtx=*vtxit; +#endif + + double x = vtx->position().x(); + double y = vtx->position().y(); + double z = vtx->position().z(); + double r = std::sqrt(x*x+y*y); m_vtx_r->Fill(r); m_vtx_z->Fill(z); m_vtx_zr_indet->Fill(z, r); m_vtx_xy_indet->Fill(x, y); - if ( HepMC::barcode(*vtx)>-20000 ) { + if ( HepMC::barcode(vtx)>-20000 ) { mx+=x; my+=y; mz+=z; @@ -210,16 +219,15 @@ StatusCode TruthTestTool::processEvent() char fname[80]; sprintf(fname,"%s.event%d.txt",m_key.c_str(),evtnum); std::ofstream of(fname); - (*currentGenEventIter)->print(of); // verbose output + HepMC::Print::line(of,*(*currentGenEventIter)); // verbose output of.close(); } int npart_prim=0, npart_sec=0; HepMC::GenEvent::particle_const_iterator currentGenParticleIter; - for (currentGenParticleIter= (*currentGenEventIter)->particles_begin(); - currentGenParticleIter!= (*currentGenEventIter)->particles_end(); ++currentGenParticleIter) { + for (auto currentGenParticle: *(*currentGenEventIter)) { - const HepMC::FourVector mom = (*currentGenParticleIter)->momentum(); + const HepMC::FourVector mom = currentGenParticle->momentum(); m_px_truth->Fill( mom.x() ); m_py_truth->Fill( mom.y() ); m_pz_truth->Fill( mom.z() ); @@ -230,16 +238,16 @@ StatusCode TruthTestTool::processEvent() m_eta_truth->Fill( mom.eta() ); m_phi_truth->Fill( mom.phi() ); - if(std::abs((*currentGenParticleIter)->pdg_id())==211) { + if(std::abs(currentGenParticle->pdg_id())==211) { m_pion_mass->Fill(mom.m()); } - m_barcode_small->Fill(HepMC::barcode(*currentGenParticleIter)); - m_barcode_large->Fill(HepMC::barcode(*currentGenParticleIter)); - int barcode = HepMC::barcode(*currentGenParticleIter); + m_barcode_small->Fill(HepMC::barcode(currentGenParticle)); + m_barcode_large->Fill(HepMC::barcode(currentGenParticle)); + int barcode = HepMC::barcode(currentGenParticle); m_log_barcode_large->Fill( barcode > 0 ? log(barcode) : -1); - m_particle_status->Fill((*currentGenParticleIter)->status()); + m_particle_status->Fill(currentGenParticle->status()); - int pdg = (*currentGenParticleIter)->pdg_id(); + int pdg = currentGenParticle->pdg_id(); int particleType = 100; switch ( abs(pdg) ) { case 22: @@ -275,13 +283,13 @@ StatusCode TruthTestTool::processEvent() particleType = (pdg<0) ? -particleType : particleType; m_particle_type->Fill( particleType ); - if ( HepMC::barcode(*currentGenParticleIter)<200000 ) { + if ( HepMC::barcode(currentGenParticle)<200000 ) { m_p_gen->Fill( mom.rho() ); m_log_p_gen->Fill( log(mom.rho()) ); m_eta_gen->Fill( mom.eta() ); m_phi_gen->Fill( mom.phi() ); ++npart_prim; - if ( HepMC::barcode(*currentGenParticleIter)<10000 ) { + if ( HepMC::barcode(currentGenParticle)<10000 ) { m_n_generations ->Fill(0); } else { @@ -290,7 +298,7 @@ StatusCode TruthTestTool::processEvent() } else { ++npart_sec; - const int gen = HepMC::barcode(*currentGenParticleIter)/ 1000000 +2; + const int gen = HepMC::barcode(currentGenParticle)/ 1000000 +2; m_n_generations ->Fill(gen); } }