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