ATLAS Offline Software
TruthRelatedMuonPlotOrganizer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 
13 
14 namespace Muon{
15 
16 TruthRelatedMuonPlotOrganizer::TruthRelatedMuonPlotOrganizer(PlotBase* pParent, const std::string& sDir, bool doBinnedResolutionPlots, std::vector<int> selPlots):
17  PlotBase(pParent, sDir)
18  // Truth related plots
19 {
20 
21  if (selPlots.empty()) {
22  for (unsigned int i=0; i<MAX_TRUTHRELATEDPLOTCLASS; i++) m_selPlots.push_back(i);
23  }
24  else m_selPlots = std::move(selPlots);
25 
26  for (auto p: m_selPlots) {
27  switch (p) {
28  case TRK_MATCHEDTRUE:
29  m_oMatchedPlots = std::make_unique< Trk::ParamPlots>(this, "/kinematics/", "Matched Muons");
30  break;
31  case TRK_MATCHEDRECO:
32  m_oMatchedRecoPlots = std::make_unique< Trk::ParamPlots>(this, "/kinematicsReco/", "Matched Muons");
33  break;
34  case TRK_MSHITDIFF:
35  m_oMSHitDiffPlots = std::make_unique< Trk::MSHitDiffPlots>(this,"/hits/");
36  break;
37  case MUON_HITDIFF:
38  m_oMuonHitDiffSummaryPlots = std::make_unique< Muon::MuonHitDiffSummaryPlots>(this,"/hits/");
39  break;
40  case MUON_TRUTHHIT:
41  m_oMuonTruthHitPlots = std::make_unique< Muon::MuonTruthHitPlots>(this,"/truthHits/");
42  break;
43  case MUON_RESOL:
44  m_oMuonResolutionPlots = std::make_unique< Muon::MuonResolutionPlots>(this, "/resolution/","",doBinnedResolutionPlots);
45  break;
46  case TRK_DEFPARAMPULLS:
47  m_oDefParamPullPlots = std::make_unique< Trk::DefParamPullPlots>(this, "/pulls/","");
48  break;
49  case MUON_PULLSTAIL:
50  m_oMomentumTruthPullPlots_Tail = std::make_unique< Muon::MomentumTruthPullPlots>(this,"/momentumPulls/","Tail");
51  break;
52  case MUON_PULLSNOTAIL:
53  m_oMomentumTruthPullPlots_NoTail = std::make_unique< Muon::MomentumTruthPullPlots>(this,"/momentumPulls/","NoTail");
54  break;
55  case MUON_PARAMELOSS:
56  m_oMatchedRecoElossPlots = std::make_unique< Muon::MuonParamElossPlots>(this,"/Eloss/");
57  break;
58  }
59  }
60 
61 }
63 
65  if (m_oMatchedPlots) m_oMatchedPlots->fill( truthMu , weight);
68 
69  // for eloss
71 
72  // Tracking related plots
73  const xAOD::TrackParticle* primaryTrk = mu.trackParticle(xAOD::Muon::Primary);
74  //const xAOD::TrackParticle* meTrk = mu.trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
75 
76  if (!primaryTrk) return;
77  if (m_oMatchedRecoPlots) m_oMatchedRecoPlots->fill( *primaryTrk , weight);
78  if (m_oMSHitDiffPlots) m_oMSHitDiffPlots->fill(*primaryTrk, truthMu, weight);
79  if (m_oMuonResolutionPlots) m_oMuonResolutionPlots->fill(*primaryTrk, truthMu, weight);
80  if (m_oDefParamPullPlots) m_oDefParamPullPlots->fill(*primaryTrk, truthMu, weight);
81 
83  //muon spectrometer track at MS entry (not extrapolated)
84  const xAOD::TrackParticle *msTrk(nullptr);
85  //muon extrapolated to IP
86  //const xAOD::TrackParticle* msExtrapTrk(0);
87 
89  //for 20.1.0...
91  //for 20.1.3...
92  //const xAOD::TrackParticle* msExtrapTrk = mu.trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
93 
94  //trying to accomodate both in a way that the code compiles in both releases
96  extrapLinkAcc("extrapolatedMuonSpectrometerTrackParticleLink");
97  if (extrapLinkAcc.isAvailable(mu) && extrapLinkAcc(mu).isValid() ) {
98  //cool, we got both links:
99  //int correctEnumForExtrap = ((int)xAOD::Muon::MuonSpectrometerTrackParticle)+2;
100  //msExtrapTrk = mu.trackParticle((xAOD::Muon::TrackParticleType) correctEnumForExtrap);
101  msTrk = mu.trackParticle( xAOD::Muon::MuonSpectrometerTrackParticle );
102  }
103  else {
104  // gymnastics to get msTrk...
105  const ElementLink<xAOD::TrackParticleContainer>& msExtrapTrkLink = mu.trackParticleLink(xAOD::Muon::MuonSpectrometerTrackParticle);
106  static const SG::ConstAccessor<TruthLink>
107  truthParticleLinkAcc("truthParticleLink");
108  if (msExtrapTrkLink.isValid()) {
109  //msExtrapTrk = mu.trackParticle( xAOD::Muon::MuonSpectrometerTrackParticle );
110  TruthLink truthLink_muTrk;
111  if( truthParticleLinkAcc.isAvailable(**msExtrapTrkLink) ) {
112  truthLink_muTrk = truthParticleLinkAcc(**msExtrapTrkLink);
113  }
114  if (truthLink_muTrk.isValid()) {
115  for (const auto trk: *MSTracks) {
116  TruthLink truthLink_msTrk;
117  if( truthParticleLinkAcc.isAvailable(*trk) ) {
118  truthLink_msTrk = truthParticleLinkAcc(*trk);
119  if (truthLink_msTrk.isValid()) {
120  if (truthLink_msTrk == truthLink_muTrk) {
121  msTrk = trk; //got it!
122  break;
123  }
124  }
125  }
126  }
127  }
128  }
129  }
130 #ifndef XAOD_ANALYSIS
131  float eloss=0;
132  if (mu.parameter(eloss,xAOD::Muon::EnergyLoss)) {
133  if ( mu.energyLossType()!=xAOD::Muon::Tail ) { //to test MEASURED energy loss
135  }
136  else {
137  if (m_oMomentumTruthPullPlots_Tail) m_oMomentumTruthPullPlots_Tail->fill(mu, msTrk, truthMu, weight); //to test PARAMETRIZED energy loss
138  }
139  }
140 #endif // not XAOD_ANALYSIS
141  }
142 }
143 
145  // Tracking related plots
146  if (m_oMatchedPlots) m_oMatchedPlots->fill( truthMu, weight );
147  if (m_oMatchedRecoPlots) m_oMatchedRecoPlots->fill( muTP , weight);
148  if (m_oDefParamPullPlots) m_oDefParamPullPlots->fill(muTP, truthMu, weight);
149  if (m_oMuonResolutionPlots) m_oMuonResolutionPlots->fill(muTP, truthMu, weight);
150  if (m_oMSHitDiffPlots) m_oMSHitDiffPlots->fill(muTP, truthMu, weight);
151 }
152 
153 }//close namespace
154 
Muon::MAX_TRUTHRELATEDPLOTCLASS
@ MAX_TRUTHRELATEDPLOTCLASS
Definition: TruthRelatedMuonPlotOrganizer.h:25
Muon::MUON_RESOL
@ MUON_RESOL
Definition: TruthRelatedMuonPlotOrganizer.h:25
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
PlotBase
Definition: PlotBase.h:33
Muon::TRK_MATCHEDRECO
@ TRK_MATCHEDRECO
Definition: TruthRelatedMuonPlotOrganizer.h:25
python.copyTCTOutput.sDir
sDir
Definition: copyTCTOutput.py:60
Muon::TRK_MATCHEDTRUE
@ TRK_MATCHEDTRUE
Definition: TruthRelatedMuonPlotOrganizer.h:25
TruthParticleContainer.h
TruthLink
ElementLink< xAOD::TruthParticleContainer > TruthLink
Definition: TruthRelatedMuonPlotOrganizer.cxx:12
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:49
Muon::MUON_HITDIFF
@ MUON_HITDIFF
Definition: TruthRelatedMuonPlotOrganizer.h:25
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
Muon::TRK_DEFPARAMPULLS
@ TRK_DEFPARAMPULLS
Definition: TruthRelatedMuonPlotOrganizer.h:25
Muon::MUON_TRUTHHIT
@ MUON_TRUTHHIT
Definition: TruthRelatedMuonPlotOrganizer.h:25
Muon::MUON_PARAMELOSS
@ MUON_PARAMELOSS
Definition: TruthRelatedMuonPlotOrganizer.h:25
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
TruthParticleAuxContainer.h
InDet::ExclusiveOrigin::Primary
@ Primary
Definition: InDetTrackTruthOriginDefs.h:163
Muon::TruthRelatedMuonPlotOrganizer::m_oMSHitDiffPlots
std::unique_ptr< Trk::MSHitDiffPlots > m_oMSHitDiffPlots
Definition: TruthRelatedMuonPlotOrganizer.h:42
Muon::TruthRelatedMuonPlotOrganizer::~TruthRelatedMuonPlotOrganizer
~TruthRelatedMuonPlotOrganizer()
Muon::TruthRelatedMuonPlotOrganizer::m_oMomentumTruthPullPlots_NoTail
std::unique_ptr< Muon::MomentumTruthPullPlots > m_oMomentumTruthPullPlots_NoTail
Definition: TruthRelatedMuonPlotOrganizer.h:48
TrackParticleAuxContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
Muon::TRK_MSHITDIFF
@ TRK_MSHITDIFF
Definition: TruthRelatedMuonPlotOrganizer.h:25
Muon::TruthRelatedMuonPlotOrganizer::TruthRelatedMuonPlotOrganizer
TruthRelatedMuonPlotOrganizer(PlotBase *pParent, const std::string &sDir, bool doBinnedResolutionPlots, std::vector< int > selPlots={})
Definition: TruthRelatedMuonPlotOrganizer.cxx:16
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
Muon::TruthRelatedMuonPlotOrganizer::m_oMatchedPlots
std::unique_ptr< Trk::ParamPlots > m_oMatchedPlots
Definition: TruthRelatedMuonPlotOrganizer.h:40
Muon::TruthRelatedMuonPlotOrganizer::m_oMatchedRecoPlots
std::unique_ptr< Trk::ParamPlots > m_oMatchedRecoPlots
Definition: TruthRelatedMuonPlotOrganizer.h:41
Muon::MUON_PULLSTAIL
@ MUON_PULLSTAIL
Definition: TruthRelatedMuonPlotOrganizer.h:25
Muon::MUON_PULLSNOTAIL
@ MUON_PULLSNOTAIL
Definition: TruthRelatedMuonPlotOrganizer.h:25
DataVector< xAOD::TrackParticle_v1 >
Muon::TruthRelatedMuonPlotOrganizer::m_oMuonTruthHitPlots
std::unique_ptr< Muon::MuonTruthHitPlots > m_oMuonTruthHitPlots
Definition: TruthRelatedMuonPlotOrganizer.h:44
Muon::TruthRelatedMuonPlotOrganizer::m_oDefParamPullPlots
std::unique_ptr< Trk::DefParamPullPlots > m_oDefParamPullPlots
Definition: TruthRelatedMuonPlotOrganizer.h:46
Muon::TruthRelatedMuonPlotOrganizer::m_selPlots
std::vector< int > m_selPlots
Definition: TruthRelatedMuonPlotOrganizer.h:34
Muon::TruthRelatedMuonPlotOrganizer::m_oMuonResolutionPlots
std::unique_ptr< Muon::MuonResolutionPlots > m_oMuonResolutionPlots
Definition: TruthRelatedMuonPlotOrganizer.h:45
Muon::TruthRelatedMuonPlotOrganizer::m_oMuonHitDiffSummaryPlots
std::unique_ptr< Muon::MuonHitDiffSummaryPlots > m_oMuonHitDiffSummaryPlots
Definition: TruthRelatedMuonPlotOrganizer.h:43
TruthRelatedMuonPlotOrganizer.h
Muon::TruthRelatedMuonPlotOrganizer::m_oMatchedRecoElossPlots
std::unique_ptr< Muon::MuonParamElossPlots > m_oMatchedRecoElossPlots
Definition: TruthRelatedMuonPlotOrganizer.h:49
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
Muon::TruthRelatedMuonPlotOrganizer::m_oMomentumTruthPullPlots_Tail
std::unique_ptr< Muon::MomentumTruthPullPlots > m_oMomentumTruthPullPlots_Tail
Definition: TruthRelatedMuonPlotOrganizer.h:47
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
Muon::TruthRelatedMuonPlotOrganizer::fill
void fill(const xAOD::TruthParticle &truthMu, const xAOD::Muon &mu, const xAOD::TrackParticleContainer *MSTracks, float weight=1.0)
Definition: TruthRelatedMuonPlotOrganizer.cxx:64
TrackParticleContainer.h