diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.cxx index 1102c9f5b8b3710e0932374a9dd624a54726df02..64104f8fd861f7350030b6fcb7ab0b9d7f747151 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.cxx @@ -110,12 +110,14 @@ void MuonTruthAssociationAlg::addMuon( const xAOD::TruthParticleContainer& truth ElementLink< xAOD::TruthParticleContainer > truthLink = tp->auxdata<ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink"); if( truthLink.isValid() ){ // loop over truth particles + bool foundTruth=false; for( const auto& truthParticle : truthParticles ){ if( truthParticle->status() != 1 ) continue; ATH_MSG_DEBUG("Adding recoMuonLink for truth muon with barcode " << truthParticle->barcode() << " pt "<< truthParticle->pt()); ElementLink< xAOD::MuonContainer > muonLink; if( ((*truthLink)->barcode())%m_barcodeOffset == truthParticle->barcode() ) { + foundTruth=true; ATH_MSG_VERBOSE(" Got truth link -> creating link with truth particle " << (*truthLink)->barcode() ); muonLink = ElementLink< xAOD::MuonContainer >(muon,muons); // add the link from xAOD::Muon to TruthParticle in m_muonTruthParticleContainerName @@ -293,6 +295,10 @@ void MuonTruthAssociationAlg::addMuon( const xAOD::TruthParticleContainer& truth break; } } + if(!foundTruth){ + ATH_MSG_DEBUG("failed to find a status=1 truth particle to match the truth link"); + setDummyTruthInfo(*muon); + } } else{ //no truth link, add a dummy setDummyTruthInfo(*muon); @@ -300,6 +306,8 @@ void MuonTruthAssociationAlg::addMuon( const xAOD::TruthParticleContainer& truth } }catch ( SG::ExcBadAuxVar& ) { ATH_MSG_WARNING("Track particle is missing truthParticleLink variable!"); + //there should always be a truthParticleLink, but just in case + setDummyTruthInfo(*muon); } } diff --git a/Tracking/TrkAlgorithms/TrkTruthAlgs/src/TrackParticleTruthAlg.cxx b/Tracking/TrkAlgorithms/TrkTruthAlgs/src/TrackParticleTruthAlg.cxx index 8365423d83ce87c2ea6a9584ec9452ab9a131616..e54b73f387e2de97e559aa0f32c55526b1261655 100644 --- a/Tracking/TrkAlgorithms/TrkTruthAlgs/src/TrackParticleTruthAlg.cxx +++ b/Tracking/TrkAlgorithms/TrkTruthAlgs/src/TrackParticleTruthAlg.cxx @@ -65,6 +65,8 @@ StatusCode TrackParticleTruthAlg::execute() { if( !particle->trackLink().isValid() ){ ATH_MSG_WARNING("Found TrackParticle with Invalid element link, skipping"); + //add dummy truth link + const_cast<xAOD::TrackParticle*>(particle)->auxdata<ElementLink<xAOD::TruthParticleContainer> >("truthParticleLink" ) = ElementLink<xAOD::TruthParticleContainer>(); continue; } ATH_MSG_DEBUG("Looking up truth for pt " << particle->pt() << " eta " << particle->eta() << " phi " << particle->phi());