[d7d2da3] | 1 | //STARTHEADER
|
---|
| 2 | // $Id: ClosestPair2DBase.hh 2577 2011-09-13 15:11:38Z salam $
|
---|
| 3 | //
|
---|
| 4 | // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
|
---|
| 5 | //
|
---|
| 6 | //----------------------------------------------------------------------
|
---|
| 7 | // This file is part of FastJet.
|
---|
| 8 | //
|
---|
| 9 | // FastJet is free software; you can redistribute it and/or modify
|
---|
| 10 | // it under the terms of the GNU General Public License as published by
|
---|
| 11 | // the Free Software Foundation; either version 2 of the License, or
|
---|
| 12 | // (at your option) any later version.
|
---|
| 13 | //
|
---|
| 14 | // The algorithms that underlie FastJet have required considerable
|
---|
| 15 | // development and are described in hep-ph/0512210. If you use
|
---|
| 16 | // FastJet as part of work towards a scientific publication, please
|
---|
| 17 | // include a citation to the FastJet paper.
|
---|
| 18 | //
|
---|
| 19 | // FastJet is distributed in the hope that it will be useful,
|
---|
| 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 22 | // GNU General Public License for more details.
|
---|
| 23 | //
|
---|
| 24 | // You should have received a copy of the GNU General Public License
|
---|
| 25 | // along with FastJet. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 26 | //----------------------------------------------------------------------
|
---|
| 27 | //ENDHEADER
|
---|
| 28 |
|
---|
| 29 | #ifndef __FASTJET_CLOSESTPAIR2DBASE__HH__
|
---|
| 30 | #define __FASTJET_CLOSESTPAIR2DBASE__HH__
|
---|
| 31 |
|
---|
| 32 | #include<vector>
|
---|
| 33 | #include "fastjet/internal/base.hh"
|
---|
| 34 |
|
---|
| 35 | FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
|
---|
| 36 |
|
---|
| 37 | //----------------------------------------------------------------------
|
---|
| 38 | /// \if internal_doc
|
---|
| 39 | /// @ingroup internal
|
---|
| 40 | /// \class Coord2D
|
---|
| 41 | /// class for representing 2d coordinates and carrying out some basic
|
---|
| 42 | /// operations on them
|
---|
| 43 | /// \endif
|
---|
| 44 | class Coord2D {
|
---|
| 45 | public:
|
---|
| 46 | double x, y;
|
---|
| 47 |
|
---|
| 48 | Coord2D() {};
|
---|
| 49 |
|
---|
| 50 | Coord2D(double a, double b): x(a), y(b) {};
|
---|
| 51 |
|
---|
| 52 | /// return the vector difference between two coordinates
|
---|
| 53 | Coord2D operator-(const Coord2D & other) const {
|
---|
| 54 | return Coord2D(x - other.x, y - other.y);};
|
---|
| 55 |
|
---|
| 56 | /// return the vector sum between two coordinates
|
---|
| 57 | Coord2D operator+(const Coord2D & other) const {
|
---|
| 58 | return Coord2D(x + other.x, y + other.y);};
|
---|
| 59 |
|
---|
| 60 | /// return the product of the coordinate with the factor
|
---|
| 61 | Coord2D operator*(double factor) const {return Coord2D(factor*x,factor*y);};
|
---|
| 62 | friend Coord2D operator*(double factor, const Coord2D & coord) {
|
---|
| 63 | return Coord2D(factor*coord.x,factor*coord.y);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /// division of each component of coordinate
|
---|
| 67 | Coord2D operator/(double divisor) const {
|
---|
| 68 | return Coord2D(x / divisor, y / divisor);};
|
---|
| 69 |
|
---|
| 70 | /// return the squared distance between two coordinates
|
---|
| 71 | friend double distance2(const Coord2D & a, const Coord2D & b) {
|
---|
| 72 | double dx = a.x - b.x, dy = a.y-b.y;
|
---|
| 73 | return dx*dx+dy*dy;
|
---|
| 74 | };
|
---|
| 75 | /// return the squared distance between two coordinates
|
---|
| 76 | double distance2(const Coord2D & b) const {
|
---|
| 77 | double dx = x - b.x, dy = y-b.y;
|
---|
| 78 | return dx*dx+dy*dy;
|
---|
| 79 | };
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | //----------------------------------------------------------------------
|
---|
| 84 | /// \if internal_doc
|
---|
| 85 | /// @ingroup internal
|
---|
| 86 | /// \class ClosestPair2DBase
|
---|
| 87 | /// abstract base class for finding closest pairs in 2D
|
---|
| 88 | /// \endif
|
---|
| 89 | class ClosestPair2DBase {
|
---|
| 90 | public:
|
---|
| 91 | /// provides the IDs of the closest pair as well as the squared
|
---|
| 92 | /// distance between them
|
---|
| 93 | virtual void closest_pair(unsigned int & ID1, unsigned int & ID2,
|
---|
| 94 | double & distance2) const = 0;
|
---|
| 95 |
|
---|
| 96 | /// removes the entry labelled by ID from the object;
|
---|
| 97 | virtual void remove(unsigned int ID) = 0;
|
---|
| 98 |
|
---|
| 99 | /// inserts the position into the closest pair structure and returns the
|
---|
| 100 | /// ID that has been allocated for the object.
|
---|
| 101 | virtual unsigned int insert(const Coord2D & position) = 0;
|
---|
| 102 |
|
---|
| 103 | /// replaces the specified ID1 and ID2 with something at a new position
|
---|
| 104 | /// assuming that ID1 and ID2 are in sequence wrt position; it returns
|
---|
| 105 | /// the ID of the new object...
|
---|
| 106 | virtual unsigned int replace(unsigned int ID1, unsigned int ID2,
|
---|
| 107 | const Coord2D & position) {
|
---|
| 108 | remove(ID1);
|
---|
| 109 | remove(ID2);
|
---|
| 110 | unsigned new_ID = insert(position);
|
---|
| 111 | return(new_ID);
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | /// replaces IDs_to_remove with points at the new_positions
|
---|
| 115 | /// indicating the IDs allocated to the new points in new_IDs
|
---|
| 116 | virtual void replace_many(const std::vector<unsigned int> & IDs_to_remove,
|
---|
| 117 | const std::vector<Coord2D> & new_positions,
|
---|
| 118 | std::vector<unsigned int> & new_IDs) {
|
---|
| 119 | for(unsigned i = 0; i < IDs_to_remove.size(); i++) {
|
---|
| 120 | remove(IDs_to_remove[i]);}
|
---|
| 121 | new_IDs.resize(0);
|
---|
| 122 | for(unsigned i = 0; i < new_positions.size(); i++) {
|
---|
| 123 | new_IDs.push_back(insert(new_positions[i]));}
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | virtual unsigned int size() = 0;
|
---|
| 127 |
|
---|
| 128 | virtual ~ClosestPair2DBase() {};
|
---|
| 129 |
|
---|
| 130 | };
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | FASTJET_END_NAMESPACE
|
---|
| 134 |
|
---|
| 135 | #endif // __FASTJET_CLOSESTPAIR2DBASE__HH__
|
---|