Skip to content
Snippets Groups Projects
Commit 6ba4f2d7 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'hepmc3_nightly_fixes_15122020_part_1' into 'master'

HepMC3 nightly branch fixes 15120202 part 1

See merge request atlas/athena!39199
parents 484a8a2a 8b88f70d
No related branches found
No related tags found
No related merge requests found
......@@ -59,61 +59,61 @@ StatusCode Trk::InDetPrimaryConversionSelector::finalize() {
return StatusCode::SUCCESS;
}
std::vector<const HepMC::GenParticle*>*
std::vector<HepMC::ConstGenParticlePtr>*
Trk::InDetPrimaryConversionSelector::selectGenSignal (const McEventCollection* SimTracks) const {
if (! SimTracks) return NULL;
std::vector<const HepMC::GenParticle *>* genSignal =
new std::vector<const HepMC::GenParticle *>;
std::vector<HepMC::ConstGenParticlePtr>* genSignal =
new std::vector<HepMC::ConstGenParticlePtr>;
// pile-up: vector of MCEC has more than one entry
DataVector<HepMC::GenEvent>::const_iterator itCollision = SimTracks->begin();
for( ; itCollision != SimTracks->end(); ++itCollision ) {
const HepMC::GenEvent* genEvent = *itCollision;
HepMC::GenParticle * particle = NULL;
for (HepMC::GenEvent::particle_const_iterator it = genEvent->particles_begin();
it != genEvent->particles_end(); ++it) {
particle = *it;
for (auto particle: *genEvent) {
// 1) require stable particle from generation or simulation
if ((particle->status()%1000) != 1 ) continue;
if(particle->production_vertex() == NULL) {
if(!particle->production_vertex()) {
ATH_MSG_WARNING ("GenParticle without production vertex - simulation corrupt? ");
ATH_MSG_DEBUG ("It's this one: " << *particle);
ATH_MSG_DEBUG ("It's this one: " << particle);
continue;
} else {
// 2) require track inside ID - relaxed definition including decays of neutrals (secondaries)
if ( fabs(particle->production_vertex()->position().perp()) > m_maxRStartAll ||
fabs(particle->production_vertex()->position().z()) > m_maxZStartAll ) continue;
if ( std::fabs(particle->production_vertex()->position().perp()) > m_maxRStartAll ||
std::fabs(particle->production_vertex()->position().z()) > m_maxZStartAll ) continue;
int pdgCode = particle->pdg_id();
if (abs(pdgCode) > 1000000000 ) continue; // ignore nuclei from hadronic interactions
if (std::abs(pdgCode) > 1000000000 ) continue; // ignore nuclei from hadronic interactions
const HepPDT::ParticleData* pd = m_particleDataTable->particle(abs(pdgCode));
if (!pd) { // nuclei excluded, still problems with a given type?
ATH_MSG_INFO ("Could not get particle data for particle with pdgCode="<<pdgCode<< ", status=" << particle->status() << ", barcode=" << particle->barcode());
ATH_MSG_INFO ("GenParticle= " << *particle);
ATH_MSG_INFO ("Could not get particle data for particle with pdgCode="<<pdgCode<< ", status=" << particle->status() << ", barcode=" << HepMC::barcode(particle));
ATH_MSG_INFO ("GenParticle= " << particle);
continue;
}
ATH_MSG_DEBUG ("found particle = " << *particle);
ATH_MSG_DEBUG ("found particle = " << particle);
// assume for the moment we're only running over single gamma MC files ...
HepMC::GenVertex* prodVertex( particle->production_vertex());
if ( abs(pdgCode) == 11 ) {
auto prodVertex = particle->production_vertex();
if ( std::abs(pdgCode) == 11 ) {
ATH_MSG_DEBUG ("Electron/Positron detected -- checking for production process ...");
HepMC::GenVertex::particles_in_const_iterator inParticle = prodVertex->particles_in_const_begin();
HepMC::GenVertex::particles_out_const_iterator inParticleEnd = prodVertex->particles_in_const_end();
for ( ; inParticle != inParticleEnd; ++inParticle) {
ATH_MSG_DEBUG(" --> checking morther: " << *(*inParticle) );
if ( abs((*inParticle)->pdg_id()) == 22 || abs((*inParticle)->pdg_id()) == 11 ){
if (fabs(particle->momentum().perp()) > m_minPt && fabs(particle->momentum().pseudoRapidity()) < m_maxEta ) {
#ifdef HEPMC3
for ( auto inParticle: prodVertex->particles_in()) {
#else
HepMC::GenVertex::particles_in_const_iterator ItinParticle = prodVertex->particles_in_const_begin();
HepMC::GenVertex::particles_out_const_iterator ItinParticleEnd = prodVertex->particles_in_const_end();
for ( ; ItinParticle != ItinParticleEnd; ++ItinParticle) {
auto inParticle=*ItinParticle;
#endif
ATH_MSG_DEBUG(" --> checking morther: " << inParticle );
if ( std::abs(inParticle->pdg_id()) == 22 || std::abs(inParticle->pdg_id()) == 11 ){
if (std::fabs(particle->momentum().perp()) > m_minPt && std::fabs(particle->momentum().pseudoRapidity()) < m_maxEta ) {
genSignal->push_back(particle);
ATH_MSG_DEBUG ("Selected this electron/positron!");
break;
......
......@@ -104,7 +104,7 @@ public:
void selectTracks( const xAOD::TruthParticleContainer* truthtracks );
bool selectTrack( const HepMC::GenParticle* track );
bool selectTrack( HepMC::ConstGenParticlePtr track );
// add a TruthParticle
......@@ -117,7 +117,7 @@ public:
// make a TIDA::Track from a GenParticle
TIDA::Track* makeTrack( const HepMC::GenParticle* track );
TIDA::Track* makeTrack( HepMC::ConstGenParticlePtr track );
// make a TIDA::Track from a TruthParticle
TIDA::Track* makeTrack( const TruthParticle* track, unsigned long tid=0 );
......
......@@ -298,13 +298,18 @@ void TrigTrackSelector::selectTracks( const xAOD::TruthParticleContainer* trutht
// add a TruthParticle from a GenParticle - easy, bet it doesn't work
bool TrigTrackSelector::selectTrack( const HepMC::GenParticle* track ) {
bool TrigTrackSelector::selectTrack( HepMC::ConstGenParticlePtr track ) {
/// not a "final state" particle
if ( track->status() != 1 ) return false;
/// set this so can use it as the identifier - don't forget to reset!!
//AV Using memory to get some value is not a good idea. This is not a repruducible/portable way, but I leave it as is.
#ifdef HEPMC3
m_id = (unsigned long)(track.get());
#else
m_id = (unsigned long)track;
#endif
bool sel;
sel = selectTrack( TruthParticle(track) );
m_id = 0;
......@@ -476,8 +481,13 @@ bool TrigTrackSelector::selectTrack( const xAOD::TruthParticle* track ) {
// make a TIDA::Track from a GenParticle
TIDA::Track* TrigTrackSelector::makeTrack( const HepMC::GenParticle* track ) {
TIDA::Track* TrigTrackSelector::makeTrack(HepMC::ConstGenParticlePtr track ) {
//AV Using memory to get some value is not a good idea. This is not a repruducible/portable way, but I leave it as is.
#ifdef HEPMC3
unsigned long id = (unsigned long)(track.get());
#else
unsigned long id = (unsigned long)track;
#endif
TruthParticle t = TruthParticle(track);
return makeTrack( &t, id );
}
......
......@@ -27,7 +27,7 @@ class SimHitHandleBase;
class AscObj_TruthPoint : public AssociatedObjectHandleBase {
public:
AscObj_TruthPoint( TrackHandleBase*, const HepMC::GenVertex * v, const HepMC::GenParticle * p );
AscObj_TruthPoint( TrackHandleBase*, HepMC::ConstGenVertexPtr v, HepMC::ConstGenParticlePtr p );
AscObj_TruthPoint( TrackHandleBase*, SimHitHandleBase* );
virtual ~AscObj_TruthPoint();
......
......@@ -36,18 +36,18 @@
//____________________________________________________________________
class AscObj_TruthPoint::Imp {
public:
Imp(const HepMC::GenVertex * v, const HepMC::GenParticle * p)
: genVertex(v), genParticle(p), simhit(0) {}
Imp(HepMC::ConstGenVertexPtr v, HepMC::ConstGenParticlePtr p)
: genVertex(v), genParticle(p), simhit(nullptr) {}
Imp(SimHitHandleBase*s)
: genVertex(0), genParticle(0), simhit(s) {}
const HepMC::GenVertex * genVertex;
const HepMC::GenParticle * genParticle;
: genVertex(nullptr), genParticle(nullptr), simhit(s) {}
HepMC::ConstGenVertexPtr genVertex;
HepMC::ConstGenParticlePtr genParticle;
SimHitHandleBase * simhit;
};
//____________________________________________________________________
AscObj_TruthPoint::AscObj_TruthPoint(TrackHandleBase*th, const HepMC::GenVertex * v, const HepMC::GenParticle * p)
AscObj_TruthPoint::AscObj_TruthPoint(TrackHandleBase*th, HepMC::ConstGenVertexPtr v, HepMC::ConstGenParticlePtr p)
: AssociatedObjectHandleBase(th), m_d(new Imp(v,p))
{
}
......
......@@ -28,18 +28,18 @@
class TrackHandle_TruthTrack::Imp {
public:
Imp(TrackHandle_TruthTrack * tc,
const SimBarCode& sbc,const SimHitList& shl,const HepMC::GenParticle* p)
const SimBarCode& sbc,const SimHitList& shl,HepMC::ConstGenParticlePtr p)
: theclass(tc),
simBarCode(sbc),
simHitList(shl),
genParticle(p),
ascObjVis(false),
ascObjs(0),
trkTrack(0) {}
trkTrack(nullptr) {}
TrackHandle_TruthTrack * theclass;
SimBarCode simBarCode;
SimHitList simHitList;
const HepMC::GenParticle* genParticle;
HepMC::ConstGenParticlePtr genParticle;
bool ascObjVis;
std::vector<AscObj_TruthPoint*> * ascObjs;
......@@ -47,11 +47,11 @@ public:
const Trk::Track * trkTrack;
void ensureInitTrkTracks();
static Trk::Perigee * createTrkPerigeeFromProdVertex(const HepMC::GenParticle * p, const double& charge )
static Trk::Perigee * createTrkPerigeeFromProdVertex(HepMC::ConstGenParticlePtr p, const double& charge )
{
if (!p)
return 0;//Fixme: message!
const HepMC::GenVertex * v = p->production_vertex();
auto v = p->production_vertex();
if (!v)
return 0;//Fixme: message!
Amg::Vector3D mom(p->momentum().px(),p->momentum().py(),p->momentum().pz());
......@@ -62,11 +62,11 @@ public:
return new Trk::Perigee(0.,0.,mom.phi(), mom.theta(), charge/absmom, pos);
}
static Trk::TrackParameters * createTrkParamFromDecayVertex(const HepMC::GenParticle * p, const double& charge )
static Trk::TrackParameters * createTrkParamFromDecayVertex(HepMC::ConstGenParticlePtr p, const double& charge )
{
if (!p)
return 0;//Fixme: message!
const HepMC::GenVertex * v = p->end_vertex();
auto v = p->end_vertex();
if (!v)
return 0;//Fixme: message!
Amg::Vector3D mom(p->momentum().px(),p->momentum().py(),p->momentum().pz());
......@@ -125,7 +125,7 @@ public:
TrackHandle_TruthTrack::TrackHandle_TruthTrack( TrackCollHandleBase* ch,
const SimBarCode& simBarCode,
const SimHitList& simHitList,
const HepMC::GenParticle* genPart )
HepMC::ConstGenParticlePtr genPart )
: TrackHandleBase(ch), m_d(new Imp(this,simBarCode,simHitList,genPart))
{
if (VP1Msg::verbose()) {
......@@ -262,7 +262,7 @@ bool TrackHandle_TruthTrack::hasVertexAtIR(const double& rmaxsq, const double& z
{
if (!m_d->genParticle)
return false;
const HepMC::GenVertex * v = m_d->genParticle->production_vertex();
auto v = m_d->genParticle->production_vertex();
if (!v)
return false;
......@@ -308,8 +308,12 @@ void TrackHandle_TruthTrack::Imp::ensureInitAscObjs()
if (ascObjs)
return;
ascObjs = new std::vector<AscObj_TruthPoint*>;
const HepMC::GenVertex * vprod = genParticle ? genParticle->production_vertex() : 0;
const HepMC::GenVertex * vend = genParticle ? genParticle->end_vertex() : 0;
HepMC::ConstGenVertexPtr vprod{nullptr};
HepMC::ConstGenVertexPtr vend{nullptr};
if (genParticle) {
vprod=genParticle->production_vertex();
vend=genParticle->end_vertex();
}
ascObjs->reserve((vprod?1:0)+(vend?1:simHitList.size()));
if (vprod)
ascObjs->push_back(new AscObj_TruthPoint(theclass,vprod,genParticle));
......
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