File indexing completed on 2023-04-21 01:53:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "L1Trigger/L1TGlobal/interface/CaloCondition.h"
0016
0017
0018 #include <iostream>
0019 #include <iomanip>
0020
0021 #include <string>
0022 #include <vector>
0023 #include <algorithm>
0024
0025
0026
0027 #include "L1Trigger/L1TGlobal/interface/CaloTemplate.h"
0028 #include "L1Trigger/L1TGlobal/interface/ConditionEvaluation.h"
0029
0030 #include "DataFormats/L1Trigger/interface/L1Candidate.h"
0031
0032 #include "L1Trigger/L1TGlobal/interface/GlobalBoard.h"
0033
0034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0035 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0036
0037
0038
0039 l1t::CaloCondition::CaloCondition() : ConditionEvaluation() {
0040 m_ifCaloEtaNumberBits = -1;
0041 m_corrParDeltaPhiNrBins = 0;
0042 }
0043
0044
0045 l1t::CaloCondition::CaloCondition(const GlobalCondition* caloTemplate,
0046 const GlobalBoard* ptrGTB,
0047 const int nrL1EG,
0048 const int nrL1Jet,
0049 const int nrL1Tau,
0050 const int ifCaloEtaNumberBits)
0051 : ConditionEvaluation(),
0052 m_gtCaloTemplate(static_cast<const CaloTemplate*>(caloTemplate)),
0053 m_uGtB(ptrGTB),
0054 m_ifCaloEtaNumberBits(ifCaloEtaNumberBits) {
0055 m_corrParDeltaPhiNrBins = 0;
0056
0057
0058
0059
0060
0061
0062 switch ((m_gtCaloTemplate->objectType())[0]) {
0063 case gtEG:
0064 m_condMaxNumberObjects = nrL1EG;
0065 break;
0066
0067 case gtJet:
0068 m_condMaxNumberObjects = nrL1Jet;
0069 break;
0070
0071 case gtTau:
0072 m_condMaxNumberObjects = nrL1Tau;
0073 break;
0074 default:
0075 m_condMaxNumberObjects = 0;
0076 break;
0077 }
0078 }
0079
0080
0081 void l1t::CaloCondition::copy(const l1t::CaloCondition& cp) {
0082 m_gtCaloTemplate = cp.gtCaloTemplate();
0083 m_uGtB = cp.getuGtB();
0084
0085 m_ifCaloEtaNumberBits = cp.gtIfCaloEtaNumberBits();
0086 m_corrParDeltaPhiNrBins = cp.m_corrParDeltaPhiNrBins;
0087
0088 m_condMaxNumberObjects = cp.condMaxNumberObjects();
0089 m_condLastResult = cp.condLastResult();
0090 m_combinationsInCond = cp.getCombinationsInCond();
0091
0092 m_verbosity = cp.m_verbosity;
0093 }
0094
0095 l1t::CaloCondition::CaloCondition(const l1t::CaloCondition& cp) : ConditionEvaluation() { copy(cp); }
0096
0097
0098 l1t::CaloCondition::~CaloCondition() {
0099
0100 }
0101
0102
0103 l1t::CaloCondition& l1t::CaloCondition::operator=(const l1t::CaloCondition& cp) {
0104 copy(cp);
0105 return *this;
0106 }
0107
0108
0109 void l1t::CaloCondition::setGtCaloTemplate(const CaloTemplate* caloTempl) { m_gtCaloTemplate = caloTempl; }
0110
0111
0112 void l1t::CaloCondition::setuGtB(const GlobalBoard* ptrGTB) { m_uGtB = ptrGTB; }
0113
0114
0115 void l1t::CaloCondition::setGtIfCaloEtaNumberBits(const int& ifCaloEtaNumberBitsValue) {
0116 m_ifCaloEtaNumberBits = ifCaloEtaNumberBitsValue;
0117 }
0118
0119
0120 void l1t::CaloCondition::setGtCorrParDeltaPhiNrBins(const int& corrParDeltaPhiNrBins) {
0121 m_corrParDeltaPhiNrBins = corrParDeltaPhiNrBins;
0122 }
0123
0124
0125 const bool l1t::CaloCondition::evaluateCondition(const int bxEval) const {
0126
0127 int nObjInCond = m_gtCaloTemplate->nrObjects();
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 const BXVector<const l1t::L1Candidate*>* candVec;
0138
0139 switch ((m_gtCaloTemplate->objectType())[0]) {
0140 case gtEG:
0141 candVec = m_uGtB->getCandL1EG();
0142 break;
0143
0144 case gtJet:
0145 candVec = m_uGtB->getCandL1Jet();
0146 break;
0147
0148 case gtTau:
0149 candVec = m_uGtB->getCandL1Tau();
0150 break;
0151
0152 default:
0153 return false;
0154 break;
0155 }
0156
0157
0158 int useBx = bxEval + m_gtCaloTemplate->condRelativeBx();
0159
0160
0161 if ((useBx < candVec->getFirstBX()) || (useBx > candVec->getLastBX())) {
0162 return false;
0163 }
0164
0165 int numberObjects = candVec->size(useBx);
0166
0167
0168 if (numberObjects < nObjInCond) {
0169 return false;
0170 }
0171
0172 std::vector<int> index(numberObjects);
0173
0174 for (int i = 0; i < numberObjects; ++i) {
0175 index[i] = i;
0176 }
0177
0178 int totalLoops = 0;
0179 int passLoops = 0;
0180
0181
0182
0183
0184 bool condResult = false;
0185
0186
0187
0188 SingleCombInCond objectsInComb;
0189 objectsInComb.reserve(nObjInCond);
0190
0191
0192 combinationsInCond().clear();
0193
0194
0195 if (nObjInCond == 1) {
0196
0197
0198
0199 for (int i = 0; i < numberObjects; i++) {
0200
0201 objectsInComb.clear();
0202
0203 totalLoops++;
0204 bool passCondition = checkObjectParameter(0, *(candVec->at(useBx, i)), index[i]);
0205 if (passCondition) {
0206 objectsInComb.push_back(i);
0207 condResult = true;
0208 passLoops++;
0209 combinationsInCond().push_back(objectsInComb);
0210 }
0211 }
0212 } else if (nObjInCond == 2) {
0213 for (int i = 0; i < numberObjects; i++) {
0214 bool passCondition0i = checkObjectParameter(0, *(candVec->at(useBx, i)), index[i]);
0215 bool passCondition1i = checkObjectParameter(1, *(candVec->at(useBx, i)), index[i]);
0216
0217 if (!(passCondition0i || passCondition1i))
0218 continue;
0219
0220 for (int j = 0; j < numberObjects; j++) {
0221 if (i == j)
0222 continue;
0223 totalLoops++;
0224
0225 bool passCondition0j = checkObjectParameter(0, *(candVec->at(useBx, j)), index[i]);
0226 bool passCondition1j = checkObjectParameter(1, *(candVec->at(useBx, j)), index[i]);
0227
0228 bool pass = ((passCondition0i && passCondition1j) || (passCondition0j && passCondition1i));
0229
0230 if (pass) {
0231 if (m_gtCaloTemplate->wsc()) {
0232
0233
0234
0235 const int ObjInWscComb = 2;
0236 if (nObjInCond != ObjInWscComb) {
0237 if (m_verbosity) {
0238 edm::LogError("L1TGlobal")
0239 << "\n Error: "
0240 << "number of particles in condition with spatial correlation = " << nObjInCond
0241 << "\n it must be = " << ObjInWscComb << std::endl;
0242 }
0243
0244 continue;
0245 }
0246
0247 CaloTemplate::CorrelationParameter corrPar = *(m_gtCaloTemplate->correlationParameter());
0248
0249
0250 if (!checkRangeDeltaEta((candVec->at(useBx, i))->hwEta(),
0251 (candVec->at(useBx, j))->hwEta(),
0252 corrPar.deltaEtaRangeLower,
0253 corrPar.deltaEtaRangeUpper,
0254 7)) {
0255 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRangeDeltaEta" << std::endl;
0256 continue;
0257 }
0258
0259
0260 if (!checkRangeDeltaPhi((candVec->at(useBx, i))->hwPhi(),
0261 (candVec->at(useBx, j))->hwPhi(),
0262 corrPar.deltaPhiRangeLower,
0263 corrPar.deltaPhiRangeUpper)) {
0264 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRangeDeltaPhi" << std::endl;
0265 continue;
0266 }
0267
0268 }
0269
0270 objectsInComb.clear();
0271 objectsInComb.push_back(i);
0272 objectsInComb.push_back(j);
0273 condResult = true;
0274 passLoops++;
0275 combinationsInCond().push_back(objectsInComb);
0276 }
0277 }
0278 }
0279 } else if (nObjInCond == 3) {
0280 for (int i = 0; i < numberObjects; i++) {
0281 bool passCondition0i = checkObjectParameter(0, *(candVec->at(useBx, i)), index[i]);
0282 bool passCondition1i = checkObjectParameter(1, *(candVec->at(useBx, i)), index[i]);
0283 bool passCondition2i = checkObjectParameter(2, *(candVec->at(useBx, i)), index[i]);
0284
0285 if (!(passCondition0i || passCondition1i || passCondition2i))
0286 continue;
0287
0288 for (int j = 0; j < numberObjects; j++) {
0289 if (i == j)
0290 continue;
0291
0292 bool passCondition0j = checkObjectParameter(0, *(candVec->at(useBx, j)), index[i]);
0293 bool passCondition1j = checkObjectParameter(1, *(candVec->at(useBx, j)), index[i]);
0294 bool passCondition2j = checkObjectParameter(2, *(candVec->at(useBx, j)), index[i]);
0295
0296 if (!(passCondition0j || passCondition1j || passCondition2j))
0297 continue;
0298
0299 for (int k = 0; k < numberObjects; k++) {
0300 if (k == i || k == j)
0301 continue;
0302 totalLoops++;
0303
0304 bool passCondition0k = checkObjectParameter(0, *(candVec->at(useBx, k)), index[i]);
0305 bool passCondition1k = checkObjectParameter(1, *(candVec->at(useBx, k)), index[i]);
0306 bool passCondition2k = checkObjectParameter(2, *(candVec->at(useBx, k)), index[i]);
0307
0308 bool pass = ((passCondition0i && passCondition1j && passCondition2k) ||
0309 (passCondition0i && passCondition1k && passCondition2j) ||
0310 (passCondition0j && passCondition1k && passCondition2i) ||
0311 (passCondition0j && passCondition1i && passCondition2k) ||
0312 (passCondition0k && passCondition1i && passCondition2j) ||
0313 (passCondition0k && passCondition1j && passCondition2i));
0314 if (pass) {
0315 condResult = true;
0316 passLoops++;
0317 objectsInComb.clear();
0318 objectsInComb.push_back(i);
0319 objectsInComb.push_back(j);
0320 objectsInComb.push_back(k);
0321 combinationsInCond().push_back(objectsInComb);
0322 }
0323 }
0324 }
0325 }
0326 }
0327 else if (nObjInCond == 4) {
0328 for (int i = 0; i < numberObjects; i++) {
0329 bool passCondition0i = checkObjectParameter(0, *(candVec->at(useBx, i)), index[i]);
0330 bool passCondition1i = checkObjectParameter(1, *(candVec->at(useBx, i)), index[i]);
0331 bool passCondition2i = checkObjectParameter(2, *(candVec->at(useBx, i)), index[i]);
0332 bool passCondition3i = checkObjectParameter(3, *(candVec->at(useBx, i)), index[i]);
0333
0334 if (!(passCondition0i || passCondition1i || passCondition2i || passCondition3i))
0335 continue;
0336
0337 for (int j = 0; j < numberObjects; j++) {
0338 if (j == i)
0339 continue;
0340
0341 bool passCondition0j = checkObjectParameter(0, *(candVec->at(useBx, j)), index[i]);
0342 bool passCondition1j = checkObjectParameter(1, *(candVec->at(useBx, j)), index[i]);
0343 bool passCondition2j = checkObjectParameter(2, *(candVec->at(useBx, j)), index[i]);
0344 bool passCondition3j = checkObjectParameter(3, *(candVec->at(useBx, j)), index[i]);
0345
0346 if (!(passCondition0j || passCondition1j || passCondition2j || passCondition3j))
0347 continue;
0348
0349 for (int k = 0; k < numberObjects; k++) {
0350 if (k == i || k == j)
0351 continue;
0352
0353 bool passCondition0k = checkObjectParameter(0, *(candVec->at(useBx, k)), index[i]);
0354 bool passCondition1k = checkObjectParameter(1, *(candVec->at(useBx, k)), index[i]);
0355 bool passCondition2k = checkObjectParameter(2, *(candVec->at(useBx, k)), index[i]);
0356 bool passCondition3k = checkObjectParameter(3, *(candVec->at(useBx, k)), index[i]);
0357
0358 if (!(passCondition0k || passCondition1k || passCondition2k || passCondition3k))
0359 continue;
0360
0361 for (int m = 0; m < numberObjects; m++) {
0362 if (m == i || m == j || m == k)
0363 continue;
0364 totalLoops++;
0365
0366 bool passCondition0m = checkObjectParameter(0, *(candVec->at(useBx, m)), index[i]);
0367 bool passCondition1m = checkObjectParameter(1, *(candVec->at(useBx, m)), index[i]);
0368 bool passCondition2m = checkObjectParameter(2, *(candVec->at(useBx, m)), index[i]);
0369 bool passCondition3m = checkObjectParameter(3, *(candVec->at(useBx, m)), index[i]);
0370
0371 bool pass = ((passCondition0i && passCondition1j && passCondition2k && passCondition3m) ||
0372 (passCondition0i && passCondition1j && passCondition2m && passCondition3k) ||
0373 (passCondition0i && passCondition1k && passCondition2j && passCondition3m) ||
0374 (passCondition0i && passCondition1k && passCondition2m && passCondition3j) ||
0375 (passCondition0i && passCondition1m && passCondition2j && passCondition3k) ||
0376 (passCondition0i && passCondition1m && passCondition2k && passCondition3j) ||
0377 (passCondition0j && passCondition1i && passCondition2k && passCondition3m) ||
0378 (passCondition0j && passCondition1i && passCondition2m && passCondition3k) ||
0379 (passCondition0j && passCondition1k && passCondition2i && passCondition3m) ||
0380 (passCondition0j && passCondition1k && passCondition2m && passCondition3i) ||
0381 (passCondition0j && passCondition1m && passCondition2i && passCondition3k) ||
0382 (passCondition0j && passCondition1m && passCondition2k && passCondition3i) ||
0383 (passCondition0k && passCondition1i && passCondition2j && passCondition3m) ||
0384 (passCondition0k && passCondition1i && passCondition2m && passCondition3j) ||
0385 (passCondition0k && passCondition1j && passCondition2i && passCondition3m) ||
0386 (passCondition0k && passCondition1j && passCondition2m && passCondition3i) ||
0387 (passCondition0k && passCondition1m && passCondition2i && passCondition3j) ||
0388 (passCondition0k && passCondition1m && passCondition2j && passCondition3i) ||
0389 (passCondition0m && passCondition1i && passCondition2j && passCondition3k) ||
0390 (passCondition0m && passCondition1i && passCondition2k && passCondition3j) ||
0391 (passCondition0m && passCondition1j && passCondition2i && passCondition3k) ||
0392 (passCondition0m && passCondition1j && passCondition2k && passCondition3i) ||
0393 (passCondition0m && passCondition1k && passCondition2i && passCondition3j) ||
0394 (passCondition0m && passCondition1k && passCondition2j && passCondition3i));
0395 if (pass) {
0396 objectsInComb.clear();
0397 objectsInComb.push_back(i);
0398 objectsInComb.push_back(j);
0399 objectsInComb.push_back(k);
0400 objectsInComb.push_back(m);
0401 condResult = true;
0402 passLoops++;
0403 combinationsInCond().push_back(objectsInComb);
0404 }
0405 }
0406 }
0407 }
0408 }
0409 }
0410
0411 LogTrace("L1TGlobal") << "\n CaloCondition: total number of permutations found: " << totalLoops
0412 << "\n CaloCondition: number of permutations passing requirements: " << passLoops << "\n"
0413 << std::endl;
0414
0415 return condResult;
0416 }
0417
0418
0419 const l1t::L1Candidate* l1t::CaloCondition::getCandidate(const int bx, const int indexCand) const {
0420
0421
0422
0423 switch ((m_gtCaloTemplate->objectType())[0]) {
0424 case gtEG:
0425 return (m_uGtB->getCandL1EG())->at(bx, indexCand);
0426 break;
0427
0428 case gtJet:
0429 return (m_uGtB->getCandL1Jet())->at(bx, indexCand);
0430 break;
0431
0432 case gtTau:
0433 return (m_uGtB->getCandL1Tau())->at(bx, indexCand);
0434 break;
0435 default:
0436 return nullptr;
0437 break;
0438 }
0439
0440 return nullptr;
0441 }
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452 const bool l1t::CaloCondition::checkObjectParameter(const int iCondition,
0453 const l1t::L1Candidate& cand,
0454 unsigned int index) const {
0455
0456 int nObjInCond = m_gtCaloTemplate->nrObjects();
0457
0458 if (iCondition >= nObjInCond || iCondition < 0) {
0459 return false;
0460 }
0461
0462
0463
0464
0465
0466
0467 const CaloTemplate::ObjectParameter objPar = (*(m_gtCaloTemplate->objectParameter()))[iCondition];
0468
0469 LogDebug("L1TGlobal") << "\n CaloTemplate: "
0470 << "\n\t condRelativeBx = " << m_gtCaloTemplate->condRelativeBx() << "\n ObjectParameter : "
0471 << "\n\t etThreshold = " << objPar.etLowThreshold << " - " << objPar.etHighThreshold
0472 << "\n\t indexRange = " << objPar.indexLow << " - " << objPar.indexHigh
0473 << "\n\t etaRange = " << objPar.etaRange << "\n\t phiRange = " << objPar.phiRange
0474 << "\n\t isolationLUT= " << objPar.isolationLUT << std::endl;
0475
0476 LogDebug("L1TGlobal") << "\n l1t::Candidate : "
0477 << "\n\t hwPt = " << cand.hwPt() << "\n\t hwEta = " << cand.hwEta()
0478 << "\n\t hwPhi = " << cand.hwPhi() << std::endl;
0479
0480
0481 if (!checkThreshold(objPar.etLowThreshold, objPar.etHighThreshold, cand.hwPt(), m_gtCaloTemplate->condGEq())) {
0482 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkThreshold" << std::endl;
0483 return false;
0484 }
0485
0486
0487 if (!checkIndex(objPar.indexLow, objPar.indexHigh, index)) {
0488 LogDebug("L1TGlobal") << "\t\t ilt::Candidate Failed checkIndex " << std::endl;
0489 return false;
0490 }
0491
0492
0493 if (!checkRangeEta(cand.hwEta(), objPar.etaWindows, 7)) {
0494 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRange(eta)" << std::endl;
0495 return false;
0496 }
0497
0498
0499
0500
0501
0502
0503 if (!checkRangePhi(cand.hwPhi(),
0504 objPar.phiWindow1Lower,
0505 objPar.phiWindow1Upper,
0506 objPar.phiWindow2Lower,
0507 objPar.phiWindow2Upper)) {
0508 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRange(phi)" << std::endl;
0509 return false;
0510 }
0511
0512
0513
0514 if (cand.hwIso() > 4) {
0515 LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwIso = " << cand.hwIso() << std::endl;
0516 return false;
0517 }
0518 bool passIsoLUT = ((objPar.isolationLUT >> cand.hwIso()) & 1);
0519 if (!passIsoLUT) {
0520 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed isolation requirement" << std::endl;
0521 return false;
0522 }
0523
0524
0525
0526
0527 if (cand.hwQual() > 7) {
0528 LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwQual = " << cand.hwQual() << std::endl;
0529 return false;
0530 }
0531
0532 bool hasDisplacedLUT =
0533 objPar.displacedLUT & 1;
0534 bool passDisplacedLUT = (objPar.displacedLUT & cand.hwQual());
0535 if (hasDisplacedLUT &&
0536 !passDisplacedLUT) {
0537 LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed displaced requirement" << std::endl;
0538 return false;
0539 }
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550 return true;
0551 }
0552
0553 void l1t::CaloCondition::print(std::ostream& myCout) const {
0554 m_gtCaloTemplate->print(myCout);
0555
0556 myCout << " Number of bits for eta of calorimeter objects = " << m_ifCaloEtaNumberBits << std::endl;
0557 myCout << " Maximum number of bins for the delta phi scales = " << m_corrParDeltaPhiNrBins << "\n " << std::endl;
0558
0559 ConditionEvaluation::print(myCout);
0560 }