SISCone  2.0.5
siscone/geom_2d.cpp
00001 
00002 // File: geom_2d.cpp                                                         //
00003 // Description: source file for two-dimensional geometry tools               //
00004 // This file is part of the SISCone project.                                 //
00005 // For more details, see http://projects.hepforge.org/siscone                //
00006 //                                                                           //
00007 // Copyright (c) 2006 Gavin Salam and Gregory Soyez                          //
00008 //                                                                           //
00009 // This program 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 // This program is distributed in the hope that it will be useful,           //
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
00017 // GNU General Public License for more details.                              //
00018 //                                                                           //
00019 // You should have received a copy of the GNU General Public License         //
00020 // along with this program; if not, write to the Free Software               //
00021 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
00022 //                                                                           //
00023 // $Revision:: 171                                                          $//
00024 // $Date:: 2007-06-19 16:26:05 +0200 (Tue, 19 Jun 2007)                     $//
00026 
00027 #include "geom_2d.h"
00028 #include <algorithm>
00029 
00030 namespace siscone{
00031 
00032 #define PHI_RANGE_MASK 0xFFFFFFFF
00033 
00034 /*********************************************************
00035  * class Ceta_phi_range implementation                   *
00036  * class for holding a covering range in eta-phi         *
00037  *                                                       *
00038  * This class deals with ranges in the eta-phi plane. It *
00039  * implements methods to test if two ranges overlap and  *
00040  * to take the union of two overlapping intervals.       *
00041  *********************************************************/
00042 
00043 using namespace std;
00044 
00045 // static member default init
00046 //----------------------------
00047 double Ceta_phi_range::eta_min = -100.0;
00048 double Ceta_phi_range::eta_max = 100.0;
00049 
00050 // default ctor
00051 //--------------
00052 Ceta_phi_range::Ceta_phi_range(){
00053   eta_range = 0;
00054   phi_range = 0;
00055 }
00056 
00057 // ctor with initialisation
00058 // we initialise with a centre (in eta,phi) and a radius
00059 //  - c_eta   eta coordinate of the centre
00060 //  - c_phi   phi coordinate of the centre
00061 //  - R       radius
00062 //-------------------------------------------------------
00063 Ceta_phi_range::Ceta_phi_range(double c_eta, double c_phi, double R){
00064   // determination of the eta range
00065   //-------------------------------
00066   double xmin = max(c_eta-R,eta_min+0.0001);
00067   double xmax = min(c_eta+R,eta_max-0.0001);
00068 
00069   unsigned int cell_min = get_eta_cell(xmin);
00070   unsigned int cell_max = get_eta_cell(xmax);
00071 
00072   // warning: if cell_max==2^31, 2*cell_max==0 hence, 
00073   // even if the next formula is formally (2*cell_max-cell_min),
00074   // expressing it as (cell_max-cell_min)+cell_max is safe.
00075   eta_range = (cell_max-cell_min)+cell_max;
00076 
00077   // determination of the phi range
00078   // !! taking care of periodicity !!
00079   //---------------------------------
00080   xmin = phi_in_range(c_phi-R);
00081   xmax = phi_in_range(c_phi+R);
00082 
00083   cell_min = get_phi_cell(xmin);
00084   cell_max = get_phi_cell(xmax);
00085 
00086   // Also, if the interval goes through pi, inversion is needed
00087   if (xmax>xmin)
00088     phi_range = (cell_max-cell_min)+cell_max;
00089   else {
00090     phi_range = (cell_min==cell_max) 
00091       ? PHI_RANGE_MASK
00092       : ((PHI_RANGE_MASK^(cell_min-cell_max)) + cell_max);
00093   }
00094 }
00095 
00096 // assignment of range
00097 //  - r   range to assign to current one
00098 //---------------------------------------
00099 Ceta_phi_range& Ceta_phi_range::operator = (const Ceta_phi_range &r){
00100   eta_range = r.eta_range;
00101   phi_range = r.phi_range;
00102 
00103   return *this;
00104 }
00105 
00106 // add a particle to the range
00107 //  - eta  eta coordinate of the particle
00108 //  - phi  phi coordinate of the particle
00109 // \return 0 on success, 1 on error
00110 //----------------------------------------
00111 int Ceta_phi_range::add_particle(const double eta, const double phi){
00112   // deal with the eta coordinate
00113   eta_range |= get_eta_cell(eta);
00114 
00115   // deal with the phi coordinate
00116   phi_range |= get_phi_cell(phi);
00117 
00118   return 0;
00119 }
00120 
00121 
00122 // test overlap
00123 //  - r1  first range
00124 //  - r2  second range
00125 // return true if overlap, false otherwise.
00126 //------------------------------------------
00127 bool is_range_overlap(const Ceta_phi_range &r1, const Ceta_phi_range &r2){
00128   // check overlap in eta AND phi
00129   return ((r1.eta_range & r2.eta_range) && (r1.phi_range & r2.phi_range));
00130 }
00131 
00132 // compute union
00133 // Note: we assume that the two intervals overlap
00134 //  - r1  first range
00135 //  - r2  second range
00136 // \return union of the two ranges
00137 //------------------------------------------
00138 const Ceta_phi_range range_union (const Ceta_phi_range &r1, const Ceta_phi_range &r2){
00139   Ceta_phi_range tmp;
00140 
00141   // compute union in eta
00142   tmp.eta_range = r1.eta_range | r2.eta_range;
00143 
00144   // compute union in phi
00145   tmp.phi_range = r1.phi_range | r2.phi_range;
00146 
00147   return tmp;
00148 }
00149 
00150 }
The SISCone project has been developed by Gavin Salam and Gregory Soyez
Documentation generated on Mon Jun 4 2012 18:23:38 for SISCone by  Doxygen 1.7.6.1