CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Particle.cc
Go to the documentation of this file.
2 #include <memory>
3 
4 const unsigned int reco::Particle::longLivedTag = 65536;
5 
6 using namespace reco;
7 
10  : qx3_(0), pt_(0), eta_(0), phi_(0), mass_(0),
11  vertex_(0, 0, 0), pdgId_(0), status_(0),
12  p4Polar_(nullptr), p4Cartesian_(nullptr)
13 {
14 }
16 Particle::Particle( Charge q, const LorentzVector & p4, const Point & vertex,
17  int pdgId, int status, bool integerCharge)
18  : qx3_( q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
19  vertex_( vertex ), pdgId_( pdgId ), status_( status ),
20  p4Polar_(nullptr), p4Cartesian_(nullptr)
21 {
22  if ( integerCharge ) qx3_ *= 3;
23 }
26  int pdgId, int status, bool integerCharge)
27  : qx3_( q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
28  vertex_( vertex ), pdgId_( pdgId ), status_( status ),
29  p4Polar_(nullptr), p4Cartesian_(nullptr)
30 {
31  if ( integerCharge ) qx3_ *= 3;
32 }
33 // copy-ctor
35  : qx3_(src.qx3_), pt_(src.pt_), eta_(src.eta_), phi_(src.phi_), mass_(src.mass_),
36  vertex_(src.vertex_), pdgId_(src.pdgId_), status_(src.status_),
37  p4Polar_(nullptr), p4Cartesian_(nullptr)
38 {
39 }
40 // copy assignment operator
41 Particle&
43  Particle temp(rhs);
44  temp.swap(*this);
45  return *this;
46 }
47 // public swap function
48 void Particle::swap(Particle& other) {
49  std::swap(qx3_, other.qx3_);
50  std::swap(pt_, other.pt_);
51  std::swap(eta_, other.eta_);
52  std::swap(phi_, other.phi_);
53  std::swap(mass_, other.mass_);
54  std::swap(vertex_, other.vertex_);
55  std::swap(pdgId_, other.pdgId_);
56  std::swap(status_, other.status_);
57  other.p4Polar_.exchange(
58  p4Polar_.exchange(other.p4Polar_, std::memory_order_acq_rel),
59  std::memory_order_acq_rel);
60  other.p4Cartesian_.exchange(
61  p4Cartesian_.exchange(other.p4Cartesian_, std::memory_order_acq_rel),
62  std::memory_order_acq_rel);
63 }
66  clearCache();
67 }
68 
70 int Particle::charge() const {
71  return qx3_ / 3;
72 }
75  qx3_ = q * 3;
76 }
78 int Particle::threeCharge() const {
79  return qx3_;
80 }
83  qx3_ = qx3;
84 }
88  return (*p4Cartesian_.load(std::memory_order_acquire));
89 }
92  cachePolar();
93  return (*p4Polar_.load(std::memory_order_acquire));
94 }
98  return (*p4Cartesian_.load(std::memory_order_acquire)).Vect();
99 }
103  cacheCartesian();
104  return (*p4Cartesian_.load(std::memory_order_acquire)).BoostToCM();
105 }
107 double Particle::p() const {
108  cacheCartesian();
109  return (*p4Cartesian_.load(std::memory_order_acquire)).P();
110 }
112 double Particle::energy() const {
113  cacheCartesian();
114  return (*p4Cartesian_.load(std::memory_order_acquire)).E();
115 }
117 double Particle::et() const {
118  cachePolar();
119  return (*p4Polar_.load(std::memory_order_acquire)).Et();
120 }
122 double Particle::mass() const {
123  return mass_;
124 }
126 double Particle::massSqr() const {
127  return mass_ * mass_;
128 }
130 double Particle::mt() const {
131  cachePolar();
132  return (*p4Polar_.load(std::memory_order_acquire)).Mt();
133 }
135 double Particle::mtSqr() const {
136  cachePolar();
137  return (*p4Polar_.load(std::memory_order_acquire)).Mt2();
138 }
140 double Particle::px() const {
141  cacheCartesian();
142  return (*p4Cartesian_.load(std::memory_order_acquire)).Px();
143 }
145 double Particle::py() const {
146  cacheCartesian();
147  return (*p4Cartesian_.load(std::memory_order_acquire)).Py();
148 }
150 double Particle::pz() const {
151  cacheCartesian();
152  return (*p4Cartesian_.load(std::memory_order_acquire)).Pz();
153 }
155 double Particle::pt() const {
156  return pt_;
157 }
159 double Particle::phi() const {
160  return phi_;
161 }
163 double Particle::theta() const {
164  cacheCartesian();
165  return (*p4Cartesian_.load(std::memory_order_acquire)).Theta();
166 }
168 double Particle::eta() const {
169  return eta_;
170 }
172 double Particle::rapidity() const {
173  cachePolar();
174  return (*p4Polar_.load(std::memory_order_acquire)).Rapidity();
175 }
177 double Particle::y() const {
178  return rapidity();
179 }
180 
183  // ensure that we have non-null pointers
184  cacheCartesian();
185  *p4Cartesian_.load(std::memory_order_acquire) = p4;
186  // ensure that we have non-null pointers
187  cachePolar();
188  *p4Polar_.load(std::memory_order_acquire) = p4;
189  auto const* p4Polar = p4Polar_.load(std::memory_order_acquire);
190  pt_ = p4Polar->pt();
191  eta_ = p4Polar->eta();
192  phi_ = p4Polar->phi();
193  mass_ = p4Polar->mass();
194 }
197  // ensure that we have non-null pointers
198  cachePolar();
199  *p4Polar_.load(std::memory_order_acquire) = p4;
200  auto const* p4Polar = p4Polar_.load(std::memory_order_acquire);
201  pt_ = p4Polar->pt();
202  eta_ = p4Polar->eta();
203  phi_ = p4Polar->phi();
204  mass_ = p4Polar->mass();
205  delete p4Cartesian_.exchange(nullptr, std::memory_order_acq_rel);
206 }
208 void Particle::setMass( double m ) {
209  mass_ = m;
210  clearCache();
211 }
212 void Particle::setPz( double pz ) {
213  // ensure that we have non-null pointers
214  cacheCartesian();
215  (*p4Cartesian_.load(std::memory_order_acquire)).SetPz(pz);
216  // ensure that we have non-null pointers
217  cachePolar();
218  (*p4Polar_.load(std::memory_order_acquire)) = (*p4Cartesian_.load(std::memory_order_acquire));
219  auto const* p4Polar = p4Polar_.load(std::memory_order_acquire);
220  pt_ = p4Polar->pt();
221  eta_ = p4Polar->eta();
222  phi_ = p4Polar->phi();
223  mass_ = p4Polar->mass();
224 }
225 
227  return vertex_;
228 }
230 double Particle::vx() const {
231  return vertex_.X();
232 }
234 double Particle::vy() const {
235  return vertex_.Y();
236 }
238 double Particle::vz() const {
239  return vertex_.Z();
240 }
242 void Particle::setVertex( const Point & vertex ) {
243  vertex_ = vertex;
244 }
246 int Particle::pdgId() const {
247  return pdgId_;
248 }
249 // set PDG identifier
251  pdgId_ = pdgId;
252 }
254 int Particle::status() const {
255  return status_;
256 }
259  status_ = status;
260 }
264 }
266 bool Particle::longLived() const {
267  return status_ & longLivedTag;
268 }
269 
271 void Particle::cachePolar() const {
272  if(!p4Polar_.load(std::memory_order_acquire)) {
273  std::unique_ptr<PolarLorentzVector> ptr{new PolarLorentzVector(pt_,eta_,phi_,mass_)};
274  PolarLorentzVector* expect = nullptr;
275  if(p4Polar_.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
276  ptr.release();
277  }
278  }
279 }
282  if(!p4Cartesian_.load(std::memory_order_acquire)) {
283  cachePolar();
284  std::unique_ptr<LorentzVector> ptr{new LorentzVector(*p4Polar_.load(std::memory_order_acquire))};
285  LorentzVector* expected = nullptr;
286  if( p4Cartesian_.compare_exchange_strong(expected, ptr.get(), std::memory_order_acq_rel) ) {
287  ptr.release();
288  }
289  }
290 }
292 void Particle::clearCache() const {
293  delete p4Polar_.exchange(nullptr, std::memory_order_acq_rel);
294  delete p4Cartesian_.exchange(nullptr, std::memory_order_acq_rel);
295 }
double px() const
x coordinate of momentum vector
Definition: Particle.cc:140
void setLongLived()
set long lived flag
Definition: Particle.cc:262
double y() const
repidity
Definition: Particle.cc:177
double energy() const
energy
Definition: Particle.cc:112
Particle()
default constructor
Definition: Particle.cc:9
void setP4(const LorentzVector &p4)
set 4-momentum
Definition: Particle.cc:182
void clearCache() const
clear internal cache
Definition: Particle.cc:292
int pdgId_
PDG identifier.
Definition: Particle.h:139
void setCharge(Charge q)
set electric charge
Definition: Particle.cc:74
int status() const
status word
Definition: Particle.cc:254
void setVertex(const Point &vertex)
set vertex
Definition: Particle.cc:242
Charge qx3_
electric charge
Definition: Particle.h:133
Point vertex_
vertex position
Definition: Particle.h:137
int status_
status word
Definition: Particle.h:141
Vector boostToCM() const
Definition: Particle.cc:102
#define nullptr
const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: Particle.cc:86
std::atomic< LorentzVector * > p4Cartesian_
internal cache for p4
Definition: Particle.h:146
#define P
int Charge
electric charge type
Definition: Particle.h:25
T eta() const
double eta() const
momentum pseudorapidity
Definition: Particle.cc:168
virtual ~Particle()
destructor
Definition: Particle.cc:65
void cacheCartesian() const
set internal cache
Definition: Particle.cc:281
double phi() const
momentum azimuthal angle
Definition: Particle.cc:159
double theta() const
momentum polar angle
Definition: Particle.cc:163
void cachePolar() const
set internal cache
Definition: Particle.cc:271
void setMass(double m)
set particle mass
Definition: Particle.cc:208
void swap(Particle &other)
Definition: Particle.cc:48
double vy() const
y coordinate of vertex position
Definition: Particle.cc:234
float pt_
four-momentum Lorentz vector
Definition: Particle.h:135
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double p4[4]
Definition: TauolaWrapper.h:92
pdgId_(cfg.getParameter< std::vector< int > >("matchPDGId"))
Vector momentum() const
spatial momentum vector
Definition: Particle.cc:96
math::XYZPoint Point
point in the space
Definition: Particle.h:31
double mass() const
mass
Definition: Particle.cc:122
std::atomic< PolarLorentzVector * > p4Polar_
internal cache for p4
Definition: Particle.h:144
double vx() const
x coordinate of vertex position
Definition: Particle.cc:230
const Point & vertex() const
vertex position
Definition: Particle.cc:226
double massSqr() const
mass squared
Definition: Particle.cc:126
double mtSqr() const
transverse mass squared
Definition: Particle.cc:135
double pt() const
transverse momentum
Definition: Particle.cc:155
double et() const
transverse energy
Definition: Particle.cc:117
void setThreeCharge(Charge qx3)
set electric charge
Definition: Particle.cc:82
Particle & operator=(const Particle &rhs)
Definition: Particle.cc:42
double p() const
magnitude of momentum vector
Definition: Particle.cc:107
double pz() const
z coordinate of momentum vector
Definition: Particle.cc:150
bool longLived() const
is long lived?
Definition: Particle.cc:266
void setPz(double pz)
set Pz
Definition: Particle.cc:212
double vz() const
z coordinate of vertex position
Definition: Particle.cc:238
double mt() const
transverse mass
Definition: Particle.cc:130
int pdgId() const
PDG identifier.
Definition: Particle.cc:246
static const unsigned int longLivedTag
long lived flag
Definition: Particle.h:125
math::XYZVector Vector
point in the space
Definition: Particle.h:33
const PolarLorentzVector & polarP4() const
four-momentum Lorentz vector
Definition: Particle.cc:91
int threeCharge() const
electric charge
Definition: Particle.cc:78
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:29
void setPdgId(int pdgId)
Definition: Particle.cc:250
tuple status
Definition: ntuplemaker.py:245
double py() const
y coordinate of momentum vector
Definition: Particle.cc:145
void setStatus(int status)
set status word
Definition: Particle.cc:258
int charge() const
electric charge
Definition: Particle.cc:70
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:27
double rapidity() const
repidity
Definition: Particle.cc:172
Definition: DDAxes.h:10