diff --git a/Generators/GeneratorObjects/src/HepMcParticleLink.cxx b/Generators/GeneratorObjects/src/HepMcParticleLink.cxx index 8bbcfddf44157596c225d276715614e450e838fa..bbbdc2afb3f80bbe3dedde27b17828aafcee6239 100644 --- a/Generators/GeneratorObjects/src/HepMcParticleLink.cxx +++ b/Generators/GeneratorObjects/src/HepMcParticleLink.cxx @@ -172,7 +172,8 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const if (!p) { if (0 == barcode()) { #if 0 - mlog() << MSG::DEBUG + MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink"); + log << MSG::DEBUG << "cptr: no truth particle associated with this hit (barcode==0)." << " Probably this is a noise hit" << endmsg; #endif @@ -186,7 +187,16 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const pEvt = pEvtColl->at(0); } else if (position != ExtendedBarCode::UNDEFINED) { - pEvt = pEvtColl->at (position); + if (position < pEvtColl->size()) { + pEvt = pEvtColl->at (position); + } + else { +#if 0 + MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink"); + log << MSG::WARNING << "cptr: position = " << position << ", McEventCollection size = "<< pEvtColl->size() << endmsg; +#endif + return nullptr; + } } else { pEvt = pEvtColl->find (index); diff --git a/Generators/GeneratorObjectsTPCnv/src/HepMcParticleLinkCnv_p1.cxx b/Generators/GeneratorObjectsTPCnv/src/HepMcParticleLinkCnv_p1.cxx index a231c671b466e02a079b37f671a31c28ca860a42..322d8255909c6d43284cf8990faa7b61b3990599 100755 --- a/Generators/GeneratorObjectsTPCnv/src/HepMcParticleLinkCnv_p1.cxx +++ b/Generators/GeneratorObjectsTPCnv/src/HepMcParticleLinkCnv_p1.cxx @@ -23,10 +23,12 @@ void HepMcParticleLinkCnv_p1::persToTrans( const HepMcParticleLink_p1* persObj, HepMcParticleLink* transObj, MsgStream &/*msg*/ ) { + EBC_EVCOLL evColl = EBC_MAINEVCOLL; + if (persObj->m_mcEvtIndex>0) evColl = EBC_FIRSTPUEVCOLL; // HACK transObj->setExtendedBarCode ( HepMcParticleLink::ExtendedBarCode( persObj->m_barcode, persObj->m_mcEvtIndex, - EBC_MAINEVCOLL, + evColl, HepMcParticleLink::IS_POSITION) ); return; } diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonPRD_MultiTruthMaker.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonPRD_MultiTruthMaker.cxx index 883cf72c5c7ee31be1839e40212b84ca425c3dea..d57d9d05870681e437e800fec1099f39d354038c 100755 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonPRD_MultiTruthMaker.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonPRD_MultiTruthMaker.cxx @@ -163,57 +163,52 @@ void MuonPRD_MultiTruthMaker::addPRDRange (SG::WriteHandle<PRD_MultiTruthCollect //================================================================ template <class SIMDATACOLLECTION> void MuonPRD_MultiTruthMaker::addPrepRawDatum(SG::WriteHandle<PRD_MultiTruthCollection> prdTruth, - const Trk::PrepRawData* prd, - SG::ReadHandle<SIMDATACOLLECTION> simDataMap - ) + const Trk::PrepRawData* prd, + SG::ReadHandle<SIMDATACOLLECTION> simDataMap + ) { - ATH_MSG_VERBOSE( "addPrepRawDatum(): new PRD "<<prd<<", id="<<prd->identify()<<", number of RDOs: " << prd->rdoList().size() ); + ATH_MSG_VERBOSE( "addPrepRawDatum(): new PRD "<<prd<<", id="<<prd->identify()<<", number of RDOs: " << prd->rdoList().size() ); - bool gotSDO = false; - bool gotValidParticle = false; + bool gotSDO = false; + bool gotValidParticle = false; // loop over RDOs - std::vector<Identifier>::const_iterator nextRDO = prd->rdoList().begin(); - std::vector<Identifier>::const_iterator lastRDO = prd->rdoList().end(); - for (; nextRDO!=lastRDO; ++nextRDO) { - typename SIMDATACOLLECTION::const_iterator iter(simDataMap->find(*nextRDO)); + for (const auto& nextRDO : prd->rdoList()) { + typename SIMDATACOLLECTION::const_iterator iter(simDataMap->find(nextRDO)); - if(iter != simDataMap->end() ) { - gotSDO = true; + if(iter != simDataMap->end() ) { + gotSDO = true; // Got an SDO. Try to associate the PRD to MC particles we have info about. - typedef typename SIMDATACOLLECTION::mapped_type SIMDATA; - const SIMDATA& sdo = iter->second; - const std::vector< typename SIMDATA::Deposit >& deposits = sdo.getdeposits(); - typename std::vector< typename SIMDATA::Deposit >::const_iterator nextdeposit = deposits.begin(); - typename std::vector< typename SIMDATA::Deposit >::const_iterator lastdeposit = deposits.end(); - for( ; nextdeposit!=lastdeposit; ++nextdeposit) { - const HepMcParticleLink& particleLink = nextdeposit->first; - - ATH_MSG_VERBOSE("addPrepRawDatum(): Barcode " << particleLink.barcode()<< " evt " << particleLink.eventIndex() ); - - if (particleLink.isValid()) { - gotValidParticle = true; - // Associate the particle to the PRD. But don't add duplicates. - // Note: it may be more efficient to filter out duplicates among particles for the current PRD, then check-and-add the reduced set to the large multimap. - // But may be not for the typically small RDO/PRD ratio. - typedef PRD_MultiTruthCollection::iterator truthiter; - std::pair<truthiter, truthiter> r = prdTruth->equal_range(prd->identify()); - if(r.second == std::find_if(r.first, r.second, - [ particleLink ](const PRD_MultiTruthCollection::value_type &prd_to_truth) { - return prd_to_truth.second == particleLink; - } )) { - prdTruth->insert(std::make_pair(prd->identify(), particleLink)); - } - } - } + typedef typename SIMDATACOLLECTION::mapped_type SIMDATA; + const SIMDATA& sdo = iter->second; + const std::vector< typename SIMDATA::Deposit >& deposits = sdo.getdeposits(); + if (deposits.empty()) { continue; } + for (const auto& [particleLink, mcData] : deposits) { + ATH_MSG_VERBOSE("addPrepRawDatum(): particleLink.isValid() " << particleLink.isValid() ); + ATH_MSG_VERBOSE("addPrepRawDatum(): Barcode " << particleLink.barcode()<< " evt " << particleLink.eventIndex() ); + if (particleLink.isValid()) { + gotValidParticle = true; + // Associate the particle to the PRD. But don't add duplicates. + // Note: it may be more efficient to filter out duplicates among particles for the current PRD, then check-and-add the reduced set to the large multimap. + // But may be not for the typically small RDO/PRD ratio. + typedef PRD_MultiTruthCollection::iterator truthiter; + std::pair<truthiter, truthiter> r = prdTruth->equal_range(prd->identify()); + if(r.second == std::find_if(r.first, r.second, + [ particleLink ](const PRD_MultiTruthCollection::value_type &prd_to_truth) { + return prd_to_truth.second == particleLink; + } )) { + prdTruth->insert(std::make_pair(prd->identify(), particleLink)); + } } + } } + } - if(gotSDO && !gotValidParticle) { + if(gotSDO && !gotValidParticle) { // Looked at all the deposits from all the SDOs, but did not find any valid particle link. //prdTruth->insert(std::make_pair(prd, particleLinkUnknown)); - ATH_MSG_DEBUG("addPrepRawDatum(): got SDO but no particles"); - } + ATH_MSG_DEBUG("addPrepRawDatum(): got SDO but no particles"); + } } //================================================================