ATLAS Offline Software
RegSelEtaPhiLUT.cxx
Go to the documentation of this file.
1 // emacs: this is -*- c++ -*-
2 /*
3  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
4 */
5 //
6 // @file RegSelEtaPhiLUT.h
7 //
8 // a look up table for eta-phi space divided up into
9 // a set of elements Neta x Nphi.
10 //
11 // "Modules" are added to the lookup table, and are
12 // stored in each element that they overlap with
13 //
14 // To accelerate the look up when there are a large
15 // number of modules, only elements that overlap with
16 // the roi are examined.
17 //
18 // Because RoIs are defined in terms of a z range,
19 // without these z positions, eta coordinates are
20 // not well defined.
21 // As a result, when passed an RoI, this class calculates
22 // a virtual RoI, just in eta-phi space, where the eta
23 // range corresponds to the maxuimum and minimum eta
24 // possible from any z position with the RoI where the
25 // object can be completely contained within a user
26 // specified radius. The default value is 600mm, chosen
27 // to completely contain the outer radius of the SCT
28 //
29 //
30 //
31 
33 
34 
35 
38 RegSelEtaPhiLUT::RegSelEtaPhiLUT(int Neta, int Nphi) :
39  m_etamin(-3), m_etamax(3), m_Neta(Neta),
40  m_phimin(0), m_phimax(2*M_PI), m_Nphi(Nphi),
41  m_grandmap( m_etamin, m_etamax, m_phimin, m_phimax,
42  std::vector< std::vector< map_element > >() )
43 {
47 
48  std::vector< std::vector< map_element > >& tmap = m_grandmap.payload();
49 
50  // std::cout << "RegSelEtaPhiUT::RegSelEtaPhiLUT() Neta " << Neta << "\tNphi " << Nphi << std::endl;
51 
52  moduleset empty_set;
53 
54  for ( int i=0 ; i<m_Neta ; i++ ) {
55 
56  double tetamin = m_etamin+i/m_ideta;
57  double tetamax = m_etamin+(i+1)/m_ideta;
58 
59  std::vector< map_element > row;
60 
61  for ( int j=0 ; j<m_Nphi ; j++ ) {
62  double tphimin = m_phimin+j/m_idphi;
63  double tphimax = m_phimin+(j+1)/m_idphi;
64 
65  map_element m( tetamin, tetamax, tphimin, tphimax, empty_set );
66 
67  row.push_back( m );
68 
69  }
70 
71  tmap.push_back( row );
72 
73  }
74 
75 }
76 
77 
78 
81 
82 
83 
84 
88 
89  // std::cout << "adding... " << m << std::endl;
90 
91  std::vector< std::vector< map_element > >& tmap = m_grandmap.payload();
92 
93  int first_eta = (m.etamin()-m_etamin)*m_ideta;
94  int last_eta = (m.etamax()-m_etamin)*m_ideta;
95 
96  int first_phi = (m.phimin()-m_phimin)*m_idphi;
97  int last_phi = (m.phimax()-m_phimin)*m_idphi;
98 
100  if ( !m_grandmap.overlap( m ) ) return false;
101 
103  if ( first_eta<0 ) first_eta = 0;
104  if ( last_eta>=m_Neta ) last_eta = m_Neta-1;
105 
107  if ( first_phi<0 ) first_phi += m_Nphi;
108  if ( first_phi>=m_Nphi ) first_phi -= m_Nphi;
109 
110  if ( last_phi<0 ) last_phi += m_Nphi;
111  if ( last_phi>=m_Nphi ) last_phi -= m_Nphi;
112 
113 
115  if ( first_phi<last_phi ) {
116  for ( int i=int(first_eta) ; i<=last_eta ; i++ ) {
117  for ( int j=int(first_phi) ; j<=last_phi ; j++ ) tmap[i][j].payload().insert( m );
118  }
119  }
120  else {
121  for ( int i=int(first_eta) ; i<=last_eta ; i++ ) {
122  for ( int j=0 ; j<=int(last_phi) ; j++ ) tmap[i][j].payload().insert( m );
123  for ( int j=first_phi ; j<m_Nphi ; j++ ) tmap[i][j].payload().insert( m );
124  }
125  }
126 
127  // std::cout << "added" << std::endl;
128 
129  return true;
130 }
131 
132 
133 
134 
138  std::vector<IdentifierHash>& hashids,
139  double r ) const {
140 
141  hashids.clear();
142 
143  std::set<EtaPhiModule> modules;
144 
145  getElements( roi, modules, r );
146 
147  hashids.reserve( modules.size() );
148 
149  std::set<EtaPhiModule>::iterator rpitr=modules.begin();
150  std::set<EtaPhiModule>::iterator rpend=modules.end();
151 
152  while ( rpitr!=rpend ) {
153  hashids.push_back( rpitr->payload() );
154  ++rpitr;
155  }
156 
157 }
158 
159 
160 
161 
162 
166 
168  std::set<EtaPhiModule>& modules,
169  double idradius ) const {
170 
171  modules.clear();
172 
173  // struct timeval timer = simpletimer_start();
174 
176  const EtaPhiBase virtual_roi( roi.etaMinLimit(idradius), roi.etaMaxLimit(idradius),
177  roi.getphiMin(), roi.getphiMax() );
178 
179  // double time = simpletimer_stop( timer );
180 
182  bool inmap = m_grandmap.overlap( virtual_roi );
183 
184  if ( !inmap ) return virtual_roi;
185 
186  int first_phi = (virtual_roi.phimin()-m_phimin)*m_idphi;
187  int last_phi = (virtual_roi.phimax()-m_phimin)*m_idphi;
188 
189  int first_eta = (virtual_roi.etamin()-m_etamin)*m_ideta;
190  int last_eta = (virtual_roi.etamax()-m_etamin)*m_ideta;
191 
194  if ( first_eta<0 ) first_eta = 0;
195  if ( last_eta>=m_Neta ) last_eta = m_Neta-1;
196 
198  if ( first_phi<0 ) first_phi += m_Nphi;
199  if ( first_phi>=m_Nphi ) first_phi -= m_Nphi;
200 
201  if ( last_phi<0 ) last_phi += m_Nphi;
202  if ( last_phi>=m_Nphi ) last_phi -= m_Nphi;
203 
204  const std::vector< std::vector< map_element > >& tmap = map();
205 
207  if ( first_phi<last_phi ) {
208  for ( int i=first_eta ; i<=last_eta ; i++ ) {
209  getRowElements( virtual_roi, tmap[i], first_phi, last_phi, modules );
210  }
211  }
212  else {
213  for ( int i=first_eta ; i<=last_eta ; i++ ) {
214  getRowElements( virtual_roi, tmap[i], 0, last_phi, modules );
215  getRowElements( virtual_roi, tmap[i], first_phi, m_Nphi-1, modules );
216  }
217  }
218 
219  return virtual_roi;
220 }
221 
222 
223 
224 
225 
226 
227 
228 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
RegSelEtaPhiLUT::getElements
const EtaPhiBase getElements(const RegSelRoI &roi, std::set< EtaPhiModule > &modules, double idradius=600) const
get the modules from the elements, returns the virtual eta-phi roi corresponding to the virtual eta -...
Definition: RegSelEtaPhiLUT.cxx:167
RegSelEtaPhiLUT::m_grandmap
TRegSelEtaPhiModule< std::vector< std::vector< map_element > > > m_grandmap
overall map, can get the limits from the object, can have different numbers and different ranges for ...
Definition: RegSelEtaPhiLUT.h:141
query_example.row
row
Definition: query_example.py:24
beamspotman.r
def r
Definition: beamspotman.py:676
RegSelEtaPhiLUT::getRowElements
void getRowElements(const EtaPhiBase &virtual_roi, const std::vector< map_element > &row, int first_phi, int last_phi, std::set< EtaPhiModule > &modules) const
get the modules from the elements in the phi direction, called for each eta slice processed
Definition: RegSelEtaPhiLUT.h:98
RegSelEtaPhiLUT::m_Nphi
int m_Nphi
Definition: RegSelEtaPhiLUT.h:134
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
RegSelEtaPhiLUT::m_etamax
double m_etamax
Definition: RegSelEtaPhiLUT.h:124
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
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
RegSelEtaPhiLUT::m_Neta
int m_Neta
Definition: RegSelEtaPhiLUT.h:126
RegSelEtaPhiLUT::m_ideta
double m_ideta
inverse eta element size
Definition: RegSelEtaPhiLUT.h:129
RegSelEtaPhiLUT::RegSelEtaPhiLUT
RegSelEtaPhiLUT(int Neta=3, int Nphi=32)
defines the number of elements in the internal eta-phi element storage NB: these numbers of internal ...
Definition: RegSelEtaPhiLUT.cxx:38
M_PI
#define M_PI
Definition: ActiveFraction.h:11
RegSelEtaPhiLUT.h
EtaPhiBase::etamax
double etamax() const
Definition: RegSelEtaPhiModule.h:56
RegSelEtaPhiLUT::map
const std::vector< std::vector< map_element > > & map() const
access the actual complete map - shouldn't be public really, is only so for the ostream streamer
Definition: RegSelEtaPhiLUT.h:86
EtaPhiBase::etamin
double etamin() const
accessors
Definition: RegSelEtaPhiModule.h:55
EtaPhiBase::phimin
double phimin() const
Definition: RegSelEtaPhiModule.h:58
RegSelEtaPhiLUT::m_idphi
double m_idphi
inverse phi element size
Definition: RegSelEtaPhiLUT.h:137
RegSelEtaPhiLUT::getModules
void getModules(const RegSelRoI &roi, std::vector< IdentifierHash > &hashids, double r=600) const
get back a vector of the payload for each of the eta-phi segments that overlap with this roi
Definition: RegSelEtaPhiLUT.cxx:137
RegSelRoI::getphiMax
double getphiMax() const
Definition: RegSelRoI.h:62
EtaPhiBase::phimax
double phimax() const
Definition: RegSelEtaPhiModule.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:92
vector
Definition: MultiHisto.h:13
RegSelRoI
Definition: RegSelRoI.h:32
RegSelRoI::getphiMin
double getphiMin() const
Definition: RegSelRoI.h:61
RegSelEtaPhiLUT::m_phimin
double m_phimin
Definition: RegSelEtaPhiLUT.h:131
RegSelRoI::etaMaxLimit
double etaMaxLimit(double r) const
find the max eta limits for an object fully contained within an roi, bounded with the specifed radius
Definition: RegSelRoI.h:94
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
RegSelEtaPhiLUT::addModule
bool addModule(EtaPhiModule &m)
add an element, returns true if element added.
Definition: RegSelEtaPhiLUT.cxx:87
RegSelEtaPhiLUT::m_phimax
double m_phimax
Definition: RegSelEtaPhiLUT.h:132
RegSelEtaPhiLUT::~RegSelEtaPhiLUT
virtual ~RegSelEtaPhiLUT()
destructor
Definition: RegSelEtaPhiLUT.cxx:80
RegSelEtaPhiLUT::moduleset
std::set< EtaPhiModule > moduleset
tower of the actual modules assigned to each element of the lookup table
Definition: RegSelEtaPhiLUT.h:55
RegSelEtaPhiLUT::m_etamin
double m_etamin
eta and phi ranges and number of internal book keeping elements in eta and phi directions
Definition: RegSelEtaPhiLUT.h:123
RegSelRoI::etaMinLimit
double etaMinLimit(double r) const
find the min eta limits for an object fully contained within an roi, bounded with the specifed radius
Definition: RegSelRoI.h:83