File indexing completed on 2024-09-07 04:36:44
0001 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCUpgradeCathodeLCTProcessor.h"
0002
0003 #include <iomanip>
0004
0005 CSCUpgradeCathodeLCTProcessor::CSCUpgradeCathodeLCTProcessor(unsigned endcap,
0006 unsigned station,
0007 unsigned sector,
0008 unsigned subsector,
0009 unsigned chamber,
0010 CSCBaseboard::Parameters& conf)
0011 : CSCCathodeLCTProcessor(endcap, station, sector, subsector, chamber, conf) {
0012 if (!runPhase2_)
0013 edm::LogError("CSCUpgradeCathodeLCTProcessor|ConfigError")
0014 << "+++ Upgrade CSCUpgradeCathodeLCTProcessor constructed while runPhase2_ is not set! +++\n";
0015
0016
0017 use_dead_time_zoning_ = conf.clctParams().getParameter<bool>("useDeadTimeZoning");
0018 clct_state_machine_zone_ = conf.clctParams().getParameter<unsigned int>("clctStateMachineZone");
0019
0020
0021 pretrig_trig_zone_ = conf.clctParams().getParameter<unsigned int>("clctPretriggerTriggerZone");
0022 }
0023
0024
0025
0026
0027
0028
0029 bool CSCUpgradeCathodeLCTProcessor::preTrigger(const int start_bx, int& first_bx) {
0030 if (runPhase2_ and !use_dead_time_zoning_) {
0031 return CSCCathodeLCTProcessor::preTrigger(start_bx, first_bx);
0032 }
0033
0034 if (infoV > 1)
0035 LogTrace("CSCUpgradeCathodeLCTProcessor")
0036 << "....................PreTrigger, Phase2 version with localized dead time zone...........................";
0037
0038 int nPreTriggers = 0;
0039
0040 bool pre_trig = false;
0041
0042
0043 for (unsigned int bx_time = start_bx; bx_time < fifo_tbins; bx_time++) {
0044
0045
0046
0047
0048
0049 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer> > hits_in_patterns;
0050 hits_in_patterns.clear();
0051
0052 bool hits_in_time = patternFinding(bx_time, hits_in_patterns);
0053 if (hits_in_time) {
0054 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0055 if (infoV > 1) {
0056 if (nhits[hstrip] > 0) {
0057 LogTrace("CSCUpgradeCathodeLCTProcessor")
0058 << " bx = " << std::setw(2) << bx_time << " --->"
0059 << " halfstrip = " << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip]
0060 << " nhits = " << nhits[hstrip];
0061 }
0062 }
0063
0064 if (nhits[hstrip] >= nplanes_hit_pretrig && best_pid[hstrip] >= pid_thresh_pretrig &&
0065 !busyMap_[hstrip][bx_time]) {
0066 pre_trig = true;
0067 ispretrig_[hstrip] = true;
0068
0069
0070 nPreTriggers++;
0071 thePreTriggerDigis.push_back(constructPreCLCT(bx_time, hstrip, nPreTriggers));
0072 }
0073
0074 else if (nhits[hstrip] >= nplanes_hit_pretrig && best_pid[hstrip] >= pid_thresh_pretrig) {
0075 ispretrig_[hstrip] = true;
0076 if (infoV > 1)
0077 LogTrace("CSCUpgradeCathodeLCTProcessor")
0078 << " halfstrip " << std::setw(3) << hstrip << " in dead zone and is pretriggerred";
0079 }
0080
0081 else if (nhits[hstrip] < nplanes_hit_pretrig || best_pid[hstrip] < pid_thresh_pretrig) {
0082 ispretrig_[hstrip] = false;
0083 }
0084 }
0085
0086
0087 markBusyZone(bx_time);
0088
0089 if (pre_trig) {
0090 first_bx = bx_time;
0091 return true;
0092 }
0093 } else {
0094
0095 clearPreTriggers();
0096 }
0097 }
0098
0099 if (infoV > 1)
0100 LogTrace("CSCUpgradeCathodeLCTProcessor") << "no pretrigger, returning \n";
0101 first_bx = fifo_tbins;
0102 return false;
0103 }
0104
0105
0106 std::vector<CSCCLCTDigi> CSCUpgradeCathodeLCTProcessor::findLCTs(
0107 const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER],
0108 const CSCL1TPLookupTableCCLUT* lookupTable) {
0109
0110 if (runPhase2_ and !use_dead_time_zoning_) {
0111 return CSCCathodeLCTProcessor::findLCTs(halfstrip, lookupTable);
0112 }
0113
0114 std::vector<CSCCLCTDigi> lctList;
0115
0116
0117 clearPreTriggers();
0118
0119 if (infoV > 1)
0120 dumpDigis(halfstrip);
0121
0122
0123 for (int i = 0; i < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; i++) {
0124 for (int j = 0; j < CSCConstants::MAX_CLCT_TBINS; j++) {
0125 busyMap_[i][j] = false;
0126 }
0127 }
0128
0129
0130 pulseExtension(halfstrip);
0131
0132 unsigned int start_bx = start_bx_shift;
0133
0134
0135 unsigned int stop_bx = fifo_tbins - drift_delay;
0136
0137
0138
0139 while (start_bx < stop_bx) {
0140
0141 CSCCLCTDigi tempBestCLCT;
0142 CSCCLCTDigi tempSecondCLCT;
0143
0144
0145 int first_bx = 999;
0146
0147
0148 bool pre_trig = CSCUpgradeCathodeLCTProcessor::preTrigger(start_bx, first_bx);
0149
0150
0151
0152 if (pre_trig) {
0153 if (infoV > 1)
0154 LogTrace("CSCUpgradeCathodeLCTProcessor")
0155 << "..... pretrigger at bx = " << first_bx << "; waiting drift delay .....";
0156
0157
0158 int latch_bx = first_bx + drift_delay;
0159
0160
0161 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer> > hits_in_patterns;
0162 hits_in_patterns.clear();
0163
0164
0165
0166 bool hits_in_time = patternFinding(latch_bx, hits_in_patterns);
0167 if (infoV > 1) {
0168 if (hits_in_time) {
0169 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0170 if (nhits[hstrip] > 0) {
0171 LogTrace("CSCUpgradeCathodeLCTProcessor")
0172 << " bx = " << std::setw(2) << latch_bx << " --->"
0173 << " halfstrip = " << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip]
0174 << " nhits = " << nhits[hstrip];
0175 }
0176 }
0177 }
0178 }
0179
0180
0181 int quality[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0182 int best_halfstrip[CSCConstants::MAX_CLCTS_PER_PROCESSOR], best_quality[CSCConstants::MAX_CLCTS_PER_PROCESSOR];
0183 for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++) {
0184 best_halfstrip[ilct] = -1;
0185 best_quality[ilct] = 0;
0186 }
0187
0188 bool pretrig_zone[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0189
0190
0191
0192 if (hits_in_time) {
0193
0194
0195 markPreTriggerZone(first_bx, pretrig_zone);
0196
0197 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210 quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
0211
0212
0213
0214 if (quality[hstrip] > best_quality[0] && pretrig_zone[hstrip] && !busyMap_[hstrip][first_bx]) {
0215 best_halfstrip[0] = hstrip;
0216 best_quality[0] = quality[hstrip];
0217
0218 const int best_hs(best_halfstrip[0]);
0219 const int best_pat(best_pid[best_hs]);
0220
0221 if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
0222
0223 tempBestCLCT = constructCLCT(first_bx, best_hs, hits_in_patterns[best_hs][best_pat], lookupTable);
0224 }
0225 }
0226 }
0227 }
0228
0229
0230 if (best_halfstrip[0] >= 0) {
0231
0232
0233
0234 const unsigned halfStripBestCLCT(tempBestCLCT.getKeyStrip() + stagger[CSCConstants::KEY_CLCT_LAYER - 1]);
0235
0236
0237
0238
0239 markBusyKeys(halfStripBestCLCT, best_pid[halfStripBestCLCT], quality);
0240
0241 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0242
0243 if (quality[hstrip] > best_quality[1] && pretrig_zone[hstrip] && !busyMap_[hstrip][first_bx]) {
0244 best_halfstrip[1] = hstrip;
0245 best_quality[1] = quality[hstrip];
0246
0247 const int best_hs(best_halfstrip[1]);
0248 const int best_pat(best_pid[best_hs]);
0249
0250 if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
0251
0252 tempSecondCLCT = constructCLCT(first_bx, best_hs, hits_in_patterns[best_hs][best_pat], lookupTable);
0253 }
0254 }
0255 }
0256
0257
0258
0259
0260 bool changeOrder = false;
0261
0262 unsigned qualityBest = 0, qualitySecond = 0;
0263 unsigned patternBest = 0, patternSecond = 0;
0264 unsigned halfStripBest = 0, halfStripSecond = 0;
0265
0266 if (tempBestCLCT.isValid() and tempSecondCLCT.isValid()) {
0267 qualityBest = tempBestCLCT.getQuality();
0268 qualitySecond = tempSecondCLCT.getQuality();
0269 if (!run3_) {
0270 patternBest = tempBestCLCT.getPattern();
0271 patternSecond = tempSecondCLCT.getPattern();
0272 } else {
0273 patternBest = tempBestCLCT.getRun3Pattern();
0274 patternSecond = tempSecondCLCT.getRun3Pattern();
0275 }
0276 halfStripBest = tempBestCLCT.getKeyStrip();
0277 halfStripSecond = tempSecondCLCT.getKeyStrip();
0278
0279 if (qualitySecond > qualityBest)
0280 changeOrder = true;
0281 else if ((qualitySecond == qualityBest) and (int(patternSecond / 2) > int(patternBest / 2)))
0282 changeOrder = true;
0283 else if ((qualitySecond == qualityBest) and (int(patternSecond / 2) == int(patternBest / 2)) and
0284 (halfStripSecond < halfStripBest))
0285 changeOrder = true;
0286 }
0287
0288 CSCCLCTDigi tempCLCT;
0289 if (changeOrder) {
0290 tempCLCT = tempBestCLCT;
0291 tempBestCLCT = tempSecondCLCT;
0292 tempSecondCLCT = tempCLCT;
0293 }
0294
0295
0296 if (tempBestCLCT.isValid()) {
0297 lctList.push_back(tempBestCLCT);
0298 }
0299 if (tempSecondCLCT.isValid()) {
0300 lctList.push_back(tempSecondCLCT);
0301 }
0302 }
0303 }
0304
0305
0306 start_bx = first_bx + 1;
0307 }
0308 return lctList;
0309 }
0310
0311 void CSCUpgradeCathodeLCTProcessor::markPreTriggerZone(
0312 int bx, bool pretrig_zone[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const {
0313
0314 for (int hstrip = 0; hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; hstrip++) {
0315 pretrig_zone[hstrip] = false;
0316 }
0317
0318 for (int hstrip = 0; hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; hstrip++) {
0319 if (ispretrig_[hstrip] && !busyMap_[hstrip][bx]) {
0320 int min_hs = hstrip - pretrig_trig_zone_;
0321 int max_hs = hstrip + pretrig_trig_zone_;
0322
0323 if (min_hs < 0)
0324 min_hs = 0;
0325
0326 if (max_hs > CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER - 1)
0327 max_hs = CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER - 1;
0328
0329 for (int hs = min_hs; hs <= max_hs; hs++)
0330 pretrig_zone[hs] = true;
0331 if (infoV > 1)
0332 LogTrace("CSCUpgradeCathodeLCTProcessor")
0333 << " marked pretrigger halfstrip zone [" << min_hs << "," << max_hs << "]";
0334 }
0335 }
0336 }
0337
0338 void CSCUpgradeCathodeLCTProcessor::markBusyZone(const int bx) {
0339 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0340
0341 if (ispretrig_[hstrip]) {
0342
0343 int min_hstrip = hstrip - clct_state_machine_zone_;
0344 int max_hstrip = hstrip + clct_state_machine_zone_;
0345
0346 if (min_hstrip < stagger[CSCConstants::KEY_CLCT_LAYER - 1])
0347 min_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1];
0348
0349 if (max_hstrip >= numHalfStrips_)
0350 max_hstrip = numHalfStrips_ - 1;
0351
0352 for (int hs = min_hstrip; hs <= max_hstrip; hs++)
0353 busyMap_[hs][bx + 1] = true;
0354 if (infoV > 1)
0355 LogTrace("CSCUpgradeCathodeLCTProcessor")
0356 << " marked zone around pretriggerred halfstrip " << hstrip << " as dead zone for pretriggering at bx"
0357 << bx + 1 << " halfstrip: [" << min_hstrip << "," << max_hstrip << "]";
0358 }
0359 }
0360 }