SISCone  2.0.5
siscone/spherical/momentum.h
00001 // -*- C++ -*-
00003 // File: momentum.h                                                          //
00004 // Description: header file for 4-momentum class Cmomentum                   //
00005 // This file is part of the SISCone project.                                 //
00006 // WARNING: this is not the main SISCone trunk but                           //
00007 //          an adaptation to spherical coordinates                           //
00008 // For more details, see http://projects.hepforge.org/siscone                //
00009 //                                                                           //
00010 // Copyright (c) 2006-2008 Gavin Salam and Gregory Soyez                     //
00011 //                                                                           //
00012 // This program is free software; you can redistribute it and/or modify      //
00013 // it under the terms of the GNU General Public License as published by      //
00014 // the Free Software Foundation; either version 2 of the License, or         //
00015 // (at your option) any later version.                                       //
00016 //                                                                           //
00017 // This program is distributed in the hope that it will be useful,           //
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
00020 // GNU General Public License for more details.                              //
00021 //                                                                           //
00022 // You should have received a copy of the GNU General Public License         //
00023 // along with this program; if not, write to the Free Software               //
00024 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
00025 //                                                                           //
00026 // $Revision:: 256                                                          $//
00027 // $Date:: 2008-07-14 13:52:16 +0200 (Mon, 14 Jul 2008)                     $//
00029 
00030 #ifndef __SPH_VECTOR_H__
00031 #define __SPH_VECTOR_H__
00032 
00033 #include <vector>
00034 #include <math.h>
00035 #include <siscone/reference.h>
00036 #include "geom_2d.h"
00037 #include <siscone/defines.h>
00038 
00039 namespace siscone_spherical{
00040 
00054 class CSph3vector{
00055  public:
00057   CSph3vector();
00058 
00060   CSph3vector(double _px, double _py, double _pz);
00061 
00063   ~CSph3vector();
00064 
00066   CSph3vector& operator = (const CSph3vector &v);
00067 
00070   const CSph3vector operator + (const CSph3vector &v);
00071 
00074   const CSph3vector operator - (const CSph3vector &v);
00075 
00078   const CSph3vector operator / (const double &r);
00079 
00082   CSph3vector& operator += (const CSph3vector &v);
00083 
00086   CSph3vector& operator -= (const CSph3vector &v);
00087 
00090   CSph3vector& operator *= (const double &r);
00091 
00094   CSph3vector& operator /= (const double &r);
00095 
00097   inline double perp() const {return sqrt(perp2());}
00098 
00100   inline double perp2() const {return px*px+py*py;}
00101 
00103   inline double norm() const {return sqrt(px*px+py*py+pz*pz);}
00104 
00106   inline double norm2() const {return px*px+py*py+pz*pz;}
00107 
00109   inline double phi() const {return atan2(py, px);}
00110 
00112   inline double theta() const {return atan2(perp(),pz);}
00113 
00120   void build_norm();
00121 
00125   void build_thetaphi();
00126 
00129   void get_angular_directions(CSph3vector &angular_dir1, CSph3vector &angular_dir2);
00130 
00131   double px;        
00132   double py;        
00133   double pz;        
00134 
00135   double _norm;     
00136   double _theta;    
00137   double _phi;      
00138 
00140   // the following part is used for checksums //
00142   siscone::Creference ref;   
00143 };
00144 
00158 class CSphmomentum : public CSph3vector{
00159  public:
00161   CSphmomentum();
00162 
00164   CSphmomentum(CSph3vector &init, double E=0.0);
00165 
00167   CSphmomentum(double _px, double _py, double _pz, double _E);
00168 
00170   //CSphmomentum(double _eta, double _phi, siscone::Creference _ref);
00171 
00173   ~CSphmomentum();
00174 
00176   inline double mass() const {return sqrt(mass2());}
00177 
00179   inline double mass2() const {return perpmass2()-perp2();}
00180 
00182   inline double perpmass() const {return sqrt((E-pz)*(E+pz));}
00183 
00185   inline double perpmass2() const {return (E-pz)*(E+pz);}
00186 
00188   inline double Et() const {return E/sqrt(1.0+pz*pz/perp2());}
00189 
00191   inline double Et2() const {return E*E/(1.0+pz*pz/perp2());}
00192 
00194   CSphmomentum& operator = (const CSphmomentum &v);
00195 
00198   const CSphmomentum operator + (const CSphmomentum &v);
00199 
00202   CSphmomentum& operator += (const CSphmomentum &v);
00203 
00206   CSphmomentum& operator -= (const CSphmomentum &v);
00207 
00208   double E;         
00209 
00210   int parent_index; 
00211   int index;        
00212 };
00213 
00216 bool operator < (const CSphmomentum &v1, const CSphmomentum &v2);
00217 
00219 bool momentum_theta_less(const CSphmomentum &v1, const CSphmomentum &v2);
00220 
00222 bool momentum_pt_less(const CSphmomentum &v1, const CSphmomentum &v2);
00223 
00224 
00226 // some handy utilities //
00228 
00230 inline double sqr(double x){return x*x;}
00231 
00235 inline double dot_product3(const CSph3vector &v1, const CSph3vector &v2){
00236   //double tmp = v1.px*v2.px + v1.py*v2.py + v1.pz*v2.pz;
00237   //if (!isfinite(tmp)){
00238   //  std::cout << "dot_product inf: " << std::endl;
00239   //  std::cout << "  angles: " << v1._theta << " " << v1._phi << " and " << v2._theta << " " << v2._phi << std::endl; 
00240   //  std::cout << "  moms  : " << v1.px << " " << v1.py << " " << v1.pz 
00241   //          << " and "      << v2.px << " " << v2.py << " " << v2.pz << std::endl;
00242   //}
00243   return v1.px*v2.px + v1.py*v2.py + v1.pz*v2.pz;
00244 }
00245 
00249 inline CSph3vector cross_product3(const CSph3vector &v1, const CSph3vector &v2){
00250   //CSph3vector tmp;
00251   //tmp.px = v1.py*v2.pz-v1.pz*v2.py;
00252   //tmp.py = v1.pz*v2.px-v1.px*v2.pz;
00253   //tmp.pz = v1.px*v2.py-v1.py*v2.px;
00254   //return tmp;
00255   return CSph3vector(v1.py*v2.pz-v1.pz*v2.py,
00256                   v1.pz*v2.px-v1.px*v2.pz,
00257                   v1.px*v2.py-v1.py*v2.px);
00258 }
00259 
00263 inline double norm2_cross_product3(const CSph3vector &v1, const CSph3vector &v2){
00264   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);
00265 }
00266 
00270 inline double get_tan2_distance(const CSphmomentum &v1, const CSphmomentum &v2){
00271   return norm2_cross_product3(v1,v2)/sqr(dot_product3(v1,v2));
00272 }
00273 
00277 inline double get_distance(const CSph3vector *v1, const CSph3vector *v2){
00278   return atan2(sqrt(norm2_cross_product3(*v1,*v2)), dot_product3(*v1,*v2));
00279 }
00280 
00289 inline bool is_closer(const CSph3vector *v1, const CSph3vector *v2, const double tan2R){
00290   double dot = dot_product3(*v1,*v2);
00291   return (dot>=0) && (norm2_cross_product3(*v1,*v2)<=tan2R*dot*dot);
00292 }
00293 
00299 inline bool is_closer_safer(const CSph3vector *v1, const CSph3vector *v2, const double cosR){
00300   return dot_product3(*v1,*v2)>=cosR*sqrt(v1->norm2()*v2->norm2());
00301   //double dot = dot_product3(*v1,*v2);
00302   //return (dot>=0) && (norm2_cross_product3(*v1,*v2)<tan2R*dot*dot);
00303 }
00304 
00307 inline CSph3vector operator * (const double &r, const CSph3vector &v){
00308   CSph3vector tmp = v;
00309   return tmp*=r;
00310 }
00311 }
00312 #endif
The SISCone project has been developed by Gavin Salam and Gregory Soyez
Documentation generated on Mon Jun 4 2012 18:23:38 for SISCone by  Doxygen 1.7.6.1