SISCone  2.0.6
momentum.h
1 // -*- C++ -*-
3 // File: momentum.h //
4 // Description: header file for 4-momentum class Cmomentum //
5 // This file is part of the SISCone project. //
6 // WARNING: this is not the main SISCone trunk but //
7 // an adaptation to spherical coordinates //
8 // For more details, see http://projects.hepforge.org/siscone //
9 // //
10 // Copyright (c) 2006-2008 Gavin Salam and Gregory Soyez //
11 // //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details. //
21 // //
22 // You should have received a copy of the GNU General Public License //
23 // along with this program; if not, write to the Free Software //
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
25 // //
26 // $Revision:: 256 $//
27 // $Date:: 2008-07-14 13:52:16 +0200 (Mon, 14 Jul 2008) $//
29 
30 #ifndef __SPH_VECTOR_H__
31 #define __SPH_VECTOR_H__
32 
33 #include <vector>
34 #include <math.h>
35 #include <siscone/reference.h>
36 #include "geom_2d.h"
37 #include <siscone/defines.h>
38 
39 namespace siscone_spherical{
40 
55  public:
57  CSph3vector();
58 
60  CSph3vector(double _px, double _py, double _pz);
61 
63  ~CSph3vector();
64 
67 
70  const CSph3vector operator + (const CSph3vector &v);
71 
74  const CSph3vector operator - (const CSph3vector &v);
75 
78  const CSph3vector operator / (const double &r);
79 
83 
87 
90  CSph3vector& operator *= (const double &r);
91 
94  CSph3vector& operator /= (const double &r);
95 
97  inline double perp() const {return sqrt(perp2());}
98 
100  inline double perp2() const {return px*px+py*py;}
101 
103  inline double norm() const {return sqrt(px*px+py*py+pz*pz);}
104 
106  inline double norm2() const {return px*px+py*py+pz*pz;}
107 
109  inline double phi() const {return atan2(py, px);}
110 
112  inline double theta() const {return atan2(perp(),pz);}
113 
120  void build_norm();
121 
125  void build_thetaphi();
126 
129  void get_angular_directions(CSph3vector &angular_dir1, CSph3vector &angular_dir2);
130 
131  double px;
132  double py;
133  double pz;
134 
135  double _norm;
136  double _theta;
137  double _phi;
138 
140  // the following part is used for checksums //
143 };
144 
158 class CSphmomentum : public CSph3vector{
159  public:
161  CSphmomentum();
162 
164  CSphmomentum(CSph3vector &init, double E=0.0);
165 
167  CSphmomentum(double _px, double _py, double _pz, double _E);
168 
170  //CSphmomentum(double _eta, double _phi, siscone::Creference _ref);
171 
173  ~CSphmomentum();
174 
176  inline double mass() const {return sqrt(mass2());}
177 
179  inline double mass2() const {return perpmass2()-perp2();}
180 
182  inline double perpmass() const {return sqrt((E-pz)*(E+pz));}
183 
185  inline double perpmass2() const {return (E-pz)*(E+pz);}
186 
188  inline double Et() const {return E/sqrt(1.0+pz*pz/perp2());}
189 
191  inline double Et2() const {return E*E/(1.0+pz*pz/perp2());}
192 
195 
198  const CSphmomentum operator + (const CSphmomentum &v);
199 
203 
207 
208  double E;
209 
211  int index;
212 };
213 
216 bool operator < (const CSphmomentum &v1, const CSphmomentum &v2);
217 
219 bool momentum_theta_less(const CSphmomentum &v1, const CSphmomentum &v2);
220 
222 bool momentum_pt_less(const CSphmomentum &v1, const CSphmomentum &v2);
223 
224 
226 // some handy utilities //
228 
230 inline double sqr(double x){return x*x;}
231 
235 inline double dot_product3(const CSph3vector &v1, const CSph3vector &v2){
236  //double tmp = v1.px*v2.px + v1.py*v2.py + v1.pz*v2.pz;
237  //if (!isfinite(tmp)){
238  // std::cout << "dot_product inf: " << std::endl;
239  // std::cout << " angles: " << v1._theta << " " << v1._phi << " and " << v2._theta << " " << v2._phi << std::endl;
240  // std::cout << " moms : " << v1.px << " " << v1.py << " " << v1.pz
241  // << " and " << v2.px << " " << v2.py << " " << v2.pz << std::endl;
242  //}
243  return v1.px*v2.px + v1.py*v2.py + v1.pz*v2.pz;
244 }
245 
249 inline CSph3vector cross_product3(const CSph3vector &v1, const CSph3vector &v2){
250  //CSph3vector tmp;
251  //tmp.px = v1.py*v2.pz-v1.pz*v2.py;
252  //tmp.py = v1.pz*v2.px-v1.px*v2.pz;
253  //tmp.pz = v1.px*v2.py-v1.py*v2.px;
254  //return tmp;
255  return CSph3vector(v1.py*v2.pz-v1.pz*v2.py,
256  v1.pz*v2.px-v1.px*v2.pz,
257  v1.px*v2.py-v1.py*v2.px);
258 }
259 
263 inline double norm2_cross_product3(const CSph3vector &v1, const CSph3vector &v2){
264  return sqr(v1.py*v2.pz-v1.pz*v2.py) + sqr(v1.pz*v2.px-v1.px*v2.pz) + sqr(v1.px*v2.py-v1.py*v2.px);
265 }
266 
270 inline double get_tan2_distance(const CSphmomentum &v1, const CSphmomentum &v2){
271  return norm2_cross_product3(v1,v2)/sqr(dot_product3(v1,v2));
272 }
273 
277 inline double get_distance(const CSph3vector *v1, const CSph3vector *v2){
278  return atan2(sqrt(norm2_cross_product3(*v1,*v2)), dot_product3(*v1,*v2));
279 }
280 
289 inline bool is_closer(const CSph3vector *v1, const CSph3vector *v2, const double tan2R){
290  double dot = dot_product3(*v1,*v2);
291  return (dot>=0) && (norm2_cross_product3(*v1,*v2)<=tan2R*dot*dot);
292 }
293 
299 inline bool is_closer_safer(const CSph3vector *v1, const CSph3vector *v2, const double cosR){
300  return dot_product3(*v1,*v2)>=cosR*sqrt(v1->norm2()*v2->norm2());
301  //double dot = dot_product3(*v1,*v2);
302  //return (dot>=0) && (norm2_cross_product3(*v1,*v2)<tan2R*dot*dot);
303 }
304 
307 inline CSph3vector operator * (const double &r, const CSph3vector &v){
308  CSph3vector tmp = v;
309  return tmp*=r;
310 }
311 }
312 #endif
CSph3vector & operator=(const CSph3vector &v)
assignment of vectors
Definition: momentum.cpp:71
CSph3vector & operator+=(const CSph3vector &v)
incrementation of vectors WARNING= norm is not updated
Definition: momentum.cpp:107
double theta() const
3-vect polar angle
Definition: momentum.h:112
const CSph3vector operator+(const CSph3vector &v)
addition of vectors WARNING= norm is not updated
Definition: momentum.cpp:86
double _norm
particle spatial norm (available ONLY after a call to build_norm)
Definition: momentum.h:135
double pz
z-momentum
Definition: momentum.h:133
const CSph3vector operator-(const CSph3vector &v)
subtraction of vectors WARNING= norm is not updated
Definition: momentum.cpp:93
double perpmass() const
transverse mass, mt = sqrt(pt^2+m^2) = sqrt(E^2 - pz^2)
Definition: momentum.h:182
double _phi
particle phi angle (available ONLY after a call to build_thetaphi)
Definition: momentum.h:137
CSph3vector & operator/=(const double &r)
division by a constant WARNING= norm is not updated
Definition: momentum.cpp:137
double perp() const
computes pT
Definition: momentum.h:97
double mass() const
computes m
Definition: momentum.h:176
siscone::Creference ref
reference number for the vector
Definition: momentum.h:142
CSph3vector & operator-=(const CSph3vector &v)
decrementation of vectors WARNING= norm is not updated
Definition: momentum.cpp:117
void build_thetaphi()
just a useful tool to store theta and phi locally (in _theta and _phi) in case you need repeated acce...
Definition: momentum.cpp:153
double py
y-momentum
Definition: momentum.h:132
CSph3vector & operator*=(const double &r)
multiplication by a constant WARNING= norm is not updated
Definition: momentum.cpp:127
void get_angular_directions(CSph3vector &angular_dir1, CSph3vector &angular_dir2)
for this direction, compute the two reference directions used to measure angles
Definition: momentum.cpp:161
double mass2() const
computes m^2
Definition: momentum.h:179
int parent_index
particle number in the parent list
Definition: momentum.h:210
double norm2() const
3-vect norm squared
Definition: momentum.h:106
double Et() const
computes transverse energy
Definition: momentum.h:188
double _theta
particle theta angle (available ONLY after a call to build_thetaphi)
Definition: momentum.h:136
double norm() const
3-vect norm
Definition: momentum.h:103
double perp2() const
computes pT^2
Definition: momentum.h:100
const CSph3vector operator/(const double &r)
division by a constant WARNING= norm is not updated
Definition: momentum.cpp:100
int index
internal particle number
Definition: momentum.h:211
void build_norm()
build the spatial normfrom 4-momentum info !!! WARNING !!! !!! computing the norm is the only time-co...
Definition: momentum.cpp:148
double perpmass2() const
transverse mass squared, mt^2 = pt^2+m^2 = E^2 - pz^2
Definition: momentum.h:185
double Et2() const
computes transverse energy (squared)
Definition: momentum.h:191
base class for dynamic coordinates management
Definition: momentum.h:158
base class for managing the spatial part of Cmomentum (defined after)
Definition: momentum.h:54
double px
x-momentum
Definition: momentum.h:131
references used for checksums.
Definition: reference.h:43
double phi() const
3-vect azimuthal angle
Definition: momentum.h:109
The SISCone project has been developed by Gavin Salam and Gregory Soyez
Documentation generated for SISCone by  Doxygen 1.8.12