ATLAS Offline Software
P4BaseEEtaPhiM.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_P4BASEEETAPHIM_H
8 #define FOURMOM_P4BASEEETAPHIM_H
9 
10 // STL includes
11 #include <cmath>
12 #include <ostream>
13 #include <sstream>
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 ~P4BaseEEtaPhiM();
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 rapidity() const;
52  double p() const;
53  double p2() const;
54  virtual double eta() const = 0;
55  virtual double phi() const = 0;
56  virtual double e() const = 0;
57  double et() const;
58  double pt() const;
59  double iPt() const;
60  double sinPhi() const;
61  double cosPhi() 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;
73  // Non-const methods:
76 
78  // Protected data:
80  private:
81 };
82 
84 // Inline methods:
86 
88 {}
89 
90 inline double P4BaseEEtaPhiM::px() const
91 {
92  return this->pt()*cos(this->phi());
93 }
94 
95 inline double P4BaseEEtaPhiM::py() const
96 {
97  return this->pt()*sin(this->phi());
98 }
99 
100 inline double P4BaseEEtaPhiM::pz() const
101 {
102  return this->p()*this->cosTh();
103 }
104 
105 inline double P4BaseEEtaPhiM::m2() const
106 {
107  const double mass = this->m();
108  return mass*mass;
109 }
110 
111 inline double P4BaseEEtaPhiM::p() const
112 {
113  const double theM=this->m();
114  const double theE=this->e();
115  // if (theM==0.) return theE ;
116  // else return sqrt(theE*theE-theM*theM);
117  //DR from Frank Paige
118  // if negative energy point in the opposite direction
119  // BUT eta and phi still the same !!!
120  if (theM==0.) {
121  return theE;
122  } else {
123  double eSign = (theE >= 0.) ? +1. : -1.;
124  return eSign*std::sqrt(theE*theE-theM*theM);
125  }
126 
127 }
128 
129 inline double P4BaseEEtaPhiM::p2() const
130 {
138  const double mass = this->m();
139  const double ene = this->e();
140 
141  return ene*ene - mass*mass;
142 }
143 
144 inline double P4BaseEEtaPhiM::et() const
145 {
146  return this->e()*this->sinTh();
147 }
148 
149 inline double P4BaseEEtaPhiM::rapidity() const
150  {
151  const double theE=this->e();
152  const double thePz=this->pz();
153  return 0.5*std::log((theE+thePz)/(theE-thePz));
154  }
155 
156 inline double P4BaseEEtaPhiM::pt() const
157 {
158  return this->p()*this->sinTh();
159 }
160 
161 inline double P4BaseEEtaPhiM::iPt() const
162 {
163  return 1./this->pt();
164 }
165 
166 inline double P4BaseEEtaPhiM::cosPhi() const
167 {
168  return std::cos(this->phi());
169 }
170 
171 inline double P4BaseEEtaPhiM::sinPhi() const
172 {
173  return std::sin(this->phi());
174 }
175 
176 
177 inline double P4BaseEEtaPhiM::tanTh() const
178 {
179  double theEta=this->eta();
180  if ( std::abs(theEta)>710) {
181  theEta=theEta>0 ? 710 : -710;
182  return 1./std::sinh(theEta);
183  }
184  return 1./this->cotTh();
185 }
186 
187 inline double P4BaseEEtaPhiM::cosTh() const
188 {
189  return std::tanh(this->eta());
190 }
191 
192 inline double P4BaseEEtaPhiM::sinTh() const
193 {
194  // avoid numeric overflow if very large eta
195 
196  double aEta=std::abs(this->eta());
197  if ( aEta>710) {
198  aEta=710;
199  }
200 
201  return 1./std::cosh(aEta);
202 }
203 
204 inline double P4BaseEEtaPhiM::cotTh() const
205 {
206  return std::sinh(this->eta());
207 }
208 
209 inline CLHEP::HepLorentzVector P4BaseEEtaPhiM::hlv() const
210 {
211  //minimize the number of calculation and dereference
212  const double theE = this->e();
213  const double theCosTh = this->cosTh();
214 
215  // DR from Frank Paige
216  // negative energy point in opposite direction
217  // BUT Eta and Phi still the same
218  // double theP=theE;
219 
220  const double theP = this->p();
221 
222  const double theSinTh = std::sqrt(1.-theCosTh*theCosTh);
223  const double thePt = theP*theSinTh;
224  const double thePx = thePt*this->cosPhi();
225  const double thePy = thePt*this->sinPhi();
226  const double thePz = theP*theCosTh;
227 
228  return CLHEP::HepLorentzVector(thePx,thePy,thePz,theE);
229 }
230 
231 inline std::ostream& P4BaseEEtaPhiM::dump( std::ostream& out ) const
232 {
233  std::stringstream s;
234  s << "[e,eta,phi,m] ="
235  << std::right << std::scientific << std::setprecision(8)
236  << std::setw(16) << this->e()
237  << std::setw(16) << this->eta()
238  << std::setw(16) << this->phi()
239  << std::setw(16) << this->m();
240 
241  out << s.str();
242  return out;
243 
244 }
245 
246 
247 #endif // FOURMOM_P4BASEEETAPHIM_H
248 
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
P4BaseEEtaPhiM::iPt
double iPt() const
Definition: P4BaseEEtaPhiM.h:161
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
P4BaseEEtaPhiM::cotTh
double cotTh() const
Definition: P4BaseEEtaPhiM.h:204
P4BaseEEtaPhiM::p
double p() const
Definition: P4BaseEEtaPhiM.h:111
P4BaseEEtaPhiM::py
double py() const
Definition: P4BaseEEtaPhiM.h:95
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
P4BaseEEtaPhiM::sinTh
double sinTh() const
Definition: P4BaseEEtaPhiM.h:192
P4BaseEEtaPhiM::sinPhi
double sinPhi() const
Definition: P4BaseEEtaPhiM.h:171
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
P4BaseEEtaPhiM::et
double et() const
Definition: P4BaseEEtaPhiM.h:144
P4BaseEEtaPhiM::m
virtual double m() const =0
P4BaseEEtaPhiM::rapidity
double rapidity() const
Definition: P4BaseEEtaPhiM.h:149
P4BaseEEtaPhiM::hlv
CLHEP::HepLorentzVector hlv() const
Definition: P4BaseEEtaPhiM.h:209
P4BaseEEtaPhiM::tanTh
double tanTh() const
Definition: P4BaseEEtaPhiM.h:177
P4BaseEEtaPhiM::~P4BaseEEtaPhiM
virtual ~P4BaseEEtaPhiM()
virtual destructor needed for inheritance
Definition: P4BaseEEtaPhiM.h:87
P4BaseEEtaPhiM::cosPhi
double cosPhi() const
Definition: P4BaseEEtaPhiM.h:166
P4BaseEEtaPhiM::eta
virtual double eta() const =0
P4BaseEEtaPhiM::m2
double m2() const
Definition: P4BaseEEtaPhiM.h:105
P4BaseEEtaPhiM::p2
double p2() const
Definition: P4BaseEEtaPhiM.h:129
P4BaseEEtaPhiM
Definition: P4BaseEEtaPhiM.h:33
P4BaseEEtaPhiM::px
double px() const
{@ a la I4Momentum -like interface
Definition: P4BaseEEtaPhiM.h:90
P4BaseEEtaPhiM::cosTh
double cosTh() const
Definition: P4BaseEEtaPhiM.h:187
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
P4BaseEEtaPhiM::e
virtual double e() const =0
P4BaseEEtaPhiM::pz
double pz() const
Definition: P4BaseEEtaPhiM.h:100
P4BaseEEtaPhiM::pt
double pt() const
Definition: P4BaseEEtaPhiM.h:156
P4BaseEEtaPhiM::dump
std::ostream & dump(std::ostream &out) const
Print I4Momentum content.
Definition: P4BaseEEtaPhiM.h:231
P4BaseEEtaPhiM::phi
virtual double phi() const =0
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36