Dnn3piCylinder.hh

Go to the documentation of this file.
00001 //STARTHEADER
00002 // $Id: Dnn3piCylinder.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_DNN3PICYLINDER_HH__
00034 #define __FASTJET_DNN3PICYLINDER_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 
00045 class Dnn3piCylinder : public DynamicNearestNeighbours {
00046  public:
00048   Dnn3piCylinder() {}
00049 
00064   Dnn3piCylinder(const std::vector<EtaPhi> &,
00065                  const bool & ignore_nearest_is_mirror = false,
00066                  const bool & verbose = false );
00067 
00070   int NearestNeighbourIndex(const int & ii) const ;
00071 
00074   double NearestNeighbourDistance(const int & ii) const ;
00075 
00079   bool Valid(const int & index) const;
00080 
00081   void RemoveAndAddPoints(const std::vector<int> & indices_to_remove,
00082                           const std::vector<EtaPhi> & points_to_add,
00083                           std::vector<int> & indices_added,
00084                           std::vector<int> & indices_of_updated_neighbours);
00085 
00086   ~Dnn3piCylinder();
00087 
00088  private:
00089 
00090   // our extras to help us navigate, find distance, etc.
00091   const static int INEXISTENT_VERTEX=-3;
00092 
00093   bool _verbose;
00094 
00095   bool _ignore_nearest_is_mirror;
00096 
00133 
00135   struct MirrorVertexInfo {
00140     int main_index; 
00143     int mirror_index; 
00144   };
00145 
00146   // for each "true" vertex we have reference to indices in the euclidean
00147   // plane structure
00148   std::vector<MirrorVertexInfo> _mirror_info;
00149   // for each index in the euclidean 0--3pi plane structure we want to
00150   // be able to get back to the "true" vertex index on the overall
00151   // 0--2pi cylinder structure
00152   std::vector<int> _cylinder_index_of_plane_vertex;
00153 
00154   // NB: we define POINTERS here because the initialisation gave
00155   //     us problems (things crashed!), perhaps because in practice
00156   //     we were making a copy without being careful and defining
00157   //     a proper copy constructor.
00158   DnnPlane * _DNN;
00159 
00162   inline EtaPhi _remap_phi(const EtaPhi & point) {
00163     double phi = point.second;
00164     if (phi < pi) { phi += twopi ;}
00165     return EtaPhi(point.first, phi);}
00166 
00167 
00168   //----------------------------------------------------------------------
00187   void _RegisterCylinderPoint (const EtaPhi & cylinder_point,
00188                                std::vector<EtaPhi> & plane_points);
00189 };
00190 
00191 
00192 // here follow some inline implementations of the simpler of the
00193 // functions defined above
00194 
00195 //----------------------------------------------------------------------
00204 inline int Dnn3piCylinder::NearestNeighbourIndex(const int & current) const {
00205   int main_index = _mirror_info[current].main_index;
00206   int mirror_index = _mirror_info[current].mirror_index;
00207   int plane_index;
00208   if (mirror_index == INEXISTENT_VERTEX ) {
00209     plane_index = _DNN->NearestNeighbourIndex(main_index);
00210   } else {
00211     plane_index = (
00212         _DNN->NearestNeighbourDistance(main_index) < 
00213         _DNN->NearestNeighbourDistance(mirror_index)) ? 
00214       _DNN->NearestNeighbourIndex(main_index) : 
00215       _DNN->NearestNeighbourIndex(mirror_index) ; 
00216   }
00217   int this_cylinder_index = _cylinder_index_of_plane_vertex[plane_index];
00218   // either the user has acknowledged the fact that they may get the
00219   // mirror copy as the closest point, or crash if it should occur
00220   // that mirror copy is the closest point.
00221   assert(_ignore_nearest_is_mirror || this_cylinder_index != current);
00222   //if (this_cylinder_index == current) {
00223   //  std::cerr << "WARNING point "<<current<<
00224   //    " has its mirror copy as its own nearest neighbour"<<endl;
00225   //}
00226   return this_cylinder_index;
00227 }
00228 
00229 inline double Dnn3piCylinder::NearestNeighbourDistance(const int & current) const {
00230   int main_index = _mirror_info[current].main_index;
00231   int mirror_index = _mirror_info[current].mirror_index;
00232   if (mirror_index == INEXISTENT_VERTEX ) {
00233     return _DNN->NearestNeighbourDistance(main_index);
00234   } else {
00235     return (
00236         _DNN->NearestNeighbourDistance(main_index) < 
00237         _DNN->NearestNeighbourDistance(mirror_index)) ? 
00238       _DNN->NearestNeighbourDistance(main_index) : 
00239       _DNN->NearestNeighbourDistance(mirror_index) ; 
00240   }
00241  
00242 }
00243 
00244 inline bool Dnn3piCylinder::Valid(const int & index) const {
00245   return (_DNN->Valid(_mirror_info[index].main_index));
00246 }
00247 
00248 
00249 inline Dnn3piCylinder::~Dnn3piCylinder() {
00250   delete _DNN; 
00251 }
00252 
00253 
00254 FASTJET_END_NAMESPACE
00255 
00256 #endif //  __FASTJET_DNN3PICYLINDER_HH__
00257 #endif //  DROP_CGAL 

Generated on Tue Dec 18 17:05:02 2007 for fastjet by  doxygen 1.5.2