ATLAS Offline Software
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>
7 #include "xAODBase/IParticle.h"
8 #include <TVector2.h>
9 
10 namespace 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 
22  SignedKinematics(fromEnergyEtaPhiM(
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(
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 
58  int SignedKinematics::sign() const {
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 
86  double SignedKinematics::sinhEta() const {
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  }
92  double SignedKinematics::coshEta() const {
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 
131  double SignedKinematics::energy() const {
132  return m_p4.E();
133  }
135  return abs(energy() );
136  }
137  double SignedKinematics::energy2() const {
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
HLT::MET::SignedKinematics::cosPhi
double cosPhi() const
Definition: SignedKinematics.cxx:79
HLT::MET::SignedKinematics::px
double px() const
Definition: SignedKinematics.cxx:121
et
Extra patterns decribing particle interation process.
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
test_pyathena.px
px
Definition: test_pyathena.py:18
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
IParticle.h
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
HLT::MET::SignedKinematics::sinPhi
double sinPhi() const
Provide accessors for sin and cos phi.
Definition: SignedKinematics.cxx:73
HLT::MET::SignedKinematics::coshEta
double coshEta() const
Definition: SignedKinematics.cxx:92
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
HLT::MET::SignedKinematics::pt
double pt() const
(signed) pt
Definition: SignedKinematics.cxx:112
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
HLT::MET::SignedKinematics::m2
double m2() const
The squared mass. There is no guarantee that this will be > 0.
Definition: SignedKinematics.cxx:159
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
HLT::MET::SignedKinematics::fromEtEtaPhiM
static SignedKinematics fromEtEtaPhiM(double et, double eta, double phi, double mass)
Factory function to construct from et eta, phi and m.
Definition: SignedKinematics.cxx:52
HLT::MET::SignedKinematics::absPt
double absPt() const
unsigned pt
Definition: SignedKinematics.cxx:115
HLT::MET::SignedKinematics::absP
double absP() const
unsigned momentum
Definition: SignedKinematics.cxx:106
SignedKinematics.h
HLT::MET::SignedKinematics::et2
double et2() const
Definition: SignedKinematics.cxx:146
HLT::MET::SignedKinematics
Class to describe the kinematics of an object that can have negative energies.
Definition: SignedKinematics.h:42
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
HLT::MET::SignedKinematics::m_p4
ROOT::Math::PxPyPzEVector m_p4
The actual kinematics.
Definition: SignedKinematics.h:119
HLT::MET::SignedKinematics::sign
int sign() const
The sign of the kinematics.
Definition: SignedKinematics.cxx:58
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
TCS::MET
@ MET
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Types.h:16
HLT::MET::SignedKinematics::operator+=
SignedKinematics & operator+=(const SignedKinematics &other)
Add another SignedKinematics to this.
Definition: SignedKinematics.cxx:167
HLT::MET::SignedKinematics::absEt
double absEt() const
Unsigned et.
Definition: SignedKinematics.cxx:143
HLT::MET::SignedKinematics::fromEnergyEtaPhi
static SignedKinematics fromEnergyEtaPhi(double energy, double eta, double phi)
Factory function to construct from energy, eta, phi (massless)
Definition: SignedKinematics.cxx:26
HLT::MET::SignedKinematics::sinhEta
double sinhEta() const
Provide accessors for sinh and cosh eta.
Definition: SignedKinematics.cxx:86
Amg::py
@ py
Definition: GeoPrimitives.h:39
Py
Definition: PyDataStore.h:24
HLT::MET::SignedKinematics::ex
double ex() const
Definition: SignedKinematics.cxx:149
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
HLT::MET::SignedKinematics::et
double et() const
(signed) et
Definition: SignedKinematics.cxx:140
HLT::MET::SignedKinematics::operator-=
SignedKinematics & operator-=(const SignedKinematics &other)
Subtract a SignedKinematics from this (exact opposite of the above function.
Definition: SignedKinematics.cxx:175
HLT::MET::SignedKinematics::p
double p() const
Momentum values (signed) momentum.
Definition: SignedKinematics.cxx:103
HLT::MET::SignedKinematics::ey
double ey() const
Definition: SignedKinematics.cxx:152
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
HLT::MET::SignedKinematics::absEnergy
double absEnergy() const
unsigned energy
Definition: SignedKinematics.cxx:134
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
HLT::MET::SignedKinematics::fromEnergyEtaPhiM
static SignedKinematics fromEnergyEtaPhiM(double energy, double eta, double phi, double mass)
Factory function to construct from energy eta, phi and m.
Definition: SignedKinematics.cxx:32
HLT::MET::SignedKinematics::pt2
double pt2() const
Definition: SignedKinematics.cxx:118
HLT::MET::operator-
PufitGrid operator-(const PufitGrid &lhs, const PufitGrid &rhs)
Elementwise subtraction.
Definition: PufitGrid.cxx:250
HLT::MET::SignedKinematics::phi
double phi() const
Definition: SignedKinematics.cxx:66
HLT::MET::SignedKinematics::energy
double energy() const
Energy values (signed) energy.
Definition: SignedKinematics.cxx:131
HLT::MET::SignedKinematics::fromEtEtaPhi
static SignedKinematics fromEtEtaPhi(double et, double eta, double phi)
Factory function to construct from et, eta, phi (massless)
Definition: SignedKinematics.cxx:46
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
HLT::MET::SignedKinematics::pz
double pz() const
Definition: SignedKinematics.cxx:127
HLT::MET::SignedKinematics::SignedKinematics
SignedKinematics()
Definition: SignedKinematics.cxx:11
HLT::MET::SignedKinematics::p2
double p2() const
Definition: SignedKinematics.cxx:109
HLT::MET::SignedKinematics::ez
double ez() const
Definition: SignedKinematics.cxx:155
HLT::MET::SignedKinematics::energy2
double energy2() const
Definition: SignedKinematics.cxx:137
HLT::MET::operator+
METComponent operator+(const METComponent &lhs, const METComponent &rhs)
Definition: METComponent.cxx:48
HLT::MET::SignedKinematics::eta
double eta() const
Direction.
Definition: SignedKinematics.cxx:62
HLT::MET::SignedKinematics::py
double py() const
Definition: SignedKinematics.cxx:124