CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/L1Trigger/DTBti/src/DTBtiChipSelTrig.cc

Go to the documentation of this file.
00001 //-----------------------------------------------------------------
00002 //
00003 //   Class: DTBtiChip
00004 //
00005 //   Description: Implementation of DTBtiChip 
00006 //                trigger algorithm
00007 //                (Trigger selection implementation)
00008 //
00009 //
00010 //   Author List:
00011 //   C. Grandi
00012 //   Modifications: 
00013 //   23/X/02 Sara Vanini : asymmetric acceptance added for H trig
00014 //   07/I/03 SV: sort patterns for equivalence with bti manual
00015 //   13/I/03 SV: fixed for Keq in manual form
00016 //   30/IX/03 SV: redundancies for xA xB xC xD low trigs included
00017 //   22/VI/04 SV: last trigger code update
00018 //----------------------------------------------------------------
00019 
00020 //-----------------------
00021 // This Class's Header --
00022 //-----------------------
00023 #include "L1Trigger/DTBti/interface/DTBtiChip.h"
00024 
00025 //-------------------------------
00026 // Collaborating Class Headers --
00027 //-------------------------------
00028 #include "L1TriggerConfig/DTTPGConfig/interface/BitArray.h"
00029 
00030 //---------------
00031 // C++ Headers --
00032 //---------------
00033 #include<iostream>
00034 #include<cmath>
00035 #include<iomanip>
00036 
00037 using namespace std;
00038 
00039 void 
00040 DTBtiChip::findTrig(){
00041 
00042   if(config()->debug()>3){
00043     cout << "DTBtiChip::findTrig called" << endl; 
00044   }
00045 
00046   //pattern type:       1 = normal
00047   //                    2 = 1L1
00048   //                    3 = 11L
00049   //                    4 = L11
00050   //                    5 = 1H1
00051   //                    6 = 11H
00052   //                    7 = H11
00053 
00054 //  int accpatB = config()->AccPattB(); //default +-1
00055 //  int accpatA = config()->AccPattA(); //default +-2
00056 //  int tiKes = config()->XON();
00057   int RON = config()->RONflag();  //default 1, redundant patterns enabled
00058   int PTMS[32];
00059   for(int i=0; i<32; i++){
00060     PTMS[i] = config()->PTMSflag(i);
00061   }
00062 
00063   //Triggers (same order as manual):
00064   for(int hl=0;hl<2;hl++){  //hl=0 high   hl=1 low
00065   if( RON==1 ){
00066     if( keepTrigPatt(PTMS[0],0,1,hl) ) return;   // 1324A --> 0 - 1L3L2R4L: nor
00067   }
00068   if( keepTrigPatt(PTMS[1],1,2,hl) ) return;   // 1324B --> 1 - 1L3L2R4R: 1L1
00069   if( keepTrigPatt(PTMS[2],2,1,hl) ) return;   // 1324C --> 2 - 1R3L2R4L: nor
00070   if( keepTrigPatt(PTMS[3],3,1,hl) ) return;   // 1324D --> 3 - 1R3L2R4R: nor
00071   if( keepTrigPatt(PTMS[4],4,3,hl) ) return;   // 1364A -->  4 - 1L3L6L4R: 11L
00072   if( keepTrigPatt(PTMS[5],5,1,hl) ) return;   // 1364B -->  5 - 1R3L6L4R: nor
00073   if( keepTrigPatt(PTMS[6],6,1,hl) ) return;   // 1364C -->  6 - 1R3R6L4R: nor
00074   if( keepTrigPatt(PTMS[7],7,5,hl) ) return;   // 1368A -->  7 - 1R3R6L8L: 1H1
00075   if( keepTrigPatt(PTMS[8],8,6,hl) ) return;   // 1368B -->  8 - 1R3R6R8L: 11H
00076   if( keepTrigPatt(PTMS[9],9,7,hl) ) return;   // 1368C -->  9 - 1R3L6L8L: H11
00077   if( keepTrigPatt(PTMS[10],10,1,hl) ) return;   // 5324A --> 10 - 5L3L2R4L: nor
00078   if( keepTrigPatt(PTMS[11],11,1,hl) ) return;   // 5324B --> 11 - 5L3R2R4L: nor
00079   if( keepTrigPatt(PTMS[12],12,6,hl) ) return;   // 5324C --> 12 - 5R3R2R4L: 11H
00080   if( keepTrigPatt(PTMS[13],13,1,hl) ) return;   // 5364A --> 13 - 5L3R6L4L: nor
00081   if( keepTrigPatt(PTMS[14],14,1,hl) ) return;   // 5364B --> 14 - 5L3R6L4R: nor
00082   if( keepTrigPatt(PTMS[15],15,5,hl) ) return;   // 5364C --> 15 - 5R3R6L4L: 1H1
00083   if( keepTrigPatt(PTMS[16],16,1,hl) ) return;   // 5364D --> 16 - 5R3R6L4R: nor
00084   if( keepTrigPatt(PTMS[17],17,1,hl) ) return;   // 5368A --> 17 - 5L3R6L8L: nor
00085   if( keepTrigPatt(PTMS[18],18,1,hl) ) return;   // 5368B --> 18 - 5L3R6R8L: nor
00086   if( keepTrigPatt(PTMS[19],19,4,hl) ) return;   // 5368C --> 19 - 5L3R6R8R: L11
00087   if( keepTrigPatt(PTMS[20],20,1,hl) ) return;   // 5764A --> 20 - 5R7L6L4R: nor
00088   if( keepTrigPatt(PTMS[21],21,1,hl) ) return;   // 5764B --> 21 - 5R7L6R4R: nor
00089   if( keepTrigPatt(PTMS[22],22,7,hl) ) return;   // 5764C --> 22 - 5R7L6L4L: H11
00090   if( keepTrigPatt(PTMS[23],23,3,hl) ) return;   // 9764A --> 23 - 9L7L6L4R: 11L
00091   if( keepTrigPatt(PTMS[24],24,2,hl) ) return;   // 9764B --> 24 - 9L7L6R4R: 1L1
00092   if( keepTrigPatt(PTMS[25],25,4,hl) ) return;   // 9764C --> 25 - 9L7R6R4R: L11
00093   if( keepTrigPatt(PTMS[26],26,1,hl) ) return;   // 5768A -->  26 - 5L7L6R8L: nor   
00094   if( RON==1 ){
00095     if( keepTrigPatt(PTMS[27],27,2,hl) ) return;   // 5768B --> 27 - 5L7L6R8R: 1L1
00096     if( keepTrigPatt(PTMS[28],28,1,hl) ) return;   // 5768C --> 28 - 5R7L6R8L: nor
00097     if( keepTrigPatt(PTMS[29],29,1,hl) ) return;   // 5768D --> 29 - 5R7L6R8R: nor
00098     if( keepTrigPatt(PTMS[30],30,1,hl) ) return;   // 9768A --> 30 - 9L7L6R8L: nor
00099     if( keepTrigPatt(PTMS[31],31,1,hl) ) return;   // 9768B --> 31 - 9L7R6R8L: nor 
00100   }
00101  
00102   }//end h/l loop
00103 
00104 
00105 
00106 /*
00107   for(int hl=0;hl<2;hl++){  //hl=0 high   hl=1 low
00108   if( keepTrigPatt(PTMS[0],0,1,hl) ) return;   // 5768A -->  0 - 5L7L6R8L: nor   
00109   if( RON==1 ){
00110     if( keepTrigPatt(PTMS[1],1,2,hl) ) return;   // 5768B -->  1 - 5L7L6R8R: 1L1
00111     if( keepTrigPatt(PTMS[2],2,1,hl) ) return;   // 5768C -->  2 - 5R7L6R8L: nor
00112     if( keepTrigPatt(PTMS[3],3,1,hl) ) return;   // 5768D -->  3 - 5R7L6R8R: nor
00113   }
00114   if( keepTrigPatt(PTMS[4],4,3,hl) ) return;   // 1364A -->  4 - 1L3L6L4R: 11L
00115   if( keepTrigPatt(PTMS[5],5,1,hl) ) return;   // 1364B -->  5 - 1R3L6L4R: nor
00116   if( keepTrigPatt(PTMS[6],6,1,hl) ) return;   // 1364C -->  6 - 1R3R6L4R: nor
00117   if( keepTrigPatt(PTMS[7],7,5,hl) ) return;   // 1368A -->  7 - 1R3R6L8L: 1H1
00118   if( keepTrigPatt(PTMS[8],8,6,hl) ) return;   // 1368B -->  8 - 1R3R6R8L: 11H
00119   if( keepTrigPatt(PTMS[9],9,7,hl) ) return;   // 1368C -->  9 - 1R3L6L8L: H11
00120   if( keepTrigPatt(PTMS[10],10,1,hl) ) return;   // 5324A --> 10 - 5L3L2R4L: nor
00121   if( keepTrigPatt(PTMS[11],11,1,hl) ) return;   // 5324B --> 11 - 5L3R2R4L: nor
00122   if( keepTrigPatt(PTMS[12],12,6,hl) ) return;   // 5324C --> 12 - 5R3R2R4L: 11H
00123   if( keepTrigPatt(PTMS[13],13,1,hl) ) return;   // 5364A --> 13 - 5L3R6L4L: nor
00124   if( keepTrigPatt(PTMS[14],14,1,hl) ) return;   // 5364B --> 14 - 5L3R6L4R: nor
00125   if( keepTrigPatt(PTMS[15],15,5,hl) ) return;   // 5364C --> 15 - 5R3R6L4L: 1H1
00126   if( keepTrigPatt(PTMS[16],16,1,hl) ) return;   // 5364D --> 16 - 5R3R6L4R: nor
00127   if( keepTrigPatt(PTMS[17],17,1,hl) ) return;   // 5368A --> 17 - 5L3R6L8L: nor
00128   if( keepTrigPatt(PTMS[18],18,1,hl) ) return;   // 5368B --> 18 - 5L3R6R8L: nor
00129   if( keepTrigPatt(PTMS[19],19,4,hl) ) return;   // 5368C --> 19 - 5L3R6R8R: L11
00130   if( keepTrigPatt(PTMS[20],20,1,hl) ) return;   // 5764A --> 20 - 5R7L6L4R: nor
00131   if( keepTrigPatt(PTMS[21],21,1,hl) ) return;   // 5764B --> 21 - 5R7L6R4R: nor
00132   if( keepTrigPatt(PTMS[22],22,7,hl) ) return;   // 5764C --> 22 - 5R7L6L4L: H11
00133   if( keepTrigPatt(PTMS[23],23,3,hl) ) return;   // 9764A --> 23 - 9L7L6L4R: 11L
00134   if( keepTrigPatt(PTMS[24],24,2,hl) ) return;   // 9764B --> 24 - 9L7L6R4R: 1L1
00135   if( keepTrigPatt(PTMS[25],25,4,hl) ) return;   // 9764C --> 25 - 9L7R6R4R: L11
00136   if( RON==1 ){
00137     if( keepTrigPatt(PTMS[26],26,1,hl) ) return;   // 1324A --> 26 - 1L3L2R4L: nor
00138   }
00139   if( keepTrigPatt(PTMS[27],27,2,hl) ) return;   // 1324B --> 27 - 1L3L2R4R: 1L1
00140   if( keepTrigPatt(PTMS[28],28,1,hl) ) return;   // 1324C --> 28 - 1R3L2R4L: nor
00141   if( keepTrigPatt(PTMS[29],29,1,hl) ) return;   // 1324D --> 29 - 1R3L2R4R: nor
00142   if( RON==1 ){
00143     if( keepTrigPatt(PTMS[30],30,1,hl) ) return;   // 9768A --> 30 - 9L7L6R8L: nor
00144   }
00145   if( keepTrigPatt(PTMS[31],31,1,hl) ) return;   // 9768B --> 31 - 9L7R6R8L: nor 
00146 
00147   }//end h/l loop
00148 
00149 */
00150   
00151 /* 
00152   // High level triggers:
00153   if( keepTrig( 1,accpatB,8) ) return;   // 5768B -->  1 - acc. patt. B
00154   if( keepTrig( 2,accpatA,8) ) return;   // 5768C -->  2 - acc. patt. A
00155   if( keepTrig( 3,accpatA,8) ) return;   // 5768D -->  3 - acc. patt. A
00156   if( keepTrig( 4,accpatB,8) ) return;   // 1364A -->  4 - acc. patt. B
00157   if( keepTrig( 5,accpatA,8) ) return;   // 1364B -->  5 - acc. patt. A
00158   if( keepTrig( 6,accpatA,8) ) return;   // 1364C -->  6 - acc. patt. A
00159   if( keepTrig( 7,accpatB,8) ) return;   // 1368A -->  7 - acc. patt. B
00160   if( keepTrig( 8,accpatB,8) ) return;   // 1368B -->  8 - acc. patt. B
00161   if( keepTrig( 9,accpatB,8) ) return;   // 1368C -->  9 - acc. patt. B
00162   if( keepTrig(10,accpatA,8) ) return;   // 5324A --> 10 - acc. patt. A
00163   if( keepTrig(11,accpatA,8) ) return;   // 5324B --> 11 - acc. patt. A
00164   if( keepTrig(12,accpatB,8) ) return;   // 5324C --> 12 - acc. patt. B
00165   if( keepTrig(13,accpatA,8) ) return;   // 5364A --> 13 - acc. patt. A
00166   if( keepTrig(14,accpatA,8) ) return;   // 5364B --> 14 - acc. patt. A
00167   if( keepTrig(15,accpatB,8) ) return;   // 5364C --> 15 - acc. patt. B
00168   if( keepTrig(16,accpatA,8) ) return;   // 5364D --> 16 - acc. patt. A
00169   if( keepTrig(17,accpatA,8) ) return;   // 5368A --> 17 - acc. patt. A
00170   if( keepTrig(18,accpatA,8) ) return;   // 5368B --> 18 - acc. patt. A
00171   if( keepTrig(19,accpatB,8) ) return;   // 5368C --> 19 - acc. patt. B
00172   if( keepTrig(20,accpatA,8) ) return;   // 5764A --> 20 - acc. patt. A
00173   if( keepTrig(21,accpatA,8) ) return;   // 5764B --> 21 - acc. patt. A
00174   if( keepTrig(22,accpatB,8) ) return;   // 5764C --> 22 - acc. patt. B
00175   if( keepTrig(23,accpatB,8) ) return;   // 9764A --> 23 - acc. patt. B
00176   if( keepTrig(24,accpatB,8) ) return;   // 9764B --> 24 - acc. patt. B
00177   if( keepTrig(25,accpatB,8) ) return;   // 9764C --> 25 - acc. patt. B
00178   if( keepTrig( 0,accpatA,8) ) return;   // 5768A -->  0 - acc. patt. A
00179   */ 
00180  /* 
00181   // Low level triggers -B
00182   if( keepTrig( 1,accpatB,2) ) return;   // 5768B -->  1 - acc. patt. B
00183   if( keepTrig( 2,accpatA,2) ) return;   // 5768C -->  2 - acc. patt. A
00184   if(tiKes==1) {
00185     if( keepTrig( 3,accpatA,2) ) return; // 5768D -->  3 - acc. patt. A
00186   }
00187   if( keepTrig( 4,accpatB,2) ) return;   // 1364A -->  4 - acc. patt. B
00188   if( keepTrig( 5,accpatA,2) ) return;   // 1364B -->  5 - acc. patt. A
00189   if( keepTrig( 6,accpatA,2) ) return;   // 1364C -->  6 - acc. patt. A
00190   if( keepTrig( 7,accpatB,2) ) return;   // 1368A -->  7 - acc. patt. B
00191   if( keepTrig( 8,accpatB,2) ) return;   // 1368B -->  8 - acc. patt. B
00192   if( keepTrig( 9,accpatB,2) ) return;   // 1368C -->  9 - acc. patt. B
00193   if( keepTrig(10,accpatA,2) ) return;   // 5324A --> 10 - acc. patt. A
00194   if( keepTrig(11,accpatA,2) ) return;   // 5324B --> 11 - acc. patt. A
00195   if( keepTrig(12,accpatB,2) ) return;   // 5324C --> 12 - acc. patt. B
00196   if(tiKes==1) {
00197     if( keepTrig(13,accpatA,2) ) return; // 5364A --> 13 - acc. patt. A
00198   }
00199   if( keepTrig(14,accpatA,2) ) return;   // 5364B --> 14 - acc. patt. A
00200   if( keepTrig(15,accpatB,2) ) return;   // 5364C --> 15 - acc. patt. B
00201   if( keepTrig(16,accpatA,2) ) return;   // 5364D --> 16 - acc. patt. A
00202   if(tiKes==1) {
00203     if( keepTrig(17,accpatA,2) ) return; // 5368A --> 17 - acc. patt. A
00204   }
00205   if( keepTrig(18,accpatA,2) ) return;   // 5368B --> 18 - acc. patt. A
00206   if( keepTrig(19,accpatB,2) ) return;   // 5368C --> 19 - acc. patt. B
00207   if( keepTrig(20,accpatA,2) ) return;   // 5764A --> 20 - acc. patt. A
00208   if(tiKes==1) {
00209     if( keepTrig(21,accpatA,2) ) return; // 5764B --> 21 - acc. patt. A
00210   }
00211   if( keepTrig(22,accpatB,2) ) return;   // 5764C --> 22 - acc. patt. B
00212   if( keepTrig(23,accpatB,2) ) return;   // 9764A --> 23 - acc. patt. B
00213   if( keepTrig(24,accpatB,2) ) return;   // 9764B --> 24 - acc. patt. B
00214   if( keepTrig(25,accpatB,2) ) return;   // 9764C --> 25 - acc. patt. B
00215   if( keepTrig( 0,accpatA,2) ) return;   // 5768A -->  0 - acc. patt. A
00216 
00217   // Low level triggers -C
00218   if( keepTrig( 1,accpatB,3) ) return;   // 5768B -->  1 - acc. patt. B
00219   if( keepTrig( 2,accpatA,3) ) return;   // 5768C -->  2 - acc. patt. A
00220   if( keepTrig( 3,accpatA,3) ) return;   // 5768D -->  3 - acc. patt. A
00221   if( keepTrig( 4,accpatB,3) ) return;   // 1364A -->  4 - acc. patt. B
00222   if( keepTrig( 5,accpatA,3) ) return;   // 1364B -->  5 - acc. patt. A
00223   if(tiKes==1) {
00224     if( keepTrig( 6,accpatA,3) ) return; // 1364C -->  6 - acc. patt. A
00225   }
00226   if( keepTrig( 7,accpatB,3) ) return;   // 1368A -->  7 - acc. patt. B
00227   if( keepTrig( 8,accpatB,3) ) return;   // 1368B -->  8 - acc. patt. B
00228   if( keepTrig( 9,accpatB,3) ) return;   // 1368C -->  9 - acc. patt. B
00229   if(tiKes==1) {
00230     if( keepTrig(10,accpatA,3) ) return; // 5324A --> 10 - acc. patt. A
00231   }
00232   if( keepTrig(11,accpatA,3) ) return;   // 5324B --> 11 - acc. patt. A
00233   if( keepTrig(12,accpatB,3) ) return;   // 5324C --> 12 - acc. patt. B
00234   if( keepTrig(13,accpatA,3) ) return;   // 5364A --> 13 - acc. patt. A
00235   if( keepTrig(14,accpatA,3) ) return;   // 5364B --> 14 - acc. patt. A
00236   if( keepTrig(15,accpatB,3) ) return;   // 5364C --> 15 - acc. patt. B
00237   if(tiKes==1) {
00238     if( keepTrig(16,accpatA,3) ) return; // 5364D --> 16 - acc. patt. A
00239   }
00240   if( keepTrig(17,accpatA,3) ) return;   // 5368A --> 17 - acc. patt. A
00241   if( keepTrig(18,accpatA,3) ) return;   // 5368B --> 18 - acc. patt. A
00242   if( keepTrig(19,accpatB,3) ) return;   // 5368C --> 19 - acc. patt. B
00243   if( keepTrig(20,accpatA,3) ) return;   // 5764A --> 20 - acc. patt. A
00244   if( keepTrig(21,accpatA,3) ) return;   // 5764B --> 21 - acc. patt. A
00245   if( keepTrig(22,accpatB,3) ) return;   // 5764C --> 22 - acc. patt. B
00246   if( keepTrig(23,accpatB,3) ) return;   // 9764A --> 23 - acc. patt. B
00247   if( keepTrig(24,accpatB,3) ) return;   // 9764B --> 24 - acc. patt. B
00248   if( keepTrig(25,accpatB,3) ) return;   // 9764C --> 25 - acc. patt. B
00249   if(tiKes==1) {
00250     if( keepTrig( 0,accpatA,3) ) return; // 5768A -->  0 - acc. patt. A
00251   }
00252 
00253   // Low level triggers -A
00254   if( keepTrig( 1,accpatB,1) ) return;   // 5768B -->  1 - acc. patt. B
00255   if( keepTrig( 2,accpatA,1) ) return;   // 5768C -->  2 - acc. patt. A
00256   if( keepTrig( 3,accpatA,1) ) return;   // 5768D -->  3 - acc. patt. A
00257   if( keepTrig( 4,accpatB,1) ) return;   // 1364A -->  4 - acc. patt. B
00258   if( keepTrig( 5,accpatA,1) ) return;   // 1364B -->  5 - acc. patt. A
00259   if( keepTrig( 6,accpatA,1) ) return;   // 1364C -->  6 - acc. patt. A
00260   if( keepTrig( 7,accpatB,1) ) return;   // 1368A -->  7 - acc. patt. B
00261   if( keepTrig( 8,accpatB,1) ) return;   // 1368B -->  8 - acc. patt. B
00262   if(tiKes==1) {
00263     if( keepTrig( 9,accpatB,1) ) return; // 1368C -->  9 - acc. patt. B
00264   }
00265   if( keepTrig(10,accpatA,1) ) return;   // 5324A --> 10 - acc. patt. A
00266   if( keepTrig(11,accpatA,1) ) return;   // 5324B --> 11 - acc. patt. A
00267   if( keepTrig(12,accpatB,1) ) return;   // 5324C --> 12 - acc. patt. B
00268   if( keepTrig(13,accpatA,1) ) return;   // 5364A --> 13 - acc. patt. A
00269   if( keepTrig(14,accpatA,1) ) return;   // 5364B --> 14 - acc. patt. A
00270   if( keepTrig(15,accpatB,1) ) return;   // 5364C --> 15 - acc. patt. B
00271   if( keepTrig(16,accpatA,1) ) return;   // 5364D --> 16 - acc. patt. A
00272   if( keepTrig(17,accpatA,1) ) return;   // 5368A --> 17 - acc. patt. A
00273   if( keepTrig(18,accpatA,1) ) return;   // 5368B --> 18 - acc. patt. A
00274   if(tiKes==1) {
00275     if( keepTrig(19,accpatB,1) ) return; // 5368C --> 19 - acc. patt. B
00276   }
00277   if( keepTrig(20,accpatA,1) ) return;   // 5764A --> 20 - acc. patt. A
00278   if( keepTrig(21,accpatA,1) ) return;   // 5764B --> 21 - acc. patt. A
00279   if(tiKes==1) {
00280     if( keepTrig(22,accpatB,1) ) return; // 5764C --> 22 - acc. patt. B
00281   }
00282   if( keepTrig(23,accpatB,1) ) return;   // 9764A --> 23 - acc. patt. B
00283   if( keepTrig(24,accpatB,1) ) return;   // 9764B --> 24 - acc. patt. B
00284   if(tiKes==1) {
00285     if( keepTrig(25,accpatB,1) ) return; // 9764C --> 25 - acc. patt. B
00286   }
00287   if( keepTrig( 0,accpatA,1) ) return;   // 5768A -->  0 - acc. patt. A
00288 
00289   // Low level triggers -D
00290   if( keepTrig( 0,accpatA,4) ) return;   // 5768A -->  0 - acc. patt. A
00291   if( keepTrig( 1,accpatB,4) ) return;   // 5768B -->  1 - acc. patt. B
00292   if( keepTrig( 2,accpatA,4) ) return;   // 5768C -->  2 - acc. patt. A
00293   if( keepTrig( 3,accpatA,4) ) return;   // 5768D -->  3 - acc. patt. A
00294   if(tiKes==1) {
00295     if( keepTrig( 4,accpatB,4) ) return; // 1364A -->  4 - acc. patt. B
00296   }
00297   if( keepTrig( 5,accpatA,4) ) return;   // 1364B -->  5 - acc. patt. A
00298   if( keepTrig( 6,accpatA,4) ) return;   // 1364C -->  6 - acc. patt. A
00299   if( keepTrig( 7,accpatB,4) ) return;   // 1368A -->  7 - acc. patt. B
00300   if(tiKes==1) {
00301     if( keepTrig( 8,accpatB,4) ) return; // 1368B -->  8 - acc. patt. B
00302   }
00303   if( keepTrig( 9,accpatB,4) ) return;   // 1368C -->  9 - acc. patt. B
00304   if( keepTrig(10,accpatA,4) ) return;   // 5324A --> 10 - acc. patt. A
00305   if( keepTrig(11,accpatA,4) ) return;   // 5324B --> 11 - acc. patt. A
00306   if(tiKes==1) {
00307     if( keepTrig(12,accpatB,4) ) return; // 5324C --> 12 - acc. patt. B
00308   }
00309   if( keepTrig(13,accpatA,4) ) return;   // 5364A --> 13 - acc. patt. A
00310   if( keepTrig(14,accpatA,4) ) return;   // 5364B --> 14 - acc. patt. A
00311   if( keepTrig(15,accpatB,4) ) return;   // 5364C --> 15 - acc. patt. B
00312   if( keepTrig(16,accpatA,4) ) return;   // 5364D --> 16 - acc. patt. A
00313   if( keepTrig(17,accpatA,4) ) return;   // 5368A --> 17 - acc. patt. A
00314   if( keepTrig(18,accpatA,4) ) return;   // 5368B --> 18 - acc. patt. A
00315   if( keepTrig(19,accpatB,4) ) return;   // 5368C --> 19 - acc. patt. B
00316   if( keepTrig(20,accpatA,4) ) return;   // 5764A --> 20 - acc. patt. A
00317   if( keepTrig(21,accpatA,4) ) return;   // 5764B --> 21 - acc. patt. A
00318   if( keepTrig(22,accpatB,4) ) return;   // 5764C --> 22 - acc. patt. B
00319   if(tiKes==1) {
00320     if( keepTrig(23,accpatB,4) ) return; // 9764A --> 23 - acc. patt. B
00321   }
00322   if( keepTrig(24,accpatB,4) ) return;   // 9764B --> 24 - acc. patt. B
00323   if( keepTrig(25,accpatB,4) ) return;   // 9764C --> 25 - acc. patt. B
00324 */
00325 }
00326 
00327 int DTBtiChip::keepTrigPatt(const int flag,const int eq,const int pattType, int hlflag) {
00328   //if pattern is not enabled, return
00329   if(flag==0)
00330     return  0;
00331 
00332   int AC1 = config()->AccPattAC1(); //default 0
00333   int AC2 = config()->AccPattAC2(); //default 3
00334   int ACH = config()->AccPattACH(); //default 1
00335   int ACL = config()->AccPattACL(); //default 2
00336   int tiKes = config()->XON();
00337 
00338   if(config()->debug()>4){
00339     cout << "DTBtiChip::keepTrigPatt called with arguments: ";
00340     cout << eq << ", " << pattType << ", " << hlflag << endl; 
00341     cout<<"AC1,AC2,ACH,ACL="<<AC1<<" "<<AC2<<" "<<ACH<<" "<<ACL<<endl;
00342   }
00343 
00344   BitArray<80> val0, val1, val2, val3, val4, val5;
00345   int mm[6];
00346 
00347   //NB _Keq = (Kman - K0)/2   where K0=tmax*2  --->OBSOLETE, now Keq=Kman
00348   //int K0 = 2 * (config()->ST()/2.); 
00349   int K0 = int (config()->ST());
00350 
00351   int i=0;
00352   float Keqfloat[6] = {0,0,0,0,0,0};
00353   for(i=0;i<6;i++){
00354     mm[i] = -1;
00355     int mk = (int)(_Keq[eq][i] - K0);
00356     //if(abs(mk) > config()->KCut(_id.superlayer()-1))continue;
00357     if(abs(mk) > 2*K0)  continue;
00358     Keqfloat[i]=_Keq[eq][i];
00359     mm[i]=(int)(_Keq[eq][i]);
00360     //    if(_Keq[eq][i]<0){
00361     //      mm[i]=_Keq[eq][i]*2-0.5+KCen;
00362     //    } else {
00363     //      mm[i]=_Keq[eq][i]*2+KCen;
00364     //    }
00365   }
00366 
00367   switch(pattType)
00368     {
00369       case 1: //normal pattern
00370         //if(hlflag==1 && (eq!=2 && eq!=14 && eq!=28) ){  //test for L
00371 /*      if(hlflag==1){  //test for L
00372           acceptMask(&val0,mm[0],AC1); //eqAB
00373           acceptMask(&val1,mm[1],AC1); //eqBC
00374           acceptMask(&val2,mm[2],AC1); //eqCD
00375         }
00376         else
00377 */
00378         {
00379           acceptMask(&val0,mm[0],AC2); //eqAB
00380           acceptMask(&val1,mm[1],AC2); //eqBC
00381           acceptMask(&val2,mm[2],AC2); //eqCD
00382         }
00383         break;
00384 
00385       case 2: //1L1 pattern
00386         acceptMask(&val0,mm[0],AC1); //eqAB
00387         acceptMask(&val1,mm[1],ACL); //eqBC
00388         acceptMask(&val2,mm[2],AC1); //eqCD
00389         break;
00390 
00391       case 3: //11L pattern
00392         acceptMask(&val0,mm[0],AC1); //eqAB
00393         acceptMask(&val1,mm[1],AC1); //eqBC
00394         acceptMask(&val2,mm[2],ACL); //eqCD
00395         break;
00396 
00397       case 4: //L11 pattern
00398         acceptMask(&val0,mm[0],ACL); //eqAB
00399         acceptMask(&val1,mm[1],AC1); //eqBC
00400         acceptMask(&val2,mm[2],AC1); //eqCD
00401         break;
00402 
00403       case 5: //1H1 pattern
00404         acceptMask(&val0,mm[0],AC1); //eqAB
00405         acceptMask(&val1,mm[1],ACH); //eqBC
00406         acceptMask(&val2,mm[2],AC1); //eqCD
00407         break;
00408 
00409       case 6: //11H pattern
00410         acceptMask(&val0,mm[0],AC1); //eqAB
00411         acceptMask(&val1,mm[1],AC1); //eqBC
00412         acceptMask(&val2,mm[2],ACH); //eqCD
00413         break;
00414 
00415       case 7: //H11 pattern
00416         acceptMask(&val0,mm[0],ACH); //eqAB
00417         acceptMask(&val1,mm[1],AC1); //eqBC
00418         acceptMask(&val2,mm[2],AC1); //eqCD
00419         break;
00420  
00421       default:
00422         acceptMask(&val0,mm[0],AC2); //eqAB
00423         acceptMask(&val1,mm[1],AC2); //eqBC
00424         acceptMask(&val2,mm[2],AC2); //eqCD
00425         break;
00426     }   
00427 
00428   //eq. AC and BD acceptance are always +-1 ->code 00
00429   int acc = 0;
00430   acceptMask(&val3,mm[3],acc); //eq.AC
00431   acceptMask(&val4,mm[4],acc); //eq.BD
00432 
00433   //eq. AD is the reference value!
00434   if(mm[5]>0){
00435     val5.set(mm[5]);
00436   }
00437 
00438   // debugging: print() method prints from last to first bit!
00439   if(config()->debug()>4){
00440     cout << " dump of val arrays: " << endl;
00441     //    cout << val0.to_string() << endl;
00442     //    cout << val1.to_string() << endl;
00443     //    cout << val2.to_string() << endl;
00444     //    cout << val3.to_string() << endl;
00445     //    cout << val4.to_string() << endl;
00446     //    cout << val5.to_string() << endl;
00447     val0.print(); 
00448     cout << endl;
00449     val1.print();
00450     cout << endl;
00451     val2.print();
00452     cout << endl;
00453     val3.print();
00454     cout << endl;
00455     val4.print();
00456     cout << endl;
00457     val5.print();
00458     cout << endl;
00459    }
00460   // end debugging
00461 
00462   //search for High trigger:
00463   if(hlflag==0){
00464     int code = 0;
00465     int KMax = 0;
00466     int LKMax = -1;
00467     for(i=0;i<80;i++){
00468       int val = val0.element(i)+val1.element(i)+val2.element(i)+
00469                 val3.element(i)+val4.element(i)+val5.element(i);
00470       if(val>KMax) {
00471         KMax=val;
00472         LKMax=i;
00473       }
00474     }
00475   
00476     //SV: K value is stored in 6 bits, so K=64->0, etc
00477     if(LKMax>63)
00478       LKMax-=64;
00479 
00480     if(KMax==6) {
00481       code=8;
00482       int X;
00483       if( eq==0 )  //store Xbc only for patt 0, else store Xad
00484         X=int(_Xeq[eq][0]);
00485       else
00486         X=int(_Xeq[eq][1]);
00487       store(eq,code,LKMax,X,Keqfloat[0],Keqfloat[1],
00488            Keqfloat[2],Keqfloat[3],Keqfloat[4],Keqfloat[5]);
00489       return 1;
00490     }
00491     return 0;
00492   } //end H 
00493 
00494   //search for Low triggers:
00495   if(hlflag==1){
00496     int code = 0;
00497     int RON = config()->RONflag();
00498 
00499 
00500     //hit in B is missing
00501     if(config()->debug()>4)
00502       cout << "SelTrig: searching low-B" << endl;
00503     int LKMax = -1;
00504     for(i=0;i<80;i++){
00505       int val = val2.element(i)+val3.element(i)+val5.element(i);
00506       if(val==3){ //Ref. is eqAD
00507         code=2;
00508         LKMax=i;
00509         int storefg = 1; 
00510 
00511         //SV - XON time-ind.Keq suppr. XON=0 do not abilitate patterns 
00512         if(tiKes==0) {
00513           if(eq==3 || eq==13 || eq==17 || eq==21 || eq==29){  
00514             if(config()->debug()>3)
00515               cout << "SelTrig: doing XON suppression!"<<endl;
00516             storefg = 0;
00517           }
00518         }
00519 
00520         //SV - RON suppression for low triggers
00521         if( RON==0 ){
00522           if( eq==19 ){
00523             if(config()->debug()>3)
00524               cout << "SelTrig: doing RON low triggers suppression!"<<endl;
00525             storefg = 0;
00526           }
00527         }
00528 
00529         if(storefg){ 
00530           //SV: K value is stored in 6 bits, so K=64->0, etc
00531           if(LKMax>63)
00532             LKMax-=64;
00533           int X;
00534           if( eq==0 )
00535             X=int(_Xeq[eq][0]);
00536           else
00537             X=int(_Xeq[eq][1]);
00538           store(eq,code,LKMax,X,Keqfloat[0],Keqfloat[1],
00539            Keqfloat[2],Keqfloat[3],Keqfloat[4],Keqfloat[5]);
00540           return 1;
00541         }  
00542       }
00543     } //end -B Low
00544 
00545     //hit in C is missing
00546     if(config()->debug()>3)
00547       cout << "SelTrig: searching low-C" << endl;
00548      for(i=0;i<80;i++){
00549       int val = val0.element(i)+val4.element(i)+val5.element(i);
00550       if(val==3){ //Ref. is eqAD
00551         code=3;
00552         LKMax=i;
00553         int storefg = 1;
00554  
00555         //SV - XON time-ind.Keq suppr.
00556         if(tiKes==0) {
00557           if(eq==0 || eq==6 || eq==10 || eq==16 || eq==26 || eq==30){  
00558             if(config()->debug()>3)
00559               cout << "SelTrig: doing XON suppression!"<<endl;
00560             storefg = 0;
00561           }
00562         }
00563 
00564         if(storefg){
00565           //SV: K value is stored in 6 bits, so K=64->0, etc
00566           if(LKMax>63)
00567             LKMax-=64;
00568 
00569           int X;
00570           if( eq==0 )
00571             X=int(_Xeq[eq][0]);
00572           else
00573             X=int(_Xeq[eq][1]);
00574           store(eq,code,LKMax,X,Keqfloat[0],Keqfloat[1],
00575            Keqfloat[2],Keqfloat[3],Keqfloat[4],Keqfloat[5]);
00576           return 1;
00577         }
00578       }
00579     } // end -C Low
00580 
00581     //for -A and -D low acceptance is +-1
00582 //    if(pattType==1){
00583       val0.reset();
00584       val1.reset();
00585       val2.reset();
00586       acceptMask(&val0,mm[0],AC1); //eqAB
00587       acceptMask(&val1,mm[1],AC1); //eqBC
00588       acceptMask(&val2,mm[2],AC1); //eqCD
00589 //    }
00590 
00591     //hit in A is missing
00592     if(config()->debug()>4)
00593       cout << "SelTrig: searching low-A" << endl;
00594     for(i=0;i<80;i++){
00595       int val = val1.element(i)+val2.element(i)+val4.element(i);
00596       if(val==3 && i==mm[4]){ //Ref. is eqBD
00597         code=1;
00598         LKMax=i;
00599         int storefg = 1;
00600 
00601         //SV - XON time-ind.Keq suppr.
00602         if(tiKes==0) {
00603           if(eq==9 || eq==19 || eq==22 || eq==25 ){  
00604             if(config()->debug()>3)
00605               cout << "SelTrig: doing low-A XON suppression!"<<endl;
00606           storefg = 0;
00607           }
00608         }
00609 
00610         if( RON==0 ){ //SV - RON suppression
00611           if( eq==26 ){
00612             if(config()->debug()>3)
00613               cout << "SelTrig: doing RON low triggers suppression!"<<endl;
00614             storefg = 0;
00615           }
00616         }
00617 
00618         if(storefg){
00619           //SV: K value is stored in 6 bits, so K=64->0, etc
00620           if(LKMax>63)
00621             LKMax-=64;
00622 
00623           store(eq,code,LKMax,int(_Xeq[eq][0]),Keqfloat[0],Keqfloat[1],
00624            Keqfloat[2],Keqfloat[3],Keqfloat[4],Keqfloat[5]);
00625           return 1;
00626         }
00627       }
00628     } //end -A Low
00629  
00630 
00631     //hit in D is missing
00632     if(config()->debug()>4)
00633       cout << "SelTrig: searching low-D" << endl;
00634     for(i=0;i<80;i++){
00635       int val = val0.element(i)+val1.element(i)+val3.element(i);
00636       if(val==3 && i==mm[3]){ //Ref. is eqAC
00637         code=4;
00638         LKMax=i;
00639         int storefg = 1;
00640 
00641         //SV - XON time-ind.Keq suppr.
00642         if(tiKes==0){
00643           if(eq==4 || eq==8 || eq==12 || eq==23){  
00644             if(config()->debug()>3)
00645               cout << "SelTrig: doing XON suppression!"<<endl;
00646             storefg = 0;
00647           }
00648         }
00649 
00650         //SV - RON suppression for low triggers
00651         if( RON==0 ){
00652           if(eq==1 || eq==2 || eq==3 || eq==24 || eq==25){
00653             if(config()->debug()>3)
00654               cout << "SelTrig: doing RON low triggers suppression!"<<endl;
00655             storefg = 0;
00656           }
00657         }
00658 
00659         if(storefg){ // && _Xeq[eq][1] >=0){
00660           //SV: K value is stored in 6 bits, so K=64->0, etc
00661           if(LKMax>63)
00662             LKMax-=64;
00663 
00664           store(eq,code,LKMax,int(_Xeq[eq][0]),Keqfloat[0],Keqfloat[1],
00665            Keqfloat[2],Keqfloat[3],Keqfloat[4],Keqfloat[5]);
00666           return 1;
00667         }
00668       }
00669     } //end -D Low
00670  
00671     return 0; 
00672   } //end Low
00673   return 0;
00674 }
00675 
00676   
00677 void 
00678 DTBtiChip::acceptMask(BitArray<80> * BitArrPtr,int k,int accep)
00679 {
00680    if(k>=0&&k<78){
00681      if(config()->debug()>4)
00682        cout<<"DTBtiChip::acceptMask ->  Setting acceptance for k="<<k<<endl;
00683 
00684      if(accep==0){ //code 00
00685        if(k>=1) 
00686          BitArrPtr->set(k-1);
00687        BitArrPtr->set(k);
00688        BitArrPtr->set(k+1);
00689      }
00690      if(accep==1){ //code 01
00691        BitArrPtr->set(k);
00692        BitArrPtr->set(k+1);
00693        BitArrPtr->set(k+2);
00694      }
00695      if(accep==2){ //code 10
00696        if(k>1)
00697          BitArrPtr->set(k-2);
00698        if(k>=1)
00699          BitArrPtr->set(k-1);
00700        BitArrPtr->set(k);
00701      }
00702      if(accep==3){ //code 11
00703        if(k>1)
00704          BitArrPtr->set(k-2);
00705        if(k>=1)
00706          BitArrPtr->set(k-1);
00707        BitArrPtr->set(k);
00708        BitArrPtr->set(k+1);
00709        BitArrPtr->set(k+2);
00710      }
00711    }
00712 
00713 
00714   if(config()->debug()>4)
00715     cout<<"DTBtiChip::acceptMask ->  END "<<endl;
00716 
00717 }
00718 
00719 
00720 
00721 int 
00722 DTBtiChip::keepTrig(const int eq, const int acp, const int code) {
00723 
00724   if(config()->debug()>4){
00725     cout << "DTBtiChip::keepTrig called with arguments: ";
00726     cout << eq << ", " << acp << ", " << code << endl; 
00727   }
00728 
00729   int const KCen = 40; // Arrays will start from 0 --> use 40 instead of 41
00730   BitArray<80> val0, val1, val2, val3, val4, val5;
00731   int mm[6];
00732 
00733   int i=0;
00734   for(i=0;i<6;i++){
00735     mm[i]=0;
00736     int mk = (int)(2*_Keq[eq][i]);
00737     if(abs(mk) > config()->KCut() )
00738         continue;
00739     mm[i]=(int)(_Keq[eq][i]*2)+KCen;
00740     //    if(_Keq[eq][i]<0){
00741     //      mm[i]=_Keq[eq][i]*2-0.5+KCen;
00742     //    } else {
00743     //      mm[i]=_Keq[eq][i]*2+KCen;
00744     //    }
00745   }
00746 
00747   if(mm[0]>0 && (code==8 || code==3 || code==4) ){
00748     val0.set(mm[0]-1);
00749     val0.set(mm[0]);
00750     val0.set(mm[0]+1);
00751     if(acp==2 && (code==8 || code==3) ) {
00752       val0.set(mm[0]-2);
00753       val0.set(mm[0]+2);
00754     }
00755   }
00756 
00757   if(mm[1]>0 && (code==8 || code==1 || code==4) ){
00758     val1.set(mm[1]-1);
00759     val1.set(mm[1]);
00760     val1.set(mm[1]+1);
00761     if(acp==2 && code==8 ) {
00762       val1.set(mm[1]-2);
00763       val1.set(mm[1]+2);
00764     }
00765   }
00766 
00767   if(mm[2]>0 && (code==8 || code==1 || code==2) ){
00768     val2.set(mm[2]-1);
00769     val2.set(mm[2]);
00770     val2.set(mm[2]+1);
00771     if(acp==2 && (code==8 || code==2) ) {
00772       val2.set(mm[2]-2);
00773       val2.set(mm[2]+2);
00774     }
00775   }
00776 
00777   if(mm[3]>0 && (code==8 || code==2 || code==4) ){
00778     val3.set(mm[3]-1);
00779     val3.set(mm[3]);
00780     val3.set(mm[3]+1);
00781   }
00782 
00783   if(mm[4]>0 && (code==8 || code==1 || code==3) ){
00784     val4.set(mm[4]-1);
00785     val4.set(mm[4]);
00786     val4.set(mm[4]+1);
00787   }
00788 
00789   if(mm[5]>0 && (code==8 || code==2 || code==3) ){
00790     val5.set(mm[5]);
00791   }
00792 
00793   // debugging
00794   if(config()->debug()>4){
00795     cout << " dump of val arrays: " << endl;
00796     //    cout << val0.to_string() << endl;
00797     //    cout << val1.to_string() << endl;
00798     //    cout << val2.to_string() << endl;
00799     //    cout << val3.to_string() << endl;
00800     //    cout << val4.to_string() << endl;
00801     //    cout << val5.to_string() << endl;
00802     val0.print();
00803     cout << endl;
00804     val1.print();
00805     cout << endl;
00806     val2.print();
00807     cout << endl;
00808     val3.print();
00809     cout << endl;
00810     val4.print();
00811     cout << endl;
00812     val5.print();
00813     cout << endl;
00814   }
00815   // end debugging
00816 
00817   int KMax = 0;
00818   int LKMax = -1;
00819   for(i=0;i<80;i++){
00820     int val = val0.element(i)+val1.element(i)+val2.element(i)+
00821               val3.element(i)+val4.element(i)+val5.element(i);
00822     //    int val = val0.test(i)+val1.test(i)+val2.test(i)+
00823     //              val3.test(i)+val4.test(i)+val5.test(i);
00824     if(val>KMax) {
00825       KMax=val;
00826       LKMax=i;
00827     }
00828   }
00829   
00830   // Note that all bits in val are shifted by one w.r.t. FORTRAN version
00831   // The output K will be the same because of the different value of Kcen
00832 
00833   if        (KMax==6 && code==8) {
00834     store(eq,8,LKMax-KCen,int(_Xeq[eq][1]));
00835     return 1;
00836   } else if (KMax==3 && code!=8) {
00837     if(code==1 || code==4) {
00838       store(eq,code,LKMax-KCen,int(_Xeq[eq][0]));
00839     } else {
00840       store(eq,code,LKMax-KCen,int(_Xeq[eq][1]));
00841     }
00842     return 1;
00843   }
00844   return 0; 
00845   // return value is ITFL of FORTRAN version
00846 }