18 #include "MathUtils.h"
24 #include "ExHEPUtils/Vectors.h"
50 : _x(0), _y(0), _z(0) { }
59 : _x(v._x), _y(v._y), _z(v._z) { }
87 static P3 mkXY(
double px,
double py) {
98 return P3().setEtaPhiPt(
eta,
phi, pt);
162 throw std::invalid_argument(
"Negative momentum given as argument");
163 const double theta = 2 * atan(exp(-
eta));
164 if (theta < 0 || theta > M_PI)
165 throw std::domain_error(
"Polar angle outside 0..pi in calculation");
177 throw std::invalid_argument(
"Negative transverse momentum given as argument");
178 const double theta = 2 * atan(exp(-
eta));
179 if (theta < 0 || theta > M_PI)
180 throw std::domain_error(
"Polar angle outside 0..pi in calculation");
181 const double p = pt / sin(
theta);
193 if (theta < 0 || theta > M_PI)
194 throw std::invalid_argument(
"Polar angle outside 0..pi given as argument");
197 throw std::invalid_argument(
"Negative momentum given as argument");
200 const double pt =
p * sin(
theta);
202 throw std::invalid_argument(
"Negative transverse momentum in calculation");
203 const double px = pt * cos(
phi);
204 const double py = pt * sin(
phi);
216 if (theta < 0 || theta > M_PI)
217 throw std::invalid_argument(
"Polar angle outside 0..pi given as argument");
219 throw std::invalid_argument(
"Negative transverse momentum given as argument");
220 const double p = pt / sin(
theta);
221 const double px = pt * cos(
phi);
222 const double py = pt * sin(
phi);
238 double px()
const {
return _x; }
242 double py()
const {
return _y; }
246 double pz()
const {
return _z; }
248 double X()
const {
return _x; }
250 double Y()
const {
return _y; }
252 double Z()
const {
return _z; }
259 double p()
const {
return sqrt(p2()); }
262 double Perp2()
const {
return sqr(
px()) +
sqr(
py()); }
265 double Perp()
const {
return sqrt(Perp2()); }
267 double pT2()
const {
return Perp2(); }
269 double pT()
const {
return Perp(); }
274 double phi()
const {
if (Perp2() == 0)
return 0;
else return atan2(
py(),
px()); }
276 double theta()
const {
if (p2() == 0)
return 0;
else if (
pz() == 0)
return M_PI;
else return atan2(
rho(),
pz()); }
278 double eta()
const {
return -log(tan( 0.5 *
theta() )); }
293 double Dot(
const P3& v)
const {
return px()*v.
px() +
py()*v.
py() +
pz()*v.
pz(); }
297 double Angle(
const P3& v)
const {
return acos(
dot3(v) /
p()/v.
p() ); }
315 double Mag()
const {
return p();}
316 double Mag2()
const {
return p2();}
317 double Theta()
const {
return theta();}
318 double Phi()
const {
return phi();}
320 double CosTheta()
const {
double pp =
p();
if (pp == 0.0)
return 0.0;
else return pz()/pp; }
342 P3& Rotate(
const double &
angle,
const P3& axis) {
343 P3 unitaxis=axis.Unit();
344 double costheta=cos(
angle);
345 double sintheta=sin(
angle);
347 double axismultiplier=Dot(unitaxis)*(1.0 - costheta);
348 setPx(
px()*costheta+kcrossv.px()*sintheta+unitaxis.px()*axismultiplier);
349 setPy(
py()*costheta+kcrossv.py()*sintheta+unitaxis.py()*axismultiplier);
350 setPz(
pz()*costheta+kcrossv.pz()*sintheta+unitaxis.pz()*axismultiplier);
365 P3 operator - ()
const {
P3 rtn;
return rtn.setP(-_x, -_y, -_z); }
366 P3& operator += (
const P3& v) { _x += v.px(); _y += v.py(); _z += v.pz() ;
return *
this; }
367 P3& operator -= (
const P3& v) { _x -= v.px(); _y -= v.py(); _z -= v.pz() ;
return *
this; }
368 P3& operator *= (
double a) { _x *= a; _y *= a; _z *= a;
return *
this; }
369 P3& operator /= (
double a) { _x /= a; _y /= a; _z /= a;
return *
this; }
381 std::stringstream ss;
382 ss <<
"(" << p3.
px() <<
", " << p3.
py() <<
", " << p3.
pz() <<
")";
439 inline P3 operator + (
const P3& a,
const P3& b) { P3 rtn = a;
return rtn += b; }
440 inline P3 operator - (
const P3& a,
const P3& b) { P3 rtn = a;
return rtn -= b; }
441 inline P3 operator * (
const P3& a,
double f) { P3 rtn = a;
return rtn *= f; }
442 inline P3 operator * (
double f,
const P3& a) { P3 rtn = a;
return rtn *= f; }
443 inline P3 operator / (
const P3& a,
double f) { P3 rtn = a;
return rtn /= f; }
Definition: Vectors3.h:34
double deltaR_eta(const P3 &v) const
Difference in pseudorapidity-based R between two vectors.
Definition: Vectors3.h:305
P3 & setThetaPhiP(double theta, double phi, double p)
Definition: Vectors3.h:192
double rho2() const
Get the spatial 3-vector |px^2 + py^2|.
Definition: Vectors3.h:261
P3(double px, double py, double pz)
Constructor from Cartesian/Minkowski coordinates.
Definition: Vectors3.h:53
double deltaR2_eta(const P3 &v) const
Difference in rapidity between two vectors.
Definition: Vectors3.h:303
double pT2() const
Get the transverse momentum squared (same as rho2)
Definition: Vectors3.h:267
P3 & setThetaPhiPt(double theta, double phi, double pt)
Definition: Vectors3.h:215
P3 & setXY(double px, double py)
set only transverse components
Definition: Vectors3.h:149
P3 & setP(double px, double py, double pz)
Set the p coordinates and mass simultaneously.
Definition: Vectors3.h:138
P3 & setPx(double px)
Set the px coordinate.
Definition: Vectors3.h:119
double angleTo(const P3 &v) const
Spatial angle to another P4 vector.
Definition: Vectors3.h:296
double pz() const
Get pz.
Definition: Vectors3.h:246
double px() const
Get px.
Definition: Vectors3.h:238
P3()
Default constructor of a null vector.
Definition: Vectors3.h:49
P3 & setEtaPhiPt(double eta, double phi, double pt)
Definition: Vectors3.h:174
double Z() const
Get pz^2.
Definition: Vectors3.h:252
double abseta() const
Get the spatial vector absolute pseudorapidity.
Definition: Vectors3.h:280
double dot3(const P3 &v) const
Spatial dot product.
Definition: Vectors3.h:291
double pT() const
Get the transverse momentum (same as rho)
Definition: Vectors3.h:269
double py() const
Get py.
Definition: Vectors3.h:242
P3 & setEtaPhiP(double eta, double phi, double P)
Definition: Vectors3.h:159
double deltaPhi(const P3 &v) const
Difference in phi between two vectors.
Definition: Vectors3.h:299
static P3 mkEtaPhiP(double eta, double phi, double P)
Make a vector from (eta,phi,p) coordinates.
Definition: Vectors3.h:92
double phi() const
Get the spatial phi.
Definition: Vectors3.h:274
static P3 mkThetaPhiPt(double theta, double phi, double pt)
Make a vector from (theta,phi,pT) coordinates and the mass.
Definition: Vectors3.h:107
static P3 mkThetaPhiP(double theta, double phi, double P)
Make a vector from (theta,phi,energy) coordinates and the mass.
Definition: Vectors3.h:102
double py2() const
Get py^2.
Definition: Vectors3.h:240
double p() const
Get the spatial 3-vector |p|.
Definition: Vectors3.h:259
P3 & setPy(double py)
Set the py coordinate.
Definition: Vectors3.h:125
double pz2() const
Get pz^2.
Definition: Vectors3.h:244
double deltaEta(const P3 &v) const
Difference in pseudorapidity between two vectors.
Definition: Vectors3.h:301
P3(const P3 &v)
Copy constructor.
Definition: Vectors3.h:58
P3 Cross(const P3 &v) const
Difference in rapidity-based R^2 between two vectors.
Definition: Vectors3.h:309
double theta() const
Get the spatial theta.
Definition: Vectors3.h:276
P3 & SetXYZ(double px, double py, double pz)
Alias for setP.
Definition: Vectors3.h:144
double Y() const
Get py^2.
Definition: Vectors3.h:250
double eta() const
Get the spatial vector pseudorapidity.
Definition: Vectors3.h:278
static P3 mkXYZ(double px, double py, double pz)
Make a vector from (px,py,pz,E) coordinates.
Definition: Vectors3.h:83
P3 & setPz(double pz)
Set the pz coordinate.
Definition: Vectors3.h:131
P3 & operator=(const P3 &v)
Copy assignment operator.
Definition: Vectors3.h:62
static P3 mkEtaPhiPt(double eta, double phi, double pt)
Make a vector from (eta,phi,pT) coordinates.
Definition: Vectors3.h:97
double px2() const
Get px^2.
Definition: Vectors3.h:236
void clear()
Set the components to zero.
Definition: Vectors3.h:70
double rho() const
Get the spatial 3-vector sqrt|px^2 + py^2|.
Definition: Vectors3.h:264
Modified by Mark Goodsell goodsell@lpthe.jussieu.fr
Definition: ATLAS_SUSY_2018_16.cc:27
std::string to_str(const P4 &p4)
Make a string representation of the vector.
Definition: Vectors.h:565
double deltaR2_eta(const P4 &a, const P4 &b)
Difference in pseudorapidity-based R^2 between two vectors.
Definition: Vectors.h:614
double deltaR_eta(const P4 &a, const P4 &b)
Difference in pseudorapidity-based R between two vectors.
Definition: Vectors.h:618
std::ostream & operator<<(std::ostream &ostr, const P4 &p4)
Write a string representation of the vector to the provided stream.
Definition: Vectors.h:572
double deltaEta(const P4 &a, const P4 &b)
Difference in pseudorapidity between two vectors.
Definition: Vectors.h:602
double deltaPhi(const P4 &a, const P4 &b)
Difference in phi between two vectors.
Definition: Vectors.h:596
constexpr std::enable_if< std::is_arithmetic< N1 >::value, N1 >::type sqr(const N1 val)
Convenience function for squaring (better than repeating long expressions/calcs or using intermediate...
Definition: MathUtils.h:45
double Dot(const P3 &a, const P3 &b)
Convenience "external" functions.
Definition: Vectors3.h:399
double angle(const P4 &a, const P4 &b)
Angle between two vectors.
Definition: Vectors.h:590