File indexing completed on 2024-04-06 12:20:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031
0032 #include "DataFormats/L1TCalorimeter/interface/CaloTower.h"
0033 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0034 #include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h"
0035
0036 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometry.hh"
0037
0038 #include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh"
0039
0040 using namespace l1t;
0041
0042
0043
0044
0045
0046 class L1TCaloLayer1Validator : public edm::one::EDAnalyzer<> {
0047 public:
0048 explicit L1TCaloLayer1Validator(const edm::ParameterSet&);
0049
0050 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0051
0052 private:
0053 void analyze(const edm::Event&, const edm::EventSetup&) override;
0054 void endJob() override;
0055
0056
0057
0058 edm::EDGetTokenT<CaloTowerBxCollection> testTowerToken;
0059 edm::EDGetTokenT<CaloTowerBxCollection> emulTowerToken;
0060
0061 edm::EDGetTokenT<L1CaloRegionCollection> testRegionToken;
0062 edm::EDGetTokenT<L1CaloRegionCollection> emulRegionToken;
0063
0064 uint32_t eventCount;
0065 uint32_t badEventCount;
0066 uint32_t towerCount;
0067 uint32_t badTowerCount;
0068 uint32_t nonZeroTowerCount;
0069 uint32_t badNonZeroTowerCount;
0070 uint32_t regionCount;
0071 uint32_t badRegionCount;
0072 uint32_t nonZeroRegionCount;
0073 uint32_t badNonZeroRegionCount;
0074
0075 uint32_t ngRegion[22];
0076 uint32_t nbRegion[22];
0077 uint32_t zgRegion[22];
0078 uint32_t zbRegion[22];
0079
0080 uint32_t ngCard[18];
0081 uint32_t nbCard[18];
0082 uint32_t zgCard[18];
0083 uint32_t zbCard[18];
0084
0085 uint32_t tLrEmulTotET;
0086 uint32_t tErEmulTotET;
0087 uint32_t tGrEmulTotET;
0088
0089 uint32_t tLeTotET;
0090 uint32_t tEeTotET;
0091 uint32_t tGeTotET;
0092
0093 bool validateTowers;
0094 bool validateRegions;
0095
0096 bool verbose;
0097 };
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 L1TCaloLayer1Validator::L1TCaloLayer1Validator(const edm::ParameterSet& iConfig)
0111 : testTowerToken(consumes<CaloTowerBxCollection>(iConfig.getParameter<edm::InputTag>("testTowerToken"))),
0112 emulTowerToken(consumes<CaloTowerBxCollection>(iConfig.getParameter<edm::InputTag>("emulTowerToken"))),
0113 testRegionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("testRegionToken"))),
0114 emulRegionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("emulRegionToken"))),
0115 eventCount(0),
0116 badEventCount(0),
0117 towerCount(0),
0118 badTowerCount(0),
0119 nonZeroTowerCount(0),
0120 badNonZeroTowerCount(0),
0121 regionCount(0),
0122 badRegionCount(0),
0123 nonZeroRegionCount(0),
0124 badNonZeroRegionCount(0),
0125 tLrEmulTotET(0),
0126 tErEmulTotET(0),
0127 tGrEmulTotET(0),
0128 tLeTotET(0),
0129 tEeTotET(0),
0130 tGeTotET(0),
0131 validateTowers(iConfig.getParameter<bool>("validateTowers")),
0132 validateRegions(iConfig.getParameter<bool>("validateRegions")),
0133 verbose(iConfig.getParameter<bool>("verbose")) {
0134 for (uint32_t r = 0; r < 22; r++)
0135 ngRegion[r] = nbRegion[r] = zgRegion[r] = zbRegion[r] = 0;
0136 for (uint32_t c = 0; c < 18; c++)
0137 ngCard[c] = nbCard[c] = zgCard[c] = zbCard[c] = 0;
0138 }
0139
0140
0141
0142
0143
0144
0145 void L1TCaloLayer1Validator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0146 using namespace edm;
0147 bool badEvent = false;
0148 int theBX = 0;
0149
0150
0151
0152
0153 edm::Handle<CaloTowerBxCollection> emulTowers;
0154 iEvent.getByToken(emulTowerToken, emulTowers);
0155 edm::Handle<L1CaloRegionCollection> testRegions;
0156 iEvent.getByToken(testRegionToken, testRegions);
0157 edm::Handle<L1CaloRegionCollection> emulRegions;
0158 iEvent.getByToken(emulRegionToken, emulRegions);
0159
0160 if (validateTowers) {
0161
0162 edm::Handle<CaloTowerBxCollection> testTowers;
0163 iEvent.getByToken(testTowerToken, testTowers);
0164 for (std::vector<CaloTower>::const_iterator testTower = testTowers->begin(theBX);
0165 testTower != testTowers->end(theBX);
0166 ++testTower) {
0167 int test_iEta = testTower->hwEta();
0168 int test_iPhi = testTower->hwPhi();
0169 int test_et = testTower->hwPt();
0170 int test_er = testTower->hwEtRatio();
0171 int test_fb = testTower->hwQual();
0172 for (std::vector<CaloTower>::const_iterator emulTower = emulTowers->begin(theBX);
0173 emulTower != emulTowers->end(theBX);
0174 ++emulTower) {
0175 int emul_iEta = emulTower->hwEta();
0176 int emul_iPhi = emulTower->hwPhi();
0177 int emul_et = emulTower->hwPt();
0178 int emul_er = emulTower->hwEtRatio();
0179 int emul_fb = emulTower->hwQual();
0180 bool success = true;
0181 if (test_iEta == emul_iEta && test_iPhi == emul_iPhi) {
0182 if (test_et != emul_et) {
0183 success = false;
0184 }
0185 if (test_er != emul_er) {
0186 success = false;
0187 }
0188 if (test_fb != emul_fb) {
0189 success = false;
0190 }
0191 if (!success) {
0192 if (test_et != emul_et) {
0193 if (verbose)
0194 LOG_ERROR << "ET ";
0195 }
0196 if (test_er != emul_er) {
0197 if (verbose)
0198 LOG_ERROR << "ER ";
0199 }
0200 if (test_fb != emul_fb) {
0201 if (verbose)
0202 LOG_ERROR << "FB ";
0203 }
0204 if (verbose)
0205 LOG_ERROR << "Checks failed for tower (" << std::dec << test_iEta << ", " << test_iPhi << ") : ("
0206 << test_et << ", " << test_er << ", " << test_fb << ") != (" << emul_et << ", " << emul_er
0207 << ", " << emul_fb << ")" << std::endl;
0208 badEvent = true;
0209 badTowerCount++;
0210 if (test_et > 0)
0211 badNonZeroTowerCount++;
0212 }
0213 towerCount++;
0214 if (test_et > 0)
0215 nonZeroTowerCount++;
0216 }
0217 if (!success && test_et == emul_et && test_iPhi == emul_iPhi) {
0218 if (verbose)
0219 LOG_ERROR << "Incidental match for tower (" << std::dec << test_iEta << ", " << test_iPhi << ") : ("
0220 << test_et << ", " << test_er << ", " << test_fb << ") != (" << emul_iEta << "," << emul_iPhi
0221 << ") :(" << emul_et << ", " << emul_er << ", " << emul_fb << ")" << std::endl;
0222 }
0223 }
0224 }
0225 }
0226
0227
0228
0229 if (validateRegions) {
0230 UCTGeometry g;
0231 uint32_t testRegionTotET = 0;
0232 uint32_t emulRegionTotET = 0;
0233 for (std::vector<L1CaloRegion>::const_iterator testRegion = testRegions->begin(); testRegion != testRegions->end();
0234 ++testRegion) {
0235
0236 uint32_t test_et = testRegion->et();
0237 testRegionTotET += test_et;
0238 uint32_t test_rEta = testRegion->id().ieta();
0239 uint32_t test_rPhi = testRegion->id().iphi();
0240
0241
0242 bool test_negativeEta = false;
0243 int test_cEta = (test_rEta - 11) * 4 + 1;
0244 if (test_rEta < 11) {
0245 test_negativeEta = true;
0246 test_cEta = -((10 - test_rEta) * 4 + 1);
0247 }
0248 int test_cPhi = test_rPhi * 4 + 1;
0249 uint32_t test_crate = g.getCrate(test_cEta, test_cPhi);
0250 uint32_t test_card = g.getCard(test_cEta, test_cPhi);
0251 uint32_t test_region = g.getRegion(test_cEta, test_cPhi);
0252 for (std::vector<L1CaloRegion>::const_iterator emulRegion = emulRegions->begin();
0253 emulRegion != emulRegions->end();
0254 ++emulRegion) {
0255
0256 uint32_t emul_et = emulRegion->et();
0257 if (testRegion == testRegions->begin())
0258 emulRegionTotET += emul_et;
0259 uint32_t emul_rEta = emulRegion->id().ieta();
0260 uint32_t emul_rPhi = emulRegion->id().iphi();
0261
0262
0263 bool emul_negativeEta = false;
0264 int emul_cEta = (emul_rEta - 11) * 4 + 1;
0265 if (emul_rEta < 11) {
0266 emul_negativeEta = true;
0267 emul_cEta = -((10 - emul_rEta) * 4 + 1);
0268 }
0269 int emul_cPhi = emul_rPhi * 4 + 1;
0270 uint32_t emul_crate = g.getCrate(emul_cEta, emul_cPhi);
0271 uint32_t emul_card = g.getCard(emul_cEta, emul_cPhi);
0272 uint32_t emul_region = g.getRegion(emul_cEta, emul_cPhi);
0273 bool success = true;
0274 if (test_rEta == emul_rEta && test_rPhi == emul_rPhi) {
0275 if (test_et != emul_et)
0276 success = false;
0277
0278
0279 if (!success) {
0280 if (verbose)
0281 LOG_ERROR << "Checks failed for region (" << std::dec << test_rEta << ", " << test_rPhi << ") ("
0282 << test_negativeEta << ", " << test_crate << ", " << test_card << ", " << test_region
0283 << ", "
0284
0285
0286 << test_et << ") != (" << emul_negativeEta << ", " << emul_crate << ", " << emul_card << ", "
0287 << emul_region
0288 << ", "
0289
0290
0291 << emul_et << ")" << std::endl;
0292 badEvent = true;
0293 badRegionCount++;
0294 if (test_et > 0) {
0295 badNonZeroRegionCount++;
0296 nbRegion[test_rEta]++;
0297 nbCard[test_rPhi]++;
0298 } else {
0299 zbRegion[test_rEta]++;
0300 zbCard[test_rPhi]++;
0301 }
0302 } else {
0303 if (test_et > 0) {
0304 ngRegion[test_rEta]++;
0305 ngCard[test_rPhi]++;
0306 if (verbose)
0307 LOG_ERROR << "Checks passed for region (" << std::dec << test_rEta << ", " << test_rPhi << ") ("
0308 << test_negativeEta << ", " << test_crate << ", " << test_card << ", " << test_region
0309 << ", "
0310
0311
0312 << test_et << ") == (" << emul_negativeEta << ", " << emul_crate << ", " << emul_card << ", "
0313 << emul_region
0314 << ", "
0315
0316
0317 << emul_et << ")" << std::endl;
0318 } else {
0319 zgRegion[test_rEta]++;
0320 zgCard[test_rPhi]++;
0321 }
0322 }
0323 regionCount++;
0324 if (test_et > 0)
0325 nonZeroRegionCount++;
0326 }
0327 if (!success && test_et == emul_et) {
0328 if (verbose)
0329 LOG_ERROR << "Incidental match for region (" << std::dec << test_rEta << ", " << test_rPhi
0330 << ", "
0331
0332
0333 << test_et << ") != (" << emul_rEta << ", " << emul_rPhi
0334 << ", "
0335
0336
0337 << emul_et << ")" << std::endl;
0338 }
0339 }
0340 }
0341 uint32_t emulTowerTotET = 0;
0342 for (std::vector<CaloTower>::const_iterator emulTower = emulTowers->begin(theBX);
0343 emulTower != emulTowers->end(theBX);
0344 ++emulTower) {
0345 int twr_et = emulTower->hwPt();
0346 int twr_cEta = emulTower->hwEta();
0347 int twr_cPhi = emulTower->hwPhi();
0348 uint32_t twr_region = g.getRegion(twr_cEta, twr_cPhi);
0349 uint32_t twr_gEta = 10 - twr_region;
0350 if (twr_cEta > 0)
0351 twr_gEta = twr_region + 11;
0352 uint32_t twr_gPhi = g.getUCTRegionPhiIndex(twr_cPhi);
0353 if (badEvent && twr_et > 0) {
0354 if (verbose)
0355 LOG_ERROR << "Non-zero tower in region (" << twr_gEta << ", " << twr_gPhi << ") "
0356 << "(cEta, cPhi, et) = (" << twr_cEta << ", " << twr_cPhi << ", " << twr_et << ")" << std::endl;
0357 }
0358 if (std::abs(twr_cEta) <= 28)
0359 emulTowerTotET += twr_et;
0360 }
0361
0362 if (emulTowerTotET < emulRegionTotET)
0363 tLrEmulTotET++;
0364 else if (emulTowerTotET > emulRegionTotET)
0365 tGrEmulTotET++;
0366 else
0367 tErEmulTotET++;
0368
0369 if (testRegionTotET < emulRegionTotET)
0370 tLeTotET++;
0371 else if (testRegionTotET > emulRegionTotET)
0372 tGeTotET++;
0373 else
0374 tEeTotET++;
0375 }
0376
0377
0378
0379 if (badEvent)
0380 badEventCount++;
0381 eventCount++;
0382 }
0383
0384
0385 void L1TCaloLayer1Validator::endJob() {
0386 if (validateTowers)
0387 LOG_ERROR << "L1TCaloLayer1Validator: Summary is Non-Zero Bad Tower / Bad Tower / Event Count = ("
0388 << badNonZeroTowerCount << " of " << nonZeroTowerCount << ") / (" << badTowerCount << " of " << towerCount
0389 << ") / (" << badEventCount << " of " << eventCount << ")" << std::endl;
0390 if (validateRegions) {
0391 LOG_ERROR << "L1TCaloLayer1Validator: Summary is Non-Zero Bad Region / Bad Region / Event Count = ("
0392 << badNonZeroRegionCount << " of " << nonZeroRegionCount << ") / (" << badRegionCount << " of "
0393 << regionCount << ") / (" << badEventCount << " of " << eventCount << ")" << std::endl;
0394 LOG_ERROR << "L1TCaloLayer1Validator reTa, non-zero-good / non-zero-bad / zero-good / zero-bad region[rEta] = "
0395 << std::endl;
0396 for (uint32_t r = 0; r < 22; r++)
0397 LOG_ERROR << r << ", " << ngRegion[r] << " / " << nbRegion[r] << " / " << zgRegion[r] << " / " << zbRegion[r]
0398 << std::endl;
0399 LOG_ERROR << "L1TCaloLayer1Validator rPhi, non-zero-good / non-zero-bad / zero-good / zero-bad region[rPhi] = "
0400 << std::endl;
0401 for (uint32_t r = 0; r < 18; r++)
0402 LOG_ERROR << r << ", " << ngCard[r] << " / " << nbCard[r] << " / " << zgCard[r] << " / " << zbCard[r]
0403 << std::endl;
0404 LOG_ERROR << "L1TCaloLayer1Validator : Total ET emulator tower vs region; less / equal / greater counts: "
0405 << tLrEmulTotET << " / " << tErEmulTotET << " / " << tGrEmulTotET << std::endl;
0406 LOG_ERROR << "L1TCaloLayer1Validator : Total ET region test vs emulator; less / equal / greater counts: "
0407 << tLeTotET << " / " << tEeTotET << " / " << tGeTotET << std::endl;
0408 }
0409 }
0410
0411
0412 void L1TCaloLayer1Validator::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0413
0414
0415 edm::ParameterSetDescription desc;
0416 desc.setUnknown();
0417 descriptions.addDefault(desc);
0418 }
0419
0420
0421 DEFINE_FWK_MODULE(L1TCaloLayer1Validator);