File indexing completed on 2025-01-18 10:01:11
0001
0002
0003
0004
0005
0006 #ifndef HEPMC3_FOURVECTOR_H
0007 #define HEPMC3_FOURVECTOR_H
0008
0009
0010
0011
0012 #include <cmath>
0013 #include <limits>
0014 #ifndef M_PI
0015
0016 #define M_PI 3.14159265358979323846264338327950288
0017 #endif
0018 namespace HepMC3 {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 class FourVector {
0037 public:
0038
0039
0040 FourVector()
0041 : m_v1(0.0), m_v2(0.0), m_v3(0.0), m_v4(0.0) {}
0042
0043 FourVector(double xx, double yy, double zz, double ee)
0044 : m_v1(xx), m_v2(yy), m_v3(zz), m_v4(ee) {}
0045
0046 FourVector(const FourVector &) = default;
0047
0048 FourVector(FourVector && ) = default;
0049
0050 FourVector& operator=(const FourVector&) = default;
0051
0052 FourVector& operator=(FourVector&&) = default;
0053
0054
0055
0056
0057
0058 void set(double x1, double x2, double x3, double x4) {
0059 m_v1 = x1;
0060 m_v2 = x2;
0061 m_v3 = x3;
0062 m_v4 = x4;
0063 }
0064
0065
0066 void set_component(const int i, const double x)
0067 {
0068 if (i==0) {m_v1=x; return; }
0069 if (i==1) {m_v2=x; return; }
0070 if (i==2) {m_v3=x; return; }
0071 if (i==3) {m_v4=x; return; }
0072 }
0073
0074 double get_component(const int i) const
0075 {
0076 if (i==0) return m_v1;
0077 if (i==1) return m_v2;
0078 if (i==2) return m_v3;
0079 if (i==3) return m_v4;
0080 return 0.0;
0081 }
0082
0083
0084
0085 double x() const { return m_v1; }
0086
0087 void set_x(double xx) { m_v1 = xx; }
0088
0089 void setX(double xx) { set_x(xx); }
0090
0091
0092 double y() const { return m_v2; }
0093
0094 void set_y(double yy) { m_v2 = yy; }
0095
0096 void setY(double yy) { set_y(yy); }
0097
0098
0099 double z() const { return m_v3; }
0100
0101 void set_z(double zz) { m_v3 = zz; }
0102
0103 void setZ(double zz) { set_z(zz); }
0104
0105
0106 double t() const { return m_v4; }
0107
0108 void set_t(double tt) { m_v4 = tt; }
0109
0110 void setT(double tt) { set_t(tt); }
0111
0112
0113
0114 double px() const { return x(); }
0115
0116 void set_px(double pxx) { set_x(pxx); }
0117
0118 void setPx(double pxx) { set_px(pxx); }
0119
0120
0121 double py() const { return y(); }
0122
0123 void set_py(double pyy) { set_y(pyy); }
0124
0125 void setPy(double pyy) { set_py(pyy); }
0126
0127
0128 double pz() const { return z(); }
0129
0130 void set_pz(double pzz) { set_z(pzz); }
0131
0132 void setPz(double pzz) { set_pz(pzz); }
0133
0134
0135 double e() const { return t(); }
0136
0137 void set_e(double ee ) { this->set_t(ee); }
0138
0139 void setE(double ee) { set_e(ee); }
0140
0141
0142
0143
0144
0145
0146
0147
0148 double length2() const { return x()*x() + y()*y() + z()*z(); }
0149
0150 double length() const { return std::sqrt(length2()); }
0151
0152 double rho() const { return length(); }
0153
0154 double perp2() const { return x()*x() + y()*y(); }
0155
0156 double perp() const { return std::sqrt(perp2()); }
0157
0158 double interval() const { return t()*t() - length2(); }
0159
0160
0161 double p3mod2() const { return length2(); }
0162
0163 double p3mod() const { return length(); }
0164
0165 double pt2() const { return perp2(); }
0166
0167 double pt() const { return perp(); }
0168
0169 double m2() const { return interval(); }
0170
0171 double m() const { return (m2() > 0.0) ? std::sqrt(m2()) : -std::sqrt(-m2()); }
0172
0173
0174 double phi() const { return std::atan2( y(), x() ); }
0175
0176 double theta() const { return std::atan2( perp(), z() ); }
0177
0178 double eta() const {
0179 if ( p3mod() == 0.0 ) return 0.0;
0180 if ( p3mod() == fabs(pz()) ) return std::copysign(HUGE_VAL, pz());
0181 return 0.5*std::log( (p3mod() + pz()) / (p3mod() - pz()) );
0182 }
0183
0184 double rap() const {
0185 if ( e() == 0.0 ) return 0.0;
0186 if ( e() == fabs(pz()) ) return std::copysign(HUGE_VAL, pz());
0187 return 0.5*std::log( (e() + pz()) / (e() - pz()) );
0188 }
0189
0190 double abs_eta() const { return std::abs( eta() ); }
0191
0192 double abs_rap() const { return std::abs( rap() ); }
0193
0194
0195
0196
0197 double pseudoRapidity() const { return eta(); }
0198
0199
0200
0201
0202
0203
0204
0205
0206 bool is_zero() const { return x() == 0 && y() == 0 && z() == 0 && t() == 0; }
0207
0208
0209 double delta_phi(const FourVector &v) const {
0210 double dphi = phi() - v.phi();
0211 if (dphi != dphi) return dphi;
0212 while (dphi >= M_PI) dphi -= 2.*M_PI;
0213 while (dphi < -M_PI) dphi += 2.*M_PI;
0214 return dphi;
0215 }
0216
0217
0218 double delta_eta(const FourVector &v) const { return eta() - v.eta(); }
0219
0220
0221 double delta_rap(const FourVector &v) const { return rap() - v.rap(); }
0222
0223
0224 double delta_r2_eta(const FourVector &v) const {
0225 return delta_phi(v)*delta_phi(v) + delta_eta(v)*delta_eta(v);
0226 }
0227
0228
0229 double delta_r_eta(const FourVector &v) const {
0230 return std::sqrt( delta_r2_eta(v) );
0231 }
0232
0233
0234 double delta_r2_rap(const FourVector &v) const {
0235 return delta_phi(v)*delta_phi(v) + delta_rap(v)*delta_rap(v);
0236 }
0237
0238
0239 double delta_r_rap(const FourVector &v) const {
0240 return std::sqrt( delta_r2_rap(v) );
0241 }
0242
0243
0244
0245
0246
0247
0248
0249
0250 bool operator==(const FourVector& rhs) const {
0251 return x() == rhs.x() && y() == rhs.y() && z() == rhs.z() && t() == rhs.t();
0252 }
0253
0254 bool operator!=(const FourVector& rhs) const { return !(*this == rhs); }
0255
0256
0257 FourVector operator+ (const FourVector& rhs) const {
0258 return FourVector( x() + rhs.x(), y() + rhs.y(), z() + rhs.z(), t() + rhs.t() );
0259 }
0260
0261 FourVector operator- (const FourVector& rhs) const {
0262 return FourVector( x() - rhs.x(), y() - rhs.y(), z() - rhs.z(), t() - rhs.t() );
0263 }
0264
0265 FourVector operator* (const double rhs) const {
0266 return FourVector( x()*rhs, y()*rhs, z()*rhs, t()*rhs );
0267 }
0268
0269 FourVector operator/ (const double rhs) const {
0270 return FourVector( x()/rhs, y()/rhs, z()/rhs, t()/rhs );
0271 }
0272
0273
0274 void operator += (const FourVector& rhs) {
0275 setX(x() + rhs.x());
0276 setY(y() + rhs.y());
0277 setZ(z() + rhs.z());
0278 setT(t() + rhs.t());
0279 }
0280
0281 void operator -= (const FourVector& rhs) {
0282 setX(x() - rhs.x());
0283 setY(y() - rhs.y());
0284 setZ(z() - rhs.z());
0285 setT(t() - rhs.t());
0286 }
0287
0288 void operator *= (const double rhs) {
0289 setX(x()*rhs);
0290 setY(y()*rhs);
0291 setZ(z()*rhs);
0292 setT(t()*rhs);
0293 }
0294
0295 void operator /= (const double rhs) {
0296 setX(x()/rhs);
0297 setY(y()/rhs);
0298 setZ(z()/rhs);
0299 setT(t()/rhs);
0300 }
0301
0302
0303
0304
0305
0306 static const FourVector& ZERO_VECTOR() {
0307 static const FourVector v;
0308 return v;
0309 }
0310
0311
0312 private:
0313
0314 double m_v1;
0315 double m_v2;
0316 double m_v3;
0317 double m_v4;
0318
0319 };
0320
0321
0322
0323
0324
0325
0326 inline double delta_phi(const FourVector &a, const FourVector &b) { return b.delta_phi(a); }
0327
0328
0329 inline double delta_eta(const FourVector &a, const FourVector &b) { return b.delta_eta(a); }
0330
0331
0332 inline double delta_rap(const FourVector &a, const FourVector &b) { return b.delta_rap(a); }
0333
0334
0335 inline double delta_r2_eta(const FourVector &a, const FourVector &b) { return b.delta_r2_eta(a); }
0336
0337
0338 inline double delta_r_eta(const FourVector &a, const FourVector &b) { return b.delta_r_eta(a); }
0339
0340
0341 inline double delta_r2_rap(const FourVector &a, const FourVector &b) { return b.delta_r2_rap(a); }
0342
0343
0344 inline double delta_r_rap(const FourVector &a, const FourVector &b) { return b.delta_r_rap(a); }
0345
0346
0347
0348
0349 }
0350 #endif