ATLAS Offline Software
P4PxPyPzEBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <cmath>
7 #include <limits>
8 #include <iomanip>
9 #include <cstdlib>
10 
12 {}
13 
14 double P4PxPyPzEBase::m2() const
15 {
16  const double px=this->px();
17  const double py=this->py();
18  const double pz=this->pz();
19  const double e =this->e();
20 
21  const double m2 = e*e - (px*px + py*py + pz*pz);
22  return m2;
23 }
24 
25 double P4PxPyPzEBase::m() const
26 {
27  const double m2 = this->m2();
28 
29  return m2 < 0.0 ? -std::sqrt(-m2) : std::sqrt (m2);
30 }
31 
32 double P4PxPyPzEBase::eta() const
33 {
34  const double e=this->e();
35 
36  const double px=this->px();
37  const double py=this->py();
38  const double pz=this->pz();
39  // FIXME: should we use a more underflow-friendly formula:
40  // sqrt(a**2 + b**2)
41  // => y.sqrt(1+(x/y)**2) where y=max(|a|,|b|) and x=min(|a|,|b|)
42  const double p =std::sqrt (px*px + py*py + pz*pz);
43  if (p==0.0) return 0.0;
44  if (p==+pz) return +std::numeric_limits<double>::infinity();
45  if (p==-pz) return -std::numeric_limits<double>::infinity();
46  //PO flip if negative e
47  return (e>0 ? 1. : -1.)* 0.5*log((p+pz)/(p-pz));
48 }
49 
50 double P4PxPyPzEBase::phi() const
51 {
52  const double e=this->e();
53  const double px= (e>0 ? 1. : -1.)*this->px();
54  const double py= (e>0 ? 1. : -1.)*this->py();
55  return px == 0.0 && py == 0.0 ? 0.0 : atan2(py,px);
56 }
57 
58 
59 double P4PxPyPzEBase::p2() const
60 {
61  const double px=this->px();
62  const double py=this->py();
63  const double pz=this->pz();
64 
65  return px*px+py*py+pz*pz;
66 }
67 
68 double P4PxPyPzEBase::p() const
69 {
70  //PO return the correc
71  const double e=this->e();
72 
73  return (e>0 ? 1. : -1.)*std::sqrt(this->p2());
74 }
75 
76 
77 double P4PxPyPzEBase::cosPhi() const
78 {
79  return this->px()/this->pt();
80 }
81 
82 double P4PxPyPzEBase::sinPhi() const
83 {
84  return this->py()/this->pt();
85 }
86 
87 double P4PxPyPzEBase::tanTh() const
88 {
89  return this->pt()/this->pz();
90 }
91 
92 double P4PxPyPzEBase::cotTh() const
93 {
94  return this->pz()/this->pt();
95 }
96 
97 
98 double P4PxPyPzEBase::cosTh() const
99 {
100 
101  return this->pz()/this->p();
102 
103 }
104 
105 
106 double P4PxPyPzEBase::sinTh() const
107 {
108 
109  return this->pt()/this->p();
110 
111 }
112 
113 
114 double P4PxPyPzEBase::pt() const
115 {
116  const double e=this->e();
117  const double px=this->px();
118  const double py=this->py();
119  //PO flip sign if negative energy
120  return (e>0 ? 1. : -1.)*std::sqrt(px*px+py*py);
121 
122  }
123 
124 
125 double P4PxPyPzEBase::et() const
126  {
127  //to be improved
128  return this->e()*this->sinTh();
129  }
130 
131 double P4PxPyPzEBase::iPt() const
132  { return 1./this->pt();
133  }
134 
135 
137 {
138  const double e =this->e();
139  const double pz=this->pz();
140  if (e==0.0) return 0.0;
141  if (e==+pz) return +std::numeric_limits<double>::infinity();
142  if (e==-pz) return -std::numeric_limits<double>::infinity();
143  //PO invariant under flipping of 4-mom with neg E
144  return 0.5*std::log((e+pz)/(e-pz));
145 }
146 
147  CLHEP::HepLorentzVector P4PxPyPzEBase::hlv() const
148 { return CLHEP::HepLorentzVector(this->px(),this->py(),this->pz(),this->e());
149 
150 }
151 
152 std::ostream& P4PxPyPzEBase::dump( std::ostream& out ) const
153 {
154 
155  std::stringstream outx;
156  outx << "[px,py,pz,e] ="
157  << std::right << std::scientific << std::setprecision(8)
158  << std::setw(16) << this->px()
159  << std::setw(16) << this->py()
160  << std::setw(16) << this->pz()
161  << std::setw(16) << this->e();
162 
163  out<<outx.str();
164 
165  return out;
166 
167 }
168 
170 {
171  return 0;
172 }
173 
174 
176 {
177  std::cout << "FATAL ERROR dummy P4PxPyPzEBase::set4Mom called " << std::endl ;
178  std::abort();
179 }
180 
181 void P4PxPyPzEBase::set4Mom(const I4Momentum * const )
182 {
183  std::cout << "FATAL ERROR dummy P4PxPyPzEBase::set4Mom called " << std::endl ;
184  std::abort();
185 
186 }
187 
188 void P4PxPyPzEBase::set4Mom(const CLHEP::HepLorentzVector & )
189 {
190  std::cout << "FATAL ERROR dummy P4PxPyPzEBase::set4Mom called " << std::endl ;
191  std::abort();
192 }
193 
I4Momentum::py
virtual double py() const =0
y component of momentum
I4Momentum
Definition: I4Momentum.h:31
P4PxPyPzEBase::p
virtual double p() const
momentum magnitude
Definition: P4PxPyPzEBase.cxx:68
P4PxPyPzEBase::errors
virtual const I4MomentumError * errors() const
Access to errors, if available; returns 0 if no errors.
Definition: P4PxPyPzEBase.cxx:169
P4PxPyPzEBase::eta
virtual double eta() const
pseudo rapidity
Definition: P4PxPyPzEBase.cxx:32
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
P4PxPyPzEBase::et
virtual double et() const
transverse energy defined to be e*sin(theta)
Definition: P4PxPyPzEBase.cxx:125
P4PxPyPzEBase::sinTh
virtual double sinTh() const
sinus theta
Definition: P4PxPyPzEBase.cxx:106
P4PxPyPzEBase::~P4PxPyPzEBase
virtual ~P4PxPyPzEBase()
virtual destructor needed by pool
Definition: P4PxPyPzEBase.cxx:11
P4PxPyPzEBase::p2
virtual double p2() const
square of momentum magnitude
Definition: P4PxPyPzEBase.cxx:59
I4Momentum::pz
virtual double pz() const =0
z component of momentum
P4PxPyPzEBase::m
virtual double m() const
mass
Definition: P4PxPyPzEBase.cxx:25
I4MomentumError
Definition: I4MomentumError.h:28
I4Momentum::e
virtual double e() const =0
energy
P4PxPyPzEBase::cosPhi
virtual double cosPhi() const
cosinus phi
Definition: P4PxPyPzEBase.cxx:77
P4PxPyPzEBase::pt
virtual double pt() const
transverse momentum
Definition: P4PxPyPzEBase.cxx:114
P4PxPyPzEBase::cosTh
virtual double cosTh() const
cosinus theta
Definition: P4PxPyPzEBase.cxx:98
P4PxPyPzEBase.h
P4PxPyPzEBase::rapidity
virtual double rapidity() const
rapidity
Definition: P4PxPyPzEBase.cxx:136
P4PxPyPzEBase::iPt
virtual double iPt() const
inverse of transverse momentum
Definition: P4PxPyPzEBase.cxx:131
P4PxPyPzEBase::tanTh
virtual double tanTh() const
tan theta
Definition: P4PxPyPzEBase.cxx:87
P4PxPyPzEBase::hlv
virtual CLHEP::HepLorentzVector hlv() const
CLHEP HepLorentzVector.
Definition: P4PxPyPzEBase.cxx:147
P4PxPyPzEBase::cotTh
virtual double cotTh() const
cottan theta
Definition: P4PxPyPzEBase.cxx:92
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
P4PxPyPzEBase::sinPhi
virtual double sinPhi() const
sinus phi
Definition: P4PxPyPzEBase.cxx:82
P4PxPyPzEBase::phi
virtual double phi() const
phi in [-pi,pi[
Definition: P4PxPyPzEBase.cxx:50
P4PxPyPzEBase::m2
virtual double m2() const
mass squared
Definition: P4PxPyPzEBase.cxx:14
P4PxPyPzEBase::set4Mom
virtual void set4Mom(const I4Momentum &theI4Mom)
set all 4-mom from another I4Momentum reference DUMMY IMPLEMENTATION
Definition: P4PxPyPzEBase.cxx:175
P4PxPyPzEBase::dump
virtual std::ostream & dump(std::ostream &out) const
Print I4Momentum content.
Definition: P4PxPyPzEBase.cxx:152
I4Momentum::px
virtual double px() const =0
x component of momentum