ATLAS Offline Software
Loading...
Searching...
No Matches
RegSelEtaPhiModule.h
Go to the documentation of this file.
1// emacs: this is -*- c++ -*-
2/*
3 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
4*/
5//
6// @file RegSelEtaPhiModule.h
7//
8// a "module" with a region in eta-phi space with max and min
9// coordinates in both eta and phi and a payload.
10// designed so can easily test whether two "modules"
11// overlap, and objects can be sorted by payload.
12//
13//
14// $Id: RegSelEtaPhiModule.h, v0.0 Sat 25 Jun 2011 10:30:34 BST sutt $
15
16
17#ifndef REGSELLUT_REGSELETAPHIMODULE_H
18#define REGSELLUT_REGSELETAPHIMODULE_H
19
20#include <iostream>
21#include <cmath>
22
23
26
28
29public:
30
31 EtaPhiBase(double etamin, double etamax, double phimin, double phimax)
32 : m_boundary(false) {
33
34 static const double twopi = 2*M_PI;
35
36 m_eta[0] = etamin;
37 m_eta[1] = etamax;
38
39 m_phi[0] = phimin;
40 m_phi[1] = phimax;
41
42 if ( m_phi[0]<0 ) m_phi[0] += twopi;
43 if ( m_phi[1]<0 ) m_phi[1] += twopi;
44
45 if ( m_phi[0]>twopi ) m_phi[0] -= twopi;
46 if ( m_phi[1]>twopi ) m_phi[1] -= twopi;
47
48 if ( m_phi[0]>m_phi[1] ) m_boundary = true;
49 }
50
52 virtual ~EtaPhiBase() = default;
53
55 double etamin() const { return m_eta[0]; }
56 double etamax() const { return m_eta[1]; }
57
58 double phimin() const { return m_phi[0]; }
59 double phimax() const { return m_phi[1]; }
60
61
63 bool overlap(const EtaPhiBase& e) const {
64
65 static const double twopi = 2*M_PI;
66
67 // struct timeval timer = simpletimer_start();
68
70 if ( ! ( e.etamin()<etamax() && e.etamax()>etamin() ) ) return false;
71
74 bool inphi = false;
75
76 double phimin1 = phimin();
77 double phimax1 = phimax();
78
79 double phimin2 = e.phimin();
80 double phimax2 = e.phimax();
81
82 // check for phi wrapping and boundary intersection
83 if ( phimin1>phimax1 ) phimax1 += twopi;
84 if ( phimin2>phimax2 ) phimax2 += twopi;
85
86 if ( ( phimin1<phimax2 && phimax1>phimin2 ) ||
87 ( phimin1<(phimax2+twopi) && phimax1>(phimin2+twopi) ) ||
88 ( (phimin1+twopi)<phimax2 && (phimax1+twopi)>phimin2 ) ) inphi = true;
89
90 // double time = simpletimer_stop( timer );
91
94 return inphi;
95 }
96
97protected:
98
100 double m_eta[2];
101 double m_phi[2];
102
104
105};
106
107
108
109inline std::ostream& operator<<( std::ostream& s, const EtaPhiBase& e ) {
110 s << "[ eta=" << e.etamin() << " - " << e.etamax();
111 s << "\tphi=" << 180*e.phimin()/M_PI << " - " << 180*e.phimax()/M_PI;
112 s<< " ]";
113 return s;
114}
115
116
117
118
119
124template<class T>
126
127public:
128
129 TRegSelEtaPhiModule(double etamin, double etamax, double phimin, double phimax, const T& t) :
131
132 virtual ~TRegSelEtaPhiModule() { }
133
134 const T& payload() const { return m_t; }
135 T& payload() { return m_t; }
136
139 template<class E> bool operator<(const TRegSelEtaPhiModule<E>& e) const { return payload()<e.payload(); }
140 template<class E> bool operator>(const TRegSelEtaPhiModule<E>& e) const { return payload()>e.payload(); }
141 template<class E> bool operator==(const TRegSelEtaPhiModule<E>& e) const { return payload()==e.payload(); }
142 template<class E> bool operator!=(const TRegSelEtaPhiModule<E>& e) const { return payload()!=e.payload(); }
143
144private:
145
148
149};
150
151
154template<class T>
155inline std::ostream& operator<<( std::ostream& s, const TRegSelEtaPhiModule<T>& e ) {
156 s << "[ eta= " << e.etamin() << " - " << e.etamax();
157 s << "\tphi= " << 180*e.phimin()/M_PI << " - " << 180*e.phimax()/M_PI;
158 s << "\tpay= " << e.payload();
159 s << " ]";
160 return s;
161}
162
163
164
165#endif // REGSELLUT_REGSELETAPHIMODULE_H
#define M_PI
std::ostream & operator<<(std::ostream &s, const EtaPhiBase &e)
constexpr double twopi
base class, with just the eta-phi limits and the overlap functionality
double phimax() const
bool overlap(const EtaPhiBase &e) const
do two eta-phi regions overlap?
double etamin() const
accessors
double etamax() const
EtaPhiBase(double etamin, double etamax, double phimin, double phimax)
virtual ~EtaPhiBase()=default
destructor
double phimin() const
double m_eta[2]
eta and phi limits for the module
template class with payload added NB: >, <, == and != operators should be defined for the payload for...
bool operator==(const TRegSelEtaPhiModule< E > &e) const
bool operator!=(const TRegSelEtaPhiModule< E > &e) const
const T & payload() const
bool operator>(const TRegSelEtaPhiModule< E > &e) const
TRegSelEtaPhiModule(double etamin, double etamax, double phimin, double phimax, const T &t)
bool operator<(const TRegSelEtaPhiModule< E > &e) const
to allow "sorting" and uniqueness tests etc technically, only need a < operator, but there you go