File indexing completed on 2024-04-06 12:19:35
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::run(CSCCLCTDigi& digi,
0009 unsigned numCFEBs,
0010 const CSCL1TPLookupTableCCLUT* lookupTableCCLUT) const {
0011
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
0026 digi.setRun3(true);
0027
0028
0029 auto compHits = digi.getHits();
0030
0031
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
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
0050 const int comparatorCode(calculateComparatorCode(compHitsCC));
0051
0052
0053 digi.setCompCode(comparatorCode);
0054
0055
0056 const int pattern(digi.getPattern());
0057
0058
0059 digi.setRun3Pattern(pattern);
0060
0061
0062 const unsigned positionCC(lookupTableCCLUT->cclutPosition(pattern, comparatorCode));
0063 const unsigned slopeCC(lookupTableCCLUT->cclutSlope(pattern, comparatorCode));
0064 const unsigned run2PatternCC(convertSlopeToRun2Pattern(slopeCC));
0065
0066
0067 const bool slopeCCSign((slopeCC >> 4) & 0x1);
0068 const unsigned slopeCCValue(slopeCC & 0xf);
0069 digi.setBend(slopeCCSign);
0070
0071
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
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
0085 digi.setSlope(slopeCCValue);
0086
0087
0088 digi.setPattern(run2PatternCC);
0089
0090
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;
0110 int rowCode = 0;
0111
0112
0113 for (int row = 2; row >= 0; row--) {
0114 rowPat = rowPat << 1;
0115 rowPat += halfStripPattern[column][row];
0116 }
0117 switch (rowPat) {
0118 case 0:
0119 rowCode = 0;
0120 break;
0121 case 1:
0122 rowCode = 1;
0123 break;
0124 case 2:
0125 rowCode = 2;
0126 break;
0127 case 4:
0128 rowCode = 3;
0129 break;
0130 default:
0131
0132 return -1;
0133 }
0134
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
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
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 }