ATLAS Offline Software
MuonSegmentHitSummaryTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <map>
8 
13 
14 namespace Muon {
15 
16 MuonSegmentHitSummaryTool::MuonSegmentHitSummaryTool(const std::string& ty, const std::string& na, const IInterface* pa)
17  : AthAlgTool(ty, na, pa)
18 {
19  declareInterface<IMuonSegmentHitSummaryTool>(this);
20  declareProperty("PositionAlongTubeCut", m_positionAlongTubeCut = -200.,
21  "Cut on distance from tube end used for holes, negative value means in the tube");
22  declareProperty("MinimumADCValue", m_lowerADCBound = 70.);
23 }
24 
27 {
29  ATH_CHECK(m_edmHelperSvc.retrieve());
30  ATH_CHECK(m_printer.retrieve());
31  ATH_CHECK(m_idHelperSvc.retrieve());
32  return StatusCode::SUCCESS;
33 }
34 
37 {
38 
39  HitCounts hitCounts;
40 
42  const MuonGM::MuonDetectorManager* MuonDetMgr{*DetectorManagerHandle};
43  if (!MuonDetMgr) {
44  ATH_MSG_ERROR("Null pointer to the read MuonDetectorManager conditions object");
45  return hitCounts;
46  }
47 
48  // calculate shortest channel
49  double shortestTube {FLT_MAX};
50  const MdtDriftCircleOnTrack* mdtShortest = nullptr;
51  bool transformIsSet = false;
52  Amg::Transform3D gToAMDB;
53  Amg::Vector3D lpos(0., 0., 0.);
54  Amg::Vector3D ldir{0.,0.,0.};
55  double dxdy = 1.;
56 
57  Identifier chid = m_edmHelperSvc->chamberId(seg);
58  MuonStationIndex::StIndex stIndex = m_idHelperSvc->stationIndex(chid);
59 
61  if ((!m_idHelperSvc->isCsc(chid) && stIndex == MuonStationIndex::EI) || stIndex == MuonStationIndex::BO)
62  hitCounts.nexpectedTrigHitLayers = 1;
63  else if (stIndex == MuonStationIndex::BM)
64  hitCounts.nexpectedTrigHitLayers = 2;
65  else if (stIndex == MuonStationIndex::EM)
66  hitCounts.nexpectedTrigHitLayers = 3;
67 
68  // loop over hits
69  for (const Trk::MeasurementBase* meas : seg.containedMeasurements()) {
70 
71  // get id and check that it is a muon hit id
72  Identifier id = m_edmHelperSvc->getIdentifier(*meas);
73  if (!id.is_valid() || !m_idHelperSvc->isMuon(id)) continue;
74 
75  // check if MDT is so increase ml counter
76  if (m_idHelperSvc->isMdt(id)) {
77  // get layer index
78  int ml = m_idHelperSvc->mdtIdHelper().multilayer(id);
79  int lay = m_idHelperSvc->mdtIdHelper().tubeLayer(id);
80  int tube = m_idHelperSvc->mdtIdHelper().tube(id);
81  int layIndex = 4 * (ml - 1) + (lay - 1); // start at 0 rather than at 1
82  MdtLayerIntersect& layIntersect = hitCounts.mdtHitHolePerLayerCounts[layIndex];
83  ++layIntersect.nhits;
84 
85  const MdtDriftCircleOnTrack* mdt = dynamic_cast<const MdtDriftCircleOnTrack*>(meas);
86  if (mdt) {
87  const MuonGM::MdtReadoutElement* detEl =
88  mdt->prepRawData() ? mdt->prepRawData()->detectorElement() : MuonDetMgr->getMdtReadoutElement(id);
89  if (!detEl) {
90  ATH_MSG_WARNING(" could not get MdtReadoutElement for tube " << m_idHelperSvc->toString(id));
91  continue;
92  }
93 
94  double tubeLen = detEl->getActiveTubeLength(lay, tube);
95  layIntersect.tubeLength = tubeLen;
96  if (!transformIsSet) {
97  gToAMDB = detEl->GlobalToAmdbLRSTransform();
98  lpos = gToAMDB * seg.globalPosition();
99  ldir = (gToAMDB * seg.globalDirection()).unit();
100  dxdy = std::abs(ldir.y()) > 0.001 ? ldir.x() / ldir.y() : 1000.;
101  transformIsSet = true;
102  }
103  if (!mdtShortest || tubeLen < shortestTube) {
104  mdtShortest = mdt;
105  shortestTube = tubeLen;
106  }
107  }
108  const bool first_layer = (m_idHelperSvc->mdtIdHelper().multilayer(id) == 1);
109  hitCounts.nmdtHitsMl1 += first_layer;
110  hitCounts.nmdtHitsMl2 += !first_layer;
111  if (mdt && mdt->prepRawData()) {
112  int adc = mdt->prepRawData()->adc();
113  if (adc > m_lowerADCBound) hitCounts.nmdtHighADCHits+=(adc > m_lowerADCBound);
114  hitCounts.adcMax = std::max(adc, hitCounts.adcMax);
115  }
116 
117  }
119  else if (m_idHelperSvc->isTrigger(id)) {
120  // get gasgap ID (same for eta/phi projection)
121  Identifier gasGapId = m_idHelperSvc->gasGapId(id);
122  const bool measuresPhi = m_idHelperSvc->measuresPhi(id);
123  hitCounts.hitCountsPerLayer[gasGapId].nphiHits+= measuresPhi;
124  hitCounts.hitCountsPerLayer[gasGapId].netaHits+= !measuresPhi;
125  } else if (m_idHelperSvc->isCsc(id)) {
126  const bool measuresPhi = m_idHelperSvc->measuresPhi(id);
127  hitCounts.ncscHits.nphiHits+= measuresPhi;
128  hitCounts.ncscHits.netaHits+= !measuresPhi;
129  } else if (m_idHelperSvc->issTgc(id)){
130  const bool measuresPhi = m_idHelperSvc->measuresPhi(id);
131  hitCounts.nstgcHits.nphiHits+= measuresPhi;
132  hitCounts.nstgcHits.netaHits+= !measuresPhi;
133  } else if (m_idHelperSvc->isMM(id)){
134  const bool isStereo = m_idHelperSvc->mmIdHelper().isStereo(id);
135  hitCounts.nmmEtaHits += !isStereo;
136  hitCounts.nmmStereoHits+= isStereo;
137  }
138  }
139 
140  const MuonSegmentQuality* quality = dynamic_cast<const MuonSegmentQuality*>(seg.fitQuality());
141  if (quality) {
142  for (const Identifier& id : quality->channelsWithoutHit()) {
144  int ml = m_idHelperSvc->mdtIdHelper().multilayer(id);
145  int lay = m_idHelperSvc->mdtIdHelper().tubeLayer(id);
146  int tube = m_idHelperSvc->mdtIdHelper().tube(id);
147  int layIndex = 4 * (ml - 1) + (lay - 1); // subtract 1 as fields start with 1 instead of 0
148  MdtLayerIntersect& layIntersect = hitCounts.mdtHitHolePerLayerCounts[layIndex];
149  ++layIntersect.nholes;
150 
151  if (transformIsSet) {
152  const MuonGM::MdtReadoutElement* detEl = MuonDetMgr->getMdtReadoutElement(id);
153  if (!detEl) {
154  ATH_MSG_WARNING(" could not get MdtReadoutElement for tube " << m_idHelperSvc->toString(id));
155  continue;
156  }
157  double tubeLen = detEl->getActiveTubeLength(lay, tube);
158  double ytube = (gToAMDB * detEl->center(id)).y();
159  double xint = dxdy * (ytube - lpos.y()) + lpos.x();
160  layIntersect.distFromTubeEnd = xint;
161  layIntersect.tubeLength = tubeLen;
162  }
163  }
164  }
165 
166 
167  // now loop over map and get the counts for the trigger hits
168  for (std::pair<const Identifier, EtaPhiHitCount>& it : hitCounts.hitCountsPerLayer) {
169  EtaPhiHitCount& counts = it.second;
170 
171  // increase eta/phi hit counts
172  if (counts.nphiHits != 0) ++hitCounts.nphiTrigHitLayers;
173  if (counts.netaHits != 0) {
174  ++hitCounts.netaTrigHitLayers;
175 
176  // if both eta/phi projection have entries increase paired counters
177  if (counts.nphiHits != 0) ++hitCounts.npairedTrigHitLayers;
178  }
179  }
180 
181  int currentEnclosedHoles = 0;
182  bool firstLayerWithHits = false;
183  // now loop over mdt map and get the number of enclosed holes
184  for ( auto& lit : hitCounts.mdtHitHolePerLayerCounts) {
185  hitCounts.nmdtHoles += lit.second.nholes;
186  if (lit.second.nhits == 0) {
187  ++currentEnclosedHoles;
188  // count holes within chamber bounds
189  if (std::abs(lit.second.distFromTubeEnd) - 0.5 * lit.second.tubeLength < m_positionAlongTubeCut)
190  ++hitCounts.nmdtHolesInChamber;
191  } else {
192  if (firstLayerWithHits) hitCounts.nmdtEnclosedHoles += currentEnclosedHoles;
193  currentEnclosedHoles = 0;
194  firstLayerWithHits = true;
195  }
196  }
197 
198  if (mdtShortest) {
199  double posAlongTube = (mdtShortest->associatedSurface().transform().inverse() * seg.globalPosition()).z();
200  if (0.5 * shortestTube - std::abs(posAlongTube) < 100.) hitCounts.closeToChamberEdge = true;
201  }
202 
203  if (seg.fitQuality()) {
204  // combine chi2 with missing hit information and apply cut
205  hitCounts.segmentQuality = seg.fitQuality()->chiSquared() + 5.1 * (hitCounts.nmdtHoles);
206  if (seg.fitQuality()->numberDoF() > 0) hitCounts.segmentQuality /= seg.fitQuality()->numberDoF();
207  }
208 
209 
210  return hitCounts;
211 }
212 
213 } // namespace Muon
Muon::MuonSegmentQuality
Definition: MuonSegmentQuality.h:34
Muon::MuonSegmentHitSummaryTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonSegmentHitSummaryTool.h:37
max
#define max(a, b)
Definition: cfImp.cxx:41
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Muon::MdtDriftCircleOnTrack::prepRawData
virtual const MdtPrepData * prepRawData() const override final
Returns the PrepRawData used to create this corrected measurement.
Definition: MdtDriftCircleOnTrack.h:257
MuonGM::MdtReadoutElement::center
virtual const Amg::Vector3D & center(const Identifier &) const override final
Return the center of the surface associated with this identifier In the case of silicon it returns th...
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmmStereoHits
uint8_t nmmStereoHits
Number of eta micromega hits.
Definition: IMuonSegmentHitSummaryTool.h:49
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmdtHitsMl1
uint8_t nmdtHitsMl1
Definition: IMuonSegmentHitSummaryTool.h:40
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmdtHighADCHits
uint8_t nmdtHighADCHits
Definition: IMuonSegmentHitSummaryTool.h:39
MuonGM::MuonReadoutElement::GlobalToAmdbLRSTransform
virtual Amg::Transform3D GlobalToAmdbLRSTransform() const
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonReadoutElement.cxx:153
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Muon::IMuonSegmentHitSummaryTool::HitCounts::adcMax
int adcMax
Definition: IMuonSegmentHitSummaryTool.h:57
Muon::IMuonSegmentHitSummaryTool::MdtLayerIntersect
Definition: IMuonSegmentHitSummaryTool.h:28
Muon::IMuonSegmentHitSummaryTool::EtaPhiHitCount
Definition: IMuonSegmentHitSummaryTool.h:18
Muon::IMuonSegmentHitSummaryTool::MdtLayerIntersect::tubeLength
double tubeLength
Definition: IMuonSegmentHitSummaryTool.h:33
Muon::MuonSegmentHitSummaryTool::m_printer
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
EDM printer tool.
Definition: MuonSegmentHitSummaryTool.h:43
Muon::IMuonSegmentHitSummaryTool::HitCounts::npairedTrigHitLayers
uint8_t npairedTrigHitLayers
Definition: IMuonSegmentHitSummaryTool.h:53
MdtPrepData.h
MuonSegmentQuality.h
MdtDriftCircleOnTrack.h
Muon::IMuonSegmentHitSummaryTool::HitCounts::mdtHitHolePerLayerCounts
MdtLayerIntersectMap mdtHitHolePerLayerCounts
Definition: IMuonSegmentHitSummaryTool.h:68
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:45
Muon::MdtPrepData::adc
int adc() const
Returns the ADC (typically range is 0 to 250)
Definition: MdtPrepData.h:146
Muon::IMuonSegmentHitSummaryTool::HitCounts::netaTrigHitLayers
uint8_t netaTrigHitLayers
Definition: IMuonSegmentHitSummaryTool.h:52
Muon::IMuonSegmentHitSummaryTool::HitCounts::nexpectedTrigHitLayers
uint8_t nexpectedTrigHitLayers
Definition: IMuonSegmentHitSummaryTool.h:54
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmdtHolesInChamber
uint8_t nmdtHolesInChamber
Definition: IMuonSegmentHitSummaryTool.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:51
z
#define z
Muon::MuonStationIndex::BM
@ BM
Definition: MuonStationIndex.h:25
Muon::IMuonSegmentHitSummaryTool::HitCounts::closeToChamberEdge
bool closeToChamberEdge
Definition: IMuonSegmentHitSummaryTool.h:55
Muon::MuonSegmentHitSummaryTool::m_DetectorManagerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
Definition: MuonSegmentHitSummaryTool.h:49
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Muon::MuonStationIndex::EI
@ EI
Definition: MuonStationIndex.h:26
MuonGM::MdtReadoutElement::getActiveTubeLength
double getActiveTubeLength(const int tubeLayer, const int tube) const
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Trk::Segment::containedMeasurements
const std::vector< const Trk::MeasurementBase * > & containedMeasurements() const
returns the vector of Trk::MeasurementBase objects
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:166
Muon::IMuonSegmentHitSummaryTool::MdtLayerIntersect::nholes
uint8_t nholes
Definition: IMuonSegmentHitSummaryTool.h:31
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::IMuonSegmentHitSummaryTool::MdtLayerIntersect::nhits
uint8_t nhits
Definition: IMuonSegmentHitSummaryTool.h:30
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmdtEnclosedHoles
uint8_t nmdtEnclosedHoles
Definition: IMuonSegmentHitSummaryTool.h:44
Muon::MdtDriftCircleOnTrack
This class represents the corrected MDT measurements, where the corrections include the effects of wi...
Definition: MdtDriftCircleOnTrack.h:37
Muon::IMuonSegmentHitSummaryTool::HitCounts::nphiTrigHitLayers
uint8_t nphiTrigHitLayers
Number of eta stereo hits.
Definition: IMuonSegmentHitSummaryTool.h:51
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Muon::IMuonSegmentHitSummaryTool::HitCounts::nstgcHits
EtaPhiHitCount nstgcHits
Definition: IMuonSegmentHitSummaryTool.h:46
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Muon::IMuonSegmentHitSummaryTool::MdtLayerIntersect::distFromTubeEnd
double distFromTubeEnd
Definition: IMuonSegmentHitSummaryTool.h:32
Muon::MuonSegmentHitSummaryTool::m_lowerADCBound
double m_lowerADCBound
lower bound for good MDT hits
Definition: MuonSegmentHitSummaryTool.h:53
Muon::IMuonSegmentHitSummaryTool::HitCounts
Definition: IMuonSegmentHitSummaryTool.h:37
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmdtHoles
uint8_t nmdtHoles
Definition: IMuonSegmentHitSummaryTool.h:42
Muon::IMuonSegmentHitSummaryTool::HitCounts::ncscHits
EtaPhiHitCount ncscHits
Definition: IMuonSegmentHitSummaryTool.h:45
MuonSegmentHitSummaryTool.h
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmmEtaHits
uint8_t nmmEtaHits
Definition: IMuonSegmentHitSummaryTool.h:48
y
#define y
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
Muon::MuonStationIndex::BO
@ BO
Definition: MuonStationIndex.h:25
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:50
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Muon::MdtDriftCircleOnTrack::associatedSurface
virtual const Trk::StraightLineSurface & associatedSurface() const override final
Returns the surface on which this measurement was taken.
Definition: MdtDriftCircleOnTrack.h:271
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:21
Muon::MuonSegmentHitSummaryTool::m_positionAlongTubeCut
double m_positionAlongTubeCut
cut on the distance from the tube wall use for hole count
Definition: MuonSegmentHitSummaryTool.h:52
Muon::IMuonSegmentHitSummaryTool::HitCounts::hitCountsPerLayer
HitCountsPerLayer hitCountsPerLayer
Definition: IMuonSegmentHitSummaryTool.h:71
Muon::MuonSegmentHitSummaryTool::MuonSegmentHitSummaryTool
MuonSegmentHitSummaryTool(const std::string &, const std::string &, const IInterface *)
Definition: MuonSegmentHitSummaryTool.cxx:16
Trk::FitQuality::chiSquared
double chiSquared() const
returns the of the overall track fit
Definition: FitQuality.h:56
MuonSegment.h
Muon::MuonStationIndex::StIndex
StIndex
enum to classify the different station layers in the muon spectrometer
Definition: MuonStationIndex.h:23
Trk::FitQuality::numberDoF
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition: FitQuality.h:60
Muon::MuonSegment::globalPosition
virtual const Amg::Vector3D & globalPosition() const override final
global position
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:157
Muon::MuonSegment
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:45
AthAlgTool
Definition: AthAlgTool.h:26
Trk::Segment::fitQuality
const FitQuality * fitQuality() const
return the FitQuality object, returns NULL if no FitQuality is defined
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:160
Muon::MuonSegmentHitSummaryTool::initialize
StatusCode initialize()
Definition: MuonSegmentHitSummaryTool.cxx:26
Muon::IMuonSegmentHitSummaryTool::HitCounts::segmentQuality
double segmentQuality
Definition: IMuonSegmentHitSummaryTool.h:56
Muon::MuonSegmentHitSummaryTool::getHitCounts
virtual HitCounts getHitCounts(const MuonSegment &seg) const
calculate segment hit counts
Definition: MuonSegmentHitSummaryTool.cxx:36
Muon::MuonSegmentHitSummaryTool::m_edmHelperSvc
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
EDM Helper tool.
Definition: MuonSegmentHitSummaryTool.h:39
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Muon::MdtPrepData::detectorElement
virtual const MuonGM::MdtReadoutElement * detectorElement() const override
Returns the detector element corresponding to this PRD.
Definition: MdtPrepData.h:141
Muon::IMuonSegmentHitSummaryTool::EtaPhiHitCount::netaHits
uint8_t netaHits
Definition: IMuonSegmentHitSummaryTool.h:21
calibdata.tube
tube
Definition: calibdata.py:31
Muon::MuonStationIndex::EM
@ EM
Definition: MuonStationIndex.h:26
Muon::MuonSegment::globalDirection
const Amg::Vector3D & globalDirection() const
global direction
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:163
Muon::IMuonSegmentHitSummaryTool::EtaPhiHitCount::nphiHits
uint8_t nphiHits
Definition: IMuonSegmentHitSummaryTool.h:20
Muon::MuonSegmentQuality::channelsWithoutHit
const std::vector< Identifier > & channelsWithoutHit() const
vector of identifiers of channels crossed by the segment but without hit
Definition: MuonSegmentQuality.h:74
Identifier
Definition: IdentifierFieldParser.cxx:14
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmdtHitsMl2
uint8_t nmdtHitsMl2
Definition: IMuonSegmentHitSummaryTool.h:41