Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

fastjet::Dnn2piCylinder Class Reference

class derived from DynamicNearestNeighbours that provides an implementation for the surface of cylinder (using one DnnPlane object spanning 0--2pi). More...

#include <Dnn2piCylinder.hh>

Inheritance diagram for fastjet::Dnn2piCylinder:

Inheritance graph
[legend]
Collaboration diagram for fastjet::Dnn2piCylinder:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Dnn2piCylinder ()
 empty initaliser
 Dnn2piCylinder (const std::vector< EtaPhi > &, const bool &ignore_nearest_is_mirror=false, const bool &verbose=false)
 initialiser...
int NearestNeighbourIndex (const int &ii) const
 Note: one of the difficulties of the 0--2pi mapping is that a point may have its mirror copy as its own nearest neighbour (if no other point is within a distance of 2pi).
double NearestNeighbourDistance (const int &ii) const
 Returns the distance to the nearest neighbour of point labelled by index ii (assumes ii is valid).
bool Valid (const int &index) const
 Returns true iff the given index corresponds to a point that exists in the DNN structure (meaning that it has been added, and not removed in the meantime).
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
 ~Dnn2piCylinder ()

Private Member Functions

EtaPhi _remap_phi (const EtaPhi &point)
 given a phi value in the 0--pi range return one in the 2pi--3pi range; whereas if it is in the pi-2pi range then remap it to be inthe range (-pi)--0.
void _RegisterCylinderPoint (const EtaPhi &cylinder_point, std::vector< EtaPhi > &plane_points)
 Actions here are similar to those in the Dnn3piCylinder::_RegisterCylinderPoint case, however here we do NOT create the mirror point -- instead we initialise the structure as if there were no need for the mirror point.
void _CreateNecessaryMirrorPoints (const std::vector< int > &plane_indices, std::vector< int > &updated_plane_points)
 For each plane point specified in the vector plane_indices, establish whether there is a need to create a mirror point according to the following criteria:.

Private Attributes

bool _verbose
bool _ignore_nearest_is_mirror
std::vector< MirrorVertexInfo_mirror_info
std::vector< int > _cylinder_index_of_plane_vertex
DnnPlane_DNN

Static Private Attributes

static const int INEXISTENT_VERTEX = -3

Classes

struct  MirrorVertexInfo

Detailed Description

class derived from DynamicNearestNeighbours that provides an implementation for the surface of cylinder (using one DnnPlane object spanning 0--2pi).

Definition at line 46 of file Dnn2piCylinder.hh.


Constructor & Destructor Documentation

fastjet::Dnn2piCylinder::Dnn2piCylinder  )  [inline]
 

empty initaliser

Definition at line 49 of file Dnn2piCylinder.hh.

00049 {}

fastjet::Dnn2piCylinder::Dnn2piCylinder const std::vector< EtaPhi > &  ,
const bool &  ignore_nearest_is_mirror = false,
const bool &  verbose = false
 

initialiser...

NB: this class is more efficient than the plain Dnn4piCylinder class, but can give wrong answers when the nearest neighbour is further away than 2pi (in this case a point's nearest neighbour becomes itself, because it is considered to be a distance 2pi away). For the kt-algorithm (e.g.) this is actually not a problem (the distance need only be accurate when it is less than R), so we can tell the routine to ignore this problem -- alternatively the routine will crash if it detects it occurring (only when finding the nearest neighbour index, not its distance).

Definition at line 41 of file Dnn2piCylinder.cc.

References _CreateNecessaryMirrorPoints(), _DNN, _ignore_nearest_is_mirror, _RegisterCylinderPoint(), and _verbose.

00044                               {
00045   
00046   _verbose = verbose;
00047   _ignore_nearest_is_mirror = ignore_nearest_is_mirror;
00048   vector<EtaPhi> plane_points;
00049   vector<int>    plane_point_indices(input_points.size());
00050   //plane_points.reserve(2*input_points.size());
00051 
00052   for (unsigned int i=0; i < input_points.size(); i++) {
00053     _RegisterCylinderPoint(input_points[i], plane_points);
00054     plane_point_indices[i] = i;
00055   }
00056   
00057   if (_verbose) cout << "============== Preparing _DNN" << endl;
00058   _DNN = new DnnPlane(plane_points, verbose);
00059 
00060 
00061   vector<int> updated_point_indices; // we'll not use information from this
00062   _CreateNecessaryMirrorPoints(plane_point_indices,updated_point_indices);
00063 }

fastjet::Dnn2piCylinder::~Dnn2piCylinder  )  [inline]
 

