From a4efebdb1577445cb6b1e5976dbfe12fdc9b9c4c Mon Sep 17 00:00:00 2001 From: Will Leight <wleight@cern.ch> Date: Wed, 21 Mar 2018 22:14:40 +0100 Subject: [PATCH] MuonRecoValidationTool was retrieving the MuonTruthSummaryTool whether or not it was running on MC, using the default values it returns when running on data. This less-than-ideal behavior is no longer feasible now that the MuonTruthSummaryTool declares in its initialization that it will be retrieving some truth containers. Therefore I added a configurable isMC flag to MuonRecoValidationTool, which now retrieves the MuonTruthSummaryTool only if it is running on MC and disables it otherwise. I also added isMC protection to all cases in the code where the MuonTruthSummaryTool is called, and updated the configuration to set the flag correctly. Probably the MuonRecoValidationTool should be reworked a bit so that it handles this in a more logical fashion, but this is outside the scope of this MR. Former-commit-id: c43313bd0b08eb2c78be8ab20b624424e7a906df --- .../src/MuonTruthSummaryTool.cxx | 1 + .../src/MuonRecoValidationTool.cxx | 53 ++++++++++++++----- .../src/MuonRecoValidationTool.h | 2 + .../python/MuGirlTagTool.py | 3 ++ 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTruthTools/src/MuonTruthSummaryTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTruthTools/src/MuonTruthSummaryTool.cxx index 76bad77ea86..99cc4192131 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTruthTools/src/MuonTruthSummaryTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTruthTools/src/MuonTruthSummaryTool.cxx @@ -123,6 +123,7 @@ namespace Muon { void MuonTruthSummaryTool::getTruth() const { for(SG::ReadHandle<PRD_MultiTruthCollection>& col : m_TruthNames.makeHandles()){ + if(!col.isValid() || !col.isPresent()) continue; ATH_MSG_DEBUG( "PRD_MultiTruthCollection " << col.key() << " found"); PRD_MultiTruthCollection::const_iterator it = col->begin(); PRD_MultiTruthCollection::const_iterator it_end = col->end(); diff --git a/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonRecoValidationTool.cxx b/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonRecoValidationTool.cxx index e07f1095420..bf65ff87672 100644 --- a/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonRecoValidationTool.cxx +++ b/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonRecoValidationTool.cxx @@ -63,7 +63,8 @@ namespace Muon { declareProperty("Extrapolator",m_extrapolator ); declareProperty("MatchTool",m_matchingTool ); declareProperty("MuonHitTimingTool",m_hitTimingTool ); - declareProperty("IncidentSvc",m_incidentSvc ); + declareProperty("IncidentSvc",m_incidentSvc ); + declareProperty("isMC",m_isMC=false); } MuonRecoValidationTool::~MuonRecoValidationTool() { @@ -76,7 +77,12 @@ namespace Muon { ATH_CHECK(m_edmHelper.retrieve()); ATH_CHECK(m_segmentHitSummaryTool.retrieve()); ATH_CHECK(m_hitSummaryTool.retrieve()); - ATH_CHECK(m_truthSummaryTool.retrieve()); + if(m_isMC){ + ATH_CHECK(m_truthSummaryTool.retrieve()); + } + else{ + m_truthSummaryTool.disable(); + } ATH_CHECK(m_extrapolator.retrieve()); ATH_CHECK(m_matchingTool.retrieve()); ATH_CHECK(m_hitTimingTool.retrieve()); @@ -164,6 +170,8 @@ namespace Muon { int MuonRecoValidationTool::getBarcode( const std::set<Identifier>& ids ) const { + if(!m_isMC) return -1; + // count how often a barcode occurs std::map<int,int> counters; for( std::set<Identifier>::const_iterator it=ids.begin();it!=ids.end();++it ){ @@ -211,8 +219,11 @@ namespace Muon { stauHit.propagationTime, stauHit.e, tof, 0., stauHit.shift, 1000 * m_candidateCounter); // barcode + pdg - int barcode = m_truthSummaryTool->getBarcode(id); - int pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + int barcode=-1,pdg=0; + if(m_isMC){ + barcode = m_truthSummaryTool->getBarcode(id); + pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + } m_ntuple.timeBlock.truth.fill(pdg,barcode); } ++m_candidateCounter; @@ -232,8 +243,11 @@ namespace Muon { m_ntuple.timeBlock.fill(2,m_idHelper->gasGapId(id).get_identifier32().get_compact(),gpos.perp(),gpos.z(),time,errorTime); // barcode + pdg - int barcode = m_truthSummaryTool->getBarcode(id); - int pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + int barcode=-1,pdg=0; + if(m_isMC){ + barcode = m_truthSummaryTool->getBarcode(id); + pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + } m_ntuple.timeBlock.truth.fill(pdg,barcode); return true; @@ -261,7 +275,8 @@ namespace Muon { std::vector<const MuonClusterOnTrack*> clusters; extract(*seg,ids,clusters); int barcode = getBarcode(ids); - int pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + int pdg=0; + if(m_isMC) pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; m_ntuple.timeBlock.truth.fill(pdg,barcode); return true; @@ -277,8 +292,11 @@ namespace Muon { // barcode + pdg - int barcode = m_truthSummaryTool->getBarcode(id); - int pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + int barcode=-1,pdg=0; + if(m_isMC){ + barcode = m_truthSummaryTool->getBarcode(id); + pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + } m_ntuple.timeBlock.truth.fill(pdg,barcode); bool measphi = m_idHelper->measuresPhi(id); @@ -352,7 +370,8 @@ namespace Muon { // barcode + pdg int barcode = getBarcode(ids); - int pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + int pdg=0; + if(m_isMC) pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; m_ntuple.segmentBlock.truth.fill(pdg,barcode); m_ntuple.segmentBlock.track.fill(getIndex(intersection)); @@ -425,8 +444,11 @@ namespace Muon { ids.insert((*hit)->prd->identify()); } } - int barcode = getBarcode(ids); - int pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + int barcode=-1,pdg=0; + if(m_isMC){ + barcode = getBarcode(ids); + pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + } m_ntuple.houghBlock.truth.fill(pdg,barcode); ATH_MSG_DEBUG(" Adding Hough maximum to ntuple "); @@ -441,8 +463,11 @@ namespace Muon { m_ntuple.hitBlock.id.fill(m_idHelper->sector(id),m_idHelper->chamberIndex(id)); m_ntuple.hitBlock.track.fill(getIndex(intersection)); - int barcode = m_truthSummaryTool->getBarcode(id); - int pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + int barcode=-1,pdg=0; + if(m_isMC){ + barcode = m_truthSummaryTool->getBarcode(id); + pdg = barcode != -1 ? m_truthSummaryTool->getPdgId(barcode) : 0; + } m_ntuple.hitBlock.truth.fill(pdg,barcode); float sign = expos < 0 ? -1. : 1.; diff --git a/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonRecoValidationTool.h b/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonRecoValidationTool.h index 54eb3dcd28e..ad783a29498 100644 --- a/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonRecoValidationTool.h +++ b/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonRecoValidationTool.h @@ -119,6 +119,8 @@ namespace Muon { TTree* m_tree; unsigned int m_candidateCounter; + + bool m_isMC; }; } diff --git a/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuGirlTagTool.py b/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuGirlTagTool.py index 62e0b6fb270..8cf4920ee27 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuGirlTagTool.py +++ b/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuGirlTagTool.py @@ -4,6 +4,7 @@ from AthenaCommon import CfgMgr from AthenaCommon.CfgGetter import getPublicTool,getService +from AthenaCommon.GlobalFlags import globalflags from RecExConfig.RecFlags import rec @@ -48,6 +49,8 @@ def MuonLayerAmbiguitySolverTool( name="MuonLayerAmbiguitySolverTool",**kwargs): return CfgMgr.Muon__MuonLayerAmbiguitySolverTool(name,**kwargs) def MuonRecoValidationTool( name="MuonRecoValidationTool",**kwargs): + if globalflags.DataSource() != 'data': + kwargs.setdefault("isMC",True) return CfgMgr.Muon__MuonRecoValidationTool(name,**kwargs) def DCMathStauSegmentMaker( name="DCMathStauSegmentMaker", **kwargs ): -- GitLab