ATLAS Offline Software
Loading...
Searching...
No Matches
RegSelSiLUT.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5/**************************************************************************
6 **
7 ** File: RegSelSiLUT.cxx
8 **
9 ** Description: RegionSelector Si LUT code
10 **
11 **
12 **
13 ** Author: M.Sutton
14 **
15 ** Created: Wed Apr 4 16:04:30 BST 2007
16 ** Modified:
17 **
18 **
19 **
20 **************************************************************************/
21
25
26#include "RegSelLUT/RegSelROB.h"
27
28#include <iostream>
29#include <fstream>
30#include <set>
31
32
33
34
36
38
39void RegSelSiLUT::HashIDList( const IRoiDescriptor& roi, std::vector<IdentifierHash>& idlist ) const {
41 if ( m_ID == RPC ) RegSelSiLUT::cleanup( idlist );
42}
43
44
45void RegSelSiLUT::HashIDList( long layer, const IRoiDescriptor& roi, std::vector<IdentifierHash>& idlist ) const {
47 if ( m_ID == RPC ) RegSelSiLUT::cleanup( idlist );
48}
49
50
52
53void RegSelSiLUT::ROBIDList( const IRoiDescriptor& roi, std::vector<uint32_t>& roblist ) const {
55}
56
57
58void RegSelSiLUT::ROBIDList( long layer, const IRoiDescriptor& roi, std::vector<uint32_t>& roblist ) const {
60}
61
62
63
65
67
68void RegSelSiLUT::HashIDList_internal( const IRoiDescriptor& roi, std::vector<IdentifierHash>& idlist ) const {
69 if ( roi.isFullscan() ) return getHashList( idlist );
70 RegSelRoI roitmp( roi.zedMinus(), roi.zedPlus(), roi.phiMinus(), roi.phiPlus(), roi.etaMinus(), roi.etaPlus() );
71 getHashList( roitmp, idlist );
72 if ( m_ID == MM || m_ID == sTGC ) removeDuplicates( idlist );
73}
74
75
76void RegSelSiLUT::HashIDList_internal( long layer, const IRoiDescriptor& roi, std::vector<IdentifierHash>& idlist ) const {
77 if ( roi.isFullscan() ) return getHashList( layer, idlist );
78 RegSelRoI roitmp( roi.zedMinus(), roi.zedPlus(), roi.phiMinus(), roi.phiPlus(), roi.etaMinus(), roi.etaPlus() );
79 getHashList( roitmp, layer, idlist );
80 if ( m_ID == MM || m_ID == sTGC ) removeDuplicates( idlist );
81}
82
84
85void RegSelSiLUT::ROBIDList_internal( const IRoiDescriptor& roi, std::vector<uint32_t>& roblist ) const {
86 if ( roi.isFullscan() ) return getRobList( roblist );
87 RegSelRoI roitmp( roi.zedMinus(), roi.zedPlus(), roi.phiMinus(), roi.phiPlus(), roi.etaMinus(), roi.etaPlus() );
88 getRobList( roitmp, roblist);
89}
90
91
92void RegSelSiLUT::ROBIDList_internal( long layer, const IRoiDescriptor& roi, std::vector<uint32_t>& roblist ) const {
93 if ( roi.isFullscan() ) return getRobList( layer, roblist );
94 RegSelRoI roitmp( roi.zedMinus(), roi.zedPlus(), roi.phiMinus(), roi.phiPlus(), roi.etaMinus(), roi.etaPlus() );
95 getRobList( roitmp, layer, roblist);
96}
97
98
99
101
103 RegSelName(r.getName()), m_ID(r.ID()) {
104 construct();
105 addModules(r.getModules());
106 initialise();
107}
108
109RegSelSiLUT::RegSelSiLUT(const std::string& s) :
110 m_ID(UNDEF) {
111 read(s);
112}
113
114
115// this is no longer needed, since the RegSelSiLUT now configures
116// the number of subdetectors and layers for each subdetector
117// automatically
118
120{
121 const std::string s[8] = { "", "pixel", "sct", "trt", "ftk", "mm", "stgc", "rpc" };
122 m_name = s[m_ID];
123}
124
125
126
127
128// clear the look up table
130 for ( unsigned i=0 ; i<m_SubDet.size() ; i++ ) m_SubDet[i].reset();
131 m_map.clear();
132}
133
134
135
136
137// initialise the look up table from the main vector of RegSelModules
138
140
141 // struct timeval inittimer = gtttimer_start();
142
143 // find out how many subdetectors there are
144
145 std::vector<int> subdetid;
146
147 for ( std::vector<RegSelModule>::iterator mptr = m_modules.begin() ;
148 mptr!=m_modules.end() ; ++mptr ) {
149 int detid = mptr->detector();
150
151 bool found = false;
152 for ( int j=subdetid.size() ; j-- ; ) if ( subdetid[j]==detid ) found = true;
153
154 if ( !found ) subdetid.push_back(detid);
155 }
156
157 // std::cout << "\tRegSelSiLUT::initialise() creating detector with " << subdetid.size() << " subdetectors" << std::endl;
158
159 // std::cout << "RegSelSiLUT::initialise()" << std::endl;
160
161 m_SubDet.reserve(subdetid.size());
162
163 // push each one to the list
164 for ( int i=subdetid.size() ; i-- ; ) {
165 m_SubDet.push_back( RegSelSubDetector(subdetid[i]) );
166 m_idmap.insert( std::map<int, int>::value_type(subdetid[i], i) );
167
168 //int ii = subdetid.size()-1-i;
169 //std::cout << "\tsubdet " << ii << "\tid " << subdetid[ii] << std::endl;
170 }
171
172
173
174
175 // initialise the subdetector look up tables
176 for ( unsigned i=0 ; i<m_SubDet.size() ; i++ ) m_SubDet[i].addModules(m_modules);
177
178 // std::cout << "\tRegSelSiLUT " << getName() << std::endl;
179 // write(getName()+".map");
180
181 // std::cout << "RegSelSiLUT::initialise() creating hash map" << std::endl;
182
183 // and save pointers to all the modules in a map by hashid
184 for ( std::vector<RegSelModule>::iterator mptr = m_modules.begin() ;
185 mptr!=m_modules.end() ; ++mptr ) {
186 m_map[(*mptr).hashID()] = &(*mptr);
187 }
188
189 // std::cout << "RegSelSiLUT::initialise() exiting" << std::endl;
190
191 // double inittime = gtttimer_stop(inittimer);
192 // std::cout << "initialise time=" << inittime << std::endl;
193
196
200
201}
202
203
205
206 m_allHashes.clear();
207 m_allROBids.clear();
208
209 std::set<uint32_t> robids;
210
211 std::vector<RegSelModule>::const_iterator mptr(m_modules.begin());
212 std::vector<RegSelModule>::const_iterator eptr(m_modules.end());
213 for ( ; mptr!=eptr ; ++mptr ) {
214 if ( (*mptr).enabled() ) {
215 m_allHashes.push_back((*mptr).hashID());
216 robids.insert((*mptr).robID());
217 }
218 }
219
220 std::set<uint32_t>::iterator ritr(robids.begin());
221 while ( ritr!=robids.end() ) {
222 m_allROBids.push_back(*ritr++);
223 }
224
225}
226
227
228
229// initialise the disabled module lists for
230// each subdetector layer
231
233 for ( std::vector<RegSelSubDetector>::iterator sptr(m_SubDet.begin()) ;
234 sptr!=m_SubDet.end() ; ++sptr ) {
235 (*sptr).setupDisabledModules();
236 }
237}
238
239
240
241// find a module from it's hashID
243 std::map<const IdentifierHash, const RegSelModule*>::const_iterator hptr(m_map.find(h));
244 if ( hptr!=m_map.end() ) return hptr->second;
245 else return NULL;
246}
247
248
249
250
252 std::map<int,int>::iterator sitr = m_idmap.find(id);
253 if ( sitr!=m_idmap.end() ) m_SubDet[sitr->second].disable();
254}
255
257 std::map<int,int>::iterator sitr = m_idmap.find(id);
258 if ( sitr!=m_idmap.end() ) m_SubDet[sitr->second].enable();
259}
260
261void RegSelSiLUT::disableLayer(int id, unsigned layer) {
262 std::map<int,int>::iterator sitr = m_idmap.find(id);
263 if ( sitr!=m_idmap.end() ) m_SubDet[sitr->second].disableLayer(layer);
264}
265
266void RegSelSiLUT::enableLayer(int id, unsigned layer) {
267 std::map<int,int>::iterator sitr = m_idmap.find(id);
268 if ( sitr!=m_idmap.end() ) m_SubDet[sitr->second].enableLayer(layer);
269}
270
271
272
273bool RegSelSiLUT::getRoIData(const RegSelRoI& roi, std::vector<const RegSelModule*>& modules) const
274{
275 // std::cout << "RegSelSiLUT::getRoIData() ID=" << ID() << "\t" << roi << std::endl;
276
277 bool inDet = false;
278
279 for ( unsigned i=0 ; i<m_SubDet.size() ; i++ ) {
280 bool inSubDet = m_SubDet[i].inRoI(roi);
281 inDet |= inSubDet;
282 // std::cout << "\tRegSelSiLUT::getRoIData() SubDet id " << m_SubDet[i].ID() << std::endl;
283 if ( inSubDet ) m_SubDet[i].getModules(roi, modules);
284 }
285
286 // std::cout << "RegSelSiLUT::getRoIData() Nmodules=" << modules.size() << std::endl;
287 // for ( int i=0 ; i<modules.size() ; i++ ) modules[i]->paw();
288
289 return inDet;
290}
291
292
293
294
295void RegSelSiLUT::getModules( unsigned layer, std::vector<const RegSelModule*>& modules) const {
296 modules.reserve(256);
297
299 bool subdetflag = layer/1000;
300 int subdet = 0;
301 int ilayer = layer%100;
302 if ( subdetflag ) subdet = (layer%1000)/100;
303
304 for ( unsigned i=0 ; i<m_SubDet.size() ; i++ ) {
305 if ( !subdetflag || ( subdetflag && subdet==std::fabs(m_SubDet[i].ID()) ) ) m_SubDet[i].getModules( ilayer, modules);
306 }
307 }
308
309
310
314
315bool RegSelSiLUT::getRoIData(const RegSelRoI& roi, unsigned layer, std::vector<const RegSelModule*>& modules) const
316{
317 // std::cout << "RegSelSiLUT::getRoIData() ID=" << ID() << std::endl;
318
319 bool inDet = false;
320
321
322 int ilayer = layer%100;
324 bool subdetflag = layer/1000;
325 int subdet = 0;
326 if ( subdetflag ) subdet = (layer%1000)/100;
327
328 for ( unsigned i=0 ; i<m_SubDet.size() ; i++ ) {
329
330 if ( !subdetflag || ( subdetflag && subdet==std::fabs(m_SubDet[i].ID()) ) ) {
331 bool inSubDet = m_SubDet[i].inRoI(roi);
332 inDet |= inSubDet;
333 if ( inSubDet ) m_SubDet[i].getModules(roi, ilayer, modules);
334 }
335 }
336
337
338
339
340 // std::cout << "RegSelSiLUT::getRoIData() Nmodules=" << modules.size() << std::endl;
341 // for ( int i=0 ; i<modules.size() ; i++ ) modules[i]->paw();
342
343 return inDet;
344}
345
346
347
348
349
350bool RegSelSiLUT::getRoIData(const RegSelRoI& roi, unsigned subdetector, unsigned layer, std::vector<const RegSelModule*>& modules) const
351{
352 // std::cout << "RegSelSiLUT::getRoIData() ID=" << ID() << std::endl;
353
354 bool inDet = false;
355
356 if ( subdetector<m_SubDet.size() ) {
357 inDet = m_SubDet[subdetector].inRoI(roi);
358 if ( inDet ) m_SubDet[subdetector].getModules(roi, layer, modules);
359 }
360 // std::cout << "RegSelSiLUT::getRoIData() Nmodules=" << modules.size() << std::endl;
361 // for ( int i=0 ; i<modules.size() ; i++ ) modules[i]->paw();
362
363 return inDet;
364}
365
366
367
368
369
370
371double phiprime(double x, double y, double phi, double r, bool& status) {
372
373 if ( x*x+y*y>r*r ) {
374 // std::cerr << "duffer x=" << x << "\ty=" << y << "\tr=" << r << std::endl;
375 status = false;
376 return 0;
377 }
378
379 double a = (y*cos(phi)-x*sin(phi))/r;
380
381 // this is bad, getting the return value to issue an error code.
382 // ouch! should maybe define an exception and catch it?
383 // this should never happen
384 if ( fabs(a)>1 ) { status = false; return 0; }
385
386 status &= true;
387
388 double phip = asin(a)+phi;
389
390 // std::cout << "phiprime()\tx=" << x << "\ty=" << y << "\tphi=" << phi << "\tr=" << r << "\tphiprime=" << phip << " before" << std::endl;
391
392 // make sure wrapped between -pi to pi
393 if ( phip>M_PI ) phip = phip-2*M_PI;
394 if ( phip<-M_PI ) phip = phip+2*M_PI;
395
396 // std::cout << "phiprime()\tx=" << x << "\ty=" << y << "\tphi=" << phi << "\tr=" << r << "\tphiprime=" << phip << std::endl;
397
398 return phip;
399
400}
401
402
403bool philimits( double x, double y, double rmin, double rmax, double& phimin, double& phimax ) {
404
405 double phi[4];
406
407 bool status = true;
408
409 // std::cout << "phimin=" << phimin << "\tphimax=" << phimax << "\tlimits" << std::endl;
410
411 phi[0] = phiprime(x, y, phimin, rmin, status);
412 phi[1] = phiprime(x, y, phimin, rmax, status);
413
414 phi[2] = phiprime(x, y, phimax, rmin, status);
415 phi[3] = phiprime(x, y, phimax, rmax, status);
416
417 // for ( int i=0 ; i<4 ; i++ ) std::cout << "phi[" << i << "]=" << phi[i] << std::endl;
418
419 if ( status ) {
420
421 // this is needed to take account of the phi=pi boundary, it's not rigorous, but it works
422
423 if ( phi[0]*phi[1]<0 && (phi[0]>0.5*M_PI||phi[1]>0.5*M_PI) ) phimin = ( phi[0]<phi[1] ? phi[1] : phi[0] );
424 else phimin = ( phi[0]<phi[1] ? phi[0] : phi[1] );
425
426 if ( phi[2]*phi[3]<0 && (phi[2]>0.5*M_PI||phi[3]>0.5*M_PI) ) phimax = ( phi[2]>phi[3] ? phi[3] : phi[2] );
427 else phimax = ( phi[2]>phi[3] ? phi[2] : phi[3] );
428
429 }
430
431 // std::cout << "phimin=" << phimin << "\tphimax=" << phimax << "\tlimits (out)" << std::endl;
432
433 return status;
434
435}
436
437
438bool RegSelSiLUT::getRoIData(const RegSelRoI& roi, std::vector<const RegSelModule*>& modules, double x, double y) const
439{
440
441 if ( x==0 && y==0 ) return getRoIData(roi, modules);
442
443 bool inDet = false;
444
445 for ( unsigned i=0 ; i<m_SubDet.size() ; i++ ) {
446
447#if 1
448
449 const std::vector<RegSelLayer>& layers = m_SubDet[i].getLayers();
450
451 for ( unsigned j=0 ; j<layers.size() ; j++ ) {
452
453 double rmin = layers[j].rMin();
454 double rmax = layers[j].rMax();
455
456 double phimin = roi.getphiMin();
457 double phimax = roi.getphiMax();
458
459 // std::cout << layers[j] << "\t" << rmin << " " << rmax << std::endl;
460
461 // std::cout << "lyr[" << j << "] " << "\tphimin=" << phimin << "\tphimax=" << phimax << "\tbefore" << std::endl;
462
463 if ( philimits(x, y, rmin, rmax, phimin, phimax) ) {
464
465 // std::cout << layers[j] << "\tphimin=" << phimin << "\tphimax=" << phimax << std::endl;
466
467 RegSelRoI troi( roi.getzMin(), roi.getzMax(), phimin, phimax, roi.getetaMin(), roi.getetaMax() );
468
469
470 bool inLayer = layers[j].inRoI(troi);
471
472 inDet |= inLayer;
473
474 if ( inLayer ) layers[j].getModules(troi, modules);
475
476 }
477
478 }
479
480#else
481
482
483 double rmin = m_SubDet[i].rMin();
484 double rmax = m_SubDet[i].rMax();
485
486 double phimin = roi.getphiMin();
487 double phimax = roi.getphiMax();
488
489 // std::cout << layers[j] << "\t" << rmin << " " << rmax << std::endl;
490
491 philimits(x, y, rmin, rmax, phimin, phimax);
492
493 // std::cout << layers[j] << "\tphimin=" << phimin << "\tphimax=" << phimax << std::endl;
494
495 RegSelRoI troi( roi.getzMin(), roi.getzMax(), phimin, phimax, roi.getetaMin(), roi.getetaMax() );
496
497 bool inSubDet = m_SubDet[i].inRoI(troi);
498 inDet |= inSubDet;
499 if ( inSubDet ) m_SubDet[i].getModules(troi, modules);
500
501#endif
502
503 }
504 // std::cout << "getRoIData() time=" << _time << " ms (shifted)" << std::endl;
505
506 // std::cout << "RegSelSiLUT::getRoIData() Nmodules=" << modules.size() << std::endl;
507
508 return inDet;
509}
510
511
512
513
514bool RegSelSiLUT::getRoIData(const RegSelRoI& roi, unsigned subdetector, unsigned layer, std::vector<const RegSelModule*>& modules, double x, double y) const
515{
516
517 if ( x==0 && y==0 ) return getRoIData(roi, subdetector, layer, modules);
518
519 // std::cout << "RegSelSiLUT::getRoIData() ID=" << ID() << std::endl;
520
521 // struct timeval _timer = gtttimer_start();
522
523 bool inDet = false;
524
525 if ( subdetector<m_SubDet.size() ) {
526
527 const std::vector<RegSelLayer>& layers = m_SubDet[subdetector].getLayers();
528
529 if ( layer<layers.size() ) {
530
531 double rmin = layers[layer].rMin();
532 double rmax = layers[layer].rMax();
533
534 double phimin = roi.getphiMin();
535 double phimax = roi.getphiMax();
536
537 // std::cout << layers[j] << "\t" << rmin << " " << rmax << std::endl;
538 // std::cout << "lyr[" << subdetector << "] " << "\tphimin=" << phimin << "\tphimax=" << phimax << "\tbefore" << std::endl;
539
540 if ( philimits(x, y, rmin, rmax, phimin, phimax) ) {
541
542 // std::cout << layers[j] << "\tphimin=" << phimin << "\tphimax=" << phimax << std::endl;
543 // std::cout << "lyr[" << subdetector << "] " << "\tphimin=" << phimin << "\tphimax=" << phimax << std::endl;
544
545 RegSelRoI troi( roi.getzMin(), roi.getzMax(), phimin, phimax, roi.getetaMin(), roi.getetaMax() );
546
547 bool inLayer = layers[layer].inRoI(troi);
548
549 inDet |= inLayer;
550
551 if ( inLayer ) layers[layer].getModules(troi, modules);
552
553 }
554 }
555 }
556
557 // double _time = gtttimer_stop(_timer);
558
559 // std::cout << "getRoIData() time=" << _time << " ms (shifted)" << std::endl;
560
561 // std::cout << "RegSelSiLUT::getRoIData() Nmodules=" << modules.size() << std::endl;
562 // for ( int i=0 ; i<modules.size() ; i++ ) modules[i]->paw();
563
564 return inDet;
565}
566
567
568
569
570
571
572void RegSelSiLUT::write(std::ostream& s) const {
573 s << m_modules.size() << std::endl;
574 for ( unsigned i=0 ; i<m_modules.size() ; i++ ) {
575 s << m_modules[i] << std::endl;
576 }
577}
578
579void RegSelSiLUT::write(const std::string& s) const {
580 std::ofstream outfile(s.c_str());
581 write(outfile);
582}
583
584
585
586
587// get the rob list and hash id's for an roi
588void RegSelSiLUT::getRobHashList(const RegSelRoI& roi, std::vector<uint32_t>& roblist, std::vector<IdentifierHash>& hashlist) const
589{
590 std::vector<const RegSelModule*> modules;
591 if ( modules.size()<256 ) modules.reserve(256);
592
593 // get the modules
594 getRoIData(roi,modules);
595
596 // fill the rob and hashid lists
597
598 std::set<uint32_t> uroblist;
599
600 hashlist.reserve(modules.size());
601 roblist.reserve(modules.size());
602 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
603 while ( mptr!=modules.end() ) {
604 hashlist.push_back((*mptr)->hashID());
605 roblist.push_back((*mptr++)->robID());
606 }
607 // removeDuplicates( hashlist );
608 removeDuplicates( roblist );
609
610 // roblist.reserve(uroblist.size());
611 // std::set<uint32_t>::iterator plist(uroblist.begin());
612 // while ( plist!=uroblist.end() ) {
613 // roblist.push_back(*plist++);
614 // }
615
616}
617
618
619
620// get the rob list and hash id's for an roi
621void RegSelSiLUT::getRobHashList(const RegSelRoI& roi, unsigned layer, std::vector<uint32_t>& roblist, std::vector<IdentifierHash>& hashlist) const
622{
623 std::vector<const RegSelModule*> modules;
624 if ( modules.size()<256 ) modules.reserve(256);
625
626 // get the modules
627 getRoIData(roi, layer, modules);
628
629 // fill the rob and hashid lists
630
631 std::set<uint32_t> uroblist;
632
633 hashlist.reserve(modules.size());
634 roblist.reserve(modules.size());
635 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
636 while ( mptr!=modules.end() ) {
637 hashlist.push_back((*mptr)->hashID());
638 roblist.push_back((*mptr++)->robID());
639 }
640 // removeDuplicates( hashlist );
641 removeDuplicates( roblist );
642
643 // roblist.reserve(uroblist.size());
644 // std::set<uint32_t>::iterator plist(uroblist.begin());
645 // while ( plist!=uroblist.end() ) {
646 // roblist.push_back(*plist++);
647 // }
648
649}
650
651
652void RegSelSiLUT::getRobList(const RegSelRoI& roi, std::vector<uint32_t>& roblist, bool removeduplicates ) const {
653
654 std::vector<const RegSelModule*> modules;
655 if ( modules.size()<256 ) modules.reserve(256);
656
657 // struct timeval datatimer = gtttimer_start();
658 getRoIData(roi,modules);
659 // double datatime = gtttimer_stop(datatimer);
660
661#if 0
662 // get the list of unique rob identifiers
663 // FIXME: this uses a set, sould be *much* faster
664 // with a seperate list of robids with their modules'
665 // corresponding extents in r, phi and z etc
666 std::set<uint32_t> uroblist;
667
668 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
669 while ( mptr!=modules.end() ) {
670 uroblist.insert((*mptr++)->robID());
671 }
672
673 roblist.reserve(uroblist.size());
674 std::set<uint32_t>::iterator plist(uroblist.begin());
675 while ( plist!=uroblist.end() ) {
676 roblist.push_back(*plist++);
677 }
678
679#endif
680
683 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
684
685 roblist.reserve(modules.size());
686 while ( mptr!=modules.end() ) roblist.push_back((*mptr++)->robID());
687 if ( removeduplicates || roblist.size()>2000 ) removeDuplicates( roblist );
688
689 // double vectortime = gtttimer_stop(datatimer);
690
691 // std::cout << "RegSelSiLUT::getRobList() datatime=" << datatime
692 // << "\tvectortime=" << vectortime << "\tf="
693 // << 100*(vectortime-datatime)/vectortime << std::endl;
694
695}
696
697
698
699
700
701
702
703void RegSelSiLUT::getRobList(const RegSelRoI& roi, std::vector<uint32_t>& roblist, double x, double y ) const {
704
705 std::vector<const RegSelModule*> modules;
706 if ( modules.size()<256 ) modules.reserve(256);
707
708 // struct timeval datatimer = gtttimer_start();
709 getRoIData( roi, modules, x, y );
710 // double datatime = gtttimer_stop(datatimer);
711
712#if 0
713 std::set<uint32_t> uroblist;
714
715 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
716 while ( mptr!=modules.end() ) {
717 uroblist.insert((*mptr++)->robID());
718 }
719
720 roblist.reserve(uroblist.size());
721 std::set<uint32_t>::iterator plist(uroblist.begin());
722 while ( plist!=uroblist.end() ) {
723 roblist.push_back(*plist++);
724 }
725
726#endif
727
728 roblist.reserve(modules.size());
729 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
730 while ( mptr!=modules.end() ) roblist.push_back((*mptr++)->robID());
731 removeDuplicates( roblist );
732
733}
734
735
736
737
738
739
740// enable all the modules
742 std::vector<RegSelModule>::iterator itr(m_modules.begin());
743 while ( itr!=m_modules.end() ) (*itr++).enable();
746}
747
748
749
750// disable all the modules
752 std::vector<RegSelModule>::iterator itr(m_modules.begin());
753 while ( itr!=m_modules.end() ) (*itr++).disable();
756}
757
758
759
760
761// disable the modules from requested robs in the look up tables
762void RegSelSiLUT::disableRobList(const std::vector<uint32_t>& roblist) {
763
764 std::set<uint32_t> robset;
765 for ( unsigned i=0 ; i<roblist.size() ; i++ ) robset.insert(roblist[i]);
766
767 std::vector<RegSelModule>::iterator itr(m_modules.begin());
768 for ( ; itr!=m_modules.end() ; ++itr ) {
769 // this module's rob is on the list, so disable it
770 if ( robset.find((*itr).robID())!=robset.end() ) (*itr).disable();
771 }
774}
775
776
777
778// enable modules from the robs in the look up tables
779void RegSelSiLUT::enableRobList(const std::vector<uint32_t>& roblist) {
780
781 std::set<uint32_t> robset;
782 for ( unsigned i=0 ; i<roblist.size() ; i++ ) robset.insert(roblist[i]);
783
784 std::vector<RegSelModule>::iterator itr(m_modules.begin());
785 for ( ; itr!=m_modules.end() ; ++itr ) {
786 // this module's rob is on the list, so enable it
787 if ( robset.find((*itr).robID())!=robset.end() ) (*itr).enable();
788 }
791}
792
793
794
795
796
797
798// disable modules in the look up tables
799void RegSelSiLUT::disableModuleList(const std::vector<IdentifierHash>& hashlist) {
800
801 std::set<IdentifierHash> hashset;
802 for ( unsigned i=0 ; i<hashlist.size() ; i++ ) hashset.insert(hashlist[i]);
803
804 std::vector<RegSelModule>::iterator itr(m_modules.begin());
805 for ( ; itr!=m_modules.end() ; ++itr ) {
806 // this module is on the list, so disable it
807 if ( hashset.find((*itr).hashID())!=hashset.end() ) (*itr).disable();
808 }
811}
812
813
814
815// enable modules in the look up tables
816void RegSelSiLUT::enableModuleList(const std::vector<IdentifierHash>& hashlist) {
817
818 std::set<IdentifierHash> hashset;
819 for ( unsigned i=0 ; i<hashlist.size() ; i++ ) hashset.insert(hashlist[i]);
820
821 std::vector<RegSelModule>::iterator itr(m_modules.begin());
822 for ( ; itr!=m_modules.end() ; ++itr ) {
823 // this module is on the list, so enable it
824 if ( hashset.find((*itr).hashID())!=hashset.end() ) (*itr).enable();
825 }
828}
829
830
831
832
833
834
835
836// get hash id's for all enabled modules in the roi
837
838void RegSelSiLUT::getHashList(const RegSelRoI& roi, std::vector<IdentifierHash>& hashlist) const {
839
840 // bool hashempty = hashlist.empty();
841
842 std::vector<const RegSelModule*> modules;
843 if ( modules.size()<256 ) modules.reserve(256);
844
845 // struct timeval datatimer = gtttimer_start();
846 getRoIData(roi,modules);
847 // double datatime = gtttimer_stop(datatimer);
848
849 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
850
851 hashlist.reserve(modules.size());
852 for ( ; mptr!=modules.end() ; ++mptr ) {
853 hashlist.push_back((*mptr)->hashID());
854 }
855
856 // if ( !hashempty ) removeDuplicates( hashlist );
857
858 // double vectortime = gtttimer_stop(datatimer);
859
860 // std::cout << "RegSelSiLUT::getHashList() datatime=" << datatime << "\tvectortime=" << vectortime << "\tf="
861 // << 100*(vectortime-datatime)/vectortime << std::endl;
862
863}
864
865
866
867
868void RegSelSiLUT::getHashList(const RegSelRoI& roi, std::vector<IdentifierHash>& hashlist, double x, double y ) const {
869
870 std::vector<const RegSelModule*> modules;
871 if ( modules.size()<256 ) modules.reserve(256);
872
873 // struct timeval datatimer = gtttimer_start();
874 getRoIData( roi, modules, x, y );
875 // double datatime = gtttimer_stop(datatimer);
876
877 // bool hashempty = hashlist.empty();
878
879 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
880
881 hashlist.reserve(modules.size());
882 for ( ; mptr!=modules.end() ; ++mptr ) {
883 hashlist.push_back((*mptr)->hashID());
884 }
885
886 // if ( !hashempty ) removeDuplicates( hashlist );
887
888}
889
890
891
892
893// get hash id's for all enabled modules
894
895void RegSelSiLUT::getHashList(std::vector<IdentifierHash>& hashlist) const {
896
897#ifndef OLDFULLSCAN
898 hashlist.reserve(m_allHashes.size());
899 hashlist = m_allHashes;
900 return;
901#else
902
903 hashlist.clear();
904 hashlist.reserve(m_modules.size());
905
906 std::vector<RegSelModule>::const_iterator mptr(m_modules.begin());
907 std::vector<RegSelModule>::const_iterator eptr(m_modules.end());
908 for ( ; mptr!=eptr ; ++mptr ) {
909 if ( (*mptr).enabled() ) hashlist.push_back((*mptr).hashID());
910 }
911#endif
912}
913
914
915
916
917// get hash id's for all enabled modules in a layer
918
919void RegSelSiLUT::getHashList( unsigned layer, std::vector<IdentifierHash>& hashlist) const {
920
921 std::vector<const RegSelModule*> modules;
922
923 // bool hashempty = hashlist.empty();
924
925 getModules( layer, modules );
926
927 hashlist.reserve(modules.size());
928 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
929 while ( mptr!=modules.end() ) {
930 hashlist.push_back((*mptr++)->hashID());
931 }
932
933 // if ( !hashempty ) removeDuplicates( hashlist );
934
935}
936
937
938
939
940
941// get robs corresponding to all enabled modules
942
943void RegSelSiLUT::getRobList(std::vector<uint32_t>& roblist) const {
944
945#ifndef OLDFULLSCAN
946 roblist.reserve(m_allROBids.size());
947 roblist = m_allROBids;
948 return;
949#else
950 roblist.reserve(256);
951
952 std::set<uint32_t> uroblist;
953 std::vector<RegSelModule>::const_iterator mptr(m_modules.begin());
954 for ( ; mptr!=m_modules.end() ; ++mptr ) {
955 if ( (*mptr).enabled() ) uroblist.insert((*mptr).robID());
956 }
957
958 std::set<uint32_t>::iterator rlist(uroblist.begin());
959 while ( rlist!=uroblist.end() ) {
960 roblist.push_back(*rlist++);
961 }
962#endif
963}
964
965// get robs and hash id's for all enabled modules
966
967void RegSelSiLUT::getRobHashList(std::vector<uint32_t>& roblist, std::vector<IdentifierHash>& hashlist) const {
968
969#ifndef OLDFULLSCAN
970 hashlist.reserve(m_allHashes.size());
971 roblist.reserve(m_allROBids.size());
972 roblist = m_allROBids;
973 hashlist = m_allHashes;
974 return;
975#else
976 roblist.reserve(256);
977 hashlist.reserve(m_modules.size());
978
979 std::set<uint32_t> uroblist;
980 std::vector<RegSelModule>::const_iterator mptr(m_modules.begin());
981 for ( ; mptr!=m_modules.end() ; ++mptr ) {
982 if ( (*mptr).enabled() ) {
983 uroblist.insert((*mptr).robID());
984 hashlist.push_back((*mptr).hashID());
985 }
986 }
987
988 std::set<uint32_t>::iterator rlist(uroblist.begin());
989 while ( rlist!=uroblist.end() ) {
990 roblist.push_back(*rlist++);
991 }
992#endif
993}
994
995
996// get modules in the roi for a specified layer
997
998void RegSelSiLUT::getHashList(const RegSelRoI& roi, unsigned layer, std::vector<IdentifierHash>& hashlist) const {
999
1000 // bool hashempty = hashlist.empty();
1001
1002 std::vector<const RegSelModule*> modules;
1003 if ( modules.size()<256 ) modules.reserve(256);
1004
1005
1006 getRoIData( roi, layer, modules);
1007
1008 // struct timeval datatimer = gtttimer_start();
1009
1010 // double datatime = gtttimer_stop(datatimer);
1011
1012 hashlist.reserve(modules.size());
1013 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
1014 while ( mptr!=modules.end() ) {
1015 hashlist.push_back((*mptr++)->hashID());
1016 }
1017
1018 // if ( !hashempty ) removeDuplicates( hashlist );
1019
1020 // double vectortime = gtttimer_stop(datatimer);
1021
1022 // std::cout << "RegSelSiLUT::getHashList() datatime=" << datatime << "\tvectortime=" << vectortime << "\tf="
1023 // << 100*(vectortime-datatime)/vectortime << std::endl;
1024
1025}
1026
1027
1028
1029
1030// get robs in the roi for a specified layer
1031
1032void RegSelSiLUT::getRobList(const RegSelRoI& roi, unsigned layer, std::vector<uint32_t>& roblist, bool removeduplicates ) const {
1033
1034 std::vector<const RegSelModule*> modules;
1035 if ( modules.size()<256 ) modules.reserve(256);
1036
1037
1038 getRoIData( roi, layer, modules);
1039
1040#if 0
1041 for ( std::vector<RegSelSubDetector>::const_iterator sptr(m_SubDet.begin()) ;
1042 sptr!=m_SubDet.end() ; sptr++ ) {
1043
1044 if ( (*sptr).inRoI(roi) ) {
1045
1046 const std::vector<RegSelLayer>& lyrs = (*sptr).getLayers();
1047
1048 if ( layer<lyrs.size() ) {
1049 const RegSelLayer& lyr = lyrs[layer];
1050 if ( lyr.inRoI(roi) ) lyr.getModules(roi,modules);
1051 }
1052 }
1053 }
1054#endif
1055
1056 // struct timeval datatimer = gtttimer_start();
1057
1058 // double datatime = gtttimer_stop(datatimer);
1059
1060 // std::vector<uint32_t> uroblist;
1061 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
1062 while ( mptr!=modules.end() ) {
1063 roblist.push_back((*mptr++)->robID());
1064 }
1065
1066 // std::set<uint32_t>::iterator rlist(uroblist.begin());
1067 // while ( rlist!=uroblist.end() ) {
1068 // roblist.push_back(*rlist++);
1069 // }
1070
1071 if ( removeduplicates || roblist.size()>4000 ) removeDuplicates( roblist );
1072
1073}
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083// get robs in the roi for a specified layer
1084
1085void RegSelSiLUT::getRobList( unsigned layer, std::vector<uint32_t>& roblist) const {
1086
1087 std::vector<const RegSelModule*> modules;
1088
1089 getModules( layer, modules );
1090
1091 roblist.reserve(256);
1092
1093 std::set<uint32_t> uroblist;
1094 std::vector<const RegSelModule*>::const_iterator mptr(modules.begin());
1095 for ( ; mptr!=modules.end() ; ++mptr ) {
1096 if ( (*mptr)->enabled() ) roblist.push_back((*mptr)->robID());
1097 }
1098 removeDuplicates( roblist );
1099
1100 // std::set<uint32_t>::iterator rlist(uroblist.begin());
1101 // while ( rlist!=uroblist.end() ) roblist.push_back(*rlist++);
1102
1103}
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113// get disabled modules in the roi for a specified layer
1114
1115void RegSelSiLUT::getDisabledHashList(const RegSelRoI& roi, unsigned layer, std::vector<IdentifierHash>& hashlist) const {
1116
1117 std::vector<const RegSelModule*> modules;
1118 if ( modules.size()<256 ) modules.reserve(256);
1119
1120 // for ( std::vector<RegSelSubDetector>::const_iterator sptr(getSubDet().begin()) ;
1121 for ( std::vector<RegSelSubDetector>::const_iterator sptr(m_SubDet.begin()) ;
1122 sptr!=m_SubDet.end() ; ++sptr ) {
1123
1124 if ( (*sptr).inRoI(roi) ) {
1125
1126 const std::vector<RegSelLayer>& lyrs = (*sptr).getLayers();
1127
1128 if ( layer<lyrs.size() ) {
1129 // const RegSelLayer& lyr = lyrs.at(layer);
1130 const RegSelLayer& lyr = lyrs[layer];
1131
1132 if ( lyr.inRoI(roi) ) lyr.getDisabledModules(roi,modules);
1133 }
1134 }
1135 }
1136
1137 hashlist.reserve(m_modules.size());
1138 std::vector<const RegSelModule*>::iterator mptr(modules.begin());
1139 while ( mptr!=modules.end() ) {
1140 hashlist.push_back((*mptr++)->hashID());
1141 }
1142}
1143
1144
1145
1146void RegSelSiLUT::getDisabledLayers(const RegSelRoI& roi, int subdetector, std::vector<int>& layers) const {
1147
1148 // layers.clear();
1149
1150 std::set<int> disabled_layers;
1151
1152 for ( std::vector<RegSelSubDetector>::const_iterator sptr(m_SubDet.begin()) ;
1153 sptr!=m_SubDet.end() ; ++sptr ) {
1154
1155 // std::cout << "subdet id = " << sptr->ID() << std::endl;
1156
1157 if ( subdetector!=sptr->ID() ) continue;
1158
1159 if ( (*sptr).inRoI(roi) ) {
1160
1161 const std::vector<RegSelLayer>& lyrs = (*sptr).getLayers();
1162
1163 for ( int layer=lyrs.size() ; layer-- ; ) {
1164
1165 std::vector<const RegSelModule*> modules;
1166 if ( modules.size()<256 ) modules.reserve(256);
1167
1168 // const RegSelLayer& lyr = lyrs.at(layer);
1169 const RegSelLayer& lyr = lyrs[layer];
1170
1171 if ( lyr.inRoI(roi) ) {
1172 lyr.getDisabledModules(roi,modules);
1173 // if ( modules.size() ) disabled_layers.insert(layer);
1174 if ( modules.size() ) layers.push_back(layer);
1175 }
1176 }
1177 }
1178 }
1179
1180#if 0
1181 // copy to output
1182 std::set<int>::iterator bitr(disabled_layers.begin());
1183 std::set<int>::iterator eitr(disabled_layers.end());
1184 while ( bitr!=eitr ) { layers.push_back(*bitr++); }
1185#endif
1186
1187}
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197bool RegSelSiLUT::read(const std::string& s) {
1198 std::ifstream infile(s.c_str());
1199 // std::cout << "RegSelSiLUT::read() from file " << s << std::endl;
1200 return read(infile);
1201}
1202
1203
1204bool RegSelSiLUT::read(std::istream& s) {
1205
1206 unsigned Nmodules = 0;
1207
1208 // old method - read number of modules and try tp read them in
1209 // new method - just read until module list exhausted,
1210 // this code will allow either
1211
1212 bool newformat = false;
1213
1214 s >> Nmodules;
1215
1216 newformat=s.fail();
1217
1218 // couldn't read number of modules - try new format
1219 if ( newformat )
1220 s.clear();
1221 else if (Nmodules > 1000000u) {
1222 // Old format --- prevent runaway on invalid input.
1223 std::cerr << "read(): Unreasonable Nmodules " << Nmodules << "\n";
1224 return false;
1225 }
1226
1227 unsigned modcount=0;
1228
1229 for ( ; newformat || modcount<Nmodules ; modcount++ ) {
1230 RegSelModule m;
1231 if ( !getModule(s, m) ) break;
1232 addModule(m);
1233 }
1234
1235 // std::cout << "read() newformat " << newformat << std::endl;
1236 // std::cout << "read() read " << modcount << " modules" << std::endl;
1237 // std::cout << "read() Nmodules " << Nmodules << "\tsize " << m_modules.size() << std::endl;
1238
1239 // std::cout << "RegSelSiLUT::read() creating tables" << std::endl;
1240 initialise();
1241
1242 if ( (!newformat) && (modcount<Nmodules ) ) return false;
1243
1244 return true;
1245}
1246
1247
1248
#define M_PI
Scalar phi() const
phi method
static Double_t a
bool getModule(std::istream &s, RegSelModule &m)
double phiprime(double x, double y, double phi, double r, bool &status)
bool philimits(double x, double y, double rmin, double rmax, double &phimin, double &phimax)
emacs: this is -*- c++ -*-
#define y
#define x
Header file for AthHistogramAlgorithm.
void IDList_layer(long layer, const IRoiDescriptor &roi, std::vector< T > &idlist, handler_layer< C, T > lister) const
Definition IRegSelLUT.h:106
static void removeDuplicates(std::vector< T > &vec)
useful for removing duplicates if required ...
Definition IRegSelLUT.h:78
void IDList(const IRoiDescriptor &roi, std::vector< T > &idlist, handler< C, T > lister) const
Definition IRegSelLUT.h:88
Describes the API of the Region of Ineterest geometry.
virtual bool isFullscan() const =0
is this a full detector RoI?
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 phiMinus() const =0
virtual double zedMinus() const =0
virtual double etaMinus() const =0
virtual double etaPlus() const =0
This is a "hash" representation of an Identifier.
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...
void getDisabledModules(const RegSelRoI &roi, std::vector< const RegSelModule * > &modules) const
const std::string & getName() const
Definition RegSelName.h:39
std::string m_name
Definition RegSelName.h:45
RegSelName(const std::string &s="")
Definition RegSelName.h:37
double getzMin() const
Definition RegSelRoI.h:44
double getetaMin() const
Definition RegSelRoI.h:48
double getzMax() const
Definition RegSelRoI.h:45
double getetaMax() const
Definition RegSelRoI.h:49
double getphiMin() const
Definition RegSelRoI.h:46
double getphiMax() const
Definition RegSelRoI.h:47
void enableRobs()
bool read(std::istream &s)
void write(std::ostream &s=std::cout) const
std::vector< RegSelModule > m_modules
virtual void ROBIDList_internal(const IRoiDescriptor &roi, std::vector< uint32_t > &roblist) const
rob methods
void initialiseDisabledModules()
virtual void construct()
std::vector< RegSelSubDetector > m_SubDet
std::map< int, int > m_idmap
void disableModuleList(const std::vector< IdentifierHash > &hashlist)
void getDisabledLayers(const RegSelRoI &roi, int subdetector, std::vector< int > &layers) const
std::vector< uint32_t > m_allROBids
std::vector< IdentifierHash > m_allHashes
std::map< const IdentifierHash, const RegSelModule * > m_map
void addModule(RegSelModule &module)
Definition RegSelSiLUT.h:71
void initialiseFullScan()
virtual void getRobList(const RegSelRoI &roi, unsigned layer, std::vector< uint32_t > &roblist, bool removeduplicates=true) const
bool getRoIData(const RegSelRoI &r, std::vector< const RegSelModule * > &modules) const
DET ID() const
Definition RegSelSiLUT.h:84
virtual void HashIDList(const IRoiDescriptor &roi, std::vector< IdentifierHash > &idlist) const override
implementation of the IRegSelUT interface hash id methods
void enableRobList(const std::vector< uint32_t > &roblist)
static void cleanup(std::vector< IdentifierHash > &idvec)
annoying cleanup function specifically for the RPC, but we have to add it here since we have abstract...
virtual void getHashList(const RegSelRoI &roi, std::vector< IdentifierHash > &hashlist) const
void disableLayer(int id, unsigned layer)
void disableRobList(const std::vector< uint32_t > &roblist)
const std::vector< RegSelModule > & getModules() const
Definition RegSelSiLUT.h:75
virtual void HashIDList_internal(const IRoiDescriptor &roi, std::vector< IdentifierHash > &idlist) const
horrible internal interface methods
void enableModuleList(const std::vector< IdentifierHash > &hashlist)
void disableSubDetector(int id)
const RegSelModule * Module(const IdentifierHash &h) const
void enableLayer(int id, unsigned layer)
virtual void getRobHashList(std::vector< uint32_t > &roblist, std::vector< IdentifierHash > &hashlist) const
virtual void ROBIDList(const IRoiDescriptor &roi, std::vector< uint32_t > &roblist) const override
rob methods
void addModules(const std::vector< RegSelModule > &m)
Definition RegSelSiLUT.h:72
void enableSubDetector(int id)
void initialise()
void disableRobs()
void getDisabledHashList(const RegSelRoI &roi, unsigned layer, std::vector< IdentifierHash > &hashlist) const
virtual bool inRoI(const RegSelRoI &roi) const
Definition ZRObject.h:71
int r
Definition globals.cxx:22