test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTSectColl.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTSectColl.cpp
4 //
5 // Description: Implementation of DTSectColl trigger algorithm
6 //
7 //
8 // Author List:
9 // S. Marcellini
10 // Modifications:
11 // 11/11/06 C. Battilana : CoarseSync and Theta included
12 // 11/12/06 C. Battilana : New Sector Collector Definition
13 // 09/01/07 C. Battilana : moved to local conf
14 // mar07 - S. Vanini : parameters from DTConfigManager
15 //
16 //
17 //--------------------------------------------------
18 
19 
20 //-----------------------
21 // This Class's Header --
22 //-----------------------
24 
25 //-------------------------------
26 // Collaborating Class Headers --
27 //-------------------------------
37 
38 //---------------
39 // C++ Headers --
40 //---------------
41 #include <iostream>
42 #include <algorithm>
43 
44 //----------------
45 // Constructors --
46 //----------------
47 
48 DTSectColl::DTSectColl(DTSectCollId id) : _sectcollid(id){
49 
50  //_config = _conf_manager->getDTConfigSectColl(_sectcollid);
51 
52  // create SC Chips
53  for(int istat=0;istat<4;istat++){
54  for(int istep=0;istep<DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1;istep++) {
55  _tsc[istep][istat] = new DTSC(istat+1);
56  }
57  }
58  for (int istat=0;istat<5;istat++) _tsphi[istat]=0;
59  for (int istat=0;istat<3;istat++) _tstheta[istat]=0;
60 
61 }
62 
63 //--------------
64 // Destructor --
65 //--------------
67 
68  localClear();
69 
70  for(int istat=0;istat<4;istat++){
71  for(int istep=0;istep<DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1;istep++){
72  delete _tsc[istep][istat];
73  }
74  }
75 
76 }
77 
78 
79 //--------------
80 // Operations --
81 //--------------
82 
83 void
85 
86  // clear all sector collectors
87  for(int istat=0;istat<4;istat++){
88  for(int istep=0;istep<DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1;istep++) {
89  _tsc[istep][istat]->clear();
90  }
91  }
92 
93  for(int iph=0;iph<2;++iph){
94  std::vector<DTSectCollPhCand*>::const_iterator phbi = _incand_ph[iph].begin();
95  std::vector<DTSectCollPhCand*>::const_iterator phei = _incand_ph[iph].end();
96  for ( std::vector<DTSectCollPhCand*>::const_iterator iphit = phbi;iphit!= phei;++iphit)
97  delete (*iphit);
98  _incand_ph[iph].clear();
99  }
100 
101  _outcand_ph.clear();
102 
103  std::vector<DTSectCollThCand*>::const_iterator thb = _incand_th.begin();
104  std::vector<DTSectCollThCand*>::const_iterator the = _incand_th.end();
105  for ( std::vector<DTSectCollThCand*>::const_iterator ithit = thb;ithit!= the;++ithit)
106  delete (*ithit);
107  _incand_th.clear();
108 
109  _outcand_th.clear();
110 
111 }
112 
113 void
115 
117 
118  for(int istat=0;istat<4;istat++){
119  for(int istep=0;istep<DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1;istep++){
120  _tsc[istep][istat]->setConfig(config());
121  }
122  }
123 
124 }
125 
126 
127 void
128 DTSectColl::addTU(DTSCTrigUnit* tru /*, int flag*/) {
129 
130  int stat = tru->station();
131  int sect = tru->sector();
132  switch (sect){
133  case 13:
134  stat = 5;
135  sect = 4;
136  break;
137  case 14:
138  stat = 5;
139  sect = 10;
140  break;
141  }
142 
143  if (_sectcollid!=DTSectCollId() &&
144  _sectcollid!=DTSectCollId(tru->wheel(),sect)){
145  std::cout << "DTSectColl::addTU: Trying to add tru " << tru
146  << " into SectColl " << _sectcollid
147  << " Skipping insertion" << std::endl;
148  return;
149  }
150 
151  if (stat<1 || stat >5) {
152  std::cout << "DTSectColl::addTU: Wrong station number Skipping insertion" << std::endl;
153  return;
154  }
155 
156  _tsphi[stat-1] = tru->TSPhTrigs();
157  if (stat<4) _tstheta[stat-1]=tru->TSThTrigs();
158 
159  if (_sectcollid==DTSectCollId())
160  _sectcollid=DTSectCollId(tru->wheel(),sect);
161 
162  // add a Trigger Unit to the Sector Collector
163 // if(flag==2) {
164 // _tsphi1 = tru->TSPhTrigs(); // these are the "normal" stations
165 // _tsphi2 = 0;
166 // _tstheta = tru->TSThTrigs();
167 // }
168 // else if (flag==0){
169 // _tsphi1 = tru->TSPhTrigs();
170 // _tstheta = 0;
171 // }
172 // else if(flag==1) {
173 // _tsphi2 = tru->TSPhTrigs(); // these are the "double" stations
174 // _tstheta = 0;
175 // }
176 // // generates SectColl Id from tsphi Id
177 // if (flag==2 || flag==0){
178 // int sect = tru->sector();
179 // if (sect == 13) sect=4;
180 // if (sect == 14) sect=10;
181 // _sectcollid=DTSectCollId(tru->wheel(),tru->station(),sect);
182 // }
183 
184 }
185 
186 
187 void
189 
190  localClear();
191 
192  std::vector<DTChambPhSegm>::const_iterator p;
193  std::vector<DTChambPhSegm>::const_iterator pend;
194 
195  for(int istat=1;istat<5;istat++){
196  pend=_tsphi[istat-1]->end();
197  for(p=_tsphi[istat-1]->begin();p!=pend;p++){
198  int step = p->step();
199  int fs = (p->isFirst()) ? 1 : 2 ;
200  // load trigger
201  addTSPhi(step, &(*p), fs, istat);
202  }
203  }
204 
205  if(!(_tsphi[4]==0)){ // only for double stations
206  pend=_tsphi[4]->end();
207  for(p=_tsphi[4]->begin();p!=pend;p++){
208  int step = p->step();
209  int fs = (p->isFirst()) ? 1 : 2 ;
210  // load trigger
211  addTSPhi(step, &(*p), fs ,4);
212  }
213  }
214  std::vector<DTChambThSegm>::const_iterator pth;
215  std::vector<DTChambThSegm>::const_iterator pthend;
216 
217  for(int istat=1;istat<4;istat++){
218  pthend=_tstheta[istat-1]->end();
219  for(pth=_tstheta[istat-1]->begin();pth!=pthend;pth++){
220  int step = pth->step();
221  // load trigger
222  addTSTheta(step, &(*pth), istat);
223  }
224  }
225 
226 }
227 
228 
229 void
230 DTSectColl::addTSPhi(int step, const DTChambPhSegm* tsmsegm, int ifs, int istat) {
231 
232  if(step<DTConfigSectColl::NSTEPF||step>DTConfigSectColl::NSTEPL){
233  std::cout << "DTSectColl::addTSPhi: step out of range: " << step;
234  std::cout << " trigger not added!" << std::endl;
235  return;
236  }
237 
238  if(istat<1 || istat>4){
239  std::cout << "DTSectColl::addTSPhi: station out of SC range: " << istat;
240  std::cout << " trigger not added!" << std::endl;
241  return;
242  }
243 
244  // Check that a trigger is present, by its code
245  if(tsmsegm->oldCode()==0) {
246  std::cout << "DTSectColl::addTSPhi --> code = 0 ! ";
247  std::cout << " trigger not added!" << std::endl;
248  return;
249  }
250 
251  DTSC* tsc = getDTSC(step,istat);
252 
253  DTSectCollPhCand* cand = new DTSectCollPhCand(tsc, tsmsegm, ifs);
254 
255  bool fs = (ifs==1);
256  _incand_ph[fs].push_back(cand);
257 
258  tsc->addDTSectCollPhCand(cand);
259 
260  // Debugging...
261  if(config()->debug()){
262  std::cout << "DTSectColl::addTSPhi at step " << step;
263  std::cout << " in SC station " << istat;
264  if(ifs==1) {
265  std::cout << " (first track)" << std::endl;
266  } else {
267  std::cout << " (second track)" << std::endl;
268  }
269  }
270 
271 }
272 
273 void
274 DTSectColl::addTSTheta(int step, const DTChambThSegm* tstsegm, int istat) {
275 
276  if(step<DTConfigSectColl::NSTEPF||step>DTConfigSectColl::NSTEPL){
277  std::cout << "DTSectColl::addTSTheta: step out of range: " << step;
278  std::cout << " trigger not added!" << std::endl;
279  return;
280  }
281 
282  if(istat<1 || istat>5){
283  std::cout << "DTSectColl::addTSTheta: station out of SC range: " << istat;
284  std::cout << " trigger not added!" << std::endl;
285  return;
286  }
287 
288  // Check if a trigger is present in theta
289  bool is_empty=0;
290  for (int i=0;i<7;i++) if (tstsegm->position(i)==1){
291  is_empty = false;
292  break;
293  }
294  if (is_empty==true) {
295  std::cout << "DTSectColl::addTSTheta --> no position bit equal to 1 ! ";
296  std::cout << " trigger not added!" << std::endl;
297  return;
298  }
299 
300 
301 
302  DTSC* tsc = getDTSC(step,istat);
303 
304  DTSectCollThCand* cand = new DTSectCollThCand(tsc, tstsegm);
305 
306  _incand_th.push_back(cand);
307 
308  tsc->addThCand(cand);
309 
310  // Debugging...
311  if(config()->debug()){
312  std::cout << "DTSectColl::addTSTheta at step " << step << std::endl;
313  }
314 
315 }
316 
317 
318 DTSC*
319 DTSectColl::getDTSC(int step, int istat) const {
320 
321  if(step<DTConfigSectColl::NSTEPF||step>DTConfigSectColl::NSTEPL){
322  std::cout << "DTSectColl::getDTSC: step out of range: " << step;
323  std::cout << " empty pointer returned!" << std::endl;
324  return 0;
325  }
326 
327  if(istat<1 || istat>4){
328  std::cout << "DTSectColl::getDTSC: station out of SC range: " << istat;
329  std::cout << " emty pointer returned!" << std::endl;
330  return 0;
331  }
332 
333  return _tsc[step-DTConfigSectColl::NSTEPF][istat-1];
334 
335 }
336 
337 
338 void
340 
341  for(int istat=0;istat<4;istat++){
342  for(int istep=DTConfigSectColl::NSTEPF;istep<DTConfigSectColl::NSTEPL+1;istep++) {
343 
344  if(_tsc[istep-DTConfigSectColl::NSTEPF][istat]->nFirstTPh()>0 || _tsc[istep-DTConfigSectColl::NSTEPF][istat]->nCandTh()>0 ) {
345 
346  _tsc[istep-DTConfigSectColl::NSTEPF][istat]->run();
347 
348  if(_tsc[istep-DTConfigSectColl::NSTEPF][istat]->nTracksPh()>0) {
349 
350  DTSectCollPhCand *cand = _tsc[istep-DTConfigSectColl::NSTEPF][istat]->getTrackPh(1);
351  DTSCPhCache::_cache.push_back(DTSectCollPhSegm(SectCollId(),istep+cand->CoarseSync(),cand->tsTr(),1));
352  _outcand_ph.push_back(cand);
353 
354  if(_tsc[istep-DTConfigSectColl::NSTEPF][istat]->nTracksPh()>1) {
355 
356  DTSectCollPhCand *cand = _tsc[istep-DTConfigSectColl::NSTEPF][istat]->getTrackPh(2);
357  DTSCPhCache::_cache.push_back(DTSectCollPhSegm(SectCollId(),istep+cand->CoarseSync(),cand->tsTr(),2));
358  _outcand_ph.push_back(cand);
359  }
360  }
361  if(_tsc[istep-DTConfigSectColl::NSTEPF][istat]->nTracksTh()>0) {
362 
363  DTSectCollThCand *cand = _tsc[istep-DTConfigSectColl::NSTEPF][istat]->getTrackTh(1);
364  DTSCThCache::_cache.push_back(DTSectCollThSegm(SectCollId(),istep+cand->CoarseSync(),cand->tsTr()));
365  _outcand_th.push_back(cand); // CB getTrackTh non dovrebbe prendere argomenti modificala!
366 
367  }
368  }
369  }
370  }
371 
372  // debugging...
373  if(config()->debug()){
375  std::cout << "====================================================" << std::endl;
376  std::cout << " Sect Coll segments " << std::endl;
377  if (DTSCPhCache::_cache.size()>0){
378  std:: cout << " ***Phi Segments*** " << std:: endl;
379  std::vector<DTSectCollPhSegm>::const_iterator pph;
380  for(pph=DTSCPhCache::_cache.begin();pph<DTSCPhCache::_cache.end();pph++) {
381  pph->print();
382  }
383  }
384  if (DTSCThCache::_cache.size()>0){
385  std:: cout << " **Theta Segments** " << std:: endl;
386  std::vector<DTSectCollThSegm>::const_iterator pth;
387  for(pth=DTSCThCache::_cache.begin();pth<DTSCThCache::_cache.end();pth++) {
388  pth->print();
389  }
390  }
391  std::cout << "====================================================" << std::endl;
392  }
393  }
394  // end debugging
395 
396 }
397 
398 
400 DTSectColl::getDTSectCollPhCand(int ifs, unsigned n) const {
401 
402  if(ifs<1||ifs>2){
403  std::cout << "DTSectColl::getDTSectCollPhCand: wrong track number: " << ifs;
404  std::cout << " empty pointer returned!" << std::endl;
405  return 0;
406  }
407  if(n<1 || n>nCandPh(ifs)) {
408  std::cout << "DTSectColl::getDTSectCollPhCand: requested trigger not present: " << n;
409  std::cout << " empty pointer returned!" << std::endl;
410  return 0;
411  }
412 
413  std::vector<DTSectCollPhCand*>::const_iterator p = _incand_ph[ifs-1].begin()+n-1;
414  return (*p);
415 
416 }
417 
420 
421  if(n<1 || n>nCandTh()) {
422  std::cout << "DTSectColl::getDTSectCollThCand: requested trigger not present: " << n;
423  std::cout << " empty pointer returned!" << std::endl;
424  return 0;
425  }
426 
427  std::vector<DTSectCollThCand*>::const_iterator p = _incand_th.begin()+n-1;
428  return (*p);
429 
430 }
431 
432 
435 
436  if(n<1 || n>nTracksPh()) {
437  std::cout << "DTSectColl::getTrackPh: requested track not present: " << n;
438  std::cout << " empty pointer returned!" << std::endl;
439  return 0;
440  }
441 
442  std::vector<DTSectCollPhCand*>::const_iterator p = _outcand_ph.begin()+n-1;
443  return (*p);
444 
445 }
446 
449 
450  if(n<1 || n>nTracksTh()) {
451  std::cout << "DTSectColl::getTrackTh: requested track not present: " << n;
452  std::cout << " empty pointer returned!" << std::endl;
453  return 0;
454  }
455 
456  std::vector<DTSectCollThCand*>::const_iterator p = _outcand_th.begin()+n-1;
457  return (*p);
458 
459 }
460 
461 
462 unsigned
463 DTSectColl::nCandPh(int ifs) const {
464 
465  if(ifs<1||ifs>2){
466  std::cout << "DTSectColl::nCandPh: wrong track number: " << ifs;
467  std::cout << " 0 returned!" << std::endl;
468  return 0;
469  }
470 
471  return _incand_ph[ifs-1].size();
472 
473 }
474 
475 unsigned
477 
478  return _incand_th.size();
479 
480 }
481 
482 int
484 
485  int n=0;
486  std::vector<DTSectCollPhSegm>::const_iterator p;
487  std::vector<DTSectCollPhSegm>::const_iterator endp = DTSCPhCache::end();
488  for(p=DTSCPhCache::begin(); p<endp; p++) {
489  if(p->step()==step)n++;
490  }
491 
492  return n;
493 
494 }
495 
496 int
498 
499  int n=0;
500  std::vector<DTSectCollThSegm>::const_iterator p;
501  std::vector<DTSectCollThSegm>::const_iterator endp = DTSCThCache::end();
502  for(p=DTSCThCache::begin(); p>endp; p++) {
503  if(p->step()==step)n++;
504  }
505 
506  return n;
507 
508 }
509 
510 
511 const DTSectCollPhSegm*
513 
514  std::vector<DTSectCollPhSegm>::const_iterator p;
515  std::vector<DTSectCollPhSegm>::const_iterator endp = DTSCPhCache::end();
516  for(p=DTSCPhCache::begin();p<endp;p++){
517  if(p->step()==step&&((n==1&&p->isFirst())||(n==2&&!p->isFirst())))
518  return &(*p);
519  }
520 
521  return 0;
522 
523 }
524 
525 const DTSectCollThSegm*
527 
528  std::vector<DTSectCollThSegm>::const_iterator p;
529  std::vector<DTSectCollThSegm>::const_iterator endp = DTSCThCache::end();
530  for(p=DTSCThCache::begin();p<endp;p++){
531  if(p->step()==step)
532  return &(*p);
533  }
534 
535  return 0;
536 
537 }
int nTracksPh() const
Return the number of output Phi tracks.
Definition: DTSectColl.h:138
int i
Definition: DBlmapReader.cc:9
my_collection _cache
Definition: DTCache.h:56
DTSectCollThCand * getDTSectCollThCand(unsigned n) const
Get a Candidate for Sector Collector.
Definition: DTSectColl.cc:419
const DTChambPhSegm * tsTr() const
Return associated TSPhi trigger.
DTSectCollId _sectcollid
Definition: DTSectColl.h:188
DTSectCollThCand * getTrackTh(int n) const
Return the requested Theta track.
Definition: DTSectColl.cc:448
const DTConfigSectColl * getDTConfigSectColl(DTSectCollId) const
Get desired SectorCollector configuration.
int CoarseSync() const
Return the Coarse Sync Parameter.
DTSectCollId SectCollId()
Return the Sector Collector Id.
Definition: DTSectColl.h:180
DTTSTheta * TSThTrigs() const
Return the chamber Trigger Server (Theta)
Definition: DTSCTrigUnit.h:97
std::vector< DTSectCollThCand * > _incand_th
Definition: DTSectColl.h:203
Definition: DTSC.h:42
static const int NSTEPF
Definition: DTConfig.h:36
const DTChambThSegm * tsTr() const
Return associated TSTheta trigger.
std::vector< DTSectCollThCand * > _outcand_th
Definition: DTSectColl.h:206
int nSegmTh(int step)
Return number of DTSectCollTheta segments (SC step)
Definition: DTSectColl.cc:497
DTTSPhi * TSPhTrigs() const
Return the chamber Trigger Server (Phi)
Definition: DTSCTrigUnit.h:94
std::vector< DTSectCollPhCand * > _outcand_ph
Definition: DTSectColl.h:200
unsigned nCandTh() const
Return the number of Theta input tracks.
Definition: DTSectColl.cc:476
DTSectCollThCand * getTrackTh(int n) const
Return the requested Theta track.
Definition: DTSC.cc:328
void addTSPhi(int step, const DTChambPhSegm *tsmsegm, int ifs, int istat)
Add a TSM candidate (step is TSM step not SC one)
Definition: DTSectColl.cc:230
DTSC * _tsc[DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1][DTConfigSectColl::NDTSC]
Definition: DTSectColl.h:194
DTTSTheta * _tstheta[DTConfigSectColl::NTSTSC]
Definition: DTSectColl.h:191
unsigned nCandPh(int ifs) const
Return the number of Phi input tracks (first/second)
Definition: DTSectColl.cc:463
int oldCode() const
Return trigger code (10*inner_code+outer_code; X_code=1,2,3,4,8)
Definition: DTChambPhSegm.h:96
int position(const int i) const
Return the position for a given set of 7 BTI.
void loadSectColl()
Load a Sector Collector.
Definition: DTSectColl.cc:188
int nSegmPh(int step)
Return number of DTSectCollPhi segments (SC step)
Definition: DTSectColl.cc:483
void addDTSectCollPhCand(DTSectCollPhCand *cand)
Add a Sector Collector.
Definition: DTSC.cc:303
void addTSTheta(int step, const DTChambThSegm *tsmsegm, int istat)
Add a TS Theta candidate (step is TSTheta step not sc one)
Definition: DTSectColl.cc:274
void addThCand(DTSectCollThCand *cand)
Add a Theta candidate to sect coll.
Definition: DTSC.cc:242
int CoarseSync() const
Return the Coarse Sync Parameter.
DTTSPhi * _tsphi[DTConfigSectColl::NTSPSC]
Definition: DTSectColl.h:190
static const int NSTEPL
Constants: first and last step to start trigger finding.
Definition: DTConfig.h:36
int nTracksTh() const
Return the number of output Theta tracks.
Definition: DTSectColl.h:141
DTSectCollPhCand * getTrackPh(int n) const
Return the requested Phi track.
Definition: DTSC.cc:312
~DTSectColl()
Destructor.
Definition: DTSectColl.cc:66
DTSectCollPhCand * getTrackPh(int n) const
Return the requested Phi track.
Definition: DTSectColl.cc:434
void addTU(DTSCTrigUnit *tru)
Add a Trigger Unit to the Sector Collector.
Definition: DTSectColl.cc:128
void run()
Run the Sector Collector algorithm.
Definition: DTSC.cc:84
#define debug
Definition: HDRShower.cc:19
int station() const
Return station number.
Definition: DTSCTrigUnit.h:82
const DTSectCollThSegm * SectCollThSegment(int step)
Return requested Sector Collector Theta Segment.
Definition: DTSectColl.cc:526
DTSC * getDTSC(int step, int istat) const
Get a Sector Collector (step is TS one)
Definition: DTSectColl.cc:319
const_iterator begin() const
Get first cache element.
Definition: DTCache.h:40
def is_empty
Definition: utils.py:167
const DTConfigSectColl * _config
Definition: DTSectColl.h:185
void clear()
Clear.
Definition: DTSC.cc:67
const DTConfigSectColl * config() const
Configuration.
Definition: DTSectColl.h:77
void runSectColl()
Run Sector Collector.
Definition: DTSectColl.cc:339
DTSectColl(DTSectCollId id)
Constructor.
Definition: DTSectColl.cc:48
void setConfig(const DTConfigSectColl *conf)
Set configuration.
Definition: DTSC.h:55
std::vector< DTSectCollPhCand * > _incand_ph[2]
Definition: DTSectColl.h:197
void setConfig(const DTConfigManager *conf)
Set configuration.
Definition: DTSectColl.cc:114
const DTSectCollPhSegm * SectCollPhSegment(int step, unsigned n)
Return requested Sector Collector Phi Segment 1st/2nd.
Definition: DTSectColl.cc:512
void localClear()
Local Clear.
Definition: DTSectColl.cc:84
int wheel() const
Return wheel number.
Definition: DTSCTrigUnit.h:79
tuple cout
Definition: gather_cfg.py:145
int sector() const
Return sector number.
Definition: DTSCTrigUnit.h:85
DTSectCollPhCand * getDTSectCollPhCand(int ifs, unsigned n) const
Get a Phi Candidate for Sector Collector.
Definition: DTSectColl.cc:400
const_iterator end() const
Get last cache element.
Definition: DTCache.h:43
int size() const
Get cache vector&#39;s size.
Definition: DTCache.h:46