00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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