DnnPlane.hh

00001 //STARTHEADER
00002 // $Id: DnnPlane.hh 1761 2010-09-16 10:43:18Z soyez $
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 
00034 #ifndef __FASTJET_DNNPLANE_HH__
00035 #define __FASTJET_DNNPLANE_HH__
00036 
00037 #include "fastjet/internal/Triangulation.hh"
00038 #include "fastjet/internal/DynamicNearestNeighbours.hh"
00039 
00040 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00041 
00042 
00049 class DnnPlane : public DynamicNearestNeighbours {
00050  public:
00052   DnnPlane() {}
00053 
00056   DnnPlane(const std::vector<EtaPhi> &, const bool & verbose = false );
00057 
00058 
00061   int NearestNeighbourIndex(const int & ii) const ;
00062 
00065   double NearestNeighbourDistance(const int & ii) const ;
00066 
00070   bool Valid(const int & index) const;
00071 
00072   void RemoveAndAddPoints(const std::vector<int> & indices_to_remove,
00073                           const std::vector<EtaPhi> & points_to_add,
00074                           std::vector<int> & indices_added,
00075                           std::vector<int> & indices_of_updated_neighbours);
00076 
00078   EtaPhi etaphi(const int i) const;
00080   double eta(const int i) const;
00082   double phi(const int i) const;
00083 
00084  private:
00085 
00088   struct SuperVertex {
00089     Vertex_handle vertex; // NULL indicates inexistence...
00090     double NNdistance;
00091     int NNindex;
00092     // later on for cylinder put a second vertex?
00093   };
00094 
00095   std::vector<SuperVertex> _supervertex;
00096   //set<Vertex_handle> _vertex_set;
00097   bool _verbose;
00098 
00099   static const bool _crash_on_coincidence = true;
00100   //static const bool _crash_on_coincidence = false;
00101 
00102   Triangulation _TR; 
00103 
00106   inline double _euclid_distance(const Point& p1, const Point& p2) const {
00107     double distx= p1.x()-p2.x();
00108     double disty= p1.y()-p2.y();
00109     return distx*distx+disty*disty;
00110   }
00111 
00112   //---------------------------------------------------------------------- 
00115   void _SetNearest(const int & j);
00116 
00117   //----------------------------------------------------------------------
00127   void _SetAndUpdateNearest(const int & j, 
00128                             std::vector<int> & indices_of_updated_neighbours);
00129 
00133   void _CrashIfVertexPresent(const Vertex_handle & vertex, 
00134                              const int & its_index);
00135 
00136 };
00137 
00138 
00139 // here follow some inline implementations of the simpler of the
00140 // functions defined above
00141 
00142 inline int DnnPlane::NearestNeighbourIndex(const int & ii) const {
00143   return _supervertex[ii].NNindex;}
00144 
00145 inline double DnnPlane::NearestNeighbourDistance(const int & ii) const {
00146   return _supervertex[ii].NNdistance;}
00147 
00148 inline bool DnnPlane::Valid(const int & index) const {
00149   if (index >= 0 && index < static_cast<int>(_supervertex.size())) {
00150     return (_supervertex[index].vertex != NULL);} else {return false;} }
00151 
00152 inline EtaPhi DnnPlane::etaphi(const int i) const {
00153   Point * p = & (_supervertex[i].vertex->point());
00154   return EtaPhi(p->x(),p->y()); }
00155 
00156 inline double DnnPlane::eta(const int i) const {
00157   return _supervertex[i].vertex->point().x(); }
00158 
00159 inline double DnnPlane::phi(const int i) const {
00160   return _supervertex[i].vertex->point().y(); }
00161 
00162 
00163 FASTJET_END_NAMESPACE
00164 
00165 #endif //  __FASTJET_DNNPLANE_HH__
00166 
00167 #endif // DROP_CGAL