Skip to content
Snippets Groups Projects
Commit a98b9442 authored by Walter Lampl's avatar Walter Lampl
Browse files

Merge branch 'MuonRecRTT_ATLASRECTS-4874_master' into 'master'

Fix crashes related to reading 21.0 RDOs where pile-up GenEvents were not recorded.

See merge request atlas/athena!21873
parents 19bccb41 ae5632a5
No related branches found
No related tags found
No related merge requests found
...@@ -172,7 +172,8 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const ...@@ -172,7 +172,8 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const
if (!p) { if (!p) {
if (0 == barcode()) { if (0 == barcode()) {
#if 0 #if 0
mlog() << MSG::DEBUG MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
log << MSG::DEBUG
<< "cptr: no truth particle associated with this hit (barcode==0)." << "cptr: no truth particle associated with this hit (barcode==0)."
<< " Probably this is a noise hit" << endmsg; << " Probably this is a noise hit" << endmsg;
#endif #endif
...@@ -186,7 +187,16 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const ...@@ -186,7 +187,16 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const
pEvt = pEvtColl->at(0); pEvt = pEvtColl->at(0);
} }
else if (position != ExtendedBarCode::UNDEFINED) { 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 { else {
pEvt = pEvtColl->find (index); pEvt = pEvtColl->find (index);
......
...@@ -23,10 +23,12 @@ void HepMcParticleLinkCnv_p1::persToTrans( const HepMcParticleLink_p1* persObj, ...@@ -23,10 +23,12 @@ void HepMcParticleLinkCnv_p1::persToTrans( const HepMcParticleLink_p1* persObj,
HepMcParticleLink* transObj, HepMcParticleLink* transObj,
MsgStream &/*msg*/ ) MsgStream &/*msg*/ )
{ {
EBC_EVCOLL evColl = EBC_MAINEVCOLL;
if (persObj->m_mcEvtIndex>0) evColl = EBC_FIRSTPUEVCOLL; // HACK
transObj->setExtendedBarCode transObj->setExtendedBarCode
( HepMcParticleLink::ExtendedBarCode( persObj->m_barcode, ( HepMcParticleLink::ExtendedBarCode( persObj->m_barcode,
persObj->m_mcEvtIndex, persObj->m_mcEvtIndex,
EBC_MAINEVCOLL, evColl,
HepMcParticleLink::IS_POSITION) ); HepMcParticleLink::IS_POSITION) );
return; return;
} }
......
...@@ -163,57 +163,52 @@ void MuonPRD_MultiTruthMaker::addPRDRange (SG::WriteHandle<PRD_MultiTruthCollect ...@@ -163,57 +163,52 @@ void MuonPRD_MultiTruthMaker::addPRDRange (SG::WriteHandle<PRD_MultiTruthCollect
//================================================================ //================================================================
template <class SIMDATACOLLECTION> template <class SIMDATACOLLECTION>
void MuonPRD_MultiTruthMaker::addPrepRawDatum(SG::WriteHandle<PRD_MultiTruthCollection> prdTruth, void MuonPRD_MultiTruthMaker::addPrepRawDatum(SG::WriteHandle<PRD_MultiTruthCollection> prdTruth,
const Trk::PrepRawData* prd, const Trk::PrepRawData* prd,
SG::ReadHandle<SIMDATACOLLECTION> simDataMap 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 gotSDO = false;
bool gotValidParticle = false; bool gotValidParticle = false;
// loop over RDOs // loop over RDOs
std::vector<Identifier>::const_iterator nextRDO = prd->rdoList().begin(); for (const auto& nextRDO : prd->rdoList()) {
std::vector<Identifier>::const_iterator lastRDO = prd->rdoList().end(); typename SIMDATACOLLECTION::const_iterator iter(simDataMap->find(nextRDO));
for (; nextRDO!=lastRDO; ++nextRDO) {
typename SIMDATACOLLECTION::const_iterator iter(simDataMap->find(*nextRDO));
if(iter != simDataMap->end() ) { if(iter != simDataMap->end() ) {
gotSDO = true; gotSDO = true;
// Got an SDO. Try to associate the PRD to MC particles we have info about. // Got an SDO. Try to associate the PRD to MC particles we have info about.
typedef typename SIMDATACOLLECTION::mapped_type SIMDATA; typedef typename SIMDATACOLLECTION::mapped_type SIMDATA;
const SIMDATA& sdo = iter->second; const SIMDATA& sdo = iter->second;
const std::vector< typename SIMDATA::Deposit >& deposits = sdo.getdeposits(); const std::vector< typename SIMDATA::Deposit >& deposits = sdo.getdeposits();
typename std::vector< typename SIMDATA::Deposit >::const_iterator nextdeposit = deposits.begin(); if (deposits.empty()) { continue; }
typename std::vector< typename SIMDATA::Deposit >::const_iterator lastdeposit = deposits.end(); for (const auto& [particleLink, mcData] : deposits) {
for( ; nextdeposit!=lastdeposit; ++nextdeposit) { ATH_MSG_VERBOSE("addPrepRawDatum(): particleLink.isValid() " << particleLink.isValid() );
const HepMcParticleLink& particleLink = nextdeposit->first; ATH_MSG_VERBOSE("addPrepRawDatum(): Barcode " << particleLink.barcode()<< " evt " << particleLink.eventIndex() );
if (particleLink.isValid()) {
ATH_MSG_VERBOSE("addPrepRawDatum(): Barcode " << particleLink.barcode()<< " evt " << particleLink.eventIndex() ); gotValidParticle = true;
// Associate the particle to the PRD. But don't add duplicates.
if (particleLink.isValid()) { // 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.
gotValidParticle = true; // But may be not for the typically small RDO/PRD ratio.
// Associate the particle to the PRD. But don't add duplicates. typedef PRD_MultiTruthCollection::iterator truthiter;
// 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. std::pair<truthiter, truthiter> r = prdTruth->equal_range(prd->identify());
// But may be not for the typically small RDO/PRD ratio. if(r.second == std::find_if(r.first, r.second,
typedef PRD_MultiTruthCollection::iterator truthiter; [ particleLink ](const PRD_MultiTruthCollection::value_type &prd_to_truth) {
std::pair<truthiter, truthiter> r = prdTruth->equal_range(prd->identify()); return prd_to_truth.second == particleLink;
if(r.second == std::find_if(r.first, r.second, } )) {
[ particleLink ](const PRD_MultiTruthCollection::value_type &prd_to_truth) { prdTruth->insert(std::make_pair(prd->identify(), particleLink));
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. // Looked at all the deposits from all the SDOs, but did not find any valid particle link.
//prdTruth->insert(std::make_pair(prd, particleLinkUnknown)); //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");
} }
} }
//================================================================ //================================================================
......
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