ATLAS Offline Software
Loading...
Searching...
No Matches
RoiUtil.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4//
5// @file RoiUtil.cxx
6//
7// non-member, non friend RoiDescriptor utility functions
8// to improve encapsulation
9//
10// @author M.Sutton
11//
12//
13
14
17
18#include <cmath>
19
20namespace {
21 constexpr double M_2PI = 2*M_PI;
22 constexpr float M_PIF = M_PI;
23
24 constexpr double MAX_R = 1100; // maximum radius of RoI - outer TRT radius ~1070 mm - should be configurable?
25}
26
27
28namespace RoiUtil {
29
30class range_error : public std::exception {
31public:
32 range_error( const char* s ) : std::exception(), m_str(s) { }
33 virtual const char* what() const throw() { return m_str.c_str(); }
34private:
35 std::string m_str;
36};
37
38}
39
40
42bool RoiUtil::contains( const IRoiDescriptor& roi, double z0, double dzdr ) {
43 const double zouter = dzdr*MAX_R + z0;
44
45 auto contains_internal = [zouter, z0]( const IRoiDescriptor& rd ) {
46 return ( z0<=rd.zedPlus() && z0>=rd.zedMinus() &&
47 zouter<=rd.zedOuterPlus() && zouter>=rd.zedOuterMinus() );
48 };
49
50 if ( roi.composite() ) {
51 for ( const IRoiDescriptor* rd : roi ) {
52 if ( contains_internal( *rd ) ) return true;
53 }
54 return false;
55 }
56 else return contains_internal( roi );
57}
58
59
60bool RoiUtil::contains_zrange( const IRoiDescriptor& roi, double z0, double dzdr, double zmin, double zmax ) {
61 const double zouter = dzdr*MAX_R + z0;
62
63 auto contains_internal = [zouter, z0, zmin, zmax]( const IRoiDescriptor& rd ) {
64 return ( z0<=zmax && z0>=zmin &&
65 zouter<=rd.zedOuterPlus() && zouter>=rd.zedOuterMinus() );
66 };
67
68 if ( roi.composite() ) {
69 for ( const IRoiDescriptor* rd : roi ) {
70 if ( contains_internal( *rd ) ) return true;
71 }
72 return false;
73 }
74 else return contains_internal( roi );
75}
76
77
79bool RoiUtil::containsPhi( const IRoiDescriptor& roi, double phi ) {
80 if ( roi.composite() ) {
81 for ( const IRoiDescriptor* rd : roi ) {
82 if ( RoiUtil::containsPhi( *rd, phi ) ) return true;
83 }
84 return false;
85 }
86 else {
87 if ( roi.isFullscan() ) return true;
88 if ( roi.phiPlus()>roi.phiMinus() ) return ( phi<roi.phiPlus() && phi>roi.phiMinus() );
89 else return ( phi<roi.phiPlus() || phi>roi.phiMinus() );
90 }
91}
92
93
94bool RoiUtil::containsZed( const IRoiDescriptor& roi, double z, double r ) {
95 if ( roi.composite() ) {
96 for ( const IRoiDescriptor* rd : roi ) {
97 if ( RoiUtil::containsZed( *rd, z, r ) ) return true;
98 }
99 return false;
100 }
101 else {
102 if ( roi.isFullscan() ) return true;
103 double zminus = r*roi.dzdrMinus() + roi.zedMinus();
104 double zplus = r*roi.dzdrPlus() + roi.zedPlus();
105 return ( z>=zminus && z<=zplus );
106 }
107}
108
109
110bool RoiUtil::contains( const IRoiDescriptor& roi, double z, double r, double phi ) {
111 if ( roi.composite() ) {
112 for ( const IRoiDescriptor* rd : roi ) {
113 if ( RoiUtil::contains( *rd, z, r, phi ) ) return true;
114 }
115 return false;
116 }
117 else {
118 return ( RoiUtil::containsZed( roi, z, r ) && RoiUtil::containsPhi( roi, phi ) );
119 }
120}
121
122
123double RoiUtil::phicheck(double phi) {
124 while ( phi> M_PIF ) phi-=M_2PI;
125 while ( phi<-M_PIF ) phi+=M_2PI;
126 if ( !(phi >= -M_PIF && phi <= M_PIF) ) { // use ! of range rather than range to also catch nan etc
127 throw range_error( (std::string("phi out of range: ")+std::to_string(phi)).c_str() );
128 }
129 return phi;
130}
131
132
133double RoiUtil::etacheck(double eta) {
134 if ( !(eta>-100 && eta<100) ) { // check also for nan
135 throw range_error( (std::string("eta out of range: ")+std::to_string(eta)).c_str() );
136 }
137 return eta;
138}
139
140
141double RoiUtil::zedcheck(double zed ) {
142 if ( !(zed>-100000 && zed<100000 ) ) { // check also for nan
143 throw range_error( (std::string("zed out of range: ")+std::to_string(zed)).c_str() );
144 }
145 return zed;
146}
147
148
149bool operator==( const IRoiDescriptor& roi0, const IRoiDescriptor& roi1 ) {
150
152 if ( &roi0 == &roi1 ) return true;
153
155 if ( roi0.composite() != roi1.composite() ) return false;
156
157 if ( !roi0.composite() ) {
159
161 if ( roi0.isFullscan() != roi1.isFullscan() ) return false;
162 if ( roi0.isFullscan() ) return true;
163
165 if ( std::fabs(roi0.zed() -roi1.zed() )>1e-7 ) return false;
166 if ( std::fabs(roi0.zedPlus() -roi1.zedPlus() )>1e-7 ) return false;
167 if ( std::fabs(roi0.zedMinus()-roi1.zedMinus())>1e-7 ) return false;
168
169 if ( std::fabs(roi0.eta() -roi1.eta() )>1e-7 ) return false;
170 if ( std::fabs(roi0.etaPlus() -roi1.etaPlus() )>1e-7 ) return false;
171 if ( std::fabs(roi0.etaMinus()-roi1.etaMinus())>1e-7 ) return false;
172
175 if ( std::fabs(roi0.phi() -roi1.phi() ) >1e-7 ) return false;
176 if ( std::fabs(roi0.phiPlus() -roi1.phiPlus()) >1e-7 ) return false;
177 if ( std::fabs(roi0.phiMinus()-roi1.phiMinus())>1e-7 ) return false;
178 }
179 else {
181 if ( roi0.size() != roi1.size() ) return false;
182 for ( unsigned i=roi0.size() ; i-- ; ) if ( !( *roi0.at(i) == *roi1.at(i) ) ) return false;
183 }
184
185 return true;
186}
187
188
189
190bool operator!=( const IRoiDescriptor& roi0, const IRoiDescriptor& roi1 ) { return !(roi0==roi1); }
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define M_2PI
bool operator==(const IRoiDescriptor &roi0, const IRoiDescriptor &roi1)
Definition RoiUtil.cxx:149
bool operator!=(const IRoiDescriptor &roi0, const IRoiDescriptor &roi1)
Definition RoiUtil.cxx:190
static const float M_PIF
#define z
Describes the API of the Region of Ineterest geometry.
virtual bool isFullscan() const =0
is this a full detector RoI?
virtual double eta() const =0
virtual double phiPlus() const =0
extreme phi values
virtual double zedPlus() const =0
the zed and eta values at the most forward and most rear ends of the RoI
virtual double dzdrMinus() const =0
return the gradients
virtual double phiMinus() const =0
virtual double phi() const =0
Methods to retrieve data members.
virtual double zedMinus() const =0
virtual double zed() const =0
virtual double dzdrPlus() const =0
virtual const IRoiDescriptor * at(int i) const =0
find an RoiDescriptor constituent
virtual unsigned size() const =0
number of constituents
virtual double etaMinus() const =0
virtual double etaPlus() const =0
virtual bool composite() const =0
Super RoI access methods.
range_error(const char *s)
Definition RoiUtil.cxx:32
std::string m_str
Definition RoiUtil.cxx:35
virtual const char * what() const
Definition RoiUtil.cxx:33
int r
Definition globals.cxx:22
double zedcheck(double zed)
Definition RoiUtil.cxx:141
double etacheck(double eta)
Definition RoiUtil.cxx:133
bool contains_zrange(const IRoiDescriptor &roi, double z0, double dzdr, double zmin, double zmax)
Definition RoiUtil.cxx:60
double phicheck(double phi)
basic range checkers
Definition RoiUtil.cxx:123
bool containsPhi(const IRoiDescriptor &roi, double phi)
test whether a stub is contained within the roi
Definition RoiUtil.cxx:79
bool contains(const IRoiDescriptor &roi, double z0, double dzdr)
see whether a segment is contained within the roi in r-z
Definition RoiUtil.cxx:42
bool containsZed(const IRoiDescriptor &roi, double z, double r)
Definition RoiUtil.cxx:94
STL namespace.