File indexing completed on 2024-04-06 12:10:27
0001 #include "EventFilter/CSCRawToDigi/interface/CSCTMBHeader2020_CCLUT.h"
0002 #include "EventFilter/CSCRawToDigi/interface/CSCDMBHeader.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004
0005 const std::vector<std::pair<unsigned, unsigned> >
0006 run3_pattern_lookup_tbl = {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4},
0007 {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 0}, {1, 1}, {1, 2}, {1, 3},
0008 {1, 4}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {3, 0}, {3, 1}, {3, 2},
0009 {3, 3}, {3, 4}, {4, 0}, {4, 1}, {4, 2}, {4, 3}, {4, 4}};
0010
0011 const unsigned run2_pattern_lookup_tbl[2][16] = {{10, 10, 10, 8, 8, 8, 6, 6, 6, 4, 4, 4, 2, 2, 2, 2},
0012 {10, 10, 10, 9, 9, 9, 7, 7, 7, 5, 5, 5, 3, 3, 3, 3}};
0013
0014 CSCTMBHeader2020_CCLUT::CSCTMBHeader2020_CCLUT() {
0015 bzero(data(), sizeInWords() * 2);
0016 bits.nHeaderFrames = 42;
0017 bits.e0bline = 0x6E0B;
0018 bits.b0cline = 0xDB0C;
0019 bits.firmRevCode = 0x401;
0020 bits.nTBins = 12;
0021 bits.nCFEBs = 7;
0022 }
0023
0024 CSCTMBHeader2020_CCLUT::CSCTMBHeader2020_CCLUT(const unsigned short* buf) { memcpy(data(), buf, sizeInWords() * 2); }
0025
0026 void CSCTMBHeader2020_CCLUT::setEventInformation(const CSCDMBHeader& dmbHeader) {
0027 bits.cscID = dmbHeader.dmbID();
0028 bits.l1aNumber = dmbHeader.l1a();
0029 bits.bxnCount = dmbHeader.bxn();
0030 }
0031
0032
0033 std::vector<CSCCLCTDigi> CSCTMBHeader2020_CCLUT::CLCTDigis(uint32_t idlayer) {
0034 std::vector<CSCCLCTDigi> result;
0035 unsigned halfstrip = bits.clct0_key_low + (bits.clct0_key_high << 7);
0036 unsigned strip = halfstrip % 32;
0037
0038 bool quartstrip = (bits.clct0_xky >> 1) & 0x1;
0039
0040 bool eighthstrip = bits.clct0_xky & 0x1;
0041 unsigned cfeb = halfstrip / 32;
0042
0043
0044 unsigned run3_pattern = bits.clct0_shape & 0x7;
0045 unsigned bend = bits.clct0_LR_bend;
0046 unsigned slope = bits.clct0_slope;
0047 unsigned run2_pattern = run2_pattern_lookup_tbl[bend][slope];
0048
0049 CSCCLCTDigi digi0(bits.clct0_valid,
0050 bits.clct0_quality,
0051 run2_pattern,
0052 1,
0053 bend,
0054 strip,
0055 cfeb,
0056 bits.clct_bxn,
0057 1,
0058 bits.bxnPreTrigger,
0059 bits.clct0_comparator_code,
0060 CSCCLCTDigi::Version::Run3,
0061 quartstrip,
0062 eighthstrip,
0063 run3_pattern,
0064 slope);
0065
0066 halfstrip = bits.clct1_key_low + (bits.clct1_key_high << 7);
0067 strip = halfstrip % 32;
0068
0069 quartstrip = (bits.clct1_xky >> 1) & 0x1;
0070
0071 eighthstrip = bits.clct1_xky & 0x1;
0072 cfeb = halfstrip / 32;
0073
0074
0075 run3_pattern = bits.clct1_shape & 0x7;
0076 bend = bits.clct1_LR_bend;
0077 slope = bits.clct1_slope;
0078 run2_pattern = run2_pattern_lookup_tbl[bend][slope];
0079
0080 CSCCLCTDigi digi1(bits.clct1_valid,
0081 bits.clct1_quality,
0082 run2_pattern,
0083 1,
0084 bend,
0085 strip,
0086 cfeb,
0087 bits.clct_bxn,
0088 2,
0089 bits.bxnPreTrigger,
0090 bits.clct1_comparator_code,
0091 CSCCLCTDigi::Version::Run3,
0092 quartstrip,
0093 eighthstrip,
0094 run3_pattern,
0095 slope);
0096
0097 result.push_back(digi0);
0098 result.push_back(digi1);
0099 return result;
0100 }
0101
0102
0103 std::vector<CSCCorrelatedLCTDigi> CSCTMBHeader2020_CCLUT::CorrelatedLCTDigis(uint32_t idlayer) const {
0104 std::vector<CSCCorrelatedLCTDigi> result;
0105
0106 unsigned strip = bits.MPC_Muon0_clct_key_halfstrip;
0107 unsigned slope = (bits.MPC_Muon0_clct_bend_low & 0x7) | (bits.MPC_Muon0_clct_bend_bit4 << 3);
0108 unsigned hmt = bits.MPC_Muon_HMT_bit0 | (bits.MPC_Muon_HMT_high << 1);
0109 unsigned clct_pattern_id = bits.MPC_Muon_clct_pattern_low | (bits.MPC_Muon_clct_pattern_bit5 << 4);
0110
0111 std::pair<unsigned, unsigned> run3_pattern_pair = run3_pattern_lookup_tbl[clct_pattern_id % 30];
0112 unsigned run2_pattern = run2_pattern_lookup_tbl[bits.MPC_Muon0_clct_LR][slope];
0113 unsigned run3_pattern = run3_pattern_pair.second & 0x7;
0114
0115 CSCCorrelatedLCTDigi digi(1,
0116 bits.MPC_Muon0_lct_vpf,
0117 bits.MPC_Muon0_lct_quality,
0118 bits.MPC_Muon0_alct_key_wire,
0119 strip,
0120 run2_pattern,
0121 bits.MPC_Muon0_clct_LR,
0122 bits.MPC_Muon_alct_bxn,
0123 0,
0124 bits.MPC_Muon0_clct_bx0,
0125 0,
0126 0,
0127 CSCCorrelatedLCTDigi::Version::Run3,
0128 bits.MPC_Muon0_clct_QuarterStrip,
0129 bits.MPC_Muon0_clct_EighthStrip,
0130 run3_pattern,
0131 slope);
0132 digi.setHMT(hmt);
0133 result.push_back(digi);
0134
0135 strip = bits.MPC_Muon1_clct_key_halfstrip;
0136 slope = (bits.MPC_Muon1_clct_bend_low & 0x7) | (bits.MPC_Muon1_clct_bend_bit4 << 3);
0137 run2_pattern = run2_pattern_lookup_tbl[bits.MPC_Muon1_clct_LR][slope];
0138 run3_pattern = run3_pattern_pair.first & 0x7;
0139
0140 digi = CSCCorrelatedLCTDigi(2,
0141 bits.MPC_Muon1_lct_vpf,
0142 bits.MPC_Muon1_lct_quality,
0143 bits.MPC_Muon1_alct_key_wire,
0144 strip,
0145 run2_pattern,
0146 bits.MPC_Muon1_clct_LR,
0147 bits.MPC_Muon_alct_bxn,
0148 0,
0149 bits.MPC_Muon1_clct_bx0,
0150 0,
0151 0,
0152 CSCCorrelatedLCTDigi::Version::Run3,
0153 bits.MPC_Muon1_clct_QuarterStrip,
0154 bits.MPC_Muon1_clct_EighthStrip,
0155 run3_pattern,
0156 slope);
0157 digi.setHMT(hmt);
0158 result.push_back(digi);
0159 return result;
0160 }
0161
0162 CSCShowerDigi CSCTMBHeader2020_CCLUT::showerDigi(uint32_t idlayer) const {
0163 unsigned hmt_bits = bits.MPC_Muon_HMT_bit0 | (bits.MPC_Muon_HMT_high << 1);
0164 uint16_t cscid = bits.cscID;
0165
0166
0167
0168 uint16_t bx = CSCConstants::LCT_CENTRAL_BX - bits.pop_l1a_match_win;
0169
0170 CSCShowerDigi result(hmt_bits & 0x3,
0171 (hmt_bits >> 2) & 0x3,
0172 cscid,
0173 bx,
0174 CSCShowerDigi::ShowerType::kLCTShower,
0175 0,
0176 hmt_nhits());
0177 return result;
0178 }
0179
0180 CSCShowerDigi CSCTMBHeader2020_CCLUT::anodeShowerDigi(uint32_t idlayer) const {
0181 uint16_t cscid = bits.cscID;
0182 uint16_t bx = CSCConstants::LCT_CENTRAL_BX - bits.pop_l1a_match_win;
0183
0184 CSCShowerDigi result(
0185 bits.anode_hmt & 0x3, 0, cscid, bx, CSCShowerDigi::ShowerType::kALCTShower, 0, 0);
0186 return result;
0187 }
0188
0189 CSCShowerDigi CSCTMBHeader2020_CCLUT::cathodeShowerDigi(uint32_t idlayer) const {
0190 uint16_t cscid = bits.cscID;
0191 uint16_t bx = CSCConstants::LCT_CENTRAL_BX - bits.pop_l1a_match_win - bits.hmt_match_win + 3;
0192
0193 CSCShowerDigi result(bits.cathode_hmt & 0x3,
0194 0,
0195 cscid,
0196 bx,
0197 CSCShowerDigi::ShowerType::kCLCTShower,
0198 0,
0199 hmt_nhits());
0200 return result;
0201 }
0202
0203 void CSCTMBHeader2020_CCLUT::addALCT0(const CSCALCTDigi& digi) {
0204 throw cms::Exception("In CSC TMBHeaderFormat 2007, ALCTs belong in ALCT header");
0205 }
0206
0207 void CSCTMBHeader2020_CCLUT::addALCT1(const CSCALCTDigi& digi) {
0208 throw cms::Exception("In CSC TMBHeaderFormat 2007, ALCTs belong in ALCT header");
0209 }
0210
0211 void CSCTMBHeader2020_CCLUT::addCLCT0(const CSCCLCTDigi& digi) {
0212 unsigned halfStrip = digi.getKeyStrip();
0213 unsigned pattern = digi.getRun3Pattern();
0214 bits.clct0_valid = digi.isValid();
0215 bits.clct0_quality = digi.getQuality();
0216 bits.clct0_shape = pattern;
0217
0218 bits.clct0_key_low = halfStrip & (0x7F);
0219
0220 bits.clct0_key_high = (halfStrip >> 7) & (0x1);
0221 bits.clct_bxn = digi.getBX();
0222 bits.bxnPreTrigger = digi.getFullBX();
0223 bits.clct0_comparator_code = digi.getCompCode();
0224 bits.clct0_xky = (digi.getEighthStripBit() & 0x1) + ((digi.getQuartStripBit() & 0x1) << 1);
0225 bits.clct0_LR_bend = digi.getBend();
0226 bits.clct0_slope = digi.getSlope();
0227 }
0228
0229 void CSCTMBHeader2020_CCLUT::addCLCT1(const CSCCLCTDigi& digi) {
0230 unsigned halfStrip = digi.getKeyStrip();
0231 unsigned pattern = digi.getRun3Pattern();
0232 bits.clct1_valid = digi.isValid();
0233 bits.clct1_quality = digi.getQuality();
0234 bits.clct1_shape = pattern;
0235
0236 bits.clct1_key_low = halfStrip & (0x7F);
0237
0238 bits.clct1_key_high = (halfStrip >> 7) & (0x1);
0239
0240
0241 bits.bxnPreTrigger = digi.getFullBX();
0242 bits.clct1_comparator_code = digi.getCompCode();
0243 bits.clct1_xky = (digi.getEighthStripBit() & 0x1) + ((digi.getQuartStripBit() & 0x1) << 1);
0244 bits.clct1_LR_bend = digi.getBend();
0245 bits.clct1_slope = digi.getSlope();
0246 }
0247
0248 void CSCTMBHeader2020_CCLUT::addCorrelatedLCT0(const CSCCorrelatedLCTDigi& digi) {
0249 bits.MPC_Muon0_lct_vpf = digi.isValid();
0250 bits.MPC_Muon0_alct_key_wire = digi.getKeyWG();
0251 bits.MPC_Muon0_clct_key_halfstrip = digi.getStrip(2) & 0xFF;
0252 bits.MPC_Muon0_clct_QuarterStrip = digi.getQuartStripBit() & 0x1;
0253 bits.MPC_Muon0_clct_EighthStrip = digi.getEighthStripBit() & 0x1;
0254 bits.MPC_Muon0_lct_quality = digi.getQuality() & 0x7;
0255
0256
0257 uint16_t run3_pattern = digi.getRun3Pattern();
0258 bits.MPC_Muon_clct_pattern_low = run3_pattern & 0xF;
0259 bits.MPC_Muon_clct_pattern_bit5 = (run3_pattern >> 4) & 0x1;
0260 bits.MPC_Muon0_clct_bend_low = digi.getSlope() & 0x7;
0261 bits.MPC_Muon0_clct_bend_bit4 = (digi.getSlope() >> 3) & 0x1;
0262 bits.MPC_Muon0_clct_LR = digi.getBend() & 0x1;
0263 bits.MPC_Muon_HMT_bit0 = digi.getHMT() & 0x1;
0264 bits.MPC_Muon_HMT_high = (digi.getHMT() >> 1) & 0x7;
0265 bits.MPC_Muon_alct_bxn = digi.getBX();
0266 bits.MPC_Muon0_clct_bx0 = digi.getBX0();
0267 }
0268
0269 void CSCTMBHeader2020_CCLUT::addCorrelatedLCT1(const CSCCorrelatedLCTDigi& digi) {
0270 bits.MPC_Muon1_lct_vpf = digi.isValid();
0271 bits.MPC_Muon1_alct_key_wire = digi.getKeyWG();
0272 bits.MPC_Muon1_clct_key_halfstrip = digi.getStrip(2) & 0xFF;
0273 bits.MPC_Muon1_clct_QuarterStrip = digi.getQuartStripBit() & 0x1;
0274 bits.MPC_Muon1_clct_EighthStrip = digi.getEighthStripBit() & 0x1;
0275 bits.MPC_Muon1_lct_quality = digi.getQuality() & 0x7;
0276
0277
0278
0279 if (digi.isValid()) {
0280 uint16_t clct_pattern_id = bits.MPC_Muon_clct_pattern_low | (bits.MPC_Muon_clct_pattern_bit5 << 4);
0281 uint16_t run3_pattern = digi.getRun3Pattern();
0282 clct_pattern_id = (clct_pattern_id + (run3_pattern + 1) * 5) % 30;
0283 bits.MPC_Muon_clct_pattern_low = clct_pattern_id & 0xF;
0284 bits.MPC_Muon_clct_pattern_bit5 = (clct_pattern_id >> 4) & 0x1;
0285 }
0286 bits.MPC_Muon1_clct_bend_low = digi.getSlope() & 0x7;
0287 bits.MPC_Muon1_clct_bend_bit4 = (digi.getSlope() >> 3) & 0x1;
0288 bits.MPC_Muon1_clct_LR = digi.getBend() & 0x1;
0289 bits.MPC_Muon_HMT_bit0 = digi.getHMT() & 0x1;
0290 bits.MPC_Muon_HMT_high = (digi.getHMT() >> 1) & 0x7;
0291 bits.MPC_Muon_alct_bxn = digi.getBX();
0292 bits.MPC_Muon1_clct_bx0 = digi.getBX0();
0293 }
0294
0295 void CSCTMBHeader2020_CCLUT::addShower(const CSCShowerDigi& digi) {
0296 uint16_t hmt_bits = digi.isValid() ? (digi.bitsInTime() & 0x3) + ((digi.bitsOutOfTime() & 0x3) << 2)
0297
0298 : ((digi.bitsOutOfTime() & 0x3) << 2);
0299 bits.MPC_Muon_HMT_bit0 = hmt_bits & 0x1;
0300 bits.MPC_Muon_HMT_high = (hmt_bits >> 1) & 0x7;
0301
0302 if (digi.isValid())
0303 bits.pop_l1a_match_win = CSCConstants::LCT_CENTRAL_BX - digi.getBX();
0304 else
0305 bits.pop_l1a_match_win = 3;
0306 }
0307
0308 void CSCTMBHeader2020_CCLUT::addAnodeShower(const CSCShowerDigi& digi) {
0309 uint16_t hmt_bits = digi.bitsInTime() & 0x3;
0310 if (not digi.isValid())
0311 hmt_bits = 0;
0312 bits.anode_hmt = hmt_bits;
0313 if (not(bits.MPC_Muon_HMT_bit0 or bits.MPC_Muon_HMT_high) and digi.isValid())
0314 bits.pop_l1a_match_win = CSCConstants::LCT_CENTRAL_BX - digi.getBX();
0315 else if (not(digi.isValid()))
0316 bits.pop_l1a_match_win = 3;
0317 }
0318
0319 void CSCTMBHeader2020_CCLUT::addCathodeShower(const CSCShowerDigi& digi) {
0320 uint16_t hmt_bits = digi.bitsInTime() & 0x3;
0321 if (not digi.isValid())
0322 hmt_bits = 0;
0323 bits.cathode_hmt = hmt_bits;
0324 bits.hmt_nhits_bit0 = digi.getComparatorNHits() & 0x1;
0325 bits.hmt_nhits_bit1 = (digi.getComparatorNHits() >> 1) & 0x1;
0326 bits.hmt_nhits_bits_high = (digi.getComparatorNHits() >> 2) & 0x1F;
0327 if (bits.MPC_Muon_HMT_bit0 or bits.MPC_Muon_HMT_high or bits.anode_hmt) {
0328
0329 bits.hmt_match_win = CSCConstants::LCT_CENTRAL_BX - bits.pop_l1a_match_win + 3 - digi.getBX();
0330 } else if (digi.isValid()) {
0331 bits.pop_l1a_match_win = 3;
0332 bits.hmt_match_win = CSCConstants::LCT_CENTRAL_BX - digi.getBX();
0333 } else {
0334 bits.pop_l1a_match_win = 3;
0335 bits.hmt_match_win = 0;
0336 }
0337 }
0338
0339 void CSCTMBHeader2020_CCLUT::print(std::ostream& os) const {
0340 os << "...............(O)TMB2020 CCLUT/HMT Header.................."
0341 << "\n";
0342 os << std::hex << "BOC LINE " << bits.b0cline << " EOB " << bits.e0bline << "\n";
0343 os << std::hex << "FW revision: 0x" << bits.firmRevCode << "\n";
0344 os << std::dec << "fifoMode = " << bits.fifoMode << ", nTBins = " << bits.nTBins << "\n";
0345 os << "boardID = " << bits.boardID << ", cscID = " << bits.cscID << "\n";
0346 os << "l1aNumber = " << bits.l1aNumber << ", bxnCount = " << bits.bxnCount << "\n";
0347 os << "trigSourceVect = " << bits.trigSourceVect << ", run3_trig_df = " << bits.run3_trig_df << ", activeCFEBs = 0x"
0348 << std::hex << (bits.activeCFEBs | (bits.activeCFEBs_2 << 5)) << ", readCFEBs = 0x" << std::hex
0349 << (bits.readCFEBs | (bits.readCFEBs_2 << 5)) << std::dec << "\n";
0350 os << "bxnPreTrigger = " << bits.bxnPreTrigger << "\n";
0351 os << "ALCT location in CLCT window " << bits.matchWin << " L1A location in TMB window " << bits.pop_l1a_match_win
0352 << " ALCT in cathde HMT window " << bits.hmt_match_win << "\n";
0353 os << "tmbMatch = " << bits.tmbMatch << " alctOnly = " << bits.alctOnly << " clctOnly = " << bits.clctOnly << "\n";
0354
0355 os << "readoutCounter: " << std::dec << bits.readoutCounter << ", buf_q_ovf: " << bits.stackOvf
0356 << ", sync_err: " << bits.syncError << ", has_buf: " << bits.hasBuf << ", buf_stalled: " << bits.bufFull << "\n";
0357 os << "r_wr_buf_adr: 0x" << std::hex << bits.r_wr_buf_adr << ", r_wr_buf_ready: " << bits.r_wr_buf_ready
0358 << ", wr_buf_ready: " << bits.wr_buf_ready << ", buf_q_full: " << bits.buf_q_full
0359 << ", buf_q_empty: " << bits.buf_q_empty << ",\nr_buf_fence_dist: 0x" << bits.r_buf_fence_dist
0360 << ", buf_q_ovf_err: " << bits.buf_q_ovf_err << ", buf_q_udf_err: " << bits.buf_q_udf_err
0361 << ", buf_q_adr_err: " << bits.buf_q_adr_err << ", buf_stalled: " << bits.buf_stalled << ",\nbuf_fence_cnt: 0x"
0362 << bits.buf_fence_cnt << ", reverse_hs_csc: " << bits.reverse_hs_csc
0363 << ", reverse_hs_me1a: " << bits.reverse_hs_me1a << ", reverse_hs_me1b: " << bits.reverse_hs_me1b << "\n";
0364 os << "CLCT Words:\n"
0365 << " bits.clct0_valid = " << bits.clct0_valid << " bits.clct0_shape = " << bits.clct0_shape
0366 << " bits.clct0_quality = " << bits.clct0_quality
0367 << " halfstrip = " << (bits.clct0_key_low + (bits.clct0_key_high << 7)) << "\n";
0368 os << " bits.clct0_xky = " << bits.clct0_xky << " bits.clct0_comparator_code = " << bits.clct0_comparator_code
0369 << " bits.clct0_LR_bend = " << bits.clct0_LR_bend << " bits.clct0_slope = " << bits.clct0_slope << "\n";
0370
0371 os << " bits.clct1_valid = " << bits.clct1_valid << " bits.clct1_shape = " << bits.clct1_shape
0372 << " bits.clct1_quality = " << bits.clct1_quality
0373 << " halfstrip = " << (bits.clct1_key_low + (bits.clct1_key_high << 7)) << "\n";
0374 os << " bits.clct1_xky = " << bits.clct1_xky << " bits.clct1_comparator_code = " << bits.clct1_comparator_code
0375 << " bits.clct1_LR_bend = " << bits.clct1_LR_bend << " bits.clct1_slope = " << bits.clct1_slope << "\n";
0376
0377 os << "MPC Words:\n"
0378 << " LCT0 valid = " << bits.MPC_Muon0_lct_vpf << " key WG = " << bits.MPC_Muon0_alct_key_wire
0379 << " key halfstrip = " << bits.MPC_Muon0_clct_key_halfstrip
0380 << " 1/4strip flag = " << bits.MPC_Muon0_clct_QuarterStrip
0381 << " 1/8strip flag = " << bits.MPC_Muon0_clct_EighthStrip << "\n"
0382 << " quality = " << bits.MPC_Muon0_lct_quality
0383 << " slope/bend = " << ((bits.MPC_Muon0_clct_bend_low & 0x7) | (bits.MPC_Muon0_clct_bend_bit4 << 3))
0384 << " L/R bend = " << bits.MPC_Muon0_clct_LR << "\n";
0385
0386 os << " LCT1 valid = " << bits.MPC_Muon1_lct_vpf << " key WG = " << bits.MPC_Muon1_alct_key_wire
0387 << " key halfstrip = " << bits.MPC_Muon1_clct_key_halfstrip
0388 << " 1/4strip flag = " << bits.MPC_Muon1_clct_QuarterStrip
0389 << " 1/8strip flag = " << bits.MPC_Muon1_clct_EighthStrip << "\n"
0390 << " quality = " << bits.MPC_Muon1_lct_quality
0391 << " slope/bend = " << ((bits.MPC_Muon1_clct_bend_low & 0x7) | (bits.MPC_Muon1_clct_bend_bit4 << 3))
0392 << " L/R bend = " << bits.MPC_Muon1_clct_LR << "\n";
0393
0394 os << " clct_5bit_pattern_id = " << (bits.MPC_Muon_clct_pattern_low | (bits.MPC_Muon_clct_pattern_bit5 << 4))
0395 << " HMT = " << (bits.MPC_Muon_HMT_bit0 | (bits.MPC_Muon_HMT_high << 1)) << ", alctHMT = " << bits.anode_hmt
0396 << ", clctHMT = " << bits.cathode_hmt << " cathode nhits " << hmt_nhits() << "\n";
0397 }