FastJet
3.5.2
Toggle main menu visibility
Loading...
Searching...
No Matches
include
fastjet
internal
Dnn3piCylinder.hh
1
//FJSTARTHEADER
2
// $Id$
3
//
4
// Copyright (c) 2005-2026, 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. They are described in the original FastJet paper,
16
// hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
17
// FastJet as part of work towards a scientific publication, please
18
// quote the version you use and include a citation to the manual and
19
// optionally also to hep-ph/0512210.
20
//
21
// FastJet is distributed in the hope that it will be useful,
22
// but WITHOUT ANY WARRANTY; without even the implied warranty of
23
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
// GNU General Public License for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with FastJet. If not, see <http://www.gnu.org/licenses/>.
28
//----------------------------------------------------------------------
29
//FJENDHEADER
30
31
#include "fastjet/config.h"
32
33
#ifndef DROP_CGAL
// in case we do not have the code for CGAL
34
#ifndef __FASTJET_DNN3PICYLINDER_HH__
35
#define __FASTJET_DNN3PICYLINDER_HH__
36
37
#include "fastjet/internal/DynamicNearestNeighbours.hh"
38
#include "fastjet/internal/DnnPlane.hh"
39
#include "fastjet/internal/numconsts.hh"
40
41
FASTJET_BEGIN_NAMESPACE
// defined in fastjet/internal/base.hh
42
43
/// \if internal_doc
44
/// @ingroup internal
45
/// \class Dnn3piCylinder
46
/// class derived from DynamicNearestNeighbours that provides an
47
/// implementation for the surface of cylinder (using one
48
/// DnnPlane object spanning 0--3pi).
49
/// \endif
50
class
Dnn3piCylinder
:
public
DynamicNearestNeighbours
{
51
public
:
52
/// empty initaliser
53
Dnn3piCylinder
() {}
54
55
/// Initialiser from a set of points on an Eta-Phi plane, where
56
/// eta can have an arbitrary ranges and phi must be in range
57
/// 0 <= phi < 2pi;
58
///
59
/// NB: this class is more efficient than the plain Dnn4piCylinder
60
/// class, but can give wrong answers when the nearest neighbour is
61
/// further away than 2pi (in this case a point's nearest neighbour
62
/// becomes itself, because it is considered to be a distance 2pi
63
/// away). For the kt-algorithm (e.g.) this is actually not a
64
/// problem (the distance need only be accurate when it is less than
65
/// R), so we can tell the routine to ignore this problem --
66
/// alternatively the routine will crash if it detects it occurring
67
/// (only when finding the nearest neighbour index, not its
68
/// distance).
69
Dnn3piCylinder
(
const
std::vector<EtaPhi> &,
70
const
bool
& ignore_nearest_is_mirror =
false
,
71
const
bool
& verbose =
false
);
72
73
/// Returns the index of the nearest neighbour of point labelled
74
/// by ii (assumes ii is valid)
75
int
NearestNeighbourIndex
(
const
int
ii)
const
;
76
77
/// Returns the distance to the nearest neighbour of point labelled
78
/// by index ii (assumes ii is valid)
79
double
NearestNeighbourDistance
(
const
int
ii)
const
;
80
81
/// Returns true iff the given index corresponds to a point that
82
/// exists in the DNN structure (meaning that it has been added, and
83
/// not removed in the meantime)
84
bool
Valid
(
const
int
index)
const
;
85
86
void
RemoveAndAddPoints
(
const
std::vector<int> & indices_to_remove,
87
const
std::vector<EtaPhi> & points_to_add,
88
std::vector<int> & indices_added,
89
std::vector<int> & indices_of_updated_neighbours);
90
91
~Dnn3piCylinder
();
92
93
private
:
94
95
// our extras to help us navigate, find distance, etc.
96
FASTJET_WINDLL
const
static
int
INEXISTENT_VERTEX=-3;
97
98
bool
_verbose;
99
100
bool
_ignore_nearest_is_mirror;
101
102
/// Picture of how things will work... Copy 0--pi part of the 0--2pi
103
/// cylinder into a region 2pi--3pi of a Euclidean plane. Below we
104
/// show points labelled by + that have a mirror image in this
105
/// manner, while points labelled by * do not have a mirror image.
106
///
107
/// | . |
108
/// | . |
109
/// | . |
110
/// | . |
111
/// | 2 . |
112
/// | * . |
113
/// | + . + |
114
/// | 0 . 1 |
115
/// | . |
116
/// 0 2pi 3pi
117
///
118
/// Each "true" point has its true "cylinder" index (the index that
119
/// is known externally to this class) as well as euclidean plane
120
/// indices (main_index and mirror index in the MirrorVertexInfo
121
/// structure), which are private concepts of this class.
122
///
123
/// In above picture our structures would hold the following info
124
/// (the picture shows the euclidean-plane numbering)
125
///
126
/// _mirror_info[cylinder_index = 0] = (0, 1)
127
/// _mirror_info[cylinder_index = 1] = (2, INEXISTENT_VERTEX)
128
///
129
/// We also need to be able to go from the euclidean plane indices
130
/// back to the "true" cylinder index, and for this purpose we use
131
/// the vector _cylinder_index_of_plane_vertex[...], which in the above example has
132
/// the following contents
133
///
134
/// _cylinder_index_of_plane_vertex[0] = 0
135
/// _cylinder_index_of_plane_vertex[1] = 0
136
/// _cylinder_index_of_plane_vertex[2] = 1
137
///
138
139
///
140
struct
MirrorVertexInfo {
141
/// index of the given point (appearing in the range 0--2pi) in the
142
/// 0--3pi euclidean plane structure (position will coincide with
143
/// that on the 0--2pi cylinder, but index labelling it will be
144
/// different)
145
int
main_index;
146
/// index of the mirror point (appearing in the range 2pi--3pi) in the
147
/// 0--3pi euclidean plane structure
148
int
mirror_index;
149
};
150
151
// for each "true" vertex we have reference to indices in the euclidean
152
// plane structure
153
std::vector<MirrorVertexInfo> _mirror_info;
154
// for each index in the euclidean 0--3pi plane structure we want to
155
// be able to get back to the "true" vertex index on the overall
156
// 0--2pi cylinder structure
157
std::vector<int> _cylinder_index_of_plane_vertex;
158
159
// NB: we define POINTERS here because the initialisation gave
160
// us problems (things crashed!), perhaps because in practice
161
// we were making a copy without being careful and defining
162
// a proper copy constructor.
163
DnnPlane
* _DNN;
164
165
/// given a phi value in the 0--2pi range return one
166
/// in the pi--3pi range.
167
inline
EtaPhi
_remap_phi(
const
EtaPhi
& point) {
168
double
phi = point.second;
169
if
(phi < pi) { phi += twopi ;}
170
return
EtaPhi(point.first, phi);}
171
172
173
//----------------------------------------------------------------------
174
/// What on earth does this do?
175
///
176
/// Example: last true "cylinder" index was 15
177
/// last plane index was 23
178
///
179
/// Then: _cylinder_index_of_plane_vertex.size() = 24 and
180
/// _mirror_info.size() = 16
181
///
182
/// IF cylinder_point's phi < pi then
183
/// create: _mirror_info[16] = (main_index = 24, mirror_index=25)
184
/// _cylinder_index_of_plane_vertex[24] = 16
185
/// _cylinder_index_of_plane_vertex[25] = 16
186
/// ELSE
187
/// create: _mirror_info[16] = (main_index = 24, mirror_index=INEXISTENT..)
188
/// _cylinder_index_of_plane_vertex[24] = 16
189
///
190
/// ADDITIONALLY push the cylinder_point (and if it exists the mirror
191
/// copy) onto the vector plane_points.
192
void
_RegisterCylinderPoint (
const
EtaPhi & cylinder_point,
193
std::vector<EtaPhi> & plane_points);
194
};
195
196
197
// here follow some inline implementations of the simpler of the
198
// functions defined above
199
200
//----------------------------------------------------------------------
201
/// Note: one of the difficulties of the 0--3pi mapping is that
202
/// a point may have its mirror copy as its own nearest neighbour
203
/// (if no other point is within a distance of 2pi). This does
204
/// not matter for the kt_algorithm with
205
/// reasonable values of radius, but might matter for a general use
206
/// of this algorithm -- depending on whether or not the user has
207
/// initialised the class with instructions to ignore this problem the
208
/// program will detect and ignore it, or crash.
209
inline
int
Dnn3piCylinder::NearestNeighbourIndex
(
const
int
current)
const
{
210
int
main_index = _mirror_info[current].main_index;
211
int
mirror_index = _mirror_info[current].mirror_index;
212
int
plane_index;
213
if
(mirror_index == INEXISTENT_VERTEX ) {
214
plane_index = _DNN->NearestNeighbourIndex(main_index);
215
}
else
{
216
plane_index = (
217
_DNN->NearestNeighbourDistance(main_index) <
218
_DNN->NearestNeighbourDistance(mirror_index)) ?
219
_DNN->NearestNeighbourIndex(main_index) :
220
_DNN->NearestNeighbourIndex(mirror_index) ;
221
}
222
int
this_cylinder_index = _cylinder_index_of_plane_vertex[plane_index];
223
// either the user has acknowledged the fact that they may get the
224
// mirror copy as the closest point, or crash if it should occur
225
// that mirror copy is the closest point.
226
assert(_ignore_nearest_is_mirror || this_cylinder_index != current);
227
//if (this_cylinder_index == current) {
228
// std::cerr << "WARNING point "<<current<<
229
// " has its mirror copy as its own nearest neighbour"<<endl;
230
//}
231
return
this_cylinder_index;
232
}
233
234
inline
double
Dnn3piCylinder::NearestNeighbourDistance
(
const
int
current)
const
{
235
int
main_index = _mirror_info[current].main_index;
236
int
mirror_index = _mirror_info[current].mirror_index;
237
if
(mirror_index == INEXISTENT_VERTEX ) {
238
return
_DNN->NearestNeighbourDistance(main_index);
239
}
else
{
240
return
(
241
_DNN->NearestNeighbourDistance(main_index) <
242
_DNN->NearestNeighbourDistance(mirror_index)) ?
243
_DNN->NearestNeighbourDistance(main_index) :
244
_DNN->NearestNeighbourDistance(mirror_index) ;
245
}
246
247
}
248
249
inline
bool
Dnn3piCylinder::Valid
(
const
int
index)
const
{
250
return
(_DNN->Valid(_mirror_info[index].main_index));
251
}
252
253
254
inline
Dnn3piCylinder::~Dnn3piCylinder() {
255
delete
_DNN;
256
}
257
258
259
FASTJET_END_NAMESPACE
260
261
#endif
// __FASTJET_DNN3PICYLINDER_HH__
262
#endif
// DROP_CGAL
fastjet::Dnn3piCylinder::NearestNeighbourIndex
int NearestNeighbourIndex(const int ii) const
Returns the index of the nearest neighbour of point labelled by ii (assumes ii is valid).
Definition
Dnn3piCylinder.hh:209
fastjet::Dnn3piCylinder::Dnn3piCylinder
Dnn3piCylinder(const std::vector< EtaPhi > &, const bool &ignore_nearest_is_mirror=false, const bool &verbose=false)
Initialiser from a set of points on an Eta-Phi plane, where eta can have an arbitrary ranges and phi ...
fastjet::Dnn3piCylinder::RemoveAndAddPoints
void RemoveAndAddPoints(const std::vector< int > &indices_to_remove, const std::vector< EtaPhi > &points_to_add, std::vector< int > &indices_added, std::vector< int > &indices_of_updated_neighbours)
insertion and removal of points
Definition
Dnn3piCylinder.cc:107
fastjet::Dnn3piCylinder::Valid
bool Valid(const int index) const
Returns true iff the given index corresponds to a point that exists in the DNN structure (meaning tha...
Definition
Dnn3piCylinder.hh:249
fastjet::Dnn3piCylinder::Dnn3piCylinder
Dnn3piCylinder()
empty initaliser
Definition
Dnn3piCylinder.hh:53
fastjet::Dnn3piCylinder::NearestNeighbourDistance
double NearestNeighbourDistance(const int ii) const
Returns the distance to the nearest neighbour of point labelled by index ii (assumes ii is valid).
Definition
Dnn3piCylinder.hh:234
fastjet::DnnPlane
Definition
DnnPlane.hh:58
fastjet::DynamicNearestNeighbours
Definition
DynamicNearestNeighbours.hh:98
fastjet::EtaPhi
Shortcut for dealing with eta-phi coordinates.
Definition
DynamicNearestNeighbours.hh:54
Generated on
for FastJet by
1.18.0