fastjet 2.4.5
DynamicNearestNeighbours.hh
Go to the documentation of this file.
00001 //STARTHEADER
00002 // $Id: DynamicNearestNeighbours.hh 293 2006-08-17 19:38:38Z salam $
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 
00045 //typedef std::pair<double,double> EtaPhi;
00046 
00049 class EtaPhi {
00050 public:
00051   double first, second;
00052   EtaPhi() {}
00053   EtaPhi(double a, double b) {first = a; second = b;}
00055   void sanitize() {    
00056     if (second <  0)     second += twopi; 
00057     if (second >= twopi) second -= twopi;
00058   }
00059 
00060 };
00061 
00064 class DnnError {
00065 public:
00066   // constructors
00067   DnnError() {;};
00068   DnnError(const std::string & message) {
00069     _message = message; std::cerr << message << std::endl;};
00070 
00071   std::string message() const {return _message;};
00072 
00073 private:
00074   std::string _message;
00075 };
00076 
00077 
00089 class DynamicNearestNeighbours {
00090 
00091 public:
00093   //virtual DynamicNearestNeighbours() {};
00094    
00097   //virtual DynamicNearestNeighbours(const std::vector<EtaPhi> &, 
00098   //                               const bool & verbose = false ) = 0;
00099 
00102   virtual int NearestNeighbourIndex(const int & ii) const = 0;
00103 
00106   virtual double NearestNeighbourDistance(const int & ii) const = 0;
00107 
00111   virtual bool Valid(const int & index) const = 0;
00112 
00123   virtual void RemoveAndAddPoints(const std::vector<int> & indices_to_remove,
00124                           const std::vector<EtaPhi> & points_to_add,
00125                           std::vector<int> & indices_added,
00126                           std::vector<int> & indices_of_updated_neighbours) = 0;
00127 
00128 
00131   inline void RemovePoint (const int & index,
00132                            std::vector<int> & indices_of_updated_neighbours) {
00133     std::vector<int> indices_added;
00134     std::vector<EtaPhi> points_to_add;
00135     std::vector<int> indices_to_remove(1);
00136     indices_to_remove[0] = index;
00137     RemoveAndAddPoints(indices_to_remove, points_to_add, indices_added,
00138                        indices_of_updated_neighbours
00139                        );};
00140 
00141 
00147   inline void RemoveCombinedAddCombination(
00148                         const int & index1, const int & index2,
00149                         const EtaPhi & newpoint,
00150                         int & index3,
00151                         std::vector<int> & indices_of_updated_neighbours) {
00152     std::vector<int> indices_added(1);
00153     std::vector<EtaPhi> points_to_add(1);
00154     std::vector<int> indices_to_remove(2);
00155     indices_to_remove[0] = index1;
00156     indices_to_remove[1] = index2;
00157     points_to_add[0] = newpoint;
00158     RemoveAndAddPoints(indices_to_remove, points_to_add, indices_added,
00159                        indices_of_updated_neighbours
00160                        );
00161     index3 = indices_added[0];
00162   };
00163 
00165   virtual ~DynamicNearestNeighbours () {}
00166 };
00167   
00168 
00169 FASTJET_END_NAMESPACE
00170 
00171 #endif // __FASTJET_DYNAMICNEARESTNEIGHBOURS_HH__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines