ATLAS Offline Software
Loading...
Searching...
No Matches
SignedKinematics.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4
6#include <TLorentzVector.h>
8#include <TVector2.h>
9
10namespace HLT { namespace MET {
13 double px, double py, double pz, double energy) :
14 m_p4(px, py, pz, energy)
15 {}
16
17 SignedKinematics::SignedKinematics(const TLorentzVector& tlv) :
18 m_p4(tlv.Px(), tlv.Py(), tlv.Pz(), tlv.E() )
19 {}
20
23 particle.e(), particle.eta(), particle.phi(), particle.m() ) )
24 {}
25
27 double energy, double eta, double phi)
28 {
29 return fromEnergyEtaPhiM(energy, eta, phi, 0.);
30 }
31
33 double energy, double eta, double phi, double mass)
34 {
35 double p = energy;
36 if (mass != 0) {
37 int sgn = (p > 0) - (p < 0);
38 p = sgn * sqrt(p*p - mass*mass);
39 }
40 double pt = p/std::cosh(eta);
41 double pz = pt*std::sinh(eta);
42 return SignedKinematics(
43 pt*std::cos(phi), pt*std::sin(phi), pz, energy);
44 }
45
47 double et, double eta, double phi)
48 {
49 return fromEtEtaPhiM(et, eta, phi, 0.);
50 }
51
53 double et, double eta, double phi, double mass)
54 {
55 return fromEnergyEtaPhiM(et*std::cosh(eta), eta, phi, mass);
56 }
57
59 return (energy() > 0) - (energy() < 0);
60 }
61
62 double SignedKinematics::eta() const {
63 return sign() * m_p4.Eta();
64 }
65
66 double SignedKinematics::phi() const {
67 double val = m_p4.Phi();
68 if (sign() < 0)
69 val += TMath::Pi();
70 return TVector2::Phi_0_2pi(val);
71 }
72
73 double SignedKinematics::sinPhi() const {
74 double thePt = pt();
75 // if pt() is 0 then the value is not determined.
76 // For this phi = 0
77 return (thePt == 0 ? 0 : py() / thePt );
78 }
79 double SignedKinematics::cosPhi() const {
80 double thePt = pt();
81 // if pt() is 0 then the value is not determined.
82 // Take phi = 0
83 return (thePt == 0 ? 1 : px() / thePt );
84 }
85
87 double thePt = pt();
88 // if pt is 0 then the value is not determined.
89 // Take eta = 0
90 return (thePt == 0 ? 0 : pz() / thePt );
91 }
93 double thePt2 = pt2();
94 // if pt is 0 then the value is not determined.
95 // Take eta = 0
96 if (thePt2 == 0)
97 return 1;
98 // Otherwise, calculate sinh^2 eta, then use
99 // cosh eta = sqrt(1 + sinh^2 eta)
100 return sqrt(1 + pz()*pz() / thePt2);
101 }
102
103 double SignedKinematics::p() const {
104 return sign() * absP();
105 }
106 double SignedKinematics::absP() const {
107 return sqrt(p2() );
108 }
109 double SignedKinematics::p2() const {
110 return pt2() + pz()*pz();
111 }
112 double SignedKinematics::pt() const {
113 return sign() * absPt();
114 }
115 double SignedKinematics::absPt() const {
116 return sqrt(pt2() );
117 }
118 double SignedKinematics::pt2() const {
119 return px()*px() + py()*py();
120 }
121 double SignedKinematics::px() const {
122 return m_p4.Px();
123 }
124 double SignedKinematics::py() const {
125 return m_p4.Py();
126 }
127 double SignedKinematics::pz() const {
128 return m_p4.Pz();
129 }
130
132 return m_p4.E();
133 }
135 return abs(energy() );
136 }
138 return energy()*energy();
139 }
140 double SignedKinematics::et() const {
141 return energy() / coshEta();
142 }
143 double SignedKinematics::absEt() const {
144 return abs(et() );
145 }
146 double SignedKinematics::et2() const {
147 return et()*et();
148 }
149 double SignedKinematics::ex() const {
150 return et() * cosPhi();
151 }
152 double SignedKinematics::ey() const {
153 return et() * sinPhi();
154 }
155 double SignedKinematics::ez() const {
156 return et() * sinhEta();
157 }
158
159 double SignedKinematics::m2() const {
160 return energy2() - p2();
161 }
162
163 SignedKinematics::operator ROOT::Math::PxPyPzEVector() const {
164 return m_p4;
165 }
166
168 {
169 m_p4.SetPx(px()+other.px() );
170 m_p4.SetPy(py()+other.py() );
171 m_p4.SetPz(pz()+other.pz() );
172 m_p4.SetE(energy()+other.energy() );
173 return *this;
174 }
176 {
177 m_p4.SetPx(px()-other.px() );
178 m_p4.SetPy(py()-other.py() );
179 m_p4.SetPz(pz()-other.pz() );
180 m_p4.SetE(energy()-other.energy() );
181 return *this;
182 }
183
185 {
186 SignedKinematics val(lhs);
187 val += rhs;
188 return val;
189 }
191 {
192 SignedKinematics val(lhs);
193 val -= rhs;
194 return val;
195 }
196} } //> end namespace HLT::MET
Class to describe the kinematics of an object that can have negative energies.
double et() const
(signed) et
static SignedKinematics fromEtEtaPhi(double et, double eta, double phi)
Factory function to construct from et, eta, phi (massless)
double sinPhi() const
Provide accessors for sin and cos phi.
double eta() const
Direction.
double sinhEta() const
Provide accessors for sinh and cosh eta.
SignedKinematics & operator+=(const SignedKinematics &other)
Add another SignedKinematics to this.
double m2() const
The squared mass. There is no guarantee that this will be > 0.
double absP() const
unsigned momentum
double p() const
Momentum values (signed) momentum.
double absPt() const
unsigned pt
SignedKinematics & operator-=(const SignedKinematics &other)
Subtract a SignedKinematics from this (exact opposite of the above function.
double absEnergy() const
unsigned energy
static SignedKinematics fromEnergyEtaPhi(double energy, double eta, double phi)
Factory function to construct from energy, eta, phi (massless)
static SignedKinematics fromEtEtaPhiM(double et, double eta, double phi, double mass)
Factory function to construct from et eta, phi and m.
double energy() const
Energy values (signed) energy.
double absEt() const
Unsigned et.
ROOT::Math::PxPyPzEVector m_p4
The actual kinematics.
static SignedKinematics fromEnergyEtaPhiM(double energy, double eta, double phi, double mass)
Factory function to construct from energy eta, phi and m.
int sign() const
The sign of the kinematics.
double pt() const
(signed) pt
Class providing the definition of the 4-vector interface.
METComponent operator+(const METComponent &lhs, const METComponent &rhs)
PufitGrid operator-(const PufitGrid &lhs, const PufitGrid &rhs)
Elementwise subtraction.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...