ATLAS Offline Software
MuonTrackTruthTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MUON_MUONTRACKTRUTHTOOL_H
6 #define MUON_MUONTRACKTRUTHTOOL_H
7 
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <utility>
12 #include <vector>
13 
15 #include "GaudiKernel/ServiceHandle.h"
16 #include "GaudiKernel/ToolHandle.h"
25 
26 class TruthTrajectory;
27 
28 namespace MuonGM {
29  class MuonDetectorManager;
30 }
31 
32 namespace Muon {
33  class MuonSegment;
34 }
35 
36 namespace Trk {
37  class Track;
38  class MeasurementBase;
39 } // namespace Trk
40 
41 namespace Muon {
42 
47  class MuonTrackTruthTool : virtual public IMuonTrackTruthTool, public AthAlgTool {
48  public:
50  bool operator()(const MatchResult& r1, const MatchResult& r2) const;
51  bool operator()(const SegmentMatchResult& r1, const SegmentMatchResult& r2) const;
52  bool operator()(const MuonTrackTruth& r1, const MuonTrackTruth& r2) const;
53  };
54 
55  public:
57  MuonTrackTruthTool(const std::string&, const std::string&, const IInterface*);
58 
60  ~MuonTrackTruthTool() = default;
61 
64 
66  ResultVec match(const TruthTree& truth_tree, const TrackCollection& tracks) const;
67 
69  SegmentResultVec match(const TruthTree& truth_tree, const std::vector<const MuonSegment*>& segments) const;
70 
72  MuonTrackTruth getTruth(const TruthTree& truth_tree, const Trk::Track& track, bool restrictedTruth = false) const;
73 
75  MuonTrackTruth getTruth(const TruthTree& truth_tree, const std::vector<const MuonSegment*>& segments,
76  bool restrictedTruth = false) const;
77 
80 
84  MuonTrackTruth getTruth(const TruthTree& truth_tree, const std::vector<const Trk::MeasurementBase*>& measurements,
85  bool restrictedTruth = false) const;
86 
88  const TruthTree createTruthTree(const TrackRecordCollection* truthTrackCol, const McEventCollection* mcEventCollection,
89  const std::vector<const MuonSimDataCollection*>& muonSimData,
90  const CscSimDataCollection* cscSimDataMap) const;
91 
94  HepMC::ConstGenParticlePtr getMother(const TruthTrajectory& traj, const int barcodeIn) const;
95 
98  HepMC::ConstGenParticlePtr getAncestor(const TruthTrajectory& traj, const int barcodeIn) const;
99 
103  HepMC::ConstGenParticlePtr getInitial(const TruthTrajectory& traj, const int barcodeIn) const;
104 
107  unsigned int getNumberOfScatters(const TruthTrajectory& traj, const int barcodeIn) const;
108 
109  private:
110  MuonTrackTruth getTruth(const std::vector<const Trk::MeasurementBase*>& measurements, const TruthTreeEntry& truthEntry,
111  bool restrictedTruth) const;
112 
113  void addSimDataToTree(TruthTree& truth_tree, std::map<int, int>& barcode_map, const MuonSimDataCollection* simDataCol) const;
114  void addCscSimDataToTree(TruthTree& truth_tree, std::map<int, int>& barcode_map, const CscSimDataCollection* simDataCol) const;
115 
116  void addMdtTruth(MuonTechnologyTruth& trackTruth, const Identifier& id, const Trk::MeasurementBase& meas,
117  const MuonSimDataCollection& simCol) const;
118 
119  void addClusterTruth(MuonTechnologyTruth& trackTruth, const Identifier& id, const Trk::MeasurementBase& meas,
120  const MuonSimDataCollection& simCol) const;
121  void addClusterTruth(MuonTechnologyTruth& trackTruth, const Identifier& id, const Trk::MeasurementBase& meas,
122  const CscSimDataCollection& simCol) const;
123 
124  void addMissedHits(MuonTechnologyTruth& truth, const std::set<Identifier>& ids, const std::set<Identifier>& chids,
125  const MuonSimDataCollection& simCol, bool restrictedTruth) const;
126 
127  void addMissedHits(MuonTechnologyTruth& truth, const std::set<Identifier>& ids, const std::set<Identifier>& chids,
128  const CscSimDataCollection& simCol, bool restrictedTruth) const;
129 
130  int manipulateBarCode(int barcode) const;
131 
132  bool selectPdg(int pdg) const { return m_selectedPdgs.count(pdg); }
133 
137  const std::pair<HepMC::ConstGenParticlePtr, unsigned int> getInitialPair(const TruthTrajectory& traj, const int barcodeIn) const;
138 
140 
141  ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
142 
143  ToolHandle<Muon::MuonEDMPrinterTool> m_printer{this, "Printer", "Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"};
144  ToolHandle<Trk::ITruthTrajectoryBuilder> m_truthTrajectoryBuilder{
145  this, "TruthTrajectoryBuilder", "Muon::MuonDecayTruthTrajectoryBuilder/MuonDecayTruthTrajectoryBuilder"};
146 
147  Gaudi::Property<bool> m_manipulateBarCode{this, "ManipulateBarCode", false};
148  Gaudi::Property<bool> m_doSummary{this, "DoSummary", false};
149  Gaudi::Property<bool> m_matchAllParticles{this, "MatchAllParticles", true};
150  Gaudi::Property<unsigned int> m_minHits{this, "MinHits", 4};
151  Gaudi::Property<std::vector<int>> m_pdgsToBeConsidered{this, "ConsideredPDGs", {}};
152 
153  std::set<int> m_selectedPdgs; // set storing particle PDG's considered for matching
154  };
155 
156 } // namespace Muon
157 
158 #endif // MUON_MDTONTRACKTOOL_H
Muon::MuonTechnologyTruth
Definition: IMuonTrackTruthTool.h:30
Muon::MuonTrackTruthTool::SortResultByMatchedHits::operator()
bool operator()(const MatchResult &r1, const MatchResult &r2) const
Definition: MuonTrackTruthTool.cxx:54
MuonGM
Ensure that the Athena extensions are properly loaded.
Definition: GeoMuonHits.h:27
Muon::MuonTrackTruthTool::m_printer
ToolHandle< Muon::MuonEDMPrinterTool > m_printer
Definition: MuonTrackTruthTool.h:143
ITruthTrajectoryBuilder.h
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
MuonEDMPrinterTool.h
Muon::MuonTrackTruthTool::getAncestor
HepMC::ConstGenParticlePtr getAncestor(const TruthTrajectory &traj, const int barcodeIn) const
Returns the ancestor particle of the particle with barcodeIn if it is found in the truth trajectory.
Definition: MuonTrackTruthTool.cxx:689
CscSimDataCollection.h
Muon::MuonTrackTruthTool::getInitial
HepMC::ConstGenParticlePtr getInitial(const TruthTrajectory &traj, const int barcodeIn) const
Returns the initial particle of the particle with barcodeIn if it is found in the truth trajectory.
Definition: MuonTrackTruthTool.cxx:768
Muon::MuonTrackTruthTool::MuonTrackTruthTool
MuonTrackTruthTool(const std::string &, const std::string &, const IInterface *)
constructor
Definition: MuonTrackTruthTool.cxx:25
Muon::MuonTrackTruthTool::m_selectedPdgs
std::set< int > m_selectedPdgs
Definition: MuonTrackTruthTool.h:153
AtlasHitsVector
Definition: AtlasHitsVector.h:33
Muon::MuonTrackTruth
Definition: IMuonTrackTruthTool.h:40
Muon::MuonTrackTruthTool::createTruthTree
const TruthTree createTruthTree(const TrackRecordCollection *truthTrackCol, const McEventCollection *mcEventCollection, const std::vector< const MuonSimDataCollection * > &muonSimData, const CscSimDataCollection *cscSimDataMap) const
create truth tree from sim data
Definition: MuonTrackTruthTool.cxx:115
Muon::MuonTrackTruthTool::addClusterTruth
void addClusterTruth(MuonTechnologyTruth &trackTruth, const Identifier &id, const Trk::MeasurementBase &meas, const MuonSimDataCollection &simCol) const
Definition: MuonTrackTruthTool.cxx:591
Muon::MuonTrackTruthTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonTrackTruthTool.h:141
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:49
xAOD::MuonSegment
MuonSegment_v1 MuonSegment
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonSegment.h:13
inspect_truth_file.truth_tree
truth_tree
Definition: inspect_truth_file.py:75
Muon::IMuonTrackTruthTool::MatchResult
std::pair< const Trk::Track *, MuonTrackTruth > MatchResult
Definition: IMuonTrackTruthTool.h:86
Muon::MuonTrackTruthTool::getMother
HepMC::ConstGenParticlePtr getMother(const TruthTrajectory &traj, const int barcodeIn) const
Returns the mother particle of the particle with barcodeIn if it is found in the truth trajectory.
Definition: MuonTrackTruthTool.cxx:667
Muon::MuonTrackTruthTool
Tool to calculate track truth.
Definition: MuonTrackTruthTool.h:47
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
Muon::MuonTrackTruthTool::SortResultByMatchedHits
Definition: MuonTrackTruthTool.h:49
MuonSimDataCollection
Definition: MuonSimDataCollection.h:21
AthAlgTool.h
TrackCollection.h
Muon::MuonTrackTruthTool::m_manipulateBarCode
Gaudi::Property< bool > m_manipulateBarCode
Definition: MuonTrackTruthTool.h:147
CscSimDataCollection
Definition: CscSimDataCollection.h:29
Muon::MuonTrackTruthTool::getTruth
MuonTrackTruth getTruth(const TruthTree &truth_tree, const Trk::Track &track, bool restrictedTruth=false) const
get track truth
Definition: MuonTrackTruthTool.cxx:392
IMuonTrackTruthTool.h
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
Muon::MuonTrackTruthTool::~MuonTrackTruthTool
~MuonTrackTruthTool()=default
destructor
Muon::MuonTrackTruthTool::initialize
StatusCode initialize()
AlgTool initilize.
Definition: MuonTrackTruthTool.cxx:30
DataVector< Trk::Track >
Muon::MuonTrackTruthTool::m_truthTrajectoryBuilder
ToolHandle< Trk::ITruthTrajectoryBuilder > m_truthTrajectoryBuilder
Definition: MuonTrackTruthTool.h:144
Muon::MuonTrackTruthTool::m_matchAllParticles
Gaudi::Property< bool > m_matchAllParticles
Definition: MuonTrackTruthTool.h:149
Muon::MuonTrackTruthTool::addSimDataToTree
void addSimDataToTree(TruthTree &truth_tree, std::map< int, int > &barcode_map, const MuonSimDataCollection *simDataCol) const
Definition: MuonTrackTruthTool.cxx:271
Muon::MuonTrackTruthTool::m_detMgr
const MuonGM::MuonDetectorManager * m_detMgr
Definition: MuonTrackTruthTool.h:139
Trk::MeasurementBase
Definition: MeasurementBase.h:58
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Muon::MuonTrackTruthTool::m_pdgsToBeConsidered
Gaudi::Property< std::vector< int > > m_pdgsToBeConsidered
Definition: MuonTrackTruthTool.h:151
TruthTrajectory
Definition: TruthTrajectory.h:26
Muon::MuonTrackTruthTool::m_minHits
Gaudi::Property< unsigned int > m_minHits
Definition: MuonTrackTruthTool.h:150
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
TrackRecordCollection.h
Muon::MuonTrackTruthTool::selectPdg
bool selectPdg(int pdg) const
Definition: MuonTrackTruthTool.h:132
Muon::IMuonTrackTruthTool::SegmentResultVec
std::vector< SegmentMatchResult > SegmentResultVec
Definition: IMuonTrackTruthTool.h:90
Muon::MuonTrackTruthTool::addMissedHits
void addMissedHits(MuonTechnologyTruth &truth, const std::set< Identifier > &ids, const std::set< Identifier > &chids, const MuonSimDataCollection &simCol, bool restrictedTruth) const
Definition: MuonTrackTruthTool.cxx:500
Muon::MuonTrackTruthTool::manipulateBarCode
int manipulateBarCode(int barcode) const
Definition: MuonTrackTruthTool.cxx:49
Muon::MuonTrackTruthTool::getInitialPair
const std::pair< HepMC::ConstGenParticlePtr, unsigned int > getInitialPair(const TruthTrajectory &traj, const int barcodeIn) const
Returns the initial particle of the particle with barcodeIn if it is found in the truth trajectory.
Definition: MuonTrackTruthTool.cxx:708
Muon::IMuonTrackTruthTool::TruthTreeEntry
Definition: IMuonTrackTruthTool.h:75
Muon::IMuonTrackTruthTool::TruthTree
std::map< int, TruthTreeEntry > TruthTree
Definition: IMuonTrackTruthTool.h:93
Muon::MuonTrackTruthTool::match
ResultVec match(const TruthTree &truth_tree, const TrackCollection &tracks) const
perform truth matching for a given set of tracks
Definition: MuonTrackTruthTool.cxx:73
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:49
Muon::IMuonTrackTruthTool
The IMuonTrackTruthTool is a pure virtual interface for tools that recover hole on a track.
Definition: IMuonTrackTruthTool.h:73
Muon::MuonTrackTruthTool::m_doSummary
Gaudi::Property< bool > m_doSummary
Definition: MuonTrackTruthTool.h:148
Muon::IMuonTrackTruthTool::SegmentMatchResult
std::pair< const Muon::MuonSegment *, MuonTrackTruth > SegmentMatchResult
Definition: IMuonTrackTruthTool.h:89
Muon::MuonTrackTruthTool::getNumberOfScatters
unsigned int getNumberOfScatters(const TruthTrajectory &traj, const int barcodeIn) const
Returns the number of steps a particle took while maintaining its PDG ID.
Definition: MuonTrackTruthTool.cxx:772
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
Muon::IMuonTrackTruthTool::ResultVec
std::vector< MatchResult > ResultVec
Definition: IMuonTrackTruthTool.h:87
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Muon::MuonSegment
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:45
AthAlgTool
Definition: AthAlgTool.h:26
MuonSimDataCollection.h
Muon::MuonTrackTruthTool::addCscSimDataToTree
void addCscSimDataToTree(TruthTree &truth_tree, std::map< int, int > &barcode_map, const CscSimDataCollection *simDataCol) const
Definition: MuonTrackTruthTool.cxx:350
IMuonIdHelperSvc.h
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
Muon::MuonTrackTruthTool::addMdtTruth
void addMdtTruth(MuonTechnologyTruth &trackTruth, const Identifier &id, const Trk::MeasurementBase &meas, const MuonSimDataCollection &simCol) const
Definition: MuonTrackTruthTool.cxx:556
ServiceHandle< Muon::IMuonIdHelperSvc >