File indexing completed on 2021-04-08 04:01:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "L1Trigger/L1TGlobal/interface/MuCondition.h"
0018
0019
0020 #include <iostream>
0021 #include <iomanip>
0022
0023 #include <string>
0024 #include <vector>
0025 #include <algorithm>
0026
0027
0028
0029 #include "L1Trigger/L1TGlobal/interface/MuonTemplate.h"
0030 #include "L1Trigger/L1TGlobal/interface/ConditionEvaluation.h"
0031
0032 #include "DataFormats/L1Trigger/interface/Muon.h"
0033
0034 #include "L1Trigger/L1TGlobal/interface/GlobalBoard.h"
0035
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0038
0039
0040
0041 l1t::MuCondition::MuCondition() : ConditionEvaluation() {
0042
0043 }
0044
0045
0046 l1t::MuCondition::MuCondition(const GlobalCondition* muonTemplate,
0047 const GlobalBoard* ptrGTL,
0048 const int nrL1Mu,
0049 const int ifMuEtaNumberBits)
0050 : ConditionEvaluation(),
0051 m_gtMuonTemplate(static_cast<const MuonTemplate*>(muonTemplate)),
0052 m_gtGTL(ptrGTL),
0053 m_ifMuEtaNumberBits(ifMuEtaNumberBits) {
0054 m_corrParDeltaPhiNrBins = 0;
0055 m_condMaxNumberObjects = nrL1Mu;
0056 }
0057
0058
0059 void l1t::MuCondition::copy(const l1t::MuCondition& cp) {
0060 m_gtMuonTemplate = cp.gtMuonTemplate();
0061 m_gtGTL = cp.gtGTL();
0062
0063 m_ifMuEtaNumberBits = cp.gtIfMuEtaNumberBits();
0064 m_corrParDeltaPhiNrBins = cp.m_corrParDeltaPhiNrBins;
0065
0066 m_condMaxNumberObjects = cp.condMaxNumberObjects();
0067 m_condLastResult = cp.condLastResult();
0068 m_combinationsInCond = cp.getCombinationsInCond();
0069
0070 m_verbosity = cp.m_verbosity;
0071 }
0072
0073 l1t::MuCondition::MuCondition(const l1t::MuCondition& cp) : ConditionEvaluation() { copy(cp); }
0074
0075
0076 l1t::MuCondition::~MuCondition() {
0077
0078 }
0079
0080
0081 l1t::MuCondition& l1t::MuCondition::operator=(const l1t::MuCondition& cp) {
0082 copy(cp);
0083 return *this;
0084 }
0085
0086
0087 void l1t::MuCondition::setGtMuonTemplate(const MuonTemplate* muonTempl) { m_gtMuonTemplate = muonTempl; }
0088
0089
0090 void l1t::MuCondition::setGtGTL(const GlobalBoard* ptrGTL) { m_gtGTL = ptrGTL; }
0091
0092
0093 void l1t::MuCondition::setGtIfMuEtaNumberBits(const int& ifMuEtaNumberBitsValue) {
0094 m_ifMuEtaNumberBits = ifMuEtaNumberBitsValue;
0095 }
0096
0097
0098 void l1t::MuCondition::setGtCorrParDeltaPhiNrBins(const int& corrParDeltaPhiNrBins) {
0099 m_corrParDeltaPhiNrBins = corrParDeltaPhiNrBins;
0100 }
0101
0102
0103 const bool l1t::MuCondition::evaluateCondition(const int bxEval) const {
0104
0105
0106
0107
0108 int nObjInCond = m_gtMuonTemplate->nrObjects();
0109
0110
0111 const BXVector<const l1t::Muon*>* candVec = m_gtGTL->getCandL1Mu();
0112
0113
0114 int useBx = bxEval + m_gtMuonTemplate->condRelativeBx();
0115
0116
0117 if ((useBx < candVec->getFirstBX()) || (useBx > candVec->getLastBX())) {
0118 return false;
0119 }
0120
0121 int numberObjects = candVec->size(useBx);
0122
0123
0124 if (numberObjects < nObjInCond) {
0125 return false;
0126 }
0127
0128 std::vector<int> index(numberObjects);
0129
0130 for (int i = 0; i < numberObjects; ++i) {
0131 index[i] = i;
0132 }
0133
0134 int numberForFactorial = numberObjects - nObjInCond;
0135
0136
0137 int myfactorial = 1;
0138 for (int i = numberForFactorial; i > 0; i--)
0139 myfactorial *= i;
0140
0141 int jumpIndex = 1;
0142 int jump = myfactorial;
0143
0144 int totalLoops = 0;
0145 int passLoops = 0;
0146
0147
0148
0149
0150 bool condResult = false;
0151
0152
0153
0154 SingleCombInCond objectsInComb;
0155 objectsInComb.reserve(nObjInCond);
0156
0157
0158 combinationsInCond().clear();
0159
0160 do {
0161 if (--jumpIndex)
0162 continue;
0163
0164 jumpIndex = jump;
0165 totalLoops++;
0166
0167
0168 objectsInComb.clear();
0169
0170 bool tmpResult = true;
0171
0172 bool passCondition = false;
0173
0174 for (int i = 0; i < nObjInCond; i++) {
0175 passCondition = checkObjectParameter(i, *(candVec->at(useBx, index[i])), index[i]);
0176 tmpResult &= passCondition;
0177 if (passCondition)
0178 LogDebug("L1TGlobal") << "===> MuCondition::evaluateCondition, CONGRATS!! This muon passed the condition."
0179 << std::endl;
0180 else
0181 LogDebug("L1TGlobal") << "===> MuCondition::evaluateCondition, FAIL!! This muon failed the condition."
0182 << std::endl;
0183 objectsInComb.push_back(index[i]);
0184 }
0185
0186
0187
0188 if (!tmpResult) {
0189 continue;
0190 }
0191
0192
0193 MuonTemplate::CorrelationParameter corrPar = *(m_gtMuonTemplate->correlationParameter());
0194
0195
0196 unsigned int chargeCorr = corrPar.chargeCorrelation;
0197
0198
0199 if ((chargeCorr & 1) == 0) {
0200 LogDebug("L1TGlobal") << "===> MuCondition:: Checking Charge Correlation" << std::endl;
0201
0202 for (int i = 0; i < nObjInCond; i++) {
0203
0204 int chargeValid = (candVec->at(useBx, index[i]))->hwChargeValid();
0205 tmpResult &= chargeValid;
0206
0207 if (chargeValid == 0) {
0208 continue;
0209 }
0210 }
0211
0212 if (!tmpResult) {
0213 LogDebug("L1TGlobal") << "===> MuCondition:: Charge Correlation Failed...No Valid Charges" << std::endl;
0214 continue;
0215 }
0216
0217 if (nObjInCond > 1) {
0218
0219
0220 bool equalSigns = true;
0221 for (int i = 0; i < nObjInCond - 1; i++) {
0222 if ((candVec->at(useBx, index[i]))->hwCharge() !=
0223 (candVec->at(useBx, index[i + 1]))->hwCharge()) {
0224 equalSigns = false;
0225 break;
0226 }
0227 }
0228
0229 LogDebug("L1TGlobal") << "===> MuCondition:: Checking Charge Correlation equalSigns = " << equalSigns
0230 << std::endl;
0231
0232
0233 if (nObjInCond == 2 || nObjInCond == 3) {
0234 if (!(((chargeCorr & 2) != 0 && equalSigns) || ((chargeCorr & 4) != 0 && !equalSigns))) {
0235 LogDebug("L1TGlobal") << "===> MuCondition:: 2/3 Muon Fail Charge Correlation Condition =" << chargeCorr
0236 << std::endl;
0237 continue;
0238 }
0239 } else if (nObjInCond == 4) {
0240
0241 unsigned int posCount = 0;
0242
0243 for (int i = 0; i < nObjInCond; i++) {
0244 if ((candVec->at(useBx, index[i]))->hwCharge() > 0) {
0245 posCount++;
0246 }
0247 }
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263 if (!(((chargeCorr & 2) != 0 && equalSigns) || ((chargeCorr & 4) != 0 && (posCount > 0 && posCount < 4)))) {
0264 LogDebug("L1TGlobal") << "===> MuCondition:: 4 Muon Fail Charge Correlation Condition = " << chargeCorr
0265 << " posCnt " << posCount << std::endl;
0266 continue;
0267 }
0268 }
0269 }
0270 }
0271
0272 if (m_gtMuonTemplate->wsc()) {
0273
0274
0275
0276 const int ObjInWscComb = 2;
0277 if (nObjInCond != ObjInWscComb) {
0278 edm::LogError("L1TGlobal") << "\n Error: "
0279 << "number of particles in condition with spatial correlation = " << nObjInCond
0280 << "\n it must be = " << ObjInWscComb << std::endl;
0281
0282
0283 continue;
0284 }
0285
0286
0287 if (!checkRangeDeltaEta((candVec->at(useBx, 0))->hwEtaAtVtx(),
0288 (candVec->at(useBx, 1))->hwEtaAtVtx(),
0289 corrPar.deltaEtaRangeLower,
0290 corrPar.deltaEtaRangeUpper,
0291 8)) {
0292 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRangeDeltaEta" << std::endl;
0293 continue;
0294 }
0295
0296
0297 if (!checkRangeDeltaPhi((candVec->at(useBx, 0))->hwPhiAtVtx(),
0298 (candVec->at(useBx, 1))->hwPhiAtVtx(),
0299 corrPar.deltaPhiRangeLower,
0300 corrPar.deltaPhiRangeUpper)) {
0301 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRangeDeltaPhi" << std::endl;
0302 continue;
0303 }
0304
0305 }
0306
0307
0308
0309
0310 condResult = true;
0311 passLoops++;
0312 (combinationsInCond()).push_back(objectsInComb);
0313
0314 } while (std::next_permutation(index.begin(), index.end()));
0315
0316
0317
0318
0319
0320
0321 return condResult;
0322 }
0323
0324
0325 const l1t::Muon* l1t::MuCondition::getCandidate(const int bx, const int indexCand) const {
0326 return (m_gtGTL->getCandL1Mu())->at(bx, indexCand);
0327 }
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338 const bool l1t::MuCondition::checkObjectParameter(const int iCondition,
0339 const l1t::Muon& cand,
0340 const unsigned int index) const {
0341
0342 int nObjInCond = m_gtMuonTemplate->nrObjects();
0343
0344 if (iCondition >= nObjInCond || iCondition < 0) {
0345 return false;
0346 }
0347
0348
0349
0350
0351
0352
0353 const MuonTemplate::ObjectParameter objPar = (*(m_gtMuonTemplate->objectParameter()))[iCondition];
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380 LogDebug("L1TGlobal") << "\n MuonTemplate::ObjectParameter : " << std::hex << "\n\t ptHighThreshold = 0x "
0381 << objPar.ptHighThreshold << "\n\t ptLowThreshold = 0x " << objPar.ptLowThreshold
0382 << "\n\t indexHigh = 0x " << objPar.indexHigh << "\n\t indexLow = 0x "
0383 << objPar.indexLow << "\n\t requestIso = 0x " << objPar.requestIso
0384 << "\n\t enableIso = 0x " << objPar.enableIso << "\n\t etaRange = 0x "
0385 << objPar.etaRange << "\n\t phiLow = 0x " << objPar.phiLow
0386 << "\n\t phiHigh = 0x " << objPar.phiHigh << "\n\t phiWindow1Lower = 0x "
0387 << objPar.phiWindow1Lower << "\n\t phiWindow1Upper = 0x " << objPar.phiWindow1Upper
0388 << "\n\t phiWindow2Lower = 0x " << objPar.phiWindow2Lower << "\n\t phiWindow2Lower = 0x "
0389 << objPar.phiWindow2Lower << "\n\t charge = 0x " << objPar.charge
0390 << "\n\t qualityLUT = 0x " << objPar.qualityLUT << "\n\t isolationLUT = 0x "
0391 << objPar.isolationLUT << "\n\t enableMip = 0x " << objPar.enableMip << std::endl;
0392
0393 LogDebug("L1TGlobal") << "\n l1t::Muon : "
0394 << "\n\t hwPt = 0x " << cand.hwPt() << "\n\t hwEtaAtVtx = 0x " << cand.hwEtaAtVtx()
0395 << "\n\t hwPhiAtVtx = 0x " << cand.hwPhiAtVtx() << "\n\t hwCharge = 0x " << cand.hwCharge()
0396 << "\n\t hwQual = 0x " << cand.hwQual() << "\n\t hwIso = 0x " << cand.hwIso()
0397 << std::dec << std::endl;
0398
0399 if (objPar.unconstrainedPtHigh > 0)
0400 {
0401 if (!checkUnconstrainedPt(objPar.unconstrainedPtLow,
0402 objPar.unconstrainedPtHigh,
0403 cand.hwPtUnconstrained(),
0404 m_gtMuonTemplate->condGEq())) {
0405 LogDebug("L1TGlobal") << "\t\t Muon Failed unconstrainedPt checkThreshold; iCondition = " << iCondition
0406 << std::endl;
0407 return false;
0408 }
0409 }
0410 if (objPar.impactParameterLUT !=
0411 0)
0412 {
0413
0414
0415 if (cand.hwDXY() > 3) {
0416 LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwDXY = " << cand.hwDXY() << std::endl;
0417 return false;
0418 }
0419 bool passImpactParameterLUT = ((objPar.impactParameterLUT >> cand.hwDXY()) & 1);
0420 if (!passImpactParameterLUT) {
0421 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed impact parameter requirement" << std::endl;
0422 return false;
0423 }
0424 }
0425
0426 if (!checkThreshold(objPar.ptLowThreshold, objPar.ptHighThreshold, cand.hwPt(), m_gtMuonTemplate->condGEq())) {
0427 LogDebug("L1TGlobal") << "\t\t Muon Failed checkThreshold " << std::endl;
0428 return false;
0429 }
0430
0431
0432 if (!checkIndex(objPar.indexLow, objPar.indexHigh, index)) {
0433 LogDebug("L1TGlobal") << "\t\t Muon Failed checkIndex " << std::endl;
0434 return false;
0435 }
0436
0437
0438 if (!checkRangeEta(cand.hwEtaAtVtx(),
0439 objPar.etaWindow1Lower,
0440 objPar.etaWindow1Upper,
0441 objPar.etaWindow2Lower,
0442 objPar.etaWindow2Upper,
0443 8)) {
0444 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRange(eta)" << std::endl;
0445 return false;
0446 }
0447
0448
0449 if (!checkRangePhi(cand.hwPhiAtVtx(),
0450 objPar.phiWindow1Lower,
0451 objPar.phiWindow1Upper,
0452 objPar.phiWindow2Lower,
0453 objPar.phiWindow2Upper)) {
0454 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRange(phi)" << std::endl;
0455 return false;
0456 }
0457
0458
0459 if (objPar.charge >= 0) {
0460 if (cand.hwCharge() != objPar.charge) {
0461 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed charge requirement" << std::endl;
0462 return false;
0463 }
0464 }
0465
0466
0467
0468 if (cand.hwQual() > 16) {
0469 LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwQual = " << cand.hwQual() << std::endl;
0470 return false;
0471 }
0472 bool passQualLUT = ((objPar.qualityLUT >> cand.hwQual()) & 1);
0473 if (!passQualLUT) {
0474 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed quality requirement" << std::endl;
0475 return false;
0476 }
0477
0478
0479
0480 if (cand.hwIso() > 4) {
0481 LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwIso = " << cand.hwIso() << std::endl;
0482 return false;
0483 }
0484 bool passIsoLUT = ((objPar.isolationLUT >> cand.hwIso()) & 1);
0485 if (!passIsoLUT) {
0486 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed isolation requirement" << std::endl;
0487 return false;
0488 }
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511 if (objPar.enableMip) {
0512
0513
0514
0515
0516 }
0517
0518
0519
0520
0521
0522 return true;
0523 }
0524
0525 void l1t::MuCondition::print(std::ostream& myCout) const {
0526 m_gtMuonTemplate->print(myCout);
0527
0528 myCout << " Number of bits for eta of muon objects = " << m_ifMuEtaNumberBits << std::endl;
0529 myCout << " Maximum number of bins for the delta phi scales = " << m_corrParDeltaPhiNrBins << "\n " << std::endl;
0530
0531 ConditionEvaluation::print(myCout);
0532 }