diff --git a/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonSimHit/Root/xAODMuonSimHit_V1.cxx b/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonSimHit/Root/xAODMuonSimHit_V1.cxx index ca06f8fc296b82eb105516457830c8043cb1443e..2d2e8bc8142217d4197e1daedadfeac4788454ce 100644 --- a/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonSimHit/Root/xAODMuonSimHit_V1.cxx +++ b/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonSimHit/Root/xAODMuonSimHit_V1.cxx @@ -69,7 +69,7 @@ const HepMcParticleLink& MuonSimHit_v1::genParticleLink() const { if (!m_hepMCLink) { auto link = std::make_unique<HepMcParticleLink>(acc_uniqueID(*this), acc_mcEventIndex(*this), - HepMcParticleLink::IS_POSITION, + HepMcParticleLink::IS_EVENTNUM, HepMcParticleLink::IS_ID); return *m_hepMCLink.set(std::move(link)); } diff --git a/MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testSensitiveDetectors.py b/MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testSensitiveDetectors.py index 339921316ed2ebd3eadc2057da73b9252913a16b..a611a54b07c35c94afa33c6c424c652395cbcdc6 100644 --- a/MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testSensitiveDetectors.py +++ b/MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testSensitiveDetectors.py @@ -15,7 +15,7 @@ def setupTestOutputCfg(flags,**kwargs): "xAOD::TruthParticleAuxContainer#", "xAOD::TruthEventContainer#", "xAOD::TruthEventAuxContainer#", - "McEventCollection#"] + OutputSimContainersCfg(flags) + "McEventCollection#TruthEvent"] + OutputSimContainersCfg(flags) from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg result.merge(SetupMetaDataForStreamCfg(flags, kwargs["streamName"])) diff --git a/MuonSpectrometer/MuonPhaseII/MuonDigitization/MuonDigitizationR4/src/MuonDigitizationTool.cxx b/MuonSpectrometer/MuonPhaseII/MuonDigitization/MuonDigitizationR4/src/MuonDigitizationTool.cxx index 69eaeb01a51bd21daf3efa7c2eedf1242419b6ba..426a44f8b89c4fe7e87d47b5c481a09855c6c30c 100644 --- a/MuonSpectrometer/MuonPhaseII/MuonDigitization/MuonDigitizationR4/src/MuonDigitizationTool.cxx +++ b/MuonSpectrometer/MuonPhaseII/MuonDigitization/MuonDigitizationR4/src/MuonDigitizationTool.cxx @@ -155,7 +155,8 @@ namespace MuonR4{ ATH_MSG_VERBOSE("Hit "<<m_idHelperSvc->toString(hit->identify())<<" is a pile-up truth link"); return nullptr; } - + ATH_MSG_VERBOSE(m_idHelperSvc->toString(hit->identify())<<", pdgID: "<<hit->pdgId()<< " genParticleLink :"<<hit->genParticleLink()); + ATH_MSG_VERBOSE("Genparticle: "<<hit->genParticleLink()); xAOD::MuonSimHit* sdoHit = sdoContainer->push_back(std::make_unique<xAOD::MuonSimHit>()); (*sdoHit) = (*hit); static const SG::Accessor<float> acc_eventTime{"MuSim_evtTime"}; diff --git a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/python/SensitiveDetectorsCfg.py b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/python/SensitiveDetectorsCfg.py index 902b6939c9988486b0a1a4e0bfdee22aee5439de..5eddadb6cf6fff0beaf8f77544c5fb8c714651f2 100644 --- a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/python/SensitiveDetectorsCfg.py +++ b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/python/SensitiveDetectorsCfg.py @@ -156,6 +156,6 @@ def OutputSimContainersCfg(flags): containerNames+=["xStgcSimHits"] outContainers +=[ f"xAOD::MuonSimHitContainer#{cont}" for cont in containerNames] - outContainers +=[ f"xAOD::MuonSimHitAuxContainer#{cont}Aux." for cont in containerNames] + outContainers +=[ f"xAOD::MuonSimHitAuxContainer#{cont}Aux.-MuonSim_G4TrkId" for cont in containerNames] return outContainers diff --git a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MuonSensitiveDetector.cxx b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MuonSensitiveDetector.cxx index 74421ee95d6a8d49b11d8d9d8207e4dcc817988d..19d2df56bd26a98598c210846cab82752fe78ae9 100644 --- a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MuonSensitiveDetector.cxx +++ b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MuonSensitiveDetector.cxx @@ -14,6 +14,8 @@ #include <G4Geantino.hh> #include <G4ChargedGeantino.hh> +#include "MCTruth/TrackInformation.h" + using namespace ActsTrk; namespace { @@ -130,9 +132,12 @@ namespace MuonG4R4 { hit->setKineticEnergy(currentTrack->GetKineticEnergy()); hit->setGenParticleLink(trHelper.GenerateParticleLink()); hit->setStepLength(aStep->GetStepLength()); - + ATH_MSG_VERBOSE("Save new hit "<<m_detMgr->idHelperSvc()->toString(hitId) - <<", "<<hit->genParticleLink()<<", trackId: "<<currentTrack->GetTrackID()<<", " + <<", pdgId: "<<hit->pdgId() + <<", "<<hit->genParticleLink() + <<", trackId: "<<currentTrack->GetTrackID()<<", " + <<", "<<hit->genParticleLink().cptr()<<std::endl <<"pos: "<<Amg::toString(hitPos)<<", dir: "<<Amg::toString(hitDir)<<", time: "<<globTime <<", energy: "<<hit->kineticEnergy()<<", stepLength: "<<hit->stepLength()<<", " <<", deposit energy: "<<hit->energyDeposit()); diff --git a/MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonTruthAlgsR4/src/TruthSegmentMaker.cxx b/MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonTruthAlgsR4/src/TruthSegmentMaker.cxx index 259b6267a78fda46df6012a0030d2d4e93c166bc..06e3140082a0c9db9b7bab38b8ec78d03ac81143 100644 --- a/MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonTruthAlgsR4/src/TruthSegmentMaker.cxx +++ b/MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonTruthAlgsR4/src/TruthSegmentMaker.cxx @@ -36,11 +36,14 @@ namespace MuonR4{ const ContainerType*& contToPush) const { contToPush = nullptr; if (key.empty()) { - ATH_MSG_VERBOSE("No key has been parsed for object "<< typeid(ContainerType).name()); + ATH_MSG_DEBUG("No key has been parsed for object "<< typeid(ContainerType).name()); return StatusCode::SUCCESS; } SG::ReadHandle readHandle{key, ctx}; - ATH_CHECK(readHandle.isPresent()); + if (!readHandle.isPresent()) { + ATH_MSG_FATAL("Failed to retrieve "<<key.fullKey()); + return StatusCode::FAILURE; + } contToPush = readHandle.cptr(); return StatusCode::SUCCESS; } @@ -94,7 +97,8 @@ namespace MuonR4{ /// skip empty truth matches for now if (!genParticle || (m_useOnlyMuonHits && !MC::isMuon(simHit))) { ATH_MSG_VERBOSE("Skip hit "<<m_idHelperSvc->toString(simHit->identify())<< - " pdgId: "<<simHit->pdgId()<<", energy: "<<simHit->kineticEnergy()); + " pdgId: "<<simHit->pdgId()<<", energy: "<<simHit->kineticEnergy() + <<", genParticle: "<<genParticle); continue; } hitCollector[id][genParticle].push_back(simHit); @@ -105,8 +109,9 @@ namespace MuonR4{ ATH_CHECK(writeHandle.record(std::make_unique<xAOD::MuonSegmentContainer>(), std::make_unique<xAOD::MuonSegmentAuxContainer>())); - using HitLinkVec = std::vector<ElementLink<xAOD::MuonSimHitContainer>>; - SG::WriteDecorHandle<xAOD::MuonSegmentContainer, HitLinkVec> hitDecor{m_eleLinkKey, ctx}; + using EleLink_t = ElementLink<xAOD::MuonSimHitContainer>; + using HitLinkVec_t = std::vector<EleLink_t>; + SG::WriteDecorHandle<xAOD::MuonSegmentContainer, HitLinkVec_t> hitDecor{m_eleLinkKey, ctx}; SG::WriteDecorHandle<xAOD::MuonSegmentContainer, float> ptDecor{m_ptKey, ctx}; SG::WriteDecorHandle<xAOD::MuonSegmentContainer, float> qDecor{m_qKey, ctx}; using SegPars = xAOD::MeasVector<toInt(ParamDefs::nPars)>; @@ -115,13 +120,15 @@ namespace MuonR4{ const Amg::Transform3D& locToGlob{chamber->localToGlobalTrans(*gctx)}; for (auto& [particle, simHits]: collectedParts) { - /* Take the hit that's closest to the chamber centre as reference */ std::ranges::stable_sort(simHits,[gctx,this](const xAOD::MuonSimHit*a, const xAOD::MuonSimHit*b){ return std::abs((toChamber(*gctx, a->identify())* xAOD::toEigen(a->localPosition())).z()) < std::abs((toChamber(*gctx, b->identify())* xAOD::toEigen(b->localPosition())).z()); }); const xAOD::MuonSimHit* simHit = simHits.front(); + ATH_MSG_VERBOSE("Create segement from hit: "<<m_idHelperSvc->toString(simHit->identify())<< + " pdgId: "<<simHit->pdgId()<<", energy: "<<simHit->kineticEnergy() + <<", genParticle: "<<simHit->genParticleLink().cptr()); const Identifier segId{simHit->identify()}; const Amg::Transform3D inChamb = toChamber(*gctx, segId); @@ -134,7 +141,7 @@ namespace MuonR4{ const Amg::Vector3D globPos = locToGlob * chamberPos; const Amg::Vector3D globDir = locToGlob.linear() * chamberDir; - HitLinkVec associatedHits{}; + HitLinkVec_t associatedHits{}; unsigned int nMdt{0}, nRpcEta{0}, nRpcPhi{0}, nTgcEta{0}, nTgcPhi{0}; unsigned int nMm{0}, nStgcEta{0}, nStgcPhi{0}; for (const xAOD::MuonSimHit* assocMe : simHits) { @@ -165,8 +172,10 @@ namespace MuonR4{ default: ATH_MSG_WARNING("Csc are not defined "<<m_idHelperSvc->toString(simHit->identify())); } - ElementLink<xAOD::MuonSimHitContainer> link{*static_cast<const xAOD::MuonSimHitContainer*>(assocMe->container()), - assocMe->index()}; + ATH_MSG_VERBOSE("Associate hit "<<m_idHelperSvc->toString(assocMe->identify()) + <<" pdgId: "<<assocMe->pdgId()<<", energy: "<<assocMe->kineticEnergy() + <<", genParticle: "<<assocMe->genParticleLink().cptr()); + EleLink_t link{*static_cast<const xAOD::MuonSimHitContainer*>(assocMe->container()), assocMe->index()}; associatedHits.push_back(std::move(link)); } int nPrecisionHits = nMdt + nMm + nStgcEta; @@ -198,6 +207,11 @@ namespace MuonR4{ } else { truthSegment->setFitQuality(0, (nPrecisionHits + nPhiLayers + nTgcEta + nRpcEta - 5)); } + /// Sort the associated hits by local Z + std::ranges::stable_sort(associatedHits,[&gctx, this](const EleLink_t& a, const EleLink_t&b) { + return (toChamber(*gctx, (*a)->identify())* xAOD::toEigen((*a)->localPosition())).z() < + (toChamber(*gctx, (*b)->identify())* xAOD::toEigen((*b)->localPosition())).z(); + }); hitDecor(*truthSegment) = std::move(associatedHits); } }