ATLAS Offline Software
RegSelLayer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /**************************************************************************
6  **
7  ** File: RegSelLayer.cxx
8  **
9  ** Description: This is the layer structure at the moment it
10  ** just contains a vector of the modules in this
11  ** layer and checks all of them to see if they are
12  ** in the RoI. Eventually it will check these in
13  ** a more efficient manner.
14  **
15  **
16  ** Author: M.Sutton
17  **
18  ** Created: Wed Apr 4 17:40:28 BST 2007
19  ** Modified:
20  **
21  **
22  **
23  **************************************************************************/
24 
25 
26 #include "RegSelLUT/RegSelLayer.h"
27 #include "RegSelLUT/RegSelTimer.h"
28 
29 
30 #include <map>
31 #include <set>
32 #include <string>
33 #include <iostream>
34 #include <fstream>
35 #include <cmath>
36 
37 
39  m_modules.clear();
40  m_disabled.clear();
41  std::vector<std::vector<const RegSelModule*> >::iterator itr(m_phimaps.begin()) ;
42  for ( ; itr!=m_phimaps.end() ; ++itr ) (*itr).clear();
43  m_set = false;
44 }
45 
46 
47 // this calculates how many segments in phi should be used by clustering
48 // the modules together
49 
51 
52  // if multiple radial "layers" in this actual layer (as in the TRT
53  // barrel, or the SCT endcaps) just find the inner most layer, as
54  // this will have the largest segmentation in phi
55 
56  if ( m_modules.size()==0 ) return 0;
57 
58  double r_in = m_modules.back()->rMax();
59 
60  for ( int i=m_modules.size()-1 ; i-- ; ) {
61  double mod_rmax = m_modules[i]->rMax();
62  if ( mod_rmax<r_in ) r_in=mod_rmax;
63  }
64 
65  // now cluster the ends of these innermost modules to calcute how
66  // many phi segments to use
67 
68  // cluster vectors
69  PhiCluster cluster;
70 
71  // use the minimum rMax+4mm just in case the detector has "moved"
72  double r2_in = 2*(r_in+4);
73 
74  for ( int i=m_modules.size() ; i-- ; ) {
75  if ( (m_modules[i]->rMin()+m_modules[i]->rMax())<r2_in ) cluster.addModule(*m_modules[i]);
76  }
77 
78  return cluster.size();
79 }
80 
81 
82 
83 
84 // add a module to the PhiCluster - used to calculate the
85 // phi segmentation automatically
86 
88 
89  static const double M_TWOPI = 2*M_PI;
90 
91  double pmin = m.phiMin();
92  double pmax = m.phiMax();
93 
94  if ( pmin>pmax ) pmax+=M_TWOPI;
95 
96  double overlap = 0.2*std::fabs(pmax-pmin);
97  double start = pmin;
98 
99  bool notoverlaping = true;
100  for ( int i=m_positions.size() ; i-- ; ) {
101 
102  double tdelphi = m_positions[i]-start;
103 
104  if ( tdelphi>M_PI ) start+=M_TWOPI;
105  if ( tdelphi<-M_PI ) start-=M_TWOPI;
106 
107  if ( std::fabs(m_positions[i]-start)<overlap ) {
109  m_N[i]++;
110  m_positions[i] /= m_N[i];
111  notoverlaping = false;
112  break;
113  }
114  }
115 
116  if ( notoverlaping ) {
117  m_N.push_back(1);
118  m_positions.push_back(start);
119  }
120 
121 }
122 
123 
124 
125 
126 
127 // add a module to the vector, update the liimits for
128 // this layer as well
129 
131  m_modules.push_back(&module);
132 
133  // if ( module.enabled() ) m_enabledmodules.push_back(&module);
134  // m_enabledmodules.push_back(&module);
135 
136  // std::cout << module
137  // << "\t rmin=" << rMin() << "\t module.rMin=" << module.rMin()
138  // << "\t zmin=" << zMin() << "\t module.zMin=" << module.zMin() << std::endl;
139 
140  if ( m_set ) {
141  if ( module.rMin()<rMin()) rMin(module.rMin());
142  if ( module.rMax()>rMax()) rMax(module.rMax());
143 
144  if ( module.zMin()<zMin()) zMin(module.zMin());
145  if ( module.zMax()>zMax()) zMax(module.zMax());
146 
147  if ( module.phiMin()<phiMin()) phiMin(module.phiMin());
148  if ( module.phiMax()>phiMax()) phiMax(module.phiMax());
149  }
150  else {
151  m_set = true;
152  rMin(module.rMin());
153  rMax(module.rMax());
154  zMin(module.zMin());
155  zMax(module.zMax());
156  phiMin(module.phiMin());
157  phiMax(module.phiMax());
158  }
159 
160 }
161 
162 
163 // set up the internal list of disabled modules for
164 // this layer
165 
167  // std::cout << "RegSelLayer::setupDisabledModuleList() clear() m_disabled.size()=" << m_disabled.size() << std::endl;
168  m_disabled.clear();
169  // std::cout << "RegSelLayer::setupDisabledModuleList() going into loop m_modules.size()=" << m_modules.size() << std::endl;
170  std::vector<const RegSelModule*>::const_iterator mptr(m_modules.begin());
171  for ( ; mptr!=m_modules.end() ; ++mptr ) {
172  if ( !(*mptr)->enabled() ) m_disabled.push_back(*mptr);
173  }
174  // std::cout << "RegSelLayer::setupDisabledModuleList() disabled " << m_disabled.size() << " modules" << std::endl;
175 }
176 
177 
178 // add the modules in this layer to a vector of modules
197 void RegSelLayer::getModules(const RegSelRoI& roi, std::vector<const RegSelModule*>& modules) const {
198 
199  // std::cout << "RegSelLayer::getModules() " << *this << std::endl;
200 
201 #if 0
202 
203  // look through all the modules in this layer and
204  // don't use the phi segmentation speed up
205 
206  std::vector<const RegSelModule*>::const_iterator mptr(m_modules.begin());
207 
208  for ( ; mptr!=m_modules.end() ; mptr++ ) {
209  // is the module inside the RoI ???
210  if ( (*mptr)->enabled() && (*mptr)->inRoI(roi) ) {
211  // then add them to the list
212  modules.push_back(*mptr);
213  }
214  }
215 
216 #else
217 
218  // std::cout << "\tRegSelLayer::getModules() " << roi << std::endl;
219 
220  // get the list of all modules in the phi segments
221  // corresponding to this RoI
222 
223  int roi_phiMin = (int) ((roi.getphiMin()-phiMin())*m_ideltaphi-1); // look at adjacent segments
224  int roi_phiMax = (int) ((roi.getphiMax()-phiMin())*m_ideltaphi+1); // also, hence the +-1
225 
226  int roi_phiWidth = roi_phiMax-roi_phiMin;
227 
228  // have to see if the RoI spans the phi=pi boundary,
229  // and also whether we need to check segments that span the booundary
230  bool noswap = true;
231 
232 
233  // there MUST be a simpler way to do it than all these add hoc conditions
234  // there just has to be, this is *awful* code
235  if ( roi_phiWidth>=m_Nphi ) {
236  if ( roi_phiMin>roi_phiMax ) noswap = false;
237  roi_phiMin = 0;
238  roi_phiMax = m_Nphi-1;
239  }
240  else {
241 
242  if ( roi.getphiWidth()*m_ideltaphi>=m_Nphi-2 ) roi_phiMax = roi_phiMin+m_Nphi-1;
243 
244  if ( roi_phiMax>=m_Nphi ) { roi_phiMax -= m_Nphi; noswap=false; }
245  if ( roi_phiMin<0 ) { roi_phiMin += m_Nphi; noswap=false; }
246  if ( roi_phiMin==0 && roi_phiMax<m_Nphi-1 && roi_phiMax!=0 ) { roi_phiMin = m_Nphi-1; noswap=false; }
247  // if ( roi_phiMin==0 && roi_phiMax==0 ) { roi_phiMin = m_Nphi-1; noswap=false; }
248 
249  }
250 
251  // std::cout << "roi phimin=" << roi.getphiMin() << "\tphimax=" << roi.getphiMax() << std::endl;
252  // std::cout << "roi iphimin=" << roi_phiMin << "\tiphimax=" << roi_phiMax << std::endl;
253 
254  // roi_phiWidth = roi_phiMax-roi_phiMin;
255 
256  // if roi not in phi boundary
257  if ( roi.getphiMin()<=roi.getphiMax() && noswap ) {
258  for ( int i=roi_phiMin ; i<=roi_phiMax ; i++ ) {
259  std::vector<const RegSelModule*>::const_iterator mptr(m_phimaps[i].begin());
260  std::vector<const RegSelModule*>::const_iterator eptr(m_phimaps[i].end());
261  for ( ; mptr!=eptr ; ++mptr ) {
262  if ( (*mptr)->enabled() && (*mptr)->inRoI(roi) ) modules.push_back(*mptr);
263  }
264  }
265  }
266  else {
267  // roi spans phi=pi boundary
268  // do phi<0 part of roi
269  for ( int i=0 ; i<=roi_phiMax ; i++ ) {
270  std::vector<const RegSelModule*>::const_iterator mptr(m_phimaps[i].begin());
271  std::vector<const RegSelModule*>::const_iterator eptr(m_phimaps[i].end());
272  for ( ; mptr!=eptr ; ++mptr ) {
273  if ( (*mptr)->enabled() && (*mptr)->inRoI(roi) ) modules.push_back(*mptr);
274  }
275  }
276  // do phi>0 part of roi
277  // this is needed in case the max and min phi slice are the same
278  // so the modules aren't added twice
279  int firstbin = (roi_phiMin<roi_phiMax?roi_phiMax+1:roi_phiMin);
280  for ( int i=firstbin ; i<m_Nphi ; i++ ) {
281  std::vector<const RegSelModule*>::const_iterator mptr(m_phimaps[i].begin());
282  std::vector<const RegSelModule*>::const_iterator eptr(m_phimaps[i].end());
283  for ( ; mptr!=eptr ; ++mptr ) {
284  if ( (*mptr)->enabled() && (*mptr)->inRoI(roi) ) modules.push_back(*mptr);
285  }
286  }
287  }
288 
289 #endif
290 
291 }
292 
293 
294 
295 void RegSelLayer::getModules( std::vector<const RegSelModule*>& modules) const {
296  std::vector<const RegSelModule*>::const_iterator mptr(m_modules.begin());
297  std::vector<const RegSelModule*>::const_iterator eptr(m_modules.end());
298  for ( ; mptr!=eptr ; ++mptr ) if ( (*mptr)->enabled() ) modules.push_back(*mptr);
299 }
300 
301 
302 
303 
304 
305 
306 
307 
308 
309 // look through all the disabled modules in this layer and
310 // don't use any phi segmentation speed up
311 // NB this is slow but will be speeded up by storing
312 // disabled modules and only looking at them
313 
314 void RegSelLayer::getDisabledModules(const RegSelRoI& roi, std::vector<const RegSelModule*>& modules) const {
315 
316  // std::cout << "RegSelLayer::getDisabledModules() " << *this << std::endl;
317  // std::cout << "RegSelLayer::getDisabledModules() m_disabled.size()=" << m_disabled.size() < std::endl;
318 
319  std::vector<const RegSelModule*>::const_iterator mptr(m_disabled.begin());
320  // std::vector<const RegSelModule*>::const_iterator mptr(m_modules.begin());
321 
322  for ( ; mptr!=m_disabled.end() ; ++mptr ) {
323  // is the module inside the RoI ???
324  if ( (*mptr)->enabled()==false && (*mptr)->inRoI(roi) ) {
325  // then add them to the list
326  modules.push_back(*mptr);
327  }
328  }
329 
330 }
331 
332 
333 
335 
336  // std::cout << "RegSelLayer::createMaps() " << *this << std::endl;
337 
339 
340  if ( m_Nphi == 0 ) return;
341 
342  // std::cout << "\t\t\tRegSelLayer::createMaps() layer with " << m_Nphi << " phi segments" << std::endl;
343 
344  m_phimaps.resize(m_Nphi);
345 
346  m_phiMin = -M_PI+0.001;
347  m_phiMax = M_PI+0.001;
348 
349  m_ideltaphi = 0.5*m_Nphi/M_PI;
350 
351  // std::map<const RegSelModule*, const RegSelModule*> tmap;
352  std::set<const RegSelModule*> tmap;
353 
354  double trmax = 0;
355 
356  std::vector<const RegSelModule*>::const_iterator mptr(m_modules.begin());
357  for ( ; mptr!=m_modules.end() ; ++mptr ) {
358 
359  double phicent = 0.5*((*mptr)->phiMax()+(*mptr)->phiMin());
360 
361  if ( (*mptr)->rMax()>trmax ) trmax = (*mptr)->rMax();
362 
363  // if cell spans pi boundary
364  if ( (*mptr)->phiMax()<(*mptr)->phiMin() ) phicent += M_PI;
365 
366  if ( phicent>M_PI ) phicent -= 2*M_PI;
367  if ( phicent<-M_PI ) phicent += 2*M_PI;
368 
369  int phibin = ((int)((phicent-phiMin())*m_ideltaphi))%m_Nphi;
370 
371  // std::cout << "phibin=" << (int)phibin
372  // << "\tphicent=" << phicent
373  // << "\t [ " << (*mptr)->phiMin() << " - " << (*mptr)->phiMax() << " ]" << std::endl;
374 
375  // check module isn't already in another phi segment
376  if ( tmap.find(*mptr)!=tmap.end() ) continue;
377 
378  // tmap[*mptr] = *mptr;
379  tmap.insert(*mptr);
380  m_phimaps[phibin].push_back(*mptr);
381 
382  }
383 
384  // std::cout << "RegSelLayer::createMaps() exiting" << std::endl;
385 }
386 
387 
388 
389 
390 
391 std::ostream& operator<<(std::ostream& s, const RegSelLayer& layer) {
392  return s << "[ layer ID=" << layer.ID()
393  << ",\tNmodules=" << layer.size()
394  << ",\tr=" << layer.rMin() << " - " << layer.rMax()
395  << ",\tz=" << layer.zMin() << " - " << layer.zMax()
396  << " ]";
397 }
398 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
RegSelModule
Definition: RegSelModule.h:38
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
RegSelLayer::phiMax
double phiMax() const
Definition: RegSelLayer.h:87
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
RegSelLayer::getDisabledModules
void getDisabledModules(const RegSelRoI &roi, std::vector< const RegSelModule * > &modules) const
Definition: RegSelLayer.cxx:314
RegSelLayer::PhiCluster::addModule
void addModule(const RegSelModule &m)
Definition: RegSelLayer.cxx:87
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
M_PI
#define M_PI
Definition: ActiveFraction.h:11
RegSelLayer::m_phiMin
double m_phiMin
Definition: RegSelLayer.h:127
RegSelLayer::m_modules
std::vector< const RegSelModule * > m_modules
Definition: RegSelLayer.h:117
RegSelLayer::PhiCluster
Definition: RegSelLayer.h:98
RegSelRoI::getphiWidth
double getphiWidth() const
Definition: RegSelRoI.h:69
RegSelLayer
Definition: RegSelLayer.h:39
RegSelTimer.h
ZRObject::rMin
double rMin() const
Definition: ZRObject.h:80
RegSelLayer::m_phiMax
double m_phiMax
Definition: RegSelLayer.h:128
operator<<
std::ostream & operator<<(std::ostream &s, const RegSelLayer &layer)
Definition: RegSelLayer.cxx:391
ZRObject::rMax
double rMax() const
Definition: ZRObject.h:81
RegSelLayer::m_disabled
std::vector< const RegSelModule * > m_disabled
Definition: RegSelLayer.h:118
RegSelLayer::PhiCluster::size
unsigned size() const
Definition: RegSelLayer.h:103
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
ZRObject::zMin
double zMin() const
Definition: ZRObject.h:83
RegSelLayer::clusterModules
int clusterModules() const
Definition: RegSelLayer.cxx:50
RegSelLayer.h
python.PyAthena.module
module
Definition: PyAthena.py:131
RegSelRoI::getphiMax
double getphiMax() const
Definition: RegSelRoI.h:62
RegSelLayer::phiMin
double phiMin() const
Definition: RegSelLayer.h:86
RegSelLayer::addModule
void addModule(const RegSelModule &module)
Definition: RegSelLayer.cxx:130
lumiFormat.i
int i
Definition: lumiFormat.py:85
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
RegSelLayer::PhiCluster::m_N
std::vector< int > m_N
Definition: RegSelLayer.h:105
RegSelRoI
Definition: RegSelRoI.h:32
RegSelRoI::getphiMin
double getphiMin() const
Definition: RegSelRoI.h:61
RegSelLayer::PhiCluster::m_positions
std::vector< double > m_positions
Definition: RegSelLayer.h:106
ZRObject::zMax
double zMax() const
Definition: ZRObject.h:84
RegSelLayer::getModules
void getModules(const RegSelRoI &roi, std::vector< const RegSelModule * > &modules) const
Fixme: This is the completely correct solution, where each module is allowed to be at a completely di...
Definition: RegSelLayer.cxx:197
RegSelLayer::m_ideltaphi
double m_ideltaphi
Definition: RegSelLayer.h:125
RegSelLayer::setupDisabledModuleList
void setupDisabledModuleList()
Definition: RegSelLayer.cxx:166
RegSelLayer::m_Nphi
int m_Nphi
Definition: RegSelLayer.h:123
RegSelLayer::createMaps
void createMaps()
Definition: RegSelLayer.cxx:334
RegSelLayer::m_set
bool m_set
Definition: RegSelLayer.h:114
RegSelLayer::reset
void reset()
Definition: RegSelLayer.cxx:38
TrackOverlayDecisionAlg::M_TWOPI
const double M_TWOPI
Definition: TrackOverlayDecisionAlg.h:27
RegSelLayer::m_phimaps
std::vector< std::vector< const RegSelModule * > > m_phimaps
Definition: RegSelLayer.h:130