Definition at line 259 of file Dnn2piCylinder.hh.

References _DNN.

00259                                        {
00260   delete _DNN; 
00261 }


Member Function Documentation

void fastjet::Dnn2piCylinder::_CreateNecessaryMirrorPoints const std::vector< int > &  plane_indices,
std::vector< int > &  updated_plane_points
[private]
 

For each plane point specified in the vector plane_indices, establish whether there is a need to create a mirror point according to the following criteria:.

. phi < pi . mirror does not already exist . phi < NearestNeighbourDistance (if this is not true then there is no way that its mirror point could have a nearer neighbour).

If conditions all hold, then create the mirror point, insert it into the _DNN structure, adjusting any nearest neighbours, and return the list of plane points whose nearest neighbours have changed (this will include the new neighbours that have just been added)

Definition at line 107 of file Dnn2piCylinder.cc.

References _cylinder_index_of_plane_vertex, _DNN, _mirror_info, _remap_phi(), fastjet::DnnPlane::etaphi(), INEXISTENT_VERTEX, fastjet::DnnPlane::NearestNeighbourDistance(), fastjet::DnnPlane::RemoveAndAddPoints(), fastjet::EtaPhi::second, and fastjet::twopi.

Referenced by Dnn2piCylinder(), and RemoveAndAddPoints().

00109                                                               {
00110 
00111   vector<EtaPhi> new_plane_points;
00112 
00113   for (size_t i = 0; i < plane_indices.size(); i++) {
00114 
00115     int ip = plane_indices[i]; // plane index
00116     EtaPhi position = _DNN->etaphi(ip);
00117     double phi = position.second;
00118 
00119     //BAD // require phi < pi
00120     //BAD if (phi >= pi) {continue;}
00121 
00122     // require absence of mirror
00123     int ic = _cylinder_index_of_plane_vertex[ip];
00124     if (_mirror_info[ic].mirror_index != INEXISTENT_VERTEX) {continue;}
00125 
00126     //printf("%3d %3d %10.5f %10.5f %3d\n",ic, ip, phi, 
00127     //     _DNN->NearestNeighbourDistance(ip),_DNN->NearestNeighbourIndex(ip));
00128 
00129 
00130     // check that we are sufficiently close to the border --
00131     // i.e. closer than nearest neighbour distance. But RECALL:
00132     // nearest neighbourDistance actually returns a squared distance
00133     // (this was really stupid on our part -- caused considerable loss
00134     // of time ... )
00135     double nndist = _DNN->NearestNeighbourDistance(ip); 
00136     if (phi*phi >= nndist && (twopi-phi)*(twopi-phi) >= nndist) {continue;}
00137 
00138     // now proceed to prepare the point for addition
00139     new_plane_points.push_back(_remap_phi(position));
00140     _mirror_info[ic].mirror_index = _cylinder_index_of_plane_vertex.size();
00141     _cylinder_index_of_plane_vertex.push_back(ic);
00142   }
00143 
00144   vector<int> indices_to_remove; // empty
00145   vector<int> indices_added;     // will be filled as result of call
00146   _DNN->RemoveAndAddPoints(indices_to_remove,new_plane_points,indices_added, 
00147                            updated_plane_points);
00148 
00149   // occasionally, addition of points might cause a change in the
00150   // nearest neighbour of a point in the 0--pi range? (But should be
00151   // impossible -- we add points beyond 2pi, so they can only be
00152   // nearest neighbours of points in the range pi--2pi; there is one
00153   // exception -- the nearest neighbour of one's self -- but in that
00154   // case this will already have been discovered, so there should be
00155   // nothing left to do). 
00156 
00157   // To be on the safe side, check to see if we have updated points
00158   // with phi<pi and no current mirror point. BUT: this check, as
00159   // written, only makes sense when the mirror image was created only
00160   // beyond 2pi, which is no longer the case. Only apparent
00161   // alternative is to run separate insertions for beyond 2pi and
00162   // below phi=0, with separate checks in the two cases. But, given
00163   // that across a large number of recombinations and events in the
00164   // old method (single mirror), we never ran into this problem, it's
00165   // probably safe to assume that the arguments given above are OK! So
00166   // comment out the check...
00167   //NOTNEEDED for (size_t i = 0; i < updated_plane_points.size(); i++) {
00168   //NOTNEEDED   int ip = updated_plane_points[i];
00169   //NOTNEEDED   double phi  = _DNN->phi(ip);
00170   //NOTNEEDED   int ic = _cylinder_index_of_plane_vertex[ip];
00171   //NOTNEEDED   assert (!(phi < pi && _mirror_info[ic].mirror_index == INEXISTENT_VERTEX));
00172   //NOTNEEDED }
00173   // alternative recursive code
00174   //vector<int> extra_updated_plane_points;
00175   //_CreateNecessaryMirrorPoints(updated_plane_points,extra_updated_plane_points)
00176   //updated_plane_points.push_back(extra_updated_plane_points);
00177 }

