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());
58 
60  // FILL VARIABLES //
62 
63  for (auto & error : errors) { error = Amg::Vector3D(1.0, 1.0, 0.0); }
64 
66  // INITIALIZATION //
68 
69  init(points, errors);
70 }
71 
72 //*****************************************************************************
73 
74 //:::::::::::::::::
75 //:: CONSTRUCTOR ::
76 //:::::::::::::::::
77 
78 CurvedLine::CurvedLine(std::vector<Amg::Vector3D>& points, std::vector<Amg::Vector3D>& x_and_y_errors) { init(points, x_and_y_errors); }
79 
80 //*****************************************************************************
81 
82 //::::::::::::::::::::::::::::::
83 //:: METHOD getPointOnLine ::
84 //::::::::::::::::::::::::::::::
85 
86 Amg::Vector3D CurvedLine::getPointOnLine(const double& loc_z) const {
88  // VARIABLES //
90 
91  double loc_x(0.0), loc_y(0.0);
92 
94  // CALCULATE THE COORDINATES //
96 
97  for (int k = 0; k < m_coeff_xz.rows(); k++) { loc_x = loc_x + m_coeff_xz[k] * m_Legendre->value(k, loc_z); }
98 
99  for (int k = 0; k < m_coeff_yz.rows(); k++) { loc_y = loc_y + m_coeff_yz[k] * m_Legendre->value(k, loc_z); }
100 
102  // RETURN THE REQUESTED POINT //
104 
105  return Amg::Vector3D(loc_x, loc_y, loc_z);
106 }
107 
108 //*****************************************************************************
109 
110 //::::::::::::::::::::::::
111 //:: METHOD getTangent ::
112 //::::::::::::::::::::::::
113 
114 MTStraightLine CurvedLine::getTangent(const double& loc_z) const {
116  // VARIABLES //
118 
119  Amg::Vector3D null_vec(0.0, 0.0, 0.0); // auxiliary 0 vector
120  Amg::Vector3D point_1(getPointOnLine(loc_z)); // first point on the curved
121  // line
122  Amg::Vector3D point_2(getPointOnLine(loc_z + 1.0)); // second point on the
123  // curved line
124 
126  // RETURN THE TANGENT //
128 
129  return MTStraightLine(point_1, point_2 - point_1, null_vec, null_vec);
130 }
131 
132 //*****************************************************************************
133 
134 //:::::::::::::::::
135 //:: METHOD init ::
136 //:::::::::::::::::
137 
138 void CurvedLine::init(std::vector<Amg::Vector3D>& points, std::vector<Amg::Vector3D>& x_and_y_errors) {
140  // CHECK THE NUMBER OF POINTS //
142 
143  if (points.size() < 3) {
144  MsgStream log(Athena::getMessageSvc(), "CurvedLine");
145  log << MSG::ERROR << "Class CurvedLine, method init: Not enough points given, must be at least 3 points!" << endmsg;
146  }
147 
149  // VARIABLES //
151 
153  LegendrePolynomial legendre; // Legendre polynomial needed by the base
154  // function fitter
155  std::vector<SamplePoint> sample_points(points.size()); // sample points needed
156  // by the base function
157  // fitter
159  // FILL THE VARIABLES AND PERFORM THE FITS //
161 
162  // xz plane //
163  for (unsigned int k = 0; k < points.size(); k++) {
164  sample_points[k].set_x1(points[k].z());
165  sample_points[k].set_x2(points[k].x());
166  sample_points[k].set_error(x_and_y_errors[k].x());
167  }
168  fitter.set_number_of_coefficients(2);
169  fitter.fit_parameters(sample_points, 1, sample_points.size(), &legendre);
170  m_coeff_xz = fitter.coefficients();
171 
172  // yz plane //
173  for (unsigned int k = 0; k < points.size(); k++) {
174  sample_points[k].set_x1(points[k].z());
175  sample_points[k].set_x2(points[k].y());
176  sample_points[k].set_error(x_and_y_errors[k].y());
177  }
178  fitter.set_number_of_coefficients(3);
179  fitter.fit_parameters(sample_points, 1, sample_points.size(), &legendre);
180  m_coeff_yz = fitter.coefficients();
181 
183  // GET A POINTER TO THE LEGENDRE POLYNOMIAL //
185 
187 
188  return;
189 }
190 void CurvedLine::setChi2(double chi2) { m_chi2 = std::isnan(chi2) ? -1 : chi2; }
191 double CurvedLine::chi2() const { return m_chi2; }
192 void CurvedLine::setNumberOfTrackHits(unsigned int n_hits) { m_numTrkHits = n_hits; }
193 unsigned int CurvedLine::numberOfTrackHits() const { return m_numTrkHits; }
194 
195 double CurvedLine::chi2PerDegreesOfFreedom() const { return m_chi2 / (m_numTrkHits > 2 ? m_numTrkHits - 3 : 0.01); }
196 
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:138
MuonCalib::CurvedLine::m_used_hits
MdtHitVec m_used_hits
Definition: CurvedLine.h:88
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
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:114
MuonCalib::CurvedLine::m_Legendre
const Legendre_polynomial * m_Legendre
Definition: CurvedLine.h:79
MuonCalib::Legendre_polynomial::get_Legendre_polynomial
static const Legendre_polynomial * get_Legendre_polynomial(void)
get a pointer to the Legendre polynomial
Definition: Legendre_polynomial.cxx:31
x
#define x
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
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:86
MuonCalib::CurvedLine::setChi2
void setChi2(double chi2)
Cache the chi2.
Definition: CurvedLine.cxx:190
MuonCalib::BaseFunctionFitter
Definition: BaseFunctionFitter.h:47
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:193
MuonCalib::CurvedLine::MdtHitVec
MuonCalibSegment::MdtHitVec MdtHitVec
Definition: CurvedLine.h:33
CurvedLine.h
MuonCalib::CurvedLine::setNumberOfTrackHits
void setNumberOfTrackHits(unsigned int n_hits)
cache the number of track hits
Definition: CurvedLine.cxx:192
z
#define z
MuonCalib::CurvedLine::m_coeff_xz
Amg::VectorX m_coeff_xz
Definition: CurvedLine.h:81
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArG4ShowerLibProcessing.hits
hits
Definition: LArG4ShowerLibProcessing.py:136
MuonCalib::Legendre_polynomial::value
double value(const int &order, const double &x) const
get the value of the Legendre polynomial of order m_order at x
MuonCalib::CurvedLine::trackHits
const MdtHitVec & trackHits() const
Definition: CurvedLine.cxx:198
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
MuonCalib::LegendrePolynomial
Definition: LegendrePolynomial.h:39
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:191
MuonCalib::CurvedLine::m_numTrkHits
unsigned int m_numTrkHits
Definition: CurvedLine.h:87
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
BaseFunctionFitter.h
MuonCalib::CurvedLine::m_chi2
double m_chi2
Definition: CurvedLine.h:86
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:195
MuonCalib::CurvedLine::setUsedHits
void setUsedHits(const MdtHitVec &hits)
Definition: CurvedLine.cxx:197
y
#define y
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::MTStraightLine
Definition: MTStraightLine.h:16
error
Definition: IImpactPoint3dEstimator.h:70
LegendrePolynomial.h
MuonCalib::CurvedLine::m_coeff_yz
Amg::VectorX m_coeff_yz
Definition: CurvedLine.h:83
fitman.k
k
Definition: fitman.py:528