FastJet 3.0beta1
|
00001 //STARTHEADER 00002 // $Id: DnnPlane.hh 1761 2010-09-16 10:43:18Z soyez $ 00003 // 00004 // Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam 00005 // 00006 //---------------------------------------------------------------------- 00007 // This file is part of FastJet. 00008 // 00009 // FastJet is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 2 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // The algorithms that underlie FastJet have required considerable 00015 // development and are described in hep-ph/0512210. If you use 00016 // FastJet as part of work towards a scientific publication, please 00017 // include a citation to the FastJet paper. 00018 // 00019 // FastJet is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with FastJet; if not, write to the Free Software 00026 // Foundation, Inc.: 00027 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 //---------------------------------------------------------------------- 00029 //ENDHEADER 00030 00031 00032 #ifndef DROP_CGAL // in case we do not have the code for CGAL 00033 00034 #ifndef __FASTJET_DNNPLANE_HH__ 00035 #define __FASTJET_DNNPLANE_HH__ 00036 00037 #include "fastjet/internal/Triangulation.hh" 00038 #include "fastjet/internal/DynamicNearestNeighbours.hh" 00039 00040 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 00041 00042 00043 /// \if internal_doc 00044 /// @ingroup internal 00045 /// \class DnnPlane 00046 /// class derived from DynamicNearestNeighbours that provides an 00047 /// implementation for the Euclidean plane 00048 /// \endif 00049 class DnnPlane : public DynamicNearestNeighbours { 00050 public: 00051 /// empty initaliser 00052 DnnPlane() {} 00053 00054 /// Initialiser from a set of points on an Eta-Phi plane, where both 00055 /// eta and phi can have arbitrary ranges 00056 DnnPlane(const std::vector<EtaPhi> &, const bool & verbose = false ); 00057 00058 00059 /// Returns the index of the nearest neighbour of point labelled 00060 /// by ii (assumes ii is valid) 00061 int NearestNeighbourIndex(const int & ii) const ; 00062 00063 /// Returns the distance to the nearest neighbour of point labelled 00064 /// by index ii (assumes ii is valid) 00065 double NearestNeighbourDistance(const int & ii) const ; 00066 00067 /// Returns true iff the given index corresponds to a point that 00068 /// exists in the DNN structure (meaning that it has been added, and 00069 /// not removed in the meantime) 00070 bool Valid(const int & index) const; 00071 00072 void RemoveAndAddPoints(const std::vector<int> & indices_to_remove, 00073 const std::vector<EtaPhi> & points_to_add, 00074 std::vector<int> & indices_added, 00075 std::vector<int> & indices_of_updated_neighbours); 00076 00077 /// returns the EtaPhi of point with index i. 00078 EtaPhi etaphi(const int i) const; 00079 /// returns the eta point with index i. 00080 double eta(const int i) const; 00081 /// returns the phi point with index i. 00082 double phi(const int i) const; 00083 00084 private: 00085 00086 /// Structure containing a vertex_handle and cached information on 00087 /// the nearest neighbour. 00088 struct SuperVertex { 00089 Vertex_handle vertex; // NULL indicates inexistence... 00090 double NNdistance; 00091 int NNindex; 00092 // later on for cylinder put a second vertex? 00093 }; 00094 00095 std::vector<SuperVertex> _supervertex; 00096 //set<Vertex_handle> _vertex_set; 00097 bool _verbose; 00098 00099 static const bool _crash_on_coincidence = true; 00100 //static const bool _crash_on_coincidence = false; 00101 00102 Triangulation _TR; /// CGAL object for dealing with triangulations 00103 00104 /// calculates and returns the euclidean distance between points p1 00105 /// and p2 00106 inline double _euclid_distance(const Point& p1, const Point& p2) const { 00107 double distx= p1.x()-p2.x(); 00108 double disty= p1.y()-p2.y(); 00109 return distx*distx+disty*disty; 00110 } 00111 00112 //---------------------------------------------------------------------- 00113 /// Determines the index and distance of the nearest neighbour to 00114 /// point j and puts the information into the _supervertex entry for j 00115 void _SetNearest(const int & j); 00116 00117 //---------------------------------------------------------------------- 00118 /// Determines and stores the nearest neighbour of j. 00119 /// 00120 /// For each voronoi neighbour D of j if the distance between j and D 00121 /// is less than D's own nearest neighbour, then update the 00122 /// nearest-neighbour info in D; push D's index onto 00123 /// indices_of_updated_neighbours 00124 /// 00125 /// Note that j is NOT pushed onto indices_of_updated_neighbours -- 00126 /// if you want it there, put it there yourself. 00127 void _SetAndUpdateNearest(const int & j, 00128 std::vector<int> & indices_of_updated_neighbours); 00129 00130 /// given a vertex_handle returned by CGAL on insertion of a new 00131 /// points, crash if it turns out that it corresponds to a vertex 00132 /// that we already knew about (usually because two points coincide) 00133 void _CrashIfVertexPresent(const Vertex_handle & vertex, 00134 const int & its_index); 00135 00136 }; 00137 00138 00139 // here follow some inline implementations of the simpler of the 00140 // functions defined above 00141 00142 inline int DnnPlane::NearestNeighbourIndex(const int & ii) const { 00143 return _supervertex[ii].NNindex;} 00144 00145 inline double DnnPlane::NearestNeighbourDistance(const int & ii) const { 00146 return _supervertex[ii].NNdistance;} 00147 00148 inline bool DnnPlane::Valid(const int & index) const { 00149 if (index >= 0 && index < static_cast<int>(_supervertex.size())) { 00150 return (_supervertex[index].vertex != NULL);} else {return false;} } 00151 00152 inline EtaPhi DnnPlane::etaphi(const int i) const { 00153 Point * p = & (_supervertex[i].vertex->point()); 00154 return EtaPhi(p->x(),p->y()); } 00155 00156 inline double DnnPlane::eta(const int i) const { 00157 return _supervertex[i].vertex->point().x(); } 00158 00159 inline double DnnPlane::phi(const int i) const { 00160 return _supervertex[i].vertex->point().y(); } 00161 00162 00163 FASTJET_END_NAMESPACE 00164 00165 #endif // __FASTJET_DNNPLANE_HH__ 00166 00167 #endif // DROP_CGAL