ATLAS Offline Software
Loading...
Searching...
No Matches
SortMeasurementsByPosition.h
Go to the documentation of this file.
1/*
2Copyright (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
18namespace 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.) {}
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 }
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
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
HWIdentifier id2
int sign(int a)
Header file for AthHistogramAlgorithm.
bool is_valid() const
Check if id is in a valid state.
Class for competing MuonClusters, it extends the Trk::CompetingRIOsOnTrack base class.
const Trk::TrackParameters * m_pars
double operator()(const Amg::Vector3D &pos) const
DistanceToPars(const Trk::TrackParameters *pars)
Helper tool containing functionality needed by multiple tools.
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
bool operator()(const Trk::MeasurementBase *meas1, const Trk::MeasurementBase *meas2)
const Trk::MeasurementBase * getMeas(const Trk::MeasurementBase *meas) const
Amg::Vector3D position(const Trk::TrackStateOnSurface &tsos) const
double operator()(const std::unique_ptr< const Trk::TrackStateOnSurface > &tsos1, const std::unique_ptr< const Trk::TrackStateOnSurface > &tsos2)
double operator()(const std::pair< bool, const Trk::TrackStateOnSurface * > &tsos1, const std::pair< bool, const Trk::TrackStateOnSurface * > &tsos2)
SortTSOSByDistanceToPars(const Trk::TrackParameters *pars)
double operator()(const Trk::TrackStateOnSurface *tsos1, const Trk::TrackStateOnSurface *tsos2)
Amg::Vector3D position(const Trk::TrackStateOnSurface &tsos)
const IMuonIdHelperSvc * m_idHelperSvc
const IMuonEDMHelperSvc * m_helperSvc
bool operator()(const std::unique_ptr< const Trk::TrackStateOnSurface > &tsos1, const std::unique_ptr< const Trk::TrackStateOnSurface > &tsos2) const
bool operator()(const Trk::TrackStateOnSurface *tsos1, const Trk::TrackStateOnSurface *tsos2) const
SortTSOSs(const IMuonEDMHelperSvc *h, const IMuonIdHelperSvc *idh)
This class is the pure abstract base class for all fittable tracking measurements.
virtual const Amg::Vector3D & globalPosition() const =0
Interface method to get the global Position.
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
represents the track state (measurement, material, fit parameters and quality) at a surface.
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
bool type(const TrackStateOnSurfaceType type) const
Use this method to find out if the TSoS is of a certain type: i.e.
@ CaloDeposit
This TSOS contains a CaloEnergy object.
Workaround x86 precision issues for FP inequality comparisons.
Eigen::Matrix< double, 3, 1 > Vector3D
bool less(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition fpcompare.h:166
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
ParametersBase< TrackParametersDim, Charged > TrackParameters
Definition dot.py:1