Fork me on GitHub

source: git/external/fastjet/plugins/SISCone/geom_2d.cc@ 374bbcc

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 374bbcc was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

  • Property mode set to 100644
File size: 5.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2// File: geom_2d.cpp //
3// Description: source file for two-dimensional geometry tools //
4// This file is part of the SISCone project. //
5// For more details, see http://projects.hepforge.org/siscone //
6// //
7// Copyright (c) 2006 Gavin Salam and Gregory Soyez //
8// //
9// This program is free software; you can redistribute it and/or modify //
10// it under the terms of the GNU General Public License as published by //
11// the Free Software Foundation; either version 2 of the License, or //
12// (at your option) any later version. //
13// //
14// This program is distributed in the hope that it will be useful, //
15// but WITHOUT ANY WARRANTY; without even the implied warranty of //
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
17// GNU General Public License for more details. //
18// //
19// You should have received a copy of the GNU General Public License //
20// along with this program; if not, write to the Free Software //
21// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
22// //
23// $Revision:: $//
24// $Date:: $//
25///////////////////////////////////////////////////////////////////////////////
26
27#include "geom_2d.h"
28#include <algorithm>
29
30namespace siscone{
31
32#define PHI_RANGE_MASK 0xFFFFFFFF
33
34/*********************************************************
35 * class Ceta_phi_range implementation *
36 * class for holding a covering range in eta-phi *
37 * *
38 * This class deals with ranges in the eta-phi plane. It *
39 * implements methods to test if two ranges overlap and *
40 * to take the union of two overlapping intervals. *
41 *********************************************************/
42
43using namespace std;
44
45// static member default init
46//----------------------------
47double Ceta_phi_range::eta_min = -100.0;
48double Ceta_phi_range::eta_max = 100.0;
49
50// default ctor
51//--------------
52Ceta_phi_range::Ceta_phi_range(){
53 eta_range = 0;
54 phi_range = 0;
55}
56
57// ctor with initialisation
58// we initialise with a centre (in eta,phi) and a radius
59// - c_eta eta coordinate of the centre
60// - c_phi phi coordinate of the centre
61// - R radius
62//-------------------------------------------------------
63Ceta_phi_range::Ceta_phi_range(double c_eta, double c_phi, double R){
64 // determination of the eta range
65 //-------------------------------
66 double xmin = max(c_eta-R,eta_min+0.0001);
67 double xmax = min(c_eta+R,eta_max-0.0001);
68
69 unsigned int cell_min = get_eta_cell(xmin);
70 unsigned int cell_max = get_eta_cell(xmax);
71
72 // warning: if cell_max==2^31, 2*cell_max==0 hence,
73 // even if the next formula is formally (2*cell_max-cell_min),
74 // expressing it as (cell_max-cell_min)+cell_max is safe.
75 eta_range = (cell_max-cell_min)+cell_max;
76
77 // determination of the phi range
78 // !! taking care of periodicity !!
79 //---------------------------------
80 xmin = phi_in_range(c_phi-R);
81 xmax = phi_in_range(c_phi+R);
82
83 cell_min = get_phi_cell(xmin);
84 cell_max = get_phi_cell(xmax);
85
86 // Also, if the interval goes through pi, inversion is needed
87 if (xmax>xmin)
88 phi_range = (cell_max-cell_min)+cell_max;
89 else {
90 phi_range = (cell_min==cell_max)
91 ? PHI_RANGE_MASK
92 : ((PHI_RANGE_MASK^(cell_min-cell_max)) + cell_max);
93 }
94}
95
96// assignment of range
97// - r range to assign to current one
98//---------------------------------------
99Ceta_phi_range& Ceta_phi_range::operator = (const Ceta_phi_range &r){
100 eta_range = r.eta_range;
101 phi_range = r.phi_range;
102
103 return *this;
104}
105
106// add a particle to the range
107// - eta eta coordinate of the particle
108// - phi phi coordinate of the particle
109// \return 0 on success, 1 on error
110//----------------------------------------
111int Ceta_phi_range::add_particle(const double eta, const double phi){
112 // deal with the eta coordinate
113 eta_range |= get_eta_cell(eta);
114
115 // deal with the phi coordinate
116 phi_range |= get_phi_cell(phi);
117
118 return 0;
119}
120
121
122// test overlap
123// - r1 first range
124// - r2 second range
125// return true if overlap, false otherwise.
126//------------------------------------------
127bool is_range_overlap(const Ceta_phi_range &r1, const Ceta_phi_range &r2){
128 // check overlap in eta AND phi
129 return ((r1.eta_range & r2.eta_range) && (r1.phi_range & r2.phi_range));
130}
131
132// compute union
133// Note: we assume that the two intervals overlap
134// - r1 first range
135// - r2 second range
136// \return union of the two ranges
137//------------------------------------------
138const Ceta_phi_range range_union (const Ceta_phi_range &r1, const Ceta_phi_range &r2){
139 Ceta_phi_range tmp;
140
141 // compute union in eta
142 tmp.eta_range = r1.eta_range | r2.eta_range;
143
144 // compute union in phi
145 tmp.phi_range = r1.phi_range | r2.phi_range;
146
147 return tmp;
148}
149
150}
Note: See TracBrowser for help on using the repository browser.