fastjet 2.4.5
Dnn2piCylinder.hh
Go to the documentation of this file.
00001 //STARTHEADER
00002 // $Id: Dnn2piCylinder.hh 431 2007-01-20 10:44:55Z salam $
00003 //
00004 // Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam
00005 //
00006 //----------------------------------------------------------------------
00007 // This file is part of FastJet.
00008 //
00009 //  FastJet is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU General Public License as published by
00011 //  the Free Software Foundation; either version 2 of the License, or
00012 //  (at your option) any later version.
00013 //
00014 //  The algorithms that underlie FastJet have required considerable
00015 //  development and are described in hep-ph/0512210. If you use
00016 //  FastJet as part of work towards a scientific publication, please
00017 //  include a citation to the FastJet paper.
00018 //
00019 //  FastJet is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with FastJet; if not, write to the Free Software
00026 //  Foundation, Inc.:
00027 //      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //----------------------------------------------------------------------
00029 //ENDHEADER
00030 
00031 
00032 #ifndef DROP_CGAL // in case we do not have the code for CGAL
00033 #ifndef __FASTJET_DNN2PICYLINDER_HH__
00034 #define __FASTJET_DNN2PICYLINDER_HH__
00035 
00036 #include "fastjet/internal/DynamicNearestNeighbours.hh"
00037 #include "fastjet/internal/DnnPlane.hh"
00038 #include "fastjet/internal/numconsts.hh"
00039 
00040 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00041 
00042 
00046 class Dnn2piCylinder : public DynamicNearestNeighbours {
00047  public:
00049   Dnn2piCylinder() {}
00050 
00065   Dnn2piCylinder(const std::vector<EtaPhi> &,
00066                  const bool & ignore_nearest_is_mirror = false,
00067                  const bool & verbose = false );
00068 
00071   int NearestNeighbourIndex(const int & ii) const ;
00072 
00075   double NearestNeighbourDistance(const int & ii) const ;
00076 
00080   bool Valid(const int & index) const;
00081 
00082   void RemoveAndAddPoints(const std::vector<int> & indices_to_remove,
00083                           const std::vector<EtaPhi> & points_to_add,
00084                           std::vector<int> & indices_added,
00085                           std::vector<int> & indices_of_updated_neighbours);
00086 
00087   ~Dnn2piCylinder();
00088 
00089  private:
00090 
00091   // our extras to help us navigate, find distance, etc.
00092   const static int INEXISTENT_VERTEX=-3;
00093 
00094   bool _verbose;
00095 
00096   bool _ignore_nearest_is_mirror;
00097 
00134 
00136   struct MirrorVertexInfo {
00141     int main_index; 
00144     int mirror_index; 
00145   };
00146 
00147   // for each "true" vertex we have reference to indices in the euclidean
00148   // plane structure
00149   std::vector<MirrorVertexInfo> _mirror_info;
00150   // for each index in the euclidean 0--2pi plane structure we want to
00151   // be able to get back to the "true" vertex index on the overall
00152   // 0--2pi cylinder structure
00153   std::vector<int> _cylinder_index_of_plane_vertex;
00154 
00155   // NB: we define POINTERS here because the initialisation gave
00156   //     us problems (things crashed!), perhaps because in practice
00157   //     we were making a copy without being careful and defining
00158   //     a proper copy constructor.
00159   DnnPlane * _DNN;
00160 
00164   inline EtaPhi _remap_phi(const EtaPhi & point) {
00165     double phi = point.second;
00166     if (phi < pi) { phi += twopi ;} else {phi -= twopi;}
00167     return EtaPhi(point.first, phi);}
00168 
00169 
00170   //----------------------------------------------------------------------
00177   void _RegisterCylinderPoint (const EtaPhi & cylinder_point,
00178                                std::vector<EtaPhi> & plane_points);
00179 
00195   void _CreateNecessaryMirrorPoints(
00196                           const std::vector<int> & plane_indices,
00197                           std::vector<int> & updated_plane_points);
00198 
00199 };
00200 
00201 
00202 // here follow some inline implementations of the simpler of the
00203 // functions defined above
00204 
00205 //----------------------------------------------------------------------
00214 inline int Dnn2piCylinder::NearestNeighbourIndex(const int & current) const {
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 }
00238 
00239 inline double Dnn2piCylinder::NearestNeighbourDistance(const int & current) const {
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 }
00253 
00254 inline bool Dnn2piCylinder::Valid(const int & index) const {
00255   return (_DNN->Valid(_mirror_info[index].main_index));
00256 }
00257 
00258 
00259 inline Dnn2piCylinder::~Dnn2piCylinder() {
00260   delete _DNN; 
00261 }
00262 
00263 
00264 FASTJET_END_NAMESPACE
00265 
00266 #endif //  __FASTJET_DNN2PICYLINDER_HH__
00267 #endif //DROP_CGAL 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines