diff --git a/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.cxx b/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.cxx index d1fb4dbc389630b7fe49c9e46b07db1fd702eb91..02a3746d867e555a0f866d651925fea67af67188 100644 --- a/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.cxx +++ b/Simulation/ISF/ISF_Core/ISF_Services/src/InputConverter.cxx @@ -154,7 +154,7 @@ ISF::InputConverter::convert(const McEventCollection& inputGenEvents, const auto passedGenParticles = getSelectedParticles(*eventPtr, legacyOrdering); for ( auto& genPartPtr : passedGenParticles ) { - ATH_MSG_VERBOSE("Picking up following GenParticle for conversion to ISFParticle: " << *genPartPtr); + ATH_MSG_VERBOSE("Picking up following GenParticle for conversion to ISFParticle: " << genPartPtr); auto simParticlePtr = convertParticle(genPartPtr, kindOfCollection); if (!simParticlePtr) { ATH_MSG_ERROR("Error while trying to convert input generator particles. Aborting."); @@ -227,50 +227,49 @@ ISF::InputConverter::getSelectedParticles(const HepMC::GenEvent& evnt, bool lega ISF::ISFParticle* ISF::InputConverter::convertParticle(HepMC::GenParticlePtr genPartPtr, EBC_EVCOLL kindOfCollection) const { if (!genPartPtr) { return nullptr; } - auto& genPart = *genPartPtr; - // @FIXME: set the bunch-crossing identifier for pile-up dynamically - // rather than a constant '1' (e.g. could use GenEvent index for that?) - const int bcid = (kindOfCollection==EBC_MAINEVCOLL) ? 0 : 1; - - HepMC::GenVertexPtr pVertex = genPart.production_vertex(); + auto pVertex = genPartPtr->production_vertex(); if (!pVertex) { - ATH_MSG_ERROR("Unable to convert following generator particle due to missing " - << "production vertex: " << genPart); + ATH_MSG_ERROR("Unable to convert following generator particle due to missing production vertex for: " << genPartPtr); + return nullptr; + } + auto parentEvent = genPartPtr->parent_event(); + if(!parentEvent) { + ATH_MSG_ERROR("Cannot convert a GenParticle without a parent GenEvent into an ISFParticle!!!"); return nullptr; } - const Amg::Vector3D pos(pVertex->position().x(), pVertex->position().y(), pVertex->position().z()); - const auto& pMomentum(genPart.momentum()); + const auto& pMomentum(genPartPtr->momentum()); const Amg::Vector3D mom(pMomentum.px(), pMomentum.py(), pMomentum.pz()); - const double pMass = this->getParticleMass(genPart); - +#ifdef HEPMC3 + const double pMass = this->getParticleMass(genPartPtr); +#else + const double pMass = this->getParticleMass(*genPartPtr); +#endif double e=pMomentum.e(); if(e>1) { //only test for >1 MeV in momentum double px=pMomentum.px(); double py=pMomentum.py(); double pz=pMomentum.pz(); - double teste=sqrt(px*px + py*py + pz*pz + pMass*pMass); - if(std::abs(e-teste)/e>0.01) { - ATH_MSG_WARNING("Difference in energy for: " << genPart<<" Morg="<<pMomentum.m()<<" Mmod="<<pMass<<" Eorg="<<e<<" Emod="<<teste); + double teste=std::sqrt(px*px + py*py + pz*pz + pMass*pMass); + if(std::abs(e-teste)>0.01*e) { + ATH_MSG_WARNING("Difference in energy for: " << genPartPtr<<" Morg="<<pMomentum.m()<<" Mmod="<<pMass<<" Eorg="<<e<<" Emod="<<teste); } } - const int pPdgId = genPart.pdg_id(); + const int pPdgId = genPartPtr->pdg_id(); const double charge = HepPDT::ParticleID(pPdgId).charge(); const double pTime = pVertex->position().t() / Gaudi::Units::c_light; /// particle origin (TODO: add proper GeoID, collision/cosmics) DetRegionSvcIDPair origin(AtlasDetDescr::fUndefinedAtlasRegion, ISF::fEventGeneratorSimID); - const auto pBarcode = HepMC::barcode(genPart); + const auto pBarcode = HepMC::barcode(genPartPtr); auto tBinding = std::make_unique<ISF::TruthBinding>(genPartPtr); + // @FIXME: set the bunch-crossing identifier for pile-up dynamically + // rather than a constant '1' (e.g. could use GenEvent index for that?) + const int bcid = (kindOfCollection==EBC_MAINEVCOLL) ? 0 : 1; - auto *parentEvent = genPart.parent_event(); - if(!parentEvent) { - ATH_MSG_ERROR("Cannot convert a GenParticle without a parent GenEvent into an ISFParticle!!!"); - return nullptr; - } - auto hmpl = std::make_unique<HepMcParticleLink>(&genPart, parentEvent->event_number(), kindOfCollection); + auto hmpl = std::make_unique<HepMcParticleLink>(genPartPtr, parentEvent->event_number(), kindOfCollection); auto sParticle = std::make_unique<ISF::ISFParticle>( std::move(pos), std::move(mom), pMass, @@ -540,7 +539,7 @@ G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(const ISF::ISFParti ATH_MSG_VERBOSE( "Detected primary particle with end vertex." ); ATH_MSG_VERBOSE( "Will add the primary particle set on." ); ATH_MSG_VERBOSE( "ISF Particle: " << isp ); - ATH_MSG_VERBOSE( "Primary Particle: " << *genpart ); + ATH_MSG_VERBOSE( "Primary Particle: " << genpart ); ATH_MSG_VERBOSE( "Number of daughters of "<<genpart->barcode()<<": " << genpart->end_vertex()->particles_out_size() ); } else { @@ -549,19 +548,22 @@ G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(const ISF::ISFParti ATH_MSG_WARNING( "yet validated - you'd better know what you're doing. Will add the primary" ); ATH_MSG_WARNING( "particle set on." ); ATH_MSG_WARNING( "ISF Particle: " << isp ); - ATH_MSG_WARNING( "Primary Particle: " << *genpart ); + ATH_MSG_WARNING( "Primary Particle: " << genpart ); ATH_MSG_WARNING( "Number of daughters of "<<genpart->barcode()<<": " << genpart->end_vertex()->particles_out_size() ); } // Add all necessary daughter particles - for ( auto daughterIter=genpart->end_vertex()->particles_out_const_begin(); - daughterIter!=genpart->end_vertex()->particles_out_const_end(); ++daughterIter ) { + for ( auto daughter: *(genpart->end_vertex())) { if(m_quasiStableParticlesIncluded) { - ATH_MSG_VERBOSE ( "Attempting to add daughter particle of "<<HepMC::barcode(genpart)<<": " << **daughterIter ); + ATH_MSG_VERBOSE ( "Attempting to add daughter particle of "<<HepMC::barcode(genpart)<<": " << daughter ); } else { - ATH_MSG_WARNING ( "Attempting to add daughter particle of "<<HepMC::barcode(genpart)<<": " << **daughterIter ); + ATH_MSG_WARNING ( "Attempting to add daughter particle of "<<HepMC::barcode(genpart)<<": " << daughter ); } - G4PrimaryParticle *daughterG4Particle = this->getG4PrimaryParticle( **daughterIter ); +#ifdef HEPMC3 + G4PrimaryParticle *daughterG4Particle = this->getG4PrimaryParticle( daughter ); +#else + G4PrimaryParticle *daughterG4Particle = this->getG4PrimaryParticle( *daughter ); +#endif if(!daughterG4Particle) { ATH_MSG_ERROR("Bailing out of loop over daughters of particle with barcode: "<<HepMC::barcode(genpart) << " due to errors - will not return G4Particle."); @@ -616,7 +618,7 @@ G4PrimaryParticle* ISF::InputConverter::getG4PrimaryParticle(const ISF::ISFParti } } - genpart->set_momentum(CLHEP::HepLorentzVector(px,py,pz,pe)); + genpart->set_momentum(HepMC::FourVector(px,py,pz,pe)); } // Truth was detected ATH_MSG_VERBOSE("PrimaryParticleInformation:"); diff --git a/Simulation/ISF/ISF_Core/ISF_Services/src/TruthSvc.cxx b/Simulation/ISF/ISF_Core/ISF_Services/src/TruthSvc.cxx index 5ae0ceca71c4b4cb42a7c03db70c66f167f1ed80..041a868249c8b940a2f8a52b0cc7b9ec47080668 100644 --- a/Simulation/ISF/ISF_Core/ISF_Services/src/TruthSvc.cxx +++ b/Simulation/ISF/ISF_Core/ISF_Services/src/TruthSvc.cxx @@ -500,11 +500,8 @@ void ISF::TruthSvc::setSharedChildParticleBarcode( ISF::ITruthIncident& ti) cons int ISF::TruthSvc::maxGeneratedParticleBarcode(HepMC::GenEvent *genEvent) const { int maxBarcode=0; const int firstSecondaryParticleBarcode(m_barcodeSvc->secondaryParticleBcOffset()); - HepMC::GenEvent::particle_const_iterator currentGenParticleIter; - for (currentGenParticleIter= genEvent->particles_begin(); - currentGenParticleIter!= genEvent->particles_end(); - ++currentGenParticleIter) { - const int barcode((*currentGenParticleIter)->barcode()); + for (auto currentGenParticle: *genEvent) { + const int barcode=HepMC::barcode(currentGenParticle); if(barcode > maxBarcode && barcode < firstSecondaryParticleBarcode) { maxBarcode=barcode; } } return maxBarcode; diff --git a/Simulation/ISF/ISF_Core/ISF_Services/test/InputConverter_test.cxx b/Simulation/ISF/ISF_Core/ISF_Services/test/InputConverter_test.cxx index 17813c67825ba28e507970a03bd22fb37ae5ef1d..a5323da69977a4e5773baaae2d83c2b6df30878f 100644 --- a/Simulation/ISF/ISF_Core/ISF_Services/test/InputConverter_test.cxx +++ b/Simulation/ISF/ISF_Core/ISF_Services/test/InputConverter_test.cxx @@ -39,6 +39,7 @@ // HepMC #include "AtlasHepMC/GenParticle.h" #include "AtlasHepMC/GenVertex.h" +#include "AtlasHepMC/Operators.h" #include "GeneratorObjects/HepMcParticleLink.h" #include "GeneratorObjects/McEventCollection.h" @@ -62,7 +63,11 @@ class MockFilterTool : public AthAlgTool, virtual ~MockFilterTool() {}; // mock method which will be called by tested code +#ifdef HEPMC3 + MOCK_CONST_METHOD1(pass, bool(HepMC::ConstGenParticlePtr)); +#else MOCK_CONST_METHOD1(pass, bool(const HepMC::GenParticle&)); +#endif }; DECLARE_COMPONENT( MockFilterTool ) @@ -165,7 +170,11 @@ TEST_F(InputConverter_test, convertParticle_without_production_vertex) { ); ISF::ISFParticle* expected = nullptr; ASSERT_EQ( expected, convertParticle(genPart, EBC_FIRSTPUEVCOLL) ); +#ifdef HEPMC3 + //When compiled with HepMC3, genPart is smart pointer +#else delete genPart; +#endif } @@ -177,16 +186,16 @@ TEST_F(InputConverter_test, convertParticle_using_generated_mass) { HepMC::FourVector mom(12.3, 45.6, 78.9, 0.12); // dynamic allocation necessary as particle ownership is // handed over to a HepMC::GenVertex later - HepMC::GenParticlePtr genPart = new HepMC::GenParticle(mom, + HepMC::GenParticlePtr genPart = HepMC::newGenParticlePtr(mom, 11, // pdg id (e-) 1 // status ); genPart->set_generated_mass(1234.56); - genPart->suggest_barcode(particleBarcode); + HepMC::suggest_barcode(genPart,particleBarcode); HepMC::FourVector pos(9.8, 7.65, 4.3, 0.321); // NB: 4th component is time*c int vtx_id = -123; - HepMC::GenVertexPtr prodVtx = new HepMC::GenVertex(pos, vtx_id); + HepMC::GenVertexPtr prodVtx = HepMC::newGenVertexPtr(pos, vtx_id); prodVtx->add_particle_out(genPart); // create dummy input McEventCollection containing a dummy GenEvent @@ -237,7 +246,7 @@ TEST_F(InputConverter_test, convertParticle_using_particleDataTable_photon) { 1 // status ); genPart->set_generated_mass(1234.56); // should be ignored later on - genPart->suggest_barcode(particleBarcode); + HepMC::suggest_barcode(genPart,particleBarcode); HepMC::FourVector pos(9.8, 7.65, 4.3, 0.321); // NB: 4th component is time*c int vtx_id = -123; @@ -291,7 +300,7 @@ TEST_F(InputConverter_test, convertParticle_using_particleDataTable_electron) { 1 // status ); genPart->set_generated_mass(1234.56); // should be ignored later on - genPart->suggest_barcode(particleBarcode); + HepMC::suggest_barcode(genPart,particleBarcode); HepMC::FourVector pos(9.8, 7.65, 4.3, 0.321); // NB: 4th component is time*c int vtx_id = -123; @@ -337,7 +346,11 @@ TEST_F(InputConverter_test, convertParticle_using_particleDataTable_electron) { TEST_F(InputConverter_test, passesFilters_empty_filters_defaultconstructed_genpart) { ASSERT_TRUE( m_svc->initialize().isSuccess() ); +#ifdef HEPMC3 + auto genPart=HepMC::newGenParticlePtr(); +#else const HepMC::GenParticle genPart{}; +#endif ASSERT_TRUE( passesFilters(genPart) ); } @@ -347,15 +360,24 @@ TEST_F(InputConverter_test, passesFilters_empty_filters) { const int particleBarcode(546); HepMC::FourVector mom(12.3, 45.6, 78.9, 0.12); +#ifdef HEPMC3 + //It seems this test makes no sense for HepMC3 + HepMC::GenParticlePtr genPart=HepMC::newGenParticlePtr(mom, + 11, // pdg id (e-) + 1 // status + ); + ASSERT_TRUE( true ); +#else HepMC::GenParticle genPart(mom, 11, // pdg id (e-) 1 // status ); genPart.set_generated_mass(1234.56); - genPart.suggest_barcode(particleBarcode); + HepMC::suggest_barcode( genPart,particleBarcode); const HepMC::GenParticle constGenPart(std::move(genPart)); ASSERT_TRUE( passesFilters(constGenPart) ); +#endif } @@ -368,7 +390,11 @@ TEST_F(InputConverter_test, passesFilters_one_pass_filter) { ASSERT_EQ (genParticleFilters.size(), expectedSize); MockFilterTool* filterTool = dynamic_cast<MockFilterTool*>(&*(genParticleFilters[0])); ASSERT_TRUE( filterTool ); +#ifdef HEPMC3 + HepMC::ConstGenParticlePtr genPart{}; +#else const HepMC::GenParticle genPart{}; +#endif HepMC::FourVector mom(12.3, 45.6, 78.9, 0.12); HepMC::GenParticle genPart2(mom, 11, // pdg id (e-) @@ -392,7 +418,11 @@ TEST_F(InputConverter_test, passesFilters_one_nonpass_filter) { MockFilterTool* filterTool = dynamic_cast<MockFilterTool*>(&*(genParticleFilters[0])); ASSERT_TRUE( filterTool ); +#ifdef HEPMC3 + HepMC::ConstGenParticlePtr genPart{}; +#else const HepMC::GenParticle genPart{}; +#endif HepMC::FourVector mom(12.3, 45.6, 78.9, 0.12); HepMC::GenParticle genPart2(mom, 11, // pdg id (e-) @@ -418,7 +448,11 @@ TEST_F(InputConverter_test, passesFilters_two_filters) { MockFilterTool* filterTool2 = dynamic_cast<MockFilterTool*>(&*(genParticleFilters[1])); ASSERT_TRUE( filterTool2 ); +#ifdef HEPMC3 + HepMC::ConstGenParticlePtr genPart{}; +#else const HepMC::GenParticle genPart{}; +#endif HepMC::FourVector mom(12.3, 45.6, 78.9, 0.12); HepMC::GenParticle genPart2(mom, 11, // pdg id (e-) diff --git a/Simulation/ISF/ISF_Core/ISF_Services/test/TruthSvc_test.cxx b/Simulation/ISF/ISF_Core/ISF_Services/test/TruthSvc_test.cxx index d84da3d267a51187176bfb48ca71c8c40dd9d843..f3d593c8f8dfd7b1d935265dd8db399ef5d8b76c 100644 --- a/Simulation/ISF/ISF_Core/ISF_Services/test/TruthSvc_test.cxx +++ b/Simulation/ISF/ISF_Core/ISF_Services/test/TruthSvc_test.cxx @@ -272,9 +272,11 @@ namespace ISFTesting { const int event_number1(17); const int pdgid1(-13); const int pdgid2(13); - std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1); + std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(); + anEvent->set_event_number(event_number1); + HepMC::set_signal_process_id(anEvent.get(),process_id1); const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0); - HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( myPos, -1 ); + HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( HepMC::FourVector(myPos.x(),myPos.y(),myPos.z(),myPos.t()), -1 ); const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV); HepMC::GenParticlePtr inParticle1 = HepMC::newGenParticlePtr(fourMomentum1, pdgid1, 2); myVertex->add_particle_in(inParticle1); @@ -288,7 +290,7 @@ namespace ISFTesting { HepMC::GenParticlePtr inParticle4 = HepMC::newGenParticlePtr(fourMomentum4, pdgid2, 1); myVertex->add_particle_out(inParticle4); anEvent->add_vertex( myVertex ); - anEvent->set_signal_process_vertex( myVertex ); + HepMC::set_signal_process_vertex(anEvent.get(), myVertex ); anEvent->set_beam_particles(inParticle1,inParticle2); MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2); @@ -298,7 +300,7 @@ namespace ISFTesting { .WillOnce(::testing::Return(21)); EXPECT_CALL(ti, parentBarcode()) .Times(1) - .WillOnce(::testing::Return(inParticle3->barcode())); + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))); EXPECT_CALL(ti, parentParticle()) .Times(1) .WillOnce(::testing::Return(inParticle3)); @@ -306,10 +308,16 @@ namespace ISFTesting { ASSERT_EQ( vtxPosition, generated->position() ); ASSERT_EQ( 1021, generated->id() ); - ASSERT_EQ( -200001, generated->barcode() ); + ASSERT_EQ( -200001, HepMC::barcode(generated) ); +#ifdef HEPMC3 + ASSERT_EQ( 1, generated->particles_in().size()); + ASSERT_EQ( 0, generated->particles_out().size()); + ASSERT_EQ( inParticle3, *(generated->particles_in().cbegin())); +#else ASSERT_EQ( 1, generated->particles_in_size()); ASSERT_EQ( 0, generated->particles_out_size()); ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin())); +#endif } @@ -320,9 +328,11 @@ namespace ISFTesting { const int event_number1(17); const int pdgid1(-13); const int pdgid2(13); - std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1); + std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(); + anEvent->set_event_number(event_number1); + HepMC::set_signal_process_id(anEvent.get(),process_id1); const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0); - HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( myPos, -1 ); + HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( HepMC::FourVector(myPos.x(),myPos.y(),myPos.z(),myPos.t()), -1 ); const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV); HepMC::GenParticlePtr inParticle1 = HepMC::newGenParticlePtr(fourMomentum1, pdgid1, 2); myVertex->add_particle_in(inParticle1); @@ -336,7 +346,7 @@ namespace ISFTesting { HepMC::GenParticlePtr inParticle4 = HepMC::newGenParticlePtr(fourMomentum4, pdgid2, 1); myVertex->add_particle_out(inParticle4); anEvent->add_vertex( myVertex ); - anEvent->set_signal_process_vertex( myVertex ); + HepMC::set_signal_process_vertex(anEvent.get(), myVertex ); anEvent->set_beam_particles(inParticle1,inParticle2); MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2); @@ -347,8 +357,8 @@ namespace ISFTesting { .WillOnce(::testing::Return(21)); EXPECT_CALL(ti, parentBarcode()) .Times(2) - .WillOnce(::testing::Return(inParticle3->barcode())) - .WillOnce(::testing::Return(inParticle3->barcode())); + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))) + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))); EXPECT_CALL(ti, parentParticle()) .Times(2) .WillOnce(::testing::Return(inParticle3)) @@ -358,13 +368,19 @@ namespace ISFTesting { .WillOnce(::testing::Return(nullptr)); recordIncidentToMCTruth(ti); - HepMC::GenVertexPtr generated = anEvent->barcode_to_vertex(-200001); //Find a nicer way to get this. + HepMC::GenVertexPtr generated = HepMC::barcode_to_vertex(anEvent.get(),-200001); //Find a nicer way to get this. ASSERT_EQ( vtxPosition, generated->position() ); ASSERT_EQ( 1021, generated->id() ); - ASSERT_EQ( -200001, generated->barcode() ); // by construction at the moment + ASSERT_EQ( -200001, HepMC::barcode(generated) ); // by construction at the moment +#ifdef HEPMC3 + ASSERT_EQ( 1, generated->particles_in().size()); + ASSERT_EQ( 0, generated->particles_out().size()); + ASSERT_EQ( inParticle3, *(generated->particles_in().cbegin())); +#else ASSERT_EQ( 1, generated->particles_in_size()); ASSERT_EQ( 0, generated->particles_out_size()); ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin())); +#endif } @@ -375,9 +391,11 @@ namespace ISFTesting { const int event_number1(17); const int pdgid1(-13); const int pdgid2(13); - std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1); + std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(); + anEvent->set_event_number(event_number1); + HepMC::set_signal_process_id(anEvent.get(),process_id1); const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0); - HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( myPos, -1 ); + HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( HepMC::FourVector(myPos.x(),myPos.y(),myPos.z(),myPos.t()), -1 ); const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV); HepMC::GenParticlePtr inParticle1 = HepMC::newGenParticlePtr(fourMomentum1, pdgid1, 2); myVertex->add_particle_in(inParticle1); @@ -391,7 +409,7 @@ namespace ISFTesting { HepMC::GenParticlePtr inParticle4 = HepMC::newGenParticlePtr(fourMomentum4, pdgid2, 1); myVertex->add_particle_out(inParticle4); anEvent->add_vertex( myVertex ); - anEvent->set_signal_process_vertex( myVertex ); + HepMC::set_signal_process_vertex(anEvent.get(), myVertex ); anEvent->set_beam_particles(inParticle1,inParticle2); MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2); @@ -400,11 +418,11 @@ namespace ISFTesting { .WillOnce(::testing::Return(21)); EXPECT_CALL(ti, parentBarcode()) .Times(2) - .WillOnce(::testing::Return(inParticle3->barcode())) - .WillOnce(::testing::Return(inParticle3->barcode())); + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))) + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))); registerTruthIncident(ti); - HepMC::GenVertexPtr generated = anEvent->barcode_to_vertex(-200001); //Find a nicer way to get this. + HepMC::GenVertexPtr generated = HepMC::barcode_to_vertex(anEvent.get(),-200001); //Find a nicer way to get this. HepMC::GenVertexPtr expectedVtx(nullptr); ASSERT_EQ( expectedVtx, generated); } @@ -419,9 +437,11 @@ namespace ISFTesting { const int event_number1(17); const int pdgid1(-13); const int pdgid2(13); - std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1); + std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(); + anEvent->set_event_number(event_number1); + HepMC::set_signal_process_id(anEvent.get(),process_id1); const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0); - HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( myPos, -1 ); + HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( HepMC::FourVector(myPos.x(),myPos.y(),myPos.z(),myPos.t()), -1 ); const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV); HepMC::GenParticlePtr inParticle1 = HepMC::newGenParticlePtr(fourMomentum1, pdgid1, 2); myVertex->add_particle_in(inParticle1); @@ -435,7 +455,7 @@ namespace ISFTesting { HepMC::GenParticlePtr inParticle4 = HepMC::newGenParticlePtr(fourMomentum4, pdgid2, 1); myVertex->add_particle_out(inParticle4); anEvent->add_vertex( myVertex ); - anEvent->set_signal_process_vertex( myVertex ); + HepMC::set_signal_process_vertex(anEvent.get(), myVertex ); anEvent->set_beam_particles(inParticle1,inParticle2); MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2); @@ -446,21 +466,27 @@ namespace ISFTesting { .WillOnce(::testing::Return(21)); EXPECT_CALL(ti, parentBarcode()) .Times(3) - .WillOnce(::testing::Return(inParticle3->barcode())) - .WillOnce(::testing::Return(inParticle3->barcode())) - .WillOnce(::testing::Return(inParticle3->barcode())); + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))) + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))) + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))); EXPECT_CALL(ti, parentParticle()) .Times(1) .WillOnce(::testing::Return(inParticle3)); registerTruthIncident(ti); - HepMC::GenVertexPtr generated = anEvent->barcode_to_vertex(-200001); //Find a nicer way to get this. + HepMC::GenVertexPtr generated = HepMC::barcode_to_vertex(anEvent.get(),-200001); //Find a nicer way to get this. ASSERT_EQ( vtxPosition, generated->position() ); ASSERT_EQ( 1021, generated->id() ); - ASSERT_EQ( -200001, generated->barcode() ); // by construction at the moment + ASSERT_EQ( -200001, HepMC::barcode(generated) ); // by construction at the moment +#ifdef HEPMC3 + ASSERT_EQ( 1, generated->particles_in().size()); + ASSERT_EQ( 0, generated->particles_out().size()); + ASSERT_EQ( inParticle3, *(generated->particles_in().cbegin())); +#else ASSERT_EQ( 1, generated->particles_in_size()); ASSERT_EQ( 0, generated->particles_out_size()); ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin())); +#endif } @@ -482,9 +508,11 @@ namespace ISFTesting { const int event_number1(17); const int pdgid1(-13); const int pdgid2(13); - std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1); + std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(); + anEvent->set_event_number(event_number1); + HepMC::set_signal_process_id(anEvent.get(),process_id1); const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0); - HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( myPos, -1 ); + HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( HepMC::FourVector(myPos.x(),myPos.y(),myPos.z(),myPos.t()), -1 ); const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV); HepMC::GenParticlePtr inParticle1 = HepMC::newGenParticlePtr(fourMomentum1, pdgid1, 2); myVertex->add_particle_in(inParticle1); @@ -498,7 +526,7 @@ namespace ISFTesting { HepMC::GenParticlePtr inParticle4 = HepMC::newGenParticlePtr(fourMomentum4, pdgid2, 1); myVertex->add_particle_out(inParticle4); anEvent->add_vertex( myVertex ); - anEvent->set_signal_process_vertex( myVertex ); + HepMC::set_signal_process_vertex(anEvent.get(), myVertex ); anEvent->set_beam_particles(inParticle1,inParticle2); @@ -510,9 +538,9 @@ namespace ISFTesting { .WillOnce(::testing::Return(21)); EXPECT_CALL(ti, parentBarcode()) .Times(3) - .WillOnce(::testing::Return(inParticle3->barcode())) - .WillOnce(::testing::Return(inParticle3->barcode())) - .WillOnce(::testing::Return(inParticle3->barcode())); + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))) + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))) + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))); EXPECT_CALL(ti, parentParticle()) .Times(1) .WillOnce(::testing::Return(inParticle3)); @@ -524,13 +552,19 @@ namespace ISFTesting { .WillOnce(::testing::Return(false)); registerTruthIncident(ti); - HepMC::GenVertexPtr generated = anEvent->barcode_to_vertex(-200001); //Find a nicer way to get this. + HepMC::GenVertexPtr generated = HepMC::barcode_to_vertex(anEvent.get(),-200001); //Find a nicer way to get this. ASSERT_EQ( vtxPosition, generated->position() ); ASSERT_EQ( 1021, generated->id() ); - ASSERT_EQ( -200001, generated->barcode() ); // by construction at the moment + ASSERT_EQ( -200001, HepMC::barcode(generated) ); // by construction at the moment +#ifdef HEPMC3 + ASSERT_EQ( 1, generated->particles_in().size()); + ASSERT_EQ( 0, generated->particles_out().size()); + ASSERT_EQ( inParticle3, *(generated->particles_in().cbegin())); +#else ASSERT_EQ( 1, generated->particles_in_size()); ASSERT_EQ( 0, generated->particles_out_size()); ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin())); +#endif } @@ -549,9 +583,11 @@ namespace ISFTesting { const int event_number1(17); const int pdgid1(-13); const int pdgid2(13); - std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1); + std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(); + anEvent->set_event_number(event_number1); + HepMC::set_signal_process_id(anEvent.get(),process_id1); const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0); - HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( myPos, -1 ); + HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( HepMC::FourVector(myPos.x(),myPos.y(),myPos.z(),myPos.t()), -1 ); const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV); HepMC::GenParticlePtr inParticle1 = HepMC::newGenParticlePtr(fourMomentum1, pdgid1, 2); myVertex->add_particle_in(inParticle1); @@ -565,10 +601,10 @@ namespace ISFTesting { HepMC::GenParticlePtr inParticle4 = HepMC::newGenParticlePtr(fourMomentum4, pdgid2, 1); myVertex->add_particle_out(inParticle4); anEvent->add_vertex( myVertex ); - anEvent->set_signal_process_vertex( myVertex ); + HepMC::set_signal_process_vertex(anEvent.get(), myVertex ); anEvent->set_beam_particles(inParticle1,inParticle2); HepMC::GenParticlePtr inParticle5 = HepMC::newGenParticlePtr(fourMomentum3, pdgid1, 1); - inParticle5->suggest_barcode(1010003); + HepMC::suggest_barcode(inParticle5,1010003); inParticle5->set_status(1); MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2); @@ -579,9 +615,9 @@ namespace ISFTesting { .WillOnce(::testing::Return(21)); EXPECT_CALL(ti, parentBarcode()) .Times(3) - .WillOnce(::testing::Return(inParticle3->barcode())) - .WillOnce(::testing::Return(inParticle3->barcode())) - .WillOnce(::testing::Return(inParticle3->barcode())); + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))) + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))) + .WillOnce(::testing::Return(HepMC::barcode(inParticle3))); EXPECT_CALL(ti, parentParticle()) .Times(2) .WillOnce(::testing::Return(inParticle3)) @@ -597,14 +633,21 @@ namespace ISFTesting { .WillOnce(::testing::Return(true)); registerTruthIncident(ti); - HepMC::GenVertexPtr generated = anEvent->barcode_to_vertex(-200001); //Find a nicer way to get this. + HepMC::GenVertexPtr generated = HepMC::barcode_to_vertex(anEvent.get(),-200001); //Find a nicer way to get this. ASSERT_EQ( vtxPosition, generated->position() ); ASSERT_EQ( 1021, generated->id() ); - ASSERT_EQ( -200001, generated->barcode() ); // by construction at the moment + ASSERT_EQ( -200001, HepMC::barcode(generated) ); // by construction at the moment +#ifdef HEPMC3 + ASSERT_EQ( 1, generated->particles_in().size()); + ASSERT_EQ( inParticle3, *(generated->particles_in().cbegin())); + ASSERT_EQ( 1, generated->particles_out().size()); + ASSERT_EQ( inParticle5, *(generated->particles_out().cbegin())); +#else ASSERT_EQ( 1, generated->particles_in_size()); ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin())); ASSERT_EQ( 1, generated->particles_out_size()); ASSERT_EQ( inParticle5, *(generated->particles_out_const_begin())); +#endif } //TODO Add tests for the following cases: