diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces/MuonRecToolInterfaces/IMuonTrackTruthTool.h b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces/MuonRecToolInterfaces/IMuonTrackTruthTool.h index bb4857d66f4f82e7cdbffb9ac0e94b52a8dba5cd..067446f3d55bf62ddecdd9ad233f487867c61413 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces/MuonRecToolInterfaces/IMuonTrackTruthTool.h +++ b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces/MuonRecToolInterfaces/IMuonTrackTruthTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef MUON_IMUONTRACKTRUTHTOOL_H @@ -43,7 +43,7 @@ namespace Muon { class MuonTrackTruth { public: const TrackRecord* truthTrack; - const TruthTrajectory* truthTrajectory; + std::shared_ptr<const TruthTrajectory> truthTrajectory; bool isHitMatched; bool isParameterMatched; MuonTechnologyTruth mdts; @@ -78,7 +78,7 @@ namespace Muon { public: struct TruthTreeEntry { const TrackRecord* truthTrack; - const TruthTrajectory* truthTrajectory; + std::shared_ptr<const TruthTrajectory> truthTrajectory; MuonSimDataCollection mdtHits; CscSimDataCollection cscHits; MuonSimDataCollection rpcHits; @@ -98,6 +98,7 @@ namespace Muon { // collect track record entries per barcode typedef std::map<int,TruthTreeEntry> TruthTree; typedef TruthTree::iterator TruthTreeIt; + typedef TruthTree::const_iterator TruthTreeConstIt; public: /** access to tool interface */ @@ -105,28 +106,28 @@ namespace Muon { /** @brief perform truth matching for a given set of tracks */ - virtual ResultVec match(const TrackCollection& tracks ) const = 0; + virtual ResultVec match(const TruthTree& truth_tree, const TrackCollection& tracks ) const = 0; /** @brief perform truth matching for a given set of segments */ - virtual SegmentResultVec match(const std::vector<const MuonSegment*>& segments ) const = 0; + virtual SegmentResultVec match(const TruthTree& truth_tree, const std::vector<const MuonSegment*>& segments ) const = 0; /** create truth tree from sim data */ virtual const TruthTree createTruthTree(const TrackRecordCollection* truthTrackCol, const McEventCollection* mcEventCollection, std::vector<const MuonSimDataCollection*> muonSimData, const CscSimDataCollection* cscSimDataMap) const = 0; /** @brief get track truth */ - virtual MuonTrackTruth getTruth( const Trk::Track& track, bool restrictedTruth = false ) const = 0; + virtual MuonTrackTruth getTruth(const TruthTree& truth_tree, const Trk::Track& track, bool restrictedTruth = false ) const = 0; /** @brief get segment truth for a list of segments, the segments will be considered to belong to the same muon */ - virtual MuonTrackTruth getTruth( const std::vector<const MuonSegment*>& segments, bool restrictedTruth = false ) const = 0; + virtual MuonTrackTruth getTruth(const TruthTree& truth_tree, const std::vector<const MuonSegment*>& segments, bool restrictedTruth = false ) const = 0; /** @brief get segment truth */ - virtual MuonTrackTruth getTruth( const Muon::MuonSegment& segment ) const = 0; + virtual MuonTrackTruth getTruth(const TruthTree& truth_tree, const Muon::MuonSegment& segment ) const = 0; /** @brief get truth for a give set of hits. If restrictedTruth is set to true only missed hits in chambers with hits will be counted. */ - virtual MuonTrackTruth getTruth( const std::vector<const Trk::MeasurementBase*>& measurements, bool restrictedTruth = false ) const = 0; + virtual MuonTrackTruth getTruth(const TruthTree& truth_tree, const std::vector<const Trk::MeasurementBase*>& measurements, bool restrictedTruth = false ) const = 0; /// returns the mother particle of the particle with barcodeIn if it is found in the truth trajectory /// It traces the decay chain until if finds the first particle that is different flavor from the starting one. diff --git a/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/MuonTrackTruthTool.h b/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/MuonTrackTruthTool.h index d919b8381b1cc45a8e57d17b510176576fabed2e..891336afb13f0e4e735e43c2d0caa3f863fe5c23 100644 --- a/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/MuonTrackTruthTool.h +++ b/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/MuonTrackTruthTool.h @@ -66,27 +66,27 @@ namespace Muon { StatusCode initialize(); /** @brief perform truth matching for a given set of tracks */ - ResultVec match(const TrackCollection& tracks ) const; + ResultVec match(const TruthTree& truth_tree, const TrackCollection& tracks ) const; /** @brief perform truth matching for a given set of segments */ - SegmentResultVec match(const std::vector<const MuonSegment*>& segments ) const; + SegmentResultVec match(const TruthTree& truth_tree, const std::vector<const MuonSegment*>& segments ) const; /** @brief get track truth */ - MuonTrackTruth getTruth( const Trk::Track& track, bool restrictedTruth = false ) const; + MuonTrackTruth getTruth(const TruthTree& truth_tree, const Trk::Track& track, bool restrictedTruth = false ) const; /** @brief get segment truth for a list of segments, the segments will be considered to belong to the same muon */ - MuonTrackTruth getTruth( const std::vector<const MuonSegment*>& segments, bool restrictedTruth = false ) const; + MuonTrackTruth getTruth(const TruthTree& truth_tree, const std::vector<const MuonSegment*>& segments, bool restrictedTruth = false ) const; /** @brief get segment truth */ - MuonTrackTruth getTruth( const Muon::MuonSegment& segment ) const; + MuonTrackTruth getTruth(const TruthTree& truth_tree, const Muon::MuonSegment& segment ) const; /** @brief get truth for a give set of hits. If restrictedTruth is set to true only missed hits in chambers with hits will be counted. */ - MuonTrackTruth getTruth( const std::vector<const Trk::MeasurementBase*>& measurements, bool restrictedTruth = false ) const; + MuonTrackTruth getTruth(const TruthTree& truth_tree, const std::vector<const Trk::MeasurementBase*>& measurements, bool restrictedTruth = false ) const; /** create truth tree from sim data */ - const TruthTree createTruthTree(const TrackRecordCollection* truthTrackCol, const McEventCollection* mcEventCollection, + const TruthTree createTruthTree( const TrackRecordCollection* truthTrackCol, const McEventCollection* mcEventCollection, std::vector<const MuonSimDataCollection*> muonSimData, const CscSimDataCollection* cscSimDataMap) const; /// Returns the mother particle of the particle with barcodeIn if it is found in the truth trajectory. @@ -108,11 +108,15 @@ namespace Muon { private: - MuonTrackTruth getTruth( const std::vector<const Trk::MeasurementBase*>& measurements, - TruthTreeEntry& truthEntry, bool restrictedTruth ) const; + MuonTrackTruth getTruth(const std::vector<const Trk::MeasurementBase*>& measurements, + const TruthTreeEntry& truthEntry, bool restrictedTruth ) const; - void addSimDataToTree( const MuonSimDataCollection* simDataCol ) const; - void addCscSimDataToTree( const CscSimDataCollection* simDataCol ) const; + void addSimDataToTree(TruthTree& truth_tree, + std::map<int,int>& barcode_map, + const MuonSimDataCollection* simDataCol ) const; + void addCscSimDataToTree(TruthTree& truth_tree, + std::map<int,int>& barcode_map, + const CscSimDataCollection* simDataCol ) const; void addMdtTruth( MuonTechnologyTruth& trackTruth, const Identifier& id, const Trk::MeasurementBase& meas, const MuonSimDataCollection& simCol ) const; @@ -130,8 +134,7 @@ namespace Muon { int manipulateBarCode( int barcode ) const; - void clear() const; - + bool selectPdg( int pdg ) const { return m_selectedPdgs.count(pdg); } /// Returns the initial particle of the particle with barcodeIn if it is found in the truth trajectory. @@ -146,10 +149,7 @@ namespace Muon { ToolHandle<Muon::MuonEDMPrinterTool> m_printer{this,"Printer","Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"}; ToolHandle<Trk::ITruthTrajectoryBuilder> m_truthTrajectoryBuilder{this,"TruthTrajectoryBuilder","Muon::MuonDecayTruthTrajectoryBuilder/MuonDecayTruthTrajectoryBuilder"}; - mutable TruthTree m_truthTree; - mutable std::vector<std::unique_ptr<TruthTrajectory> > m_truthTrajectoriesToBeDeleted; - mutable std::map<int,int> m_barcodeMap; // map used to link barcode of TrackRecord particles/hits to 'final' state barcode - + Gaudi::Property<bool> m_manipulateBarCode{this,"ManipulateBarCode",false}; Gaudi::Property<bool> m_doSummary{this,"DoSummary",false}; Gaudi::Property<bool> m_matchAllParticles{this,"MatchAllParticles",true}; diff --git a/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/TrackParticleTruthMaker.h b/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/TrackParticleTruthMaker.h deleted file mode 100755 index 602428cee49aa679fbba34c28696e08ecbd2106e..0000000000000000000000000000000000000000 --- a/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/TrackParticleTruthMaker.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/////////////////////////////////////////////////////////////////// -// TrackParticleTruthMaker.h -// Header file for class TrackParticleTruthMaker -/////////////////////////////////////////////////////////////////// - -#ifndef TRUTHPARTICLEALGS_TRACKPARTICLETRUTHMAKER_H -#define TRUTHPARTICLEALGS_TRACKPARTICLETRUTHMAKER_H - -#include "AthenaBaseComps/AthAlgorithm.h" -#include <string> - -namespace Muon { - -class TrackParticleTruthMaker : public AthAlgorithm { - -public: - - // Constructor with parameters: - TrackParticleTruthMaker(const std::string &name,ISvcLocator *pSvcLocator); - - /////////////////////////////////////////////////////////////////// - // Non-const methods: - /////////////////////////////////////////////////////////////////// - - // Basic algorithm methods: - virtual StatusCode initialize(); - virtual StatusCode execute(); - virtual StatusCode finalize(); - - /////////////////////////////////////////////////////////////////// - // Private methods: - /////////////////////////////////////////////////////////////////// -private: - TrackParticleTruthMaker(); - TrackParticleTruthMaker(const TrackParticleTruthMaker&); - TrackParticleTruthMaker &operator=(const TrackParticleTruthMaker&); - - /////////////////////////////////////////////////////////////////// - // Private data: - /////////////////////////////////////////////////////////////////// -private: - - std::string m_trackParticlesName; - std::string m_trackParticleTruthCollection; - std::string m_tracksName; - std::string m_tracksTruthName; - -}; - -} // namespace Muon - - -#endif //TRUTHPARTICLEALGS_TRACKPARTICLETRUTHMAKER_H diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonSegmentTruthAssociationAlg.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonSegmentTruthAssociationAlg.cxx index be594782038c51d12d070f272703eb08a7ade61c..c078ac608884b0c513660fef6011902b7ada00f8 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonSegmentTruthAssociationAlg.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonSegmentTruthAssociationAlg.cxx @@ -15,7 +15,7 @@ namespace Muon { // Constructor with parameters: MuonSegmentTruthAssociationAlg::MuonSegmentTruthAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator) : - AthAlgorithm(name,pSvcLocator) { + AthReentrantAlgorithm(name,pSvcLocator) { } // Initialize method: @@ -37,12 +37,12 @@ namespace Muon { } // Execute method: - StatusCode MuonSegmentTruthAssociationAlg::execute() + StatusCode MuonSegmentTruthAssociationAlg::execute(const EventContext& ctx) const { // skip if no input data found - SG::WriteDecorHandle<xAOD::MuonSegmentContainer,ElementLink< xAOD::MuonSegmentContainer > > muonTruthSegments(m_muonTruthSegmentContainerName); - SG::WriteDecorHandle<xAOD::MuonSegmentContainer,ElementLink< xAOD::MuonSegmentContainer > > segments(m_muonSegmentCollectionName); + SG::WriteDecorHandle<xAOD::MuonSegmentContainer,ElementLink< xAOD::MuonSegmentContainer > > muonTruthSegments(m_muonTruthSegmentContainerName,ctx); + SG::WriteDecorHandle<xAOD::MuonSegmentContainer,ElementLink< xAOD::MuonSegmentContainer > > segments(m_muonSegmentCollectionName,ctx); if(!muonTruthSegments.isPresent()){ ATH_MSG_DEBUG("No muon truth segments"); return StatusCode::SUCCESS; @@ -59,7 +59,7 @@ namespace Muon { ATH_MSG_ERROR("Muon segments not valid"); return StatusCode::FAILURE; } - SG::ReadHandle<TrackRecordCollection> truthTrackCol(m_trackRecord); + SG::ReadHandle<TrackRecordCollection> truthTrackCol(m_trackRecord, ctx); if (!truthTrackCol.isValid()){ ATH_MSG_ERROR("Track collection "<<m_trackRecord.key()<<" is not present"); return StatusCode::FAILURE; @@ -94,9 +94,9 @@ namespace Muon { ++segIndex; } - SG::ReadHandle<McEventCollection> mcEventCollection(m_mcEventColl); + SG::ReadHandle<McEventCollection> mcEventCollection(m_mcEventColl, ctx); std::vector<const MuonSimDataCollection*> muonSimData; - for(SG::ReadHandle<MuonSimDataCollection>& simDataMap : m_muonSimData.makeHandles()){ + for(SG::ReadHandle<MuonSimDataCollection>& simDataMap : m_muonSimData.makeHandles(ctx)){ if(!simDataMap.isValid()){ ATH_MSG_WARNING(simDataMap.key()<<" not valid"); continue; @@ -104,19 +104,21 @@ namespace Muon { if(!simDataMap.isPresent()) continue; muonSimData.push_back(simDataMap.cptr()); } + IMuonTrackTruthTool::TruthTree truth_tree; if(m_idHelperSvc->hasCSC()){ - SG::ReadHandle<CscSimDataCollection> cscSimDataMap(m_cscSimData); + SG::ReadHandle<CscSimDataCollection> cscSimDataMap(m_cscSimData, ctx); if(!cscSimDataMap.isValid()){ ATH_MSG_WARNING(cscSimDataMap.key()<<" not valid"); - m_muonTrackTruthTool->createTruthTree(truthTrackCol.cptr(),mcEventCollection.cptr(),muonSimData,nullptr); + truth_tree = m_muonTrackTruthTool->createTruthTree(truthTrackCol.cptr(),mcEventCollection.cptr(),muonSimData,nullptr); } else{ - m_muonTrackTruthTool->createTruthTree(truthTrackCol.cptr(),mcEventCollection.cptr(),muonSimData,cscSimDataMap.cptr()); + truth_tree = m_muonTrackTruthTool->createTruthTree(truthTrackCol.cptr(),mcEventCollection.cptr(),muonSimData,cscSimDataMap.cptr()); } + } else { + truth_tree = m_muonTrackTruthTool->createTruthTree(truthTrackCol.cptr(),mcEventCollection.cptr(),muonSimData,nullptr); } - else m_muonTrackTruthTool->createTruthTree(truthTrackCol.cptr(),mcEventCollection.cptr(),muonSimData,nullptr); ATH_MSG_DEBUG("Matching reconstructed segments " << muonSegments.size() ); - IMuonTrackTruthTool::SegmentResultVec segmentMatchResult = m_muonTrackTruthTool->match(muonSegments); + IMuonTrackTruthTool::SegmentResultVec segmentMatchResult = m_muonTrackTruthTool->match(truth_tree, muonSegments); // create a map of chamber index onto the truth segments std::map<Muon::MuonStationIndex::ChIndex, std::vector<ElementLink< xAOD::MuonSegmentContainer> > > chamberTruthSegmentLinks; diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonSegmentTruthAssociationAlg.h b/MuonSpectrometer/MuonTruthAlgs/src/MuonSegmentTruthAssociationAlg.h index d3d0a4979d7d836d085160bdce3cc2db59274a54..b38bd05e724a76bcefa9d4fba74f4270118d240a 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonSegmentTruthAssociationAlg.h +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonSegmentTruthAssociationAlg.h @@ -1,11 +1,11 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRUTHPARTICLEALGS_MUONSEGMENTTRUTHASSOCIATION_H #define TRUTHPARTICLEALGS_MUONSEGMENTTRUTHASSOCIATION_H -#include "AthenaBaseComps/AthAlgorithm.h" +#include "AthenaBaseComps/AthReentrantAlgorithm.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" @@ -23,15 +23,15 @@ namespace Muon { -class MuonSegmentTruthAssociationAlg : public AthAlgorithm { +class MuonSegmentTruthAssociationAlg : public AthReentrantAlgorithm { public: // Constructor with parameters: MuonSegmentTruthAssociationAlg(const std::string &name,ISvcLocator *pSvcLocator); // Basic algorithm methods: - virtual StatusCode initialize(); - virtual StatusCode execute(); + virtual StatusCode initialize() override; + virtual StatusCode execute(const EventContext& ctx) const override; private: ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTrackTruthTool.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonTrackTruthTool.cxx index 8b81b7eee306aa984769b9aca88e33359814d6f3..97994280275cca783faa26f8ef42999361d2bd4c 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTrackTruthTool.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonTrackTruthTool.cxx @@ -76,7 +76,8 @@ namespace Muon { - MuonTrackTruthTool::ResultVec MuonTrackTruthTool::match( const TrackCollection& tracks ) const { + MuonTrackTruthTool::ResultVec MuonTrackTruthTool::match(const TruthTree& truth_tree, + const TrackCollection& tracks ) const { ResultVec result; result.reserve(tracks.size()); @@ -85,7 +86,7 @@ namespace Muon { TrackCollection::const_iterator tit_end = tracks.end(); for( ;tit!=tit_end;++tit ){ - MuonTrackTruth match = getTruth(**tit); + MuonTrackTruth match = getTruth(truth_tree, **tit); if( !match.truthTrack ) continue; if( match.numberOfMatchedHits() == 0 ) continue; @@ -100,7 +101,8 @@ namespace Muon { return result; } - MuonTrackTruthTool::SegmentResultVec MuonTrackTruthTool::match(const std::vector<const MuonSegment*>& segments ) const { + MuonTrackTruthTool::SegmentResultVec MuonTrackTruthTool::match(const TruthTree& truth_tree, + const std::vector<const MuonSegment*>& segments ) const { SegmentResultVec result; result.reserve(segments.size()); @@ -110,7 +112,7 @@ namespace Muon { for( ;sit!=sit_end;++sit ){ // create truth association - result.push_back( std::make_pair(*sit,getTruth(**sit)) ); + result.push_back( std::make_pair(*sit,getTruth(truth_tree, **sit)) ); } // sort result per muon and per number of matched hits @@ -123,11 +125,11 @@ namespace Muon { std::vector<const MuonSimDataCollection*> muonSimData, const CscSimDataCollection* cscSimDataMap) const { - clear(); - + std::map<int,int> barcode_map; + MuonTrackTruthTool::TruthTree truth_tree; if( truthTrackCol->empty() ) { ATH_MSG_WARNING(" TrackRecordCollection is empty "); - return m_truthTree; + return truth_tree; } const HepMC::GenEvent* genEvent = nullptr; @@ -150,8 +152,8 @@ namespace Muon { } // check whether barcode is already in, skip if that is the case - if( m_barcodeMap.count(barcode) ){ - ATH_MSG_VERBOSE(" barcode " << barcode << " already in map, final state barcode " << m_barcodeMap[barcode]); + if( barcode_map.count(barcode) ){ + ATH_MSG_VERBOSE(" barcode " << barcode << " already in map, final state barcode " << barcode_map[barcode]); continue; } ATH_MSG_VERBOSE(" found new particle with pdgid " << PDGCode << " in truth record, barcode " << barcode); @@ -199,45 +201,46 @@ namespace Muon { if( (*pit)->production_vertex() ) ATH_MSG_VERBOSE(" vertex: r " << (*pit)->production_vertex()->position().perp() << " z " << (*pit)->production_vertex()->position().z()); // sanity check - if( m_barcodeMap.count(code) ) ATH_MSG_VERBOSE(" pre-existing barcode " << code); + if( barcode_map.count(code) ) ATH_MSG_VERBOSE(" pre-existing barcode " << code); } // enter barcode - m_barcodeMap[code] = barcode; + barcode_map[code] = barcode; } }else{ ATH_MSG_WARNING(" empty truth trajectory " << barcode); } } }else{ - // add one to one relation - m_barcodeMap[barcode] = barcode; + // add one to one relation + barcode_map[barcode] = barcode; } - if( m_truthTree.count(barcode) ) { + if( truth_tree.count(barcode) ) { ATH_MSG_WARNING(" found muon barcode twice in truth record: " << barcode); continue; } - TruthTreeEntry& entry = m_truthTree[barcode]; + TruthTreeEntry& entry = truth_tree[barcode]; entry.truthTrack = &(*tr_it); - entry.truthTrajectory = truthTrajectory.get(); - m_truthTrajectoriesToBeDeleted.push_back(std::move(truthTrajectory)); + //entry.truthTrajectory = truthTrajectory.get(); + entry.truthTrajectory = std::move(truthTrajectory); + //m_truthTrajectoriesToBeDeleted.push_back(std::move(truthTrajectory)); } // add sim data collections for(const MuonSimDataCollection* simDataMap : muonSimData){ - addSimDataToTree(simDataMap); + addSimDataToTree(truth_tree, barcode_map,simDataMap); } if(cscSimDataMap){ - addCscSimDataToTree(cscSimDataMap); + addCscSimDataToTree(truth_tree, barcode_map,cscSimDataMap); } unsigned int ngood(0); std::vector<int> badBarcodes; // erase entries with too few hits or no track record - TruthTreeIt it = m_truthTree.begin(); - for( ;it!=m_truthTree.end();++it ){ + TruthTreeIt it = truth_tree.begin(); + for( ;it!=truth_tree.end();++it ){ bool erase = false; unsigned int nhits = it->second.mdtHits.size() + it->second.rpcHits.size() + it->second.tgcHits.size() + it->second.cscHits.size() + it->second.stgcHits.size() + it->second.mmHits.size(); @@ -257,17 +260,17 @@ namespace Muon { std::vector<int>::iterator badIt = badBarcodes.begin(); std::vector<int>::iterator badIt_end = badBarcodes.end(); - for( ;badIt!=badIt_end;++badIt ) m_truthTree.erase(*badIt); + for( ;badIt!=badIt_end;++badIt ) truth_tree.erase(*badIt); - if( ngood != m_truthTree.size() ){ - ATH_MSG_WARNING(" Problem cleaning map: size " << m_truthTree.size() << " accepted entries " << ngood); + if( ngood != truth_tree.size() ){ + ATH_MSG_WARNING(" Problem cleaning map: size " << truth_tree.size() << " accepted entries " << ngood); } if( m_doSummary || msgLvl(MSG::DEBUG) ){ - ATH_MSG_INFO(" summarizing truth tree: number of particles " << m_truthTree.size()); - TruthTreeIt it = m_truthTree.begin(); - TruthTreeIt it_end = m_truthTree.end(); + ATH_MSG_INFO(" summarizing truth tree: number of particles " << truth_tree.size()); + TruthTreeIt it = truth_tree.begin(); + TruthTreeIt it_end = truth_tree.end(); for( ;it!=it_end;++it ){ if( !it->second.truthTrack ) ATH_MSG_INFO(" no TrackRecord "); else{ @@ -285,11 +288,13 @@ namespace Muon { } } - return m_truthTree; + return truth_tree; } - void MuonTrackTruthTool::addSimDataToTree( const MuonSimDataCollection* simDataCol ) const { + void MuonTrackTruthTool::addSimDataToTree(TruthTree& truth_tree, + std::map<int,int>& barcode_map, + const MuonSimDataCollection* simDataCol ) const { // loop over sim collection and check whether identifiers are on track MuonSimDataCollection::const_iterator it = simDataCol->begin(); @@ -303,16 +308,16 @@ namespace Muon { std::vector<MuonSimData::Deposit>::const_iterator dit_end = it->second.getdeposits().end(); for( ;dit!=dit_end;++dit ){ int barcodeIn = dit->first.barcode(); - std::map<int,int>::iterator bit = m_barcodeMap.find(barcodeIn); - if( bit == m_barcodeMap.end() ){ + std::map<int,int>::const_iterator bit = barcode_map.find(barcodeIn); + if( bit == barcode_map.end() ){ ATH_MSG_VERBOSE( " discarding " << " " << m_idHelperSvc->toString(id) << " barcode " << barcodeIn); continue; } // replace barcode with barcode from map int barcode = bit->second; - TruthTreeIt eit = m_truthTree.find(barcode); - if( eit == m_truthTree.end() ){ + TruthTreeIt eit = truth_tree.find(barcode); + if( eit == truth_tree.end() ){ ATH_MSG_VERBOSE( " discarding " << " " << m_idHelperSvc->toString(id) << " barcode " << barcode); continue; } @@ -367,7 +372,7 @@ namespace Muon { } } - void MuonTrackTruthTool::addCscSimDataToTree( const CscSimDataCollection* simDataCol ) const { + void MuonTrackTruthTool::addCscSimDataToTree(TruthTree& truth_tree, std::map<int,int>& barcode_map, const CscSimDataCollection* simDataCol ) const { // loop over sim collection and check whether identifiers are on track CscSimDataCollection::const_iterator it = simDataCol->begin(); @@ -382,16 +387,16 @@ namespace Muon { for( ;dit!=dit_end;++dit ){ int barcodeIn = manipulateBarCode(dit->first.barcode()); - std::map<int,int>::iterator bit = m_barcodeMap.find(barcodeIn); - if( bit == m_barcodeMap.end() ){ + std::map<int,int>::const_iterator bit = barcode_map.find(barcodeIn); + if( bit == barcode_map.end() ){ ATH_MSG_VERBOSE( " discarding " << " " << m_idHelperSvc->toString(id) << " barcode " << barcodeIn); continue; } // replace barcode with barcode from map int barcode = bit->second; - TruthTreeIt eit = m_truthTree.find(barcode); - if( eit == m_truthTree.end() ){ + TruthTreeIt eit = truth_tree.find(barcode); + if( eit == truth_tree.end() ){ ATH_MSG_VERBOSE( " discarding " << " " << m_idHelperSvc->toString(id) << " barcode " << barcode); continue; } @@ -405,18 +410,23 @@ namespace Muon { } } - MuonTrackTruth MuonTrackTruthTool::getTruth( const Muon::MuonSegment& segment ) const { + MuonTrackTruth MuonTrackTruthTool::getTruth(const TruthTree& truth_tree, + const Muon::MuonSegment& segment ) const { - return getTruth(segment.containedMeasurements(),true); + return getTruth(truth_tree, segment.containedMeasurements(),true); } - MuonTrackTruth MuonTrackTruthTool::getTruth( const Trk::Track& track, bool restrictedTruth ) const { - if( track.measurementsOnTrack() ) return getTruth(track.measurementsOnTrack()->stdcont(),restrictedTruth); + MuonTrackTruth MuonTrackTruthTool::getTruth( const TruthTree& truth_tree, + const Trk::Track& track, + bool restrictedTruth ) const { + if( track.measurementsOnTrack() ) return getTruth(truth_tree, track.measurementsOnTrack()->stdcont(),restrictedTruth); return MuonTrackTruth(); } - MuonTrackTruth MuonTrackTruthTool::getTruth( const std::vector<const MuonSegment*>& segments, bool restrictedTruth ) const { + MuonTrackTruth MuonTrackTruthTool::getTruth(const TruthTree& truth_tree, + const std::vector<const MuonSegment*>& segments, + bool restrictedTruth ) const { Trk::RoT_Extractor rotExtractor; std::set<Identifier> ids; std::vector<const Trk::MeasurementBase*> measurements; @@ -440,12 +450,13 @@ namespace Muon { ids.insert(id); } } - return getTruth(measurements,restrictedTruth); + return getTruth(truth_tree, measurements,restrictedTruth); } - MuonTrackTruth MuonTrackTruthTool::getTruth( const std::vector<const Trk::MeasurementBase*>& measurements, - bool restrictedTruth ) const { + MuonTrackTruth MuonTrackTruthTool::getTruth(const TruthTree& truth_tree, + const std::vector<const Trk::MeasurementBase*>& measurements, + bool restrictedTruth ) const { MuonTrackTruth bestMatch; bestMatch.truthTrack = 0; @@ -453,8 +464,8 @@ namespace Muon { unsigned int nmatchedHitsBest = 0; // loop over muons and match hits - TruthTreeIt tit = m_truthTree.begin(); - TruthTreeIt tit_end = m_truthTree.end(); + TruthTreeConstIt tit = truth_tree.begin(); + TruthTreeConstIt tit_end = truth_tree.end(); for( ;tit!=tit_end;++tit ){ unsigned int nhits = tit->second.mdtHits.size() + tit->second.cscHits.size() + tit->second.rpcHits.size() + tit->second.tgcHits.size() @@ -474,8 +485,8 @@ namespace Muon { return bestMatch; } - MuonTrackTruth MuonTrackTruthTool::getTruth( const std::vector<const Trk::MeasurementBase*>& measurements, - TruthTreeEntry& truthEntry, bool restrictedTruth ) const { + MuonTrackTruth MuonTrackTruthTool::getTruth(const std::vector<const Trk::MeasurementBase*>& measurements, + const TruthTreeEntry& truthEntry, bool restrictedTruth ) const { Trk::RoT_Extractor rotExtractor; MuonTrackTruth trackTruth; @@ -492,7 +503,7 @@ namespace Muon { continue; } - const Trk::RIO_OnTrack* rot = 0; + const Trk::RIO_OnTrack* rot = nullptr; rotExtractor.extract(rot,meas); if( !rot ) { if( !dynamic_cast<const Trk::PseudoMeasurementOnTrack*>(meas) ) ATH_MSG_WARNING(" Could not get rot from measurement "); @@ -704,12 +715,6 @@ namespace Muon { } } - void MuonTrackTruthTool::clear() const { - m_truthTree.clear(); - m_barcodeMap.clear(); - m_truthTrajectoriesToBeDeleted.clear(); - } - HepMC::ConstGenParticlePtr MuonTrackTruthTool::getMother( const TruthTrajectory& traj, const int barcodeIn ) const { ATH_MSG_DEBUG( "getMother() : size = " << traj.size() ); int pdgFinal = ( (traj.size()==0)? -999 : traj.front()->pdg_id()); diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.cxx index 902d2082c81f56edbba73422de49b1088e435a44..9e1e1fb204f3fe0a958e22261863521ecfeac68b 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.cxx @@ -10,9 +10,16 @@ #include "MuonCompetingRIOsOnTrack/CompetingMuonClustersOnTrack.h" #include "StoreGate/WriteDecorHandle.h" +namespace { + constexpr unsigned int dummy_unsigned = 999; + void increment_unsigned(unsigned& val){ + if (val == dummy_unsigned) val = 1; + else ++val; + } +} // Constructor with parameters: MuonTruthAssociationAlg::MuonTruthAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator) : - AthAlgorithm(name,pSvcLocator) + AthReentrantAlgorithm(name,pSvcLocator) {} // Initialize method: @@ -40,26 +47,25 @@ StatusCode MuonTruthAssociationAlg::initialize() } // Execute method: -StatusCode MuonTruthAssociationAlg::execute() -{ +StatusCode MuonTruthAssociationAlg::execute(const EventContext& ctx) const { - SG::WriteDecorHandle<xAOD::TruthParticleContainer,ElementLink< xAOD::MuonContainer > > muonTruthParticleRecoLink(m_muonTruthParticleContainerName); + SG::WriteDecorHandle<xAOD::TruthParticleContainer,ElementLink< xAOD::MuonContainer > > muonTruthParticleRecoLink(m_muonTruthParticleContainerName,ctx); if(!muonTruthParticleRecoLink.isPresent()) return StatusCode::SUCCESS; if(!muonTruthParticleRecoLink.isValid()){ ATH_MSG_WARNING("truth particle container not valid"); return StatusCode::FAILURE; } - SG::WriteDecorHandle<xAOD::MuonContainer,ElementLink<xAOD::TruthParticleContainer> > muonTruthParticleLink(m_muonTruthParticleLink); + SG::WriteDecorHandle<xAOD::MuonContainer,ElementLink<xAOD::TruthParticleContainer> > muonTruthParticleLink(m_muonTruthParticleLink,ctx); if(!muonTruthParticleLink.isPresent()) return StatusCode::SUCCESS; if(!muonTruthParticleLink.isValid()){ ATH_MSG_WARNING("muon particle container not valid"); return StatusCode::FAILURE; } - SG::WriteDecorHandle<xAOD::MuonContainer,int > muonTruthParticleType(m_muonTruthParticleType); - SG::WriteDecorHandle<xAOD::MuonContainer,int > muonTruthParticleOrigin(m_muonTruthParticleOrigin); - SG::WriteDecorHandle<xAOD::MuonContainer,std::vector<unsigned int> > muonTruthParticleNPrecMatched(m_muonTruthParticleNPrecMatched); - SG::WriteDecorHandle<xAOD::MuonContainer,std::vector<unsigned int> > muonTruthParticleNPhiMatched(m_muonTruthParticleNPhiMatched); - SG::WriteDecorHandle<xAOD::MuonContainer,std::vector<unsigned int> > muonTruthParticleNTrigEtaMatched(m_muonTruthParticleNTrigEtaMatched); + SG::WriteDecorHandle<xAOD::MuonContainer,int > muonTruthParticleType(m_muonTruthParticleType,ctx); + SG::WriteDecorHandle<xAOD::MuonContainer,int > muonTruthParticleOrigin(m_muonTruthParticleOrigin,ctx); + SG::WriteDecorHandle<xAOD::MuonContainer,std::vector<unsigned int> > muonTruthParticleNPrecMatched(m_muonTruthParticleNPrecMatched,ctx); + SG::WriteDecorHandle<xAOD::MuonContainer,std::vector<unsigned int> > muonTruthParticleNPhiMatched(m_muonTruthParticleNPhiMatched,ctx); + SG::WriteDecorHandle<xAOD::MuonContainer,std::vector<unsigned int> > muonTruthParticleNTrigEtaMatched(m_muonTruthParticleNTrigEtaMatched,ctx); // add link to reco muons and viceversa @@ -68,276 +74,191 @@ StatusCode MuonTruthAssociationAlg::execute() for( const auto muon : *muonTruthParticleLink ){ // use primary track particle to get the truth link (except for the case of STACO, where we must use the ID track particle, as the combined is not truth-matched) ATH_MSG_DEBUG("muon with pT "<<muon->pt()<<" and author "<<muon->author()); - const xAOD::TrackParticle* tp(0); - if (m_associateWithInDetTP || muon->author()==2 || muon->author()==6 ) { + const xAOD::TrackParticle* tp= nullptr; + if (m_associateWithInDetTP || muon->author()==xAOD::Muon::STACO || muon->author()==xAOD::Muon::MuGirl) { tp = muon->trackParticle(xAOD::Muon::InnerDetectorTrackParticle); - } - else{ + } else{ tp=muon->primaryTrackParticle(); } - if( !tp ){ - ATH_MSG_DEBUG("no track particle associated?"); - muonTruthParticleLink(*muon)=ElementLink<xAOD::TruthParticleContainer>(); - muonTruthParticleOrigin(muonInd)=-99999; - muonTruthParticleType(muonInd)=-99999; - //add these empty vectors - std::vector<unsigned int> nprecHitsPerChamberLayer; - std::vector<unsigned int> nphiHitsPerChamberLayer; - std::vector<unsigned int> ntrigEtaHitsPerChamberLayer; - muonTruthParticleNPrecMatched(muonInd)=nprecHitsPerChamberLayer; - muonTruthParticleNPhiMatched(muonInd)=nphiHitsPerChamberLayer; - muonTruthParticleNTrigEtaMatched(muonInd)=ntrigEtaHitsPerChamberLayer; - continue; + bool foundTruth=false; + + if (tp){ + // Associate reco with truth muon. Loop over reconstructed muons, get track particle for each one. + //Each track particle should carry a link to the corresponding truth particle. Then compare this truth particle link with the given truth muon particle + try { + ElementLink< xAOD::TruthParticleContainer > truthLink = tp->auxdata<ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink"); + if (truthLink.isValid() ){ + ATH_MSG_VERBOSE(" Got valid truth link for muon author " << muon->author() << " barcode " << (*truthLink)->barcode()); + // loop over truth particles + + for( const auto truthParticle : *muonTruthParticleRecoLink ){ + if( truthParticle->status() != 1 ) continue; + ATH_MSG_DEBUG("Got truth muon with barcode " << truthParticle->barcode() << " pt "<< truthParticle->pt()); + ElementLink< xAOD::MuonContainer > muonLink; + if( ((*truthLink)->barcode())%m_barcodeOffset != truthParticle->barcode() ) { + continue; + } + ATH_MSG_VERBOSE("Truth muon barcode matches -> creating link with truth particle " << (*truthLink)->barcode() ); + foundTruth=true; + muonLink = ElementLink< xAOD::MuonContainer >(muon,*muonTruthParticleLink); + // add the link from xAOD::Muon to TruthParticle in m_muonTruthParticleContainerName + ElementLink< xAOD::TruthParticleContainer > muonTruthLink = ElementLink< xAOD::TruthParticleContainer >(truthParticle, *muonTruthParticleRecoLink); + muonTruthLink.toPersistent(); + muonTruthParticleLink(*muon)=muonTruthLink; + muonTruthParticleOrigin(muonInd)=tp->auxdata<int>("truthOrigin"); + muonTruthParticleType(muonInd)=tp->auxdata<int>("truthType"); + + /// Zero supression do not want to store meaningless zeros + std::vector<unsigned int> nprecHitsPerChamberLayer(Muon::MuonStationIndex::ChIndexMax, dummy_unsigned); + std::vector<unsigned int> nphiHitsPerChamberLayer(Muon::MuonStationIndex::PhiIndexMax, dummy_unsigned); + std::vector<unsigned int> ntrigEtaHitsPerChamberLayer(Muon::MuonStationIndex::PhiIndexMax, dummy_unsigned); + + count_chamber_layers( (muon->author()==xAOD::Muon::MuidCo || muon->author()==xAOD::Muon::MuidSA || muon->author()==xAOD::Muon::MuGirl)? truthParticle: nullptr, + tp->track(), + nprecHitsPerChamberLayer, + nphiHitsPerChamberLayer, + ntrigEtaHitsPerChamberLayer ); + /// Decorate the results + muonTruthParticleNPrecMatched(muonInd)=nprecHitsPerChamberLayer; + muonTruthParticleNPhiMatched(muonInd)=nphiHitsPerChamberLayer; + muonTruthParticleNTrigEtaMatched(muonInd)=ntrigEtaHitsPerChamberLayer; + + muonLink.toPersistent(); + muonTruthParticleRecoLink(*truthParticle)=muonLink; + break; + } + } + } catch ( const SG::ExcBadAuxVar& ) { + ATH_MSG_WARNING("Track particle is missing truthParticleLink variable!"); + } } - // Associate reco with truth muon. Loop over reconstructed muons, get track particle for each one. - //Each track particle should carry a link to the corresponding truth particle. Then compare this truth particle link with the given truth muon particle - try { - ElementLink< xAOD::TruthParticleContainer > truthLink = tp->auxdata<ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink"); - if( truthLink.isValid() ){ - ATH_MSG_VERBOSE(" Got valid truth link for muon author " << muon->author() << " barcode " << (*truthLink)->barcode()); - // loop over truth particles - bool foundTruth=false; - for( const auto truthParticle : *muonTruthParticleRecoLink ){ - if( truthParticle->status() != 1 ) continue; - ATH_MSG_DEBUG("Got truth muon with barcode " << truthParticle->barcode() << " pt "<< truthParticle->pt()); - ElementLink< xAOD::MuonContainer > muonLink; - - if( ((*truthLink)->barcode())%m_barcodeOffset == truthParticle->barcode() ) { - ATH_MSG_VERBOSE("Truth muon barcode matches -> creating link with truth particle " << (*truthLink)->barcode() ); - foundTruth=true; - muonLink = ElementLink< xAOD::MuonContainer >(muon,*muonTruthParticleLink); - // add the link from xAOD::Muon to TruthParticle in m_muonTruthParticleContainerName - ElementLink< xAOD::TruthParticleContainer > muonTruthLink = ElementLink< xAOD::TruthParticleContainer >(truthParticle, *muonTruthParticleRecoLink); - muonTruthLink.toPersistent(); - muonTruthParticleLink(*muon)=muonTruthLink; - muonTruthParticleOrigin(muonInd)=tp->auxdata<int>("truthOrigin"); - muonTruthParticleType(muonInd)=tp->auxdata<int>("truthType"); - if(muon->author()==1 || muon->author()==5 || muon->author()==6){ //only match hits for muons with MS tracks - if(!truthParticle->isAvailable<std::vector<unsigned long long> >("truthMdtHits")){ - ATH_MSG_DEBUG("muon with author "<<muon->author()<<" has no truth hits vector in the truth association alg"); - } - else{ - std::vector<unsigned long long> mdtTruth=truthParticle->auxdata<std::vector<unsigned long long> >("truthMdtHits"); - std::vector<unsigned long long> cscTruth; - if(m_idHelperSvc->hasCSC()) cscTruth=truthParticle->auxdata<std::vector<unsigned long long> >("truthCscHits"); - std::vector<unsigned long long> rpcTruth=truthParticle->auxdata<std::vector<unsigned long long> >("truthRpcHits"); - std::vector<unsigned long long> tgcTruth=truthParticle->auxdata<std::vector<unsigned long long> >("truthTgcHits"); - const Trk::Track* ptrk=tp->track(); - const DataVector<const Trk::TrackStateOnSurface>* trkstates = ptrk->trackStateOnSurfaces(); - DataVector<const Trk::TrackStateOnSurface>::const_reverse_iterator tsit = trkstates->rbegin(); - DataVector<const Trk::TrackStateOnSurface>::const_reverse_iterator tsit_end = trkstates->rend(); - std::vector<unsigned int> nprecHitsPerChamberLayer; - std::vector<unsigned int> nphiHitsPerChamberLayer; - std::vector<unsigned int> ntrigEtaHitsPerChamberLayer; - nprecHitsPerChamberLayer.resize(Muon::MuonStationIndex::ChIndexMax); - nphiHitsPerChamberLayer.resize(Muon::MuonStationIndex::PhiIndexMax); - ntrigEtaHitsPerChamberLayer.resize(Muon::MuonStationIndex::PhiIndexMax); - //zero-suppression: don't want to store meaningless zeroes (no truth or reco hits found) - for(unsigned int i=0;i<nprecHitsPerChamberLayer.size();i++) nprecHitsPerChamberLayer[i]=999; - for(unsigned int i=0;i<nphiHitsPerChamberLayer.size();i++) nphiHitsPerChamberLayer[i]=999; - for(unsigned int i=0;i<ntrigEtaHitsPerChamberLayer.size();i++) ntrigEtaHitsPerChamberLayer[i]=999; - for( ; tsit!=tsit_end ; ++tsit ){ - if(!*tsit) continue; - if(!(*tsit)->trackParameters() || !(*tsit)->measurementOnTrack()) continue; - const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); - Identifier id; - const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas); - if(rot) id=rot->identify(); - else{ - const Muon::CompetingMuonClustersOnTrack* crot = dynamic_cast<const Muon::CompetingMuonClustersOnTrack*>(meas); - if(crot){ - if( !crot->containedROTs().empty() && crot->containedROTs().front() ) id=crot->containedROTs().front()->identify(); - } - } - if(!m_idHelperSvc->isMuon(id)) continue; - bool measPhi = m_idHelperSvc->measuresPhi(id); - bool isTgc = m_idHelperSvc->isTgc(id); - Muon::MuonStationIndex::ChIndex chIndex = !isTgc ? m_idHelperSvc->chamberIndex(id) : Muon::MuonStationIndex::ChUnknown; - bool found=false; - for(unsigned int i=0;i<mdtTruth.size();i++){ - if(id==mdtTruth[i]){ - if(nprecHitsPerChamberLayer[chIndex]==999) nprecHitsPerChamberLayer[chIndex]=1; - else ++nprecHitsPerChamberLayer[chIndex]; - found=true; - break; - } - } - if(found) continue; - if(m_idHelperSvc->hasCSC()){ - for(unsigned int i=0;i<cscTruth.size();i++){ - if(id==cscTruth[i]){ - if( measPhi ) { - Muon::MuonStationIndex::PhiIndex index = m_idHelperSvc->phiIndex(id); - if(nphiHitsPerChamberLayer[index]==999) nphiHitsPerChamberLayer[index]=1; - else ++nphiHitsPerChamberLayer[index]; - } - else{ - if(nprecHitsPerChamberLayer[chIndex]==999) nprecHitsPerChamberLayer[chIndex]=1; - else ++nprecHitsPerChamberLayer[chIndex]; - } - found=true; - break; - } - } - } - if(found) continue; - for(unsigned int i=0;i<rpcTruth.size();i++){ - if(id==rpcTruth[i]){ - int index = m_idHelperSvc->phiIndex(id); - if( measPhi ){ - if(nphiHitsPerChamberLayer[index]==999) nphiHitsPerChamberLayer[index]=1; - else ++nphiHitsPerChamberLayer[index]; - } - else{ - if(ntrigEtaHitsPerChamberLayer[index]==999) ntrigEtaHitsPerChamberLayer[index]=1; - else ++ntrigEtaHitsPerChamberLayer[index]; - } - found=true; - break; - } - } - if(found) continue; - for(unsigned int i=0;i<tgcTruth.size();i++){ - if(id==tgcTruth[i]){ - int index = m_idHelperSvc->phiIndex(id); - if( measPhi ){ - if(nphiHitsPerChamberLayer[index]==999) nphiHitsPerChamberLayer[index]=1; - else ++nphiHitsPerChamberLayer[index]; - } - else{ - if(ntrigEtaHitsPerChamberLayer[index]==999) ntrigEtaHitsPerChamberLayer[index]=1; - else ++ntrigEtaHitsPerChamberLayer[index]; - } - found=true; - break; - } - } - } //end loop over TSOS - ATH_MSG_DEBUG("finished loop over TSOS"); - //now, have to check if there are non-zero truth hits in indices without reco hits - for(unsigned int i=0;i<nprecHitsPerChamberLayer.size();i++){ - if(nprecHitsPerChamberLayer[i]==999){ - bool found=false; - for(unsigned int j=0;j<mdtTruth.size();j++){ - Identifier id(mdtTruth[j]); - if(m_idHelperSvc->chamberIndex(id)==(Muon::MuonStationIndex::ChIndex)i){ nprecHitsPerChamberLayer[i]=0; found=true; break;} - } - if(found) continue; - if(m_idHelperSvc->hasCSC()){ - for(unsigned int j=0;j<cscTruth.size();j++){ - Identifier id(cscTruth[j]); - if(!m_idHelperSvc->measuresPhi(id)){ - if(m_idHelperSvc->chamberIndex(id)==(Muon::MuonStationIndex::ChIndex)i){ nprecHitsPerChamberLayer[i]=0; break;} - } - } - } - } - } - for(unsigned int i=0;i<nphiHitsPerChamberLayer.size();i++){ - if(nphiHitsPerChamberLayer[i]==999){ - bool found=false; - if(m_idHelperSvc->hasCSC()){ - for(unsigned int j=0;j<cscTruth.size();j++){ - Identifier id(cscTruth[j]); - if(m_idHelperSvc->measuresPhi(id)){ - if(m_idHelperSvc->phiIndex(id)==(Muon::MuonStationIndex::PhiIndex)i){nphiHitsPerChamberLayer[i]=0; found=true; break;} - } - } - } - if(found) continue; - for(unsigned int j=0;j<rpcTruth.size();j++){ - Identifier id(rpcTruth[j]); - if(m_idHelperSvc->measuresPhi(id)){ - if(m_idHelperSvc->phiIndex(id)==(Muon::MuonStationIndex::PhiIndex)i){nphiHitsPerChamberLayer[i]=0; found=true; break;} - } - } - if(found) continue; - for(unsigned int j=0;j<tgcTruth.size();j++){ - Identifier id(tgcTruth[j]); - if(m_idHelperSvc->measuresPhi(id)){ - if(m_idHelperSvc->phiIndex(id)==(Muon::MuonStationIndex::PhiIndex)i){nphiHitsPerChamberLayer[i]=0; break;} - } - } - } - } - for(unsigned int i=0;i<ntrigEtaHitsPerChamberLayer.size();i++){ - if(ntrigEtaHitsPerChamberLayer[i]==999){ - bool found=false; - for(unsigned int j=0;j<rpcTruth.size();j++){ - Identifier id(rpcTruth[j]); - if(!m_idHelperSvc->measuresPhi(id)){ - if(m_idHelperSvc->phiIndex(id)==(Muon::MuonStationIndex::PhiIndex)i){nphiHitsPerChamberLayer[i]=0; found=true; break;} - } - } - if(found) continue; - for(unsigned int j=0;j<tgcTruth.size();j++){ - Identifier id(tgcTruth[j]); - if(!m_idHelperSvc->measuresPhi(id)){ - if(m_idHelperSvc->phiIndex(id)==(Muon::MuonStationIndex::PhiIndex)i){nphiHitsPerChamberLayer[i]=0; break;} - } - } - } - } - muonTruthParticleNPrecMatched(muonInd)=nprecHitsPerChamberLayer; - muonTruthParticleNPhiMatched(muonInd)=nphiHitsPerChamberLayer; - muonTruthParticleNTrigEtaMatched(muonInd)=ntrigEtaHitsPerChamberLayer; - } - } - muonLink.toPersistent(); - muonTruthParticleRecoLink(*truthParticle)=muonLink; - break; - } - } - if(!foundTruth){ - ATH_MSG_DEBUG("failed to find a status=1 truth particle to match the truth link"); - muonTruthParticleLink(*muon)=ElementLink<xAOD::TruthParticleContainer>(); - muonTruthParticleOrigin(muonInd)=-99999; - muonTruthParticleType(muonInd)=-99999; - std::vector<unsigned int> nprecHitsPerChamberLayer; - std::vector<unsigned int> nphiHitsPerChamberLayer; - std::vector<unsigned int> ntrigEtaHitsPerChamberLayer; - muonTruthParticleNPrecMatched(muonInd)=nprecHitsPerChamberLayer; - muonTruthParticleNPhiMatched(muonInd)=nphiHitsPerChamberLayer; - muonTruthParticleNTrigEtaMatched(muonInd)=ntrigEtaHitsPerChamberLayer; - } - } - else{ //no truth link, add a dummy - ATH_MSG_VERBOSE(" Reco muon has no truth association"); - muonTruthParticleLink(*muon)=ElementLink<xAOD::TruthParticleContainer>(); - muonTruthParticleOrigin(muonInd)=-99999; - muonTruthParticleType(muonInd)=-99999; - //add these empty vectors - std::vector<unsigned int> nprecHitsPerChamberLayer; - std::vector<unsigned int> nphiHitsPerChamberLayer; - std::vector<unsigned int> ntrigEtaHitsPerChamberLayer; - muonTruthParticleNPrecMatched(muonInd)=nprecHitsPerChamberLayer; - muonTruthParticleNPhiMatched(muonInd)=nphiHitsPerChamberLayer; - muonTruthParticleNTrigEtaMatched(muonInd)=ntrigEtaHitsPerChamberLayer; - } - }catch ( SG::ExcBadAuxVar& ) { - ATH_MSG_WARNING("Track particle is missing truthParticleLink variable!"); - //there should always be a truthParticleLink, but just in case + if(!foundTruth) { muonTruthParticleLink(*muon)=ElementLink<xAOD::TruthParticleContainer>(); muonTruthParticleOrigin(muonInd)=-99999; muonTruthParticleType(muonInd)=-99999; - std::vector<unsigned int> nprecHitsPerChamberLayer; - std::vector<unsigned int> nphiHitsPerChamberLayer; - std::vector<unsigned int> ntrigEtaHitsPerChamberLayer; - muonTruthParticleNPrecMatched(muonInd)=nprecHitsPerChamberLayer; - muonTruthParticleNPhiMatched(muonInd)=nphiHitsPerChamberLayer; - muonTruthParticleNTrigEtaMatched(muonInd)=ntrigEtaHitsPerChamberLayer; - } + //add these empty vectors + muonTruthParticleNPrecMatched(muonInd)=std::vector<unsigned int>{}; + muonTruthParticleNPhiMatched(muonInd)=std::vector<unsigned int>{}; + muonTruthParticleNTrigEtaMatched(muonInd)=std::vector<unsigned int>{}; + } muonInd++; } - - //one more thing: need to have muonlink set for all truth particles to avoid ELReset errors + ///one more thing: need to have muonlink set for all truth particles to avoid ELReset errors for( const auto truthParticle : *muonTruthParticleRecoLink ){ - if(!truthParticle->isAvailable<ElementLink< xAOD::MuonContainer > >("recoMuonLink")){ - ATH_MSG_DEBUG("no reco muon link set, add an empty one"); - muonTruthParticleRecoLink(*truthParticle)=ElementLink< xAOD::MuonContainer > (); - } - } - return StatusCode::SUCCESS; + if(!truthParticle->isAvailable<ElementLink< xAOD::MuonContainer > >("recoMuonLink")){ + ATH_MSG_DEBUG("no reco muon link set, add an empty one"); + muonTruthParticleRecoLink(*truthParticle)=ElementLink< xAOD::MuonContainer > (); + } + } + return StatusCode::SUCCESS; +} + + +void MuonTruthAssociationAlg::count_chamber_layers(const xAOD::IParticle* truthParticle, + const Trk::Track* ptrk, + std::vector<unsigned int>& nprecHitsPerChamberLayer, + std::vector<unsigned int>& nphiHitsPerChamberLayer, + std::vector<unsigned int>& ntrigEtaHitsPerChamberLayer) const { + + if(!truthParticle || !truthParticle->isAvailable<std::vector<unsigned long long> >("truthMdtHits")){ + ATH_MSG_DEBUG("muon has no truth hits vector in the truth association alg"); + nprecHitsPerChamberLayer.clear(); + nphiHitsPerChamberLayer.clear(); + ntrigEtaHitsPerChamberLayer.clear(); + return; + } + std::vector<unsigned long long> mdtTruth=truthParticle->auxdata<std::vector<unsigned long long> >("truthMdtHits"); + std::vector<unsigned long long> cscTruth; + if(m_idHelperSvc->hasCSC()) cscTruth=truthParticle->auxdata<std::vector<unsigned long long> >("truthCscHits"); + std::vector<unsigned long long> rpcTruth=truthParticle->auxdata<std::vector<unsigned long long> >("truthRpcHits"); + std::vector<unsigned long long> tgcTruth=truthParticle->auxdata<std::vector<unsigned long long> >("truthTgcHits"); + + for(const Trk::TrackStateOnSurface* tsit : *ptrk->trackStateOnSurfaces()){ + if(!tsit || !tsit->trackParameters() || !tsit->measurementOnTrack()) continue; + const Trk::MeasurementBase* meas = tsit->measurementOnTrack(); + Identifier id; + const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas); + if(rot) id=rot->identify(); + else{ + const Muon::CompetingMuonClustersOnTrack* crot = dynamic_cast<const Muon::CompetingMuonClustersOnTrack*>(meas); + if(crot && !crot->containedROTs().empty() && crot->containedROTs().front() ) id=crot->containedROTs().front()->identify(); + } + if(!m_idHelperSvc->isMuon(id)) continue; + + bool measPhi = m_idHelperSvc->measuresPhi(id); + bool isTgc = m_idHelperSvc->isTgc(id); + Muon::MuonStationIndex::ChIndex chIndex = !isTgc ? m_idHelperSvc->chamberIndex(id) : Muon::MuonStationIndex::ChUnknown; + if(m_idHelperSvc->isMdt(id)){ + for(unsigned int i=0;i<mdtTruth.size();i++){ + if(id==mdtTruth[i]){ + increment_unsigned(nprecHitsPerChamberLayer[chIndex]); + break; + } + } + } else if(m_idHelperSvc->hasCSC() && m_idHelperSvc->isCsc(id)){ + for(unsigned int i=0;i<cscTruth.size();i++){ + if(id!=cscTruth[i]) continue; + if(measPhi) { + Muon::MuonStationIndex::PhiIndex index = m_idHelperSvc->phiIndex(id); + increment_unsigned(nphiHitsPerChamberLayer[index]); + } else{ + increment_unsigned(nprecHitsPerChamberLayer[chIndex]); + } + break; + } + } else if (m_idHelperSvc->isRpc(id)){ + for(unsigned int i=0;i<rpcTruth.size();i++){ + if(id!=rpcTruth[i]){ continue;} + int index = m_idHelperSvc->phiIndex(id); + if(measPhi) { + increment_unsigned(nphiHitsPerChamberLayer[index]); + }else { + increment_unsigned(ntrigEtaHitsPerChamberLayer[index]); + } + break; + } + } else if (m_idHelperSvc->isTgc(id)){ + for(unsigned int i=0;i<tgcTruth.size();i++){ + if(id!=tgcTruth[i]){continue;} + int index = m_idHelperSvc->phiIndex(id); + if( measPhi) { + increment_unsigned(nphiHitsPerChamberLayer[index]); + } else{ + increment_unsigned(ntrigEtaHitsPerChamberLayer[index]); + } + break; + } + } + } //end loop over TSOS + ATH_MSG_DEBUG("finished loop over TSOS"); + + //now, have to check if there are non-zero truth hits in indices without reco hits + clear_dummys(mdtTruth, nprecHitsPerChamberLayer); + clear_dummys(cscTruth, nprecHitsPerChamberLayer); + + clear_dummys(cscTruth, nphiHitsPerChamberLayer); + clear_dummys(rpcTruth, nphiHitsPerChamberLayer); + clear_dummys(tgcTruth, nphiHitsPerChamberLayer); + + clear_dummys(rpcTruth, ntrigEtaHitsPerChamberLayer); + clear_dummys(tgcTruth, ntrigEtaHitsPerChamberLayer); + } +void MuonTruthAssociationAlg::clear_dummys(const std::vector<unsigned long long>& identifiers, std::vector<unsigned int>& vec) const{ + /// If the identifiers are empty then there + /// is no change that a dummy value could be cleared from this list + if (identifiers.empty()){ + return; + } + for(unsigned int i=0;i<vec.size();i++){ + if (vec[i] != dummy_unsigned) continue; + for (unsigned j = 0;j< identifiers.size();++j){ + Identifier id(identifiers[j]); + if((m_idHelperSvc->measuresPhi(id) && m_idHelperSvc->phiIndex(id)==(Muon::MuonStationIndex::PhiIndex)i) || + (!m_idHelperSvc->measuresPhi(id) && m_idHelperSvc->chamberIndex(id)==(Muon::MuonStationIndex::ChIndex)i)) + {vec[i]=0; break;} + } + } +} \ No newline at end of file diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.h b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.h index 51bd40a309d1029a47561c5da99218a49ace98fa..35ac4bd6da22f3dd928f4d4adb86d949373f9d98 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.h +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthAssociationAlg.h @@ -1,11 +1,11 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRUTHPARTICLEALGS_MUONTRUTHASSOCIATIONALG_H #define TRUTHPARTICLEALGS_MUONTRUTHASSOCIATIONALG_H -#include "AthenaBaseComps/AthAlgorithm.h" +#include "AthenaBaseComps/AthReentrantAlgorithm.h" #include "xAODMuon/MuonContainer.h" #include "xAODTruth/TruthParticleContainer.h" #include "StoreGate/WriteDecorHandleKey.h" @@ -13,15 +13,15 @@ #include "GaudiKernel/ServiceHandle.h" #include "MuonIdHelpers/IMuonIdHelperSvc.h" -class MuonTruthAssociationAlg : public AthAlgorithm { +class MuonTruthAssociationAlg : public AthReentrantAlgorithm { public: // Constructor with parameters: MuonTruthAssociationAlg(const std::string &name,ISvcLocator *pSvcLocator); // Basic algorithm methods: - virtual StatusCode initialize(); - virtual StatusCode execute(); + StatusCode initialize() override; + StatusCode execute(const EventContext& ctx) const override; private: SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> m_muonTruthParticleContainerName{this,"MuonTruthParticleContainerName","MuonTruthParticles","container name for muon truth particles; the full handle name, including the reco muon link auxdata, is set in initialize()"}; @@ -32,13 +32,21 @@ private: SG::WriteDecorHandleKey<xAOD::MuonContainer> m_muonTruthParticleNPhiMatched{this,"MuonTruthParticleNPhiMatched","Muons.nphiMatchedHitsPerChamberLayer","muon vector of number of phi matched hits per chamber layer auxdata name; name will be reset in initialize() based on m_muonName"}; SG::WriteDecorHandleKey<xAOD::MuonContainer> m_muonTruthParticleNTrigEtaMatched{this,"MuonTruthParticleNTrigEtaMatched","Muons.ntrigEtaMatchedHitsPerChamberLayer","muon vector of number of phi matched hits per chamber layer auxdata name; name will be reset in initialize() based on m_muonName"}; SG::ReadDecorHandleKey<xAOD::MuonContainer> m_cbMuTrkPartLinkToRead{this,"CombinedMuonTrackParticlesTruthLink","CombinedMuonTrackParticles.truthParticleLink","CombinedMuonTrackParticles truth particle link auxdata name; just needed to schedule this alg after the TrackParticleTruthAlg"}; - SG::ReadDecorHandleKey<xAOD::MuonContainer> m_extMuTrkPartLinkToRead{this,"ExtrapolateMuonTrackParticlesTruthLink","ExtrapolateMuonTrackParticles.truthParticleLink","ExtrapolateMuonTrackParticles truth particle link auxdata name; just needed to schedule this alg after the TrackParticleTruthAlg"}; + SG::ReadDecorHandleKey<xAOD::MuonContainer> m_extMuTrkPartLinkToRead{this,"ExtrapolatedMuonTrackParticlesTruthLink","ExtrapolatedMuonTrackParticles.truthParticleLink","ExtrapolatedMuonTrackParticles truth particle link auxdata name; just needed to schedule this alg after the TrackParticleTruthAlg"}; SG::ReadDecorHandleKey<xAOD::MuonContainer> m_indetTrkPartLinkToRead{this,"InDetTrackParticlesTruthLink","InDetTrackParticles.truthParticleLink","InDetTrackParticles truth particle link auxdata name; just needed to schedule this alg after the TrackParticleTruthAlg"}; Gaudi::Property<std::string> m_muonName{this,"MuonContainerName","Muons","muon container name"}; Gaudi::Property<bool>m_associateWithInDetTP{this,"AssociateWithInDetTP",false,"force use of ID track particles for association"}; Gaudi::Property<int>m_barcodeOffset{this,"BarcodeOffset",1000000 ,"barcode offset for truth particles"}; ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; + + void count_chamber_layers(const xAOD::IParticle* truth_particle, + const Trk::Track* ptrk, + std::vector<unsigned int>& nprecHitsPerChamberLayer, + std::vector<unsigned int>& nphiHitsPerChamberLayer, + std::vector<unsigned int>& ntrigEtaHitsPerChamberLayer) const; + void clear_dummys(const std::vector<unsigned long long>& identifiers, std::vector<unsigned int>& vec) const; + }; diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.cxx index 14809093e5f11e8a4e448b05a9341a01120c0956..9dfda3d76ba0efc167faa4d4b48e89838d4ba58b 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.cxx @@ -20,11 +20,18 @@ #include "EventPrimitives/EventPrimitivesHelpers.h" #include "MuonReadoutGeometry/CscReadoutElement.h" + +namespace{ + const SG::AuxElement::Decorator<int> dec_truthOrigin{"truthOrigin"}; + const SG::AuxElement::Decorator<int> dec_truthType{"truthType"}; + const std::vector<float> emptyVec; + +} namespace Muon { // Constructor with parameters: MuonTruthDecorationAlg::MuonTruthDecorationAlg(const std::string &name, ISvcLocator *pSvcLocator) : - AthAlgorithm(name,pSvcLocator), + AthReentrantAlgorithm(name,pSvcLocator), m_muonMgr(nullptr) { } @@ -39,7 +46,6 @@ namespace Muon { ATH_CHECK(m_SDO_TruthNames.initialize()); if (!m_CSC_SDO_TruthNames.empty()) ATH_CHECK(m_CSC_SDO_TruthNames.initialize()); ATH_CHECK(m_idHelperSvc.retrieve()); - ATH_CHECK(m_printer.retrieve()); ATH_CHECK(m_truthClassifier.retrieve()); ATH_CHECK(m_extrapolator.retrieve()); ATH_CHECK(detStore()->retrieve(m_muonMgr)); @@ -47,10 +53,9 @@ namespace Muon { } // Execute method: - StatusCode MuonTruthDecorationAlg::execute() - { + StatusCode MuonTruthDecorationAlg::execute(const EventContext& ctx) const { // skip if no input data found - SG::ReadHandle<xAOD::TruthParticleContainer> truthContainer(m_truthParticleContainerName); + SG::ReadHandle<xAOD::TruthParticleContainer> truthContainer(m_truthParticleContainerName,ctx); if(!truthContainer.isPresent()) return StatusCode::SUCCESS; if(!truthContainer.isValid()){ ATH_MSG_WARNING("truth container "<<truthContainer.name()<<" not valid"); @@ -58,11 +63,11 @@ namespace Muon { } // create output container - SG::WriteHandle<xAOD::TruthParticleContainer> muonTruthContainer(m_muonTruthParticleContainerName); + SG::WriteHandle<xAOD::TruthParticleContainer> muonTruthContainer(m_muonTruthParticleContainerName,ctx); ATH_CHECK(muonTruthContainer.record(std::make_unique<xAOD::TruthParticleContainer>(),std::make_unique<xAOD::TruthParticleAuxContainer>())); ATH_MSG_DEBUG( "Recorded TruthParticleContainer with key: " << m_muonTruthParticleContainerName ); - SG::WriteHandle<xAOD::MuonSegmentContainer> segmentContainer(m_muonTruthSegmentContainerName); + SG::WriteHandle<xAOD::MuonSegmentContainer> segmentContainer(m_muonTruthSegmentContainerName,ctx); if(m_createTruthSegment){ ATH_CHECK(segmentContainer.record(std::make_unique<xAOD::MuonSegmentContainer>(),std::make_unique<xAOD::MuonSegmentAuxContainer>())); ATH_MSG_DEBUG( "Recorded MuonSegmentContainer with key: " << segmentContainer.name() ); @@ -70,8 +75,7 @@ namespace Muon { // loop over truth coll for( const auto truth : *truthContainer ){ - if( truth->status() != 1 ) continue; - if( abs(truth->pdgId()) != 13 || truth->pt() < 1000. ) continue; + if( truth->status() != 1 || !truth->isMuon() || truth->pt() < 1000. ) continue; xAOD::TruthParticle* truthParticle = new xAOD::TruthParticle(); muonTruthContainer->push_back( truthParticle ); truthParticle->setPdgId(truth->pdgId()); @@ -94,25 +98,21 @@ namespace Muon { // if configured look up truth classification if( !m_truthClassifier.empty() ){ - // if configured also get truth classification - auto truthClass = m_truthClassifier->particleTruthClassifier(truth); - type = truthClass.first; - origin = truthClass.second; - ATH_MSG_VERBOSE("Got truth type " << static_cast<int>(type) << " origin " << static_cast<int>(origin)); - int& theType = const_cast<xAOD::TruthParticle*>(truthParticle)->auxdata<int>("truthType"); - int& theOrigin = const_cast<xAOD::TruthParticle*>(truthParticle)->auxdata<int>("truthOrigin"); - theType = static_cast<int>(type); - theOrigin = static_cast<int>(origin); - iType = static_cast<int>(type); - iOrigin = static_cast<int>(origin); + // if configured also get truth classification + auto truthClass = m_truthClassifier->particleTruthClassifier(truth); + int iType = truthClass.first; + int iOrigin = truthClass.second; + ATH_MSG_VERBOSE("Got truth type " << static_cast<int>(type) << " origin " << static_cast<int>(origin)); + dec_truthOrigin(*truthParticle) = iOrigin; + dec_truthType(*truthParticle) = iType; } - // add track records - addTrackRecords(*truthParticle,truth->prodVtx()); + /// add track records + addTrackRecords(ctx,*truthParticle); ChamberIdMap ids; // add hit counts - addHitCounts(*truthParticle,&ids); + addHitCounts(ctx, *truthParticle, ids); //add hit ID vectors addHitIDVectors(*truthParticle,ids); @@ -125,7 +125,7 @@ namespace Muon { // create segments if( m_createTruthSegment && goodMuon ){ - createSegments(truthLink,segmentContainer,ids); + createSegments(ctx, truthLink,segmentContainer,ids); } } @@ -135,12 +135,14 @@ namespace Muon { return StatusCode::SUCCESS; } - void MuonTruthDecorationAlg::createSegments( const ElementLink< xAOD::TruthParticleContainer >& truthLink, SG::WriteHandle<xAOD::MuonSegmentContainer> segmentContainer, + void MuonTruthDecorationAlg::createSegments(const EventContext& ctx, + const ElementLink< xAOD::TruthParticleContainer >& truthLink, + SG::WriteHandle<xAOD::MuonSegmentContainer> segmentContainer, const MuonTruthDecorationAlg::ChamberIdMap& ids) const { std::vector<SG::ReadHandle<MuonSimDataCollection> > sdoCollections(6); for(const SG::ReadHandleKey<MuonSimDataCollection>& k : m_SDO_TruthNames){ - SG::ReadHandle<MuonSimDataCollection> col(k); + SG::ReadHandle<MuonSimDataCollection> col(k,ctx); if(!col.isPresent()){ ATH_MSG_DEBUG("MuonSimDataCollection "<<col.name()<<" not in StoreGate"); continue; @@ -236,7 +238,7 @@ namespace Muon { } } else{ - SG::ReadHandle<CscSimDataCollection> cscCollection(m_CSC_SDO_TruthNames); + SG::ReadHandle<CscSimDataCollection> cscCollection(m_CSC_SDO_TruthNames,ctx); auto pos = cscCollection->find(id); if( pos != cscCollection->end() ) { const MuonGM::CscReadoutElement * descriptor = m_muonMgr->getCscReadoutElement(id); @@ -294,16 +296,16 @@ namespace Muon { } } - void MuonTruthDecorationAlg::addTrackRecords( xAOD::TruthParticle& truthParticle, - const xAOD::TruthVertex* vertex ) const { + void MuonTruthDecorationAlg::addTrackRecords( const EventContext& ctx,xAOD::TruthParticle& truthParticle ) const { // first loop over track records, store parameters at the different positions int barcode = truthParticle.barcode(); + const xAOD::TruthVertex* vertex = truthParticle.prodVtx(); std::vector< std::pair< Amg::Vector3D, Amg::Vector3D > > parameters; if( vertex ) parameters.push_back( std::make_pair(Amg::Vector3D(vertex->x(),vertex->y(),vertex->z()), Amg::Vector3D(truthParticle.px(),truthParticle.py(),truthParticle.pz())) ); - for( SG::ReadHandle<TrackRecordCollection>& col : m_trackRecordCollectionNames.makeHandles() ){ + for( SG::ReadHandle<TrackRecordCollection>& col : m_trackRecordCollectionNames.makeHandles(ctx) ){ if(!col.isPresent()) continue; const std::string name = col.key(); float& x = truthParticle.auxdata<float>(name+"_x"); @@ -397,7 +399,7 @@ namespace Muon { epy=-99999.; epz=-99999.; - const Trk::TrackParameters* exPars = m_extrapolator->extrapolateToVolume(pars,*volume,Trk::alongMomentum,Trk::muon); + std::unique_ptr<const Trk::TrackParameters> exPars { m_extrapolator->extrapolateToVolume(ctx,pars,*volume,Trk::alongMomentum,Trk::muon)}; if( exPars ){ ex = exPars->position().x(); ey = exPars->position().y(); @@ -417,22 +419,20 @@ namespace Muon { << " res p " << (parameters[i+1].second.mag() - exPars->momentum().mag()) << " error " << errorp << " cov " << (*exPars->covariance())(Trk::qOverP,Trk::qOverP) << " pull p " << (parameters[i+1].second.mag() - exPars->momentum().mag())/errorp); - delete exPars; } } } - std::vector<float> emptyVec; for( unsigned int i=0;i<m_trackRecordCollectionNames.size();i++){ const std::string name = m_trackRecordCollectionNames.at(i).key(); if(!truthParticle.isAvailable<std::vector<float> >(name+"_cov_extr")){ - truthParticle.auxdata<std::vector<float> >(name+"_cov_extr")=emptyVec; + truthParticle.auxdata<std::vector<float> >(name+"_cov_extr")=emptyVec; } } } - void MuonTruthDecorationAlg::addHitCounts( xAOD::TruthParticle& truthParticle, - MuonTruthDecorationAlg::ChamberIdMap* ids) const { + void MuonTruthDecorationAlg::addHitCounts(const EventContext& ctx, xAOD::TruthParticle& truthParticle, + MuonTruthDecorationAlg::ChamberIdMap& ids) const { int barcode = truthParticle.barcode(); std::vector<unsigned int> nprecHitsPerChamberLayer; @@ -443,7 +443,7 @@ namespace Muon { ntrigEtaHitsPerChamberLayer.resize(Muon::MuonStationIndex::PhiIndexMax); ATH_MSG_DEBUG("addHitCounts: barcode " << barcode); // loop over detector technologies - for( SG::ReadHandle<PRD_MultiTruthCollection>& col : m_PRD_TruthNames.makeHandles() ){ + for( SG::ReadHandle<PRD_MultiTruthCollection>& col : m_PRD_TruthNames.makeHandles(ctx) ){ if(!col.isPresent()){ ATH_MSG_DEBUG("PRD_MultiTruthCollection "<<col.name()<<" not in StoreGate"); continue; @@ -461,20 +461,19 @@ namespace Muon { Muon::MuonStationIndex::ChIndex chIndex = !isTgc ? m_idHelperSvc->chamberIndex(id) : Muon::MuonStationIndex::ChUnknown; // add identifier to map - if( ids ) { if( isTgc ){ // TGCS should be added to both EIL and EIS Muon::MuonStationIndex::PhiIndex index = m_idHelperSvc->phiIndex(id); if( index == Muon::MuonStationIndex::T4 ){ - (*ids)[Muon::MuonStationIndex::EIS].push_back(id); - (*ids)[Muon::MuonStationIndex::EIL].push_back(id); + ids[Muon::MuonStationIndex::EIS].push_back(id); + ids[Muon::MuonStationIndex::EIL].push_back(id); }else{ - (*ids)[Muon::MuonStationIndex::EMS].push_back(id); - (*ids)[Muon::MuonStationIndex::EML].push_back(id); + ids[Muon::MuonStationIndex::EMS].push_back(id); + ids[Muon::MuonStationIndex::EML].push_back(id); } }else{ - (*ids)[chIndex].push_back(id); - } - } + ids[chIndex].push_back(id); + } + if( m_idHelperSvc->issTgc(id) ) { int index = m_idHelperSvc->phiIndex(id); if( measPhi ) ++nphiHitsPerChamberLayer[index]; diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.h b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.h index ef4044910cf648f5cf7336bcbc76b57eb72f8025..a33fef954043068da350d2e63934a261fe4028be 100755 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.h +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.h @@ -1,16 +1,15 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRUTHPARTICLEALGS_MUONTRUTHDECORATIONALG_H #define TRUTHPARTICLEALGS_MUONTRUTHDECORATIONALG_H -#include "AthenaBaseComps/AthAlgorithm.h" +#include "AthenaBaseComps/AthReentrantAlgorithm.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" #include "MuonIdHelpers/IMuonIdHelperSvc.h" -#include "MuonRecToolInterfaces/IMuonTrackTruthTool.h" #include "MuonRecHelperTools/MuonEDMPrinterTool.h" #include "TrkExInterfaces/IExtrapolator.h" #include "TrackRecord/TrackRecordCollection.h" @@ -38,7 +37,7 @@ namespace MuonGM { namespace Muon { -class MuonTruthDecorationAlg : public AthAlgorithm { +class MuonTruthDecorationAlg : public AthReentrantAlgorithm { public: typedef std::map<Muon::MuonStationIndex::ChIndex, std::vector<Identifier> > ChamberIdMap; @@ -47,14 +46,15 @@ public: MuonTruthDecorationAlg(const std::string &name,ISvcLocator *pSvcLocator); // Basic algorithm methods: - virtual StatusCode initialize(); - virtual StatusCode execute(); + virtual StatusCode initialize()override; + virtual StatusCode execute(const EventContext& ctx) const override; private: - void addTrackRecords( xAOD::TruthParticle& truthParticle, const xAOD::TruthVertex* vertex ) const; - void addHitCounts( xAOD::TruthParticle& truthParticle, ChamberIdMap* ids = 0 ) const; + void addTrackRecords( const EventContext& ctx,xAOD::TruthParticle& truthParticle) const; + void addHitCounts(const EventContext& ctx, xAOD::TruthParticle& truthParticle, ChamberIdMap& ids) const; void addHitIDVectors( xAOD::TruthParticle& truthParticle, const MuonTruthDecorationAlg::ChamberIdMap& ids) const; - void createSegments( const ElementLink< xAOD::TruthParticleContainer >& truthLink,SG::WriteHandle<xAOD::MuonSegmentContainer> segmentContainer, + void createSegments( const EventContext& ctx, + const ElementLink< xAOD::TruthParticleContainer >& truthLink,SG::WriteHandle<xAOD::MuonSegmentContainer> segmentContainer, const MuonTruthDecorationAlg::ChamberIdMap& ids) const; SG::ReadHandleKey<xAOD::TruthParticleContainer> m_truthParticleContainerName{this,"TruthParticleContainerName","TruthParticles"}; @@ -68,7 +68,6 @@ private: ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; - ToolHandle<Muon::MuonEDMPrinterTool> m_printer{this,"MuonEDMPrinterTool","Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"}; ToolHandle<IMCTruthClassifier> m_truthClassifier{this,"MCTruthClassifier","MCTruthClassifier/MCTruthClassifier"}; ToolHandle<Trk::IExtrapolator> m_extrapolator{this,"Extrapolator","Trk::Extrapolator/AtlasExtrapolator"}; diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthSummaryAlg.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthSummaryAlg.cxx deleted file mode 100644 index cdc3303d7ac89a22e9d59b053a68b6c37045e51e..0000000000000000000000000000000000000000 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthSummaryAlg.cxx +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration -*/ - -#include "MuonTruthSummaryAlg.h" - -#include "TrkTrack/TrackCollection.h" -#include "TrkSegment/SegmentCollection.h" -#include "MuonSegment/MuonSegment.h" -#include "xAODTracking/TrackParticleContainer.h" - -MuonTruthSummaryAlg::MuonTruthSummaryAlg(const std::string& name, ISvcLocator* pSvcLocator) : - AthAlgorithm( name, pSvcLocator ) { -} - -StatusCode MuonTruthSummaryAlg::initialize() { - ATH_MSG_INFO ("Initializing " << name() << "..."); - if( m_truthSummaryTool.retrieve().isFailure()){ - ATH_MSG_ERROR("Failed to initialize " << m_truthSummaryTool ); - return StatusCode::FAILURE; - } - return StatusCode::SUCCESS; -} - -StatusCode MuonTruthSummaryAlg::execute() { - ATH_MSG_DEBUG ("Executing " << name() << "..."); - - const Trk::SegmentCollection* segments = 0; - if (evtStore()->retrieve(segments, m_segmentContainerName).isSuccess()){ - for (auto seg : *segments) { - const Trk::Segment* tseg = seg; - const Muon::MuonSegment* muonSeg = dynamic_cast<const Muon::MuonSegment*>(tseg); - if(muonSeg) m_truthSummaryTool->add(*muonSeg,2); - else ATH_MSG_WARNING ("Trk::Segment cannot be casted in Muon::MuonSegment."); - } - } - - const TrackCollection* tracks = 0; - if (evtStore()->retrieve(tracks, m_msTracksContainerName).isSuccess()){ - for (auto trk : *tracks) { - m_truthSummaryTool->add(*trk,3); - } - } - - return StatusCode::SUCCESS; -} - - diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthSummaryAlg.h b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthSummaryAlg.h deleted file mode 100644 index d5c8dc975443ea537e2562926fe5eee78e8b6671..0000000000000000000000000000000000000000 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthSummaryAlg.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef MUONTRUTHALGS_MUONTRUTHSUMMARYALGS_H -#define MUONTRUTHALGS_MUONTRUTHSUMMARYALGS_H - -#include "AthenaBaseComps/AthAlgorithm.h" -#include "GaudiKernel/ToolHandle.h" - -#include "MuonRecToolInterfaces/IMuonTruthSummaryTool.h" - -#include <string> - -class MuonTruthSummaryAlg: public AthAlgorithm { - public: - MuonTruthSummaryAlg( const std::string& name, ISvcLocator* pSvcLocator ); - virtual ~MuonTruthSummaryAlg()=default; - - virtual StatusCode initialize(); - virtual StatusCode execute(); - - private: - ToolHandle<Muon::IMuonTruthSummaryTool> m_truthSummaryTool{this,"MuonTruthSummaryTool","MuonTruthSummaryTool"}; - - Gaudi::Property<std::string> m_segmentContainerName{this,"SegmentContainerName","MuonSegments"}; - Gaudi::Property<std::string> m_msTracksContainerName{this,"MSTracksContainerName","MuonSpectrometerTracks"}; - Gaudi::Property<std::string> m_msTrackletContainerName{this,"MSTrackletsContainerName","MSonlyTracklets"}; -}; - -#endif //> !MUONTRUTHALGS_MUONTRUTHSUMMARYALGS_H diff --git a/MuonSpectrometer/MuonTruthAlgs/src/TrackParticleTruthMaker.cxx b/MuonSpectrometer/MuonTruthAlgs/src/TrackParticleTruthMaker.cxx deleted file mode 100644 index ceb8c218aa48c742deaac2e2ccf2643696785137..0000000000000000000000000000000000000000 --- a/MuonSpectrometer/MuonTruthAlgs/src/TrackParticleTruthMaker.cxx +++ /dev/null @@ -1,130 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/////////////////////////////////////////////////////////////////// -// TrackParticleTruthMaker.cxx -// Implementation file for class TrackParticleTruthMaker -/////////////////////////////////////////////////////////////////// - -#include "MuonTruthAlgs/TrackParticleTruthMaker.h" - -#include "Particle/TrackParticleContainer.h" -#include "TrkTruthData/TrackTruthCollection.h" -#include "TrkTruthData/DetailedTrackTruthCollection.h" -#include "ParticleTruth/TrackParticleTruthCollection.h" -#include "TrkTrack/TrackCollection.h" -#include "TrkTruthData/TruthTrajectory.h" -#include "AtlasHepMC/GenParticle.h" - -#include <map> -#include "AthLinks/ElementLink.h" - -namespace Muon { - - // Constructor with parameters: - TrackParticleTruthMaker::TrackParticleTruthMaker(const std::string &name, - ISvcLocator *pSvcLocator) : - AthAlgorithm(name,pSvcLocator), - m_trackParticlesName ("MooreTrackParticles"), // input track particles - m_trackParticleTruthCollection("MooreTrackParticlesTruth"), // output container - m_tracksName ("MooreTracks"), // input tracks - m_tracksTruthName ("MooreTracksTruth") // input track truth - { - // Get parameter values from jobOptions file - declareProperty("trackParticlesName" , m_trackParticlesName); - declareProperty("trackParticleTruthCollection" , m_trackParticleTruthCollection); - declareProperty("tracksName" , m_tracksName); - declareProperty("tracksTruthName" , m_tracksTruthName); - } - - // Initialize method: - StatusCode TrackParticleTruthMaker::initialize() - { - return StatusCode::SUCCESS; - } - - // Execute method: - StatusCode TrackParticleTruthMaker::execute() - { - StatusCode sc; - - /// - const TrackCollection* myTracks(0); - sc = evtStore()->retrieve(myTracks, m_tracksName); - if (sc.isFailure()) { - ATH_MSG_WARNING ("Could not retrieve '" << m_tracksName << "' from StoreGate !"); - return StatusCode::SUCCESS; - } else { - ATH_MSG_DEBUG ("Retrieved '" << m_tracksName << "' from StoreGate !"); - } - /// - - const DetailedTrackTruthCollection * simTrackMap(0); - - // retrieve associated TrackTruth from StoreGate (Track*, TrackTruth) - sc = evtStore()->retrieve(simTrackMap, m_tracksTruthName); - if (sc.isFailure()) { - ATH_MSG_WARNING ("Could not retrieve '" << m_tracksTruthName << "' from StoreGate !"); - return StatusCode::SUCCESS; - } else { - ATH_MSG_DEBUG ("Retrieved '" << m_tracksTruthName << "' from StoreGate"); - } - - const Rec::TrackParticleContainer * origTrackPC(0); - sc = evtStore()->retrieve(origTrackPC, m_trackParticlesName); - if (sc.isFailure()) { - ATH_MSG_WARNING ("Could not retrieve '" << m_trackParticlesName << "' from StoreGate !"); - return StatusCode::SUCCESS; - } else { - ATH_MSG_DEBUG ("Retrieve '" << m_trackParticlesName << "' from StoreGate ! " << origTrackPC->size() ); - } - - TrackParticleTruthCollection* tpTruthColl = new TrackParticleTruthCollection(origTrackPC); - - typedef Rec::TrackParticleContainer::const_iterator TPCIter; - for (TPCIter i=origTrackPC->begin(); i!=origTrackPC->end(); i++) { - const Trk::Track* track = (*i)->originalTrack(); - ElementLink<TrackCollection> tracklink; - tracklink.setElement(const_cast<Trk::Track*>(track)); - tracklink.setStorableObject(*myTracks); // otherwise the find does not work - - - // this should work since both DetailedTrackTruthCollection and TrackTruthCollection use the same kay: Trk::TrackTruthKey - DetailedTrackTruthCollection::const_iterator tempTrackTruthItr = simTrackMap->find(tracklink); - if (tempTrackTruthItr != simTrackMap->end()) { - for (unsigned int j=0; j< (*tempTrackTruthItr).second.trajectory().size(); j++) { - if(!(*tempTrackTruthItr).second.trajectory().at(j).cptr()) continue; - ATH_MSG_DEBUG ("Barcode: " << (*tempTrackTruthItr).second.trajectory().at(j).cptr()->pdg_id() - << "Status: " << (*tempTrackTruthItr).second.trajectory().at(j).cptr()->status() << "\t Probability: " << 1.); - ElementLink< Rec::TrackParticleContainer > myLink; - myLink.setElement(const_cast<Rec::TrackParticle*>(*i)); - myLink.setStorableObject(*origTrackPC); - std::pair< ElementLink< Rec::TrackParticleContainer > , TrackParticleTruth> - entry(myLink,TrackParticleTruth((HepMcParticleLink)(*tempTrackTruthItr).second.trajectory().at(j),1.)); - tpTruthColl->insert(entry); - } - }else{ - ATH_MSG_DEBUG(" no truth track found " ); - } - } - - // record associated TrackParticleTruth to StoreGate (TrackParticle*, TrackParticleTruth) - sc = evtStore()->record(tpTruthColl, m_trackParticleTruthCollection, false); - if (sc.isFailure()) { - ATH_MSG_FATAL ("Could not record '" << m_trackParticleTruthCollection << "' to StoreGate !"); - return StatusCode::FAILURE; - } else { - ATH_MSG_DEBUG ("Recorded '" << m_trackParticleTruthCollection << "' to StoreGate !"); - } - return StatusCode::SUCCESS; - } - - // Finalize method: - StatusCode TrackParticleTruthMaker::finalize() - { - return StatusCode::SUCCESS; - } - -} // namespace Muon - diff --git a/MuonSpectrometer/MuonTruthAlgs/src/components/MuonTruthAlgs_entries.cxx b/MuonSpectrometer/MuonTruthAlgs/src/components/MuonTruthAlgs_entries.cxx index ae070958c899b8110823537ec798a6d83f6a94a4..12f5f894361f6d10e203f8a9de25198033bdbd51 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/components/MuonTruthAlgs_entries.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/components/MuonTruthAlgs_entries.cxx @@ -3,12 +3,10 @@ #include "MuonTruthAlgs/MuonPatternCombinationDetailedTrackTruthMaker.h" #include "MuonTruthAlgs/MuonTrackTruthTool.h" #include "../MuonDecayTruthTrajectoryBuilder.h" -#include "MuonTruthAlgs/TrackParticleTruthMaker.h" #include "../DetailedMuonPatternTruthBuilder.h" #include "../MuonTruthDecorationAlg.h" #include "../MuonTruthAssociationAlg.h" #include "../MuonSegmentTruthAssociationAlg.h" -#include "../MuonTruthSummaryAlg.h" using namespace Muon; @@ -17,11 +15,9 @@ using namespace Trk; DECLARE_COMPONENT( MuonPRD_MultiTruthMaker ) DECLARE_COMPONENT( MuonDetailedTrackTruthMaker ) DECLARE_COMPONENT( MuonPatternCombinationDetailedTrackTruthMaker ) -DECLARE_COMPONENT( TrackParticleTruthMaker ) DECLARE_COMPONENT( MuonTruthDecorationAlg ) DECLARE_COMPONENT( MuonTruthAssociationAlg ) DECLARE_COMPONENT( MuonSegmentTruthAssociationAlg ) -DECLARE_COMPONENT( MuonTruthSummaryAlg ) DECLARE_COMPONENT( MuonTrackTruthTool ) DECLARE_COMPONENT( MuonDecayTruthTrajectoryBuilder ) diff --git a/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/MuonTrackPerformance/MuonTrackPerformanceAlg.h b/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/MuonTrackPerformance/MuonTrackPerformanceAlg.h index 8a51e1f90a7cdb4687af9871733bbce7a111b1cf..47d40f5b4b857109effc4b81b73abebc59b8db51 100644 --- a/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/MuonTrackPerformance/MuonTrackPerformanceAlg.h +++ b/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/MuonTrackPerformance/MuonTrackPerformanceAlg.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTRACKPERFORMANCEALG_H @@ -60,7 +60,7 @@ public: }; struct TrackData{ - TrackData() : truthTrack(0),motherPdg(-1),chi2Ndof(0.),productionVertex(0),momentumAtProduction(0),truthTrajectory(0),trackPars(0),trackSummary(0) {} + TrackData() : truthTrack(nullptr),motherPdg(-1),chi2Ndof(0.),productionVertex(nullptr),momentumAtProduction(nullptr),truthTrajectory(nullptr),trackPars(nullptr),trackSummary(nullptr) {} ~TrackData() { delete trackPars; @@ -202,8 +202,7 @@ private: bool handleTrackTruth( const TrackCollection& trackCollection ); bool handleSegmentCombi( const Muon::MuonSegmentCombination& combi ); - bool handleSegmentTruth( const std::vector<const Muon::MuonSegment*>& segments ); - + void doSummary( const TrackCollection& tracks ) const; void doSummary( const Muon::IMuonTrackTruthTool::TruthTree& truthTracks ) const; diff --git a/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonTrackPerformanceAlg.cxx b/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonTrackPerformanceAlg.cxx index 302a732f07ab1352adf822f2916c7801de7b04eb..be2c679e658c51443a69de0dd63bfcb9e94b406a 100644 --- a/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonTrackPerformanceAlg.cxx +++ b/MuonSpectrometer/MuonValidation/MuonRecValidation/MuonTrackPerformance/src/MuonTrackPerformanceAlg.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "MuonTrackPerformance/MuonTrackPerformanceAlg.h" @@ -144,43 +144,6 @@ StatusCode MuonTrackPerformanceAlg::execute() return StatusCode::SUCCESS; } -bool MuonTrackPerformanceAlg::handleSegmentTruth( const std::vector<const Muon::MuonSegment*>& segments ) { - Muon::IMuonTrackTruthTool::SegmentResultVec result = m_truthTool->match(segments); - Muon::IMuonTrackTruthTool::SegmentResultVec::iterator rit = result.begin(); - Muon::IMuonTrackTruthTool::SegmentResultVec::iterator rit_end = result.end(); - for( ;rit!=rit_end;++rit ){ - - Muon::MuonTrackTruth& trackTruth = rit->second; - if( rit == result.begin() ) { - if( trackTruth.mdts.missedChambers.size() > 0 ){ - if( m_debug ) *m_log << MSG::DEBUG << "Missing mdt chamber " << endmsg; - } - if(m_idHelperSvc->hasCSC()){ - if( trackTruth.cscs.missedChambers.size() > 0 ){ - if( m_debug ) *m_log << MSG::DEBUG << "Missing csc chamber " << endmsg; - } - } - if(m_idHelperSvc->hasSTgc()){ - if( trackTruth.stgcs.missedChambers.size() > 0 ){ - if( m_debug ) *m_log << MSG::DEBUG << "Missing stgc chamber " << endmsg; - } - } - if(m_idHelperSvc->hasMM()){ - if( trackTruth.mms.missedChambers.size() > 0 ){ - if( m_debug ) *m_log << MSG::DEBUG << "Missing mm chamber " << endmsg; - } - } - if( trackTruth.rpcs.missedChambers.size() > 0 ){ - if( m_debug ) *m_log << MSG::DEBUG << "Missing rpc chamber " << endmsg; - } - if( trackTruth.tgcs.missedChambers.size() > 0 ){ - if( m_debug ) *m_log << MSG::DEBUG << "Missing tgc chamber " << endmsg; - } - } - } - return true; -} - bool MuonTrackPerformanceAlg::handleSegmentCombi( const Muon::MuonSegmentCombination& combi ) { /** This method loops over the segments in the combi and filles them into the internal structure of the MuonCombiTrackMaker */ @@ -215,7 +178,7 @@ bool MuonTrackPerformanceAlg::handleSegmentCombi( const Muon::MuonSegmentCombina bool MuonTrackPerformanceAlg::handleTracks() { - std::unique_ptr<TrackCollection> allTracks(new TrackCollection()); + std::unique_ptr<TrackCollection> allTracks = std::make_unique<TrackCollection>(); if(!m_trackKey.key().empty()){ //MS tracks SG::ReadHandle<TrackCollection> trackCol(m_trackKey); if (!trackCol.isValid() ) { @@ -328,7 +291,7 @@ bool MuonTrackPerformanceAlg::handleTrackTruth( const TrackCollection& trackColl if(!simDataMap.isPresent()) continue; muonSimData.push_back(simDataMap.cptr()); } - const CscSimDataCollection* cscSimData=NULL; + const CscSimDataCollection* cscSimData=nullptr; if(m_idHelperSvc->hasCSC()){ SG::ReadHandle<CscSimDataCollection> cscSimDataMap(m_cscSimData); if(!cscSimDataMap.isValid()){ @@ -370,7 +333,7 @@ bool MuonTrackPerformanceAlg::handleTrackTruth( const TrackCollection& trackColl unsigned int nmatched(0); unsigned int nmatchedSecondary(0); - Muon::IMuonTrackTruthTool::ResultVec result = m_truthTool->match(trackCollection); + Muon::IMuonTrackTruthTool::ResultVec result = m_truthTool->match(truthTree, trackCollection); Muon::IMuonTrackTruthTool::ResultVec::iterator rit = result.begin(); Muon::IMuonTrackTruthTool::ResultVec::iterator rit_end = result.end(); for( ;rit!=rit_end;++rit ){