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