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