void fastjet::Dnn2piCylinder::_RegisterCylinderPoint const EtaPhi cylinder_point,
std::vector< EtaPhi > &  plane_points
[private]
 

Actions here are similar to those in the Dnn3piCylinder::_RegisterCylinderPoint case, however here we do NOT create the mirror point -- instead we initialise the structure as if there were no need for the mirror point.

ADDITIONALLY push the cylinder_point onto the vector plane_points.

Definition at line 73 of file Dnn2piCylinder.cc.

References _cylinder_index_of_plane_vertex, _mirror_info, INEXISTENT_VERTEX, fastjet::Dnn2piCylinder::MirrorVertexInfo::main_index, fastjet::Dnn2piCylinder::MirrorVertexInfo::mirror_index, fastjet::pi, and fastjet::EtaPhi::second.

Referenced by Dnn2piCylinder(), and RemoveAndAddPoints().

00074                                                                             {
00075   double phi = cylinder_point.second;
00076   assert(phi >= 0.0 && phi < 2*pi);
00077   
00078   // do main point
00079   MirrorVertexInfo mvi;
00080   mvi.main_index = _cylinder_index_of_plane_vertex.size();
00081   _cylinder_index_of_plane_vertex.push_back(_mirror_info.size());
00082   plane_points.push_back(cylinder_point);
00083   mvi.mirror_index = INEXISTENT_VERTEX;
00084   
00085   // 
00086   _mirror_info.push_back(mvi);
00087 }

EtaPhi fastjet::Dnn2piCylinder::_remap_phi const EtaPhi point  )  [inline, private]
 

given a phi value in the 0--pi range return one in the 2pi--3pi range; whereas if it is in the pi-2pi range then remap it to be inthe range (-pi)--0.

Definition at line 164 of file Dnn2piCylinder.hh.

References fastjet::EtaPhi::first, fastjet::pi, fastjet::EtaPhi::second, and twopi.

Referenced by _CreateNecessaryMirrorPoints().

00164                                                  {
00165     double phi = point.second;
00166     if (phi < pi) { phi += twopi ;} else {phi -= twopi;}
00167     return EtaPhi(point.first, phi);}

double fastjet::Dnn2piCylinder::NearestNeighbourDistance const int &  ii  )  const [inline, virtual]
 

Returns the distance to the nearest neighbour of point labelled by index ii (assumes ii is valid).

Implements fastjet::DynamicNearestNeighbours.

Definition at line 239 of file Dnn2piCylinder.hh.

References _DNN, _mirror_info, INEXISTENT_VERTEX, and fastjet::DnnPlane::NearestNeighbourDistance().

