ATLAS Offline Software
Loading...
Searching...
No Matches
MuonValidationPlots.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <utility>
9
11
14
15MuonValidationPlots::MuonValidationPlots(PlotBase* pParent, const std::string& sDir, std::vector<int> wps,
16 std::vector<unsigned int> authors, bool isData, bool doBinnedResolutionPlots,
17 bool doSeparateSAFMuons, bool doMuonTree) :
18 PlotBase(pParent, sDir),
19 m_selectedWPs(std::move(wps)),
20 m_selectedAuthors(std::move(authors)),
21 m_truthSelections(2, ""),
23 m_isData(isData),
24 m_doSeparateSAFMuons(doSeparateSAFMuons),
25 m_MuonTree(nullptr) {
26 if (!m_isData) {
27 m_truthSelections[0] = "all"; // no selection on truth muons (minimum selection is |eta|<2.5, pt>5 GeV, defined in
28 // MuonPhysValMonitoringTool::handleTruthMuon()
29 m_truthSelections[1] = "MSAcceptance"; // truth muons in MS acceptance (at least 4 associated hits in the MS)
30
31 // histogram classes for all muons
32 for (const auto& truthSelection : m_truthSelections) {
33 m_oTruthMuonPlots.emplace_back(new Muon::TruthMuonPlotOrganizer(this, "truth/" + truthSelection));
34 }
36 new Muon::TruthRelatedMuonPlotOrganizer(this, "matched/AllMuons", doBinnedResolutionPlots));
37 }
38
39 std::vector<int> allPlotCategories(0);
40 std::vector<int> selectedPlotCategories(0);
41 for (unsigned int i = 0; i < Muon::MAX_RECOPLOTCLASS; i++) {
42 allPlotCategories.emplace_back(i);
43 if (i != Muon::MUON_CHARGEPARAM) selectedPlotCategories.emplace_back(i);
44 }
45
46 // histogram classes for all muons
47 m_oRecoMuonPlots.reset(new Muon::RecoMuonPlotOrganizer(this, "reco/AllMuons", allPlotCategories));
48
49 // define a histogram class for each of the selected muon qualities
50 for (unsigned int i = 0; i < m_selectedWPs.size(); i++) {
51 std::string sQuality = Muon::EnumDefs::toString((xAOD::Muon::Quality)m_selectedWPs[i]);
53 this, "reco/" + sQuality, (sQuality == "Medium" || sQuality == "Tight") ? allPlotCategories : selectedPlotCategories));
54
55 if (!m_isData) {
56 bool doBinnedPlots = false;
57 if (sQuality == "Medium") doBinnedPlots = true;
59 new Muon::TruthRelatedMuonPlotOrganizer(this, "matched/" + sQuality, doBinnedPlots));
60 }
61 }
62
63 // define a histogram class for each of the selected muon authors (+one inclusive for all authors)
64 for (unsigned int i = 0; i < m_selectedAuthors.size(); i++) {
65 std::string sAuthor = Muon::EnumDefs::toString((xAOD::Muon::Author)m_selectedAuthors[i]);
66 if (sAuthor == "CaloTag") sAuthor = "CaloTagTight";
67 m_oRecoMuonPlots_perAuthor.emplace_back(
68 new Muon::RecoMuonPlotOrganizer(this, "reco/" + sAuthor, (sAuthor == "MuidCo") ? allPlotCategories : selectedPlotCategories));
69 if (!m_isData)
71 new Muon::TruthRelatedMuonPlotOrganizer(this, "matched/" + sAuthor, doBinnedResolutionPlots));
72 }
73
74 // define histogram class for loose CaloTag and append to author plots, not very nice workaround though
75 for (unsigned int i = 0; i < m_selectedAuthors.size(); i++) {
76 if ((xAOD::Muon::Author)m_selectedAuthors[i] == xAOD::Muon::CaloTag) { // found CaloTag in list, also do CaloTagLoose
77 m_oRecoMuonPlots_perAuthor.emplace_back(new Muon::RecoMuonPlotOrganizer(this, "reco/CaloTagLoose", selectedPlotCategories));
78 if (!m_isData)
80 new Muon::TruthRelatedMuonPlotOrganizer(this, "matched/CaloTagLoose", doBinnedResolutionPlots));
81 }
82 }
83
84 // define histogram class for SiliconAssociatedForwardMuons
86 m_oRecoMuonPlots_SiAssocFwrdMu.emplace_back(new Muon::RecoMuonPlotOrganizer(this, "reco/SiAssocForward", selectedPlotCategories));
87 if (!m_isData)
89 new Muon::TruthRelatedMuonPlotOrganizer(this, "matched/SiAssocForward", doBinnedResolutionPlots));
90 }
91
92 if (doMuonTree) m_MuonTree.reset(new Muon::MuonTree(this, "", !m_isData));
93}
94
96
98 // fill hists for all muons
99 m_oRecoMuonPlots->fill(mu, weight);
100 // fill separate hists for each muon quality
101 xAOD::Muon::Quality muqual = mu.quality();
102 for (unsigned int i = 0; i < m_selectedWPs.size(); i++) {
103 if (muqual <= (xAOD::Muon::Quality)m_selectedWPs[i]) { m_oRecoMuonPlots_perQuality[i]->fill(mu, weight); }
104 }
105 // fill separate hists for each author
106 for (unsigned int i = 0; i < m_selectedAuthors.size(); i++) {
107 if (mu.isAuthor((xAOD::Muon::Author)m_selectedAuthors[i])) {
108 if ((xAOD::Muon::Author)m_selectedAuthors[i] == (xAOD::Muon::CaloTag)) {
109 int ipar = 0;
110 if (mu.parameter(ipar, xAOD::Muon::CaloMuonIDTag)) { ; }
111 if (ipar < 11) continue;
112 }
113
114 // filter SiliconAssociatedForwardMuons
115 if (mu.muonType() != (xAOD::Muon::MuonType)xAOD::Muon::SiliconAssociatedForwardMuon || !m_doSeparateSAFMuons)
116 m_oRecoMuonPlots_perAuthor[i]->fill(mu, weight);
117 }
118 }
119 // fill SiliconAssociatedForwardMuons
120 for (unsigned int i = 0; i < m_oTruthRelatedMuonPlots_SiAssocFwrdMu.size(); i++) {
121 if (mu.muonType() == (xAOD::Muon::MuonType)xAOD::Muon::SiliconAssociatedForwardMuon)
122 m_oRecoMuonPlots_SiAssocFwrdMu[i]->fill(mu, weight);
123 }
124 // fill CaloTagLoose (one additional plot in plot list)
125 unsigned int counter = m_selectedAuthors.size();
126 if (counter + 1 == m_oRecoMuonPlots_perAuthor.size()) {
127 if (mu.isAuthor(xAOD::Muon::CaloTag)) m_oRecoMuonPlots_perAuthor[counter]->fill(mu, weight);
128 }
129}
130
132 m_oTruthMuonPlots[0]->fill(truthMu, weight); // no selections
133 if (isGoodTruthTrack(truthMu)) { // in MS acceptance (minimum precision hits)
134 m_oTruthMuonPlots[1]->fill(truthMu, weight);
135 }
136}
137
138void MuonValidationPlots::fill(const xAOD::Muon& mu, float weight) { fillRecoMuonPlots(mu, weight); }
139
140void MuonValidationPlots::fill(const xAOD::TruthParticle& truthMu, float weight) { fillTruthMuonPlots(truthMu, weight); }
141
143 float weight) {
144 if (truthMu) fillTruthMuonPlots(*truthMu, weight);
145 if (mu) fillRecoMuonPlots(*mu, weight);
146
147 if ((mu) && (truthMu)) {
148 // plots for all
149 m_oTruthRelatedMuonPlots->fill(*truthMu, *mu, MSTracks, weight);
150 // fill SiliconAssociatedForwardMuons
151 for (unsigned int i = 0; i < m_oTruthRelatedMuonPlots_SiAssocFwrdMu.size(); i++) {
152 if (mu->muonType() == xAOD::Muon::SiliconAssociatedForwardMuon || !m_doSeparateSAFMuons)
153 m_oTruthRelatedMuonPlots_SiAssocFwrdMu[i]->fill(*truthMu, *mu, MSTracks, weight);
154 }
155
156 // plots per quality
157 xAOD::Muon::Quality muqual = mu->quality();
158 for (unsigned int i = 0; i < m_selectedWPs.size(); i++) {
159 if (muqual <= (xAOD::Muon::Quality)m_selectedWPs[i]) {
160 m_oTruthRelatedMuonPlots_perQuality[i]->fill(*truthMu, *mu, MSTracks, weight);
161 }
162 }
163 // plots per author
164 for (unsigned int i = 0; i < m_selectedAuthors.size(); i++) {
165 if (mu->isAuthor((xAOD::Muon::Author)m_selectedAuthors[i])) {
166 if ((xAOD::Muon::Author)m_selectedAuthors[i] == xAOD::Muon::CaloTag) {
167 int ipar = 0;
168 if (mu->parameter(ipar, xAOD::Muon::CaloMuonIDTag)) { ; }
169 if (ipar < 11) continue;
170 }
171 // filter SilicionAssociatedForwardMuons
172 if (mu->muonType() != xAOD::Muon::SiliconAssociatedForwardMuon || !m_doSeparateSAFMuons)
173 m_oTruthRelatedMuonPlots_perAuthor[i]->fill(*truthMu, *mu, MSTracks, weight);
174 }
175 }
176 // fill CaloTagLoose (one additional plot in plot list)
177 unsigned int counter = m_selectedAuthors.size();
178 if (counter + 1 == m_oRecoMuonPlots_perAuthor.size()) {
179 if (mu->isAuthor(xAOD::Muon::CaloTag)) m_oTruthRelatedMuonPlots_perAuthor[counter]->fill(*truthMu, *mu, MSTracks, weight);
180 }
181 }
182}
183
185
187 if (m_MuonTree) m_MuonTree->fillRecoMuonBranches(mu);
188}
189
191 if (m_MuonTree) m_MuonTree->fillTruthMuonBranches(truthMu, isGoodTruthTrack(truthMu));
192}
193
195 const xAOD::TrackParticleContainer* MSTracks) {
196 if (!m_MuonTree) return;
197 if (mu) m_MuonTree->fillRecoMuonBranches(*mu);
198 if (truthMu) m_MuonTree->fillTruthMuonBranches(*truthMu, isGoodTruthTrack(*truthMu));
199
200 if (truthMu && mu) { m_MuonTree->fillTruthMuonBranches(*truthMu, *mu, MSTracks, isGoodTruthTrack(*truthMu)); }
201}
202
203void MuonValidationPlots::fillTree(const xAOD::EventInfo* eventInfo, bool isData) {
204 if (!m_MuonTree) return;
205 m_MuonTree->fillEventBranches(eventInfo, isData);
206 m_MuonTree->getTree()->Fill();
207 m_MuonTree->postFillTreeActions();
208}
209
211 static const std::array<std::string,6> hitTypes{"innerSmallHits", "innerLargeHits", "middleSmallHits",
212 "middleLargeHits", "outerSmallHits", "outerLargeHits"}; // MDT + CSC
213 int minPrecHits = 5;
214
215 int nPrecHits = 0;
216 bool hasEnoughPrecHits = false;
217
218 for (const auto& hitTypeItr : hitTypes) {
219 SG::ConstAccessor<uint8_t> acc(hitTypeItr);
220 nPrecHits += acc.withDefault (truthMu, 0);
221 if (nPrecHits >= minPrecHits) {
222 hasEnoughPrecHits = true;
223 break;
224 }
225 }
226 return (hasEnoughPrecHits);
227}
ElementLink< xAOD::MuonContainer > MuonLink
Helper class to provide constant type-safe access to aux data.
ElementLink< xAOD::TrackParticleContainer > TrackLink
bool isGoodTruthTrack(const xAOD::TruthParticle &truthMu)
void fill(const xAOD::Muon &mu, float weight=1.0)
std::unique_ptr< Muon::MuonTree > m_MuonTree
std::unique_ptr< Muon::RecoMuonPlotOrganizer > m_oRecoMuonPlots
void fillTreeBranches(const xAOD::Muon &mu)
std::vector< int > m_selectedWPs
std::vector< std::unique_ptr< Muon::TruthMuonPlotOrganizer > > m_oTruthMuonPlots
void fillRecoMuonPlots(const xAOD::Muon &mu, float weight=1.0)
std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > m_oTruthRelatedMuonPlots
void fillTree(const xAOD::EventInfo *eventInfo, bool isData)
std::vector< std::unique_ptr< Muon::RecoMuonPlotOrganizer > > m_oRecoMuonPlots_perAuthor
std::vector< std::string > m_truthSelections
std::vector< std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > > m_oTruthRelatedMuonPlots_perAuthor
virtual ~MuonValidationPlots()
std::vector< std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > > m_oTruthRelatedMuonPlots_perQuality
Muon::MuonTree * getMuonTree()
std::vector< unsigned int > m_selectedAuthors
std::vector< std::unique_ptr< Muon::RecoMuonPlotOrganizer > > m_oRecoMuonPlots_SiAssocFwrdMu
std::vector< std::unique_ptr< Muon::RecoMuonPlotOrganizer > > m_oRecoMuonPlots_perQuality
void fillTruthMuonPlots(const xAOD::TruthParticle &truthMu, float weight=1.0)
MuonValidationPlots(PlotBase *pParent, const std::string &sDir, std::vector< int > wps, std::vector< unsigned int > authors, bool isData, bool doBinnedResolutionPlots, bool doSplitSAFMuons, bool doMuonTree=false)
std::vector< std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > > m_oTruthRelatedMuonPlots_SiAssocFwrdMu
PlotBase(PlotBase *parent, const std::string &sDir)
Definition PlotBase.cxx:29
Helper class to provide constant type-safe access to aux data.
static const char * toString(Muon::EnumDefs::DetRegion reg)
STL namespace.
EventInfo_v1 EventInfo
Definition of the latest event info 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: