CMS 3D CMS Logo

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