ATLAS Offline Software
RoiDescriptor.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 /**************************************************************************
6  ** @file RoiDescriptor.cxx
7  ** @author sutt@cern.ch
8  **
9  ** Description: standalone RoIDescriptor implementation
10  **
11  ** Created: Tue 5 Aug 2014 00:13:41 CEST
12  ** Modified:
13  **************************************************************************/
14 
17 
18 #include <cmath>
19 #include <sstream>
20 #include <stdexcept>
21 
22 
23 namespace {
24  constexpr double M_2PI = 2*M_PI;
26  constexpr float M_PIF = M_PI;
27  constexpr int RoiVersion = 4;
28 }
29 
30 std::atomic<double> RoiDescriptor::s_zedWidthDefault = 225;
31 std::atomic<bool> RoiDescriptor::s_firstInstanceCreated = false;
32 
34 {
36  throw std::runtime_error("Cannot set default z-width because a RoiDescriptor has already been created");
37  }
39 }
40 
42  : m_phi(0), m_eta(0), m_zed(0),
43  m_phiMinus(0), m_phiPlus(0),
44  m_etaMinus(0), m_etaPlus(0),
45  m_zedMinus(-s_zedWidthDefault), m_zedPlus(s_zedWidthDefault),
46  m_dzdrMinus(0), m_dzdrPlus(0),
47  m_drdzMinus(0), m_drdzPlus(0),
48  m_zedOuterMinus(0), m_zedOuterPlus(0),
49  m_fullscan(fullscan),
50  m_composite(false),
51  m_manageConstituents(true),
52  m_version(RoiVersion)
53 {
59  if ( m_fullscan ) construct( 0, -5, 5, 0, -M_PI, M_PI, 0, -s_zedWidthDefault, s_zedWidthDefault );
60 }
61 
62 
63 RoiDescriptor::RoiDescriptor(double eta_, double etaMinus_, double etaPlus_,
64  double phi_, double phiMinus_, double phiPlus_,
65  double zed_, double zedMinus_, double zedPlus_)
66  : m_phi(RoiUtil::phicheck(phi_)), m_eta(RoiUtil::etacheck(eta_)), m_zed(RoiUtil::zedcheck(zed_)),
67  m_phiMinus(0), m_phiPlus(0),
68  m_etaMinus(0), m_etaPlus(0),
69  m_zedMinus(0), m_zedPlus(0),
70  m_dzdrMinus(0), m_dzdrPlus(0),
71  m_drdzMinus(0), m_drdzPlus(0),
72  m_zedOuterMinus(0), m_zedOuterPlus(0),
73  m_fullscan(false),
74  m_composite(false),
75  m_manageConstituents(true),
76  m_version(RoiVersion)
77 {
78  construct( eta_, etaMinus_, etaPlus_, phi_, phiMinus_, phiPlus_, zed_, zedMinus_, zedPlus_ );
79 }
80 
81 
82 RoiDescriptor::RoiDescriptor(double etaMinus_, double etaPlus_,
83  double phiMinus_, double phiPlus_ )
84  : m_phi(0), m_eta(0), m_zed(0),
85  m_phiMinus(0), m_phiPlus(0),
86  m_etaMinus(0), m_etaPlus(0),
87  m_zedMinus(0), m_zedPlus(0),
88  m_dzdrMinus(0), m_dzdrPlus(0),
89  m_drdzMinus(0), m_drdzPlus(0),
90  m_zedOuterMinus(0), m_zedOuterPlus(0),
91  m_fullscan(false),
92  m_composite(false),
93  m_manageConstituents(true),
94  m_version(RoiVersion)
95 {
96  double eta_ = 0.5*(etaMinus_+etaPlus_);
97  double phi_ = 0.5*(phiMinus_+phiPlus_);
98 
99  if ( phiMinus_>phiPlus_ ) phi_ += M_PI;
100  if ( phi_<-M_PI ) phi_ += M_2PI;
101  if ( phi_>M_PI ) phi_ -= M_2PI;
102 
103  construct( eta_, etaMinus_, etaPlus_, phi_, phiMinus_, phiPlus_, 0, -s_zedWidthDefault, s_zedWidthDefault );
104 }
105 
106 
108  m_phi(roi.phi()), m_eta(roi.eta()), m_zed(roi.zed()),
109  m_phiMinus(0), m_phiPlus(0),
110  m_etaMinus(0), m_etaPlus(0),
111  m_zedMinus(0), m_zedPlus(0),
112  m_dzdrMinus(0), m_dzdrPlus(0),
113  m_drdzMinus(0), m_drdzPlus(0),
114  m_zedOuterMinus(0), m_zedOuterPlus(0),
115  m_fullscan(roi.isFullscan()),
116  m_composite(roi.composite()),
117  m_manageConstituents(true),
118  m_version(roi.version()) {
119 
121 
122 }
123 
125 
126 
128 
129  if ( this==&roi ) return *this;
130  construct( roi );
131  m_fullscan = roi.isFullscan();
132  m_composite = roi.composite();
133  m_manageConstituents = true;
134  m_version = roi.version();
135 
136  if ( roi.size()>0 ) {
137  if ( m_manageConstituents ) {
139  for ( unsigned i=0 ; i<roi.size() ; i++ ) push_back( new RoiDescriptor( *roi.at(i) ) );
140  }
141  else {
143  for ( unsigned i=0 ; i<roi.size() ; i++ ) push_back( roi.at(i) );
144  }
145  }
146 
147  return *this;
148 }
149 
150 
151 RoiDescriptor& RoiDescriptor::operator=( const RoiDescriptor& roi ) { return operator=( static_cast<const IRoiDescriptor&>(roi) ); }
152 
153 
154 
156  if ( manageConstituents() ) for ( roi_iterator itr=begin() ; itr!=end() ; itr++ ) delete *itr;
157 }
158 
159 
160 void RoiDescriptor::construct(double eta_, double etaMinus_, double etaPlus_,
161  double phi_, double phiMinus_, double phiPlus_,
162  double zed_, double zedMinus_, double zedPlus_)
163 {
164  s_firstInstanceCreated = true;
165 
166  m_eta = eta_;
167  m_phi = phi_;
168  m_zed = zed_;
169 
170  if ( std::isnan(m_eta) ) throw std::invalid_argument( "RoiDescriptor: eta nan" );
171  if ( std::isnan(m_phi) ) throw std::invalid_argument( "RoiDescriptor: phi nan" );
172  if ( std::isnan(m_zed) ) throw std::invalid_argument( "RoiDescriptor: zed nan" );
173 
174 
175  m_etaPlus = etaPlus_;
176  m_etaMinus = etaMinus_;
177 
178  if ( std::isnan(m_etaPlus) ) throw std::invalid_argument( "RoiDescriptor: etaPlus nan" );
179  if ( std::isnan(m_etaMinus) ) throw std::invalid_argument( "RoiDescriptor: etaMinus nan" );
180 
181 
182  m_zedMinus = zedMinus_;
183  m_zedPlus = zedPlus_;
184 
185  if ( std::isnan(m_zedPlus) ) throw std::invalid_argument( "RoiDescriptor: zedPlus nan" );
186  if ( std::isnan(m_zedMinus) ) throw std::invalid_argument( "RoiDescriptor: zedMinus nan" );
187 
188 
189  // deal with double -> float M_PI conversion
190 
191  m_phiPlus = phiPlus_;
192 
193  if ( std::isnan(m_phiPlus) ) throw std::invalid_argument( "RoiDescriptor: phiPlus nan" );
194 
195 
196  while ( m_phiPlus> M_PIF ) m_phiPlus -= M_2PI;
197  while ( m_phiPlus<-M_PIF ) m_phiPlus += M_2PI;
205  if ( m_phiPlus> M_PI ) m_phiPlus -= 1e-7;
206  if ( m_phiPlus<-M_PI ) m_phiPlus += 1e-7;
207 
208 
209  m_phiMinus = phiMinus_;
210 
211  if ( std::isnan(m_phiMinus) ) throw std::invalid_argument( "RoiDescriptor: phiMinus nan" );
212 
213  while ( m_phiMinus<-M_PIF ) m_phiMinus += M_2PI;
214  while ( m_phiMinus> M_PIF ) m_phiMinus -= M_2PI;
216  if ( m_phiMinus> M_PI ) m_phiMinus -= 1e-7;
217  if ( m_phiMinus<-M_PI ) m_phiMinus += 1e-7;
218 
219 
221 
222  m_drdzMinus = std::tan(2*std::atan(std::exp(-etaMinus_)));
223  m_drdzPlus = std::tan(2*std::atan(std::exp(-etaPlus_)));
224 
227 
228  const double maxR = 1100; // maximum radius of an ID RoI, hmmm should be a configurable parameter?
229 
232 
233 }
234 
235 
237  construct( roi.eta(), roi.etaMinus(), roi.etaPlus(),
238  roi.phi(), roi.phiMinus(), roi.phiPlus(),
239  roi.zed(), roi.zedMinus(), roi.zedPlus() );
240 }
241 
244 double RoiDescriptor::zedMin(double r) const { return r*m_dzdrMinus+m_zedMinus; }
245 double RoiDescriptor::zedMax(double r) const { return r*m_dzdrPlus+m_zedPlus; }
246 
247 double RoiDescriptor::rhoMin(double z) const { return (z-m_zedMinus)*m_drdzMinus; }
248 double RoiDescriptor::rhoMax(double z) const { return (z-m_zedPlus)*m_drdzPlus ; }
249 
250 
251 
253 // helper operators
254 
255 RoiDescriptor::operator std::string() const {
256  std::stringstream ss;
257  ss << " z: " << zed() << " (" << zedMinus() << " - " << zedPlus() << ")"
258  << " eta: " << eta() << " (" << etaMinus() << " - " << etaPlus() << ")"
259  << " phi: " << phi() << " (" << phiMinus() << " - " << phiPlus() << ")"
260  << ( isFullscan() ? " - fullscan": "" );
261  if ( composite() ) {
262  ss << "\t : components: " << size() << "\n";
263  for ( unsigned i=0 ; i<size() ; i++ ) ss << "\t\t" << i << " " << at(i) << " " << *at(i) << "\n";
264  }
265  return ss.str();
266 }
267 
268 std::string str( const RoiDescriptor& d ) {
269  return std::string(d);
270 }
271 
272 std::ostream& operator<<( std::ostream& m, const RoiDescriptor& d ) {
273  return m << std::string(d);
274 }
275 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
IRoiDescriptor::phi
virtual double phi() const =0
Methods to retrieve data members.
beamspotman.r
def r
Definition: beamspotman.py:676
RoiUtil::phicheck
double phicheck(double phi)
basic range checkers
Definition: RoiUtil.cxx:123
RoiDescriptor::m_composite
bool m_composite
flag this as a composite RoI
Definition: RoiDescriptor.h:233
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
operator<<
std::ostream & operator<<(std::ostream &m, const RoiDescriptor &d)
Definition: RoiDescriptor.cxx:272
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
IRoiDescriptor::roi_iterator
std::vector< const IRoiDescriptor * >::const_iterator roi_iterator
Definition: IRoiDescriptor.h:28
RoiDescriptor::m_eta
float m_eta
eta of RoI center
Definition: RoiDescriptor.h:213
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
hist_file_dump.d
d
Definition: hist_file_dump.py:137
RoiDescriptor::m_etaMinus
float m_etaMinus
eta of RoI at zedMinus
Definition: RoiDescriptor.h:218
IRoiDescriptor::etaMinus
virtual double etaMinus() const =0
str
std::string str(const RoiDescriptor &d)
Definition: RoiDescriptor.cxx:268
IRoiDescriptor::size
virtual unsigned size() const =0
number of constituents
M_PI
#define M_PI
Definition: ActiveFraction.h:11
RoiDescriptor::m_manageConstituents
bool m_manageConstituents
flag to determine whether consituents should be managed
Definition: RoiDescriptor.h:234
IRoiDescriptor::etaPlus
virtual double etaPlus() const =0
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
RoiDescriptor::operator=
RoiDescriptor & operator=(const IRoiDescriptor &r)
Definition: RoiDescriptor.cxx:127
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
RoiDescriptor::m_zedOuterPlus
float m_zedOuterPlus
z at front of RoI at the outer radius ( = 1100 mm)
Definition: RoiDescriptor.h:230
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
IRoiDescriptor::eta
virtual double eta() const =0
RoiDescriptor::push_back
void push_back(const IRoiDescriptor *roi)
add a RoiDescriptor
Definition: RoiDescriptor.h:157
RoiDescriptor::m_zedPlus
float m_zedPlus
z position at most positive position along the beamline
Definition: RoiDescriptor.h:221
RoiDescriptor::s_zedWidthDefault
static std::atomic< double > s_zedWidthDefault
default parameters - there may be better ways, but this will do
Definition: RoiDescriptor.h:206
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
IRoiDescriptor
Describes the API of the Region of Ineterest geometry.
Definition: IRoiDescriptor.h:23
RoiUtil::zedcheck
double zedcheck(double zed)
Definition: RoiUtil.cxx:141
RoiDescriptor::~RoiDescriptor
virtual ~RoiDescriptor()
Definition: RoiDescriptor.cxx:155
RoiDescriptor.h
RoiDescriptor::m_zedOuterMinus
float m_zedOuterMinus
z at rear of RoI at the outer radius ( = 1100 mm)
Definition: RoiDescriptor.h:229
RoiDescriptor::m_phiPlus
float m_phiPlus
most positive RoI in azimuthal
Definition: RoiDescriptor.h:217
IRoiDescriptor::phiMinus
virtual double phiMinus() const =0
RoiDescriptor
Describes the Region of Ineterest geometry It has basically 9 parameters.
Definition: RoiDescriptor.h:40
RoiDescriptor::end
virtual roi_iterator end() const override final
Definition: RoiDescriptor.h:161
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
RoiDescriptor::m_drdzMinus
float m_drdzMinus
dr/dz at the rear of the RoI
Definition: RoiDescriptor.h:226
RoiDescriptor::m_dzdrMinus
float m_dzdrMinus
dz/dr at the rear of the RoI
Definition: RoiDescriptor.h:223
RoiDescriptor::m_drdzPlus
float m_drdzPlus
dr/dz at the front of the RoI
Definition: RoiDescriptor.h:227
RoiDescriptor::m_zedMinus
float m_zedMinus
z position at most negative position along the beamline
Definition: RoiDescriptor.h:220
IRoiDescriptor::phiPlus
virtual double phiPlus() const =0
extreme phi values
RoiDescriptor::RoiDescriptor
RoiDescriptor(bool fullscan=ROI)
default constructor
Definition: RoiDescriptor.cxx:41
RoiUtil
Definition: RoiUtil.h:20
RoiDescriptor::rhoMax
virtual double rhoMax(double z) const override final
Definition: RoiDescriptor.cxx:248
RoiUtil.h
RoiDescriptor::m_dzdrPlus
float m_dzdrPlus
dz/dr at the front of the RoI
Definition: RoiDescriptor.h:224
RoiDescriptor::rhoMin
virtual double rhoMin(double z) const override final
accessors to calculate r position at position z along the RoI boundaries
Definition: RoiDescriptor.cxx:247
get_generator_info.version
version
Definition: get_generator_info.py:33
RoiDescriptor::m_zed
float m_zed
zed of RoI center
Definition: RoiDescriptor.h:214
IRoiDescriptor::zedPlus
virtual double zedPlus() const =0
the zed and eta values at the most forward and most rear ends of the RoI
RoiDescriptor::s_firstInstanceCreated
static std::atomic< bool > s_firstInstanceCreated
to ensure default width is only set once at job startup
Definition: RoiDescriptor.h:208
RoiDescriptor::zedWidthDefault
static double zedWidthDefault()
Definition: RoiDescriptor.h:183
IRoiDescriptor::isFullscan
virtual bool isFullscan() const =0
is this a full detector RoI?
RoiDescriptor::zedMin
virtual double zedMin(double r) const override final
methods to calculate z position at the RoI boundary at a given radius
Definition: RoiDescriptor.cxx:244
RoiDescriptor::begin
virtual roi_iterator begin() const override final
iterators
Definition: RoiDescriptor.h:160
RoiDescriptor::zedMax
virtual double zedMax(double r) const override final
Definition: RoiDescriptor.cxx:245
IRoiDescriptor::zed
virtual double zed() const =0
RoiDescriptor::m_fullscan
bool m_fullscan
flag this as a full detector RoI
Definition: RoiDescriptor.h:232
IRoiDescriptor::zedMinus
virtual double zedMinus() const =0
RoiDescriptor::manageConstituents
bool manageConstituents() const
always manage constituents ???
Definition: RoiDescriptor.h:141
M_2PI
#define M_2PI
Definition: CaloGpuGeneral_fnc.cxx:8
RoiDescriptor::m_phiMinus
float m_phiMinus
most negative RoI in azimuthal
Definition: RoiDescriptor.h:216
IRoiDescriptor::at
virtual const IRoiDescriptor * at(int i) const =0
find an RoiDescriptor constituent
RoiDescriptor::m_phi
float m_phi
phi of RoI center
Definition: RoiDescriptor.h:212
RoiUtil::etacheck
double etacheck(double eta)
Definition: RoiUtil.cxx:133
IRoiDescriptor::version
virtual int version() const =0
which roi version?
RoiDescriptor::m_etaPlus
float m_etaPlus
eta of RoI at zedPlus
Definition: RoiDescriptor.h:219
IRoiDescriptor::composite
virtual bool composite() const =0
Super RoI access methods.
RoiDescriptor::m_version
int m_version
transient version identifier
Definition: RoiDescriptor.h:236
RoiDescriptor::construct
void construct(double eta, double etaMinus, double etaPlus, double phi, double phiMinus, double phiPlus, double zed, double zedMinus, double zedPlus)
construct RoiDescriptor internals - similar to constructors
Definition: RoiDescriptor.cxx:160