ATLAS Offline Software
MuonSegmentConverterTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
10 
11 namespace {
12  const SG::AuxElement::Accessor<float> acc_clusterTime("clusterTime");
13  const SG::AuxElement::Accessor<float> acc_clusterTimeError("clusterTimeError");
14  const SG::AuxElement::Accessor<bool> acc_clusterTimeValid("clusterTimeValid");
15 
16  const SG::AuxElement::Accessor<uint8_t> acc_mmStereoHits("N_MicromegaStereoHits");
17  const SG::AuxElement::Accessor<uint8_t> acc_mmEtaHits("N_MicromegaEtaHits");
18 
19  const SG::AuxElement::Accessor<uint8_t> acc_stgcEtaHits("N_StgcEtaHits");
20  const SG::AuxElement::Accessor<uint8_t> acc_stgcPhiHits("N_StgcPhiHits");
21 }
22 
23 namespace Muon {
24 
25 MuonSegmentConverterTool::MuonSegmentConverterTool(const std::string& t, const std::string& n, const IInterface* p)
26  : base_class(t, n, p) {}
27 
30 {
31  ATH_CHECK(m_hitSummaryTool.retrieve());
32  ATH_CHECK(m_idHelperSvc.retrieve());
33  ATH_CHECK(m_edmHelper.retrieve());
34  ATH_CHECK(m_hitTimingTool.retrieve());
35 
36  return StatusCode::SUCCESS;
37 }
38 
41  xAOD::MuonSegmentContainer* container) const
42 {
43  // sanity checks
44  if (!segLink.isValid() || !*segLink) {
45  ATH_MSG_WARNING(" Got invalid element link");
46  return nullptr;
47  }
48  const MuonSegment* seg = dynamic_cast<const MuonSegment*>(*segLink);
49  if (!seg) {
50  ATH_MSG_WARNING(" Trk::Segment is not a MuonSegment ");
51  return nullptr;
52  }
53 
54  // create xAOD::Muon and set link
55  xAOD::MuonSegment* xaodSeg = convert(*seg, container);
56  if (xaodSeg) xaodSeg->setMuonSegment(segLink);
57  return xaodSeg;
58 }
59 
60 
61 void
63 {
64 
65  // loop over hits and extract clusters
66  std::vector<const MuonClusterOnTrack*> clusters;
67  for (const Trk::MeasurementBase* meas : seg.containedMeasurements()) {
68 
69  // get Identifier and remove MDT hits
70  Identifier id = m_edmHelper->getIdentifier(*meas);
71  if (!id.is_valid() || !m_idHelperSvc->isTrigger(id)) continue;
72 
73  // cast to MuonClusterOnTrack
74  const MuonClusterOnTrack* clus = dynamic_cast<const MuonClusterOnTrack*>(meas);
75  if (clus)
76  clusters.push_back(clus);
77  else {
78  const CompetingMuonClustersOnTrack* crot = dynamic_cast<const CompetingMuonClustersOnTrack*>(meas);
79  if (!crot || crot->containedROTs().empty()) continue;
80  clusters.insert(clusters.end(), crot->containedROTs().begin(), crot->containedROTs().end());
81  }
82  }
83 
84  // call timing tool and dress xaodSeg
86  if (std::abs(result.time) > std::numeric_limits<float>::max()
87  || std::abs(result.error) > std::numeric_limits<float>::max())
88  {
89  // xAOD stores this as a float. To avoid FPE, we need to check here...
90  if (result.valid)
91  ATH_MSG_WARNING("Unphysical time returned by tool - ignoring. result.valid = "
92  + std::to_string(result.valid));
93  acc_clusterTime(xaodSeg) = std::numeric_limits<float>::max();
94  acc_clusterTimeError(xaodSeg) = std::numeric_limits<float>::max();
95  acc_clusterTimeValid(xaodSeg) = 0;
96  } else {
97  acc_clusterTime(xaodSeg) = result.time;
98  acc_clusterTimeError(xaodSeg) = result.error;
99  acc_clusterTimeValid(xaodSeg) = result.valid;
100  }
101 }
102 
103 
106 {
107 
108  // create xAOD::MuonSegment
109  xAOD::MuonSegment* xaodSeg = new xAOD::MuonSegment();
110  if (container)
111  container->push_back(xaodSeg);
112  else
113  xaodSeg->makePrivateStore();
114 
115  // set position and direction
116  xaodSeg->setPosition(seg.globalPosition().x(), seg.globalPosition().y(), seg.globalPosition().z());
117  xaodSeg->setDirection(seg.globalDirection().x(), seg.globalDirection().y(), seg.globalDirection().z());
118 
119  // fit chi2
120  const Trk::FitQuality* fq = seg.fitQuality();
121  if (fq) xaodSeg->setFitQuality(fq->chiSquared(), fq->numberDoF());
122 
123  // identifier
124  Identifier id = m_edmHelper->chamberId(seg);
125  int eta = m_idHelperSvc->stationEta(id);
126  int sector = m_idHelperSvc->sector(id);
127  MuonStationIndex::ChIndex chIndex = m_idHelperSvc->chamberIndex(id);
128  MuonStationIndex::TechnologyIndex technology = m_idHelperSvc->technologyIndex(id);
129  xaodSeg->setIdentifier(sector, chIndex, eta, technology);
130 
131  // hit counts
132  IMuonSegmentHitSummaryTool::HitCounts hitCounts = m_hitSummaryTool->getHitCounts(seg);
133  xaodSeg->setNHits(hitCounts.nmdtHits()+ hitCounts.nmmHits() + hitCounts.nstgcHits.netaHits + hitCounts.ncscHits.netaHits,
134  hitCounts.nphiTrigHitLayers + hitCounts.nstgcHits.nphiHits, hitCounts.netaTrigHitLayers);
135 
136  // MDT + cluster timing
137  if (seg.hasFittedT0()) xaodSeg->setT0Error(seg.time(), seg.errorTime());
138  if (!m_hitTimingTool.empty()) addClusterTiming(seg, *xaodSeg);
140  if (m_idHelperSvc->hasMM()) {
141  acc_mmStereoHits(*xaodSeg) = hitCounts.nmmStereoHits;
142  acc_mmEtaHits(*xaodSeg) = hitCounts.nmmEtaHits;
143  }
144  if (m_idHelperSvc->hasSTGC()) {
145  acc_stgcEtaHits(*xaodSeg) = hitCounts.nstgcHits.netaHits;
146  acc_stgcPhiHits(*xaodSeg) = hitCounts.nstgcHits.nphiHits;
147  }
148  return xaodSeg;
149 }
150 
151 
152 } // namespace Muon
Muon::MuonSegmentConverterTool::addClusterTiming
void addClusterTiming(const MuonSegment &seg, xAOD::MuonSegment &xaodSeg) const
helper function to dress output segment with cluster hit timing information
Definition: MuonSegmentConverterTool.cxx:62
Trk::SpaceTimePointBase::errorTime
float errorTime() const
access to the error on the measured time
Definition: SpaceTimePointBase.h:50
MuonSegmentConverterTool.h
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::MuonSegment_v1::setPosition
void setPosition(float x, float y, float z)
Sets the global position.
Definition: MuonSegment_v1.cxx:26
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmmStereoHits
uint8_t nmmStereoHits
Number of eta micromega hits.
Definition: IMuonSegmentHitSummaryTool.h:49
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
CompetingMuonClustersOnTrack.h
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Muon::CompetingMuonClustersOnTrack
Definition: CompetingMuonClustersOnTrack.h:54
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
Muon::MuonSegmentConverterTool::m_edmHelper
ServiceHandle< IMuonEDMHelperSvc > m_edmHelper
Definition: MuonSegmentConverterTool.h:64
xAOD::MuonSegment
MuonSegment_v1 MuonSegment
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonSegment.h:13
Muon::MuonSegment::hasFittedT0
bool hasFittedT0() const
returns whether the segment has a fitted t0
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:212
Muon::MuonSegmentConverterTool::MuonSegmentConverterTool
MuonSegmentConverterTool(const std::string &, const std::string &, const IInterface *)
default AlgTool constructor
Definition: MuonSegmentConverterTool.cxx:25
Muon::IMuonSegmentHitSummaryTool::HitCounts::netaTrigHitLayers
uint8_t netaTrigHitLayers
Definition: IMuonSegmentHitSummaryTool.h:52
xAOD::MuonSegment_v1::setT0Error
void setT0Error(float t0, float t0Error)
Sets the time error.
Definition: MuonSegment_v1.cxx:51
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmdtHits
uint8_t nmdtHits() const
Returns the number of hits in both MDT layers.
Definition: IMuonSegmentHitSummaryTool.h:60
xAOD::MuonSegment_v1::setNHits
void setNHits(int nPrecisionHits, int nPhiLayers, int nTrigEtaLayers)
Set the number of hits/layers.
Definition: MuonSegment_v1.cxx:88
Muon::MuonSegmentConverterTool::initialize
StatusCode initialize()
initialize method, method taken from bass-class AlgTool
Definition: MuonSegmentConverterTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmmHits
uint8_t nmmHits() const
Returns the number of hits in the micromegas.
Definition: IMuonSegmentHitSummaryTool.h:62
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Muon::MuonSegmentConverterTool::m_hitSummaryTool
ToolHandle< IMuonSegmentHitSummaryTool > m_hitSummaryTool
Definition: MuonSegmentConverterTool.h:49
Muon::MuonSegmentConverterTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonSegmentConverterTool.h:59
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::FitQuality
Class to represent and store fit qualities from track reconstruction in terms of and number of degre...
Definition: FitQuality.h:97
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Muon::IMuonHitTimingTool::TimingResult
simple struct holding the result of the tool
Definition: IMuonHitTimingTool.h:38
Trk::MeasurementBase
Definition: MeasurementBase.h:58
xAOD::MuonSegment_v1::setMuonSegment
void setMuonSegment(const ElementLink< ::Trk::SegmentCollection > &segment)
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Muon::IMuonSegmentHitSummaryTool::HitCounts::nphiTrigHitLayers
uint8_t nphiTrigHitLayers
Number of eta stereo hits.
Definition: IMuonSegmentHitSummaryTool.h:51
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:192
Muon::IMuonSegmentHitSummaryTool::HitCounts::nstgcHits
EtaPhiHitCount nstgcHits
Definition: IMuonSegmentHitSummaryTool.h:46
Muon::CompetingMuonClustersOnTrack::containedROTs
const std::vector< const MuonClusterOnTrack * > & containedROTs() const
returns the vector of SCT_ClusterOnTrack objects .
Definition: CompetingMuonClustersOnTrack.h:184
Muon::IMuonSegmentHitSummaryTool::HitCounts
Definition: IMuonSegmentHitSummaryTool.h:37
Muon::IMuonSegmentHitSummaryTool::HitCounts::ncscHits
EtaPhiHitCount ncscHits
Definition: IMuonSegmentHitSummaryTool.h:45
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmmEtaHits
uint8_t nmmEtaHits
Definition: IMuonSegmentHitSummaryTool.h:48
Muon::MuonSegmentConverterTool::convert
xAOD::MuonSegment * convert(const ElementLink< ::Trk::SegmentCollection > &segLink, xAOD::MuonSegmentContainer *container=0) const
convert a ElementLink to a Trk::Segment (should be of type MuonSegment) to a xAOD::MuonSegment,...
Definition: MuonSegmentConverterTool.cxx:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::MuonSegment_v1::setIdentifier
void setIdentifier(int sector, ::Muon::MuonStationIndex::ChIndex chamberIndex, int etaIndex, ::Muon::MuonStationIndex::TechnologyIndex technology)
Set the identifier.
Definition: MuonSegment_v1.cxx:73
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
xAOD::MuonSegment_v1::setDirection
void setDirection(float px, float py, float pz)
Sets the direction.
Definition: MuonSegment_v1.cxx:39
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
Trk::FitQuality::chiSquared
double chiSquared() const
returns the of the overall track fit
Definition: FitQuality.h:56
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
MuonClusterOnTrack.h
Trk::SpaceTimePointBase::time
float time() const
access to the measured time
Definition: SpaceTimePointBase.h:47
Muon::MuonSegment
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:45
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
FitQuality.h
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
xAOD::MuonSegment_v1::setFitQuality
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
Definition: MuonSegment_v1.cxx:61
Muon::MuonSegmentConverterTool::m_hitTimingTool
ToolHandle< IMuonHitTimingTool > m_hitTimingTool
Definition: MuonSegmentConverterTool.h:54
Muon::IMuonSegmentHitSummaryTool::EtaPhiHitCount::netaHits
uint8_t netaHits
Definition: IMuonSegmentHitSummaryTool.h:21
Muon::MuonClusterOnTrack
Base class for Muon cluster RIO_OnTracks.
Definition: MuonClusterOnTrack.h:34
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
Identifier
Definition: IdentifierFieldParser.cxx:14