ATLAS Offline Software
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 
27 class EtaPhiBase {
28 
29 public:
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 
97 protected:
98 
100  double m_eta[2];
101  double m_phi[2];
102 
104 
105 };
106 
107 
108 
109 inline 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 
124 template<class T>
126 
127 public:
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 
144 private:
145 
148 
149 };
150 
151 
154 template<class T>
155 inline 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
EtaPhiBase::m_boundary
bool m_boundary
Definition: RegSelEtaPhiModule.h:103
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
EtaPhiBase::m_phi
double m_phi[2]
Definition: RegSelEtaPhiModule.h:101
TRegSelEtaPhiModule
template class with payload added NB: >, <, == and != operators should be defined for the payload for...
Definition: RegSelEtaPhiModule.h:125
EtaPhiBase
base class, with just the eta-phi limits and the overlap functionality
Definition: RegSelEtaPhiModule.h:27
TRegSelEtaPhiModule::TRegSelEtaPhiModule
TRegSelEtaPhiModule(double etamin, double etamax, double phimin, double phimax, const T &t)
Definition: RegSelEtaPhiModule.h:129
TRegSelEtaPhiModule::operator!=
bool operator!=(const TRegSelEtaPhiModule< E > &e) const
Definition: RegSelEtaPhiModule.h:142
M_PI
#define M_PI
Definition: ActiveFraction.h:11
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TRegSelEtaPhiModule::~TRegSelEtaPhiModule
virtual ~TRegSelEtaPhiModule()
Definition: RegSelEtaPhiModule.h:132
EtaPhiBase::etamax
double etamax() const
Definition: RegSelEtaPhiModule.h:56
EtaPhiBase::etamin
double etamin() const
accessors
Definition: RegSelEtaPhiModule.h:55
EtaPhiBase::phimin
double phimin() const
Definition: RegSelEtaPhiModule.h:58
EtaPhiBase::EtaPhiBase
EtaPhiBase(double etamin, double etamax, double phimin, double phimax)
Definition: RegSelEtaPhiModule.h:31
TRegSelEtaPhiModule::operator<
bool operator<(const TRegSelEtaPhiModule< E > &e) const
to allow "sorting" and uniqueness tests etc technically, only need a < operator, but there you go
Definition: RegSelEtaPhiModule.h:139
EtaPhiBase::phimax
double phimax() const
Definition: RegSelEtaPhiModule.h:59
TRegSelEtaPhiModule::payload
T & payload()
Definition: RegSelEtaPhiModule.h:135
TRegSelEtaPhiModule::operator>
bool operator>(const TRegSelEtaPhiModule< E > &e) const
Definition: RegSelEtaPhiModule.h:140
EtaPhiBase::overlap
bool overlap(const EtaPhiBase &e) const
do two eta-phi regions overlap?
Definition: RegSelEtaPhiModule.h:63
EtaPhiBase::m_eta
double m_eta[2]
eta and phi limits for the module
Definition: RegSelEtaPhiModule.h:100
twopi
constexpr double twopi
Definition: VertexPointEstimator.cxx:16
EtaPhiBase::~EtaPhiBase
virtual ~EtaPhiBase()=default
destructor
TRegSelEtaPhiModule::payload
const T & payload() const
Definition: RegSelEtaPhiModule.h:134
operator<<
std::ostream & operator<<(std::ostream &s, const EtaPhiBase &e)
Definition: RegSelEtaPhiModule.h:109
TRegSelEtaPhiModule::m_t
T m_t
payload
Definition: RegSelEtaPhiModule.h:147
TRegSelEtaPhiModule::operator==
bool operator==(const TRegSelEtaPhiModule< E > &e) const
Definition: RegSelEtaPhiModule.h:141
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35