FastJet 3.5.0
Loading...
Searching...
No Matches
Dnn3piCylinder.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/Dnn3piCylinder.hh"
36using namespace std;
37
38FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
39
40//----------------------------------------------------------------------
41/// initialiser...
42Dnn3piCylinder::Dnn3piCylinder(
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 //plane_points.reserve(2*input_points.size());
51
52 for (unsigned int i=0; i < input_points.size(); i++) {
53 _RegisterCylinderPoint(input_points[i], plane_points);
54 }
55
56 if (_verbose) cout << "============== Preparing _DNN" << endl;
57 _DNN = new DnnPlane(plane_points, verbose);
58}
59
60
61//----------------------------------------------------------------------
62/// What on earth does this do?
63///
64/// Example: last true "cylinder" index was 15
65/// last plane index was 23
66///
67/// Then: _cylinder_index_of_plane_vertex.size() = 24 and
68/// _mirror_info.size() = 16
69///
70/// IF cylinder_point's phi < pi then
71/// create: _mirror_info[16] = (main_index = 24, mirror_index=25)
72/// _cylinder_index_of_plane_vertex[24] = 16
73/// _cylinder_index_of_plane_vertex[25] = 16
74/// ELSE
75/// create: _mirror_info[16] = (main_index = 24, mirror_index=INEXISTENT..)
76/// _cylinder_index_of_plane_vertex[24] = 16
77///
78/// ADDITIONALLY push the cylinder_point (and if it exists the mirror
79/// copy) onto the vector plane_points.
80void Dnn3piCylinder::_RegisterCylinderPoint (const EtaPhi & cylinder_point,
81 vector<EtaPhi> & plane_points) {
82 double phi = cylinder_point.second;
83 assert(phi >= 0.0 && phi < 2*pi);
84
85 // do main point
86 MirrorVertexInfo mvi;
87 mvi.main_index = _cylinder_index_of_plane_vertex.size();
88 _cylinder_index_of_plane_vertex.push_back(_mirror_info.size());
89 plane_points.push_back(cylinder_point);
90
91 // do mirror point if need be
92 if (phi < pi) {
93 mvi.mirror_index = _cylinder_index_of_plane_vertex.size();
94 _cylinder_index_of_plane_vertex.push_back(_mirror_info.size());
95 plane_points.push_back(_remap_phi(cylinder_point));
96 } else {
97 mvi.mirror_index = INEXISTENT_VERTEX;
98 }
99
100 //
101 _mirror_info.push_back(mvi);
102}
103
104
105//----------------------------------------------------------------------
106/// insertion and removal of points
107void Dnn3piCylinder::RemoveAndAddPoints(const vector<int> & indices_to_remove,
108 const vector<EtaPhi> & points_to_add,
109 vector<int> & indices_added,
110 vector<int> & indices_of_updated_neighbours) {
111
112 // translate from "cylinder" indices of points to remove to the
113 // plane indices of points to remove, bearing in mind that sometimes
114 // there are multple plane points to remove.
115 vector<int> plane_indices_to_remove;
116 for (unsigned int i=0; i < indices_to_remove.size(); i++) {
117 MirrorVertexInfo * mvi;
118 mvi = & _mirror_info[indices_to_remove[i]];
119 plane_indices_to_remove.push_back(mvi->main_index);
120 if (mvi->mirror_index != INEXISTENT_VERTEX) {
121 plane_indices_to_remove.push_back(mvi->mirror_index);
122 }
123 }
124
125 // given "cylinder" points to add get hold of the list of
126 // plane-points to add.
127 vector<EtaPhi> plane_points_to_add;
128 indices_added.clear();
129 for (unsigned int i=0; i < points_to_add.size(); i++) {
130 indices_added.push_back(_mirror_info.size());
131 _RegisterCylinderPoint(points_to_add[i], plane_points_to_add);
132 }
133
134 // now get the hard work done (note that we need to supply the
135 // plane_indices_added vector but that we will not actually check
136 // its contents in any way -- the indices_added that is actually
137 // returned has been calculated above).
138 vector<int> updated_plane_neighbours, plane_indices_added;
139 _DNN->RemoveAndAddPoints(plane_indices_to_remove, plane_points_to_add,
140 plane_indices_added, updated_plane_neighbours);
141
142 // extract, from the updated_plane_neighbours, the set of cylinder
143 // neighbours that have changed
144 set<int> index_set;
145 unsigned int i;
146 for (i=0; i < updated_plane_neighbours.size(); i++) {
147 index_set.insert(
148 _cylinder_index_of_plane_vertex[updated_plane_neighbours[i]]);}
149
150 // decant the set into the vector that needs to be returned
151 indices_of_updated_neighbours.clear();
152 for (set<int>::iterator iter = index_set.begin();
153 iter != index_set.end(); iter++) {
154 indices_of_updated_neighbours.push_back(*iter);
155 }
156}
157
158
159FASTJET_END_NAMESPACE
160
161#endif // DROP_CGAL
162