![]() |
|
|||
File indexing completed on 2025-04-19 09:09:43
0001 // -*- C++ -*- 0002 /////////////////////////////////////////////////////////////////////////////// 0003 // File: geom_2d.h // 0004 // Description: header file for two-dimensional geometry tools // 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 __GEOM_2D_H__ 0029 #define __GEOM_2D_H__ 0030 0031 #include <iostream> 0032 #include <math.h> 0033 #include "defines.h" 0034 0035 #ifndef M_PI 0036 #define M_PI 3.141592653589793238462643383279502884197 0037 #endif 0038 0039 namespace siscone{ 0040 0041 /// return a result that corresponds to phi, but in the 0042 /// range (-pi..pi]; the result is only correct if -3pi < phi <= 3pi 0043 inline double phi_in_range(double phi) { 0044 if (phi <= -M_PI) phi += twopi; 0045 else if (phi > M_PI) phi -= twopi; 0046 return phi; 0047 } 0048 0049 /// return the difference between the two phi values, 0050 /// placed in the correct range (-pi..pi], , assuming that phi1,phi2 0051 /// are already in the correct range. 0052 inline double dphi(double phi1, double phi2) { 0053 return phi_in_range(phi1-phi2); 0054 } 0055 0056 0057 /// return the absolute difference between the two phi values, 0058 /// placed in the correct range, assuming that phi1,phi2 are already 0059 /// in the correct range. 0060 inline double abs_dphi(double phi1, double phi2) { 0061 double delta = fabs(phi1-phi2); 0062 return delta > M_PI ? twopi-delta : delta; 0063 } 0064 0065 /// return the square of the argument 0066 inline double pow2(double x) {return x*x;} 0067 0068 0069 /** 0070 * \class Ctwovect 0071 * \brief class for holding a two-vector 0072 */ 0073 class Ctwovect { 0074 public: 0075 /// default ctor 0076 Ctwovect() : x(0.0), y(0.0) {} 0077 0078 /// ctor with initialisation 0079 /// \param _x first coordinate 0080 /// \param _y second coordinate 0081 Ctwovect(double _x, double _y) : x(_x), y(_y) {} 0082 0083 /// vector coordinates 0084 double x, y; 0085 0086 /// norm (modulud square) of the vector 0087 inline double mod2() const {return pow2(x)+pow2(y);} 0088 0089 /// modulus of the vector 0090 inline double modulus() const {return sqrt(mod2());} 0091 }; 0092 0093 0094 /// dot product of two 2-vectors 0095 /// \param a first 2-vect 0096 /// \param b second 2-vect 0097 /// \return a.b is returned 0098 inline double dot_product(const Ctwovect & a, const Ctwovect & b) { 0099 return a.x*b.x + a.y*b.y; 0100 } 0101 0102 0103 /// cross product of two 2-vectors 0104 /// \param a first 2-vect 0105 /// \param b second 2-vect 0106 /// \return a x b is returned 0107 inline double cross_product(const Ctwovect & a, const Ctwovect & b) { 0108 return a.x*b.y - a.y*b.x; 0109 } 0110 0111 0112 /** 0113 * \class Ceta_phi_range 0114 * \brief class for holding a covering range in eta-phi 0115 * 0116 * This class deals with ranges in the eta-phi plane. It 0117 * implements methods to test if two ranges overlap and 0118 * to take the union of two overlapping intervals. 0119 */ 0120 class Ceta_phi_range{ 0121 public: 0122 /// default ctor 0123 Ceta_phi_range(); 0124 0125 /// ctor with initialisation 0126 /// we initialise with a centre (in eta,phi) and a radius 0127 /// \param c_eta eta coordinate of the centre 0128 /// \param c_phi phi coordinate of the centre 0129 /// \param R radius 0130 Ceta_phi_range(double c_eta, double c_phi, double R); 0131 0132 /// assignment of range 0133 /// \param r range to assign to current one 0134 Ceta_phi_range& operator = (const Ceta_phi_range &r); 0135 0136 /// add a particle to the range 0137 /// \param eta eta coordinate of the particle 0138 /// \param phi phi coordinate of the particle 0139 /// \return 0 on success, 1 on error 0140 int add_particle(const double eta, const double phi); 0141 0142 /// eta range as a binary coding of covered cells 0143 unsigned int eta_range; 0144 0145 /// phi range as a binary coding of covered cells 0146 unsigned int phi_range; 0147 0148 // extremal value for eta 0149 static double eta_min; ///< minimal value for eta 0150 static double eta_max; ///< maximal value for eta 0151 0152 private: 0153 /// return the cell index corrsponding to an eta value 0154 inline unsigned int get_eta_cell(double eta){ 0155 return (unsigned int) (1u << ((int) (32*((eta-eta_min)/(eta_max-eta_min))))); 0156 } 0157 0158 /// return the cell index corrsponding to a phi value 0159 inline unsigned int get_phi_cell(double phi){ 0160 return (unsigned int) (1u << ((int) (32*phi/twopi+16)%32)); 0161 } 0162 }; 0163 0164 /// test overlap 0165 /// \param r1 first range 0166 /// \param r2 second range 0167 /// \return true if overlap, false otherwise. 0168 bool is_range_overlap(const Ceta_phi_range &r1, const Ceta_phi_range &r2); 0169 0170 /// compute union 0171 /// Note: we assume that the two intervals overlap 0172 /// \param r1 first range 0173 /// \param r2 second range 0174 /// \return union of the two ranges 0175 const Ceta_phi_range range_union(const Ceta_phi_range &r1, const Ceta_phi_range &r2); 0176 0177 } 0178 0179 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |