CMS 3D CMS Logo

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