Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:06:45

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 #ifndef __FASTJET_CLOSESTPAIR2DBASE__HH__
0032 #define __FASTJET_CLOSESTPAIR2DBASE__HH__
0033 
0034 #include<vector>
0035 #include "fastjet/internal/base.hh"
0036 
0037 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
0038 
0039 //----------------------------------------------------------------------
0040 /// \if internal_doc
0041 /// @ingroup internal
0042 /// \class Coord2D
0043 /// class for representing 2d coordinates and carrying out some basic 
0044 /// operations on them
0045 /// \endif
0046 class Coord2D {
0047 public:
0048   double x, y;
0049 
0050   Coord2D() : x(0.0), y(0.0) {};
0051 
0052   Coord2D(double a, double b): x(a), y(b) {};
0053 
0054   /// return the vector difference between two coordinates
0055   Coord2D operator-(const Coord2D & other) const {
0056     return Coord2D(x - other.x,  y - other.y);};
0057 
0058   /// return the vector sum between two coordinates
0059   Coord2D operator+(const Coord2D & other) const {
0060     return Coord2D(x + other.x,  y + other.y);};
0061 
0062   /// return the product of the coordinate with the factor
0063   Coord2D operator*(double factor) const {return Coord2D(factor*x,factor*y);};
0064   friend Coord2D operator*(double factor, const Coord2D & coord) {
0065     return Coord2D(factor*coord.x,factor*coord.y);
0066   }
0067 
0068   /// division of each component of coordinate
0069   Coord2D operator/(double divisor) const {
0070     return Coord2D(x / divisor,  y / divisor);};
0071 
0072   /// return the squared distance between two coordinates
0073   friend double distance2(const Coord2D & a, const Coord2D & b) {
0074     double dx = a.x - b.x, dy = a.y-b.y;
0075     return dx*dx+dy*dy;
0076   };
0077   /// return the squared distance between two coordinates
0078   double distance2(const Coord2D & b) const {
0079     double dx = x - b.x, dy = y-b.y;
0080     return dx*dx+dy*dy;
0081   };
0082 };
0083 
0084 
0085 //----------------------------------------------------------------------
0086 /// \if internal_doc
0087 /// @ingroup internal
0088 /// \class ClosestPair2DBase
0089 /// abstract base class for finding closest pairs in 2D
0090 /// \endif
0091 class ClosestPair2DBase {
0092 public:
0093   /// provides the IDs of the closest pair as well as the squared
0094   /// distance between them
0095   virtual void closest_pair(unsigned int & ID1, unsigned int & ID2, 
0096                 double & distance2) const = 0;
0097   
0098   /// removes the entry labelled by ID from the object;
0099   virtual void remove(unsigned int ID) = 0;
0100  
0101   /// inserts the position into the closest pair structure and returns the
0102   /// ID that has been allocated for the object.
0103   virtual unsigned int insert(const Coord2D & position) = 0;
0104 
0105   /// replaces the specified ID1 and ID2 with something at a new position
0106   /// assuming that ID1 and ID2 are in sequence wrt position; it returns
0107   /// the ID of the new object...
0108   virtual unsigned int replace(unsigned int ID1, unsigned int ID2, 
0109                    const Coord2D & position) {
0110     remove(ID1); 
0111     remove(ID2); 
0112     unsigned new_ID = insert(position);
0113     return(new_ID);
0114   };
0115 
0116   /// replaces IDs_to_remove with points at the new_positions
0117   /// indicating the IDs allocated to the new points in new_IDs
0118   virtual void replace_many(const std::vector<unsigned int> & IDs_to_remove,
0119                const std::vector<Coord2D> & new_positions,
0120                std::vector<unsigned int> & new_IDs) {
0121     for(unsigned i = 0; i < IDs_to_remove.size(); i++) {
0122       remove(IDs_to_remove[i]);}
0123     new_IDs.resize(0);
0124     for(unsigned i = 0; i < new_positions.size(); i++) {
0125       new_IDs.push_back(insert(new_positions[i]));}
0126   }
0127 
0128   virtual unsigned int size() = 0;
0129 
0130   virtual ~ClosestPair2DBase() {};
0131   
0132 };
0133 
0134 
0135 FASTJET_END_NAMESPACE
0136 
0137 #endif // __FASTJET_CLOSESTPAIR2DBASE__HH__