00239                                                                                 {
00240   int main_index = _mirror_info[current].main_index;
00241   int mirror_index = _mirror_info[current].mirror_index;
00242   if (mirror_index == INEXISTENT_VERTEX ) {
00243     return _DNN->NearestNeighbourDistance(main_index);
00244   } else {
00245     return (
00246         _DNN->NearestNeighbourDistance(main_index) < 
00247         _DNN->NearestNeighbourDistance(mirror_index)) ? 
00248       _DNN->NearestNeighbourDistance(main_index) : 
00249       _DNN->NearestNeighbourDistance(mirror_index) ; 
00250   }
00251  
00252 }

int fastjet::Dnn2piCylinder::NearestNeighbourIndex const int &  current  )  const [inline, virtual]
 

Note: one of the difficulties of the 0--2pi mapping is that a point may have its mirror copy as its own nearest neighbour (if no other point is within a distance of 2pi).

This does not matter for the kt_algorithm with reasonable values of radius, but might matter for a general use of this algorithm -- depending on whether or not the user has initialised the class with instructions to ignore this problem the program will detect and ignore it, or crash.

Implements fastjet::DynamicNearestNeighbours.

Definition at line 214 of file Dnn2piCylinder.hh.

References _cylinder_index_of_plane_vertex, _DNN, _ignore_nearest_is_mirror, _mirror_info, INEXISTENT_VERTEX, fastjet::DnnPlane::NearestNeighbourDistance(), and fastjet::DnnPlane::NearestNeighbourIndex().

00214                                                                           {
00215   int main_index = _mirror_info[current].main_index;
00216   int mirror_index = _mirror_info[current].mirror_index;
00217   int plane_index;
00218   if (mirror_index == INEXISTENT_VERTEX ) {
00219     plane_index = _DNN->NearestNeighbourIndex(main_index);
00220   } else {
00221     plane_index = (
00222         _DNN->NearestNeighbourDistance(main_index) < 
00223         _DNN->NearestNeighbourDistance(mirror_index)) ? 
00224       _DNN->NearestNeighbourIndex(main_index) : 
00225       _DNN->NearestNeighbourIndex(mirror_index) ; 
00226   }
00227   int this_cylinder_index = _cylinder_index_of_plane_vertex[plane_index];
00228   // either the user has acknowledged the fact that they may get the
00229   // mirror copy as the closest point, or crash if it should occur
00230   // that mirror copy is the closest point.
00231   assert(_ignore_nearest_is_mirror || this_cylinder_index != current);
00232   //if (this_cylinder_index == current) {
00233   //  cerr << "WARNING point "<<current<<
00234   //    " has its mirror copy as its own nearest neighbour"<<endl;
00235   //}
00236   return this_cylinder_index;
00237 }

void fastjet::Dnn2piCylinder::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
[virtual]
 

insertion and removal of points

Implements fastjet::DynamicNearestNeighbours.

Definition at line 183 of file Dnn2piCylinder.cc.

References _CreateNecessaryMirrorPoints(), _cylinder_index_of_plane_vertex, _DNN, _mirror_info, _RegisterCylinderPoint(), INEXISTENT_VERTEX, fastjet::Dnn2piCylinder::MirrorVertexInfo::main_index, fastjet::Dnn2piCylinder::MirrorVertexInfo::mirror_index, and fastjet::DnnPlane::RemoveAndAddPoints().

