ATLAS Offline Software
Loading...
Searching...
No Matches
FPTracker/src/Point.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "FPTracker/Point.h"
7#include <sstream>
8#include <cmath>
9#include <stdexcept>
10#include <iomanip>
11namespace FPTracker{
12 Point::Point():m_x(0.), m_y(0.), m_z(0.){
13 }
14 Point::Point(double x, double y, double z):m_x(x), m_y(y), m_z(z){
15 }
16
17 double Point::x() const {return m_x;}
18 double Point::y() const {return m_y;}
19 double Point::z() const {return m_z;}
20
21 double Point::perp2() const {return m_x*m_x+m_y*m_y;}
22
23 TransversePoint Point::transverse() const {return TransversePoint(m_x, m_y);}
24
25 Point& Point::operator*=(double scalar) {
26 m_x *= scalar;
27 m_y *= scalar;
28 m_z *= scalar;
29 return *this;
30 }
31
32 double Point::mag2() const {return m_x*m_x+m_y*m_y+m_z*m_z;}
33
34 double Point::mag() const {
35 return std::sqrt(mag2());
36 }
37
38 double Point::operator[](unsigned int i) const {
39
40 if ( i>2 )
41 {
42 std::ostringstream ost;
43 ost<<"TranversePoint index out of range: "<<i<<'\n';
44 throw std::range_error(ost.str());
45 }
46
47 if(i == 0){return m_x;}
48 if(i == 1){return m_y;}
49 return m_z;
50 }
51
52 double& Point::operator[](unsigned int i){
53
54 if ( i>2 )
55 {
56 std::ostringstream ost;
57 ost<<"TranversePoint index out of range: "<<i<<'\n';
58 throw std::range_error(ost.str());
59 }
60
61 if(i == 0){return m_x;}
62 if(i == 1){return m_y;}
63 return m_z;
64 }
65
66 Point& Point::operator+=(const Point& rhs){
67 m_x += rhs.m_x;
68 m_y += rhs.m_y;
69 m_z += rhs.m_z;
70 return *this;
71 }
72
73 Point& Point::operator-=(const Point& rhs){
74 m_x -= rhs.m_x;
75 m_y -= rhs.m_y;
76 m_z -= rhs.m_z;
77 return *this;
78 }
79
80 Point& Point::operator+=(const TransversePoint& rhs){
81 m_x += rhs.x();
82 m_y += rhs.y();
83 return *this;
84 }
85
86 Point& Point::operator-=(const TransversePoint& rhs){
87 m_x -= rhs.x();
88 m_y -= rhs.y();
89 return *this;
90 }
91
92 std::string Point::str() const{
93 std::ostringstream ost;
94 ost<<std::setprecision(3)<<std::scientific<<"x\t"<<m_x<<" y\t"<<m_y<<" z\t"<<m_z;
95 return ost.str();
96 }
97
98 Point operator+(const Point& lhs, const Point& rhs){
99 Point point(lhs);
100 return point += rhs;
101 }
102
103 Point operator-(const Point& lhs, const Point& rhs){
104 Point point(lhs);
105 return point -= rhs;
106 }
107
108 Point operator+(const Point& lhs, const TransversePoint& rhs){
109 Point point(lhs);
110 return point += rhs;
111 }
112
113 Point operator-(const Point& lhs, const TransversePoint& rhs){
114 Point point(lhs);
115 return point -= rhs;
116 }
117
118 std::ostream& operator<<(std::ostream& os, const Point& p){
119 os<<p.str();
120 return os;
121 }
122
123 Point operator*(double scalar, const Point& point) {
124 Point p = point;
125 return p*=scalar;
126 }
127
128
129}
Point operator-(const Point &lhs, const Point &rhs)
Point operator+(const Point &lhs, const Point &rhs)
Point operator*(double, const Point &lhs)
std::ostream & operator<<(std::ostream &os, const Beamline &bl)
Point(double x_, double y_, double slope_)
Single point and slope to next point.