FastJet 3.0.2
|
00001 //STARTHEADER 00002 // $Id: DnnPlane.hh 2577 2011-09-13 15:11:38Z salam $ 00003 // 00004 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez 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, see <http://www.gnu.org/licenses/>. 00026 //---------------------------------------------------------------------- 00027 //ENDHEADER 00028 00029 00030 #ifndef DROP_CGAL // in case we do not have the code for CGAL 00031 00032 #ifndef __FASTJET_DNNPLANE_HH__ 00033 #define __FASTJET_DNNPLANE_HH__ 00034 00035 #include "fastjet/internal/Triangulation.hh" 00036 #include "fastjet/internal/DynamicNearestNeighbours.hh" 00037 00038 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 00039 00040 00041 /// \if internal_doc 00042 /// @ingroup internal 00043 /// \class DnnPlane 00044 /// class derived from DynamicNearestNeighbours that provides an 00045 /// implementation for the Euclidean plane 00046 /// \endif 00047 class DnnPlane : public DynamicNearestNeighbours { 00048 public: 00049 /// empty initaliser 00050 DnnPlane() {} 00051 00052 /// Initialiser from a set of points on an Eta-Phi plane, where both 00053 /// eta and phi can have arbitrary ranges 00054 DnnPlane(const std::vector<EtaPhi> &, const bool & verbose = false ); 00055 00056 00057 /// Returns the index of the nearest neighbour of point labelled 00058 /// by ii (assumes ii is valid) 00059 int NearestNeighbourIndex(const int & ii) const ; 00060 00061 /// Returns the distance to the nearest neighbour of point labelled 00062 /// by index ii (assumes ii is valid) 00063 double NearestNeighbourDistance(const int & ii) const ; 00064 00065 /// Returns true iff the given index corresponds to a point that 00066 /// exists in the DNN structure (meaning that it has been added, and 00067 /// not removed in the meantime) 00068 bool Valid(const int & index) const; 00069 00070 void RemoveAndAddPoints(const std::vector<int> & indices_to_remove, 00071 const std::vector<EtaPhi> & points_to_add, 00072 std::vector<int> & indices_added, 00073 std::vector<int> & indices_of_updated_neighbours); 00074 00075 /// returns the EtaPhi of point with index i. 00076 EtaPhi etaphi(const int i) const; 00077 /// returns the eta point with index i. 00078 double eta(const int i) const; 00079 /// returns the phi point with index i. 00080 double phi(const int i) const; 00081 00082 private: 00083 00084 /// Structure containing a vertex_handle and cached information on 00085 /// the nearest neighbour. 00086 struct SuperVertex { 00087 Vertex_handle vertex; // NULL indicates inexistence... 00088 double NNdistance; 00089 int NNindex; 00090 // later on for cylinder put a second vertex? 00091 }; 00092 00093 std::vector<SuperVertex> _supervertex; 00094 //set<Vertex_handle> _vertex_set; 00095 bool _verbose; 00096 00097 static const bool _crash_on_coincidence = true; 00098 //static const bool _crash_on_coincidence = false; 00099 00100 Triangulation _TR; /// CGAL object for dealing with triangulations 00101 00102 /// calculates and returns the euclidean distance between points p1 00103 /// and p2 00104 inline double _euclid_distance(const Point& p1, const Point& p2) const { 00105 double distx= p1.x()-p2.x(); 00106 double disty= p1.y()-p2.y(); 00107 return distx*distx+disty*disty; 00108 } 00109 00110 //---------------------------------------------------------------------- 00111 /// Determines the index and distance of the nearest neighbour to 00112 /// point j and puts the information into the _supervertex entry for j 00113 void _SetNearest(const int & j); 00114 00115 //---------------------------------------------------------------------- 00116 /// Determines and stores the nearest neighbour of j. 00117 /// 00118 /// For each voronoi neighbour D of j if the distance between j and D 00119 /// is less than D's own nearest neighbour, then update the 00120 /// nearest-neighbour info in D; push D's index onto 00121 /// indices_of_updated_neighbours 00122 /// 00123 /// Note that j is NOT pushed onto indices_of_updated_neighbours -- 00124 /// if you want it there, put it there yourself. 00125 void _SetAndUpdateNearest(const int & j, 00126 std::vector<int> & indices_of_updated_neighbours); 00127 00128 /// given a vertex_handle returned by CGAL on insertion of a new 00129 /// points, crash if it turns out that it corresponds to a vertex 00130 /// that we already knew about (usually because two points coincide) 00131 void _CrashIfVertexPresent(const Vertex_handle & vertex, 00132 const int & its_index); 00133 00134 }; 00135 00136 00137 // here follow some inline implementations of the simpler of the 00138 // functions defined above 00139 00140 inline int DnnPlane::NearestNeighbourIndex(const int & ii) const { 00141 return _supervertex[ii].NNindex;} 00142 00143 inline double DnnPlane::NearestNeighbourDistance(const int & ii) const { 00144 return _supervertex[ii].NNdistance;} 00145 00146 inline bool DnnPlane::Valid(const int & index) const { 00147 if (index >= 0 && index < static_cast<int>(_supervertex.size())) { 00148 return (_supervertex[index].vertex != NULL);} else {return false;} } 00149 00150 inline EtaPhi DnnPlane::etaphi(const int i) const { 00151 Point * p = & (_supervertex[i].vertex->point()); 00152 return EtaPhi(p->x(),p->y()); } 00153 00154 inline double DnnPlane::eta(const int i) const { 00155 return _supervertex[i].vertex->point().x(); } 00156 00157 inline double DnnPlane::phi(const int i) const { 00158 return _supervertex[i].vertex->point().y(); } 00159 00160 00161 FASTJET_END_NAMESPACE 00162 00163 #endif // __FASTJET_DNNPLANE_HH__ 00164 00165 #endif // DROP_CGAL