ATLAS Offline Software
SortMeasurementsByPosition.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef SORTMEASUREMENTSBYPOSITION_H
6 #define SORTMEASUREMENTSBYPOSITION_H
7 
8 #include <functional>
9 #include <iostream>
10 
11 #include "CxxUtils/fpcompare.h"
17 
18 namespace Muon {
19 
21  public:
23  double operator()(const Amg::Vector3D& pos) const {
24  Amg::Vector3D difPos = pos - m_pars->position();
25  double sign = difPos.dot(m_pars->momentum()) < 0 ? -1. : 1.;
26  return difPos.mag() * sign;
27  }
28 
29  private:
31  };
32 
34  public:
35  SortTSOSsByPos(bool isEndcap) : m_isEndcap(isEndcap), m_dummyPosition(0., 0., 0.) {}
36  double operator()(const Trk::TrackStateOnSurface* tsos1, const Trk::TrackStateOnSurface* tsos2) {
37  if (m_isEndcap)
38  return std::abs(position(*tsos1).z()) < std::abs(position(*tsos2).z());
39  else
40  return position(*tsos1).perp() < position(*tsos2).perp();
41  }
42 
43  private:
45  if (tsos.trackParameters())
46  return tsos.trackParameters()->position();
47  else if (tsos.measurementOnTrack())
48  return tsos.measurementOnTrack()->globalPosition();
49  return m_dummyPosition;
50  }
51  bool m_isEndcap;
53  };
54 
56  public:
58  // SortTSOSByDistanceToPars(std::unique_ptr<const Trk::TrackParameters> pars) : SortTSOSByDistanceToPars(pars.get()) {}
59  double operator()(const std::pair<bool, const Trk::TrackStateOnSurface*>& tsos1,
60  const std::pair<bool, const Trk::TrackStateOnSurface*>& tsos2) {
61  return CxxUtils::fpcompare::less(m_distToPars(position(*tsos1.second)), m_distToPars(position(*tsos2.second)));
62  }
63  double operator()(const std::unique_ptr<const Trk::TrackStateOnSurface>& tsos1,
64  const std::unique_ptr<const Trk::TrackStateOnSurface>& tsos2) {
66  }
67 
68  private:
70  if (tsos.trackParameters())
71  return tsos.trackParameters()->position();
72  else if (tsos.measurementOnTrack())
73  return tsos.measurementOnTrack()->globalPosition();
74  return m_dummyPosition;
75  }
78  };
79 
80  class SortTSOSs {
81  public:
82  bool operator()(const Trk::TrackStateOnSurface* tsos1, const Trk::TrackStateOnSurface* tsos2) const {
83  if (!tsos1->trackParameters()) {
84  std::cout << "Muon::SortTSOSs: state 1 without parameters " << std::endl;
85  return false;
86  }
87  if (!tsos2->trackParameters()) {
88  std::cout << "Muon::SortTSOSs: state 2 without parameters " << std::endl;
89  return true;
90  }
91  // first, address rare problems with funky track directions leading to strange orderings by checking for comparisons of calo
92  // deposits and MS hits
93  const Trk::MeasurementBase* meas1 = tsos1->measurementOnTrack();
94  Identifier id1 = meas1 ? m_helperSvc->getIdentifier(*meas1) : Identifier();
95 
96  const Trk::MeasurementBase* meas2 = tsos2->measurementOnTrack();
97  Identifier id2 = meas2 ? m_helperSvc->getIdentifier(*meas2) : Identifier();
98 
99  bool okId1 = id1.is_valid() && m_idHelperSvc->isMuon(id1) ? true : false;
100  bool okId2 = id2.is_valid() && m_idHelperSvc->isMuon(id2) ? true : false;
101 
102  if (tsos1->type(Trk::TrackStateOnSurface::TrackStateOnSurfaceType::CaloDeposit) ||
103  tsos2->type(Trk::TrackStateOnSurface::TrackStateOnSurfaceType::CaloDeposit)) {
104  if (okId1 && tsos2->type(Trk::TrackStateOnSurface::TrackStateOnSurfaceType::CaloDeposit)) return false;
105  if (tsos1->type(Trk::TrackStateOnSurface::TrackStateOnSurfaceType::CaloDeposit) && okId2) return true;
106  }
107 
108  // get average direction of the 2 TSOSs
109  Amg::Vector3D trackDir = tsos1->trackParameters()->momentum().unit();
110  trackDir += tsos2->trackParameters()->momentum().unit();
111  const Amg::Vector3D& pos1 = tsos1->trackParameters()->position();
112  const Amg::Vector3D& pos2 = tsos2->trackParameters()->position();
113  double dist = (pos2 - pos1).dot(trackDir);
114 
115  if (std::abs(dist) < 1e-5) {
116  // one is a good muon hit and one is not: good muon hit comes after
117  if (okId1 && !okId2) return true;
118  if (!okId1 && okId2) return false;
119  // both invalid or non-muon: consider them equal
120  if (!okId1 && !okId2) return false;
121  // now we have 2 valid muon Ids
122  bool measPhi1 = m_idHelperSvc->measuresPhi(id1);
123  bool measPhi2 = m_idHelperSvc->measuresPhi(id2);
124  // put phi measurement in front of eta measurements
125  if (measPhi1 && !measPhi2) return true;
126  if (!measPhi1 && measPhi2) return false;
127  // now both are phi or both are eta
128  // decide on identifier (increasing away from IP within same technology)
129  double inOrOut = (pos1 + pos2).dot(trackDir);
130  if (inOrOut >= 0.0) {
131  return id1 < id2;
132  } else {
133  return id1 > id2;
134  }
135 
136  // if we get here, there was no decision
137  return false; // consider them equal
138  }
139  return dist > 0.;
140  }
141  bool operator()(const std::unique_ptr<const Trk::TrackStateOnSurface>& tsos1,
142  const std::unique_ptr<const Trk::TrackStateOnSurface>& tsos2) const {
143  return this->operator()(tsos1.get(), tsos2.get());
144  }
145 
147 
150  };
151 
153  public:
154  SortMeasurementsByPosition(bool hasEndcap = true) : m_isEndcap(hasEndcap) {}
155 
156  bool operator()(const Trk::MeasurementBase* meas1, const Trk::MeasurementBase* meas2) {
157  const Trk::MeasurementBase* m1 = getMeas(meas1);
158  const Trk::MeasurementBase* m2 = getMeas(meas2);
159 
160  double d1 = m_isEndcap ? std::abs(m1->globalPosition().z()) : std::abs(m1->globalPosition().perp());
161  double d2 = m_isEndcap ? std::abs(m2->globalPosition().z()) : std::abs(m2->globalPosition().perp());
162  bool result = d1 < d2;
163  return result;
164  }
165 
166  private:
167  // hack to correctly sort competing rots
169  const CompetingMuonClustersOnTrack* cm = dynamic_cast<const CompetingMuonClustersOnTrack*>(meas);
170  if (cm) {
171  if (cm->numberOfContainedROTs() != 0) return &cm->rioOnTrack(cm->indexOfMaxAssignProb());
172  }
173  return meas;
174  }
175 
177  };
178 
179 } // namespace Muon
180 
181 #endif
Muon::SortTSOSsByPos::m_dummyPosition
Amg::Vector3D m_dummyPosition
Definition: SortMeasurementsByPosition.h:52
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
Trk::TrackStateOnSurface::trackParameters
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
Muon::IMuonIdHelperSvc::isMuon
virtual bool isMuon(const Identifier &id) const =0
returns whether this is a Muon Identifier or not
Muon::SortTSOSs
Definition: SortMeasurementsByPosition.h:80
Muon::IMuonEDMHelperSvc::getIdentifier
virtual Identifier getIdentifier(const Trk::MeasurementBase &meas) const =0
tries to get Identifier for measurement, if not possible it will return Identifier()
get_generator_info.result
result
Definition: get_generator_info.py:21
python.SystemOfUnits.m2
int m2
Definition: SystemOfUnits.py:92
Muon::IMuonEDMHelperSvc
Helper tool containing functionality needed by multiple tools.
Definition: IMuonEDMHelperSvc.h:33
Muon::SortMeasurementsByPosition::SortMeasurementsByPosition
SortMeasurementsByPosition(bool hasEndcap=true)
Definition: SortMeasurementsByPosition.h:154
Muon::SortTSOSs::operator()
bool operator()(const Trk::TrackStateOnSurface *tsos1, const Trk::TrackStateOnSurface *tsos2) const
Definition: SortMeasurementsByPosition.h:82
MeasurementBase.h
Muon::SortMeasurementsByPosition::operator()
bool operator()(const Trk::MeasurementBase *meas1, const Trk::MeasurementBase *meas2)
Definition: SortMeasurementsByPosition.h:156
Muon::SortTSOSs::m_idHelperSvc
const IMuonIdHelperSvc * m_idHelperSvc
Definition: SortMeasurementsByPosition.h:149
Muon::SortMeasurementsByPosition::getMeas
const Trk::MeasurementBase * getMeas(const Trk::MeasurementBase *meas) const
Definition: SortMeasurementsByPosition.h:168
Muon::SortTSOSsByPos::operator()
double operator()(const Trk::TrackStateOnSurface *tsos1, const Trk::TrackStateOnSurface *tsos2)
Definition: SortMeasurementsByPosition.h:36
Muon::SortTSOSsByPos
Definition: SortMeasurementsByPosition.h:33
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
Muon::SortTSOSs::operator()
bool operator()(const std::unique_ptr< const Trk::TrackStateOnSurface > &tsos1, const std::unique_ptr< const Trk::TrackStateOnSurface > &tsos2) const
Definition: SortMeasurementsByPosition.h:141
CompetingMuonClustersOnTrack.h
Muon::SortTSOSByDistanceToPars::m_dummyPosition
Amg::Vector3D m_dummyPosition
Definition: SortMeasurementsByPosition.h:77
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
Trk::TrackStateOnSurface::measurementOnTrack
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
Muon::SortTSOSByDistanceToPars::operator()
double operator()(const std::pair< bool, const Trk::TrackStateOnSurface * > &tsos1, const std::pair< bool, const Trk::TrackStateOnSurface * > &tsos2)
Definition: SortMeasurementsByPosition.h:59
Muon::IMuonIdHelperSvc::measuresPhi
virtual bool measuresPhi(const Identifier &id) const =0
returns whether channel measures phi or not
Muon::CompetingMuonClustersOnTrack
Definition: CompetingMuonClustersOnTrack.h:54
Muon::SortMeasurementsByPosition::m_isEndcap
bool m_isEndcap
Definition: SortMeasurementsByPosition.h:176
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
Muon::SortTSOSByDistanceToPars::position
Amg::Vector3D position(const Trk::TrackStateOnSurface &tsos) const
Definition: SortMeasurementsByPosition.h:69
Muon::SortTSOSsByPos::SortTSOSsByPos
SortTSOSsByPos(bool isEndcap)
Definition: SortMeasurementsByPosition.h:35
Muon::SortTSOSs::m_helperSvc
const IMuonEDMHelperSvc * m_helperSvc
Definition: SortMeasurementsByPosition.h:148
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
GeoPrimitives.h
Trk::TrackStateOnSurface::type
bool type(const TrackStateOnSurfaceType type) const
Use this method to find out if the TSoS is of a certain type: i.e.
Muon::SortMeasurementsByPosition
Definition: SortMeasurementsByPosition.h:152
python.changerun.m1
m1
Definition: changerun.py:32
id2
HWIdentifier id2
Definition: LArRodBlockPhysicsV0.cxx:562
fpcompare.h
Workaround x86 precision issues for FP inequality comparisons.
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:107
Trk::ParametersBase
Definition: ParametersBase.h:55
dot.dot
def dot(G, fn, nodesToHighlight=[])
Definition: dot.py:5
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Muon::SortTSOSByDistanceToPars::operator()
double operator()(const std::unique_ptr< const Trk::TrackStateOnSurface > &tsos1, const std::unique_ptr< const Trk::TrackStateOnSurface > &tsos2)
Definition: SortMeasurementsByPosition.h:63
IMuonEDMHelperSvc.h
Muon::DistanceToPars::operator()
double operator()(const Amg::Vector3D &pos) const
Definition: SortMeasurementsByPosition.h:23
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
Muon::SortTSOSs::SortTSOSs
SortTSOSs(const IMuonEDMHelperSvc *h, const IMuonIdHelperSvc *idh)
Definition: SortMeasurementsByPosition.h:146
Trk::MeasurementBase::globalPosition
virtual const Amg::Vector3D & globalPosition() const =0
Interface method to get the global Position.
CxxUtils::fpcompare::less
bool less(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition: fpcompare.h:166
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Muon::SortTSOSByDistanceToPars::m_distToPars
DistanceToPars m_distToPars
Definition: SortMeasurementsByPosition.h:76
Muon::DistanceToPars::DistanceToPars
DistanceToPars(const Trk::TrackParameters *pars)
Definition: SortMeasurementsByPosition.h:22
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
h
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
Muon::SortTSOSByDistanceToPars
Definition: SortMeasurementsByPosition.h:55
Muon::DistanceToPars::m_pars
const Trk::TrackParameters * m_pars
Definition: SortMeasurementsByPosition.h:30
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:27
Muon::SortTSOSsByPos::m_isEndcap
bool m_isEndcap
Definition: SortMeasurementsByPosition.h:51
Muon::SortTSOSByDistanceToPars::SortTSOSByDistanceToPars
SortTSOSByDistanceToPars(const Trk::TrackParameters *pars)
Definition: SortMeasurementsByPosition.h:57
Muon::SortTSOSsByPos::position
Amg::Vector3D position(const Trk::TrackStateOnSurface &tsos)
Definition: SortMeasurementsByPosition.h:44
Muon::DistanceToPars
Definition: SortMeasurementsByPosition.h:20
IMuonIdHelperSvc.h
Identifier
Definition: IdentifierFieldParser.cxx:14