fastjet 2.4.5
|
00001 //STARTHEADER 00002 // $Id: ClosestPair2DBase.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 #ifndef __FASTJET_CLOSESTPAIR2DBASE__HH__ 00032 #define __FASTJET_CLOSESTPAIR2DBASE__HH__ 00033 00034 #include<vector> 00035 #include "fastjet/internal/base.hh" 00036 00037 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 00038 00039 //---------------------------------------------------------------------- 00042 class Coord2D { 00043 public: 00044 double x, y; 00045 00046 Coord2D() {}; 00047 00048 Coord2D(double a, double b): x(a), y(b) {}; 00049 00051 Coord2D operator-(const Coord2D & other) const { 00052 return Coord2D(x - other.x, y - other.y);}; 00053 00055 Coord2D operator+(const Coord2D & other) const { 00056 return Coord2D(x + other.x, y + other.y);}; 00057 00059 Coord2D operator*(double factor) const {return Coord2D(factor*x,factor*y);}; 00060 friend Coord2D operator*(double factor, const Coord2D & coord) { 00061 return Coord2D(factor*coord.x,factor*coord.y); 00062 } 00063 00065 Coord2D operator/(double divisor) const { 00066 return Coord2D(x / divisor, y / divisor);}; 00067 00069 friend double distance2(const Coord2D & a, const Coord2D & b) { 00070 double dx = a.x - b.x, dy = a.y-b.y; 00071 return dx*dx+dy*dy; 00072 }; 00074 double distance2(const Coord2D & b) const { 00075 double dx = x - b.x, dy = y-b.y; 00076 return dx*dx+dy*dy; 00077 }; 00078 }; 00079 00080 00081 //---------------------------------------------------------------------- 00083 class ClosestPair2DBase { 00084 public: 00087 virtual void closest_pair(unsigned int & ID1, unsigned int & ID2, 00088 double & distance2) const = 0; 00089 00091 virtual void remove(unsigned int ID) = 0; 00092 00095 virtual unsigned int insert(const Coord2D & position) = 0; 00096 00100 virtual unsigned int replace(unsigned int ID1, unsigned int ID2, 00101 const Coord2D & position) { 00102 remove(ID1); 00103 remove(ID2); 00104 unsigned new_ID = insert(position); 00105 return(new_ID); 00106 }; 00107 00110 virtual void replace_many(const std::vector<unsigned int> & IDs_to_remove, 00111 const std::vector<Coord2D> & new_positions, 00112 std::vector<unsigned int> & new_IDs) { 00113 for(unsigned i = 0; i < IDs_to_remove.size(); i++) { 00114 remove(IDs_to_remove[i]);} 00115 new_IDs.resize(0); 00116 for(unsigned i = 0; i < new_positions.size(); i++) { 00117 new_IDs.push_back(insert(new_positions[i]));} 00118 } 00119 00120 virtual unsigned int size() = 0; 00121 00122 virtual ~ClosestPair2DBase() {}; 00123 00124 }; 00125 00126 00127 FASTJET_END_NAMESPACE 00128 00129 #endif // __FASTJET_CLOSESTPAIR2DBASE__HH__