Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-03 22:28:27

0001 #include "L1Trigger/CSCTriggerPrimitives/interface/ComparatorCodeLUT.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 ComparatorCodeLUT::ComparatorCodeLUT(const edm::ParameterSet& conf) {
0005   clct_pattern_ = CSCPatternBank::clct_pattern_run3_;
0006 }
0007 
0008 void ComparatorCodeLUT::setESLookupTables(const CSCL1TPLookupTableCCLUT* conf) { lookupTableCCLUT_ = conf; }
0009 
0010 void ComparatorCodeLUT::run(CSCCLCTDigi& digi, unsigned numCFEBs) const {
0011   // print out the old CLCT for debugging
0012   if (infoV_ > 2) {
0013     std::ostringstream strm;
0014     strm << "\n";
0015     strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
0016     strm << "+                  Before CCCLUT algorithm:                       +\n";
0017     strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
0018     strm << " Old CLCT digi " << digi << "\n";
0019     strm << " 1/4 strip bit " << digi.getQuartStripBit() << " 1/8 strip bit " << digi.getEighthStripBit() << "\n";
0020     strm << " 1/4 strip number " << digi.getKeyStrip(4) << " 1/8 strip number " << digi.getKeyStrip(8) << "\n";
0021     strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
0022     LogDebug("ComparatorCodeLUT") << strm.str();
0023   }
0024 
0025   // set Run-3 flag
0026   digi.setRun3(true);
0027 
0028   // Get the comparator hits
0029   auto compHits = digi.getHits();
0030 
0031   // Wrap the comparator code in a format for calculation
0032   pattern compHitsCC;
0033 
0034   for (int i = 0; i < CSCConstants::NUM_LAYERS; i++) {
0035     int iCC = 0;
0036     for (int j = 0; j < CSCConstants::CLCT_PATTERN_WIDTH; j++) {
0037       // only fill when the pattern is active
0038       if (clct_pattern_[digi.getPattern()][i][j]) {
0039         if (compHits[i][j] != CSCConstants::INVALID_HALF_STRIP) {
0040           compHitsCC[i][iCC] = 1;
0041         } else {
0042           compHitsCC[i][iCC] = 0;
0043         }
0044         iCC++;
0045       }
0046     }
0047   }
0048 
0049   // calculate the comparator code
0050   const int comparatorCode(calculateComparatorCode(compHitsCC));
0051 
0052   // store the comparator code
0053   digi.setCompCode(comparatorCode);
0054 
0055   // calculate the slope and position offset
0056   const int pattern(digi.getPattern());
0057 
0058   // set the Run-3 pattern
0059   digi.setRun3Pattern(pattern);
0060 
0061   // look-up the unsigned values
0062   const unsigned positionCC(lookupTableCCLUT_->cclutPosition(pattern, comparatorCode));
0063   const unsigned slopeCC(lookupTableCCLUT_->cclutSlope(pattern, comparatorCode));
0064   const unsigned run2PatternCC(convertSlopeToRun2Pattern(slopeCC));
0065 
0066   // if the slope is negative, set bending to 0
0067   const bool slopeCCSign((slopeCC >> 4) & 0x1);
0068   const unsigned slopeCCValue(slopeCC & 0xf);
0069   digi.setBend(slopeCCSign);
0070 
0071   // calculate the new position
0072   uint16_t halfstrip = digi.getKeyStrip();
0073   std::tuple<int16_t, bool, bool> stripoffset;
0074   assignPositionCC(positionCC, stripoffset);
0075   const int halfstripoffset = std::get<0>(stripoffset);
0076   halfstrip += halfstripoffset;
0077 
0078   // store the new CFEB, 1/2, 1/4 and 1/8 strip positions
0079   digi.setCFEB(halfstrip / CSCConstants::NUM_HALF_STRIPS_PER_CFEB);
0080   digi.setStrip(halfstrip % CSCConstants::NUM_HALF_STRIPS_PER_CFEB);
0081   digi.setQuartStripBit(std::get<1>(stripoffset));
0082   digi.setEighthStripBit(std::get<2>(stripoffset));
0083 
0084   // store the bending angle value in the pattern data member
0085   digi.setSlope(slopeCCValue);
0086 
0087   // set the quasi Run-2 pattern - to accommodate integration with EMTF/OMTF
0088   digi.setPattern(run2PatternCC);
0089 
0090   // now print out the new CLCT for debugging
0091   if (infoV_ > 2) {
0092     std::ostringstream strm;
0093     strm << "\n";
0094     strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
0095     strm << "+                  CCCLUT algorithm results:                       +\n";
0096     strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
0097     strm << " New CLCT digi " << digi << "\n";
0098     strm << " 1/4 strip bit " << digi.getQuartStripBit() << " 1/8 strip bit " << digi.getEighthStripBit() << "\n";
0099     strm << " 1/4 strip number " << digi.getKeyStrip(4) << " 1/8 strip number " << digi.getKeyStrip(8) << "\n";
0100     strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
0101     LogDebug("ComparatorCodeLUT") << strm.str();
0102   }
0103 }
0104 
0105 int ComparatorCodeLUT::calculateComparatorCode(const pattern& halfStripPattern) const {
0106   int id = 0;
0107 
0108   for (unsigned int column = 0; column < CSCConstants::NUM_LAYERS; column++) {
0109     int rowPat = 0;   //physical arrangement of the three bits
0110     int rowCode = 0;  //code used to identify the arrangement
0111 
0112     //use Firmware definition for comparator code definition
0113     for (int row = 2; row >= 0; row--) {
0114       rowPat = rowPat << 1;  //bitshift the last number to the left
0115       rowPat += halfStripPattern[column][row];
0116     }
0117     switch (rowPat) {
0118       case 0:  //000
0119         rowCode = 0;
0120         break;
0121       case 1:  //00X
0122         rowCode = 1;
0123         break;
0124       case 2:  //0X0
0125         rowCode = 2;
0126         break;
0127       case 4:  //00X
0128         rowCode = 3;
0129         break;
0130       default:
0131         // default return value is -1
0132         return -1;
0133     }
0134     //each column has two bits of information, largest layer is most significant bit
0135     id += (rowCode << 2 * column);
0136   }
0137   return id;
0138 }
0139 
0140 unsigned ComparatorCodeLUT::convertSlopeToRun2Pattern(const unsigned slope) const {
0141   const unsigned slopeList[32] = {10, 10, 10, 8, 8, 8, 6, 6, 6, 4, 4, 4, 2, 2, 2, 2,
0142                                   10, 10, 10, 9, 9, 9, 7, 7, 7, 5, 5, 5, 3, 3, 3, 3};
0143   return slopeList[slope];
0144 }
0145 
0146 void ComparatorCodeLUT::assignPositionCC(const unsigned offset, std::tuple<int16_t, bool, bool>& returnValue) const {
0147   /*
0148     | Value | Half-Strip Offset  | Delta Half-Strip  | Quarter-Strip Bit  | Eighth-Strip Bit |
0149     |-------|--------------------|-------------------|--------------------|------------------|
0150     |   0   |   -7/4             |   -2              |   0                |   1              |
0151     |   1   |   -3/2             |   -2              |   1                |   0              |
0152     |   2   |   -5/4             |   -2              |   1                |   1              |
0153     |   3   |   -1               |   -1              |   0                |   0              |
0154     |   4   |   -3/4             |   -1              |   0                |   1              |
0155     |   5   |   -1/2             |   -1              |   1                |   0              |
0156     |   6   |   -1/4             |   -1              |   1                |   1              |
0157     |   7   |   0                |   0               |   0                |   0              |
0158     |   8   |   1/4              |   0               |   0                |   1              |
0159     |   9   |   1/2              |   0               |   1                |   0              |
0160     |   10  |   3/4              |   0               |   1                |   1              |
0161     |   11  |   1                |   1               |   0                |   0              |
0162     |   12  |   5/4              |   1               |   0                |   1              |
0163     |   13  |   3/2              |   1               |   1                |   0              |
0164     |   14  |   7/4              |   1               |   1                |   1              |
0165     |   15  |   2                |   2               |   0                |   0              |
0166   */
0167   std::vector<std::tuple<int16_t, bool, bool>> my_tuple = {
0168       {-2, false, true},
0169       {-2, true, false},
0170       {-2, true, true},
0171       {-1, false, false},
0172       {-1, false, true},
0173       {-1, true, false},
0174       {-1, true, true},
0175       {0, false, false},
0176       {0, false, true},
0177       {0, true, false},
0178       {0, true, true},
0179       {1, false, false},
0180       {1, false, true},
0181       {1, true, false},
0182       {1, true, true},
0183       {2, false, false},
0184   };
0185   returnValue = my_tuple[offset];
0186 }