CMS 3D CMS Logo

DTTracoChip.cc
Go to the documentation of this file.
1 //-------------------------------------------------------------
2 //
3 // Class: DTTracoChip
4 //
5 // Description: Implementation of TRACO
6 // trigger algorithm
7 //
8 //
9 // Author List:
10 // SV 4/II/2003
11 // Modifications:
12 // 22/VI/04 SV : last trigger code update
13 // 16/I/07 SV : new DTConfig update
14 // 3/IV/07 SV : setTracoAcceptance moved from card to chip
15 // 30/10/09 SV : lut parameters from DB are used in code
16 // 110208 SV : TRACO hardware bug included
17 //------------------------------------------------------------
18 
19 //-----------------------
20 // This Class's Header --
21 //-----------------------
23 
24 //-------------------------------
25 // Collaborating Class Headers --
26 //-------------------------------
34 
35 //---------------
36 // C++ Headers --
37 //---------------
38 #include <algorithm>
39 #include <cmath>
40 #include <iostream>
41 #include <string>
42 
43 //----------------
44 // Constructors --
45 //----------------
46 
47 DTTracoChip::DTTracoChip(DTTracoCard *card, int n, DTConfigTraco *conf) : _card(card), _config(conf) {
48  _geom = _card->geom();
49 
50  // n=traco number 1,2,...
51  if (config()->debug() == 4) {
52  std::cout << "DTTracoChip constructor called for TRACO number " << n << std::endl;
53  }
54 
55  // set acceptances from CMSSW geometry
57 
58  // reserve the appropriate amount of space for vectors
59  int i = 0;
60  for (i = 0; i < DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF; i++) {
62  _outerCand[i].reserve(3 * DTConfigTraco::NBTITC);
63  _tracotrig[i].reserve(2);
64  }
65 
66  // the identifier
67  DTChamberId sid = _geom->statId();
68  _id = DTTracoId(sid, n);
69 
70  // Flags for LTS
71  _bxlts.zero();
72  for (int is = 0; is < DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF + 1; is++) {
73  _flag[is].zero();
74  }
75 
76  // debugging
77  if (config()->debug() == 4) {
78  std::cout << "CMS position:" << CMSPosition() << std::endl;
79  std::cout << " psiRad=" << psiRad() << " KRad=" << KRad() << std::endl;
80  }
81 
82  // init traco parameters from traco config file
83  _krad = config()->KRAD();
84  _btic = config()->BTIC();
85 
86  // offset from geometry (x1-x3 FE view): converted from cm to ST units (0.9999
87  // for rounding)
88  _ibtioff = static_cast<int>(config()->BTIC() / (_geom->cellPitch()) * (_geom->phiSLOffset() / 0.9999));
89 
90  // 091030 SV lut parameters from DB
91  // SV 08/12/12 : added flag for computing luts from DB parameters
92  if (_card->lutFromDBFlag() == 1) {
93  // int board = int( (n-1)/4 );
94  // int traco = int(fmod( double(n-1),4.));
95  // 110208 SV for TRACO hardware bug included SL_shift
96  // SL shift
97  float xBTI1_3 = _geom->localPosition(DTBtiId(DTSuperLayerId(sid.wheel(), sid.station(), sid.sector(), 3), 1)).x();
98  float xBTI1_1 = _geom->localPosition(DTBtiId(DTSuperLayerId(sid.wheel(), sid.station(), sid.sector(), 1), 1)).x();
99  float SL_shift = xBTI1_3 - xBTI1_1;
100 
101  _lutsCCB = new Lut(_card->config_luts(), n, SL_shift);
102  _luts = nullptr;
103  } else
104  // this is always the case with new DTConfig SV 15/I/2007
105  // if( config()->trigSetupGeom()==0 ){
106  {
107  _luts = nullptr;
108  _lutsCCB = nullptr;
109  }
110  /*
111  //SV 21/V/03 for testbeam purpose: parameters from hardware setup
112  if(config()->trigSetupGeom()==1){
113  //init traco parameters
114  _dd=config()->DD();
115  _krad=config()->KRAD();
116  _btic=config()->BTIC();
117  _ibtioff=config()->IBTIOFF();
118 
119  //const char* testfile = "traco"; //FIXTB
120  std::string testfile = "traco_";
121  int it = number() - 4 - 1;
122  if(it<10)
123  testfile += it+'0';
124  if(it>9){
125  testfile += int(float(it)/10.0) + '0'; //add decimal char
126  testfile += int(fmod(float(it),float(10))) + '0'; //add unit char
127  }
128 
129  //const char* name = testfile;
130  if(config()->debug()==4)
131  std::cout << "Loading " << testfile << " luts for traco " << number() <<
132  std::endl; _luts = new DTTracoLUTs(testfile); _luts->reset(); _luts->load();
133  if(config()->debug()==4)
134  _luts->print();
135  }//end hardware setup
136 
137  //TB 2004 setup : luts from minicrate ccb equations
138  if(config()->trigSetupGeom()==2){
139  int board = int( (n-1)/4 );
140  int traco = fmod( double(n-1),4. );
141  _lutsCCB = new Lut(sid.station(),board,traco);
142  // 091030 SV this constructur is obsolete now, use setForTestBeam instead
143  }//end TB2004
144  */
145 }
146 
148  : _geom(traco._geom), _id(traco._id), _card(traco._card), _luts(traco._luts) {
149  int i = 0;
150  for (i = 0; i < DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF; i++) {
152  std::vector<DTTracoCand>::const_iterator p;
153  for (p = traco._innerCand[i].begin(); p < traco._innerCand[i].end(); p++) {
154  _innerCand[i].push_back(*p);
155  }
156  _outerCand[i].reserve(3 * DTConfigTraco::NBTITC);
157  for (p = traco._outerCand[i].begin(); p < traco._outerCand[i].end(); p++) {
158  _outerCand[i].push_back(*p);
159  }
160  _tracotrig[i].reserve(2);
161  std::vector<DTTracoTrig *>::const_iterator p1;
162  for (p1 = traco._tracotrig[i].begin(); p1 < traco._tracotrig[i].end(); p1++) {
163  _tracotrig[i].push_back(*p1);
164  }
165  }
166  _bxlts = traco._bxlts;
167  for (int is = 0; is < DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF + 1; is++) {
168  _flag[is] = traco._flag[is];
169  }
170 }
171 
172 //--------------
173 // Destructor --
174 //--------------
176  clear();
177  /*
178  if(config()->trigSetupGeom()==1){
179  _luts->reset();
180  delete _luts;
181  }
182 
183  if(config()->trigSetupGeom()==2)
184  delete _lutsCCB;
185  */
186 
187  if (_card->lutFromDBFlag() == 1)
188  delete _lutsCCB;
189 }
190 
191 //--------------
192 // Operations --
193 //--------------
194 
196  if (this != &traco) {
197  _geom = traco._geom;
198  _id = traco._id;
199  _card = traco._card;
200  int i = 0;
201  for (i = 0; i < DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF; i++) {
203  std::vector<DTTracoCand>::const_iterator p;
204  for (p = traco._innerCand[i].begin(); p < traco._innerCand[i].end(); p++) {
205  _innerCand[i].push_back(*p);
206  }
207  _outerCand[i].reserve(3 * DTConfigTraco::NBTITC);
208  for (p = traco._outerCand[i].begin(); p < traco._outerCand[i].end(); p++) {
209  _outerCand[i].push_back(*p);
210  }
211  _tracotrig[i].reserve(2);
212  std::vector<DTTracoTrig *>::const_iterator p1;
213  for (p1 = traco._tracotrig[i].begin(); p1 < traco._tracotrig[i].end(); p1++) {
214  _tracotrig[i].push_back(*p1);
215  }
216  }
217  _bxlts = traco._bxlts;
218  for (int is = 0; is < DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF + 1; is++) {
219  _flag[is] = traco._flag[is];
220  }
221  }
222  return *this;
223 }
224 
226  std::vector<DTTracoTrig *>::iterator p1;
227  for (int is = 0; is < DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF + 1; is++) {
228  for (p1 = _tracotrig[is].begin(); p1 < _tracotrig[is].end(); p1++) {
229  delete (*p1);
230  }
231  _tracotrig[is].clear();
232  _innerCand[is].clear();
233  _outerCand[is].clear();
234  _flag[is].zero();
235  }
236  _bxlts.zero();
237 }
238 
240  // Debugging...
241  if (config()->debug() > 1) {
242  std::cout << "DTTracoChip::run: Processing TRACO " << _id.traco() << std::endl;
243  }
244  // End debugging
245 
246  int maxtc = static_cast<int>(ceil(float(geom()->nCell(1)) / float(DTConfigTraco::NBTITC)));
247 
248  if (_id.traco() < 1 || _id.traco() > maxtc) {
249  if (config()->debug() == 4)
250  std::cout << "DTTracoChip::run: wrong TRACO number " << _id.traco() << std::endl;
251  return;
252  }
253 
254  // Loop on step
255  for (int is = DTConfigTraco::NSTEPF; is <= DTConfigTraco::NSTEPL; is++) {
256  if (config()->debug() > 1) {
257  std::cout << "\n STEP: " << is << std::endl;
258  std::cout << " ================" << std::endl;
259  }
260 
261  // skip if no cand. at this step
263  continue;
264 
265  // Debugging...
266  if (config()->debug() == 4) {
267  std::cout << " --> "
268  << _innerCand[is - DTConfigTraco::NSTEPF].size() + _outerCand[is - DTConfigTraco::NSTEPF].size();
269  std::cout << " candidates " << std::endl;
270  }
271  // End debugging
272 
273  // Multiple trigger detection between consecutive TRACO's
274  setFlag(is);
275 
276  // check if there is a H in bx for LVALIDIFH flag
277  if (config()->LVALIDIFH()) {
278  for (unsigned int e = 0; e < _innerCand[is - DTConfigTraco::NSTEPF].size(); e++) {
279  if (_innerCand[is - DTConfigTraco::NSTEPF][e].BtiTrig()->code() == 8) {
281  break;
282  }
283  }
284  for (unsigned int e = 0; e < _outerCand[is - DTConfigTraco::NSTEPF].size(); e++) {
285  if (_outerCand[is - DTConfigTraco::NSTEPF][e].BtiTrig()->code() == 8) {
287  break;
288  }
289  }
290  }
291 
292  // Loop over first/second tracks
293  // for(int itk=0; itk < DTConfigTraco::NMAXCAND; itk++){
294  // FIX this hardcoded 2!!
295  for (int itk = 0; itk < 2; itk++) {
296  // Get the best inner and outer segments
297  if (config()->debug() == 4)
298  std::cout << "Inner:" << std::endl;
300  if (config()->debug() == 4)
301  std::cout << "Outer:" << std::endl;
303 
304  // debug
305  if (config()->debug() > 1) {
306  if (inner || outer)
307  std::cout << "Best candidates for track " << itk + 1 << " are:" << std::endl;
308  if (inner) {
309  std::cout << "inner->";
310  inner->print();
311  }
312  if (outer) {
313  std::cout << "outer->";
314  outer->print();
315  }
316  }
317 
318  // Skip to next step if no suitable candidates found
319  if (inner == nullptr && outer == nullptr)
320  break;
321 
322  // suppression of LTRIG on BTI close to selected HTRIG
323  // SV 24/IX/03 : AND suppression of LTRIG close to H in adiacent Traco
324  // SV 31/III/03 : test : only if htprf is off--> NO, it's worse
325  // if( config()->prefHtrig(0) && config()->prefHtrig(1) ){
326  if (inner) {
328  }
329  if (outer) {
331  }
332  //}
333 
334  // set candidates unusable by further steps
335  if (inner)
336  inner->setUsed();
337  if (outer)
338  outer->setUsed();
339  // Create a new TRACO trigger with preview for TS
340  DTTracoTrig *tct = setPV(itk, inner, outer);
341 
342  // skip if no TRACO trigger has been created with this trigger
343  if (!tct)
344  break; // something nasty happened. Go to next step
345 
346  // try a correlation between segments
347  int stored = 0;
348  if (inner && outer) {
349  stored = storeCorr(tct, inner, outer, itk);
350  }
351 
352  if (!stored) {
353  // No suitable candidate found or no correlation possible
354  // Fill single trigger
355  stored = storeUncorr(tct, inner, outer, itk);
356  }
357 
358  // if trigger has been filled store it in TRACO, otherway delete it
359  if (stored) {
360  addTrig(is, tct);
361  } else {
362  delete tct;
363  // break;-> II track is computed even if no I track found...
364  }
365 
366  } // end loop on first/second track
367 
368  // Inhibit second track at previous bunch crossing
369  if (config()->debug() == 4)
370  std::cout << "Checking overlap I-II track..." << std::endl;
372  (_tracotrig[is - DTConfigTraco::NSTEPF])[0]->isFirst()) { // I track at bx
373  if (nTrig(is - 1) > 0) { // there is a track at bx-1
374  if (!(trigger(is - 1, 1)->isFirst()) || // trig 1 is II track
375  (nTrig(is - 1) == 2 && !(trigger(is - 1, 2)->isFirst()))) { // trig 2 is II track
376  raiseOverlap(is);
377  if (config()->debug() == 4) {
378  std::cout << "II track at step " << std::hex << is - 1 << std::dec << "marked rej." << std::endl;
379  std::cout << "I track overlap flag at step " << std::hex << is << std::dec << " setted" << std::endl;
380  }
381  }
382  }
383  }
384  // debug...
385  for (int isd = 0; isd <= DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF + 1; isd++)
386  if (config()->debug() == 4) {
387  std::cout << "overlap flag step = " << isd + DTConfigTraco::NSTEPF << " " << _flag[isd].element(1)
388  << std::endl;
389  }
390  // debugging...
391  if (config()->debug() > 0) {
392  if (nTrig(is) > 0) {
393  for (int cc = 1; cc <= nTrig(is); cc++) {
394  trigger(is, cc)->print();
395  }
396  }
397  } // end debugging
398  } // end loop on step
399 }
400 
402  _flag[step - DTConfigTraco::NSTEPF].set(1); // overlap flag raised
403  _flag[step - DTConfigTraco::NSTEPF - 1].set(2); // mark II rej.
404 }
405 
406 void DTTracoChip::setFlag(int step, int ext) {
407  if (ext == 0) {
408  // this is the original: flags from card
409  DTTracoChip *prevTraco = _card->getTRACO(_id.traco() - 1);
410  if (prevTraco != nullptr) {
411  if (prevTraco->edgeBTI(step, 1, 2))
412  _flag[step - DTConfigTraco::NSTEPF].set(3);
413  if (prevTraco->edgeBTI(step, 2, 2))
414  _flag[step - DTConfigTraco::NSTEPF].set(5);
415  }
416  DTTracoChip *nextTraco = _card->getTRACO(_id.traco() + 1);
417  if (nextTraco != nullptr) {
418  if (nextTraco->edgeBTI(step, 1, 1))
419  _flag[step - DTConfigTraco::NSTEPF].set(4);
420  if (nextTraco->edgeBTI(step, 2, 1))
421  _flag[step - DTConfigTraco::NSTEPF].set(6);
422  }
423  } else {
424  // SV III/03: flags from input EXT: only for testing purpose
425  for (int i = 0; i < 6; i++) {
426  int ibit = ext >> i;
427  if (ibit & 0x01) // bit i+1 -> flag 3,4,5,6 : IL,IR,OL,OR
428  _flag[step - DTConfigTraco::NSTEPF].set(i + 1 + 2);
429  }
430  }
431 
432  // debug:
433  if (config()->debug() == 4) {
434  std::cout << "Flags set for bx=" << step << std::endl;
443  std::cout << _flag[step - DTConfigTraco::NSTEPF].element(9) << " " << std::endl;
444  } // end debugging
445 }
446 
447 DTTracoCand *DTTracoChip::bestCand(int itk, std::vector<DTTracoCand> &tclist) {
448  // Return if no candidates
449  if (tclist.empty())
450  return nullptr;
451 
452  // stl function: sort in Ktc ascending or descending order according
453  // to user request comparing by default with user-defined <
454  // NB don't reverse if candidates are two with same K
455  stable_sort(tclist.begin(), tclist.end()); // 0=K ascending, 1=K descending
456  if (config()->sortKascend(itk) && !(tclist.size() == 2 && tclist[0].K() == tclist[1].K())) {
457  reverse(tclist.begin(), tclist.end());
458  if (config()->debug() == 4)
459  std::cout << "Reversing order of sorted candidate list..." << std::endl;
460  }
461 
462  /*
463  if(!config()->sortKascend(itk)){
464  stable_sort( tclist.begin(),tclist.end(),DTTracoCand::closer );
465  } else {
466  stable_sort( tclist.begin(),tclist.end(),DTTracoCand::wider );
467  }
468  */
469 
470  // debugging...
471  if (config()->debug() == 4) {
472  std::cout << "DTTracoChip::findBest - Looking for track number " << itk + 1 << std::endl;
473  std::cout << "Sorted std::vector of usable track candidates is:" << std::endl;
474  int i = 1;
475  for (std::vector<DTTracoCand>::iterator p = tclist.begin(); p < tclist.end(); p++) {
476  if ((*p).usable()) {
477  std::cout << " DTTracoChip Candidate # " << i++;
478  (*p).print();
479  }
480  }
481  std::cout << "--------------------------------------------------" << std::endl;
482  }
483  // end debugging
484 
485  // return the best candidate
486  int i = 0;
487  DTTracoCand *bestltrig = nullptr;
488  std::vector<DTTracoCand>::iterator p;
489  for (p = tclist.begin(); p < tclist.end(); ++p) {
490  i++;
491  // candidate must be usable and not suppressed by LTS
492  if (AdjBtiLTSuppressed(&(*p)))
493  if (config()->debug() == 4)
494  std::cout << "Candidate # " << i << " supp. because next to H in adiacent Tracos" << std::endl;
495  if ((*p).usable() && !AdjBtiLTSuppressed(&(*p))) {
496  // check if preference to HTRIG is set and return first trigger
497  if (!config()->prefHtrig(itk))
498  return &(*p);
499  if ((*p).BtiTrig()->code() == 8)
500  return &(*p);
501  if (bestltrig == nullptr)
502  bestltrig = &(*p);
503  }
504  }
505  return bestltrig;
506 }
507 
508 void DTTracoChip::DoAdjBtiLts(DTTracoCand *candidate, std::vector<DTTracoCand> &tclist) {
509  // If requested, do suppression of LTRIG on BTI close to selected HTRIG in
510  // same traco
511  // if(!(config()->adjBtiLts()) && candidate->BtiTrig()->code()==8) {
512  // SV this is done always, not parametrized !!
513  if (candidate->BtiTrig()->code() == 8) {
514  std::vector<DTTracoCand>::iterator p;
515  for (p = tclist.begin(); p < tclist.end(); p++) {
516  if ((*p).BtiTrig()->code() < 8 && abs((*p).BtiTrig()->btiNumber() - candidate->BtiTrig()->btiNumber()) < 2) {
517  (*p).setUsed();
518  if (config()->debug() == 4) {
519  std::cout << "Candidate :";
520  (*p).print();
521  std::cout << "Suppressed because adiacent to H trig" << std::endl;
522  } // end debug
523  } // end if
524  } // end candidate loop
525  } // end if H
526 }
527 
529  // If requested, do suppression of LTRIG on adjacent BTI -> obsolete!
530  // if(!(config()->adjBtiLts()) && candidate->BtiTrig()->code()<8) {
531  // SV: Ltrig always suppressed in hardware if Htrig in adj traco!
532  if (candidate->BtiTrig()->code() < 8) {
533  if (_flag[candidate->step() - DTConfigTraco::NSTEPF].element(3) && candidate->position() == 1)
534  return 1;
535  if (_flag[candidate->step() - DTConfigTraco::NSTEPF].element(4) && candidate->position() == DTConfigTraco::NBTITC)
536  return 1;
537  if (_flag[candidate->step() - DTConfigTraco::NSTEPF].element(5) &&
538  candidate->position() == DTConfigTraco::NBTITC + 1)
539  return 1;
540  if (_flag[candidate->step() - DTConfigTraco::NSTEPF].element(6) &&
541  candidate->position() == DTConfigTraco::NBTITC * 4)
542  return 1;
543  }
544  //}
545  return 0;
546 }
547 
549  // debugging...
550  if (config()->debug() == 4) {
551  std::cout << "DTTracoChip::setPV called for candidates : " << std::endl;
552  if (inner)
553  inner->print();
554  if (outer)
555  outer->print();
556  std::cout << "--------------------------------------------------" << std::endl;
557  }
558  // end debugging
559 
560  // first or second track. This is tricky:
561  // itk=0 menas first track ==> first= true=1
562  // itk=1 menas second track ==> first=false=0
563  int first = (itk == 0) ? 1 : 0;
564 
565  // preview selector: the same as priority selector I !!
566  // select which of the inner/outer segments should be used
567 
568  DTTracoCand *candidate = nullptr;
569  if (inner != nullptr && outer != nullptr) {
570  // if(config()->prefHtrig(itk)){
571  // ---> BUG! selection is ALWAYS for H trigs
572  // ---> fixed by Sara Vanini 25/III/03
573  if (inner->BtiTrig()->code() == 8 && outer->BtiTrig()->code() < 8) {
574  candidate = inner;
575  } else if (inner->BtiTrig()->code() < 8 && outer->BtiTrig()->code() == 8) {
576  candidate = outer;
577  } else { // for same quality tracks, pref. to in/out selection
578  if (!config()->prefInner(itk)) {
579  candidate = inner;
580  } else {
581  candidate = outer;
582  }
583  }
584  // } //end if(config()->prefHtrig...
585  /*
586  else {
587  if(!config()->prefInner(itk)) {
588  candidate=inner;
589  } else {
590  candidate=outer;
591  }
592  }
593  */
594  } else if (inner == nullptr && outer != nullptr) {
595  candidate = outer;
596  } else if (inner != nullptr && outer == nullptr) {
597  candidate = inner;
598  } else {
599  return nullptr; // no candidates
600  }
601 
602  // create new trigger with this candidate
603  DTTracoTrig *tct = new DTTracoTrig(this, candidate->step());
604  // store preview for TS
605  int cod = candidate->BtiTrig()->code();
606  if (candidate->BtiTrig()->btiSL() == 1)
607  cod *= 10;
608  // k output is 5 bits!!! SV
609  int K = candidate->K();
610  if (K > 31)
611  K -= 32;
612  int ioflag = 0;
613  if (candidate->position() > 4)
614  ioflag = 1;
615  tct->setPV(first, cod, K, ioflag); // this is already BTI_K-KRAD
616 
617  if (config()->debug() == 4) {
618  std::cout << "Selected candidate stored for preview is: ";
619  candidate->print();
620  }
621  return tct;
622 }
623 
625  // Bunch crossing
626  int is = tctrig->step();
627 
628  // Debugging...
629  if (config()->debug() == 4) {
630  std::cout << "DTTracoChip::storeCorr called with candidates: " << std::endl;
631  if (inner)
632  inner->print();
633  if (outer)
634  outer->print();
635  std::cout << "--------------------------------------------------" << std::endl;
636  }
637  // End debugging
638 
639  // old orca shift definition
640  float shift = 0.;
641  // if( config()->trigSetupGeom()!=1 )
642  shift = (int)(_geom->distSL() / _geom->cellH() + 0.5);
643  // else
644  // shift = DD();
645 
646  int kcor = 9999;
647  int xcor = 0;
648  int icor = 0;
649 
650  // Check correlation only if --> this cuts LL follow by H in next 4 bx
651  // SV 1/IV/04 BUG FIX: this cuts LL preview also, traco outputs preview when
652  // LTS cut!!!
653  // if( !config()->TcBxLts() || // BX LTS is not enabled or
654  // !_bxlts.element(is) || // no HTRIG in next 4 BX or
655  // inner->BtiTrig()->code()==8 || // inner track is HTRIG or
656  // outer->BtiTrig()->code()==8 ){ // outer track is HTRIG
657  // otherwise in and out trig are L, and necessary one is suppressed for LTS
658 
659  int xq1 = inner->X();
660  int xq2 = outer->X();
661  xcor = (xq2 + xq1) / 2;
662  kcor = (xq1 - xq2) + 512;
663  int kq1 = int(shift / 2.) * (inner->BtiTrig()->K() - BTIC()) + 512;
664  int kq2 = int(shift / 2.) * (outer->BtiTrig()->K() - BTIC()) + 512;
665  // int kd1 = abs(kcor/16-kq1/16);
666  // int kd2 = abs(kcor/16-kq2/16);
667  int kd1 = abs(kcor / 16 - kq1 / 16);
668  int kd2 = abs(kcor / 16 - kq2 / 16);
669 
670  icor = kd1 <= config()->TcKToll(tkn) && kd2 <= config()->TcKToll(tkn) && xcor > 0;
671 
672  // Debugging...
673  if (config()->debug() == 4) {
674  std::cout << "*************************************************************";
675  std::cout << std::endl;
676  std::cout << " shift = " << shift;
677  std::cout << " xq1 = " << xq1;
678  std::cout << " xq2 = " << xq2;
679  std::cout << " xcor = " << xcor;
680  std::cout << " kcor = " << kcor;
681  std::cout << " kq1 = " << kq1;
682  std::cout << " kq2 = " << kq2;
683  std::cout << " kd1 = " << kd1;
684  std::cout << " kd2 = " << kd2;
685  std::cout << " icor = " << icor;
686  std::cout << std::endl;
687  std::cout << "*************************************************************";
688  std::cout << std::endl;
689  } // End debugging
690 
691  //}//end if TcBxLts....
692 
693  if (icor) {
694  // correlation was successfull
695  // set the preview correlation bit. It isn't reset if outside ang. window
696  tctrig->setPVCorr(1);
697  // set K and X
698  tctrig->setK(kcor - 512);
699  // std::cout<<"Set K " << kcor << " instead of " << kcor-512 << std::endl;
700  // tctrig->setK(kcor);
701  tctrig->setX(xcor);
702  // set codes
703  tctrig->setCodeIn(inner->BtiTrig()->code());
704  tctrig->setCodeOut(outer->BtiTrig()->code());
705  // set position mask
706  // tctrig->setPosIn(inner->position());
707  // tctrig->setPosOut(outer->position());
708  // SV number of bti instead of position...
709  tctrig->setPosIn(inner->BtiTrig()->btiNumber());
710  tctrig->setPosOut(outer->BtiTrig()->btiNumber());
711  // SV store also equation: pattern numbers are 1-32
712  tctrig->setEqIn(inner->BtiTrig()->eq() + 1);
713  tctrig->setEqOut(outer->BtiTrig()->eq() + 1);
714 
715  // calculate psi, psi_r and Delta(psi_r)
716  calculateAngles(tctrig);
717  // check angular window for LL --> fixed by SV 27/III/03 --> NO, for all!
718  // if( (tctrig->qdec()==4) && !insideAngWindow(tctrig)) {
719  if (!insideAngWindow(tctrig)) {
720  // reset codes, K, X and angles
721  tctrig->resetVar();
722  }
723  // SV 1/IV/04 BUG FIX: check LTS after angle cut...
724  else if (tctrig->qdec() == 4 && // cut only LL
725  config()->TcBxLts()) { // BX LTS is enabled or
726  // reset codes, K, X and angles
727  if (tkn == 0 && _bxlts.element(is)) // I track : there is H -4,+1
728  tctrig->resetVar();
729  if (tkn == 1 && _bxlts.element(is + 1)) // II track : there is H -4,+1 1 bx later
730  tctrig->resetVar();
731  } else {
732  // set links to BTI triggers
733  tctrig->addDTBtiTrig(inner->BtiTrig());
734  tctrig->addDTBtiTrig(outer->BtiTrig());
735  }
736 
737  // Debugging...
738  if (config()->debug() > 1) {
739  std::cout << "*************************************************************";
740  std::cout << std::endl;
741  std::cout << " Correlation was successfull: ";
742  std::cout << std::endl;
743  std::cout << " Code = " << tctrig->code();
744  std::cout << " K = " << tctrig->K();
745  std::cout << " X = " << tctrig->X();
746  std::cout << std::endl;
747  std::cout << "*************************************************************";
748  std::cout << std::endl;
749  }
750  // End debugging
751 
752  } else {
753  // Debugging...
754  if (config()->debug() > 1) {
755  std::cout << "*************************************************************";
756  std::cout << std::endl;
757  std::cout << " No correlation possible ";
758  std::cout << std::endl;
759  std::cout << "*************************************************************";
760  std::cout << std::endl;
761  }
762  // End debugging
763  }
764 
765  return icor;
766 }
767 
769  // Bunch crossing
770  int is = tctrig->step();
771 
772  // Debugging...
773  if (config()->debug() == 4) {
774  std::cout << "DTTracoChip::storeUncorr called with candidates: " << std::endl;
775  if (inner)
776  inner->print();
777  if (outer)
778  outer->print();
779  std::cout << "--------------------------------------------------" << std::endl;
780  }
781 
782  // End debugging
783  // priority selector
784  // select which of the inner/outer segments should be used
785  // allow re-use of other segment according to configuration
786  DTTracoCand *candidate = nullptr;
787  if (inner != nullptr && outer != nullptr) {
788  // if(config()->prefHtrig(tkn)){
789  // --> BUG: selector I preference is ALWAYS for H trig
790  // fixed by Sara Vanini - 25/III/03
791  if (inner->BtiTrig()->code() == 8 && outer->BtiTrig()->code() < 8) {
792  candidate = inner;
793  // if(config()->TcReuse(1)) outer->setUnused(); // reusable
794  } else if (inner->BtiTrig()->code() < 8 && outer->BtiTrig()->code() == 8) {
795  candidate = outer;
796  // if(config()->TcReuse(0)) inner->setUnused(); // reusable
797  } else { // for the same quality triggers:
798  if (!config()->prefInner(tkn)) {
799  candidate = inner;
800  // if(config()->TcReuse(1)) outer->setUnused(); // reusable
801  } else {
802  candidate = outer;
803  // if(config()->TcReuse(0)) inner->setUnused(); // reusable
804  }
805  } // end else
806  /*
807  } else {//no Htrig preference
808  if(!config()->prefInner(tkn)) {
809  candidate=inner;
810  if(config()->TcReuse(1)) outer->setUnused(); // reusable
811  } else {
812  candidate=outer;
813  if(config()->TcReuse(0)) inner->setUnused(); // reusable
814  }
815  }
816  */
817  } else if (inner == nullptr && outer != nullptr) {
818  candidate = outer;
819  } else if (inner != nullptr && outer == nullptr) {
820  candidate = inner;
821  } else {
822  return 0; // no candidates
823  }
824 
825  // SV *** FOR TESTBEAM OR TEST BENCH PURPOSE ***
826  // theta trigger bin present(1) or absent(0)
827  // int thTr = (_flag[is-DTConfigTraco::NSTEPF].element(7)) ?
828  // _flag[is-DTConfigTraco::NSTEPF].element(7):
829  // _flag[is-DTConfigTraco::NSTEPF].element(8);
830 
831  // priority selector II: accept or discard candidate according to masks:
832  // ** LOW TRIGGERS
833  if (candidate->BtiTrig()->code() < 8) {
834  // first check with LVALIDIFH: if 1, accept low if there is a H in traco at
835  // bx
836  if (config()->LVALIDIFH() && _flag[is - DTConfigTraco::NSTEPF].element(9)) {
837  if (config()->debug() > 1)
838  std::cout << "Low accepted because LVALIDIFH on...." << std::endl;
839  } else { // LVALIDIFH==0 or there isn't H in traco in bx : check theta!
840  // theta check
841  if (!config()->singleLenab(tkn)) {
842  // LTF: single LTRIG not always en. Check cond.:
843  if (config()->singleLflag(tkn) == 1 || // always discarded
844  (config()->singleLflag(tkn) == 2 && !(_card->TSTh()->nHTrig(is))) ||
845  (config()->singleLflag(tkn) == 0 && !(_card->TSTh()->nTrig(is)))) {
846  // SV --> for TESTS version
847  // config()->singleLflag(tkn)==0 && thTr==0 || //only with
848  // theta trig. config()->singleLflag(tkn)==2 && thTr==0 ){
849  // //only with theta H trig (not hw)
850  if (config()->debug() > 1)
851  std::cout << "Single low trigger discarded by preview and "
852  << "priority selector for ltmsk!" << std::endl;
853  return 0;
854  }
855  // ^-------- trigger is suppressed and will not be stored
856  } // end theta
857 
858  } // end else
859  // REUSE : mark candidates reusable HERE! SV BUG FIX 6IV04
860  if (candidate == inner && config()->TcReuse(1) && outer)
861  outer->setUnused();
862  if (candidate == outer && config()->TcReuse(0) && inner)
863  inner->setUnused();
864 
865  // LTS suppression
866  if (config()->TcBxLts()) {
867  if ((tkn == 0 && _bxlts.element(is)) // I track : there is H -4,+1
868  || (tkn == 1 && _bxlts.element(is + 1))) { // II track : there is H -4,+1 1 bx later
869  tctrig->resetVar();
870  if (config()->debug() > 1)
871  std::cout << "Low trigger suppressed because H in next 4 bx "
872  << " and LTS flag on...." << std::endl;
873  return 1; // trigger is suppressed but preview will be stored
874  }
875  } // end lts
876 
877  // } //end else
878  } // Low trigs
879 
880  // Preview Htmsk not implemented: awaiting decision
881  // --> implemented in priority selector by SV
882  else { // HTRIG
883  // if(config()->singleHflag(tkn)==1 && thTr==0 ) //this is for testing
884  if (config()->singleHflag(tkn) == 1 && !(_card->TSTh()->nTrig(is)))
885  return 0;
886  // ^-----trigger is suppressed and will not be stored
887 
888  // mark candidates reusable HERE! SV BUG FIX 6IV04
889  if (candidate == inner && config()->TcReuse(1) && outer)
890  outer->setUnused();
891  if (candidate == outer && config()->TcReuse(0) && inner)
892  inner->setUnused();
893  }
894 
895  // set code, position, K and X
896  float shift;
897  // if(config()->trigSetupGeom()!=1 )
898  shift = (int)(_geom->distSL() / _geom->cellH() + 0.5);
899  // else
900  // shift = DD(); //SV 19/III/03
901  int kucor = (int)(0.5 * shift * (candidate->BtiTrig()->K() - BTIC()));
902  tctrig->setK(kucor);
903  tctrig->setX(candidate->X());
904  // correlation wasn't successfull
905  // set the preview correlation bit.
906  tctrig->setPVCorr(0);
907  if (candidate->BtiTrig()->btiSL() == 1) { // inner track
908  tctrig->setCodeIn(candidate->BtiTrig()->code());
909  tctrig->setCodeOut(0);
910  // tctrig->setPosIn(candidate->position());
911  // SV number of bti instead of position...
912  tctrig->setPosIn(candidate->BtiTrig()->btiNumber());
913  tctrig->setPosOut(0);
914  // SV store also equation
915  tctrig->setEqIn(candidate->BtiTrig()->eq() + 1);
916  tctrig->setEqOut(0);
917  } else { // outer track
918  tctrig->setCodeIn(0);
919  tctrig->setCodeOut(candidate->BtiTrig()->code());
920  tctrig->setPosIn(0);
921  // SV number of bti instead of position...
922  tctrig->setPosOut(candidate->BtiTrig()->btiNumber());
923  // tctrig->setPosOut(candidate->position());
924  // SV store also equation
925  tctrig->setEqIn(0);
926  tctrig->setEqOut(candidate->BtiTrig()->eq() + 1);
927  }
928 
929  // coordinate converter LUT
930  // calculate psi, psi_r and Delta(psi_r)
931  calculateAngles(tctrig);
932  // check angular window only for Low!! --> fixed SV 27/III/03--> NO, for all!
933  // if( candidate->BtiTrig()->code() < 8 && !insideAngWindow(tctrig) ){
934  if (!insideAngWindow(tctrig)) {
935  // reset codes, K, X and angles
936  tctrig->resetVar();
937  if (config()->debug() > 1)
938  std::cout << "L rejected because outside angular window!" << std::endl;
939  } else {
940  // set links to BTI trigger
941  tctrig->addDTBtiTrig(candidate->BtiTrig());
942  }
943 
944  // Debugging...
945  if (config()->debug() > 1) {
946  std::cout << "*************************************************************";
947  std::cout << std::endl;
948  std::cout << " Single trigger stored: ";
949  std::cout << std::endl;
950  std::cout << " Code = " << tctrig->code();
951  std::cout << " K = " << tctrig->K();
952  std::cout << " X = " << tctrig->X();
953  std::cout << std::endl;
954  std::cout << "*************************************************************";
955  std::cout << std::endl;
956  }
957  // End debugging
958 
959  return 1;
960 }
961 
962 void DTTracoChip::add_btiT(int step, int pos, const DTBtiTrigData *btitrig) {
963  if (pos < 1 || pos > 4 * DTConfigTraco::NBTITC) {
964  std::cout << "DTTracoChip::add_btiT: wrong position: " << pos;
965  std::cout << "trigger not added!" << std::endl;
966  return;
967  }
969  std::cout << "DTTracoChip::add_btiT: step out of range: " << step;
970  std::cout << "trigger not added!" << std::endl;
971  return;
972  }
973 
974  if (!config()->usedBti(pos)) {
975  if (config()->debug() == 4) {
976  std::cout << "DTTracoChip::add_btiT: position: " << pos;
977  std::cout << "has disconnected bti" << std::endl;
978  }
979  return;
980  }
981 
982  // 091103 SV: acceptances are taken from geometry if useAcceptParam()=false
983  // otherwise cuts based on LL,LH,CL,CH,RL,RH taken from configuration are
984  // applied in TracoCard::loadTraco
985  if (_card->useAcceptParamFlag() == false) {
986  // check K inside acceptance
987  if (btitrig->K() < _PSIMIN[pos - 1] || btitrig->K() > _PSIMAX[pos - 1]) {
988  if (config()->debug() > 1) {
989  std::cout << "In TRACO num. " << number() << " BTI trig. in pos " << pos << " outside K acceptance (";
990  std::cout << _PSIMIN[pos - 1] << "-->";
991  std::cout << _PSIMAX[pos - 1] << ") - Not added" << std::endl;
992  }
993  return;
994  }
995  }
996 
997  // Store trigger candidate
998  if (pos <= DTConfigTraco::NBTITC) {
999  _innerCand[step - DTConfigTraco::NSTEPF].push_back(DTTracoCand(this, btitrig, pos, step));
1000  } else {
1001  _outerCand[step - DTConfigTraco::NSTEPF].push_back(DTTracoCand(this, btitrig, pos, step));
1002  }
1003 
1004  // Fill array for BX LTS
1005  if (btitrig->code() == 8) {
1006  for (int is = step - 4; is < step; is++) { // set flag for 4 previous BX
1007  if (is > 0 && is <= DTConfigTraco::NSTEPL)
1008  _bxlts.set(is);
1009  }
1010  // SV 1/IV/04 BUG FIX
1011  _bxlts.set(step + 1);
1012  // Debugging
1013  if (config()->debug() == 4)
1014  for (int is = 0; is < DTConfigTraco::NSTEPL; is++)
1015  std::cout << "_bxlts[" << is << "]=" << _bxlts.element(is) << std::endl;
1016  }
1017 
1018  // Debugging
1019  if (config()->debug() > 1) {
1020  std::cout << "BTI Trigger added at step " << step;
1021  std::cout << " to TRACO " << _id.traco() << " at position " << pos << std::endl;
1022  btitrig->print();
1023  } // End debugging
1024 }
1025 
1028  std::cout << "DTTracoChip::addTrig: step out of range: " << step;
1029  std::cout << " trigger not added!" << std::endl;
1030  return;
1031  }
1032  _tracotrig[step - DTConfigTraco::NSTEPF].push_back(tctrig);
1033 
1034  // Debugging...
1035 
1036  if (config()->debug() == 4) {
1037  std::cout << "DTTracoChip::addTrig: adding trigger:" << std::endl;
1038  tctrig->print();
1039  }
1040  // End debugging
1041 }
1042 
1043 int DTTracoChip::nTrig(int step) const {
1045  std::cout << "DTTracoChip::nTrig: step out of range: " << step;
1046  std::cout << " 0 returned!" << std::endl;
1047  return 0;
1048  }
1049  return _tracotrig[step - DTConfigTraco::NSTEPF].size();
1050 }
1051 
1052 DTTracoTrig *DTTracoChip::trigger(int step, unsigned n) const {
1054  std::cout << "DTTracoChip::trigger: step out of range: " << step;
1055  std::cout << " empty pointer returned!" << std::endl;
1056  return nullptr;
1057  }
1058  if (n < 1 || n > _tracotrig[step - DTConfigTraco::NSTEPF].size()) {
1059  std::cout << "DTTracoChip::trigger: requested trigger doesn't exist: " << n;
1060  std::cout << " empty pointer returned!" << std::endl;
1061  return nullptr;
1062  }
1063  std::vector<DTTracoTrig *>::const_iterator p = _tracotrig[step - DTConfigTraco::NSTEPF].begin() + n - 1;
1064  return *p;
1065 }
1066 
1069  std::cout << "DTTracoChip::triggerData: step out of range: " << step;
1070  std::cout << " dummy trigger returned!" << std::endl;
1071  return DTTracoTrigData();
1072  }
1073  if (n < 1 || n > _tracotrig[step - DTConfigTraco::NSTEPF].size()) {
1074  std::cout << "DTTracoChip::trigger: requested trigger doesn't exist: " << n;
1075  std::cout << " dummy trigger returned!" << std::endl;
1076  return DTTracoTrigData();
1077  }
1078  std::vector<DTTracoTrig *>::const_iterator p = _tracotrig[step - DTConfigTraco::NSTEPF].begin() + n - 1;
1079  return (*p)->data();
1080 }
1081 
1082 float DTTracoChip::psiRad(int sl) const {
1083  /*
1084  // Radial angle of correlator center in mrad in CMS frame
1085  LocalPoint p = localPosition();
1086  float x = p.x();
1087  float y = p.y();
1088  float z = p.z();
1089  if (sl==1) {
1090  z -= 0.5 * _geom->distSL();
1091  } else if (sl==3) {
1092  z += 0.5 * _geom->distSL();
1093  }
1094  float fpsir = _geom->stat()->toGlobal(LocalPoint(x,y,z)).phi()-
1095  _geom->phiCh();
1096  if(fpsir<-M_PI)fpsir+=M_PI*2;
1097  if(fpsir>M_PI)fpsir-=M_PI*2;
1098  return fpsir*1000;
1099  */
1100  return 0.0;
1101 }
1102 
1103 int DTTracoChip::KRad() const {
1104  // K parameter of the radial angle of correlator center
1105  // float distp2 = (int)(2*_geom->cellH()*config()->ST()/_geom->cellPitch());
1106  // return -(int)(tan(psiRad(sl)/1000)*distp2); // sign is reverted!!!
1107  // return _krad;
1108 
1109  // SV V/03: for harware bug in traco....
1110  int KRad = 0;
1111  return KRad;
1112 }
1113 
1115  // return 1 if II track use is allow
1116  // return 0 if II track has been rejected
1118  std::cout << "DTTracoChip::useSecondTrack: step out of range: " << step;
1119  std::cout << " 0 returned!" << std::endl;
1120  return 0;
1121  }
1122  return !(_flag[step - DTConfigTraco::NSTEPF].element(2));
1123 }
1124 
1125 int DTTracoChip::edgeBTI(int step, int io, int lr) const {
1127  std::cout << "DTTracoChip::edgeBTI: step out of range: " << step;
1128  std::cout << " 0 returned!" << std::endl;
1129  return 0;
1130  }
1131  //
1132  // inner supl ==> io=1; outer supl ==> io=2 |21 | | 22|
1133  // right edge ==> rl=1; left edge ==> rl=2 |11 12|
1134  //
1135  std::vector<DTTracoCand>::const_iterator p;
1136  if (io == 1) {
1138  // SV 24/IX/03 fix: only HTRIG accepted
1140  p++) {
1141  if (lr == 1 && (*p).position() == 1 && (*p).BtiTrig()->code() == 8)
1142  return 1;
1143  if (lr == 2 && (*p).position() == DTConfigTraco::NBTITC && (*p).BtiTrig()->code() == 8)
1144  return 1;
1145  }
1146  }
1147  } else {
1150  p++) {
1151  // SV: is the following correct???FIX if using _card to set _flag
1152  // if(lr==1 && (*p).position()==DTConfigTraco::NBTITC+1)return 1; //or
1153  // pos=8?? if(lr==2 && (*p).position()==DTConfigTraco::NBTITC*4)return
1154  // 1;
1155  // //or pos=13?? SV 24/IX/03 fix
1156  if (lr == 1 && (*p).position() == DTConfigTraco::NBTITC * 3 + 1 && (*p).BtiTrig()->code() == 8)
1157  return 1;
1158  if (lr == 2 && (*p).position() == DTConfigTraco::NBTITC * 2 && (*p).BtiTrig()->code() == 8)
1159  return 1;
1160  }
1161  }
1162  }
1163  return 0;
1164 }
1165 
1167  int ipsi = 0;
1168  int iphir = 0;
1169  int idpsir = 0;
1170  /* obsolete
1171  //TB 2004 luts formula from minicrate CCB
1172  if( config()->trigSetupGeom()==2 ){
1173  ipsi = _lutsCCB->get_k( (tct->K()+511) );
1174 
1175  int flag = 0;
1176  int qual=tct->data().qdec();
1177  if(qual==3 || qual==1) //case 0:outer
1178  flag=0;
1179  if(qual==2 || qual==0) //case 1:inner
1180  flag=1;
1181  if(qual==6 || qual==5 || qual==4) //case 2:correlated
1182  flag=2;
1183 
1184  iphir = _lutsCCB->get_x( (tct->X()+512*flag) );
1185 
1186  idpsir = ipsi - iphir/8;
1187  }
1188 
1189  //TB 2003 luts data format
1190  if( config()->trigSetupGeom()==1 ){
1191  //compute bending angles of traco output with lookup tables
1192  //SV TB2003: first trigger board isn't connected;
1193  ipsi = _luts->getPsi(tct->K());
1194  int flag = 0;
1195  int qual=tct->data().qdec();
1196  if(qual==3 || qual==1) //case 0:outer
1197  flag=0;
1198  if(qual==2 || qual==0) //case 1:inner
1199  flag=1;
1200  if(qual==6 || qual==5 || qual==4) //case 2:correlated
1201  flag=2;
1202  iphir = _luts->getPhiRad( tct->X(), flag);
1203  idpsir = _luts->getBendAng( tct->X(), tct->K(), flag);
1204  }
1205  */
1206 
1207  // 091030 SV angles computed from DB lut parameters
1208  if (_card->lutFromDBFlag() == 1) {
1209  ipsi = _lutsCCB->get_k((tct->K() + 512));
1210 
1211  int flag = 0;
1212  int qual = tct->data().qdec();
1213  if (qual == 3 || qual == 1) // case 0:outer
1214  flag = 0;
1215  if (qual == 2 || qual == 0) // case 1:inner
1216  flag = 1;
1217  if (qual == 6 || qual == 5 || qual == 4) // case 2:correlated
1218  flag = 2;
1219 
1220  iphir = _lutsCCB->get_x((tct->X() + 512 * flag));
1221 
1222  idpsir = ipsi - iphir / 8;
1223  } else
1224  // compute angles from CMSSW geometry
1225  // if( config()->trigSetupGeom()==0 )
1226  {
1227  DTTracoTrigData td = tct->data();
1228  // psi
1229  // float fpsi = atan( (float)(tct->K()) * _geom->cellPitch() /
1230  // (_geom->distSL() * config()->ST()) );
1231  float fpsi = atan(_card->localDirection(&td).x() / // e.g. x>0 and
1232  _card->localDirection(&td).z()); // z<0 => fpsi<0
1233 
1234  // Change sign in case of wheel<0 or wheel==0 and station == 1,4,5,8,9,12
1235  int mywh = tct->ChamberId().wheel();
1236  if (mywh < 0 || (mywh == 0 && (tct->ChamberId().sector() % 4) < 2))
1237  fpsi = -fpsi;
1238 
1239  fpsi *= DTConfigTraco::RESOLPSI;
1240  if (fpsi <= 0)
1241  fpsi -= 1.0;
1242  ipsi = (int)fpsi;
1243  // if outside range set to lower edge
1244  if (ipsi >= DTConfigTraco::RESOLPSI || ipsi < -DTConfigTraco::RESOLPSI)
1245  ipsi = -DTConfigTraco::RESOLPSI;
1246 
1247  // psi_r
1248  float fpsir = _card->CMSPosition(&td).phi() - _geom->phiCh();
1249 
1250  if (fpsir < -M_PI)
1251  fpsir += M_PI * 2;
1252  if (fpsir > M_PI)
1253  fpsir -= M_PI * 2;
1254  fpsir *= DTConfigTraco::RESOLPSIR;
1255  if (fpsir <= 0)
1256  fpsir -= 1.0;
1257  iphir = (int)fpsir;
1258  // if outside range set to lower edge
1259  if (iphir >= DTConfigTraco::RESOLPSIR / 2 || iphir < -DTConfigTraco::RESOLPSIR / 2)
1260  iphir = -DTConfigTraco::RESOLPSIR / 2;
1261 
1262  // Delta(psi_r)
1263  int dpsir = (iphir * DTConfigTraco::RESOLPSI) / DTConfigTraco::RESOLPSIR;
1264  idpsir = ipsi - dpsir;
1265  // if outside range set to lower edge
1266  if (idpsir >= DTConfigTraco::RESOLPSI || idpsir < -DTConfigTraco::RESOLPSI)
1267  idpsir = -DTConfigTraco::RESOLPSI;
1268  }
1269 
1270  tct->setAngles(ipsi, iphir, idpsir);
1271 
1272  // debugging
1273  if (config()->debug() == 4) {
1274  std::cout << "DTTracoChip::calculateAngles :" << std::endl;
1275  tct->print();
1276  std::cout << std::dec << "K = " << tct->K() << " X = " << tct->X();
1277  std::cout << " ipsi = " << ipsi << " iphir = " << iphir;
1278  std::cout << " idpsir = " << idpsir << std::endl;
1279  if (_card->lutFromDBFlag() == 1)
1280  std::cout << "Angles are calculated from LUT parameters from DB!" << std::endl;
1281  } // end debugging
1282 }
1283 
1285  // check angular window for every station type
1286  // return 1 for accept, 0 for reject
1287  // abs value of bending angle is 9 bits
1288 
1289  BitArray<10> bendAng;
1290  bendAng.assign(0, 10, tctrig->DeltaPsiR());
1291  // bendAng.print();
1292  if (bendAng.element(9)) // negativo!
1293  bendAng.twoComplement();
1294  int bendAngINT = bendAng.read(0, 9);
1295  // std::cout<<"abs bend angle int ="<< bendAngINT <<std::endl;
1296 
1297  if (config()->BendingAngleCut() != -1 && bendAngINT > 2 * (config()->BendingAngleCut())) {
1298  int absBendAng = tctrig->DeltaPsiR() & 0x1FF;
1299  if (config()->debug() == 4)
1300  std::cout << "Attention: abs(bendAng)=" << absBendAng << " > " << 2 * config()->BendingAngleCut()
1301  << "!! reject trigger" << std::endl;
1302  return 0;
1303  }
1304  return 1;
1305 }
1306 
1308  // Set K acceptances of DTTracoChip MT ports: Ktraco = Xinner - Xouter
1309  float h = _geom->cellH();
1310  float pitch = _geom->cellPitch();
1311  float distsl = _geom->distSL();
1312  float K0 = config()->BTIC();
1313  float shiftSL = _geom->phiSLOffset() / pitch * K0;
1314 
1315  // mt ports from orca geometry: this is always the case with new DTConfig
1316  // if(config_traco(tracoid)->trigSetupGeom() != 1){
1317  {
1318  // Master Plane
1319  int i = 0;
1320  for (i = 0; i < DTConfig::NBTITC; i++) {
1321  float Xin_min = (i + DTConfig::NBTITC) * K0 + shiftSL;
1322  float Xin_max = Xin_min + K0;
1323  float Xout_min = 0;
1324  float Xout_max = 3 * DTConfig::NBTITC * K0;
1325  _PSIMAX[i] = int(2. * h / distsl * (Xin_max - Xout_min) + K0 + 1.01);
1326  _PSIMIN[i] = int(2. * h / distsl * (Xin_min - Xout_max) + K0);
1327  }
1328 
1329  // Slave Plane
1330  for (i = 0; i < 3 * DTConfig::NBTITC; i++) {
1331  float Xin_min = (DTConfig::NBTITC)*K0 + shiftSL;
1332  float Xin_max = 2. * DTConfig::NBTITC * K0 + shiftSL;
1333  float Xout_min = i * K0;
1334  float Xout_max = Xout_min + K0;
1335  _PSIMAX[DTConfig::NBTITC + i] = int(2. * h / distsl * (Xin_max - Xout_min) + K0 + 1.01);
1336  _PSIMIN[DTConfig::NBTITC + i] = int(2. * h / distsl * (Xin_min - Xout_max) + K0);
1337  }
1338  }
1339 
1340  // debugging
1341  if (config()->debug() == 4) {
1342  // if(wheel()==2&&station()==3&&sector()==1){ // only 1 chamber
1343  std::cout << "Acceptance of mt ports for offset (cell unit) " << _geom->phiSLOffset() / pitch << std::endl;
1344  for (int i = 0; i < 4 * DTConfig::NBTITC; i++) {
1345  std::cout << "Port " << i + 1 << " : ";
1346  std::cout << _PSIMIN[i] << " --> " << _PSIMAX[i] << std::endl;
1347  }
1348  //}
1349  } // end debugging
1350 }
void setPosIn(int pos)
Set position of segments, inner.
Definition: DTTracoTrig.h:73
LocalVector localDirection(const DTTrigData *) const override
NEWGEO Local direction in chamber of a trigger-data object.
Definition: DTTracoCard.cc:403
size
Write out results.
LocalPoint localPosition(const DTBtiId) const
Local position in chamber of a BTI.
Definition: DTTrigGeom.cc:508
int btiNumber() const
Return parent BTI number.
Definition: DTBtiTrigData.h:96
int _PSIMAX[4 *DTConfig::NBTITC]
Definition: DTTracoChip.h:215
int station() const
Return the station number.
Definition: DTChamberId.h:42
constexpr int32_t ceil(float num)
const DTBtiTrigData * BtiTrig() const
Return associated BTI trigger.
Definition: DTTracoCand.h:68
int btiSL() const
Return parent BTI superlayer.
Definition: DTBtiTrigData.h:99
int KRad() const
K par of the radial angle of corr center referred to plane sl.
int singleLflag(int i) const
Single LTRIG enabling on first/second tracks: F(S)LTMSK.
Definition: DTConfigTraco.h:90
DTTracoChip * getTRACO(int n) const
Returns the required DTTracoChip. Return 0 if it doesn&#39;t exist.
Definition: DTTracoCard.cc:286
void run()
Run TRACO algorithm.
Definition: DTTracoChip.cc:239
int sortKascend(int i) const
Ascend. order for K sorting first/second tracks: F(S)HISM.
int nHTrig(int step)
Return number of DTBtiChip fired with a HTRIG (used by DTTracoChip)
Definition: DTTSTheta.cc:229
int AdjBtiLTSuppressed(DTTracoCand *candidate)
Do suppression of LTRIG on adjacent TRACO.
Definition: DTTracoChip.cc:528
int BTIC() const
BTIC traco parameter: must be equal to Btis ST parameter.
Definition: DTConfigTraco.h:68
float cellPitch() const
Width of a cell (cm) i.e. distance between ywo wires.
Definition: DTTrigGeom.h:76
int K() const
Return trigger K parameter.
void setX(int x)
Set trigger X parameter.
Definition: DTTracoTrig.h:88
void setK(int k)
Set trigger K parameter.
Definition: DTTracoTrig.h:85
Lut * _lutsCCB
Definition: DTTracoChip.h:220
void calculateAngles(DTTracoTrig *)
Calculate trigger angles.
void setFlag(int step, int ext=0)
Set flags for multiple trigger detection between cons. TRACO&#39;s.
Definition: DTTracoChip.cc:406
T z() const
Definition: PV3DBase.h:61
void addTrig(int step, DTTracoTrig *)
Add a TRACO trigger.
void setTracoAcceptances()
Compute traco chip acceptances.
DTTracoLUTs * _luts
Definition: DTTracoChip.h:218
int DeltaPsiR() const
Return DeltaPsiR.
Definition: DTTracoTrig.h:166
int BTIC() const
BTIC parameter.
Definition: DTTracoChip.h:123
DTTracoTrigData data() const
Return the data part.
Definition: DTTracoTrig.h:115
float phiCh() const
Rotation angle of chamber (deg)
Definition: DTTrigGeom.h:70
void resetVar()
Reset all variables but preview.
Definition: DTTracoTrig.h:94
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
int prefInner(int i) const
Preference to inner on first/second tracks: F(S)SLMSK.
Definition: DTConfigTraco.h:98
DTTracoId _id
Definition: DTTracoChip.h:186
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
void zero()
Definition: BitArray.h:210
static const int NSTEPF
Definition: DTConfig.h:35
DTTrigGeom * geom() const
Return trigger geometry.
Definition: DTTracoChip.h:95
int qdec() const
Return the trigger code in new format.
bool lutFromDBFlag()
Return lut computation option (DB/geometry)
Definition: DTTracoCard.h:114
int K() const
Return K-KRAD.
Definition: DTTracoCand.h:77
int BendingAngleCut() const
Bending angle cut for all stations and triggers : KPRGCOM.
void add_btiT(int step, int pos, const DTBtiTrigData *btitrig)
Add a BTI trigger to the TRACO.
Definition: DTTracoChip.cc:962
void setCodeIn(int code)
Set trigger code, inner segment.
Definition: DTTracoTrig.h:67
int step() const
Return step.
Definition: DTTracoTrig.h:121
int K() const
Return trigger K parameter.
Definition: DTTracoTrig.h:154
int position() const
Return position inside TRACO.
Definition: DTTracoCand.h:74
int singleLenab(int i) const
Single LTRIG accept enabling on first/second tracks LTF.
void setPosOut(int pos)
Set position of segments, outer.
Definition: DTTracoTrig.h:76
float psiRad(int sl=0) const
Radial angle of correlator center in mrad referred to plane sl.
void print() const
Print candidate.
Definition: DTTracoCand.cc:120
int nTrig(int step) const
Return the number of trigger candidates.
~DTTracoChip()
Destructor.
Definition: DTTracoChip.cc:175
DTTracoCand * bestCand(int itk, std::vector< DTTracoCand > &tclist)
Get the best inner/outer candidate.
Definition: DTTracoChip.cc:447
int insideAngWindow(DTTracoTrig *) const
Check if a trigger is inside the angular acceptance window.
T x() const
Definition: PV3DBase.h:59
int code() const
Return trigger code.
DTChamberId ChamberId() const override
Return chamber identifier.
Definition: DTTracoTrig.h:106
GlobalPoint CMSPosition() const
Position in CMS frame.
Definition: DTTracoChip.h:150
int useSecondTrack(int step) const
a flag for a usable second track
float distSL() const
Distance between the phi view superlayers (cms)
Definition: DTTrigGeom.h:79
DTTrigGeom * geom() const
Associated geometry.
int X() const
Return trigger X parameter.
Definition: DTTracoTrig.h:157
void setCodeOut(int code)
Set trigger code, outer segment.
Definition: DTTracoTrig.h:70
int edgeBTI(int step, int io, int lr) const
flags for HTRIG in edge BTI
int step() const
Return Bunch crossing.
Definition: DTTracoCand.h:71
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void raiseOverlap(int step)
raise overlap flag
Definition: DTTracoChip.cc:401
int traco() const
Returns the traco.
Definition: DTTracoId.h:59
DTChamberId statId() const
Identifier of the associated chamber.
Definition: DTTrigGeom.h:53
BitArray< N > twoComplement() const
Definition: BitArray.h:507
std::vector< DTTracoCand > _outerCand[DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF+1]
Definition: DTTracoChip.h:199
int storeUncorr(DTTracoTrig *tctrig, DTTracoCand *inner, DTTracoCand *outer, int tkn)
Store uncorrelated trigger.
Definition: DTTracoChip.cc:768
void setEqOut(int eq)
Set bti trigger equation of segments, outer.
Definition: DTTracoTrig.h:82
static const int NSTEPL
Constants: first and last step to start trigger finding.
Definition: DTConfig.h:35
std::vector< DTTracoTrig * > _tracotrig[DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF+1]
Definition: DTTracoChip.h:202
DTTracoTrigData triggerData(int step, unsigned n) const
Return the data part of the requested trigger.
isFirst
Definition: cuy.py:418
void addDTBtiTrig(const DTBtiTrigData *btitrig)
Add a BTI trigger to the list.
Definition: DTTracoTrig.h:58
void setAngles(int psi, int psir, int dpsir)
Set trigger angles.
Definition: DTTracoTrig.h:91
#define M_PI
DTTracoChip(DTTracoCard *card, int n, DTConfigTraco *config)
Constructor.
Definition: DTTracoChip.cc:47
int TcKToll(int i) const
K tollerance for correlation in TRACO: F(S)PRGCOMP.
int prefHtrig(int i) const
Preference to HTRIG on first/second tracks: F(S)HTPRF.
std::vector< DTTracoCand > _innerCand[DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF+1]
Definition: DTTracoChip.h:198
DTTracoChip & operator=(const DTTracoChip &traco)
Assignment operator.
Definition: DTTracoChip.cc:195
float cellH() const
Height of a cell (cm)
Definition: DTTrigGeom.h:73
void print() const override
Print.
Definition: DTTracoTrig.h:109
#define debug
Definition: HDRShower.cc:19
static const int RESOLPSIR
Costant: resulution for psiR (phi)
Definition: DTConfigTraco.h:42
int debug() const
Debug flag.
Definition: DTConfigTraco.h:62
int qdec() const
Return the trigger code in new format.
Definition: DTTracoTrig.h:169
float phiSLOffset()
Superlayer offset in chamber front-end frame, in cm.
Definition: DTTrigGeom.cc:64
GlobalPoint CMSPosition(const DTTrigData *trig) const
CMS position in chamber of a trigger-data object.
int TcReuse(int i) const
Recycling of TRACO cand. in inner/outer SL : REUSEI/REUSEO.
Definition: DTConfigTraco.h:74
void clear()
Clear.
Definition: DTTracoChip.cc:225
bool useAcceptParamFlag()
Return acceptance flag.
Definition: DTTracoCard.h:111
void DoAdjBtiLts(DTTracoCand *candidate, std::vector< DTTracoCand > &tclist)
Do suppression of LTRIG on BTI close to selected HTRIG.
Definition: DTTracoChip.cc:508
DTTracoTrig * trigger(int step, unsigned n) const
Return the requested trigger.
void assign(const int p, const int n, const int val)
Definition: BitArray.h:233
int storeCorr(DTTracoTrig *tctrig, DTTracoCand *inner, DTTracoCand *outer, int tkn)
Check correlation and store correlated trigger.
Definition: DTTracoChip.cc:624
void setPVCorr(int ic)
Set trigger preview correlation bit.
Definition: DTTracoTrig.h:64
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
const DTConfigLUTs * config_luts() const
Return LUTS config for this chamber (=minicrate)
Definition: DTTracoCard.h:108
int sector() const
Definition: DTChamberId.h:49
DTConfigTraco * config() const
Configuration set.
Definition: DTTracoChip.h:113
void setEqIn(int eq)
Set bti trigger equation of segments, inner.
Definition: DTTracoTrig.h:79
BitArray< 32 > _flag[DTConfigTraco::NSTEPL - DTConfigTraco::NSTEPF+1]
Definition: DTTracoChip.h:211
int _PSIMIN[4 *DTConfig::NBTITC]
Definition: DTTracoChip.h:214
void print() const override
Print.
static unsigned int const shift
int X() const
Return local X coordinate.
Definition: DTTracoCand.h:80
DTTracoCard * _card
Definition: DTTracoChip.h:188
int KRAD() const
KRAD traco parameter.
Definition: DTConfigTraco.h:65
int code() const
Return trigger code.
Definition: DTTracoTrig.h:124
int get_x(int addr) const
Definition: Lut.cc:121
DTTSTheta * TSTh() const
Return TSTheta.
Definition: DTTracoCard.h:77
BitArray< DTConfigTraco::NSTEPL+2 > _bxlts
Definition: DTTracoChip.h:205
step
Definition: StallMonitor.cc:98
int TcBxLts() const
Suppr. of LTRIG in 4 BX before HTRIG: LTS.
static const int NBTITC
Definition: DTConfig.h:37
void setPV(int first, int code, int K, int io)
Set trigger preview parameters.
Definition: DTTracoTrig.h:61
int LVALIDIFH() const
Flag for Low validation parameter.
unsigned read(const int p, const int n) const
Definition: BitArray.h:269
Definition: memstream.h:15
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static const int RESOLPSI
Costants: esolution for psi and DeltaPsiR (phi_B)
Definition: DTConfigTraco.h:40
int number() const
Return TRACO number.
Definition: DTTracoChip.h:89
DTTrigGeom * _geom
Definition: DTTracoChip.h:185
int eq() const
Return triggering equation.
void set(const int i)
Definition: BitArray.h:224
void setPV(int step, int ntrk, int code, int K)
Set the preview values for a TRACO trigger.
int element(const int pos) const
Definition: BitArray.h:206
Definition: Lut.h:31
int get_k(int addr) const
Definition: Lut.cc:107
int nTrig(int step)
Return number of DTBtiChip fired (used by DTTracoChip)
Definition: DTTSTheta.cc:218