00186                                                                              {
00187 
00188   // translate from "cylinder" indices of points to remove to the
00189   // plane indices of points to remove, bearing in mind that sometimes
00190   // there are multple plane points to remove.
00191   vector<int> plane_indices_to_remove;
00192   for (unsigned int i=0; i < indices_to_remove.size(); i++) {
00193     MirrorVertexInfo * mvi;
00194     mvi = & _mirror_info[indices_to_remove[i]];
00195     plane_indices_to_remove.push_back(mvi->main_index);
00196     if (mvi->mirror_index != INEXISTENT_VERTEX) {
00197       plane_indices_to_remove.push_back(mvi->mirror_index);
00198     }
00199   }
00200 
00201   // given "cylinder" points to add get hold of the list of
00202   // plane-points to add.
00203   vector<EtaPhi> plane_points_to_add;
00204   indices_added.clear();
00205   for (unsigned int i=0; i < points_to_add.size(); i++) {
00206     indices_added.push_back(_mirror_info.size());
00207     _RegisterCylinderPoint(points_to_add[i], plane_points_to_add);
00208   }
00209 
00210   // now get the hard work done (note that we need to supply the
00211   // plane_indices_added vector but that we will not actually check
00212   // its contents in any way -- the indices_added that is actually
00213   // returned has been calculated above).
00214   vector<int> updated_plane_neighbours, plane_indices_added;
00215   _DNN->RemoveAndAddPoints(plane_indices_to_remove, plane_points_to_add,
00216                              plane_indices_added, updated_plane_neighbours);
00217 
00218   vector<int> extra_updated_plane_neighbours;
00219   _CreateNecessaryMirrorPoints(updated_plane_neighbours,
00220                                extra_updated_plane_neighbours);
00221 
00222   // extract, from the updated_plane_neighbours, and
00223   // extra_updated_plane_neighbours, the set of cylinder neighbours
00224   // that have changed
00225   set<int> index_set;
00226   unsigned int i;
00227   for (i=0; i < updated_plane_neighbours.size(); i++) {
00228     index_set.insert(
00229        _cylinder_index_of_plane_vertex[updated_plane_neighbours[i]]);}
00230   for (i=0; i < extra_updated_plane_neighbours.size(); i++) {
00231     index_set.insert(
00232        _cylinder_index_of_plane_vertex[extra_updated_plane_neighbours[i]]);}
00233 
00234   // decant the set into the vector that needs to be returned
00235   indices_of_updated_neighbours.clear();
00236   for (set<int>::iterator iter = index_set.begin(); 
00237        iter != index_set.end(); iter++) {
00238     indices_of_updated_neighbours.push_back(*iter);
00239   }
00240 }

bool fastjet::Dnn2piCylinder::Valid const int &  index  )  const [inline, virtual]
 

Returns true iff the given index corresponds to a point that exists in the DNN structure (meaning that it has been added, and not removed in the meantime).

Implements fastjet::DynamicNearestNeighbours.

Definition at line 254 of file Dnn2piCylinder.hh.

References _DNN, _mirror_info, and fastjet::DnnPlane::Valid().

00254                                                          {
00255   return (_DNN->Valid(_mirror_info[index].main_index));
00256 }


Member Data Documentation

std::vector<int> fastjet::Dnn2piCylinder::_cylinder_index_of_plane_vertex [private]
 

Definition at line 153 of file Dnn2piCylinder.hh.

Referenced by _CreateNecessaryMirrorPoints(), _RegisterCylinderPoint(), NearestNeighbourIndex(), and RemoveAndAddPoints().

DnnPlane* fastjet::Dnn2piCylinder::_DNN [private]
 

Definition at line 159 of file Dnn2piCylinder.hh.

Referenced by _CreateNecessaryMirrorPoints(), Dnn2piCylinder(), NearestNeighbourDistance(), NearestNeighbourIndex(), RemoveAndAddPoints(), Valid(), and ~Dnn2piCylinder().

bool fastjet::Dnn2piCylinder::_ignore_nearest_is_mirror [private]
 

Definition at line 96 of file Dnn2piCylinder.hh.

Referenced by Dnn2piCylinder(), and NearestNeighbourIndex().

std::vector<MirrorVertexInfo> fastjet::Dnn2piCylinder::_mirror_info [private]
 

Definition at line 149 of file Dnn2piCylinder.hh.

Referenced by _CreateNecessaryMirrorPoints(), _RegisterCylinderPoint(), NearestNeighbourDistance(), NearestNeighbourIndex(), RemoveAndAddPoints(), and Valid().

bool fastjet::Dnn2piCylinder::_verbose [private]
 

Definition at line 94 of file Dnn2piCylinder.hh.

Referenced by Dnn2piCylinder().

const int fastjet::Dnn2piCylinder::INEXISTENT_VERTEX = -3 [static, private]
 

Definition at line 92 of file Dnn2piCylinder.hh.

Referenced by _CreateNecessaryMirrorPoints(), _RegisterCylinderPoint(), NearestNeighbourDistance(), NearestNeighbourIndex(), and RemoveAndAddPoints().


The documentation for this class was generated from the following files:
Generated on Mon Apr 2 20:58:21 2007 for fastjet by  doxygen 1.4.2