File indexing completed on 2023-03-17 11:11:02
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 const edm::ParameterSet& 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_ = clctParams_.getParameter<bool>("useDeadTimeZoning");
0018 clct_state_machine_zone_ = clctParams_.getParameter<unsigned int>("clctStateMachineZone");
0019
0020
0021 pretrig_trig_zone_ = 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
0109 if (runPhase2_ and !use_dead_time_zoning_) {
0110 return CSCCathodeLCTProcessor::findLCTs(halfstrip);
0111 }
0112
0113 std::vector<CSCCLCTDigi> lctList;
0114
0115
0116 clearPreTriggers();
0117
0118 if (infoV > 1)
0119 dumpDigis(halfstrip);
0120
0121
0122 for (int i = 0; i < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; i++) {
0123 for (int j = 0; j < CSCConstants::MAX_CLCT_TBINS; j++) {
0124 busyMap_[i][j] = false;
0125 }
0126 }
0127
0128
0129 pulseExtension(halfstrip);
0130
0131 unsigned int start_bx = start_bx_shift;
0132
0133
0134 unsigned int stop_bx = fifo_tbins - drift_delay;
0135
0136
0137
0138 while (start_bx < stop_bx) {
0139
0140 CSCCLCTDigi tempBestCLCT;
0141 CSCCLCTDigi tempSecondCLCT;
0142
0143
0144 int first_bx = 999;
0145
0146
0147 bool pre_trig = CSCUpgradeCathodeLCTProcessor::preTrigger(start_bx, first_bx);
0148
0149
0150
0151 if (pre_trig) {
0152 if (infoV > 1)
0153 LogTrace("CSCUpgradeCathodeLCTProcessor")
0154 << "..... pretrigger at bx = " << first_bx << "; waiting drift delay .....";
0155
0156
0157 int latch_bx = first_bx + drift_delay;
0158
0159
0160 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer> > hits_in_patterns;
0161 hits_in_patterns.clear();
0162
0163
0164
0165 bool hits_in_time = patternFinding(latch_bx, hits_in_patterns);
0166 if (infoV > 1) {
0167 if (hits_in_time) {
0168 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0169 if (nhits[hstrip] > 0) {
0170 LogTrace("CSCUpgradeCathodeLCTProcessor")
0171 << " bx = " << std::setw(2) << latch_bx << " --->"
0172 << " halfstrip = " << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip]
0173 << " nhits = " << nhits[hstrip];
0174 }
0175 }
0176 }
0177 }
0178
0179
0180 int quality[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0181 int best_halfstrip[CSCConstants::MAX_CLCTS_PER_PROCESSOR], best_quality[CSCConstants::MAX_CLCTS_PER_PROCESSOR];
0182 for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++) {
0183 best_halfstrip[ilct] = -1;
0184 best_quality[ilct] = 0;
0185 }
0186
0187 bool pretrig_zone[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0188
0189
0190
0191 if (hits_in_time) {
0192
0193
0194 markPreTriggerZone(pretrig_zone);
0195
0196 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209 quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
0210
0211
0212
0213 if (quality[hstrip] > best_quality[0] && pretrig_zone[hstrip] && !busyMap_[hstrip][first_bx]) {
0214 best_halfstrip[0] = hstrip;
0215 best_quality[0] = quality[hstrip];
0216
0217 const int best_hs(best_halfstrip[0]);
0218 const int best_pat(best_pid[best_hs]);
0219
0220 if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
0221
0222 tempBestCLCT = constructCLCT(first_bx, best_hs, hits_in_patterns[best_hs][best_pat]);
0223 }
0224 }
0225 }
0226 }
0227
0228
0229 if (best_halfstrip[0] >= 0) {
0230
0231
0232
0233 const unsigned halfStripBestCLCT(tempBestCLCT.getKeyStrip() + stagger[CSCConstants::KEY_CLCT_LAYER - 1]);
0234
0235
0236
0237
0238 markBusyKeys(halfStripBestCLCT, best_pid[halfStripBestCLCT], quality);
0239
0240 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0241
0242 if (quality[hstrip] > best_quality[1] && pretrig_zone[hstrip] && !busyMap_[hstrip][first_bx]) {
0243 best_halfstrip[1] = hstrip;
0244 best_quality[1] = quality[hstrip];
0245
0246 const int best_hs(best_halfstrip[1]);
0247 const int best_pat(best_pid[best_hs]);
0248
0249 if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
0250
0251 tempSecondCLCT = constructCLCT(first_bx, best_hs, hits_in_patterns[best_hs][best_pat]);
0252 }
0253 }
0254 }
0255
0256
0257
0258
0259 bool changeOrder = false;
0260
0261 unsigned qualityBest = 0, qualitySecond = 0;
0262 unsigned patternBest = 0, patternSecond = 0;
0263 unsigned halfStripBest = 0, halfStripSecond = 0;
0264
0265 if (tempBestCLCT.isValid() and tempSecondCLCT.isValid()) {
0266 qualityBest = tempBestCLCT.getQuality();
0267 qualitySecond = tempSecondCLCT.getQuality();
0268 if (!run3_) {
0269 patternBest = tempBestCLCT.getPattern();
0270 patternSecond = tempSecondCLCT.getPattern();
0271 } else {
0272 patternBest = tempBestCLCT.getRun3Pattern();
0273 patternSecond = tempSecondCLCT.getRun3Pattern();
0274 }
0275 halfStripBest = tempBestCLCT.getKeyStrip();
0276 halfStripSecond = tempSecondCLCT.getKeyStrip();
0277
0278 if (qualitySecond > qualityBest)
0279 changeOrder = true;
0280 else if ((qualitySecond == qualityBest) and (int(patternSecond / 2) > int(patternBest / 2)))
0281 changeOrder = true;
0282 else if ((qualitySecond == qualityBest) and (int(patternSecond / 2) == int(patternBest / 2)) and
0283 (halfStripSecond < halfStripBest))
0284 changeOrder = true;
0285 }
0286
0287 CSCCLCTDigi tempCLCT;
0288 if (changeOrder) {
0289 tempCLCT = tempBestCLCT;
0290 tempBestCLCT = tempSecondCLCT;
0291 tempSecondCLCT = tempCLCT;
0292 }
0293
0294
0295 if (tempBestCLCT.isValid()) {
0296 lctList.push_back(tempBestCLCT);
0297 }
0298 if (tempSecondCLCT.isValid()) {
0299 lctList.push_back(tempSecondCLCT);
0300 }
0301 }
0302 }
0303
0304
0305 start_bx = first_bx + 1;
0306 }
0307 return lctList;
0308 }
0309
0310 void CSCUpgradeCathodeLCTProcessor::markPreTriggerZone(
0311 bool pretrig_zone[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const {
0312
0313 for (int hstrip = 0; hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; hstrip++) {
0314 pretrig_zone[hstrip] = false;
0315 }
0316
0317 for (int hstrip = 0; hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; hstrip++) {
0318 if (ispretrig_[hstrip]) {
0319 int min_hs = hstrip - pretrig_trig_zone_;
0320 int max_hs = hstrip + pretrig_trig_zone_;
0321
0322 if (min_hs < 0)
0323 min_hs = 0;
0324
0325 if (max_hs > CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER - 1)
0326 max_hs = CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER - 1;
0327
0328 for (int hs = min_hs; hs <= max_hs; hs++)
0329 pretrig_zone[hs] = true;
0330 if (infoV > 1)
0331 LogTrace("CSCUpgradeCathodeLCTProcessor")
0332 << " marked pretrigger halfstrip zone [" << min_hs << "," << max_hs << "]";
0333 }
0334 }
0335 }
0336
0337 void CSCUpgradeCathodeLCTProcessor::markBusyZone(const int bx) {
0338 for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
0339
0340 if (ispretrig_[hstrip]) {
0341
0342 int min_hstrip = hstrip - clct_state_machine_zone_;
0343 int max_hstrip = hstrip + clct_state_machine_zone_;
0344
0345 if (min_hstrip < stagger[CSCConstants::KEY_CLCT_LAYER - 1])
0346 min_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1];
0347
0348 if (max_hstrip >= numHalfStrips_)
0349 max_hstrip = numHalfStrips_ - 1;
0350
0351 for (int hs = min_hstrip; hs <= max_hstrip; hs++)
0352 busyMap_[hs][bx + 1] = true;
0353 if (infoV > 1)
0354 LogTrace("CSCUpgradeCathodeLCTProcessor")
0355 << " marked zone around pretriggerred halfstrip " << hstrip << " as dead zone for pretriggering at bx"
0356 << bx + 1 << " halfstrip: [" << min_hstrip << "," << max_hstrip << "]";
0357 }
0358 }
0359 }