Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:40

0001 //-----------------------------------------------------------------
0002 //
0003 //   Class: DTBtiChip
0004 //
0005 //   Description: Implementation of DTBtiChip
0006 //                trigger algorithm
0007 //                (Trigger selection implementation)
0008 //
0009 //
0010 //   Author List:
0011 //   C. Grandi
0012 //   Modifications:
0013 //   23/X/02 Sara Vanini : asymmetric acceptance added for H trig
0014 //   07/I/03 SV: sort patterns for equivalence with bti manual
0015 //   13/I/03 SV: fixed for Keq in manual form
0016 //   30/IX/03 SV: redundancies for xA xB xC xD low trigs included
0017 //   22/VI/04 SV: last trigger code update
0018 //----------------------------------------------------------------
0019 
0020 //-----------------------
0021 // This Class's Header --
0022 //-----------------------
0023 #include "L1Trigger/DTBti/interface/DTBtiChip.h"
0024 
0025 //-------------------------------
0026 // Collaborating Class Headers --
0027 //-------------------------------
0028 #include "L1TriggerConfig/DTTPGConfig/interface/BitArray.h"
0029 
0030 //---------------
0031 // C++ Headers --
0032 //---------------
0033 #include <iostream>
0034 #include <cmath>
0035 #include <iomanip>
0036 
0037 using namespace std;
0038 
0039 void DTBtiChip::findTrig() {
0040   if (config()->debug() > 3) {
0041     cout << "DTBtiChip::findTrig called" << endl;
0042   }
0043 
0044   //pattern type:       1 = normal
0045   //            2 = 1L1
0046   //            3 = 11L
0047   //            4 = L11
0048   //            5 = 1H1
0049   //            6 = 11H
0050   //            7 = H11
0051 
0052   //  int accpatB = config()->AccPattB(); //default +-1
0053   //  int accpatA = config()->AccPattA(); //default +-2
0054   //  int tiKes = config()->XON();
0055   int RON = config()->RONflag();  //default 1, redundant patterns enabled
0056   int PTMS[32];
0057   for (int i = 0; i < 32; i++) {
0058     PTMS[i] = config()->PTMSflag(i);
0059   }
0060 
0061   //Triggers (same order as manual):
0062   for (int hl = 0; hl < 2; hl++) {  //hl=0 high   hl=1 low
0063     if (RON == 1) {
0064       if (keepTrigPatt(PTMS[0], 0, 1, hl))
0065         return;  // 1324A --> 0 - 1L3L2R4L: nor
0066     }
0067     if (keepTrigPatt(PTMS[1], 1, 2, hl))
0068       return;  // 1324B --> 1 - 1L3L2R4R: 1L1
0069     if (keepTrigPatt(PTMS[2], 2, 1, hl))
0070       return;  // 1324C --> 2 - 1R3L2R4L: nor
0071     if (keepTrigPatt(PTMS[3], 3, 1, hl))
0072       return;  // 1324D --> 3 - 1R3L2R4R: nor
0073     if (keepTrigPatt(PTMS[4], 4, 3, hl))
0074       return;  // 1364A -->  4 - 1L3L6L4R: 11L
0075     if (keepTrigPatt(PTMS[5], 5, 1, hl))
0076       return;  // 1364B -->  5 - 1R3L6L4R: nor
0077     if (keepTrigPatt(PTMS[6], 6, 1, hl))
0078       return;  // 1364C -->  6 - 1R3R6L4R: nor
0079     if (keepTrigPatt(PTMS[7], 7, 5, hl))
0080       return;  // 1368A -->  7 - 1R3R6L8L: 1H1
0081     if (keepTrigPatt(PTMS[8], 8, 6, hl))
0082       return;  // 1368B -->  8 - 1R3R6R8L: 11H
0083     if (keepTrigPatt(PTMS[9], 9, 7, hl))
0084       return;  // 1368C -->  9 - 1R3L6L8L: H11
0085     if (keepTrigPatt(PTMS[10], 10, 1, hl))
0086       return;  // 5324A --> 10 - 5L3L2R4L: nor
0087     if (keepTrigPatt(PTMS[11], 11, 1, hl))
0088       return;  // 5324B --> 11 - 5L3R2R4L: nor
0089     if (keepTrigPatt(PTMS[12], 12, 6, hl))
0090       return;  // 5324C --> 12 - 5R3R2R4L: 11H
0091     if (keepTrigPatt(PTMS[13], 13, 1, hl))
0092       return;  // 5364A --> 13 - 5L3R6L4L: nor
0093     if (keepTrigPatt(PTMS[14], 14, 1, hl))
0094       return;  // 5364B --> 14 - 5L3R6L4R: nor
0095     if (keepTrigPatt(PTMS[15], 15, 5, hl))
0096       return;  // 5364C --> 15 - 5R3R6L4L: 1H1
0097     if (keepTrigPatt(PTMS[16], 16, 1, hl))
0098       return;  // 5364D --> 16 - 5R3R6L4R: nor
0099     if (keepTrigPatt(PTMS[17], 17, 1, hl))
0100       return;  // 5368A --> 17 - 5L3R6L8L: nor
0101     if (keepTrigPatt(PTMS[18], 18, 1, hl))
0102       return;  // 5368B --> 18 - 5L3R6R8L: nor
0103     if (keepTrigPatt(PTMS[19], 19, 4, hl))
0104       return;  // 5368C --> 19 - 5L3R6R8R: L11
0105     if (keepTrigPatt(PTMS[20], 20, 1, hl))
0106       return;  // 5764A --> 20 - 5R7L6L4R: nor
0107     if (keepTrigPatt(PTMS[21], 21, 1, hl))
0108       return;  // 5764B --> 21 - 5R7L6R4R: nor
0109     if (keepTrigPatt(PTMS[22], 22, 7, hl))
0110       return;  // 5764C --> 22 - 5R7L6L4L: H11
0111     if (keepTrigPatt(PTMS[23], 23, 3, hl))
0112       return;  // 9764A --> 23 - 9L7L6L4R: 11L
0113     if (keepTrigPatt(PTMS[24], 24, 2, hl))
0114       return;  // 9764B --> 24 - 9L7L6R4R: 1L1
0115     if (keepTrigPatt(PTMS[25], 25, 4, hl))
0116       return;  // 9764C --> 25 - 9L7R6R4R: L11
0117     if (keepTrigPatt(PTMS[26], 26, 1, hl))
0118       return;  // 5768A -->  26 - 5L7L6R8L: nor
0119     if (RON == 1) {
0120       if (keepTrigPatt(PTMS[27], 27, 2, hl))
0121         return;  // 5768B --> 27 - 5L7L6R8R: 1L1
0122       if (keepTrigPatt(PTMS[28], 28, 1, hl))
0123         return;  // 5768C --> 28 - 5R7L6R8L: nor
0124       if (keepTrigPatt(PTMS[29], 29, 1, hl))
0125         return;  // 5768D --> 29 - 5R7L6R8R: nor
0126       if (keepTrigPatt(PTMS[30], 30, 1, hl))
0127         return;  // 9768A --> 30 - 9L7L6R8L: nor
0128       if (keepTrigPatt(PTMS[31], 31, 1, hl))
0129         return;  // 9768B --> 31 - 9L7R6R8L: nor
0130     }
0131 
0132   }  //end h/l loop
0133 
0134   /*
0135   for(int hl=0;hl<2;hl++){  //hl=0 high   hl=1 low
0136   if( keepTrigPatt(PTMS[0],0,1,hl) ) return;   // 5768A -->  0 - 5L7L6R8L: nor   
0137   if( RON==1 ){
0138     if( keepTrigPatt(PTMS[1],1,2,hl) ) return;   // 5768B -->  1 - 5L7L6R8R: 1L1
0139     if( keepTrigPatt(PTMS[2],2,1,hl) ) return;   // 5768C -->  2 - 5R7L6R8L: nor
0140     if( keepTrigPatt(PTMS[3],3,1,hl) ) return;   // 5768D -->  3 - 5R7L6R8R: nor
0141   }
0142   if( keepTrigPatt(PTMS[4],4,3,hl) ) return;   // 1364A -->  4 - 1L3L6L4R: 11L
0143   if( keepTrigPatt(PTMS[5],5,1,hl) ) return;   // 1364B -->  5 - 1R3L6L4R: nor
0144   if( keepTrigPatt(PTMS[6],6,1,hl) ) return;   // 1364C -->  6 - 1R3R6L4R: nor
0145   if( keepTrigPatt(PTMS[7],7,5,hl) ) return;   // 1368A -->  7 - 1R3R6L8L: 1H1
0146   if( keepTrigPatt(PTMS[8],8,6,hl) ) return;   // 1368B -->  8 - 1R3R6R8L: 11H
0147   if( keepTrigPatt(PTMS[9],9,7,hl) ) return;   // 1368C -->  9 - 1R3L6L8L: H11
0148   if( keepTrigPatt(PTMS[10],10,1,hl) ) return;   // 5324A --> 10 - 5L3L2R4L: nor
0149   if( keepTrigPatt(PTMS[11],11,1,hl) ) return;   // 5324B --> 11 - 5L3R2R4L: nor
0150   if( keepTrigPatt(PTMS[12],12,6,hl) ) return;   // 5324C --> 12 - 5R3R2R4L: 11H
0151   if( keepTrigPatt(PTMS[13],13,1,hl) ) return;   // 5364A --> 13 - 5L3R6L4L: nor
0152   if( keepTrigPatt(PTMS[14],14,1,hl) ) return;   // 5364B --> 14 - 5L3R6L4R: nor
0153   if( keepTrigPatt(PTMS[15],15,5,hl) ) return;   // 5364C --> 15 - 5R3R6L4L: 1H1
0154   if( keepTrigPatt(PTMS[16],16,1,hl) ) return;   // 5364D --> 16 - 5R3R6L4R: nor
0155   if( keepTrigPatt(PTMS[17],17,1,hl) ) return;   // 5368A --> 17 - 5L3R6L8L: nor
0156   if( keepTrigPatt(PTMS[18],18,1,hl) ) return;   // 5368B --> 18 - 5L3R6R8L: nor
0157   if( keepTrigPatt(PTMS[19],19,4,hl) ) return;   // 5368C --> 19 - 5L3R6R8R: L11
0158   if( keepTrigPatt(PTMS[20],20,1,hl) ) return;   // 5764A --> 20 - 5R7L6L4R: nor
0159   if( keepTrigPatt(PTMS[21],21,1,hl) ) return;   // 5764B --> 21 - 5R7L6R4R: nor
0160   if( keepTrigPatt(PTMS[22],22,7,hl) ) return;   // 5764C --> 22 - 5R7L6L4L: H11
0161   if( keepTrigPatt(PTMS[23],23,3,hl) ) return;   // 9764A --> 23 - 9L7L6L4R: 11L
0162   if( keepTrigPatt(PTMS[24],24,2,hl) ) return;   // 9764B --> 24 - 9L7L6R4R: 1L1
0163   if( keepTrigPatt(PTMS[25],25,4,hl) ) return;   // 9764C --> 25 - 9L7R6R4R: L11
0164   if( RON==1 ){
0165     if( keepTrigPatt(PTMS[26],26,1,hl) ) return;   // 1324A --> 26 - 1L3L2R4L: nor
0166   }
0167   if( keepTrigPatt(PTMS[27],27,2,hl) ) return;   // 1324B --> 27 - 1L3L2R4R: 1L1
0168   if( keepTrigPatt(PTMS[28],28,1,hl) ) return;   // 1324C --> 28 - 1R3L2R4L: nor
0169   if( keepTrigPatt(PTMS[29],29,1,hl) ) return;   // 1324D --> 29 - 1R3L2R4R: nor
0170   if( RON==1 ){
0171     if( keepTrigPatt(PTMS[30],30,1,hl) ) return;   // 9768A --> 30 - 9L7L6R8L: nor
0172   }
0173   if( keepTrigPatt(PTMS[31],31,1,hl) ) return;   // 9768B --> 31 - 9L7R6R8L: nor 
0174 
0175   }//end h/l loop
0176 
0177 */
0178 
0179   /* 
0180   // High level triggers:
0181   if( keepTrig( 1,accpatB,8) ) return;   // 5768B -->  1 - acc. patt. B
0182   if( keepTrig( 2,accpatA,8) ) return;   // 5768C -->  2 - acc. patt. A
0183   if( keepTrig( 3,accpatA,8) ) return;   // 5768D -->  3 - acc. patt. A
0184   if( keepTrig( 4,accpatB,8) ) return;   // 1364A -->  4 - acc. patt. B
0185   if( keepTrig( 5,accpatA,8) ) return;   // 1364B -->  5 - acc. patt. A
0186   if( keepTrig( 6,accpatA,8) ) return;   // 1364C -->  6 - acc. patt. A
0187   if( keepTrig( 7,accpatB,8) ) return;   // 1368A -->  7 - acc. patt. B
0188   if( keepTrig( 8,accpatB,8) ) return;   // 1368B -->  8 - acc. patt. B
0189   if( keepTrig( 9,accpatB,8) ) return;   // 1368C -->  9 - acc. patt. B
0190   if( keepTrig(10,accpatA,8) ) return;   // 5324A --> 10 - acc. patt. A
0191   if( keepTrig(11,accpatA,8) ) return;   // 5324B --> 11 - acc. patt. A
0192   if( keepTrig(12,accpatB,8) ) return;   // 5324C --> 12 - acc. patt. B
0193   if( keepTrig(13,accpatA,8) ) return;   // 5364A --> 13 - acc. patt. A
0194   if( keepTrig(14,accpatA,8) ) return;   // 5364B --> 14 - acc. patt. A
0195   if( keepTrig(15,accpatB,8) ) return;   // 5364C --> 15 - acc. patt. B
0196   if( keepTrig(16,accpatA,8) ) return;   // 5364D --> 16 - acc. patt. A
0197   if( keepTrig(17,accpatA,8) ) return;   // 5368A --> 17 - acc. patt. A
0198   if( keepTrig(18,accpatA,8) ) return;   // 5368B --> 18 - acc. patt. A
0199   if( keepTrig(19,accpatB,8) ) return;   // 5368C --> 19 - acc. patt. B
0200   if( keepTrig(20,accpatA,8) ) return;   // 5764A --> 20 - acc. patt. A
0201   if( keepTrig(21,accpatA,8) ) return;   // 5764B --> 21 - acc. patt. A
0202   if( keepTrig(22,accpatB,8) ) return;   // 5764C --> 22 - acc. patt. B
0203   if( keepTrig(23,accpatB,8) ) return;   // 9764A --> 23 - acc. patt. B
0204   if( keepTrig(24,accpatB,8) ) return;   // 9764B --> 24 - acc. patt. B
0205   if( keepTrig(25,accpatB,8) ) return;   // 9764C --> 25 - acc. patt. B
0206   if( keepTrig( 0,accpatA,8) ) return;   // 5768A -->  0 - acc. patt. A
0207   */
0208   /* 
0209   // Low level triggers -B
0210   if( keepTrig( 1,accpatB,2) ) return;   // 5768B -->  1 - acc. patt. B
0211   if( keepTrig( 2,accpatA,2) ) return;   // 5768C -->  2 - acc. patt. A
0212   if(tiKes==1) {
0213     if( keepTrig( 3,accpatA,2) ) return; // 5768D -->  3 - acc. patt. A
0214   }
0215   if( keepTrig( 4,accpatB,2) ) return;   // 1364A -->  4 - acc. patt. B
0216   if( keepTrig( 5,accpatA,2) ) return;   // 1364B -->  5 - acc. patt. A
0217   if( keepTrig( 6,accpatA,2) ) return;   // 1364C -->  6 - acc. patt. A
0218   if( keepTrig( 7,accpatB,2) ) return;   // 1368A -->  7 - acc. patt. B
0219   if( keepTrig( 8,accpatB,2) ) return;   // 1368B -->  8 - acc. patt. B
0220   if( keepTrig( 9,accpatB,2) ) return;   // 1368C -->  9 - acc. patt. B
0221   if( keepTrig(10,accpatA,2) ) return;   // 5324A --> 10 - acc. patt. A
0222   if( keepTrig(11,accpatA,2) ) return;   // 5324B --> 11 - acc. patt. A
0223   if( keepTrig(12,accpatB,2) ) return;   // 5324C --> 12 - acc. patt. B
0224   if(tiKes==1) {
0225     if( keepTrig(13,accpatA,2) ) return; // 5364A --> 13 - acc. patt. A
0226   }
0227   if( keepTrig(14,accpatA,2) ) return;   // 5364B --> 14 - acc. patt. A
0228   if( keepTrig(15,accpatB,2) ) return;   // 5364C --> 15 - acc. patt. B
0229   if( keepTrig(16,accpatA,2) ) return;   // 5364D --> 16 - acc. patt. A
0230   if(tiKes==1) {
0231     if( keepTrig(17,accpatA,2) ) return; // 5368A --> 17 - acc. patt. A
0232   }
0233   if( keepTrig(18,accpatA,2) ) return;   // 5368B --> 18 - acc. patt. A
0234   if( keepTrig(19,accpatB,2) ) return;   // 5368C --> 19 - acc. patt. B
0235   if( keepTrig(20,accpatA,2) ) return;   // 5764A --> 20 - acc. patt. A
0236   if(tiKes==1) {
0237     if( keepTrig(21,accpatA,2) ) return; // 5764B --> 21 - acc. patt. A
0238   }
0239   if( keepTrig(22,accpatB,2) ) return;   // 5764C --> 22 - acc. patt. B
0240   if( keepTrig(23,accpatB,2) ) return;   // 9764A --> 23 - acc. patt. B
0241   if( keepTrig(24,accpatB,2) ) return;   // 9764B --> 24 - acc. patt. B
0242   if( keepTrig(25,accpatB,2) ) return;   // 9764C --> 25 - acc. patt. B
0243   if( keepTrig( 0,accpatA,2) ) return;   // 5768A -->  0 - acc. patt. A
0244 
0245   // Low level triggers -C
0246   if( keepTrig( 1,accpatB,3) ) return;   // 5768B -->  1 - acc. patt. B
0247   if( keepTrig( 2,accpatA,3) ) return;   // 5768C -->  2 - acc. patt. A
0248   if( keepTrig( 3,accpatA,3) ) return;   // 5768D -->  3 - acc. patt. A
0249   if( keepTrig( 4,accpatB,3) ) return;   // 1364A -->  4 - acc. patt. B
0250   if( keepTrig( 5,accpatA,3) ) return;   // 1364B -->  5 - acc. patt. A
0251   if(tiKes==1) {
0252     if( keepTrig( 6,accpatA,3) ) return; // 1364C -->  6 - acc. patt. A
0253   }
0254   if( keepTrig( 7,accpatB,3) ) return;   // 1368A -->  7 - acc. patt. B
0255   if( keepTrig( 8,accpatB,3) ) return;   // 1368B -->  8 - acc. patt. B
0256   if( keepTrig( 9,accpatB,3) ) return;   // 1368C -->  9 - acc. patt. B
0257   if(tiKes==1) {
0258     if( keepTrig(10,accpatA,3) ) return; // 5324A --> 10 - acc. patt. A
0259   }
0260   if( keepTrig(11,accpatA,3) ) return;   // 5324B --> 11 - acc. patt. A
0261   if( keepTrig(12,accpatB,3) ) return;   // 5324C --> 12 - acc. patt. B
0262   if( keepTrig(13,accpatA,3) ) return;   // 5364A --> 13 - acc. patt. A
0263   if( keepTrig(14,accpatA,3) ) return;   // 5364B --> 14 - acc. patt. A
0264   if( keepTrig(15,accpatB,3) ) return;   // 5364C --> 15 - acc. patt. B
0265   if(tiKes==1) {
0266     if( keepTrig(16,accpatA,3) ) return; // 5364D --> 16 - acc. patt. A
0267   }
0268   if( keepTrig(17,accpatA,3) ) return;   // 5368A --> 17 - acc. patt. A
0269   if( keepTrig(18,accpatA,3) ) return;   // 5368B --> 18 - acc. patt. A
0270   if( keepTrig(19,accpatB,3) ) return;   // 5368C --> 19 - acc. patt. B
0271   if( keepTrig(20,accpatA,3) ) return;   // 5764A --> 20 - acc. patt. A
0272   if( keepTrig(21,accpatA,3) ) return;   // 5764B --> 21 - acc. patt. A
0273   if( keepTrig(22,accpatB,3) ) return;   // 5764C --> 22 - acc. patt. B
0274   if( keepTrig(23,accpatB,3) ) return;   // 9764A --> 23 - acc. patt. B
0275   if( keepTrig(24,accpatB,3) ) return;   // 9764B --> 24 - acc. patt. B
0276   if( keepTrig(25,accpatB,3) ) return;   // 9764C --> 25 - acc. patt. B
0277   if(tiKes==1) {
0278     if( keepTrig( 0,accpatA,3) ) return; // 5768A -->  0 - acc. patt. A
0279   }
0280 
0281   // Low level triggers -A
0282   if( keepTrig( 1,accpatB,1) ) return;   // 5768B -->  1 - acc. patt. B
0283   if( keepTrig( 2,accpatA,1) ) return;   // 5768C -->  2 - acc. patt. A
0284   if( keepTrig( 3,accpatA,1) ) return;   // 5768D -->  3 - acc. patt. A
0285   if( keepTrig( 4,accpatB,1) ) return;   // 1364A -->  4 - acc. patt. B
0286   if( keepTrig( 5,accpatA,1) ) return;   // 1364B -->  5 - acc. patt. A
0287   if( keepTrig( 6,accpatA,1) ) return;   // 1364C -->  6 - acc. patt. A
0288   if( keepTrig( 7,accpatB,1) ) return;   // 1368A -->  7 - acc. patt. B
0289   if( keepTrig( 8,accpatB,1) ) return;   // 1368B -->  8 - acc. patt. B
0290   if(tiKes==1) {
0291     if( keepTrig( 9,accpatB,1) ) return; // 1368C -->  9 - acc. patt. B
0292   }
0293   if( keepTrig(10,accpatA,1) ) return;   // 5324A --> 10 - acc. patt. A
0294   if( keepTrig(11,accpatA,1) ) return;   // 5324B --> 11 - acc. patt. A
0295   if( keepTrig(12,accpatB,1) ) return;   // 5324C --> 12 - acc. patt. B
0296   if( keepTrig(13,accpatA,1) ) return;   // 5364A --> 13 - acc. patt. A
0297   if( keepTrig(14,accpatA,1) ) return;   // 5364B --> 14 - acc. patt. A
0298   if( keepTrig(15,accpatB,1) ) return;   // 5364C --> 15 - acc. patt. B
0299   if( keepTrig(16,accpatA,1) ) return;   // 5364D --> 16 - acc. patt. A
0300   if( keepTrig(17,accpatA,1) ) return;   // 5368A --> 17 - acc. patt. A
0301   if( keepTrig(18,accpatA,1) ) return;   // 5368B --> 18 - acc. patt. A
0302   if(tiKes==1) {
0303     if( keepTrig(19,accpatB,1) ) return; // 5368C --> 19 - acc. patt. B
0304   }
0305   if( keepTrig(20,accpatA,1) ) return;   // 5764A --> 20 - acc. patt. A
0306   if( keepTrig(21,accpatA,1) ) return;   // 5764B --> 21 - acc. patt. A
0307   if(tiKes==1) {
0308     if( keepTrig(22,accpatB,1) ) return; // 5764C --> 22 - acc. patt. B
0309   }
0310   if( keepTrig(23,accpatB,1) ) return;   // 9764A --> 23 - acc. patt. B
0311   if( keepTrig(24,accpatB,1) ) return;   // 9764B --> 24 - acc. patt. B
0312   if(tiKes==1) {
0313     if( keepTrig(25,accpatB,1) ) return; // 9764C --> 25 - acc. patt. B
0314   }
0315   if( keepTrig( 0,accpatA,1) ) return;   // 5768A -->  0 - acc. patt. A
0316 
0317   // Low level triggers -D
0318   if( keepTrig( 0,accpatA,4) ) return;   // 5768A -->  0 - acc. patt. A
0319   if( keepTrig( 1,accpatB,4) ) return;   // 5768B -->  1 - acc. patt. B
0320   if( keepTrig( 2,accpatA,4) ) return;   // 5768C -->  2 - acc. patt. A
0321   if( keepTrig( 3,accpatA,4) ) return;   // 5768D -->  3 - acc. patt. A
0322   if(tiKes==1) {
0323     if( keepTrig( 4,accpatB,4) ) return; // 1364A -->  4 - acc. patt. B
0324   }
0325   if( keepTrig( 5,accpatA,4) ) return;   // 1364B -->  5 - acc. patt. A
0326   if( keepTrig( 6,accpatA,4) ) return;   // 1364C -->  6 - acc. patt. A
0327   if( keepTrig( 7,accpatB,4) ) return;   // 1368A -->  7 - acc. patt. B
0328   if(tiKes==1) {
0329     if( keepTrig( 8,accpatB,4) ) return; // 1368B -->  8 - acc. patt. B
0330   }
0331   if( keepTrig( 9,accpatB,4) ) return;   // 1368C -->  9 - acc. patt. B
0332   if( keepTrig(10,accpatA,4) ) return;   // 5324A --> 10 - acc. patt. A
0333   if( keepTrig(11,accpatA,4) ) return;   // 5324B --> 11 - acc. patt. A
0334   if(tiKes==1) {
0335     if( keepTrig(12,accpatB,4) ) return; // 5324C --> 12 - acc. patt. B
0336   }
0337   if( keepTrig(13,accpatA,4) ) return;   // 5364A --> 13 - acc. patt. A
0338   if( keepTrig(14,accpatA,4) ) return;   // 5364B --> 14 - acc. patt. A
0339   if( keepTrig(15,accpatB,4) ) return;   // 5364C --> 15 - acc. patt. B
0340   if( keepTrig(16,accpatA,4) ) return;   // 5364D --> 16 - acc. patt. A
0341   if( keepTrig(17,accpatA,4) ) return;   // 5368A --> 17 - acc. patt. A
0342   if( keepTrig(18,accpatA,4) ) return;   // 5368B --> 18 - acc. patt. A
0343   if( keepTrig(19,accpatB,4) ) return;   // 5368C --> 19 - acc. patt. B
0344   if( keepTrig(20,accpatA,4) ) return;   // 5764A --> 20 - acc. patt. A
0345   if( keepTrig(21,accpatA,4) ) return;   // 5764B --> 21 - acc. patt. A
0346   if( keepTrig(22,accpatB,4) ) return;   // 5764C --> 22 - acc. patt. B
0347   if(tiKes==1) {
0348     if( keepTrig(23,accpatB,4) ) return; // 9764A --> 23 - acc. patt. B
0349   }
0350   if( keepTrig(24,accpatB,4) ) return;   // 9764B --> 24 - acc. patt. B
0351   if( keepTrig(25,accpatB,4) ) return;   // 9764C --> 25 - acc. patt. B
0352 */
0353 }
0354 
0355 int DTBtiChip::keepTrigPatt(const int flag, const int eq, const int pattType, int hlflag) {
0356   //if pattern is not enabled, return
0357   if (flag == 0)
0358     return 0;
0359 
0360   int AC1 = config()->AccPattAC1();  //default 0
0361   int AC2 = config()->AccPattAC2();  //default 3
0362   int ACH = config()->AccPattACH();  //default 1
0363   int ACL = config()->AccPattACL();  //default 2
0364   int tiKes = config()->XON();
0365 
0366   if (config()->debug() > 4) {
0367     cout << "DTBtiChip::keepTrigPatt called with arguments: ";
0368     cout << eq << ", " << pattType << ", " << hlflag << endl;
0369     cout << "AC1,AC2,ACH,ACL=" << AC1 << " " << AC2 << " " << ACH << " " << ACL << endl;
0370   }
0371 
0372   BitArray<80> val0, val1, val2, val3, val4, val5;
0373   int mm[6];
0374 
0375   //NB _Keq = (Kman - K0)/2   where K0=tmax*2  --->OBSOLETE, now Keq=Kman
0376   //int K0 = 2 * (config()->ST()/2.);
0377   int K0 = int(config()->ST());
0378 
0379   int i = 0;
0380   float Keqfloat[6] = {0, 0, 0, 0, 0, 0};
0381   for (i = 0; i < 6; i++) {
0382     mm[i] = -1;
0383     int mk = (int)(_Keq[eq][i] - K0);
0384     //if(abs(mk) > config()->KCut(_id.superlayer()-1))continue;
0385     if (abs(mk) > 2 * K0)
0386       continue;
0387     Keqfloat[i] = _Keq[eq][i];
0388     mm[i] = (int)(_Keq[eq][i]);
0389     //    if(_Keq[eq][i]<0){
0390     //      mm[i]=_Keq[eq][i]*2-0.5+KCen;
0391     //    } else {
0392     //      mm[i]=_Keq[eq][i]*2+KCen;
0393     //    }
0394   }
0395 
0396   switch (pattType) {
0397     case 1:  //normal pattern
0398              //if(hlflag==1 && (eq!=2 && eq!=14 && eq!=28) ){  //test for L
0399              /* if(hlflag==1){  //test for L
0400           acceptMask(&val0,mm[0],AC1); //eqAB
0401           acceptMask(&val1,mm[1],AC1); //eqBC
0402           acceptMask(&val2,mm[2],AC1); //eqCD
0403         }
0404         else
0405 */
0406       {
0407         acceptMask(&val0, mm[0], AC2);  //eqAB
0408         acceptMask(&val1, mm[1], AC2);  //eqBC
0409         acceptMask(&val2, mm[2], AC2);  //eqCD
0410       }
0411       break;
0412 
0413     case 2:                           //1L1 pattern
0414       acceptMask(&val0, mm[0], AC1);  //eqAB
0415       acceptMask(&val1, mm[1], ACL);  //eqBC
0416       acceptMask(&val2, mm[2], AC1);  //eqCD
0417       break;
0418 
0419     case 3:                           //11L pattern
0420       acceptMask(&val0, mm[0], AC1);  //eqAB
0421       acceptMask(&val1, mm[1], AC1);  //eqBC
0422       acceptMask(&val2, mm[2], ACL);  //eqCD
0423       break;
0424 
0425     case 4:                           //L11 pattern
0426       acceptMask(&val0, mm[0], ACL);  //eqAB
0427       acceptMask(&val1, mm[1], AC1);  //eqBC
0428       acceptMask(&val2, mm[2], AC1);  //eqCD
0429       break;
0430 
0431     case 5:                           //1H1 pattern
0432       acceptMask(&val0, mm[0], AC1);  //eqAB
0433       acceptMask(&val1, mm[1], ACH);  //eqBC
0434       acceptMask(&val2, mm[2], AC1);  //eqCD
0435       break;
0436 
0437     case 6:                           //11H pattern
0438       acceptMask(&val0, mm[0], AC1);  //eqAB
0439       acceptMask(&val1, mm[1], AC1);  //eqBC
0440       acceptMask(&val2, mm[2], ACH);  //eqCD
0441       break;
0442 
0443     case 7:                           //H11 pattern
0444       acceptMask(&val0, mm[0], ACH);  //eqAB
0445       acceptMask(&val1, mm[1], AC1);  //eqBC
0446       acceptMask(&val2, mm[2], AC1);  //eqCD
0447       break;
0448 
0449     default:
0450       acceptMask(&val0, mm[0], AC2);  //eqAB
0451       acceptMask(&val1, mm[1], AC2);  //eqBC
0452       acceptMask(&val2, mm[2], AC2);  //eqCD
0453       break;
0454   }
0455 
0456   //eq. AC and BD acceptance are always +-1 ->code 00
0457   int acc = 0;
0458   acceptMask(&val3, mm[3], acc);  //eq.AC
0459   acceptMask(&val4, mm[4], acc);  //eq.BD
0460 
0461   //eq. AD is the reference value!
0462   if (mm[5] > 0) {
0463     val5.set(mm[5]);
0464   }
0465 
0466   // debugging: print() method prints from last to first bit!
0467   if (config()->debug() > 4) {
0468     cout << " dump of val arrays: " << endl;
0469     //    cout << val0.to_string() << endl;
0470     //    cout << val1.to_string() << endl;
0471     //    cout << val2.to_string() << endl;
0472     //    cout << val3.to_string() << endl;
0473     //    cout << val4.to_string() << endl;
0474     //    cout << val5.to_string() << endl;
0475     val0.print();
0476     cout << endl;
0477     val1.print();
0478     cout << endl;
0479     val2.print();
0480     cout << endl;
0481     val3.print();
0482     cout << endl;
0483     val4.print();
0484     cout << endl;
0485     val5.print();
0486     cout << endl;
0487   }
0488   // end debugging
0489 
0490   //search for High trigger:
0491   if (hlflag == 0) {
0492     int code = 0;
0493     int KMax = 0;
0494     int LKMax = -1;
0495     for (i = 0; i < 80; i++) {
0496       int val =
0497           val0.element(i) + val1.element(i) + val2.element(i) + val3.element(i) + val4.element(i) + val5.element(i);
0498       if (val > KMax) {
0499         KMax = val;
0500         LKMax = i;
0501       }
0502     }
0503 
0504     //SV: K value is stored in 6 bits, so K=64->0, etc
0505     if (LKMax > 63)
0506       LKMax -= 64;
0507 
0508     if (KMax == 6) {
0509       code = 8;
0510       int X;
0511       if (eq == 0)  //store Xbc only for patt 0, else store Xad
0512         X = int(_Xeq[eq][0]);
0513       else
0514         X = int(_Xeq[eq][1]);
0515       store(eq, code, LKMax, X, Keqfloat[0], Keqfloat[1], Keqfloat[2], Keqfloat[3], Keqfloat[4], Keqfloat[5]);
0516       return 1;
0517     }
0518     return 0;
0519   }  //end H
0520 
0521   //search for Low triggers:
0522   if (hlflag == 1) {
0523     int code = 0;
0524     int RON = config()->RONflag();
0525 
0526     //hit in B is missing
0527     if (config()->debug() > 4)
0528       cout << "SelTrig: searching low-B" << endl;
0529     int LKMax = -1;
0530     for (i = 0; i < 80; i++) {
0531       int val = val2.element(i) + val3.element(i) + val5.element(i);
0532       if (val == 3) {  //Ref. is eqAD
0533         code = 2;
0534         LKMax = i;
0535         int storefg = 1;
0536 
0537         //SV - XON time-ind.Keq suppr. XON=0 do not abilitate patterns
0538         if (tiKes == 0) {
0539           if (eq == 3 || eq == 13 || eq == 17 || eq == 21 || eq == 29) {
0540             if (config()->debug() > 3)
0541               cout << "SelTrig: doing XON suppression!" << endl;
0542             storefg = 0;
0543           }
0544         }
0545 
0546         //SV - RON suppression for low triggers
0547         if (RON == 0) {
0548           if (eq == 19) {
0549             if (config()->debug() > 3)
0550               cout << "SelTrig: doing RON low triggers suppression!" << endl;
0551             storefg = 0;
0552           }
0553         }
0554 
0555         if (storefg) {
0556           //SV: K value is stored in 6 bits, so K=64->0, etc
0557           if (LKMax > 63)
0558             LKMax -= 64;
0559           int X;
0560           if (eq == 0)
0561             X = int(_Xeq[eq][0]);
0562           else
0563             X = int(_Xeq[eq][1]);
0564           store(eq, code, LKMax, X, Keqfloat[0], Keqfloat[1], Keqfloat[2], Keqfloat[3], Keqfloat[4], Keqfloat[5]);
0565           return 1;
0566         }
0567       }
0568     }  //end -B Low
0569 
0570     //hit in C is missing
0571     if (config()->debug() > 3)
0572       cout << "SelTrig: searching low-C" << endl;
0573     for (i = 0; i < 80; i++) {
0574       int val = val0.element(i) + val4.element(i) + val5.element(i);
0575       if (val == 3) {  //Ref. is eqAD
0576         code = 3;
0577         LKMax = i;
0578         int storefg = 1;
0579 
0580         //SV - XON time-ind.Keq suppr.
0581         if (tiKes == 0) {
0582           if (eq == 0 || eq == 6 || eq == 10 || eq == 16 || eq == 26 || eq == 30) {
0583             if (config()->debug() > 3)
0584               cout << "SelTrig: doing XON suppression!" << endl;
0585             storefg = 0;
0586           }
0587         }
0588 
0589         if (storefg) {
0590           //SV: K value is stored in 6 bits, so K=64->0, etc
0591           if (LKMax > 63)
0592             LKMax -= 64;
0593 
0594           int X;
0595           if (eq == 0)
0596             X = int(_Xeq[eq][0]);
0597           else
0598             X = int(_Xeq[eq][1]);
0599           store(eq, code, LKMax, X, Keqfloat[0], Keqfloat[1], Keqfloat[2], Keqfloat[3], Keqfloat[4], Keqfloat[5]);
0600           return 1;
0601         }
0602       }
0603     }  // end -C Low
0604 
0605     //for -A and -D low acceptance is +-1
0606     //    if(pattType==1){
0607     val0.reset();
0608     val1.reset();
0609     val2.reset();
0610     acceptMask(&val0, mm[0], AC1);  //eqAB
0611     acceptMask(&val1, mm[1], AC1);  //eqBC
0612     acceptMask(&val2, mm[2], AC1);  //eqCD
0613                                     //    }
0614 
0615     //hit in A is missing
0616     if (config()->debug() > 4)
0617       cout << "SelTrig: searching low-A" << endl;
0618     for (i = 0; i < 80; i++) {
0619       int val = val1.element(i) + val2.element(i) + val4.element(i);
0620       if (val == 3 && i == mm[4]) {  //Ref. is eqBD
0621         code = 1;
0622         LKMax = i;
0623         int storefg = 1;
0624 
0625         //SV - XON time-ind.Keq suppr.
0626         if (tiKes == 0) {
0627           if (eq == 9 || eq == 19 || eq == 22 || eq == 25) {
0628             if (config()->debug() > 3)
0629               cout << "SelTrig: doing low-A XON suppression!" << endl;
0630             storefg = 0;
0631           }
0632         }
0633 
0634         if (RON == 0) {  //SV - RON suppression
0635           if (eq == 26) {
0636             if (config()->debug() > 3)
0637               cout << "SelTrig: doing RON low triggers suppression!" << endl;
0638             storefg = 0;
0639           }
0640         }
0641 
0642         if (storefg) {
0643           //SV: K value is stored in 6 bits, so K=64->0, etc
0644           if (LKMax > 63)
0645             LKMax -= 64;
0646 
0647           store(eq,
0648                 code,
0649                 LKMax,
0650                 int(_Xeq[eq][0]),
0651                 Keqfloat[0],
0652                 Keqfloat[1],
0653                 Keqfloat[2],
0654                 Keqfloat[3],
0655                 Keqfloat[4],
0656                 Keqfloat[5]);
0657           return 1;
0658         }
0659       }
0660     }  //end -A Low
0661 
0662     //hit in D is missing
0663     if (config()->debug() > 4)
0664       cout << "SelTrig: searching low-D" << endl;
0665     for (i = 0; i < 80; i++) {
0666       int val = val0.element(i) + val1.element(i) + val3.element(i);
0667       if (val == 3 && i == mm[3]) {  //Ref. is eqAC
0668         code = 4;
0669         LKMax = i;
0670         int storefg = 1;
0671 
0672         //SV - XON time-ind.Keq suppr.
0673         if (tiKes == 0) {
0674           if (eq == 4 || eq == 8 || eq == 12 || eq == 23) {
0675             if (config()->debug() > 3)
0676               cout << "SelTrig: doing XON suppression!" << endl;
0677             storefg = 0;
0678           }
0679         }
0680 
0681         //SV - RON suppression for low triggers
0682         if (RON == 0) {
0683           if (eq == 1 || eq == 2 || eq == 3 || eq == 24 || eq == 25) {
0684             if (config()->debug() > 3)
0685               cout << "SelTrig: doing RON low triggers suppression!" << endl;
0686             storefg = 0;
0687           }
0688         }
0689 
0690         if (storefg) {  // && _Xeq[eq][1] >=0){
0691           //SV: K value is stored in 6 bits, so K=64->0, etc
0692           if (LKMax > 63)
0693             LKMax -= 64;
0694 
0695           store(eq,
0696                 code,
0697                 LKMax,
0698                 int(_Xeq[eq][0]),
0699                 Keqfloat[0],
0700                 Keqfloat[1],
0701                 Keqfloat[2],
0702                 Keqfloat[3],
0703                 Keqfloat[4],
0704                 Keqfloat[5]);
0705           return 1;
0706         }
0707       }
0708     }  //end -D Low
0709 
0710     return 0;
0711   }  //end Low
0712   return 0;
0713 }
0714 
0715 void DTBtiChip::acceptMask(BitArray<80>* BitArrPtr, int k, int accep) {
0716   if (k >= 0 && k < 78) {
0717     if (config()->debug() > 4)
0718       cout << "DTBtiChip::acceptMask ->  Setting acceptance for k=" << k << endl;
0719 
0720     if (accep == 0) {  //code 00
0721       if (k >= 1)
0722         BitArrPtr->set(k - 1);
0723       BitArrPtr->set(k);
0724       BitArrPtr->set(k + 1);
0725     }
0726     if (accep == 1) {  //code 01
0727       BitArrPtr->set(k);
0728       BitArrPtr->set(k + 1);
0729       BitArrPtr->set(k + 2);
0730     }
0731     if (accep == 2) {  //code 10
0732       if (k > 1)
0733         BitArrPtr->set(k - 2);
0734       if (k >= 1)
0735         BitArrPtr->set(k - 1);
0736       BitArrPtr->set(k);
0737     }
0738     if (accep == 3) {  //code 11
0739       if (k > 1)
0740         BitArrPtr->set(k - 2);
0741       if (k >= 1)
0742         BitArrPtr->set(k - 1);
0743       BitArrPtr->set(k);
0744       BitArrPtr->set(k + 1);
0745       BitArrPtr->set(k + 2);
0746     }
0747   }
0748 
0749   if (config()->debug() > 4)
0750     cout << "DTBtiChip::acceptMask ->  END " << endl;
0751 }
0752 
0753 int DTBtiChip::keepTrig(const int eq, const int acp, const int code) {
0754   if (config()->debug() > 4) {
0755     cout << "DTBtiChip::keepTrig called with arguments: ";
0756     cout << eq << ", " << acp << ", " << code << endl;
0757   }
0758 
0759   int const KCen = 40;  // Arrays will start from 0 --> use 40 instead of 41
0760   BitArray<80> val0, val1, val2, val3, val4, val5;
0761   int mm[6];
0762 
0763   int i = 0;
0764   for (i = 0; i < 6; i++) {
0765     mm[i] = 0;
0766     int mk = (int)(2 * _Keq[eq][i]);
0767     if (abs(mk) > config()->KCut())
0768       continue;
0769     mm[i] = (int)(_Keq[eq][i] * 2) + KCen;
0770     //    if(_Keq[eq][i]<0){
0771     //      mm[i]=_Keq[eq][i]*2-0.5+KCen;
0772     //    } else {
0773     //      mm[i]=_Keq[eq][i]*2+KCen;
0774     //    }
0775   }
0776 
0777   if (mm[0] > 0 && (code == 8 || code == 3 || code == 4)) {
0778     val0.set(mm[0] - 1);
0779     val0.set(mm[0]);
0780     val0.set(mm[0] + 1);
0781     if (acp == 2 && (code == 8 || code == 3)) {
0782       val0.set(mm[0] - 2);
0783       val0.set(mm[0] + 2);
0784     }
0785   }
0786 
0787   if (mm[1] > 0 && (code == 8 || code == 1 || code == 4)) {
0788     val1.set(mm[1] - 1);
0789     val1.set(mm[1]);
0790     val1.set(mm[1] + 1);
0791     if (acp == 2 && code == 8) {
0792       val1.set(mm[1] - 2);
0793       val1.set(mm[1] + 2);
0794     }
0795   }
0796 
0797   if (mm[2] > 0 && (code == 8 || code == 1 || code == 2)) {
0798     val2.set(mm[2] - 1);
0799     val2.set(mm[2]);
0800     val2.set(mm[2] + 1);
0801     if (acp == 2 && (code == 8 || code == 2)) {
0802       val2.set(mm[2] - 2);
0803       val2.set(mm[2] + 2);
0804     }
0805   }
0806 
0807   if (mm[3] > 0 && (code == 8 || code == 2 || code == 4)) {
0808     val3.set(mm[3] - 1);
0809     val3.set(mm[3]);
0810     val3.set(mm[3] + 1);
0811   }
0812 
0813   if (mm[4] > 0 && (code == 8 || code == 1 || code == 3)) {
0814     val4.set(mm[4] - 1);
0815     val4.set(mm[4]);
0816     val4.set(mm[4] + 1);
0817   }
0818 
0819   if (mm[5] > 0 && (code == 8 || code == 2 || code == 3)) {
0820     val5.set(mm[5]);
0821   }
0822 
0823   // debugging
0824   if (config()->debug() > 4) {
0825     cout << " dump of val arrays: " << endl;
0826     //    cout << val0.to_string() << endl;
0827     //    cout << val1.to_string() << endl;
0828     //    cout << val2.to_string() << endl;
0829     //    cout << val3.to_string() << endl;
0830     //    cout << val4.to_string() << endl;
0831     //    cout << val5.to_string() << endl;
0832     val0.print();
0833     cout << endl;
0834     val1.print();
0835     cout << endl;
0836     val2.print();
0837     cout << endl;
0838     val3.print();
0839     cout << endl;
0840     val4.print();
0841     cout << endl;
0842     val5.print();
0843     cout << endl;
0844   }
0845   // end debugging
0846 
0847   int KMax = 0;
0848   int LKMax = -1;
0849   for (i = 0; i < 80; i++) {
0850     int val = val0.element(i) + val1.element(i) + val2.element(i) + val3.element(i) + val4.element(i) + val5.element(i);
0851     //    int val = val0.test(i)+val1.test(i)+val2.test(i)+
0852     //              val3.test(i)+val4.test(i)+val5.test(i);
0853     if (val > KMax) {
0854       KMax = val;
0855       LKMax = i;
0856     }
0857   }
0858 
0859   // Note that all bits in val are shifted by one w.r.t. FORTRAN version
0860   // The output K will be the same because of the different value of Kcen
0861 
0862   if (KMax == 6 && code == 8) {
0863     store(eq, 8, LKMax - KCen, int(_Xeq[eq][1]));
0864     return 1;
0865   } else if (KMax == 3 && code != 8) {
0866     if (code == 1 || code == 4) {
0867       store(eq, code, LKMax - KCen, int(_Xeq[eq][0]));
0868     } else {
0869       store(eq, code, LKMax - KCen, int(_Xeq[eq][1]));
0870     }
0871     return 1;
0872   }
0873   return 0;
0874   // return value is ITFL of FORTRAN version
0875 }