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
12
13MuonValidationPlots::MuonValidationPlots(PlotBase* pParent, const std::string& sDir, std::set<int> wps,
14 std::set<int> authors, bool isData, bool doBinnedResolutionPlots,
15 bool doSeparateSAFMuons) :
16 PlotBase(pParent, sDir),
17 m_selectedWPs(wps.begin(),wps.end()),
18 m_selectedAuthors(authors.begin(), authors.end()),
19 m_truthSelections(2, ""),
21 m_isData(isData),
22 m_doSeparateSAFMuons(doSeparateSAFMuons) {
23 if (!m_isData) {
24 m_truthSelections[0] = "all"; // no selection on truth muons (minimum selection is |eta|<2.5, pt>5 GeV, defined in
25 // MuonPhysValMonitoringTool::handleTruthMuon()
26 m_truthSelections[1] = "MSAcceptance"; // truth muons in MS acceptance (at least 4 associated hits in the MS)
27
28 // histogram classes for all muons
29 for (const auto& truthSelection : m_truthSelections) {
30 m_oTruthMuonPlots.emplace_back(std::make_unique<Muon::TruthMuonPlotOrganizer>(this, "truth/" + truthSelection));
31 }
32 m_oTruthRelatedMuonPlots = std::make_unique<Muon::TruthRelatedMuonPlotOrganizer>(this, "matched/AllMuons", doBinnedResolutionPlots);
33 }
34
35 std::vector<int> allPlotCategories(0);
36 std::vector<int> selectedPlotCategories(0);
37 for (unsigned int i = 0; i < Muon::MAX_RECOPLOTCLASS; i++) {
38 allPlotCategories.emplace_back(i);
39 if (i != Muon::MUON_CHARGEPARAM) selectedPlotCategories.emplace_back(i);
40 }
41
42 // histogram classes for all muons
43 m_oRecoMuonPlots = std::make_unique<Muon::RecoMuonPlotOrganizer>(this, "reco/AllMuons", allPlotCategories);
44
45 // define a histogram class for each of the selected muon qualities
46 for (unsigned int i = 0; i < m_selectedWPs.size(); i++) {
47 auto sQuality = xAOD::Muon::toString(static_cast<xAOD::Muon::Quality>(m_selectedWPs[i]));
48 m_oRecoMuonPlots_perQuality.emplace_back(std::make_unique<Muon::RecoMuonPlotOrganizer>(
49 this, std::format("reco/{:}", sQuality), (sQuality == "Medium" || sQuality == "Tight") ? allPlotCategories : selectedPlotCategories));
50
51 if (!m_isData) {
52 bool doBinnedPlots = false;
53 if (sQuality == "Medium") doBinnedPlots = true;
55 std::make_unique<Muon::TruthRelatedMuonPlotOrganizer>(this, std::format("matched/{:}", sQuality), doBinnedPlots));
56 }
57 }
58
59 // define a histogram class for each of the selected muon authors (+one inclusive for all authors)
60 for (unsigned int i = 0; i < m_selectedAuthors.size(); i++) {
61 const auto author = static_cast<xAOD::Muon::Author>(m_selectedAuthors[i]);
62 std::string sAuthor{xAOD::Muon::toString(author)};
63 if (sAuthor == "CaloTag") sAuthor = "CaloTagTight";
64 m_oRecoMuonPlots_perAuthor.emplace_back(
65 std::make_unique<Muon::RecoMuonPlotOrganizer>(this, "reco/" + sAuthor, (sAuthor == "MuidCo") ? allPlotCategories : selectedPlotCategories));
66 if (!m_isData)
68 std::make_unique<Muon::TruthRelatedMuonPlotOrganizer>(this, "matched/" + sAuthor, doBinnedResolutionPlots));
69 }
70
71 // define histogram class for loose CaloTag and append to author plots, not very nice workaround though
72 for (unsigned int i = 0; i < m_selectedAuthors.size(); i++) {
73 if (static_cast<xAOD::Muon::Author>(m_selectedAuthors[i]) == xAOD::Muon::Author::CaloTag) { // found CaloTag in list, also do CaloTagLoose
74 m_oRecoMuonPlots_perAuthor.emplace_back(std::make_unique<Muon::RecoMuonPlotOrganizer>(this, "reco/CaloTagLoose", selectedPlotCategories));
75 if (!m_isData)
77 std::make_unique<Muon::TruthRelatedMuonPlotOrganizer>(this, "matched/CaloTagLoose", doBinnedResolutionPlots));
78 }
79 }
80
81 // define histogram class for SiliconAssociatedForwardMuons
83 m_oRecoMuonPlots_SiAssocFwrdMu.emplace_back(std::make_unique<Muon::RecoMuonPlotOrganizer>(this, "reco/SiAssocForward", selectedPlotCategories));
84 if (!m_isData)
86 std::make_unique<Muon::TruthRelatedMuonPlotOrganizer>(this, "matched/SiAssocForward", doBinnedResolutionPlots));
87 }
88
89}
90
92
94 // fill hists for all muons
95 m_oRecoMuonPlots->fill(mu, weight);
96 // fill separate hists for each muon quality
97 xAOD::Muon::Quality muqual = mu.quality();
98 for (unsigned int i = 0; i < m_selectedWPs.size(); i++) {
99 if (muqual <= (xAOD::Muon::Quality)m_selectedWPs[i]) { m_oRecoMuonPlots_perQuality[i]->fill(mu, weight); }
100 }
101 // fill separate hists for each author
102 for (unsigned int i = 0; i < m_selectedAuthors.size(); i++) {
103 auto author = static_cast<xAOD::Muon::Author>(m_selectedAuthors[i]);
104 if (mu.isAuthor(author)) {
105 if (author == (xAOD::Muon::Author::CaloTag)) {
106 int ipar = 0;
107 if (mu.parameter(ipar, xAOD::Muon::ParamDef::CaloMuonIDTag)) { ; }
108 if (ipar < 11) continue;
109 }
110
111 // filter SiliconAssociatedForwardMuons
112 if (mu.muonType() != xAOD::Muon::MuonType::SiliconAssociatedForwardMuon || !m_doSeparateSAFMuons)
113 m_oRecoMuonPlots_perAuthor[i]->fill(mu, weight);
114 }
115 }
116 // fill SiliconAssociatedForwardMuons
117 for (unsigned int i = 0; i < m_oTruthRelatedMuonPlots_SiAssocFwrdMu.size(); i++) {
118 if (mu.muonType() == xAOD::Muon::MuonType::SiliconAssociatedForwardMuon)
119 m_oRecoMuonPlots_SiAssocFwrdMu[i]->fill(mu, weight);
120 }
121 // fill CaloTagLoose (one additional plot in plot list)
122 unsigned int counter = m_selectedAuthors.size();
123 if (counter + 1 == m_oRecoMuonPlots_perAuthor.size()) {
124 if (mu.isAuthor(xAOD::Muon::Author::CaloTag)) m_oRecoMuonPlots_perAuthor[counter]->fill(mu, weight);
125 }
126}
127
129 m_oTruthMuonPlots[0]->fill(truthMu, weight); // no selections
130 if (isGoodTruthTrack(truthMu)) { // in MS acceptance (minimum precision hits)
131 m_oTruthMuonPlots[1]->fill(truthMu, weight);
132 }
133}
134
135void MuonValidationPlots::fill(const xAOD::Muon& mu, float weight) { fillRecoMuonPlots(mu, weight); }
136
137void MuonValidationPlots::fill(const xAOD::TruthParticle& truthMu, float weight) { fillTruthMuonPlots(truthMu, weight); }
138
140 const xAOD::Muon* mu, const xAOD::TrackParticleContainer* ,
141 float weight) {
142 if (truthMu) fillTruthMuonPlots(*truthMu, weight);
143 if (mu) fillRecoMuonPlots(*mu, weight);
144
145 if ((mu) && (truthMu)) {
146 // plots for all
147 m_oTruthRelatedMuonPlots->fill(*truthMu, *mu, weight);
148 // fill SiliconAssociatedForwardMuons
149 for (unsigned int i = 0; i < m_oTruthRelatedMuonPlots_SiAssocFwrdMu.size(); i++) {
150 if (mu->muonType() == xAOD::Muon::MuonType::SiliconAssociatedForwardMuon || !m_doSeparateSAFMuons)
151 m_oTruthRelatedMuonPlots_SiAssocFwrdMu[i]->fill(*truthMu, *mu, weight);
152 }
153
154 // plots per quality
155 xAOD::Muon::Quality muqual = mu->quality();
156 for (unsigned int i = 0; i < m_selectedWPs.size(); i++) {
157 if (muqual <= (xAOD::Muon::Quality)m_selectedWPs[i]) {
158 m_oTruthRelatedMuonPlots_perQuality[i]->fill(*truthMu, *mu, weight);
159 }
160 }
161 // plots per author
162 for (unsigned int i = 0; i < m_selectedAuthors.size(); i++) {
163 auto author = static_cast<xAOD::Muon::Author>(m_selectedAuthors[i]);
164 if (mu->isAuthor(author)) {
165 if (author == xAOD::Muon::Author::CaloTag) {
166 int ipar = 0;
167 if (mu->parameter(ipar, xAOD::Muon::ParamDef::CaloMuonIDTag)) { ; }
168 if (ipar < 11) continue;
169 }
170 // filter SilicionAssociatedForwardMuons
171 if (mu->muonType() != xAOD::Muon::MuonType::SiliconAssociatedForwardMuon || !m_doSeparateSAFMuons)
172 m_oTruthRelatedMuonPlots_perAuthor[i]->fill(*truthMu, *mu, weight);
173 }
174 }
175 // fill CaloTagLoose (one additional plot in plot list)
176 unsigned int counter = m_selectedAuthors.size();
177 if (counter + 1 == m_oRecoMuonPlots_perAuthor.size()) {
178 if (mu->isAuthor(xAOD::Muon::Author::CaloTag)) m_oTruthRelatedMuonPlots_perAuthor[counter]->fill(*truthMu, *mu, weight);
179 }
180 }
181}
182
183
184
186 static const std::array<std::string,6> hitTypes{"innerSmallHits", "innerLargeHits", "middleSmallHits",
187 "middleLargeHits", "outerSmallHits", "outerLargeHits"}; // MDT + CSC
188 int minPrecHits = 5;
189
190 int nPrecHits = 0;
191 bool hasEnoughPrecHits = false;
192
193 for (const auto& hitTypeItr : hitTypes) {
194 SG::ConstAccessor<uint8_t> acc(hitTypeItr);
195 nPrecHits += acc.withDefault (truthMu, 0);
196 if (nPrecHits >= minPrecHits) {
197 hasEnoughPrecHits = true;
198 break;
199 }
200 }
201 return (hasEnoughPrecHits);
202}
Helper class to provide constant type-safe access to aux data.
bool isGoodTruthTrack(const xAOD::TruthParticle &truthMu)
void fill(const xAOD::Muon &mu, float weight=1.0)
std::unique_ptr< Muon::RecoMuonPlotOrganizer > m_oRecoMuonPlots
MuonValidationPlots(PlotBase *pParent, const std::string &sDir, std::set< int > wps, std::set< int > authors, bool isData, bool doBinnedResolutionPlots, bool doSplitSAFMuons)
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
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
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)
std::vector< std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > > m_oTruthRelatedMuonPlots_SiAssocFwrdMu
PlotBase(PlotBase *parent, std::string_view sDir)
Definition PlotBase.cxx:29
Helper class to provide constant type-safe access to aux data.
TruthParticle_v1 TruthParticle
Typedef to implementation.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Muon_v1 Muon
Reference the current persistent version: