SISCone
2.0.6
Main Page
Classes
Files
File List
File Members
siscone
geom_2d.h
1
// -*- C++ -*-
3
// File: geom_2d.h //
4
// Description: header file for two-dimensional geometry tools //
5
// This file is part of the SISCone project. //
6
// For more details, see http://projects.hepforge.org/siscone //
7
// //
8
// Copyright (c) 2006 Gavin Salam and Gregory Soyez //
9
// //
10
// This program is free software; you can redistribute it and/or modify //
11
// it under the terms of the GNU General Public License as published by //
12
// the Free Software Foundation; either version 2 of the License, or //
13
// (at your option) any later version. //
14
// //
15
// This program is distributed in the hope that it will be useful, //
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
18
// GNU General Public License for more details. //
19
// //
20
// You should have received a copy of the GNU General Public License //
21
// along with this program; if not, write to the Free Software //
22
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
23
// //
24
// $Revision:: 268 $//
25
// $Date:: 2009-03-12 21:24:16 +0100 (Thu, 12 Mar 2009) $//
27
28
#ifndef __GEOM_2D_H__
29
#define __GEOM_2D_H__
30
31
#include <iostream>
32
#include <math.h>
33
#include "
defines.h
"
34
35
#ifndef M_PI
36
#define M_PI 3.141592653589793238462643383279502884197
37
#endif
38
39
namespace
siscone{
40
43
inline
double
phi_in_range(
double
phi) {
44
if
(phi <= -M_PI) phi +=
twopi
;
45
else
if
(phi > M_PI) phi -=
twopi
;
46
return
phi;
47
}
48
52
inline
double
dphi(
double
phi1,
double
phi2) {
53
return
phi_in_range(phi1-phi2);
54
}
55
56
60
inline
double
abs_dphi(
double
phi1,
double
phi2) {
61
double
delta = fabs(phi1-phi2);
62
return
delta > M_PI ?
twopi
-delta : delta;
63
}
64
66
inline
double
pow2(
double
x) {
return
x*x;}
67
68
73
class
Ctwovect
{
74
public
:
76
Ctwovect
() :
x
(0.0), y(0.0) {}
77
81
Ctwovect
(
double
_x,
double
_y) :
x
(_x), y(_y) {}
82
84
double
x
, y;
85
87
inline
double
mod2
()
const
{
return
pow2(
x
)+pow2(y);}
88
90
inline
double
modulus
()
const
{
return
sqrt(
mod2
());}
91
};
92
93
98
inline
double
dot_product(
const
Ctwovect & a,
const
Ctwovect & b) {
99
return
a.x*b.x + a.y*b.y;
100
}
101
102
107
inline
double
cross_product(
const
Ctwovect & a,
const
Ctwovect & b) {
108
return
a.x*b.y - a.y*b.x;
109
}
110
111
120
class
Ceta_phi_range
{
121
public
:
123
Ceta_phi_range
();
124
130
Ceta_phi_range
(
double
c_eta,
double
c_phi,
double
R);
131
134
Ceta_phi_range
&
operator =
(
const
Ceta_phi_range
&r);
135
140
int
add_particle
(
const
double
eta,
const
double
phi);
141
143
unsigned
int
eta_range
;
144
146
unsigned
int
phi_range
;
147
148
// extremal value for eta
149
static
double
eta_min
;
150
static
double
eta_max
;
151
152
private
:
154
inline
unsigned
int
get_eta_cell(
double
eta){
155
return
(
unsigned
int
) (1 << ((int) (32*((eta-
eta_min
)/(
eta_max
-
eta_min
)))));
156
}
157
159
inline
unsigned
int
get_phi_cell(
double
phi){
160
return
(
unsigned
int
) (1 << ((int) (32*phi/
twopi
+16)%32));
161
}
162
};
163
168
bool
is_range_overlap(
const
Ceta_phi_range &r1,
const
Ceta_phi_range &r2);
169
175
const
Ceta_phi_range range_union(
const
Ceta_phi_range &r1,
const
Ceta_phi_range &r2);
176
177
}
178
179
#endif
The
SISCone
project has been developed by
Gavin Salam
and
Gregory Soyez
Documentation generated on Mon May 6 2013 04:18:17 for SISCone by
Doxygen
1.8.1.2