|
SISCone
2.0.5
|
00001 // -*- C++ -*- 00003 // File: geom_2d.h // 00004 // Description: header file for two-dimensional geometry tools // 00005 // This file is part of the SISCone project. // 00006 // For more details, see http://projects.hepforge.org/siscone // 00007 // // 00008 // Copyright (c) 2006 Gavin Salam and Gregory Soyez // 00009 // // 00010 // This program is free software; you can redistribute it and/or modify // 00011 // it under the terms of the GNU General Public License as published by // 00012 // the Free Software Foundation; either version 2 of the License, or // 00013 // (at your option) any later version. // 00014 // // 00015 // This program is distributed in the hope that it will be useful, // 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00018 // GNU General Public License for more details. // 00019 // // 00020 // You should have received a copy of the GNU General Public License // 00021 // along with this program; if not, write to the Free Software // 00022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA // 00023 // // 00024 // $Revision:: 268 $// 00025 // $Date:: 2009-03-12 21:24:16 +0100 (Thu, 12 Mar 2009) $// 00027 00028 #ifndef __GEOM_2D_H__ 00029 #define __GEOM_2D_H__ 00030 00031 #include <iostream> 00032 #include <math.h> 00033 #include "defines.h" 00034 00035 #ifndef M_PI 00036 #define M_PI 3.141592653589793238462643383279502884197 00037 #endif 00038 00039 namespace siscone{ 00040 00043 inline double phi_in_range(double phi) { 00044 if (phi <= -M_PI) phi += twopi; 00045 else if (phi > M_PI) phi -= twopi; 00046 return phi; 00047 } 00048 00052 inline double dphi(double phi1, double phi2) { 00053 return phi_in_range(phi1-phi2); 00054 } 00055 00056 00060 inline double abs_dphi(double phi1, double phi2) { 00061 double delta = fabs(phi1-phi2); 00062 return delta > M_PI ? twopi-delta : delta; 00063 } 00064 00066 inline double pow2(double x) {return x*x;} 00067 00068 00073 class Ctwovect { 00074 public: 00076 Ctwovect() : x(0.0), y(0.0) {} 00077 00081 Ctwovect(double _x, double _y) : x(_x), y(_y) {} 00082 00084 double x, y; 00085 00087 inline double mod2() const {return pow2(x)+pow2(y);} 00088 00090 inline double modulus() const {return sqrt(mod2());} 00091 }; 00092 00093 00098 inline double dot_product(const Ctwovect & a, const Ctwovect & b) { 00099 return a.x*b.x + a.y*b.y; 00100 } 00101 00102 00107 inline double cross_product(const Ctwovect & a, const Ctwovect & b) { 00108 return a.x*b.y - a.y*b.x; 00109 } 00110 00111 00120 class Ceta_phi_range{ 00121 public: 00123 Ceta_phi_range(); 00124 00130 Ceta_phi_range(double c_eta, double c_phi, double R); 00131 00134 Ceta_phi_range& operator = (const Ceta_phi_range &r); 00135 00140 int add_particle(const double eta, const double phi); 00141 00143 unsigned int eta_range; 00144 00146 unsigned int phi_range; 00147 00148 // extremal value for eta 00149 static double eta_min; 00150 static double eta_max; 00151 00152 private: 00154 inline unsigned int get_eta_cell(double eta){ 00155 return (unsigned int) (1 << ((int) (32*((eta-eta_min)/(eta_max-eta_min))))); 00156 } 00157 00159 inline unsigned int get_phi_cell(double phi){ 00160 return (unsigned int) (1 << ((int) (32*phi/twopi+16)%32)); 00161 } 00162 }; 00163 00168 bool is_range_overlap(const Ceta_phi_range &r1, const Ceta_phi_range &r2); 00169 00175 const Ceta_phi_range range_union(const Ceta_phi_range &r1, const Ceta_phi_range &r2); 00176 00177 } 00178 00179 #endif