Fork me on GitHub

source: svn/trunk/Utilities/Fastjet/include/fastjet/internal/ClosestPair2DBase.hh@ 226

Last change on this file since 226 was 11, checked in by severine ovyn, 16 years ago

Fastjet added; CDFCones directory has been changed

File size: 4.5 KB
Line 
1//STARTHEADER
2// $Id: ClosestPair2DBase.hh,v 1.1 2008-11-06 14:32:09 ovyn Exp $
3//
4// Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam
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, write to the Free Software
26// Foundation, Inc.:
27// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28//----------------------------------------------------------------------
29//ENDHEADER
30
31#ifndef __FASTJET_CLOSESTPAIR2DBASE__HH__
32#define __FASTJET_CLOSESTPAIR2DBASE__HH__
33
34#include<vector>
35#include "Utilities/Fastjet/include/fastjet/internal/base.hh"
36
37FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
38
39//----------------------------------------------------------------------
40/// class for representing 2d coordinates and carrying out some basic
41/// operations on them
42class Coord2D {
43public:
44 double x, y;
45
46 Coord2D() {};
47
48 Coord2D(double a, double b): x(a), y(b) {};
49
50 /// return the vector difference between two coordinates
51 Coord2D operator-(const Coord2D & other) const {
52 return Coord2D(x - other.x, y - other.y);};
53
54 /// return the vector sum between two coordinates
55 Coord2D operator+(const Coord2D & other) const {
56 return Coord2D(x + other.x, y + other.y);};
57
58 /// return the product of the coordinate with the factor
59 Coord2D operator*(double factor) const {return Coord2D(factor*x,factor*y);};
60 friend Coord2D operator*(double factor, const Coord2D & coord) {
61 return Coord2D(factor*coord.x,factor*coord.y);
62 }
63
64 /// division of each component of coordinate
65 Coord2D operator/(double divisor) const {
66 return Coord2D(x / divisor, y / divisor);};
67
68 /// return the squared distance between two coordinates
69 friend double distance2(const Coord2D & a, const Coord2D & b) {
70 double dx = a.x - b.x, dy = a.y-b.y;
71 return dx*dx+dy*dy;
72 };
73 /// return the squared distance between two coordinates
74 double distance2(const Coord2D & b) const {
75 double dx = x - b.x, dy = y-b.y;
76 return dx*dx+dy*dy;
77 };
78};
79
80
81//----------------------------------------------------------------------
82/// abstract base class for finding closest pairs in 2D
83class ClosestPair2DBase {
84public:
85 /// provides the IDs of the closest pair as well as the squared
86 /// distance between them
87 virtual void closest_pair(unsigned int & ID1, unsigned int & ID2,
88 double & distance2) const = 0;
89
90 /// removes the entry labelled by ID from the object;
91 virtual void remove(unsigned int ID) = 0;
92
93 /// inserts the position into the closest pair structure and returns the
94 /// ID that has been allocated for the object.
95 virtual unsigned int insert(const Coord2D & position) = 0;
96
97 /// replaces the specified ID1 and ID2 with something at a new position
98 /// assuming that ID1 and ID2 are in sequence wrt position; it returns
99 /// the ID of the new object...
100 virtual unsigned int replace(unsigned int ID1, unsigned int ID2,
101 const Coord2D & position) {
102 remove(ID1);
103 remove(ID2);
104 unsigned new_ID = insert(position);
105 return(new_ID);
106 };
107
108 /// replaces IDs_to_remove with points at the new_positions
109 /// indicating the IDs allocated to the new points in new_IDs
110 virtual void replace_many(const std::vector<unsigned int> & IDs_to_remove,
111 const std::vector<Coord2D> & new_positions,
112 std::vector<unsigned int> & new_IDs) {
113 for(unsigned i = 0; i < IDs_to_remove.size(); i++) {
114 remove(IDs_to_remove[i]);}
115 new_IDs.resize(0);
116 for(unsigned i = 0; i < new_positions.size(); i++) {
117 new_IDs.push_back(insert(new_positions[i]));}
118 }
119
120 virtual unsigned int size() = 0;
121
122 virtual ~ClosestPair2DBase() {};
123
124};
125
126
127FASTJET_END_NAMESPACE
128
129#endif // __FASTJET_CLOSESTPAIR2DBASE__HH__
Note: See TracBrowser for help on using the repository browser.