Fork me on GitHub

source: svn/trunk/Utilities/Fastjet/include/fastjet/internal/DnnPlane.hh@ 191

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

Fastjet added; CDFCones directory has been changed

File size: 5.7 KB
Line 
1//STARTHEADER
2// $Id: DnnPlane.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
32#ifndef DROP_CGAL // in case we do not have the code for CGAL
33
34#ifndef __FASTJET_DNNPLANE_HH__
35#define __FASTJET_DNNPLANE_HH__
36
37#include "fastjet/internal/Triangulation.hh"
38#include "fastjet/internal/DynamicNearestNeighbours.hh"
39
40FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
41
42
43/// class derived from DynamicNearestNeighbours that provides an
44/// implementation for the Euclidean plane
45class DnnPlane : public DynamicNearestNeighbours {
46 public:
47 /// empty initaliser
48 DnnPlane() {}
49
50 /// Initialiser from a set of points on an Eta-Phi plane, where both
51 /// eta and phi can have arbitrary ranges
52 DnnPlane(const std::vector<EtaPhi> &, const bool & verbose = false );
53
54
55 /// Returns the index of the nearest neighbour of point labelled
56 /// by ii (assumes ii is valid)
57 int NearestNeighbourIndex(const int & ii) const ;
58
59 /// Returns the distance to the nearest neighbour of point labelled
60 /// by index ii (assumes ii is valid)
61 double NearestNeighbourDistance(const int & ii) const ;
62
63 /// Returns true iff the given index corresponds to a point that
64 /// exists in the DNN structure (meaning that it has been added, and
65 /// not removed in the meantime)
66 bool Valid(const int & index) const;
67
68 void RemoveAndAddPoints(const std::vector<int> & indices_to_remove,
69 const std::vector<EtaPhi> & points_to_add,
70 std::vector<int> & indices_added,
71 std::vector<int> & indices_of_updated_neighbours);
72
73 /// returns the EtaPhi of point with index i.
74 EtaPhi etaphi(const int i) const;
75 /// returns the eta point with index i.
76 double eta(const int i) const;
77 /// returns the phi point with index i.
78 double phi(const int i) const;
79
80 private:
81
82 /// Structure containing a vertex_handle and cached information on
83 /// the nearest neighbour.
84 struct SuperVertex {
85 Vertex_handle vertex; // NULL indicates inexistence...
86 double NNdistance;
87 int NNindex;
88 // later on for cylinder put a second vertex?
89 };
90
91 std::vector<SuperVertex> _supervertex;
92 //set<Vertex_handle> _vertex_set;
93 bool _verbose;
94
95 static const bool _crash_on_coincidence = true;
96 //static const bool _crash_on_coincidence = false;
97
98 Triangulation _TR; /// CGAL object for dealing with triangulations
99
100 /// calculates and returns the euclidean distance between points p1
101 /// and p2
102 inline double _euclid_distance(const Point& p1, const Point& p2) const {
103 double distx= p1.x()-p2.x();
104 double disty= p1.y()-p2.y();
105 return distx*distx+disty*disty;
106 }
107
108 //----------------------------------------------------------------------
109 /// Determines the index and distance of the nearest neighbour to
110 /// point j and puts the information into the _supervertex entry for j
111 void _SetNearest(const int & j);
112
113 //----------------------------------------------------------------------
114 /// Determines and stores the nearest neighbour of j.
115 ///
116 /// For each voronoi neighbour D of j if the distance between j and D
117 /// is less than D's own nearest neighbour, then update the
118 /// nearest-neighbour info in D; push D's index onto
119 /// indices_of_updated_neighbours
120 ///
121 /// Note that j is NOT pushed onto indices_of_updated_neighbours --
122 /// if you want it there, put it there yourself.
123 void _SetAndUpdateNearest(const int & j,
124 std::vector<int> & indices_of_updated_neighbours);
125
126 /// given a vertex_handle returned by CGAL on insertion of a new
127 /// points, crash if it turns out that it corresponds to a vertex
128 /// that we already knew about (usually because two points coincide)
129 void _CrashIfVertexPresent(const Vertex_handle & vertex,
130 const int & its_index);
131
132};
133
134
135// here follow some inline implementations of the simpler of the
136// functions defined above
137
138inline int DnnPlane::NearestNeighbourIndex(const int & ii) const {
139 return _supervertex[ii].NNindex;}
140
141inline double DnnPlane::NearestNeighbourDistance(const int & ii) const {
142 return _supervertex[ii].NNdistance;}
143
144inline bool DnnPlane::Valid(const int & index) const {
145 if (index >= 0 && index < static_cast<int>(_supervertex.size())) {
146 return (_supervertex[index].vertex != NULL);} else {return false;} }
147
148inline EtaPhi DnnPlane::etaphi(const int i) const {
149 Point * p = & (_supervertex[i].vertex->point());
150 return EtaPhi(p->x(),p->y()); }
151
152inline double DnnPlane::eta(const int i) const {
153 return _supervertex[i].vertex->point().x(); }
154
155inline double DnnPlane::phi(const int i) const {
156 return _supervertex[i].vertex->point().y(); }
157
158
159FASTJET_END_NAMESPACE
160
161#endif // __FASTJET_DNNPLANE_HH__
162
163#endif // DROP_CGAL
Note: See TracBrowser for help on using the repository browser.