Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:15:33

0001 // -*- C++ -*-
0002 ///////////////////////////////////////////////////////////////////////////////
0003 // File: protocones.h                                                        //
0004 // Description: header file for stable cones determination (Cstable_cones)   //
0005 // This file is part of the SISCone project.                                 //
0006 // For more details, see http://projects.hepforge.org/siscone                //
0007 //                                                                           //
0008 // Copyright (c) 2006 Gavin Salam and Gregory Soyez                          //
0009 //                                                                           //
0010 // This program is free software; you can redistribute it and/or modify      //
0011 // it under the terms of the GNU General Public License as published by      //
0012 // the Free Software Foundation; either version 2 of the License, or         //
0013 // (at your option) any later version.                                       //
0014 //                                                                           //
0015 // This program is distributed in the hope that it will be useful,           //
0016 // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
0017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
0018 // GNU General Public License for more details.                              //
0019 //                                                                           //
0020 // You should have received a copy of the GNU General Public License         //
0021 // along with this program; if not, write to the Free Software               //
0022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
0023 //                                                                           //
0024 // $Revision::                                                              $//
0025 // $Date::                                                                  $//
0026 ///////////////////////////////////////////////////////////////////////////////
0027 
0028 #ifndef __PROTOCONES_H__
0029 #define __PROTOCONES_H__
0030 
0031 #include "momentum.h"
0032 #include "vicinity.h"
0033 #include <stdio.h>
0034 #include <vector>
0035 #include <list>
0036 #include "hash.h"
0037 
0038 #include "defines.h"
0039 
0040 namespace siscone{
0041 
0042 /**
0043  * \class Cborder_store
0044  * 
0045  * class for storing a border momentum (in context of co-circularity
0046  * checks).
0047 
0048  * This class essentially calculates angle of border point w.r.t.
0049  * circle center (eta & phi), and provides a store of information
0050  * about whether we are currently including this point in the
0051  * candidate 
0052  */
0053 class Cborder_store{
0054 public:
0055   /// default ctor
0056   Cborder_store(Cmomentum * momentum, double centre_eta, double centre_phi) : 
0057     mom(momentum),  is_in(false) {
0058     angle = atan2(mom->phi - centre_phi, mom->eta - centre_eta);
0059   }
0060 
0061   Cmomentum * mom;  ///< particle momentum
0062   double angle;     ///< angle w.r.t. circle centre
0063   bool   is_in;     ///< inclusion status of the particle
0064 };
0065 
0066 
0067 /// allows easy sorting of Cborder_store objects (which need to be
0068 /// ordered in angle).
0069 inline bool operator<(const Cborder_store & a, const Cborder_store & b) {
0070   return a.angle < b.angle;
0071 }
0072 
0073 
0074 /**
0075  * \class Cstable_cones
0076  * \brief Computes the list of stable comes from a particle list.
0077  *
0078  * This class does the first fundamental task of te cone algorithm:
0079  * it is used to compute the list of stable cones given a list
0080  * of particles.
0081  */
0082 class Cstable_cones : public Cvicinity{
0083  public:
0084   /// default ctor
0085   Cstable_cones();
0086 
0087   /// ctor with initialisation (sse init for details)
0088   Cstable_cones(std::vector<Cmomentum> &_particle_list);
0089 
0090   /// default dtor
0091   ~Cstable_cones();
0092 
0093   /**
0094    * initialisation
0095    * \param _particle_list  list of particles
0096    */
0097   void init(std::vector<Cmomentum> &_particle_list);
0098 
0099   /**
0100    * compute stable cones.
0101    * This function really does the job i.e. computes
0102    * the list of stable cones (in a seedless way)
0103    * \param _radius   radius of the cones
0104    * \return The number of stable cones found is returned
0105    */
0106   int get_stable_cones(double _radius);
0107 
0108   /// list of stable cones
0109   std::vector<Cmomentum> protocones;
0110 
0111   /// list of candidates
0112   hash_cones *hc;
0113 
0114   /// total number of tested cones
0115   int nb_tot;
0116 #ifdef DEBUG_STABLE_CONES
0117   int nb_hash_cones, nb_hash_occupied;
0118 #endif
0119 
0120  protected:
0121   /// cone radius
0122   double R;
0123 
0124   /// cone radius SQUARED
0125   double R2;
0126 
0127  private:
0128   /// cone with a given particle as parent
0129   /// this reduction to a single vector assumes we trust the checksums
0130   Cmomentum cone;
0131 
0132   /// child particle, taken in the 'vicinity' list
0133   Cmomentum *child;
0134 
0135   /// centre of the tested cone 
0136   Cvicinity_elm *centre;
0137 
0138   /// index in the particle list;
0139   unsigned int centre_idx;
0140 
0141   /// first cone used in the vicinity list
0142   unsigned int first_cone;
0143 
0144   /**
0145    * initialise the cone.
0146    * We take the first particle in the angular ordering to compute this one
0147    * \return 0 on success, 1 on error
0148    */
0149   int init_cone();
0150 
0151   /**
0152    * test cones.
0153    * We check if the cone(s) build with the present parent and child 
0154    * are stable
0155    * \return 0 on success 1 on error
0156    */
0157   int test_cone();
0158 
0159   /**
0160    * update the cone
0161    * go to the next child for that parent and update 'cone' appropriately
0162    * \return 0 if update candidate found, 1 otherwise
0163    */
0164   int update_cone();
0165 
0166   /*
0167    * run through the vicinity of the current parent and for each child
0168    * indicate which members are cocircular...
0169    */
0170   void prepare_cocircular_lists();
0171 
0172   /**
0173    * check if we are in a situation of cocircularity.
0174    * if it is the case, update and test in the corresponding way
0175    * \return 'false' if no cocircularity detected, 'true' otherwise
0176    * Note that if cocircularity is detected, we need to 
0177    * recall 'update' from 'update' !!!
0178    */
0179   bool cocircular_check();
0180 
0181   /**
0182    * Routine for testing cocircular configurations in p^3 time,
0183    * rather than 2^p time;
0184    */
0185   void test_cone_cocircular(Cmomentum & borderless_cone, 
0186                 std::list<Cmomentum *> & border_list);
0187 
0188   /**
0189    * carry out the computations needed for the stability check of the
0190    * candidate, using the border_vect to indicate which particles
0191    * should / should not be in the stable cone; if the cone is stable
0192    * insert it into the hash.
0193    */
0194   void test_stability(Cmomentum & candidate, 
0195                       const std::vector<Cborder_store> & border_vect);
0196 
0197   /**
0198    * compute the cone contents by going once around the full set of
0199    * circles and tracking the entry/exit status each time -- this sets
0200    * up the inclusion information, which can then be directly used to
0201    * calculate the cone momentum.
0202    */
0203   void compute_cone_contents();
0204 
0205   /**
0206    * compute the cone momentum from particle list.
0207    * in this version, we use the 'pincluded' information
0208    * from the Cviinity class
0209    */
0210   void recompute_cone_contents();
0211 
0212   /*
0213    * if we have gone beyond the acceptable threshold of change, compute
0214    * the cone momentum from particle list.  in this version, we use the
0215    * 'pincluded' information from the Cvicinity class, but we don't
0216    * change the member cone, only the locally supplied one
0217    */
0218   void recompute_cone_contents_if_needed(Cmomentum & this_cone, double & this_dpt);
0219 
0220   /**
0221    * compute stability of all enumerated candidates.
0222    * For all candidate cones which are stable w.r.t. their border particles,
0223    * pass the last test: stability with quadtree intersection
0224    */
0225   int proceed_with_stability();
0226 
0227   /*
0228    * circle intersection.
0229    * computes the intersection with a circle of given centre and radius.
0230    * The output takes the form of a checkxor of the intersection's particles
0231    *  - cx    circle centre x coordinate
0232    *  - cy    circle centre y coordinate
0233    * return the checkxor for the intersection
0234    ******************************************************************/
0235   Creference circle_intersect(double cx, double cy);
0236 
0237   /// present candidate cone
0238   Cmomentum cone_candidate;
0239 
0240   /// in case of co-circular points, vector for them
0241   std::vector<Cmomentum*> child_list;
0242 
0243   /// list of cocircular enclusures already studied
0244   /// first element if cone contents, second is cone border
0245   std::vector< std::pair<Creference,Creference> > multiple_centre_done;
0246 
0247   // information for updating cone contents to avoid rounding errors
0248   double dpt;          ///< sums of Delta P_t
0249 
0250   /**
0251    * test if a particle is inside a cone of given centre.
0252    * check if the particle of coordinates 'v' is inside the circle of radius R 
0253    * centered at 'centre'.
0254    * \param centre   centre of the circle
0255    * \param v        particle to test
0256    * \return true if inside, false if outside
0257    */
0258   inline bool is_inside(Cmomentum *centre, Cmomentum *v);
0259 };
0260 
0261 /*
0262  * compute the absolute value of the difference between 2 angles.
0263  * We take care of the 2pi periodicity
0264  * \param angle1   first angle
0265  * \param angle2   second angle
0266  * \return the absolute value of the difference between the angles
0267  *****************************************************************/
0268 inline double abs_dangle(double &angle1, double &angle2);
0269 
0270 }
0271 #endif