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
11
13
14namespace Muon{
15
16TruthRelatedMuonPlotOrganizer::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;
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;
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
64 void TruthRelatedMuonPlotOrganizer::fill(const xAOD::TruthParticle& truthMu, const xAOD::Muon& mu, const xAOD::TrackParticleContainer* MSTracks, float weight){
65 if (m_oMatchedPlots) m_oMatchedPlots->fill( truthMu , weight);
66 if (m_oMuonHitDiffSummaryPlots) m_oMuonHitDiffSummaryPlots->fill(mu, truthMu, weight);
67 if (m_oMuonTruthHitPlots) m_oMuonTruthHitPlots->fill(mu,weight);
68
69 // for eloss
70 if (m_oMatchedRecoElossPlots) m_oMatchedRecoElossPlots->fill(truthMu, mu , weight );
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);
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
134 if (m_oMomentumTruthPullPlots_NoTail) m_oMomentumTruthPullPlots_NoTail->fill(mu, msTrk, truthMu, weight);
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
144 void TruthRelatedMuonPlotOrganizer::fill(const xAOD::TruthParticle& truthMu, const xAOD::TrackParticle& muTP, float weight){
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
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
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, const std::string &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: