ATLAS Offline Software
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 
5 #include "MuonValidationPlots.h"
7 
8 #include <utility>
9 
11 
14 
15 MuonValidationPlots::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, ""),
22  m_oTruthRelatedMuonPlots(nullptr),
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])) {
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)
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)
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()) {
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 
139 
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])) {
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 
203 void 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 }
MuonValidationPlots::fillRecoMuonPlots
void fillRecoMuonPlots(const xAOD::Muon &mu, float weight=1.0)
Definition: MuonValidationPlots.cxx:97
MuonValidationPlots::MuonValidationPlots
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)
Definition: MuonValidationPlots.cxx:15
MuonValidationPlots::fillTruthMuonPlots
void fillTruthMuonPlots(const xAOD::TruthParticle &truthMu, float weight=1.0)
Definition: MuonValidationPlots.cxx:131
MuonValidationPlots::m_truthSelections
std::vector< std::string > m_truthSelections
Definition: MuonValidationPlots.h:35
MuonValidationPlots::fillTree
void fillTree(const xAOD::EventInfo *eventInfo, bool isData)
Definition: MuonValidationPlots.cxx:203
MuonValidationPlots::m_selectedWPs
std::vector< int > m_selectedWPs
Definition: MuonValidationPlots.h:33
PlotBase
Definition: PlotBase.h:34
MuonValidationPlots::m_MuonTree
std::unique_ptr< Muon::MuonTree > m_MuonTree
Definition: MuonValidationPlots.h:55
TrackLink
ElementLink< xAOD::TrackParticleContainer > TrackLink
Definition: MuonValidationPlots.cxx:12
python.copyTCTOutput.sDir
sDir
Definition: copyTCTOutput.py:60
MuonValidationPlots::~MuonValidationPlots
virtual ~MuonValidationPlots()
MuonValidationPlots::m_oRecoMuonPlots_perQuality
std::vector< std::unique_ptr< Muon::RecoMuonPlotOrganizer > > m_oRecoMuonPlots_perQuality
Definition: MuonValidationPlots.h:39
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
MuonValidationPlots::m_oRecoMuonPlots
std::unique_ptr< Muon::RecoMuonPlotOrganizer > m_oRecoMuonPlots
Definition: MuonValidationPlots.h:37
Muon::TruthMuonPlotOrganizer
Definition: TruthMuonPlotOrganizer.h:21
MuonParameters::CaloTag
@ CaloTag
Definition: MuonParamDefs.h:64
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
MuonValidationPlots::m_isData
bool m_isData
Definition: MuonValidationPlots.h:52
MuonValidationPlots::m_oTruthRelatedMuonPlots
std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > m_oTruthRelatedMuonPlots
Definition: MuonValidationPlots.h:38
MuonValidationPlots::m_oRecoMuonPlots_perAuthor
std::vector< std::unique_ptr< Muon::RecoMuonPlotOrganizer > > m_oRecoMuonPlots_perAuthor
Definition: MuonValidationPlots.h:40
MuonValidationPlots::m_selectedAuthors
std::vector< unsigned int > m_selectedAuthors
Definition: MuonValidationPlots.h:34
lumiFormat.i
int i
Definition: lumiFormat.py:85
MuonValidationPlots::getMuonTree
Muon::MuonTree * getMuonTree()
Definition: MuonValidationPlots.cxx:184
MuonValidationPlots::fill
void fill(const xAOD::Muon &mu, float weight=1.0)
Definition: MuonValidationPlots.cxx:138
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
Muon::RecoMuonPlotOrganizer
Definition: RecoMuonPlotOrganizer.h:27
MuonValidationPlots::m_doSeparateSAFMuons
bool m_doSeparateSAFMuons
Definition: MuonValidationPlots.h:53
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonValidationPlots::fillTreeBranches
void fillTreeBranches(const xAOD::Muon &mu)
Definition: MuonValidationPlots.cxx:186
Muon::TruthRelatedMuonPlotOrganizer
Definition: TruthRelatedMuonPlotOrganizer.h:27
MuonLink
ElementLink< xAOD::MuonContainer > MuonLink
Definition: MuonValidationPlots.cxx:13
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
MuonValidationPlots::m_oTruthRelatedMuonPlots_perQuality
std::vector< std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > > m_oTruthRelatedMuonPlots_perQuality
Definition: MuonValidationPlots.h:41
Muon::MUON_CHARGEPARAM
@ MUON_CHARGEPARAM
Definition: RecoMuonPlotOrganizer.h:25
MuonValidationPlots::m_oTruthRelatedMuonPlots_perAuthor
std::vector< std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > > m_oTruthRelatedMuonPlots_perAuthor
Definition: MuonValidationPlots.h:42
MuonValidationPlots::m_oTruthRelatedMuonPlots_SiAssocFwrdMu
std::vector< std::unique_ptr< Muon::TruthRelatedMuonPlotOrganizer > > m_oTruthRelatedMuonPlots_SiAssocFwrdMu
Definition: MuonValidationPlots.h:45
MuonValidationPlots::isGoodTruthTrack
bool isGoodTruthTrack(const xAOD::TruthParticle &truthMu)
Definition: MuonValidationPlots.cxx:210
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
test_pyathena.counter
counter
Definition: test_pyathena.py:15
ParticleJetParams::Author
Author
Definition: ParticleJetParamDefs.h:33
Muon::MAX_RECOPLOTCLASS
@ MAX_RECOPLOTCLASS
Definition: RecoMuonPlotOrganizer.h:25
MuonEnumDefs.h
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
Muon::MuonTree
Definition: MuonTree.h:20
MuonValidationPlots::m_oTruthMuonPlots
std::vector< std::unique_ptr< Muon::TruthMuonPlotOrganizer > > m_oTruthMuonPlots
Definition: MuonValidationPlots.h:43
MuonValidationPlots.h
MuonValidationPlots::m_oRecoMuonPlots_SiAssocFwrdMu
std::vector< std::unique_ptr< Muon::RecoMuonPlotOrganizer > > m_oRecoMuonPlots_SiAssocFwrdMu
Definition: MuonValidationPlots.h:46