FastJet 3.5.0
Loading...
Searching...
No Matches
Dnn2piCylinder.cc
1//FJSTARTHEADER
2// $Id$
3//
4// Copyright (c) 2005-2025, 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#include <set>
35#include "fastjet/internal/Dnn2piCylinder.hh"
36using namespace std;
37
38FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
39
40//----------------------------------------------------------------------
41/// initialiser...
42Dnn2piCylinder::Dnn2piCylinder(
43 const vector<EtaPhi> & input_points,
44 const bool & ignore_nearest_is_mirror,
45 const bool & verbose) {
46
47 _verbose = verbose;
48 _ignore_nearest_is_mirror = ignore_nearest_is_mirror;
49 vector<EtaPhi> plane_points;
50 vector<int> plane_point_indices(input_points.size());
51 //plane_points.reserve(2*input_points.size());
52
53 for (unsigned int i=0; i < input_points.size(); i++) {
54 _RegisterCylinderPoint(input_points[i], plane_points);
55 plane_point_indices[i] = i;
56 }
57
58 if (_verbose) cout << "============== Preparing _DNN" << endl;
59 _DNN = new DnnPlane(plane_points, verbose);
60
61
62 vector<int> updated_point_indices; // we'll not use information from this
63 _CreateNecessaryMirrorPoints(plane_point_indices,updated_point_indices);
64}
65
66
67//----------------------------------------------------------------------
68/// Actions here are similar to those in the
69/// Dnn3piCylinder::_RegisterCylinderPoint case, however here we do
70/// NOT create the mirror point -- instead we initialise the structure
71/// as if there were no need for the mirror point.
72///
73/// ADDITIONALLY push the cylinder_point onto the vector plane_points.
74void Dnn2piCylinder::_RegisterCylinderPoint (const EtaPhi & cylinder_point,
75 vector<EtaPhi> & plane_points) {
76 double phi = cylinder_point.second;
77 assert(phi >= 0.0 && phi < 2*pi);
78
79 // do main point
80 MirrorVertexInfo mvi;
81 mvi.main_index = _cylinder_index_of_plane_vertex.size();
82 _cylinder_index_of_plane_vertex.push_back(_mirror_info.size());
83 plane_points.push_back(cylinder_point);
84 mvi.mirror_index = INEXISTENT_VERTEX;
85
86 //
87 _mirror_info.push_back(mvi);
88}
89
90
91
92//----------------------------------------------------------------------
93/// For each plane point specified in the vector plane_indices,
94/// establish whether there is a need to create a mirror point
95/// according to the following criteria:
96///
97/// . phi < pi
98/// . mirror does not already exist
99/// . phi < NearestNeighbourDistance
100/// (if this is not true then there is no way that its mirror point
101/// could have a nearer neighbour).
102///
103/// If conditions all hold, then create the mirror point, insert it
104/// into the _DNN structure, adjusting any nearest neighbours, and
105/// return the list of plane points whose nearest neighbours have
106/// changed (this will include the new neighbours that have just been
107/// added)
108void Dnn2piCylinder::_CreateNecessaryMirrorPoints(
109 const vector<int> & plane_indices,
110 vector<int> & updated_plane_points) {
111
112 vector<EtaPhi> new_plane_points;
113
114 for (size_t i = 0; i < plane_indices.size(); i++) {
115
116 int ip = plane_indices[i]; // plane index
117 EtaPhi position = _DNN->etaphi(ip);
118 double phi = position.second;
119
120 //BAD // require phi < pi
121 //BAD if (phi >= pi) {continue;}
122
123 // require absence of mirror
124 int ic = _cylinder_index_of_plane_vertex[ip];
125 if (_mirror_info[ic].mirror_index != INEXISTENT_VERTEX) {continue;}
126
127 //printf("%3d %3d %10.5f %10.5f %3d\n",ic, ip, phi,
128 // _DNN->NearestNeighbourDistance(ip),_DNN->NearestNeighbourIndex(ip));
129
130
131 // check that we are sufficiently close to the border --
132 // i.e. closer than nearest neighbour distance. But RECALL:
133 // nearest neighbourDistance actually returns a squared distance
134 // (this was really stupid on our part -- caused considerable loss
135 // of time ... )
136 double nndist = _DNN->NearestNeighbourDistance(ip);
137 if (phi*phi >= nndist && (twopi-phi)*(twopi-phi) >= nndist) {continue;}
138
139 // now proceed to prepare the point for addition
140 new_plane_points.push_back(_remap_phi(position));
141 _mirror_info[ic].mirror_index = _cylinder_index_of_plane_vertex.size();
142 _cylinder_index_of_plane_vertex.push_back(ic);
143 }
144
145 vector<int> indices_to_remove; // empty
146 vector<int> indices_added; // will be filled as result of call
147 _DNN->RemoveAndAddPoints(indices_to_remove,new_plane_points,indices_added,
148 updated_plane_points);
149
150 // occasionally, addition of points might cause a change in the
151 // nearest neighbour of a point in the 0--pi range? (But should be
152 // impossible -- we add points beyond 2pi, so they can only be
153 // nearest neighbours of points in the range pi--2pi; there is one
154 // exception -- the nearest neighbour of one's self -- but in that
155 // case this will already have been discovered, so there should be
156 // nothing left to do).
157
158 // To be on the safe side, check to see if we have updated points
159 // with phi<pi and no current mirror point. BUT: this check, as
160 // written, only makes sense when the mirror image was created only
161 // beyond 2pi, which is no longer the case. Only apparent
162 // alternative is to run separate insertions for beyond 2pi and
163 // below phi=0, with separate checks in the two cases. But, given
164 // that across a large number of recombinations and events in the
165 // old method (single mirror), we never ran into this problem, it's
166 // probably safe to assume that the arguments given above are OK! So
167 // comment out the check...
168 //NOTNEEDED for (size_t i = 0; i < updated_plane_points.size(); i++) {
169 //NOTNEEDED int ip = updated_plane_points[i];
170 //NOTNEEDED double phi = _DNN->phi(ip);
171 //NOTNEEDED int ic = _cylinder_index_of_plane_vertex[ip];
172 //NOTNEEDED assert (!(phi < pi && _mirror_info[ic].mirror_index == INEXISTENT_VERTEX));
173 //NOTNEEDED }
174 // alternative recursive code
175 //vector<int> extra_updated_plane_points;
176 //_CreateNecessaryMirrorPoints(updated_plane_points,extra_updated_plane_points)
177 //updated_plane_points.push_back(extra_updated_plane_points);
178}
179
180
181
182//----------------------------------------------------------------------
183/// insertion and removal of points
184void Dnn2piCylinder::RemoveAndAddPoints(const vector<int> & indices_to_remove,
185 const vector<EtaPhi> & points_to_add,
186 vector<int> & indices_added,
187 vector<int> & indices_of_updated_neighbours) {
188
189 // translate from "cylinder" indices of points to remove to the
190 // plane indices of points to remove, bearing in mind that sometimes
191 // there are multple plane points to remove.
192 vector<int> plane_indices_to_remove;
193 for (unsigned int i=0; i < indices_to_remove.size(); i++) {
194 MirrorVertexInfo * mvi;
195 mvi = & _mirror_info[indices_to_remove[i]];
196 plane_indices_to_remove.push_back(mvi->main_index);
197 if (mvi->mirror_index != INEXISTENT_VERTEX) {
198 plane_indices_to_remove.push_back(mvi->mirror_index);
199 }
200 }
201
202 // given "cylinder" points to add get hold of the list of
203 // plane-points to add.
204 vector<EtaPhi> plane_points_to_add;
205 indices_added.clear();
206 for (unsigned int i=0; i < points_to_add.size(); i++) {
207 indices_added.push_back(_mirror_info.size());
208 _RegisterCylinderPoint(points_to_add[i], plane_points_to_add);
209 }
210
211 // now get the hard work done (note that we need to supply the
212 // plane_indices_added vector but that we will not actually check
213 // its contents in any way -- the indices_added that is actually
214 // returned has been calculated above).
215 vector<int> updated_plane_neighbours, plane_indices_added;
216 _DNN->RemoveAndAddPoints(plane_indices_to_remove, plane_points_to_add,
217 plane_indices_added, updated_plane_neighbours);
218
219 vector<int> extra_updated_plane_neighbours;
220 _CreateNecessaryMirrorPoints(updated_plane_neighbours,
221 extra_updated_plane_neighbours);
222
223 // extract, from the updated_plane_neighbours, and
224 // extra_updated_plane_neighbours, the set of cylinder neighbours
225 // that have changed
226 set<int> index_set;
227 unsigned int i;
228 for (i=0; i < updated_plane_neighbours.size(); i++) {
229 index_set.insert(
230 _cylinder_index_of_plane_vertex[updated_plane_neighbours[i]]);}
231 for (i=0; i < extra_updated_plane_neighbours.size(); i++) {
232 index_set.insert(
233 _cylinder_index_of_plane_vertex[extra_updated_plane_neighbours[i]]);}
234
235 // decant the set into the vector that needs to be returned
236 indices_of_updated_neighbours.clear();
237 for (set<int>::iterator iter = index_set.begin();
238 iter != index_set.end(); iter++) {
239 indices_of_updated_neighbours.push_back(*iter);
240 }
241}
242
243FASTJET_END_NAMESPACE
244
245#endif // DROP_CGAL