Skip to content
Snippets Groups Projects
Commit 815b3041 authored by Olivier Arnaez's avatar Olivier Arnaez Committed by John Chapman
Browse files

Migrating the TrackParticleTruth TP Converters to use the new HepMcParticleLink

Update `TrackParticleTruthAthenaPool` to write out the new
`TrackParticleTruthCollection_p2` and `TrackParticleTruthCollectionContainer_p2`
classes which use `HepMcParticleLink_p2` by default.
(cherry picked from commit aa3286c2a93ac47d342d30131581dc15970e1f27)

Add unit tests the for new TP Converters
(cherry picked from commit 4d3cc18027874d378522730b6e941ced8e8eba5a)

Update the new unit tests to use valid `HepMcParticleLinks`.
parent b710e859
No related branches found
No related tags found
No related merge requests found
Showing
with 125 additions and 13 deletions
......@@ -33,9 +33,9 @@ TrackParticleTruthCollectionCnv::TrackParticleTruthCollectionCnv(ISvcLocator* sv
//================================================================
TrackParticleTruthCollectionPERS* TrackParticleTruthCollectionCnv::createPersistent(TrackParticleTruthCollection* trans) {
MsgStream log(msgSvc(), "TrackParticleTruthCollectionCnv");
log<<MSG::DEBUG<<"Writing TrackParticleTruthCollection_p1"<<endmsg;
log<<MSG::DEBUG<<"Writing TrackParticleTruthCollection_p2"<<endmsg;
TrackParticleTruthCollectionPERS* pers=new TrackParticleTruthCollectionPERS();
m_converter_p1.transToPers(trans,pers,log);
m_converter_p2.transToPers(trans,pers,log);
return pers;
}
......
......@@ -13,9 +13,9 @@
#include "TrackParticleTruthTPCnv/TrackParticleTruthCollectionCnv_p1.h"
#include "TrackParticleTruthTPCnv/TrackParticleTruthCollectionCnv_p0.h"
namespace Trk { class TrackParticleTruthCollection_p1; }
namespace Trk { class TrackParticleTruthCollection_p2; }
typedef Rec::TrackParticleTruthCollection_p1 TrackParticleTruthCollectionPERS;
typedef Rec::TrackParticleTruthCollection_p2 TrackParticleTruthCollectionPERS;
typedef T_AthenaPoolCustomCnv<TrackParticleTruthCollection, TrackParticleTruthCollectionPERS> TrackParticleTruthCollectionCnvBase;
......
......@@ -28,9 +28,9 @@ TrackParticleTruthCollectionContainerCnv::~TrackParticleTruthCollectionContainer
TrackParticleTruthCollectionContainerPERS* TrackParticleTruthCollectionContainerCnv::createPersistent(TrackParticleTruthCollectionContainer* trans) {
MsgStream log(msgSvc(), "TrackParticleTruthCollectionContainerCnv");
log<<MSG::DEBUG<<"Writing TrackParticleTruthCollectionContainer_tlp1"<<endmsg;
log<<MSG::DEBUG<<"Writing TrackParticleTruthCollectionContainer_tlp2"<<endmsg;
TrackParticleTruthCollectionContainerPERS* p_cont = m_converter_p1->createPersistent( trans, log );
TrackParticleTruthCollectionContainerPERS* p_cont = m_converter_p2->createPersistent( trans, log );
return p_cont;
}
......
......@@ -15,9 +15,9 @@
#include "ParticleTruth/TrackParticleTruthCollectionContainer.h"
#include "ParticleTruth/TrackParticleTruthVector.h"
class TrackParticleTruthCollectionContainer_tlp1;
class TrackParticleTruthCollectionContainer_tlp2;
typedef TrackParticleTruthCollectionContainer_tlp1 TrackParticleTruthCollectionContainerPERS;
typedef TrackParticleTruthCollectionContainer_tlp2 TrackParticleTruthCollectionContainerPERS;
typedef T_AthenaPoolCustomCnv<TrackParticleTruthCollectionContainer, TrackParticleTruthCollectionContainerPERS> TrackParticleTruthCollectionContainerCnvBase;
......
......@@ -43,3 +43,9 @@ atlas_add_test( TrackParticleTruthCollectionCnv_p1_test
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} AthContainers AthLinks DataModelAthenaPoolLib AthenaPoolCnvSvcLib AthenaPoolUtilities GeneratorObjectsTPCnv Particle ParticleTruth TestTools AthenaKernel SGTools StoreGateLib SGtests TrackParticleTruthTPCnv )
atlas_add_test( TrackParticleTruthCollectionCnv_p2_test
SOURCES
test/TrackParticleTruthCollectionCnv_p2_test.cxx
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} AthContainers AthLinks DataModelAthenaPoolLib AthenaPoolCnvSvcLib AthenaPoolUtilities GeneratorObjectsTPCnv Particle ParticleTruth TestTools AthenaKernel SGTools StoreGateLib SGtests TrackParticleTruthTPCnv )
ApplicationMgr SUCCESS
====================================================================================================================================
Welcome to ApplicationMgr (GaudiCoreSvc v4r1)
running on lxplus055.cern.ch on Sat Feb 17 16:55:20 2018
====================================================================================================================================
ApplicationMgr INFO Application Manager Configured successfully
EventLoopMgr WARNING Unable to locate service "EventSelector"
EventLoopMgr WARNING No events will be processed from external input.
HistogramPersis...WARNING Histograms saving not required.
ApplicationMgr INFO Application Manager Initialized successfully
ApplicationMgr Ready
test1
HepMcParticleLink INFO find_hostkey: Using TruthEvent as McEventCollection key for this job
......@@ -26,19 +26,19 @@
DECLARE_TPCNV_FACTORY(TrackParticleTruthCollectionContainerCnv_tlp1,
DataVector<TrackParticleTruthCollection>,
TrackParticleTruthCollectionContainer_tlp1,
Athena::TPCnvVers::Current)
Athena::TPCnvVers::Old)
DECLARE_TPCNV_FACTORY(TrackParticleTruthCollectionContainerCnv_tlp2,
DataVector<TrackParticleTruthCollection>,
TrackParticleTruthCollectionContainer_tlp2,
Athena::TPCnvVers::Old)
Athena::TPCnvVers::Current)
DECLARE_TPCNV_FACTORY(TrackParticleTruthCollectionCnv_p1,
TrackParticleTruthCollection,
Rec::TrackParticleTruthCollection_p1,
Athena::TPCnvVers::Current)
Athena::TPCnvVers::Old)
DECLARE_TPCNV_FACTORY(TrackParticleTruthCollectionCnv_p2,
TrackParticleTruthCollection,
Rec::TrackParticleTruthCollection_p2,
Athena::TPCnvVers::Old)
Athena::TPCnvVers::Current)
......@@ -77,7 +77,7 @@ void test1(std::vector<HepMC::GenParticle*> genPartVector)
TrackParticleTruthCollection trans1 (DataLink<Rec::TrackParticleContainer>("tpc"));
for (int i=0; i<10; i++) {
const HepMC::GenParticle* pGenParticle = genPartVector.at(i);
HepMcParticleLink trkLink(pGenParticle->barcode());
HepMcParticleLink trkLink(pGenParticle->barcode(),pGenParticle->parent_event()->event_number());
Rec::TrackParticleTruthKey key (ElementLink<Rec::TrackParticleContainer> ("tpc", i));
TrackParticleTruth val (trkLink, (float)i/10);
trans1[key] = val;
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
// $Id$
/**
* @file InDetSimEventTPCnv/test/TrackParticleTruthCollectionCnv_p2_test.cxx
* @author scott snyder <snyder@bnl.gov>
* @date Feb, 2016
* @brief Tests for TrackParticleTruthCollectionCnv_p2.
*/
#undef NDEBUG
#include "TrackParticleTruthTPCnv/TrackParticleTruthCollectionCnv_p2.h"
#include "TrackParticleTruthTPCnv/TrackParticleTruthCollection_p2.h"
#include "ParticleTruth/TrackParticleTruthCollection.h"
#include "SGTools/TestStore.h"
#include "GeneratorObjectsTPCnv/initMcEventCollection.h"
#include "HepMC/GenEvent.h"
#include "HepMC/GenParticle.h"
#include <cassert>
#include <iostream>
void compare (const HepMcParticleLink& p1,
const HepMcParticleLink& p2)
{
assert ( p1.isValid() == p2.isValid() );
assert ( p1.barcode() == p2.barcode() );
assert ( p1.eventIndex() == p2.eventIndex() );
assert ( p1.cptr() == p2.cptr() );
assert ( p1 == p2 );
}
void compare (const TrackParticleTruthCollection& p1,
const TrackParticleTruthCollection& p2)
{
assert (p1.trackParticleContainerLink() == p2.trackParticleContainerLink());
assert (p1.size() == p2.size());
TrackParticleTruthCollection::const_iterator i1 = p1.begin();
TrackParticleTruthCollection::const_iterator i2 = p2.begin();
for (; i1 != p1.end(); ++i1, ++i2) {
assert (i1->first.link() == i2->first.link());
compare (i1->second.particleLink(), i2->second.particleLink());
assert (i1->second.particleLink() == i2->second.particleLink());
assert (i1->second.probability() == i2->second.probability());
}
}
void testit (const TrackParticleTruthCollection& trans1)
{
MsgStream log (0, "test");
TrackParticleTruthCollectionCnv_p2 cnv;
Rec::TrackParticleTruthCollection_p2 pers;
cnv.transToPers (&trans1, &pers, log);
TrackParticleTruthCollection trans2;
cnv.persToTrans (&pers, &trans2, log);
compare (trans1, trans2);
}
void test1(std::vector<HepMC::GenParticle*> genPartVector)
{
std::cout << "test1\n";
TrackParticleTruthCollection trans1 (DataLink<Rec::TrackParticleContainer>("tpc"));
for (int i=0; i<10; i++) {
const HepMC::GenParticle* pGenParticle = genPartVector.at(i);
HepMcParticleLink trkLink(pGenParticle->barcode(),pGenParticle->parent_event()->event_number());
Rec::TrackParticleTruthKey key (ElementLink<Rec::TrackParticleContainer> ("tpc", i));
TrackParticleTruth val (trkLink, (float)i/10);
trans1[key] = val;
}
testit (trans1);
}
int main()
{
ISvcLocator* pSvcLoc = nullptr;
std::vector<HepMC::GenParticle*> genPartVector;
if (!Athena_test::initMcEventCollection(pSvcLoc,genPartVector)) {
std::cerr << "This test can not be run" << std::endl;
return 0;
}
test1(genPartVector);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment