SISCone  2.0.6
geom_2d.cpp
1 // File: geom_2d.cpp //
3 // Description: source file for two-dimensional geometry tools //
4 // This file is part of the SISCone project. //
5 // WARNING: this is not the main SISCone trunk but //
6 // an adaptation to spherical coordinates //
7 // For more details, see http://projects.hepforge.org/siscone //
8 // //
9 // Copyright (c) 2006-2008 Gavin Salam and Gregory Soyez //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details. //
20 // //
21 // You should have received a copy of the GNU General Public License //
22 // along with this program; if not, write to the Free Software //
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
24 // //
25 // $Revision:: 255 $//
26 // $Date:: 2008-07-12 17:40:35 +0200 (Sat, 12 Jul 2008) $//
28 
29 #include "geom_2d.h"
30 #include <algorithm>
31 
32 namespace siscone_spherical{
33 
34 #define PHI_RANGE_MASK 0xFFFFFFFF
35 
36 /*********************************************************
37  * class CSphtheta_phi_range implementation *
38  * class for holding a covering range in eta-phi *
39  * *
40  * This class deals with ranges in the eta-phi plane. It *
41  * implements methods to test if two ranges overlap and *
42  * to take the union of two overlapping intervals. *
43  *********************************************************/
44 
45 using namespace std;
46 
47 // static member default init
48 //----------------------------
50 double CSphtheta_phi_range::theta_max = M_PI;
51 
52 // default ctor
53 //--------------
55  theta_range = 0;
56  phi_range = 0;
57 }
58 
59 // ctor with initialisation
60 // we initialise with a centre (in eta,phi) and a radius
61 // - c_theta theta coordinate of the centre
62 // - c_phi phi coordinate of the centre
63 // - R radius
64 //-------------------------------------------------------
65 CSphtheta_phi_range::CSphtheta_phi_range(double c_theta, double c_phi, double R){
66  // determination of the eta range
67  //-------------------------------
68  double xmin = max(c_theta-R,theta_min+0.00001);
69  double xmax = min(c_theta+R,theta_max-0.00001);
70 
71  unsigned int cell_min = get_theta_cell(xmin);
72  unsigned int cell_max = get_theta_cell(xmax);
73 
74  // warning: if cell_max==2^31, 2*cell_max==0 hence,
75  // even if the next formula is formally (2*cell_max-cell_min),
76  // expressing it as (cell_max-cell_min)+cell_max is safe.
77  theta_range = (cell_max-cell_min)+cell_max;
78 
79  // determination of the phi range
80  // !! taking care of periodicity !!
81  // !! and the theta dependence !!
82  //---------------------------------
83  double ymin,ymax;
84  double extra = asin(R/M_PI);
85  if (xmin<=theta_min+extra){
86  ymin = -M_PI+0.00001;
87  ymax = M_PI-0.00001;
88  } else if (xmax>=theta_max-extra){
89  ymin = -M_PI+0.00001;
90  ymax = M_PI-0.00001;
91  } else {
92  extra = max(1.0/sin(xmin), 1.0/sin(xmax));
93  ymin = (c_phi-R)*extra;
94  while (ymin<-M_PI) ymin+=twopi;
95  while (ymin> M_PI) ymin-=twopi;
96  ymax = (c_phi-R)*extra;
97  while (ymax<-M_PI) ymax+=twopi;
98  while (ymax> M_PI) ymax-=twopi;
99  }
100  cell_min = get_phi_cell(ymin);
101  cell_max = get_phi_cell(ymax);
102 
103  // Also, if the interval goes through pi, inversion is needed
104  if (ymax>ymin)
105  phi_range = (cell_max-cell_min)+cell_max;
106  else {
107  phi_range = (cell_min==cell_max)
108  ? PHI_RANGE_MASK
109  : ((PHI_RANGE_MASK^(cell_min-cell_max)) + cell_max);
110  }
111 }
112 
113 // assignment of range
114 // - r range to assign to current one
115 //---------------------------------------
117  theta_range = r.theta_range;
118  phi_range = r.phi_range;
119 
120  return *this;
121 }
122 
123 // add a particle to the range
124 // - eta eta coordinate of the particle
125 // - phi phi coordinate of the particle
126 // \return 0 on success, 1 on error
127 //----------------------------------------
128 int CSphtheta_phi_range::add_particle(const double theta, const double phi){
129  // deal with the eta coordinate
130  theta_range |= get_theta_cell(theta);
131 
132  // deal with the phi coordinate
133  phi_range |= get_phi_cell(phi);
134 
135  return 0;
136 }
137 
138 
139 // test overlap
140 // - r1 first range
141 // - r2 second range
142 // return true if overlap, false otherwise.
143 //------------------------------------------
144 bool is_range_overlap(const CSphtheta_phi_range &r1, const CSphtheta_phi_range &r2){
145  // check overlap in eta AND phi
146  return ((r1.theta_range & r2.theta_range) && (r1.phi_range & r2.phi_range));
147 }
148 
149 // compute union
150 // Note: we assume that the two intervals overlap
151 // - r1 first range
152 // - r2 second range
153 // \return union of the two ranges
154 //------------------------------------------
155 const CSphtheta_phi_range range_union (const CSphtheta_phi_range &r1, const CSphtheta_phi_range &r2){
156  CSphtheta_phi_range tmp;
157 
158  // compute union in eta
159  tmp.theta_range = r1.theta_range | r2.theta_range;
160 
161  // compute union in phi
162  tmp.phi_range = r1.phi_range | r2.phi_range;
163 
164  return tmp;
165 }
166 
167 }
static double theta_max
maximal value for theta (set to pi)
Definition: geom_2d.h:82
const double twopi
definition of 2*M_PI which is useful a bit everyhere!
Definition: defines.h:114
class for holding a covering range in eta-phi
Definition: geom_2d.h:52
static double theta_min
extremal value for theta
Definition: geom_2d.h:81
unsigned int theta_range
theta range as a binary coding of covered cells
Definition: geom_2d.h:75
unsigned int phi_range
phi range as a binary coding of covered cells
Definition: geom_2d.h:78
unsigned int phi_range
phi range as a binary coding of covered cells
Definition: geom_2d.h:146
int add_particle(const double theta, const double phi)
add a particle to the range
Definition: geom_2d.cpp:128
CSphtheta_phi_range & operator=(const CSphtheta_phi_range &r)
assignment of range
Definition: geom_2d.cpp:116
The SISCone project has been developed by Gavin Salam and Gregory Soyez
Documentation generated on Tue Aug 4 2015 16:34:54 for SISCone by  Doxygen 1.8.9.1