diff --git a/Simulation/Tools/McEventCollectionFilter/src/McEventCollectionFilter.cxx b/Simulation/Tools/McEventCollectionFilter/src/McEventCollectionFilter.cxx index 0f100552ce32e55b6557bf30862dfdf82a6f7ce0..0a6c9a1f712101a60a4c8446f66edcaf48ba89df 100644 --- a/Simulation/Tools/McEventCollectionFilter/src/McEventCollectionFilter.cxx +++ b/Simulation/Tools/McEventCollectionFilter/src/McEventCollectionFilter.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ ////////////////////////////////////////////////////////////////////////// @@ -176,12 +176,12 @@ StatusCode McEventCollectionFilter::ReduceMCEventCollection(){ if (!m_outputTruthCollection.isValid()) m_outputTruthCollection = std::make_unique<McEventCollection>(); //.......Create new particle (geantino) to link hits from pileup - HepMC::GenParticle* genPart=new HepMC::GenParticle(); + HepMC::GenParticlePtr genPart=HepMC::newGenParticlePtr(); genPart->set_pdg_id(m_PileupPartPDGID); //Geantino genPart->set_status(1); //!< set decay status - genPart->suggest_barcode( std::numeric_limits<int32_t>::max() ); + HepMC::suggest_barcode(genPart, std::numeric_limits<int32_t>::max() ); - HepMC::GenVertex* genVertex=new HepMC::GenVertex(); + HepMC::GenVertexPtr genVertex = HepMC::newGenVertexPtr(); genVertex->add_particle_out(genPart); const HepMC::GenEvent* genEvt = *(m_inputTruthCollection->begin()); @@ -191,7 +191,7 @@ StatusCode McEventCollectionFilter::ReduceMCEventCollection(){ //to set geantino vertex as a truth primary vertex - HepMC::GenVertex* hScatVx = genEvt->barcode_to_vertex(-3); + HepMC::GenVertexPtr hScatVx = genEvt->barcode_to_vertex(-3); if(hScatVx!=nullptr) { HepMC::FourVector pmvxpos=hScatVx->position(); genVertex->set_position(pmvxpos); @@ -211,33 +211,29 @@ StatusCode McEventCollectionFilter::ReduceMCEventCollection(){ } if(!evt->vertices_empty()){ - std::vector<HepMC::GenVertex *> vtxvec; HepMC::GenEvent::vertex_iterator itvtx = evt->vertices_begin(); for (;itvtx != evt ->vertices_end(); ++itvtx ) { - evt->remove_vertex(*itvtx); - vtxvec.push_back((*itvtx)); - //fix me: delete vertex pointer causes crash - //delete (*itvtx); + HepMC::GenVertexPtr vtx = *itvtx++; + evt->remove_vertex(vtx); + delete vtx; } - for(unsigned int i=0;i<vtxvec.size();i++) delete vtxvec[i]; } //-------------------------------------- if(m_IsKeepTRTElect){ for(int i=0;i<(int) m_elecBarcode.size();i++){ - HepMC::GenParticle* thePart=genEvt->barcode_to_particle(m_elecBarcode[i]); + HepMC::GenParticlePtr thePart=genEvt->barcode_to_particle(m_elecBarcode[i]); if (!thePart){ ATH_MSG_DEBUG( "Could not find particle for barcode " << m_elecBarcode[i] ); continue; } - const HepMC::GenVertex* vx = thePart->production_vertex(); - HepMC::GenParticle* thePart_new=new HepMC::GenParticle( thePart->momentum(),thePart->pdg_id(), - thePart->status(),thePart->flow(), - thePart->polarization() ); - thePart_new->suggest_barcode(m_elecBarcode[i]); + HepMC::ConstGenVertexPtr vx = thePart->production_vertex(); + HepMC::GenParticlePtr thePart_new = HepMC::newGenParticlePtr( thePart->momentum(),thePart->pdg_id(), + thePart->status()); + HepMC::suggest_barcode(thePart_new, m_elecBarcode[i]); HepMC::FourVector pos= vx->position(); - HepMC::GenVertex* vx_new=new HepMC::GenVertex(pos); + HepMC::GenVertexPtr vx_new = HepMC::newGenVertexPtr(pos); vx_new->add_particle_out(thePart_new); evt->add_vertex(vx_new); } @@ -245,7 +241,7 @@ StatusCode McEventCollectionFilter::ReduceMCEventCollection(){ //.....add new vertex with geantino evt->add_vertex(genVertex); - m_RefBarcode=genPart->barcode(); + m_RefBarcode=HepMC::barcode(*genPart); m_outputTruthCollection->push_back(evt);