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  : AthAlgTool(t, n, p) {
27  declareInterface<xAODMaker::IMuonSegmentConverterTool>(this);
28 }
29 
32 {
33  ATH_CHECK(m_hitSummaryTool.retrieve());
34  ATH_CHECK(m_idHelperSvc.retrieve());
35  ATH_CHECK(m_edmHelper.retrieve());
36  ATH_CHECK(m_hitTimingTool.retrieve());
37 
38  return StatusCode::SUCCESS;
39 }
40 
43  xAOD::MuonSegmentContainer* container) const
44 {
45  // sanity checks
46  if (!segLink.isValid() || !*segLink) {
47  ATH_MSG_WARNING(" Got invalid element link");
48  return nullptr;
49  }
50  const MuonSegment* seg = dynamic_cast<const MuonSegment*>(*segLink);
51  if (!seg) {
52  ATH_MSG_WARNING(" Trk::Segment is not a MuonSegment ");
53  return nullptr;
54  }
55 
56  // create xAOD::Muon and set link
57  xAOD::MuonSegment* xaodSeg = convert(*seg, container);
58  if (xaodSeg) xaodSeg->setMuonSegment(segLink);
59  return xaodSeg;
60 }
61 
62 
63 void
65 {
66 
67  // loop over hits and extract clusters
68  std::vector<const MuonClusterOnTrack*> clusters;
69  for (const Trk::MeasurementBase* meas : seg.containedMeasurements()) {
70 
71  // get Identifier and remove MDT hits
72  Identifier id = m_edmHelper->getIdentifier(*meas);
73  if (!id.is_valid() || !m_idHelperSvc->isTrigger(id)) continue;
74 
75  // cast to MuonClusterOnTrack
76  const MuonClusterOnTrack* clus = dynamic_cast<const MuonClusterOnTrack*>(meas);
77  if (clus)
78  clusters.push_back(clus);
79  else {
80  const CompetingMuonClustersOnTrack* crot = dynamic_cast<const CompetingMuonClustersOnTrack*>(meas);
81  if (!crot || crot->containedROTs().empty()) continue;
82  clusters.insert(clusters.end(), crot->containedROTs().begin(), crot->containedROTs().end());
83  }
84  }
85 
86  // call timing tool and dress xaodSeg
88  if (std::abs(result.time) > std::numeric_limits<float>::max()
89  || std::abs(result.error) > std::numeric_limits<float>::max())
90  {
91  // xAOD stores this as a float. To avoid FPE, we need to check here...
92  if (result.valid)
93  ATH_MSG_WARNING("Unphysical time returned by tool - ignoring. result.valid = "
94  + std::to_string(result.valid));
95  acc_clusterTime(xaodSeg) = std::numeric_limits<float>::max();
96  acc_clusterTimeError(xaodSeg) = std::numeric_limits<float>::max();
97  acc_clusterTimeValid(xaodSeg) = 0;
98  } else {
99  acc_clusterTime(xaodSeg) = result.time;
100  acc_clusterTimeError(xaodSeg) = result.error;
101  acc_clusterTimeValid(xaodSeg) = result.valid;
102  }
103 }
104 
105 
108 {
109 
110  // create xAOD::MuonSegment
111  xAOD::MuonSegment* xaodSeg = new xAOD::MuonSegment();
112  if (container)
113  container->push_back(xaodSeg);
114  else
115  xaodSeg->makePrivateStore();
116 
117  // set position and direction
118  xaodSeg->setPosition(seg.globalPosition().x(), seg.globalPosition().y(), seg.globalPosition().z());
119  xaodSeg->setDirection(seg.globalDirection().x(), seg.globalDirection().y(), seg.globalDirection().z());
120 
121  // fit chi2
122  const Trk::FitQuality* fq = seg.fitQuality();
123  if (fq) xaodSeg->setFitQuality(fq->chiSquared(), fq->numberDoF());
124 
125  // identifier
126  Identifier id = m_edmHelper->chamberId(seg);
127  int eta = m_idHelperSvc->stationEta(id);
128  int sector = m_idHelperSvc->sector(id);
129  MuonStationIndex::ChIndex chIndex = m_idHelperSvc->chamberIndex(id);
130  MuonStationIndex::TechnologyIndex technology = m_idHelperSvc->technologyIndex(id);
131  xaodSeg->setIdentifier(sector, chIndex, eta, technology);
132 
133  // hit counts
134  IMuonSegmentHitSummaryTool::HitCounts hitCounts = m_hitSummaryTool->getHitCounts(seg);
135  xaodSeg->setNHits(hitCounts.nmdtHits()+ hitCounts.nmmHits() + hitCounts.nstgcHits.netaHits + hitCounts.ncscHits.netaHits,
136  hitCounts.nphiTrigHitLayers + hitCounts.nstgcHits.nphiHits, hitCounts.netaTrigHitLayers);
137 
138  // MDT + cluster timing
139  if (seg.hasFittedT0()) xaodSeg->setT0Error(seg.time(), seg.errorTime());
140  if (!m_hitTimingTool.empty()) addClusterTiming(seg, *xaodSeg);
142  if (m_idHelperSvc->hasMM()) {
143  acc_mmStereoHits(*xaodSeg) = hitCounts.nmmStereoHits;
144  acc_mmEtaHits(*xaodSeg) = hitCounts.nmmEtaHits;
145  }
146  if (m_idHelperSvc->hasSTGC()) {
147  acc_stgcEtaHits(*xaodSeg) = hitCounts.nstgcHits.netaHits;
148  acc_stgcPhiHits(*xaodSeg) = hitCounts.nstgcHits.nphiHits;
149  }
150  return xaodSeg;
151 }
152 
153 
154 } // 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:64
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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
max
#define max(a, b)
Definition: cfImp.cxx:41
xAOD::MuonSegment_v1::setPosition
void setPosition(float x, float y, float z)
Sets the global position.
Definition: MuonSegment_v1.cxx:22
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmmStereoHits
uint8_t nmmStereoHits
Number of eta micromega hits.
Definition: IMuonSegmentHitSummaryTool.h:49
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
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
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:49
Muon::MuonSegmentConverterTool::m_edmHelper
ServiceHandle< IMuonEDMHelperSvc > m_edmHelper
Definition: MuonSegmentConverterTool.h:71
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:47
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:84
Muon::MuonSegmentConverterTool::initialize
StatusCode initialize()
initialize method, method taken from bass-class AlgTool
Definition: MuonSegmentConverterTool.cxx:31
Muon::IMuonSegmentHitSummaryTool::HitCounts::nmmHits
uint8_t nmmHits() const
Returns the number of hits in the micromegas.
Definition: IMuonSegmentHitSummaryTool.h:62
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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:56
Muon::MuonSegmentConverterTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonSegmentConverterTool.h:66
Trk::Segment::containedMeasurements
const std::vector< const Trk::MeasurementBase * > & containedMeasurements() const
returns the vector of Trk::MeasurementBase objects
Definition: 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:581
Muon::IMuonHitTimingTool::TimingResult
simple struct holding the result of the tool
Definition: IMuonHitTimingTool.h:39
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:172
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:42
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:69
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:35
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
AthAlgTool
Definition: AthAlgTool.h:26
Trk::Segment::fitQuality
const FitQuality * fitQuality() const
return the FitQuality object, returns NULL if no FitQuality is defined
Definition: 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:57
Muon::MuonSegmentConverterTool::m_hitTimingTool
ToolHandle< IMuonHitTimingTool > m_hitTimingTool
Definition: MuonSegmentConverterTool.h:61
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