ATLAS Offline Software
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 
12 using 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 
52 CurvedLine::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 
72 CurvedLine::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 
80 Amg::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 
112 MTStraightLine 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 
136 void 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 
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 }
181 void CurvedLine::setChi2(double chi2) { m_chi2 = std::isnan(chi2) ? -1 : chi2; }
182 double CurvedLine::chi2() const { return m_chi2; }
183 void CurvedLine::setNumberOfTrackHits(unsigned int n_hits) { m_numTrkHits = n_hits; }
184 unsigned int CurvedLine::numberOfTrackHits() const { return m_numTrkHits; }
185 
186 double CurvedLine::chi2PerDegreesOfFreedom() const { return m_chi2 / (m_numTrkHits > 2 ? m_numTrkHits - 3 : 0.01); }
187 
LArSamples::FitterData::fitter
const ShapeFitter * fitter
Definition: ShapeFitter.cxx:23
MuonCalib::CurvedLine::init
void init(std::vector< Amg::Vector3D > &points, std::vector< Amg::Vector3D > &x_and_y_errors)
Definition: CurvedLine.cxx:136
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
MuonCalib::CurvedLine::m_used_hits
MdtHitVec m_used_hits
Definition: CurvedLine.h:84
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
x
#define x
MuonCalib::CurvedLine::getTangent
MTStraightLine getTangent(const double loc_z) const
get the tangent to the line a the local z coordinate "loc_z"
Definition: CurvedLine.cxx:112
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonCalib::CurvedLine::setChi2
void setChi2(double chi2)
Cache the chi2.
Definition: CurvedLine.cxx:181
MuonCalib::BaseFunctionFitter
Definition: BaseFunctionFitter.h:39
MuonCalib::CurvedLine::CurvedLine
CurvedLine()
Default constructor: a straight line through (0,0,0) pointing in in the local x direction of the cham...
Definition: CurvedLine.cxx:20
MuonCalib::CurvedLine::numberOfTrackHits
unsigned int numberOfTrackHits() const
Definition: CurvedLine.cxx:184
MuonCalib::CurvedLine::MdtHitVec
MuonCalibSegment::MdtHitVec MdtHitVec
Definition: CurvedLine.h:32
CurvedLine.h
MuonCalib::CurvedLine::setNumberOfTrackHits
void setNumberOfTrackHits(unsigned int n_hits)
cache the number of track hits
Definition: CurvedLine.cxx:183
z
#define z
MuonCalib::CurvedLine::m_coeff_xz
Amg::VectorX m_coeff_xz
Definition: CurvedLine.h:77
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib::CurvedLine::trackHits
const MdtHitVec & trackHits() const
Definition: CurvedLine.cxx:189
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:523
MuonCalib::LegendrePolynomial
Definition: LegendrePolynomial.h:19
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::CurvedLine::chi2
double chi2() const
Definition: CurvedLine.cxx:182
MuonCalib::CurvedLine::m_numTrkHits
unsigned int m_numTrkHits
Definition: CurvedLine.h:83
MuonCalib::CurvedLine::getPointOnLine
Amg::Vector3D getPointOnLine(const double loc_z) const
get the point on the line a the local z coordinate "loc_z"
Definition: CurvedLine.cxx:80
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
BaseFunctionFitter.h
MuonCalib::CurvedLine::m_chi2
double m_chi2
Definition: CurvedLine.h:82
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonCalib::CurvedLine::chi2PerDegreesOfFreedom
double chi2PerDegreesOfFreedom() const
Return chi2 / number of TrackHits - 3.
Definition: CurvedLine.cxx:186
MuonCalib::CurvedLine::setUsedHits
void setUsedHits(const MdtHitVec &hits)
Definition: CurvedLine.cxx:188
y
#define y
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::MTStraightLine
Definition: MTStraightLine.h:16
LegendrePolynomial.h
jobOptions.points
points
Definition: jobOptions.GenevaPy8_Zmumu.py:97
MuonCalib::CurvedLine::m_coeff_yz
Amg::VectorX m_coeff_yz
Definition: CurvedLine.h:79
fitman.k
k
Definition: fitman.py:528