ATLAS Offline Software
MTStraightLine.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 
7 #include <iostream>
8 
10 #include "GaudiKernel/MsgStream.h"
11 #include "cmath"
12 using namespace MuonCalib;
13 
15  m_position = Amg::Vector3D(0.0, 0.0, 0.0);
16  m_direction = Amg::Vector3D(0.0, 0.0, 0.0);
17  m_position_error = Amg::Vector3D(0.0, 0.0, 0.0);
18  m_direction_error = Amg::Vector3D(0.0, 0.0, 0.0);
19 
20  return;
21 }
22 
23 void MTStraightLine::init(const Amg::Vector3D& r_position, const Amg::Vector3D& r_direction, const Amg::Vector3D& r_position_error,
24  const Amg::Vector3D& r_direction_error) {
25  m_position = r_position;
26  m_direction = r_direction;
27  m_position_error = r_position_error;
28  m_direction_error = r_direction_error;
29 
30  return;
31 }
32 
33 void MTStraightLine::init(const double& r_a_x1, const double& r_b_x1, const double& r_a_x2, const double& r_b_x2, const double& r_a_x1_err,
34  const double& r_b_x1_err, const double& r_a_x2_err, const double& r_b_x2_err) {
35  m_position = Amg::Vector3D(r_b_x1, r_b_x2, 0.0);
36  m_direction = Amg::Vector3D(r_a_x1, r_a_x2, 1.0);
37  m_position_error = Amg::Vector3D(r_b_x1_err, r_b_x2_err, 0.0);
38  m_direction_error = Amg::Vector3D(r_a_x1_err, r_a_x2_err, 1.0);
39 
40  return;
41 }
46 double MTStraightLine::a_x1() const { return (m_direction.z() != 0.) ? m_direction.x() / m_direction.z() : 0.; }
47 
49  return m_direction.z() != 0.
50  ? std::hypot(m_direction_error.x() / m_direction_error.z(), m_direction_error.y() * a_x1() / m_direction_error.z())
51  : 0.;
52 }
53 double MTStraightLine::b_x1() const {
54  if (m_direction.z() == 0.0) {
55  MsgStream log(Athena::getMessageSvc(), "MTStraightLine");
56  log << MSG::WARNING << "Class MTStraightLine, method b_x1: b_x1 not uniquely defined." << endmsg;
57  return m_position.x();
58  }
59  return (m_position.x() - m_position.z() * a_x1());
60 }
61 
63  return std::hypot(m_position_error.x(), a_x1() * m_position_error.z(), m_position.z() * a_x1_error());
64 }
65 double MTStraightLine::a_x2() const { return (m_direction.z() == 0.0) ? 0. : m_direction.y() / m_direction.z(); }
67  return (m_direction.z() == 0)
68  ? 0.0
69  :
70 
71  std::hypot(m_direction_error.y() / m_direction_error.z(), m_direction_error.y() * a_x2() / m_direction_error.z());
72 }
73 
74 double MTStraightLine::b_x2() const {
75  if (m_direction.z() == 0.0) {
76  MsgStream log(Athena::getMessageSvc(), "MTStraightLine");
77  log << MSG::WARNING << "Class MTStraightLine, method b_x2: b_x2 not uniquely defined." << endmsg;
78  return m_position.x();
79  }
80  return (m_position.y() - m_position.z() * a_x2());
81 }
82 
84  return std::hypot(m_position_error.y(), a_x2() * m_position_error.z(), m_position.z() * a_x2_error());
85 }
86 
87 Amg::Vector3D MTStraightLine::pointOnLine(const double& lambda) const { return m_position + lambda * m_direction; }
88 
90  //:::::::::::::::::::::::::
91  //:: AUXILIARY VARIABLES ::
92  //:::::::::::::::::::::::::
93 
95  // position and direction vectors of g
96  Amg::Vector3D b = h.positionVector(), v = h.directionVector();
97  // position and direction vectors of h
98  Amg::Vector3D n; // normal vector of plane spanned by g and h
99  Amg::Vector3D d; // distance vector
100 
101  //:::::::::::::
102  //:: PROGRAM ::
103  //:::::::::::::
104 
105  //::::::::::::::::::::::::
106  //:: collinearity check ::
107  //::::::::::::::::::::::::
108 
109  n = u.cross(v);
110  d = a - b;
111  if (n.dot(n) == 0.0) {
112  // straight lines are parallel
113  // no sign given
114  return std::sqrt(d.dot(d) - (u.unit().dot(d)) * (u.unit().dot(d)));
115  }
116 
117  return (d.dot(n.unit()));
118 }
119 
120 double MTStraightLine::distFromLine(const Amg::Vector3D& point) const {
121  //:::::::::::::::::::::::::
122  //:: AUXILIARY VARIABLES ::
123  //:::::::::::::::::::::::::
124 
126 
127  //::::::::::::::::::::::::
128  //:: CALCULATE DISTANCE ::
129  //::::::::::::::::::::::::
130 
131  return std::sqrt((point - m_position).dot(point - m_position) -
132  ((point - m_position).dot(u.unit())) * ((point - m_position).dot(u.unit())));
133 }
134 void MTStraightLine::setChi2(double chi2) { m_chi2 = std::isnan(chi2) ? -1 : chi2; }
135 double MTStraightLine::chi2() const { return m_chi2; }
136 void MTStraightLine::setNumberOfTrackHits(unsigned int n_hits) { m_numTrkHits = n_hits; }
137 unsigned int MTStraightLine::numberOfTrackHits() const { return m_numTrkHits; }
138 
139 double MTStraightLine::chi2PerDegreesOfFreedom() const { return m_chi2 / (m_numTrkHits > 2 ? m_numTrkHits - 2 : 0.01); }
140 
MuonCalib::MTStraightLine::MdtHitVec
MuonCalibSegment::MdtHitVec MdtHitVec
Definition: MTStraightLine.h:18
MuonCalib::MTStraightLine::a_x1
double a_x1() const
get the slope of the straight line in the x1-x3 plane
Definition: MTStraightLine.cxx:46
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonCalib::MTStraightLine::setChi2
void setChi2(double chi2)
Cache the chi2.
Definition: MTStraightLine.cxx:134
MuonCalib::MTStraightLine::m_numTrkHits
unsigned int m_numTrkHits
Definition: MTStraightLine.h:124
MuonCalib::MTStraightLine::m_direction
Amg::Vector3D m_direction
Definition: MTStraightLine.h:117
MuonCalib::MTStraightLine::positionError
Amg::Vector3D positionError() const
get the error on the position vector of the straight line
Definition: MTStraightLine.cxx:44
hist_file_dump.d
d
Definition: hist_file_dump.py:137
MTStraightLine.h
MuonCalib::MTStraightLine::a_x2
double a_x2() const
get the slope of the straight line in the x2-x3 plane
Definition: MTStraightLine.cxx:65
MuonCalib::MTStraightLine::directionVector
Amg::Vector3D directionVector() const
get the direction vector of the straight line
Definition: MTStraightLine.cxx:43
MuonCalib::MTStraightLine::b_x1_error
double b_x1_error() const
get the error on the intercept of the straight line in the x1-x3 plane
Definition: MTStraightLine.cxx:62
MuonCalib::MTStraightLine::pointOnLine
Amg::Vector3D pointOnLine(const double &lambda) const
get the point on the line for the given scale factor lambda, point=position_vector+lambda*direction_v...
Definition: MTStraightLine.cxx:87
MuonCalib::MTStraightLine::b_x1
double b_x1() const
get the intercept of the straight line in the x1-x3 plane
Definition: MTStraightLine.cxx:53
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonCalib::MTStraightLine::m_direction_error
Amg::Vector3D m_direction_error
Definition: MTStraightLine.h:121
MuonCalib::MTStraightLine::init
void init()
Definition: MTStraightLine.cxx:14
MuonCalib::MTStraightLine::a_x2_error
double a_x2_error() const
get the error on the slope of the straight line in the x2-x3 plane
Definition: MTStraightLine.cxx:66
MuonCalib::MTStraightLine::chi2PerDegreesOfFreedom
double chi2PerDegreesOfFreedom() const
Return chi2 / number of TrackHits - 2.
Definition: MTStraightLine.cxx:139
MuonCalib::MTStraightLine::a_x1_error
double a_x1_error() const
get the error on the slope of the straight line in the x1-x3 plane
Definition: MTStraightLine.cxx:48
MuonCalib::MTStraightLine::numberOfTrackHits
unsigned int numberOfTrackHits() const
Definition: MTStraightLine.cxx:137
MuonCalib::MTStraightLine::directionError
Amg::Vector3D directionError() const
get the error on the direction vector of the straight line
Definition: MTStraightLine.cxx:45
h
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArG4ShowerLibProcessing.hits
hits
Definition: LArG4ShowerLibProcessing.py:136
MuonCalib::MTStraightLine::m_chi2
double m_chi2
Definition: MTStraightLine.h:123
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::MTStraightLine::m_position
Amg::Vector3D m_position
Definition: MTStraightLine.h:116
MuonCalib::MTStraightLine::b_x2
double b_x2() const
get the intercept of the straight line in the x2-x3 plane
Definition: MTStraightLine.cxx:74
MuonCalib::MTStraightLine::chi2
double chi2() const
Definition: MTStraightLine.cxx:135
dot.dot
def dot(G, fn, nodesToHighlight=[])
Definition: dot.py:5
MuonCalib::MTStraightLine::m_position_error
Amg::Vector3D m_position_error
Definition: MTStraightLine.h:120
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
MuonCalib::MTStraightLine::signDistFrom
double signDistFrom(const MTStraightLine &h) const
get the signed distance of two lines (if both are parallel, dist>0)
Definition: MTStraightLine.cxx:89
MuonCalib::MTStraightLine::setUsedHits
void setUsedHits(const MdtHitVec &hits)
Definition: MTStraightLine.cxx:141
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.PyAthena.v
v
Definition: PyAthena.py:157
MuonCalib::MTStraightLine::distFromLine
double distFromLine(const Amg::Vector3D &point) const
get the distance of point point from straight line
Definition: MTStraightLine.cxx:120
a
TList * a
Definition: liststreamerinfos.cxx:10
MuonCalib::MTStraightLine::m_used_hits
MdtHitVec m_used_hits
Definition: MTStraightLine.h:125
MuonCalib::MTStraightLine::b_x2_error
double b_x2_error() const
get the slope of the intercept of the straight line in the x2-x3 plane
Definition: MTStraightLine.cxx:83
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::MTStraightLine
Definition: MTStraightLine.h:16
MuonCalib::MTStraightLine::trackHits
const MdtHitVec & trackHits() const
Definition: MTStraightLine.cxx:142
MuonCalib::MTStraightLine::positionVector
Amg::Vector3D positionVector() const
get the position vector of the straight line
Definition: MTStraightLine.cxx:42
MuonCalib::MTStraightLine::setNumberOfTrackHits
void setNumberOfTrackHits(unsigned int n_hits)
cache the number of track hits
Definition: MTStraightLine.cxx:136