ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
12
14
15namespace Muon {
16
18 PlotBase* pParent, const std::string& sDir, bool doBinnedResolutionPlots,
19 std::vector<int> selPlots)
20 : PlotBase(pParent, sDir)
21// Truth related plots
22{
23
24 if (selPlots.empty()) {
25 for (unsigned int i = 0; i < MAX_TRUTHRELATEDPLOTCLASS; i++) {
26 m_selPlots.push_back(i);
27 }
28 } else {
29 m_selPlots = std::move(selPlots);
30 }
31
32 for (auto p : m_selPlots) {
33 switch (p) {
34 case TRK_MATCHEDTRUE:
35 m_oMatchedPlots = std::make_unique<Trk::ParamPlots>(
36 this, "/kinematics/", "Matched Muons");
37 break;
38 case TRK_MATCHEDRECO:
39 m_oMatchedRecoPlots = std::make_unique<Trk::ParamPlots>(
40 this, "/kinematicsReco/", "Matched Muons");
41 break;
42 case TRK_MSHITDIFF:
43 m_oMSHitDiffPlots =
44 std::make_unique<Trk::MSHitDiffPlots>(this, "/hits/");
45 break;
46 case MUON_HITDIFF:
47 m_oMuonHitDiffSummaryPlots =
48 std::make_unique<Muon::MuonHitDiffSummaryPlots>(this,
49 "/hits/");
50 break;
51 case MUON_TRUTHHIT:
52 m_oMuonTruthHitPlots =
53 std::make_unique<Muon::MuonTruthHitPlots>(this,
54 "/truthHits/");
55 break;
56 case MUON_RESOL:
57 m_oMuonResolutionPlots =
58 std::make_unique<Muon::MuonResolutionPlots>(
59 this, "/resolution/", "", doBinnedResolutionPlots);
60 break;
62 m_oDefParamPullPlots = std::make_unique<Trk::DefParamPullPlots>(
63 this, "/pulls/", "");
64 break;
65 case MUON_PULLSTAIL:
66 m_oMomentumTruthPullPlots_Tail =
67 std::make_unique<Muon::MomentumTruthPullPlots>(
68 this, "/momentumPulls/", "Tail");
69 break;
71 m_oMomentumTruthPullPlots_NoTail =
72 std::make_unique<Muon::MomentumTruthPullPlots>(
73 this, "/momentumPulls/", "NoTail");
74 break;
75 case MUON_PARAMELOSS:
76 m_oMatchedRecoElossPlots =
77 std::make_unique<Muon::MuonParamElossPlots>(this,
78 "/Eloss/");
79 break;
80 }
81 }
82}
83TruthRelatedMuonPlotOrganizer::~TruthRelatedMuonPlotOrganizer() = default;
84
86 const xAOD::TruthParticle& truthMu, const xAOD::Muon& mu,
87 const xAOD::TrackParticleContainer* MSTracks, float weight) {
88 if (m_oMatchedPlots) {
89 m_oMatchedPlots->fill(truthMu, weight);
90 }
92 m_oMuonHitDiffSummaryPlots->fill(mu, truthMu, weight);
93 }
95 m_oMuonTruthHitPlots->fill(mu, weight);
96 }
97
98 // for eloss
100 m_oMatchedRecoElossPlots->fill(truthMu, mu, weight);
101 }
102
103 // Tracking related plots
104 const xAOD::TrackParticle* primaryTrk =
105 mu.trackParticle(xAOD::Muon::Primary);
106 // const xAOD::TrackParticle* meTrk =
107 // mu.trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
108
109 if (!primaryTrk) {
110 return;
111 }
113 m_oMatchedRecoPlots->fill(*primaryTrk, weight);
114 }
115 if (m_oMSHitDiffPlots) {
116 m_oMSHitDiffPlots->fill(*primaryTrk, truthMu, weight);
117 }
119 m_oMuonResolutionPlots->fill(*primaryTrk, truthMu, weight);
120 }
122 m_oDefParamPullPlots->fill(*primaryTrk, truthMu, weight);
123 }
124
126 // muon spectrometer track at MS entry (not extrapolated)
127 const xAOD::TrackParticle* msTrk(nullptr);
128 // muon extrapolated to IP
129 // const xAOD::TrackParticle* msExtrapTrk(0);
130
133 // for 20.1.0...
138 // for 20.1.3...
139 // const xAOD::TrackParticle* msExtrapTrk =
140 // mu.trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
141
142 // trying to accomodate both in a way that the code compiles in both
143 // releases
144 static const SG::ConstAccessor<
146 extrapLinkAcc("extrapolatedMuonSpectrometerTrackParticleLink");
147 if (extrapLinkAcc.isAvailable(mu) && extrapLinkAcc(mu).isValid()) {
148 // cool, we got both links:
149 // int correctEnumForExtrap =
150 // ((int)xAOD::Muon::MuonSpectrometerTrackParticle)+2; msExtrapTrk =
151 // mu.trackParticle((xAOD::Muon::TrackParticleType)
152 // correctEnumForExtrap);
153 msTrk = mu.trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
154 } else {
155 // gymnastics to get msTrk...
156 const ElementLink<xAOD::TrackParticleContainer>& msExtrapTrkLink =
157 mu.trackParticleLink(xAOD::Muon::MuonSpectrometerTrackParticle);
158 static const SG::ConstAccessor<TruthLink> truthParticleLinkAcc(
159 "truthParticleLink");
160 if (msExtrapTrkLink.isValid()) {
161 // msExtrapTrk = mu.trackParticle(
162 // xAOD::Muon::MuonSpectrometerTrackParticle );
163 TruthLink truthLink_muTrk;
164 if (truthParticleLinkAcc.isAvailable(**msExtrapTrkLink)) {
165 truthLink_muTrk = truthParticleLinkAcc(**msExtrapTrkLink);
166 }
167 if (truthLink_muTrk.isValid()) {
168 for (const auto trk : *MSTracks) {
169 TruthLink truthLink_msTrk;
170 if (truthParticleLinkAcc.isAvailable(*trk)) {
171 truthLink_msTrk = truthParticleLinkAcc(*trk);
172 if (truthLink_msTrk.isValid()) {
173 if (truthLink_msTrk == truthLink_muTrk) {
174 msTrk = trk; // got it!
175 break;
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183#ifndef XAOD_ANALYSIS
184 float eloss = 0;
185 if (mu.parameter(eloss, xAOD::Muon::EnergyLoss)) {
186 if (mu.energyLossType() !=
187 xAOD::Muon::Tail) { // to test MEASURED energy loss
189 m_oMomentumTruthPullPlots_NoTail->fill(mu, msTrk, truthMu,
190 weight);
191 }
192 } else {
195 mu, msTrk, truthMu,
196 weight); // to test PARAMETRIZED energy loss
197 }
198 }
199 }
200#endif // not XAOD_ANALYSIS
201 }
202}
203
205 const xAOD::TrackParticle& muTP,
206 float weight) {
207 // Tracking related plots
208 if (m_oMatchedPlots) {
209 m_oMatchedPlots->fill(truthMu, weight);
210 }
212 m_oMatchedRecoPlots->fill(muTP, weight);
213 }
215 m_oDefParamPullPlots->fill(muTP, truthMu, weight);
216 }
218 m_oMuonResolutionPlots->fill(muTP, truthMu, weight);
219 }
220 if (m_oMSHitDiffPlots) {
221 m_oMSHitDiffPlots->fill(muTP, truthMu, weight);
222 }
223}
224
225} // namespace Muon
Helper class to provide constant type-safe access to aux data.
ElementLink< xAOD::TruthParticleContainer > TruthLink
void fill(const xAOD::TruthParticle &truthMu, const xAOD::Muon &mu, const xAOD::TrackParticleContainer *MSTracks, float weight=1.0)
std::unique_ptr< Muon::MuonHitDiffSummaryPlots > m_oMuonHitDiffSummaryPlots
std::unique_ptr< Trk::DefParamPullPlots > m_oDefParamPullPlots
std::unique_ptr< Trk::ParamPlots > m_oMatchedRecoPlots
std::unique_ptr< Trk::ParamPlots > m_oMatchedPlots
std::unique_ptr< Muon::MuonResolutionPlots > m_oMuonResolutionPlots
std::unique_ptr< Muon::MuonParamElossPlots > m_oMatchedRecoElossPlots
TruthRelatedMuonPlotOrganizer(PlotBase *pParent, const std::string &sDir, bool doBinnedResolutionPlots, std::vector< int > selPlots={})
std::unique_ptr< Muon::MomentumTruthPullPlots > m_oMomentumTruthPullPlots_NoTail
std::unique_ptr< Trk::MSHitDiffPlots > m_oMSHitDiffPlots
std::unique_ptr< Muon::MuonTruthHitPlots > m_oMuonTruthHitPlots
std::unique_ptr< Muon::MomentumTruthPullPlots > m_oMomentumTruthPullPlots_Tail
PlotBase(PlotBase *parent, std::string_view sDir)
Definition PlotBase.cxx:29
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Muon_v1 Muon
Reference the current persistent version: