00001
00012 #ifndef JETUTIL_TILEDETAPHIMAP_H
00013 #define JETUTIL_TILEDETAPHIMAP_H
00014
00015
00016 #include <list>
00017 #include <vector>
00018 #include <iostream>
00019
00020 #include <math.h>
00021
00022
00023 #include "JetUtils/JetDistances.h"
00024
00025 namespace JetTiledMap {
00026
00027 struct utils {
00028 static double DR2(double eta1, double phi1, double eta2,double phi2) {
00029 double deta = eta1 - eta2;
00030 static double pi = acos(-1.0);
00031 static double twopi = 2.0*pi;
00032 double dphi = phi1 - phi2;
00033 while ( dphi > pi ) dphi -= twopi;
00034 while ( dphi <= -pi ) dphi += twopi;
00035 return dphi*dphi + deta*deta;
00036 }
00037 };
00038
00039 enum Directions {
00040 N=0, NE,E,SE,S,SW,W,NW
00041 };
00042
00043
00048 template<class POINT, class DIST2>
00049 class Tile : public std::list<POINT> {
00050 public:
00051 typedef typename std::list<POINT> tilecontainerbase_t;
00052 typedef typename tilecontainerbase_t::iterator iterator;
00053 typedef typename tilecontainerbase_t::const_iterator const_iterator;
00054 typedef typename std::vector<POINT> pointvec_t;
00055
00056 Tile(){this->clear();for(int i=0;i<8;i++) m_neighbour[i]=0;}
00057
00059 void fillPointsInDr2(POINT &p, double r2, pointvec_t& points ) const;
00060
00062 static Tile voidTile;
00063 public:
00064 Tile<POINT,DIST2>* m_neighbour[8];
00065 static DIST2 dr2;
00066 POINT center;
00067 };
00068
00069
00070
00071
00079 template<class POINT, class DIST2 = typename POINT::DR2>
00080 class TiledEtaPhiMap {
00081 public:
00082 typedef Tile<POINT, DIST2> tile_t;
00083
00084 public:
00085 TiledEtaPhiMap(): m_etarange(10.0), m_halfetarange(5.), m_size(0) {};
00086 virtual ~TiledEtaPhiMap(){}
00087 void init(double rmax);
00088
00089 void insert(POINT & p);
00090
00092 std::vector<POINT> pointsInDr(POINT &p, double r) const ;
00093
00094 virtual void clear();
00095
00096 virtual void reset(){m_tiles.clear();m_size=0;}
00097
00098 unsigned int size()const {return m_size;} ;
00099
00100 void setEtaRange(double r){m_etarange=r; m_halfetarange = r/2;}
00101
00102 protected:
00103
00104 double m_etarange ;
00105 double m_halfetarange;
00106 double m_rmax;
00107 size_t m_ndivX, m_ndivY;
00108 double m_sizeX,m_sizeY;
00109
00110 unsigned int m_size;
00111
00112
00114 size_t tileIndex(POINT &p) const {
00115
00116 int indx = int( (p.x()+m_halfetarange)/m_sizeX) ;
00117 if(indx<0) indx=0;
00118 if(indx>=static_cast<int>(m_ndivX)) indx=m_ndivX-1;
00119 int indy = int((M_PI-p.y())/m_sizeY);
00120 if(indy>=static_cast<int>(m_ndivY)) indy=m_ndivY-1;
00121
00122 return tileIndex_i(indx,indy);
00123 }
00124
00126 size_t tileIndex_i(int ix, int iy) const {return ix*m_ndivY + iy;};
00127
00128 std::vector<tile_t> m_tiles;
00129
00130 };
00131
00132
00133 }
00134
00135 #include "JetUtils/TiledEtaPhiMap.icc"
00136
00137 #endif