ATLAS Offline Software
MuonHitSummaryTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MuonHitSummaryTool.h"
6 
7 #include <iostream>
8 
10 #include "TrkTrack/Track.h"
13 
14 namespace Muon {
15 
16  MuonHitSummaryTool::MuonHitSummaryTool(const std::string& ty, const std::string& na, const IInterface* pa) : AthAlgTool(ty, na, pa) {
17  declareInterface<IMuonHitSummaryTool>(this);
18  }
19 
21  ATH_CHECK(m_idHelperSvc.retrieve());
22  if (!m_summaryHelperTool.empty()) ATH_CHECK(m_summaryHelperTool.retrieve());
23  if (!m_printer.empty()) ATH_CHECK(m_printer.retrieve());
24  ATH_CHECK(m_edmHelperSvc.retrieve());
25  return StatusCode::SUCCESS;
26  }
27 
29  // check whether helper tool set
30  if (m_summaryHelperTool.empty()) return;
31 
32  Trk::TrackSummary tmpSummary;
33  m_summaryHelperTool->addDetailedTrackSummary(track, tmpSummary);
34  if (!tmpSummary.muonTrackSummary()) {
35  ATH_MSG_WARNING("Could not create MuonTrackSummary, please enable the creation in " << m_summaryHelperTool);
36  return;
37  }
38  muonSummary = *tmpSummary.muonTrackSummary();
39  }
40 
42  if (msgLvl(MSG::DEBUG)) ATH_MSG_DEBUG(m_printer->print(track) << std::endl << m_printer->printStations(track));
43 
44  // check if the track already has a MuonTrackSummary, if so use it
45  if (track.trackSummary() && track.trackSummary()->muonTrackSummary()) return summary(*track.trackSummary()->muonTrackSummary());
46 
47  // calculate muon summary from track
48  Trk::MuonTrackSummary muonSummary;
49  getMuonTrackSummary(muonSummary, track);
50  return summary(muonSummary);
51  }
52 
54  // check if the track summary has a MuonTrackSummary, if so use it
55  if (sum.muonTrackSummary()) return summary(*sum.muonTrackSummary());
56  return {};
57  }
58 
61 
62  std::map<int, int> sectorLayerCounts; // count hits per sector
63 
64  // loop over chambers
65  std::vector<Trk::MuonTrackSummary::ChamberHitSummary>::const_iterator chit = s.chamberHitSummary().begin();
66  std::vector<Trk::MuonTrackSummary::ChamberHitSummary>::const_iterator chit_end = s.chamberHitSummary().end();
67  for (; chit != chit_end; ++chit) {
68  const Identifier& chId = chit->chamberId();
69  bool isMdt = m_idHelperSvc->isMdt(chId);
70  bool isCsc = m_idHelperSvc->isCsc(chId);
71  bool isMM = m_idHelperSvc->isMM(chId);
72  bool issTgc = m_idHelperSvc->issTgc(chId);
73  bool isEIPrec = isCsc || isMM || issTgc;
74 
75  // only account for sectors if chamber has eta hits
76  if ((isMdt && chit->nhits() > 0) || (isEIPrec && chit->netaHits() > 0)) {
77  int sector = m_idHelperSvc->sector(chId);
78  if (isMdt)
79  sectorLayerCounts[sector] += chit->nhits();
80  else
81  sectorLayerCounts[sector] += chit->netaHits();
82  sum.sectors.insert(sector);
83  }
84 
85  // only account for phi layers if not an MDT and has phi hits
86  if (!isMdt && chit->nphiHits() > 0) {
88  sum.phiLayers.insert(index);
89  }
90 
91  MuonStationIndex::StIndex index = m_idHelperSvc->stationIndex(chId);
92  HitSummary& hitSummary = sum.stationLayers[index];
93  hitSummary.isEndcap = m_idHelperSvc->isEndcap(chId);
94  hitSummary.isSmall = m_idHelperSvc->isSmallChamber(chId);
95  if (isMdt) {
96  hitSummary.nprecisionHits += chit->nhits();
97  hitSummary.nprecisionHoles += chit->nholes();
98  hitSummary.nprecisionOutliers += chit->noutliers();
99  hitSummary.nprecisionCloseHits += chit->ncloseHits();
100  hitSummary.nprecisionGoodHits += chit->ngoodHits();
101  hitSummary.noutBoundsHits += chit->noutBoundsHits();
102  } else {
103  if (isEIPrec) {
104  hitSummary.nprecisionHits += chit->netaHits();
105  hitSummary.nprecisionGoodHits += chit->netaHits();
106  hitSummary.nprecisionHoles += chit->etaProjection().nholes;
107  hitSummary.nprecisionOutliers += chit->etaProjection().noutliers;
108  hitSummary.nprecisionCloseHits += chit->etaProjection().ncloseHits;
109  } else {
110  if (chit->netaHits() > 0) ++hitSummary.netaTriggerLayers;
111  }
112  if (chit->nphiHits() > 0) ++hitSummary.nphiLayers;
113  if (chit->nphiHits() > 0 && chit->netaHits() > 0) ++hitSummary.netaPhiLayers;
114 
115  if (!isEIPrec && chit->etaProjection().nholes > 0 && chit->etaProjection().nhits == 0) ++hitSummary.netaTriggerHoleLayers;
116  if (chit->phiProjection().nholes > 0 && chit->phiProjection().nhits == 0) ++hitSummary.nphiHoleLayers;
117  }
118  }
119 
120  int maxHits = -1;
121  int mainSec = -1;
122  std::map<int, int>::iterator secIt = sectorLayerCounts.begin();
123  std::map<int, int>::iterator secIt_end = sectorLayerCounts.end();
124  for (; secIt != secIt_end; ++secIt) {
125  if (secIt->second > maxHits) {
126  maxHits = secIt->second;
127  mainSec = secIt->first;
128  }
129  }
130  sum.mainSector = mainSec;
131 
133 
134  if (msgLvl(MSG::DEBUG)) ATH_MSG_DEBUG(sum.dump());
135 
136  return sum;
137  }
138 
140  sum.nprecisionLayers = 0;
141  sum.nprecisionGoodLayers = 0;
142  sum.nprecisionHoleLayers = 0;
143  sum.nphiLayers = 0;
144  sum.ntrigEtaLayers = 0;
145  sum.nphiHoleLayers = 0;
146  sum.ntrigEtaHoleLayers = 0;
147 
148  std::map<MuonStationIndex::StIndex, Muon::IMuonHitSummaryTool::HitSummary>::const_iterator hsit = sum.stationLayers.begin();
149  std::map<MuonStationIndex::StIndex, Muon::IMuonHitSummaryTool::HitSummary>::const_iterator hsit_end = sum.stationLayers.end();
150  for (; hsit != hsit_end; ++hsit) {
151  const Muon::IMuonHitSummaryTool::HitSummary& hitSummary = hsit->second;
152  sum.ntrigEtaLayers += hitSummary.netaTriggerLayers;
153  sum.nphiHoleLayers += hitSummary.nphiHoleLayers;
154  sum.ntrigEtaHoleLayers += hitSummary.netaTriggerHoleLayers;
155  if (hitSummary.nprecisionHits > 2) {
156  ++sum.nprecisionLayers;
157  if (hitSummary.nprecisionGoodHits > 2) {
158  ++sum.nprecisionGoodLayers;
159  sum.isEndcap = hitSummary.isEndcap;
160  sum.isSmall = hitSummary.isSmall;
161  }
162  } else if (hitSummary.nprecisionHoles > 2)
163  ++sum.nprecisionHoleLayers;
164  }
165  sum.nphiLayers = sum.phiLayers.size();
166  }
167 
169  return summary(segment.containedMeasurements());
170  }
171 
172  IMuonHitSummaryTool::CompactSummary MuonHitSummaryTool::summary(const std::vector<const Muon::MuonSegment*>& segments) const {
173  std::vector<const Trk::MeasurementBase*> rioVec;
174  std::vector<const Muon::MuonSegment*>::const_iterator sit = segments.begin();
175  std::vector<const Muon::MuonSegment*>::const_iterator sit_end = segments.end();
176  for (; sit != sit_end; ++sit)
177  rioVec.insert(rioVec.end(), (*sit)->containedMeasurements().begin(), (*sit)->containedMeasurements().end());
178  return summary(rioVec);
179  }
180 
181  IMuonHitSummaryTool::CompactSummary MuonHitSummaryTool::summary(const std::vector<const Trk::MeasurementBase*>& rioVec) const {
183  std::map<int, int> sectorLayerCounts; // count hits per sector
184 
185  std::map<MuonStationIndex::StIndex, std::map<MuonStationIndex::PhiIndex, std::pair<int, int> > > countLayersPerStation;
186 
187  std::vector<const Trk::MeasurementBase*>::const_iterator it = rioVec.begin();
188  std::vector<const Trk::MeasurementBase*>::const_iterator it_end = rioVec.end();
189  for (; it != it_end; ++it) {
190  Identifier id = m_edmHelperSvc->getIdentifier(**it);
191  if (!id.is_valid() || !m_idHelperSvc->isMuon(id)) continue;
192 
193  bool isMdt = m_idHelperSvc->isMdt(id);
194  bool isCsc = m_idHelperSvc->isCsc(id);
195  bool measuresPhi = m_idHelperSvc->measuresPhi(id);
196 
197  // only account for sectors if chamber has eta hits
198  if (isMdt || (isCsc && !measuresPhi)) {
199  int sector = m_idHelperSvc->sector(id);
200  if (isMdt) ++sectorLayerCounts[sector];
201  if (isCsc) ++sectorLayerCounts[sector];
202  sum.sectors.insert(sector);
203  }
204 
205  // only account for phi layers if not an MDT and has phi hits
206  if (!isMdt && measuresPhi) {
208  sum.phiLayers.insert(index);
209  }
210 
211  MuonStationIndex::StIndex index = m_idHelperSvc->stationIndex(id);
212  HitSummary& hitSummary = sum.stationLayers[index];
213  if (isMdt || (isCsc && !measuresPhi)) ++hitSummary.nprecisionHits;
214 
215  if (!isMdt) {
216  MuonStationIndex::PhiIndex pindex = m_idHelperSvc->phiIndex(id);
217  std::pair<int, int> etaPhiCount = countLayersPerStation[index][pindex];
218  if (measuresPhi)
219  ++etaPhiCount.first;
220  else
221  ++etaPhiCount.second;
222  }
223  }
224 
225  int maxHits = -1;
226  int mainSec = -1;
227  std::map<int, int>::iterator secIt = sectorLayerCounts.begin();
228  std::map<int, int>::iterator secIt_end = sectorLayerCounts.end();
229  for (; secIt != secIt_end; ++secIt) {
230  if (secIt->second > maxHits) {
231  maxHits = secIt->second;
232  mainSec = secIt->first;
233  }
234  }
235  sum.mainSector = mainSec;
236 
237  std::map<MuonStationIndex::StIndex, std::map<MuonStationIndex::PhiIndex, std::pair<int, int> > >::iterator sit =
238  countLayersPerStation.begin();
239  std::map<MuonStationIndex::StIndex, std::map<MuonStationIndex::PhiIndex, std::pair<int, int> > >::iterator sit_end =
240  countLayersPerStation.end();
241  for (; sit != sit_end; ++sit) {
242  HitSummary& hitSummary = sum.stationLayers[sit->first];
243 
244  std::map<MuonStationIndex::PhiIndex, std::pair<int, int> >::iterator pit = sit->second.begin();
245  std::map<MuonStationIndex::PhiIndex, std::pair<int, int> >::iterator pit_end = sit->second.end();
246  for (; pit != pit_end; ++pit) {
247  if (pit->second.first != 0) ++hitSummary.nphiLayers;
248  if (pit->second.second != 0 && pit->first != MuonStationIndex::CSC) ++hitSummary.netaTriggerLayers;
249  if (pit->second.second != 0 && pit->second.first != 0) ++hitSummary.netaPhiLayers;
250  }
251  }
253  return sum;
254  }
255 
256 } // namespace Muon
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Muon::MuonHitSummaryTool::getMuonTrackSummary
void getMuonTrackSummary(Trk::MuonTrackSummary &muonSummary, const Trk::Track &track) const
helper function to calculate MuonTrackSummary from track
Definition: MuonHitSummaryTool.cxx:28
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Muon::MuonHitSummaryTool::summary
virtual CompactSummary summary(const Trk::Track &track) const
Calculate compact summary.
Definition: MuonHitSummaryTool.cxx:41
Muon::IMuonHitSummaryTool::HitSummary::nprecisionOutliers
unsigned int nprecisionOutliers
number of phi layer holes
Definition: IMuonHitSummaryTool.h:59
MuonTrackSummary.h
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
index
Definition: index.py:1
Muon::IMuonHitSummaryTool::HitSummary::nprecisionCloseHits
unsigned int nprecisionCloseHits
number of outliers hits
Definition: IMuonHitSummaryTool.h:60
Muon::MuonHitSummaryTool::m_edmHelperSvc
ServiceHandle< IMuonEDMHelperSvc > m_edmHelperSvc
Definition: MuonHitSummaryTool.h:77
Muon::IMuonHitSummaryTool::HitSummary::nphiLayers
unsigned int nphiLayers
number of eta trigger layers
Definition: IMuonHitSummaryTool.h:50
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Muon::IMuonHitSummaryTool::CompactSummary
Definition: IMuonHitSummaryTool.h:70
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:45
Muon::IMuonHitSummaryTool::HitSummary::noutBoundsHits
unsigned int noutBoundsHits
number of close hits hits
Definition: IMuonHitSummaryTool.h:61
Muon::MuonStationIndex::PhiIndex
PhiIndex
enum to classify the different phi layers in the muon spectrometer
Definition: MuonStationIndex.h:31
Track.h
Muon::MuonHitSummaryTool::initialize
StatusCode initialize()
Definition: MuonHitSummaryTool.cxx:20
Muon::IMuonHitSummaryTool::HitSummary::nphiHoleLayers
unsigned int nphiHoleLayers
number of eta trigger layer holes
Definition: IMuonHitSummaryTool.h:56
Muon::MuonHitSummaryTool::m_summaryHelperTool
ToolHandle< Trk::ITrackSummaryHelperTool > m_summaryHelperTool
Definition: MuonHitSummaryTool.h:89
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
Muon::IMuonHitSummaryTool::HitSummary::netaPhiLayers
unsigned int netaPhiLayers
number of phi layers
Definition: IMuonHitSummaryTool.h:51
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Muon::IMuonHitSummaryTool::HitSummary::netaTriggerHoleLayers
unsigned int netaTriggerHoleLayers
number of precision holes
Definition: IMuonHitSummaryTool.h:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::MuonTrackSummary
Detailed track summary for the muon system Give access to hit counts per chamber.
Definition: MuonTrackSummary.h:26
TrackSummary.h
Muon::MuonHitSummaryTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonHitSummaryTool.h:72
Muon::IMuonHitSummaryTool::HitSummary::isEndcap
bool isEndcap
number of out of bounds hits
Definition: IMuonHitSummaryTool.h:64
Trk::TrackSummary
A summary of the information contained by a track.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:287
Muon::IMuonHitSummaryTool::HitSummary
Definition: IMuonHitSummaryTool.h:30
Muon::MuonHitSummaryTool::m_printer
PublicToolHandle< MuonEDMPrinterTool > m_printer
Definition: MuonHitSummaryTool.h:84
Muon::IMuonHitSummaryTool::HitSummary::isSmall
bool isSmall
Definition: IMuonHitSummaryTool.h:65
Muon::IMuonHitSummaryTool::HitSummary::nprecisionHits
unsigned int nprecisionHits
hit counts
Definition: IMuonHitSummaryTool.h:47
DeMoScan.index
string index
Definition: DeMoScan.py:364
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
Muon::MuonStationIndex::CSC
@ CSC
Definition: MuonStationIndex.h:33
Muon::IMuonHitSummaryTool::HitSummary::netaTriggerLayers
unsigned int netaTriggerLayers
number of precision hits that are not deweighted
Definition: IMuonHitSummaryTool.h:49
MuonSegment.h
Muon::IMuonHitSummaryTool::HitSummary::nprecisionHoles
unsigned int nprecisionHoles
number of paired eta/phi trigger layers
Definition: IMuonHitSummaryTool.h:54
Muon::MuonStationIndex::StIndex
StIndex
enum to classify the different station layers in the muon spectrometer
Definition: MuonStationIndex.h:23
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Muon::MuonSegment
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:45
AthAlgTool
Definition: AthAlgTool.h:26
Trk::TrackSummary::muonTrackSummary
const MuonTrackSummary * muonTrackSummary() const
returns a pointer to the MuonTrackSummary if available
Muon::MuonHitSummaryTool::MuonHitSummaryTool
MuonHitSummaryTool(const std::string &, const std::string &, const IInterface *)
Definition: MuonHitSummaryTool.cxx:16
MuonHitSummaryTool.h
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
Muon::IMuonHitSummaryTool::HitSummary::nprecisionGoodHits
unsigned int nprecisionGoodHits
number of precision hits
Definition: IMuonHitSummaryTool.h:48
Muon::MuonHitSummaryTool::calculateSummaryCounts
static void calculateSummaryCounts(CompactSummary &sum)
Definition: MuonHitSummaryTool.cxx:139
Identifier
Definition: IdentifierFieldParser.cxx:14