31#include "fastjet/config.h"
35#include "fastjet/internal/Dnn2piCylinder.hh"
38FASTJET_BEGIN_NAMESPACE
42Dnn2piCylinder::Dnn2piCylinder(
43 const vector<EtaPhi> & input_points,
44 const bool & ignore_nearest_is_mirror,
45 const bool & verbose) {
48 _ignore_nearest_is_mirror = ignore_nearest_is_mirror;
49 vector<EtaPhi> plane_points;
50 vector<int> plane_point_indices(input_points.size());
53 for (
unsigned int i=0; i < input_points.size(); i++) {
54 _RegisterCylinderPoint(input_points[i], plane_points);
55 plane_point_indices[i] = i;
58 if (_verbose) cout <<
"============== Preparing _DNN" << endl;
59 _DNN =
new DnnPlane(plane_points, verbose);
62 vector<int> updated_point_indices;
63 _CreateNecessaryMirrorPoints(plane_point_indices,updated_point_indices);
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);
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;
87 _mirror_info.push_back(mvi);
108void Dnn2piCylinder::_CreateNecessaryMirrorPoints(
109 const vector<int> & plane_indices,
110 vector<int> & updated_plane_points) {
112 vector<EtaPhi> new_plane_points;
114 for (
size_t i = 0; i < plane_indices.size(); i++) {
116 int ip = plane_indices[i];
117 EtaPhi position = _DNN->etaphi(ip);
118 double phi = position.second;
124 int ic = _cylinder_index_of_plane_vertex[ip];
125 if (_mirror_info[ic].mirror_index != INEXISTENT_VERTEX) {
continue;}
136 double nndist = _DNN->NearestNeighbourDistance(ip);
137 if (phi*phi >= nndist && (twopi-phi)*(twopi-phi) >= nndist) {
continue;}
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);
145 vector<int> indices_to_remove;
146 vector<int> indices_added;
147 _DNN->RemoveAndAddPoints(indices_to_remove,new_plane_points,indices_added,
148 updated_plane_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) {
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);
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);
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);
219 vector<int> extra_updated_plane_neighbours;
220 _CreateNecessaryMirrorPoints(updated_plane_neighbours,
221 extra_updated_plane_neighbours);
228 for (i=0; i < updated_plane_neighbours.size(); i++) {
230 _cylinder_index_of_plane_vertex[updated_plane_neighbours[i]]);}
231 for (i=0; i < extra_updated_plane_neighbours.size(); i++) {
233 _cylinder_index_of_plane_vertex[extra_updated_plane_neighbours[i]]);}
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);