Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:15

0001 //FJSTARTHEADER
0002 // $Id$
0003 //
0004 // Copyright (c) 2005-2021, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
0005 //
0006 //----------------------------------------------------------------------
0007 // This file is part of FastJet.
0008 //
0009 //  FastJet is free software; you can redistribute it and/or modify
0010 //  it under the terms of the GNU General Public License as published by
0011 //  the Free Software Foundation; either version 2 of the License, or
0012 //  (at your option) any later version.
0013 //
0014 //  The algorithms that underlie FastJet have required considerable
0015 //  development. They are described in the original FastJet paper,
0016 //  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
0017 //  FastJet as part of work towards a scientific publication, please
0018 //  quote the version you use and include a citation to the manual and
0019 //  optionally also to hep-ph/0512210.
0020 //
0021 //  FastJet is distributed in the hope that it will be useful,
0022 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
0023 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0024 //  GNU General Public License for more details.
0025 //
0026 //  You should have received a copy of the GNU General Public License
0027 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
0028 //----------------------------------------------------------------------
0029 //FJENDHEADER
0030 
0031 
0032 #ifndef __FASTJET_DYNAMICNEARESTNEIGHBOURS_HH__
0033 #define __FASTJET_DYNAMICNEARESTNEIGHBOURS_HH__
0034 
0035 #include<vector>
0036 #include<string>
0037 #include<iostream>
0038 #include<sstream>
0039 #include<cassert>
0040 #include "fastjet/internal/numconsts.hh"
0041 #include "fastjet/Error.hh"
0042 
0043 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
0044 
0045 /// Shortcut for dealing with eta-phi coordinates.
0046 //typedef std::pair<double,double> EtaPhi;
0047 
0048 /// \if internal_doc
0049 /// @ingroup internal
0050 /// \class EtaPhi
0051 /// use a class instead of a pair so that phi can be sanitized
0052 /// and put into proper range on initialization.
0053 /// \endif
0054 class EtaPhi {
0055 public:
0056   double first, second;
0057   EtaPhi() {}
0058   EtaPhi(double a, double b) {first = a; second = b;}
0059   /// put things into the desired range.
0060   void sanitize() {    
0061     if (second <  0)     second += twopi; 
0062     if (second >= twopi) second -= twopi;
0063   }
0064 
0065 };
0066 
0067 /// \if internal_doc
0068 /// @ingroup internal
0069 /// \class DnnError
0070 /// class corresponding to errors that will be thrown by Dynamic
0071 /// Nearest Neighbours code
0072 /// \endif
0073 class DnnError : public Error {
0074 public:
0075   // constructors
0076   //DnnError() {}
0077   DnnError(const std::string & message_in) : Error(message_in) {}
0078 };
0079 
0080 
0081 /// \if internal_doc
0082 /// @ingroup internal
0083 /// \class DynamicNearestNeighbours
0084 /// Abstract base class for quick location of nearest neighbours in a set of
0085 /// points.
0086 ///
0087 /// Abstract base class for quick location of nearest neighbours in a set of
0088 /// points, with facilities for adding and removing points from the
0089 /// set after initialisation. Derived classes will be
0090 /// named according to the convention DnnSomeName (e.g. DnnPlane).
0091 ///
0092 /// The main purpose of this abstract base class is to define the
0093 /// general interface of a whole set of classes that deal with
0094 /// nearest-neighbour location on different 2-d geometries and with
0095 /// various underlying data structures and algorithms.
0096 ///
0097 /// \endif
0098 class DynamicNearestNeighbours {
0099 
0100 public:
0101   /// Dummy initialiser --- does nothing!
0102   //virtual DynamicNearestNeighbours() {};
0103    
0104   /// Initialiser --- sets up the necessary structures to allow efficient
0105   /// nearest-neighbour finding on the std::vector<EtaPhi> of input points
0106   //virtual DynamicNearestNeighbours(const std::vector<EtaPhi> &, 
0107   //                   const bool & verbose = false ) = 0;
0108 
0109   /// Returns the index of the nearest neighbour of point labelled
0110   /// by ii (assumes ii is valid)
0111   virtual int NearestNeighbourIndex(const int ii) const = 0;
0112 
0113   /// Returns the distance to the nearest neighbour of point labelled
0114   /// by index ii (assumes ii is valid)
0115   virtual double NearestNeighbourDistance(const int ii) const = 0;
0116 
0117   /// Returns true iff the given index corresponds to a point that
0118   /// exists in the DNN structure (meaning that it has been added, and
0119   /// not removed in the meantime)
0120   virtual bool Valid(const int index) const = 0;
0121 
0122   /// remove the points labelled by the std::vector indices_to_remove, and
0123   /// add the points specified by the std::vector points_to_add
0124   /// (corresponding indices will be calculated automatically); the
0125   /// idea behind this routine is that the points to be added will
0126   /// somehow be close to the one or other of the points being removed
0127   /// and this can be used by the implementation to provide hints for
0128   /// inserting the new points in whatever structure it is using.  In a
0129   /// kt-algorithm the points being added will be a result of a
0130   /// combination of the points to be removed -- hence the proximity
0131   /// is (more or less) guaranteed.
0132   virtual void RemoveAndAddPoints(const std::vector<int> & indices_to_remove,
0133               const std::vector<EtaPhi> & points_to_add,
0134               std::vector<int> & indices_added,
0135               std::vector<int> & indices_of_updated_neighbours) = 0;
0136 
0137 
0138   /// Remove the point labelled by index and return the list of
0139   /// points whose nearest neighbours have changed in the process
0140   inline void RemovePoint (const int index,
0141                std::vector<int> & indices_of_updated_neighbours) {
0142     std::vector<int> indices_added;
0143     std::vector<EtaPhi> points_to_add;
0144     std::vector<int> indices_to_remove(1);
0145     indices_to_remove[0] = index;
0146     RemoveAndAddPoints(indices_to_remove, points_to_add, indices_added,
0147                indices_of_updated_neighbours
0148                );};
0149 
0150 
0151   /// Removes the two points labelled by index1, index2 and adds in the
0152   /// a point with coordinates newpoint; it returns an index for the new 
0153   /// point (index 3) and a std::vector of indices of neighbours whose
0154   /// nearest neighbour has changed (the list includes index3, i.e. the new
0155   /// point).
0156   inline void RemoveCombinedAddCombination(
0157             const int index1, const int index2,
0158             const EtaPhi & newpoint,
0159             int & index3,
0160             std::vector<int> & indices_of_updated_neighbours) {
0161     std::vector<int> indices_added(1);
0162     std::vector<EtaPhi> points_to_add(1);
0163     std::vector<int> indices_to_remove(2);
0164     indices_to_remove[0] = index1;
0165     indices_to_remove[1] = index2;
0166     points_to_add[0] = newpoint;
0167     RemoveAndAddPoints(indices_to_remove, points_to_add, indices_added,
0168                indices_of_updated_neighbours
0169                );
0170     index3 = indices_added[0];
0171   };
0172 
0173   /// destructor -- here it is now implemented
0174   virtual ~DynamicNearestNeighbours () {}
0175 };
0176   
0177 
0178 FASTJET_END_NAMESPACE
0179 
0180 #endif // __FASTJET_DYNAMICNEARESTNEIGHBOURS_HH__