00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMotherboard.h>
00040
00041 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00042 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
00043
00044 CSCMotherboard::CSCMotherboard() :
00045 theEndcap(1), theStation(1), theSector(1),
00046 theSubsector(1), theTrigChamber(1) {
00047
00048 alct = new CSCAnodeLCTProcessor();
00049 clct = new CSCCathodeLCTProcessor();
00050 infoV = 2;
00051 }
00052
00053 CSCMotherboard::CSCMotherboard(unsigned endcap, unsigned station,
00054 unsigned sector, unsigned subsector,
00055 unsigned chamber,
00056 const edm::ParameterSet& conf) :
00057 theEndcap(endcap), theStation(station), theSector(sector),
00058 theSubsector(subsector), theTrigChamber(chamber) {
00059
00060
00061
00062
00063
00064
00065
00066 edm::ParameterSet commonParams =
00067 conf.getParameter<edm::ParameterSet>("commonParam");
00068 isMTCC = commonParams.getParameter<bool>("isMTCC");
00069
00070
00071 isTMB07 = commonParams.getParameter<bool>("isTMB07");
00072
00073
00074
00075 edm::ParameterSet alctParams, clctParams;
00076 if (!isMTCC) {
00077 alctParams = conf.getParameter<edm::ParameterSet>("alctParamDef");
00078 clctParams = conf.getParameter<edm::ParameterSet>("clctParamDef");
00079 }
00080 else {
00081 alctParams = conf.getParameter<edm::ParameterSet>("alctParamMTCC2");
00082 clctParams = conf.getParameter<edm::ParameterSet>("clctParamMTCC2");
00083 }
00084 alct = new CSCAnodeLCTProcessor(endcap, station, sector, subsector,
00085 chamber, alctParams, commonParams);
00086 clct = new CSCCathodeLCTProcessor(endcap, station, sector, subsector,
00087 chamber, clctParams, commonParams);
00088
00089
00090 edm::ParameterSet tmbParams =
00091 conf.getParameter<edm::ParameterSet>("tmbParam");
00092 infoV = tmbParams.getUntrackedParameter<int>("verbosity", 0);
00093
00094
00095
00096
00097 }
00098
00099 CSCMotherboard::~CSCMotherboard() {
00100 if (alct) delete alct;
00101 if (clct) delete clct;
00102 }
00103
00104 void CSCMotherboard::clear() {
00105 if (alct) alct->clear();
00106 if (clct) clct->clear();
00107 firstLCT.clear();
00108 secondLCT.clear();
00109 }
00110
00111
00112 void CSCMotherboard::setConfigParameters(const CSCL1TPParameters* conf) {
00113 alct->setConfigParameters(conf);
00114 clct->setConfigParameters(conf);
00115
00116 }
00117
00118 void CSCMotherboard::run(
00119 std::vector<int> time1[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_WIRES],
00120 int time2[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_STRIPS],
00121 int triad[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_STRIPS]) {
00122
00123 clear();
00124 alct->run(time1);
00125 clct->run(triad, time2, time2);
00126
00127 int first_bx = CSCAnodeLCTProcessor::MAX_ALCT_BINS;
00128 for (int bx = 0; bx < CSCAnodeLCTProcessor::MAX_ALCT_BINS; bx++) {
00129 if (alct->bestALCT[bx].isValid()) {first_bx = bx; break;}
00130 }
00131
00132 if (first_bx < CSCAnodeLCTProcessor::MAX_ALCT_BINS) {
00133 correlateLCTs(alct->bestALCT[first_bx], alct->secondALCT[first_bx],
00134 clct->bestCLCT, clct->secondCLCT);
00135 }
00136
00137 else if (clct->bestCLCT.isValid()) {
00138 correlateLCTs(alct->bestALCT[0], alct->secondALCT[0],
00139 clct->bestCLCT, clct->secondCLCT);
00140 }
00141 }
00142
00143 std::vector<CSCCorrelatedLCTDigi>
00144 CSCMotherboard::run(const CSCWireDigiCollection* wiredc,
00145 const CSCComparatorDigiCollection* compdc) {
00146 clear();
00147 if (alct && clct) {
00148 {
00149
00150
00151
00152 std::vector<CSCALCTDigi> alctV = alct->run(wiredc);
00153 }
00154 {
00155
00156
00157
00158 std::vector<CSCCLCTDigi> clctV = clct->run(compdc);
00159 }
00160
00161
00162
00163
00164
00165 int first_bx = CSCAnodeLCTProcessor::MAX_ALCT_BINS;
00166 for (int bx = 0; bx < CSCAnodeLCTProcessor::MAX_ALCT_BINS; bx++) {
00167 if (alct->bestALCT[bx].isValid()) {first_bx = bx; break;}
00168 }
00169
00170 if (first_bx < CSCAnodeLCTProcessor::MAX_ALCT_BINS) {
00171 correlateLCTs(alct->bestALCT[first_bx], alct->secondALCT[first_bx],
00172 clct->bestCLCT, clct->secondCLCT);
00173 }
00174
00175 else if (clct->bestCLCT.isValid()) {
00176 correlateLCTs(alct->bestALCT[0], alct->secondALCT[0],
00177 clct->bestCLCT, clct->secondCLCT);
00178 }
00179 if (infoV > 0) {
00180 if (firstLCT.isValid()) LogDebug("CSCMotherboard") << firstLCT;
00181 if (secondLCT.isValid()) LogDebug("CSCMotherboard") << secondLCT;
00182 }
00183 }
00184 else {
00185 if (infoV > 0) edm::LogWarning("CSCMotherboard")
00186 << "+++ run() called for non-existing ALCT/CLCT processor! +++ \n";
00187 }
00188
00189 std::vector<CSCCorrelatedLCTDigi> tmpV = getLCTs();
00190 return tmpV;
00191 }
00192
00193
00194 std::vector<CSCCorrelatedLCTDigi> CSCMotherboard::getLCTs() {
00195 std::vector<CSCCorrelatedLCTDigi> tmpV;
00196
00197
00198 bool me11 =
00199 (theStation == 1 &&
00200 CSCTriggerNumbering::ringFromTriggerLabels(theStation,theTrigChamber)==1);
00201 if (firstLCT.isValid())
00202 if (!me11 || firstLCT.getStrip() <= 127)
00203 tmpV.push_back(firstLCT);
00204 if (secondLCT.isValid())
00205 if (!me11 || secondLCT.getStrip() <= 127)
00206 tmpV.push_back(secondLCT);
00207 return tmpV;
00208 }
00209
00210 void CSCMotherboard::correlateLCTs(CSCALCTDigi bestALCT,
00211 CSCALCTDigi secondALCT,
00212 CSCCLCTDigi bestCLCT,
00213 CSCCLCTDigi secondCLCT) {
00214
00215 bool anodeBestValid = bestALCT.isValid();
00216 bool anodeSecondValid = secondALCT.isValid();
00217 bool cathodeBestValid = bestCLCT.isValid();
00218 bool cathodeSecondValid = secondCLCT.isValid();
00219
00220
00221
00222
00223
00224 if (anodeBestValid && !anodeSecondValid) secondALCT = bestALCT;
00225 if (!anodeBestValid && anodeSecondValid) bestALCT = secondALCT;
00226 if (cathodeBestValid && !cathodeSecondValid) secondCLCT = bestCLCT;
00227 if (!cathodeBestValid && cathodeSecondValid) bestCLCT = secondCLCT;
00228
00229
00230 if (isMTCC && (bestCLCT.isValid() == false && secondCLCT.isValid() == false))
00231 return;
00232
00233 firstLCT = constructLCTs(bestALCT, bestCLCT);
00234 firstLCT.setTrknmb(1);
00235
00236 if ((secondALCT != bestALCT) || (secondCLCT != bestCLCT)) {
00237 secondLCT = constructLCTs(secondALCT, secondCLCT);
00238 secondLCT.setTrknmb(2);
00239 }
00240 }
00241
00242
00243
00244 CSCCorrelatedLCTDigi CSCMotherboard::constructLCTs(const CSCALCTDigi& aLCT,
00245 const CSCCLCTDigi& cLCT) {
00246
00247 unsigned int pattern = encodePattern(cLCT.getPattern(), cLCT.getStripType());
00248
00249
00250 unsigned int quality = findQuality(aLCT, cLCT);
00251
00252
00253
00254
00255
00256 int bx = aLCT.isValid() ? aLCT.getBX() : cLCT.getBX();
00257
00258
00259 int trknmb = 0;
00260 CSCCorrelatedLCTDigi thisLCT(trknmb, 1, quality, aLCT.getKeyWG(),
00261 cLCT.getKeyStrip(), pattern, cLCT.getBend(),
00262 bx, 0, 0, 0, theTrigChamber);
00263 return thisLCT;
00264 }
00265
00266
00267
00268 unsigned int CSCMotherboard::encodePattern(const int ptn,
00269 const int stripType) {
00270 const int kPatternBitWidth = 4;
00271 unsigned int pattern;
00272
00273 if (!isTMB07) {
00274
00275 pattern = (abs(ptn) & ((1<<(kPatternBitWidth-1))-1));
00276
00277
00278
00279 if (stripType) {
00280 pattern = pattern | (1<<(kPatternBitWidth-1));
00281 }
00282 }
00283 else {
00284
00285 pattern = (abs(ptn) & ((1<<kPatternBitWidth)-1));
00286 }
00287
00288 return pattern;
00289 }
00290
00291
00292
00293
00294 unsigned int CSCMotherboard::findQuality(const CSCALCTDigi& aLCT,
00295 const CSCCLCTDigi& cLCT) {
00296 unsigned int quality = 0;
00297
00298 if (!isTMB07) {
00299 bool isDistrip = (cLCT.getStripType() == 0);
00300
00301 if (aLCT.isValid() && !(cLCT.isValid())) {
00302 if (aLCT.getAccelerator()) {quality = 1;}
00303 else {quality = 3;}
00304 }
00305 else if (!(aLCT.isValid()) && cLCT.isValid()) {
00306 if (isDistrip) {quality = 4;}
00307 else {quality = 5;}
00308 }
00309 else if (aLCT.isValid() && cLCT.isValid()) {
00310 if (aLCT.getAccelerator()) {quality = 2;}
00311 else {
00312
00313
00314 int sumQual = aLCT.getQuality() + (cLCT.getQuality()-3);
00315 if (sumQual < 1 || sumQual > 6) {
00316 if (infoV > 0) edm::LogWarning("CSCMotherboard")
00317 << "+++ findQuality: sumQual = " << sumQual << "+++ \n";
00318 }
00319 if (isDistrip) {
00320 if (sumQual == 2) {quality = 6;}
00321 else if (sumQual == 3) {quality = 7;}
00322 else if (sumQual == 4) {quality = 8;}
00323 else if (sumQual == 5) {quality = 9;}
00324 else if (sumQual == 6) {quality = 10;}
00325 }
00326 else {
00327 if (sumQual == 2) {quality = 11;}
00328 else if (sumQual == 3) {quality = 12;}
00329 else if (sumQual == 4) {quality = 13;}
00330 else if (sumQual == 5) {quality = 14;}
00331 else if (sumQual == 6) {quality = 15;}
00332 }
00333 }
00334 }
00335 }
00336 #ifdef OLD
00337 else {
00338
00339
00340
00341
00342 if (!(aLCT.isValid()) || !(cLCT.isValid())) {
00343 if (aLCT.isValid() && !(cLCT.isValid())) quality = 1;
00344 else if (!(aLCT.isValid()) && cLCT.isValid()) quality = 2;
00345 else quality = 0;
00346 }
00347 else {
00348
00349
00350
00351 int sumQual = aLCT.getQuality() + (cLCT.getQuality()-3);
00352 if (sumQual < 1 || sumQual > 6) {
00353 if (infoV > 0) edm::LogWarning("CSCMotherboard")
00354 << "+++ findQuality: Unexpected sumQual = " << sumQual << "+++\n";
00355 }
00356
00357
00358
00359
00360 int offset = 0;
00361 if (cLCT.getPattern() <= 7) offset = 4;
00362 else offset = 9;
00363 quality = offset + sumQual;
00364 }
00365 }
00366 #endif
00367 else {
00368
00369 if (!(aLCT.isValid()) || !(cLCT.isValid())) {
00370 if (aLCT.isValid() && !(cLCT.isValid())) quality = 1;
00371 else if (!(aLCT.isValid()) && cLCT.isValid()) quality = 2;
00372 else quality = 0;
00373 }
00374 else {
00375 int pattern = cLCT.getPattern();
00376 if (pattern == 1) quality = 3;
00377 else {
00378
00379
00380 bool a4 = (aLCT.getQuality() >= 1);
00381 bool c4 = (cLCT.getQuality() >= 4);
00382
00383 if (!a4 && !c4) quality = 5;
00384 else if ( a4 && !c4) quality = 6;
00385 else if (!a4 && c4) quality = 7;
00386 else if ( a4 && c4) {
00387 if (aLCT.getAccelerator()) quality = 8;
00388 else {
00389
00390
00391 if (pattern == 2 || pattern == 3) quality = 11;
00392 else if (pattern == 4 || pattern == 5) quality = 12;
00393 else if (pattern == 6 || pattern == 7) quality = 13;
00394 else if (pattern == 8 || pattern == 9) quality = 14;
00395 else if (pattern == 10) quality = 15;
00396 else {
00397 if (infoV > 0) edm::LogWarning("CSCMotherboard")
00398 << "+++ findQuality: Unexpected CLCT pattern id = "
00399 << pattern << "+++\n";
00400 }
00401 }
00402 }
00403 }
00404 }
00405 }
00406 return quality;
00407 }
00408
00409
00410
00411 int CSCMotherboard::findSTA(const bool a1, const bool a2,
00412 const bool c1, const bool c2) {
00413 int STA = 0;
00414
00415 if (a1 && a2 && !c1 && !c2)
00416 STA = 1;
00417 else if (!a1 && !a2 && c1 && c2)
00418 STA = 1;
00419 else if (!a1 && a2 && c1 && !c2)
00420 STA = 1;
00421 else if (a1 && !a2 && !c1 && c2)
00422 STA = 1;
00423 else if (!a1 && a2 && !c1 && c2)
00424 STA = 1;
00425 else if (a1 && !a2 && c1 && c2)
00426 STA = 2;
00427 else if (!a1 && a2 && c1 && c2)
00428 STA = 1;
00429 else if (a1 && a2 && c1 && !c2)
00430 STA = 2;
00431 else if (a1 && a2 && !c1 && c2)
00432 STA = 1;
00433 else if (a1 && !a2 && c1 && !c2)
00434 STA = 3;
00435 else if (a1 && a2 && c1 && c2)
00436 STA = 3;
00437 else if (a1 || a2 || c1 || c2 )
00438 STA = 1;
00439 else {
00440 if (infoV > 0) edm::LogWarning("CSCMotherboard")
00441 << "+++ findSTA: STA not assigned: \n"
00442 << " a1 " << a1 << " a2 " << a2 << " c1 " << c1 << " c2 " << c2
00443 << " +++ \n";
00444 }
00445
00446 return STA;
00447 }
00448
00449
00450
00451 int CSCMotherboard::findBxnMatch(const int aBxn, const int cBxn) {
00452 int bxnMatch = 3;
00453
00454 if (aBxn == cBxn) {bxnMatch = 0;}
00455 else if ((aBxn - cBxn) == 1) {bxnMatch = 1;}
00456 else if ((cBxn - aBxn) == 1) {bxnMatch = 2;}
00457 return bxnMatch;
00458 }
00459
00460 void CSCMotherboard::testLCT() {
00461 unsigned int lctPattern, lctQuality;
00462 for (int pattern = 0; pattern < 8; pattern++) {
00463 for (int bend = 0; bend < 2; bend++) {
00464 for (int cfeb = 0; cfeb < 5; cfeb++) {
00465 for (int strip = 0; strip < 32; strip++) {
00466 for (int bx = 0; bx < 7; bx++) {
00467 for (int stripType = 0; stripType < 2; stripType++) {
00468 for (int quality = 3; quality < 7; quality++) {
00469 CSCCLCTDigi cLCT(1, quality, pattern, stripType, bend,
00470 strip, cfeb, bx);
00471 lctPattern = encodePattern(cLCT.getPattern(),
00472 cLCT.getStripType());
00473 for (int aQuality = 0; aQuality < 4; aQuality++) {
00474 for (int wireGroup = 0; wireGroup < 120; wireGroup++) {
00475 for (int abx = 0; abx < 7; abx++) {
00476 CSCALCTDigi aLCT(1, aQuality, 0, 1, wireGroup, abx);
00477 lctQuality = findQuality(aLCT, cLCT);
00478 CSCCorrelatedLCTDigi
00479 thisLCT(0, 1, lctQuality, aLCT.getKeyWG(),
00480 cLCT.getKeyStrip(), lctPattern, cLCT.getBend(),
00481 aLCT.getBX());
00482 if (lctPattern != static_cast<unsigned int>(thisLCT.getPattern()) )
00483 edm::LogWarning("CSCMotherboard")
00484 << "pattern mismatch: " << lctPattern
00485 << " " << thisLCT.getPattern();
00486 if (bend != thisLCT.getBend())
00487 edm::LogWarning("CSCMotherboard")
00488 << "bend mismatch: " << bend
00489 << " " << thisLCT.getBend();
00490 int key_strip = 32*cfeb + strip;
00491 if (key_strip != thisLCT.getStrip())
00492 edm::LogWarning("CSCMotherboard")
00493 << "strip mismatch: " << key_strip
00494 << " " << thisLCT.getStrip();
00495 if (wireGroup != thisLCT.getKeyWG())
00496 edm::LogWarning("CSCMotherboard")
00497 << "wire group mismatch: " << wireGroup
00498 << " " << thisLCT.getKeyWG();
00499 if (abx != thisLCT.getBX())
00500 edm::LogWarning("CSCMotherboard")
00501 << "bx mismatch: " << abx << " " << thisLCT.getBX();
00502 if (lctQuality != static_cast<unsigned int>(thisLCT.getQuality()))
00503 edm::LogWarning("CSCMotherboard")
00504 << "quality mismatch: " << lctQuality
00505 << " " << thisLCT.getQuality();
00506 }
00507 }
00508 }
00509 }
00510 }
00511 }
00512 }
00513 }
00514 }
00515 }
00516 }