ATLAS Offline Software
P4BasePtEtaPhiM.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef FOURMOM_P4BASEPTETAPHIM_H
8 #define FOURMOM_P4BASEPTETAPHIM_H
9 
10 // STL includes
11 #include <cmath>
12 #include <sstream>
13 #include <ostream>
14 #include <iomanip>
15 
16 // CLHEP includes
17 #include "CLHEP/Vector/LorentzVector.h"
18 #include "CLHEP/Units/SystemOfUnits.h"
19 
33 {
34  public:
35 
37  virtual ~P4BasePtEtaPhiM();
38 
40  // Const methods:
42 
46  double px() const;
47  double py() const;
48  double pz() const;
49  virtual double m() const = 0;
50  double m2() const;
51  double p() const;
52  double p2() const;
53  virtual double eta() const = 0;
54  virtual double phi() const = 0;
55  double e() const;
56  double et() const;
57  virtual double pt() const = 0;
58  double iPt() const;
59  double rapidity() const;
60  double cosPhi() const;
61  double sinPhi() const;
62  double tanTh() const;
63  double cosTh() const;
64  double sinTh() const;
65  double cotTh() const;
66  CLHEP::HepLorentzVector hlv() const;
67 
69  std::ostream& dump( std::ostream& out ) const;
70 
74  // Not in @c I4Momentum interface
75  // double tanTh() const;
76 
78  // Non-const methods:
80 
82  // Private data:
84  private:
85 
86 };
87 
89 // Inline methods:
91 
93 {}
94 
95 inline double P4BasePtEtaPhiM::px() const
96 {
97  return this->pt() * std::cos(this->phi());
98 }
99 
100 inline double P4BasePtEtaPhiM::py() const
101 {
102  return this->pt() * std::sin(this->phi());
103 }
104 
105 inline double P4BasePtEtaPhiM::pz() const
106 {
107  return this->pt()/this->tanTh();
108 }
109 
110 inline double P4BasePtEtaPhiM::m2() const
111 {
112  const double mass = this->m();
113  return mass*mass;
114 }
115 
116 inline double P4BasePtEtaPhiM::p() const
117 {
118  const double thePt = this->pt();
119  const double thePz = this->pz();
120 
121  //DR from Frank Paige
122  // if negative pt point in the opposite direction
123  // BUT eta and phi still the same !!!
124 
125  const double eSign = (thePt >= 0.) ? +1. : -1.;
126  return eSign * std::sqrt( thePt*thePt + thePz*thePz );
127 }
128 
129 inline double P4BasePtEtaPhiM::p2() const
130 {
131  // This method has been implemented so as to give the same as would be
132  // obtained from pow((this->p()),2) with this->p() implemented according to
133  // Frank Paige's algorithm above.
134 
135  const double pt = this->pt();
136  const double pz = this->pz();
137 
138  return pt*pt + pz*pz;
139 }
140 
141 inline double P4BasePtEtaPhiM::e() const
142 {
143  const double theMass = this->m();
144  const double thePt = this->pt();
145  const double thePz = this->pz();
146 
147  //DR from Frank Paige
148  // if negative pt point in the opposite direction
149  // BUT eta and phi still the same !!!
150 
151  const double eSign = (thePt >= 0.) ? +1. : -1.;
152  return eSign * std::sqrt( thePt*thePt + thePz*thePz + theMass*theMass);
153 }
154 
155 inline double P4BasePtEtaPhiM::et() const
156 {
157  return this->e()*this->sinTh();
158 }
159 
160 inline double P4BasePtEtaPhiM::iPt() const
161 {
162  return 1./this->pt();
163 }
164 
165 inline double P4BasePtEtaPhiM::rapidity() const
166  {
167  const double theE=this->e();
168  const double thePz=this->pz();
169  return 0.5*std::log((theE+thePz)/(theE-thePz));
170  }
171 
172 inline double P4BasePtEtaPhiM::cosPhi() const
173 {
174  return std::cos(this->phi());
175 }
176 
177 inline double P4BasePtEtaPhiM::sinPhi() const
178 {
179  return std::sin(this->phi());
180 }
181 
182 
183 
184 inline double P4BasePtEtaPhiM::cosTh() const
185 {
186  return std::tanh(this->eta());
187 }
188 
189 inline double P4BasePtEtaPhiM::sinTh() const
190 {
191  // avoid numeric overflow if very large eta
192 
193  double aEta=std::abs(this->eta());
194  if ( aEta>710) {
195  aEta=710;
196  }
197 
198  return 1./std::cosh(aEta);
199 }
200 
201 inline double P4BasePtEtaPhiM::cotTh() const
202 {
203  return std::sinh(this->eta());
204 }
205 
206 inline double P4BasePtEtaPhiM::tanTh() const
207 {
208  return 1./std::sinh(this->eta());
209 }
210 
211 // less efficient
212 //inline double P4BasePtEtaPhiM::tanTh() const
213 //{
214 // return std::tan( 2.* std::atan( std::exp( -(this->eta()) ) ) );
215 //}
216 
217 inline CLHEP::HepLorentzVector P4BasePtEtaPhiM::hlv() const
218 {
219  //minimize the number of calculation and dereference
220  const double theM = this->m();
221  // note that pt can have negative sign : then it points in opposite direction but eta and phi are still on the same side
222  const double thePt = this->pt();
223 
224 
225  const double thePx = thePt*this->cosPhi();
226  const double thePy = thePt*this->sinPhi();
227 
228  const double thePz = thePt*this->cotTh();
229 
230  const double theE=std::sqrt(thePt*thePt+thePz*thePz+theM*theM);
231 
232 
233  return CLHEP::HepLorentzVector( thePx, thePy, thePz, theE );
234 }
235 
236 inline std::ostream& P4BasePtEtaPhiM::dump( std::ostream& out ) const
237 {
238  std::stringstream s;
239  s << "[pt,eta,phi,m] ="
240  << std::right << std::scientific << std::setprecision(8)
241  << std::setw(16) << this->pt()
242  << std::setw(16) << this->eta()
243  << std::setw(16) << this->phi()
244  << std::setw(16) << this->m();
245 
246  out << s.str();
247  return out;
248 }
249 
250 #endif
P4BasePtEtaPhiM::cotTh
double cotTh() const
Definition: P4BasePtEtaPhiM.h:201
P4BasePtEtaPhiM::p
double p() const
Definition: P4BasePtEtaPhiM.h:116
P4BasePtEtaPhiM::m
virtual double m() const =0
P4BasePtEtaPhiM::cosTh
double cosTh() const
Definition: P4BasePtEtaPhiM.h:184
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
P4BasePtEtaPhiM::~P4BasePtEtaPhiM
virtual ~P4BasePtEtaPhiM()
virtual destructor needed for inheritance
Definition: P4BasePtEtaPhiM.h:92
P4BasePtEtaPhiM::px
double px() const
{@ a la I4Momentum -like interface
Definition: P4BasePtEtaPhiM.h:95
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
P4BasePtEtaPhiM::e
double e() const
Definition: P4BasePtEtaPhiM.h:141
P4BasePtEtaPhiM::sinPhi
double sinPhi() const
Definition: P4BasePtEtaPhiM.h:177
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
P4BasePtEtaPhiM::hlv
CLHEP::HepLorentzVector hlv() const
Definition: P4BasePtEtaPhiM.h:217
P4BasePtEtaPhiM::tanTh
double tanTh() const
Definition: P4BasePtEtaPhiM.h:206
P4BasePtEtaPhiM::py
double py() const
Definition: P4BasePtEtaPhiM.h:100
P4BasePtEtaPhiM::cosPhi
double cosPhi() const
Definition: P4BasePtEtaPhiM.h:172
P4BasePtEtaPhiM::phi
virtual double phi() const =0
P4BasePtEtaPhiM::p2
double p2() const
Definition: P4BasePtEtaPhiM.h:129
P4BasePtEtaPhiM::rapidity
double rapidity() const
Definition: P4BasePtEtaPhiM.h:165
P4BasePtEtaPhiM::dump
std::ostream & dump(std::ostream &out) const
Print I4Momentum content.
Definition: P4BasePtEtaPhiM.h:236
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
P4BasePtEtaPhiM::pt
virtual double pt() const =0
P4BasePtEtaPhiM::et
double et() const
Definition: P4BasePtEtaPhiM.h:155
P4BasePtEtaPhiM::iPt
double iPt() const
Definition: P4BasePtEtaPhiM.h:160
P4BasePtEtaPhiM
Definition: P4BasePtEtaPhiM.h:33
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
P4BasePtEtaPhiM::sinTh
double sinTh() const
Definition: P4BasePtEtaPhiM.h:189
P4BasePtEtaPhiM::m2
double m2() const
Definition: P4BasePtEtaPhiM.h:110
P4BasePtEtaPhiM::pz
double pz() const
Definition: P4BasePtEtaPhiM.h:105
P4BasePtEtaPhiM::eta
virtual double eta() const =0