FastJet 3.0beta1
|
00001 //STARTHEADER 00002 // $Id: DynamicNearestNeighbours.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 __FASTJET_DYNAMICNEARESTNEIGHBOURS_HH__ 00033 #define __FASTJET_DYNAMICNEARESTNEIGHBOURS_HH__ 00034 00035 #include<vector> 00036 #include<string> 00037 #include<iostream> 00038 #include<sstream> 00039 #include<cassert> 00040 #include "fastjet/internal/numconsts.hh" 00041 00042 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 00043 00044 /// Shortcut for dealing with eta-phi coordinates. 00045 //typedef std::pair<double,double> EtaPhi; 00046 00047 /// \if internal_doc 00048 /// @ingroup internal 00049 /// \class EtaPhi 00050 /// use a class instead of a pair so that phi can be sanitized 00051 /// and put into proper range on initialization. 00052 /// \endif 00053 class EtaPhi { 00054 public: 00055 double first, second; 00056 EtaPhi() {} 00057 EtaPhi(double a, double b) {first = a; second = b;} 00058 /// put things into the desired range. 00059 void sanitize() { 00060 if (second < 0) second += twopi; 00061 if (second >= twopi) second -= twopi; 00062 } 00063 00064 }; 00065 00066 /// \if internal_doc 00067 /// @ingroup internal 00068 /// \class DnnError 00069 /// class corresponding to errors that will be thrown by Dynamic 00070 /// Nearest Neighbours code 00071 /// \endif 00072 class DnnError { 00073 public: 00074 // constructors 00075 DnnError() {;}; 00076 DnnError(const std::string & message) { 00077 _message = message; std::cerr << message << std::endl;}; 00078 00079 std::string message() const {return _message;}; 00080 00081 private: 00082 std::string _message; 00083 }; 00084 00085 00086 /// \if internal_doc 00087 /// @ingroup internal 00088 /// \class DynamicNearestNeighbours 00089 /// Abstract base class for quick location of nearest neighbours in a set of 00090 /// points. 00091 /// 00092 /// Abstract base class for quick location of nearest neighbours in a set of 00093 /// points, with facilities for adding and removing points from the 00094 /// set after initialisation. Derived classes will be 00095 /// named according to the convention DnnSomeName (e.g. DnnPlane). 00096 /// 00097 /// The main purpose of this abstract base class is to define the 00098 /// general interface of a whole set of classes that deal with 00099 /// nearest-neighbour location on different 2-d geometries and with 00100 /// various underlying data structures and algorithms. 00101 /// 00102 /// \endif 00103 class DynamicNearestNeighbours { 00104 00105 public: 00106 /// Dummy initialiser --- does nothing! 00107 //virtual DynamicNearestNeighbours() {}; 00108 00109 /// Initialiser --- sets up the necessary structures to allow efficient 00110 /// nearest-neighbour finding on the std::vector<EtaPhi> of input points 00111 //virtual DynamicNearestNeighbours(const std::vector<EtaPhi> &, 00112 // const bool & verbose = false ) = 0; 00113 00114 /// Returns the index of the nearest neighbour of point labelled 00115 /// by ii (assumes ii is valid) 00116 virtual int NearestNeighbourIndex(const int & ii) const = 0; 00117 00118 /// Returns the distance to the nearest neighbour of point labelled 00119 /// by index ii (assumes ii is valid) 00120 virtual double NearestNeighbourDistance(const int & ii) const = 0; 00121 00122 /// Returns true iff the given index corresponds to a point that 00123 /// exists in the DNN structure (meaning that it has been added, and 00124 /// not removed in the meantime) 00125 virtual bool Valid(const int & index) const = 0; 00126 00127 /// remove the points labelled by the std::vector indices_to_remove, and 00128 /// add the points specified by the std::vector points_to_add 00129 /// (corresponding indices will be calculated automatically); the 00130 /// idea behind this routine is that the points to be added will 00131 /// somehow be close to the one or other of the points being removed 00132 /// and this can be used by the implementation to provide hints for 00133 /// inserting the new points in whatever structure it is using. In a 00134 /// kt-algorithm the points being added will be a result of a 00135 /// combination of the points to be removed -- hence the proximity 00136 /// is (more or less) guaranteed. 00137 virtual void RemoveAndAddPoints(const std::vector<int> & indices_to_remove, 00138 const std::vector<EtaPhi> & points_to_add, 00139 std::vector<int> & indices_added, 00140 std::vector<int> & indices_of_updated_neighbours) = 0; 00141 00142 00143 /// Remove the point labelled by index and return the list of 00144 /// points whose nearest neighbours have changed in the process 00145 inline void RemovePoint (const int & index, 00146 std::vector<int> & indices_of_updated_neighbours) { 00147 std::vector<int> indices_added; 00148 std::vector<EtaPhi> points_to_add; 00149 std::vector<int> indices_to_remove(1); 00150 indices_to_remove[0] = index; 00151 RemoveAndAddPoints(indices_to_remove, points_to_add, indices_added, 00152 indices_of_updated_neighbours 00153 );}; 00154 00155 00156 /// Removes the two points labelled by index1, index2 and adds in the 00157 /// a point with coordinates newpoint; it returns an index for the new 00158 /// point (index 3) and a std::vector of indices of neighbours whose 00159 /// nearest neighbour has changed (the list includes index3, i.e. the new 00160 /// point). 00161 inline void RemoveCombinedAddCombination( 00162 const int & index1, const int & index2, 00163 const EtaPhi & newpoint, 00164 int & index3, 00165 std::vector<int> & indices_of_updated_neighbours) { 00166 std::vector<int> indices_added(1); 00167 std::vector<EtaPhi> points_to_add(1); 00168 std::vector<int> indices_to_remove(2); 00169 indices_to_remove[0] = index1; 00170 indices_to_remove[1] = index2; 00171 points_to_add[0] = newpoint; 00172 RemoveAndAddPoints(indices_to_remove, points_to_add, indices_added, 00173 indices_of_updated_neighbours 00174 ); 00175 index3 = indices_added[0]; 00176 }; 00177 00178 /// destructor -- here it is now implemented 00179 virtual ~DynamicNearestNeighbours () {} 00180 }; 00181 00182 00183 FASTJET_END_NAMESPACE 00184 00185 #endif // __FASTJET_DYNAMICNEARESTNEIGHBOURS_HH__