ATLAS Offline Software
Loading...
Searching...
No Matches
CurvedLine.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8#include "GaudiKernel/MsgStream.h"
11
12using namespace MuonCalib;
13
14//*****************************************************************************
15
16//:::::::::::::::::::::::::
17//:: DEFAULT CONSTRUCTOR ::
18//:::::::::::::::::::::::::
19
22 // VARIABLES //
24
25 std::vector<Amg::Vector3D> points(3);
26 std::vector<Amg::Vector3D> errors(3);
27
29 // FILL VARIABLES //
31
32 points[0] = Amg::Vector3D(0.0, 0.0, 0.0);
33 errors[0] = Amg::Vector3D(1.0, 1.0, 0.0);
34 points[1] = Amg::Vector3D(0.0, 0.0, 1.0);
35 errors[1] = Amg::Vector3D(1.0, 1.0, 0.0);
36 points[2] = Amg::Vector3D(0.0, 0.0, 2.0);
37 errors[2] = Amg::Vector3D(1.0, 1.0, 0.0);
38
40 // INITIALIZATION //
42
43 init(points, errors);
44}
45
46//*****************************************************************************
47
48//:::::::::::::::::
49//:: CONSTRUCTOR ::
50//:::::::::::::::::
51
52CurvedLine::CurvedLine(std::vector<Amg::Vector3D>& points) {
54 // VARIABLES //
56
57 std::vector<Amg::Vector3D> errors(points.size(), Amg::Vector3D(1.0, 1.0, 0.0));
58
60 // INITIALIZATION //
62
63 init(points, errors);
64}
65
66//*****************************************************************************
67
68//:::::::::::::::::
69//:: CONSTRUCTOR ::
70//:::::::::::::::::
71
72CurvedLine::CurvedLine(std::vector<Amg::Vector3D>& points, std::vector<Amg::Vector3D>& x_and_y_errors) { init(points, x_and_y_errors); }
73
74//*****************************************************************************
75
76//::::::::::::::::::::::::::::::
77//:: METHOD getPointOnLine ::
78//::::::::::::::::::::::::::::::
79
80Amg::Vector3D CurvedLine::getPointOnLine(const double loc_z) const {
82 // VARIABLES //
84
85 double loc_x{0.0}, loc_y{0.0};
86
88 // CALCULATE THE COORDINATES //
90
91 for (int k = 0; k < m_coeff_xz.rows(); k++) {
92 loc_x += m_coeff_xz[k] * std::legendre(k, loc_z);
93 }
94
95 for (int k = 0; k < m_coeff_yz.rows(); k++) {
96 loc_y += m_coeff_yz[k] * std::legendre(k, loc_z);
97 }
98
100 // RETURN THE REQUESTED POINT //
102
103 return Amg::Vector3D(loc_x, loc_y, loc_z);
104}
105
106//*****************************************************************************
107
108//::::::::::::::::::::::::
109//:: METHOD getTangent ::
110//::::::::::::::::::::::::
111
112MTStraightLine CurvedLine::getTangent(const double loc_z) const {
114 // VARIABLES //
116
117 Amg::Vector3D null_vec(0.0, 0.0, 0.0); // auxiliary 0 vector
118 Amg::Vector3D point_1(getPointOnLine(loc_z)); // first point on the curved
119 // line
120 Amg::Vector3D point_2(getPointOnLine(loc_z + 1.0)); // second point on the
121 // curved line
122
124 // RETURN THE TANGENT //
126
127 return MTStraightLine(point_1, point_2 - point_1, null_vec, null_vec);
128}
129
130//*****************************************************************************
131
132//:::::::::::::::::
133//:: METHOD init ::
134//:::::::::::::::::
135
136void CurvedLine::init(std::vector<Amg::Vector3D>& points, std::vector<Amg::Vector3D>& x_and_y_errors) {
138 // CHECK THE NUMBER OF POINTS //
140
141 if (points.size() < 3) {
142 MsgStream log(Athena::getMessageSvc(), "CurvedLine");
143 log << MSG::ERROR << "Class CurvedLine, method init: Not enough points given, must be at least 3 points!" << endmsg;
144 }
145
147 // VARIABLES //
149
150 BaseFunctionFitter fitter;
151 LegendrePolynomial legendre; // Legendre polynomial needed by the base
152 // function fitter
153 std::vector<SamplePoint> sample_points(points.size()); // sample points needed
154 // by the base function
155 // fitter
157 // FILL THE VARIABLES AND PERFORM THE FITS //
159
160 // xz plane //
161 for (unsigned int k = 0; k < points.size(); k++) {
162 sample_points[k].set_x1(points[k].z());
163 sample_points[k].set_x2(points[k].x());
164 sample_points[k].set_error(x_and_y_errors[k].x());
165 }
166 fitter.set_number_of_coefficients(2);
167 fitter.fit_parameters(sample_points, 1, sample_points.size(), legendre);
168 m_coeff_xz = fitter.coefficients();
169
170 // yz plane //
171 for (unsigned int k = 0; k < points.size(); k++) {
172 sample_points[k].set_x1(points[k].z());
173 sample_points[k].set_x2(points[k].y());
174 sample_points[k].set_error(x_and_y_errors[k].y());
175 }
176 fitter.set_number_of_coefficients(3);
177 fitter.fit_parameters(sample_points, 1, sample_points.size(), legendre);
178 m_coeff_yz = fitter.coefficients();
179
180}
181void CurvedLine::setChi2(double chi2) { m_chi2 = std::isnan(chi2) ? -1 : chi2; }
182double CurvedLine::chi2() const { return m_chi2; }
183void CurvedLine::setNumberOfTrackHits(unsigned int n_hits) { m_numTrkHits = n_hits; }
184unsigned int CurvedLine::numberOfTrackHits() const { return m_numTrkHits; }
185
186double CurvedLine::chi2PerDegreesOfFreedom() const { return m_chi2 / (m_numTrkHits > 2 ? m_numTrkHits - 3 : 0.01); }
187
188void CurvedLine::setUsedHits(const MdtHitVec& hits) { m_used_hits = hits; }
#define endmsg
#define y
#define x
#define z
This class performs a fit of a linear combination of base functions to a set of sample points.
Amg::VectorX m_coeff_yz
Definition CurvedLine.h:79
unsigned int m_numTrkHits
Definition CurvedLine.h:83
void setChi2(double chi2)
Cache the chi2.
double chi2PerDegreesOfFreedom() const
Return chi2 / number of TrackHits - 3.
const MdtHitVec & trackHits() const
double chi2() const
MTStraightLine getTangent(const double loc_z) const
get the tangent to the line a the local z coordinate "loc_z"
unsigned int numberOfTrackHits() const
MuonCalibSegment::MdtHitVec MdtHitVec
Definition CurvedLine.h:32
Amg::VectorX m_coeff_xz
Definition CurvedLine.h:77
void init(std::vector< Amg::Vector3D > &points, std::vector< Amg::Vector3D > &x_and_y_errors)
Amg::Vector3D getPointOnLine(const double loc_z) const
get the point on the line a the local z coordinate "loc_z"
void setUsedHits(const MdtHitVec &hits)
CurvedLine()
Default constructor: a straight line through (0,0,0) pointing in in the local x direction of the cham...
void setNumberOfTrackHits(unsigned int n_hits)
cache the number of track hits
This class provides a legendre polynomial of order k.
singleton-like access to IMessageSvc via open function and helper
Eigen::Matrix< double, 3, 1 > Vector3D
IMessageSvc * getMessageSvc(bool quiet=false)
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.