Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-27 04:18:02

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/L1TCaloLayer1
0004 // Class:      L1TCaloLayer1Validator
0005 //
0006 /**\class L1TCaloLayer1Validator L1TCaloLayer1Validator.cc L1Trigger/L1TCaloLayer1/plugins/L1TCaloLayer1Validator.cc
0007 
0008  Description: This ED Analyzer compares output of CMS L1 Trigger Calo Layer-1 output (CaloTowers) from two sources
0009 
0010  Implementation:
0011               It is expected that we compare CaloTowers from the spy source to that of the emulator.  
0012               It can be used to compare any two CaloTower collections
0013 */
0014 //
0015 // Original Author:  Sridhara Dasu
0016 //         Created:  Sun, 11 Oct 2015 08:14:01 GMT
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
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 // class declaration
0044 //
0045 
0046 class L1TCaloLayer1Validator : public edm::one::EDAnalyzer<> {
0047 public:
0048   explicit L1TCaloLayer1Validator(const edm::ParameterSet&);
0049   ~L1TCaloLayer1Validator() override;
0050 
0051   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052 
0053 private:
0054   void beginJob() override;
0055   void analyze(const edm::Event&, const edm::EventSetup&) override;
0056   void endJob() override;
0057 
0058   //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
0059   //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
0060   //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0061   //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0062 
0063   // ----------member data ---------------------------
0064 
0065   edm::EDGetTokenT<CaloTowerBxCollection> testTowerToken;
0066   edm::EDGetTokenT<CaloTowerBxCollection> emulTowerToken;
0067 
0068   edm::EDGetTokenT<L1CaloRegionCollection> testRegionToken;
0069   edm::EDGetTokenT<L1CaloRegionCollection> emulRegionToken;
0070 
0071   uint32_t eventCount;
0072   uint32_t badEventCount;
0073   uint32_t towerCount;
0074   uint32_t badTowerCount;
0075   uint32_t nonZeroTowerCount;
0076   uint32_t badNonZeroTowerCount;
0077   uint32_t regionCount;
0078   uint32_t badRegionCount;
0079   uint32_t nonZeroRegionCount;
0080   uint32_t badNonZeroRegionCount;
0081 
0082   uint32_t ngRegion[22];
0083   uint32_t nbRegion[22];
0084   uint32_t zgRegion[22];
0085   uint32_t zbRegion[22];
0086 
0087   uint32_t ngCard[18];
0088   uint32_t nbCard[18];
0089   uint32_t zgCard[18];
0090   uint32_t zbCard[18];
0091 
0092   uint32_t tLrEmulTotET;
0093   uint32_t tErEmulTotET;
0094   uint32_t tGrEmulTotET;
0095 
0096   uint32_t tLeTotET;
0097   uint32_t tEeTotET;
0098   uint32_t tGeTotET;
0099 
0100   bool validateTowers;
0101   bool validateRegions;
0102 
0103   bool verbose;
0104 };
0105 
0106 //
0107 // constants, enums and typedefs
0108 //
0109 
0110 //
0111 // static data member definitions
0112 //
0113 
0114 //
0115 // constructors and destructor
0116 //
0117 L1TCaloLayer1Validator::L1TCaloLayer1Validator(const edm::ParameterSet& iConfig)
0118     : testTowerToken(consumes<CaloTowerBxCollection>(iConfig.getParameter<edm::InputTag>("testTowerToken"))),
0119       emulTowerToken(consumes<CaloTowerBxCollection>(iConfig.getParameter<edm::InputTag>("emulTowerToken"))),
0120       testRegionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("testRegionToken"))),
0121       emulRegionToken(consumes<L1CaloRegionCollection>(iConfig.getParameter<edm::InputTag>("emulRegionToken"))),
0122       eventCount(0),
0123       badEventCount(0),
0124       towerCount(0),
0125       badTowerCount(0),
0126       nonZeroTowerCount(0),
0127       badNonZeroTowerCount(0),
0128       regionCount(0),
0129       badRegionCount(0),
0130       nonZeroRegionCount(0),
0131       badNonZeroRegionCount(0),
0132       tLrEmulTotET(0),
0133       tErEmulTotET(0),
0134       tGrEmulTotET(0),
0135       tLeTotET(0),
0136       tEeTotET(0),
0137       tGeTotET(0),
0138       validateTowers(iConfig.getParameter<bool>("validateTowers")),
0139       validateRegions(iConfig.getParameter<bool>("validateRegions")),
0140       verbose(iConfig.getParameter<bool>("verbose")) {
0141   for (uint32_t r = 0; r < 22; r++)
0142     ngRegion[r] = nbRegion[r] = zgRegion[r] = zbRegion[r] = 0;
0143   for (uint32_t c = 0; c < 18; c++)
0144     ngCard[c] = nbCard[c] = zgCard[c] = zbCard[c] = 0;
0145 }
0146 
0147 L1TCaloLayer1Validator::~L1TCaloLayer1Validator() {}
0148 
0149 //
0150 // member functions
0151 //
0152 
0153 // ------------ method called for each event  ------------
0154 void L1TCaloLayer1Validator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0155   using namespace edm;
0156   bool badEvent = false;
0157   int theBX = 0;
0158 
0159   // Emulator calo towers and regions should always be available - get them
0160   // Data will always contain calo regions, but not necessarily calo towers
0161 
0162   edm::Handle<CaloTowerBxCollection> emulTowers;
0163   iEvent.getByToken(emulTowerToken, emulTowers);
0164   edm::Handle<L1CaloRegionCollection> testRegions;
0165   iEvent.getByToken(testRegionToken, testRegions);
0166   edm::Handle<L1CaloRegionCollection> emulRegions;
0167   iEvent.getByToken(emulRegionToken, emulRegions);
0168 
0169   if (validateTowers) {
0170     // Test towers will be available for spy and fat events only
0171     edm::Handle<CaloTowerBxCollection> testTowers;
0172     iEvent.getByToken(testTowerToken, testTowers);
0173     for (std::vector<CaloTower>::const_iterator testTower = testTowers->begin(theBX);
0174          testTower != testTowers->end(theBX);
0175          ++testTower) {
0176       int test_iEta = testTower->hwEta();
0177       int test_iPhi = testTower->hwPhi();
0178       int test_et = testTower->hwPt();
0179       int test_er = testTower->hwEtRatio();
0180       int test_fb = testTower->hwQual();
0181       for (std::vector<CaloTower>::const_iterator emulTower = emulTowers->begin(theBX);
0182            emulTower != emulTowers->end(theBX);
0183            ++emulTower) {
0184         int emul_iEta = emulTower->hwEta();
0185         int emul_iPhi = emulTower->hwPhi();
0186         int emul_et = emulTower->hwPt();
0187         int emul_er = emulTower->hwEtRatio();
0188         int emul_fb = emulTower->hwQual();
0189         bool success = true;
0190         if (test_iEta == emul_iEta && test_iPhi == emul_iPhi) {
0191           if (test_et != emul_et) {
0192             success = false;
0193           }
0194           if (test_er != emul_er) {
0195             success = false;
0196           }
0197           if (test_fb != emul_fb) {
0198             success = false;
0199           }
0200           if (!success) {
0201             if (test_et != emul_et) {
0202               if (verbose)
0203                 LOG_ERROR << "ET ";
0204             }
0205             if (test_er != emul_er) {
0206               if (verbose)
0207                 LOG_ERROR << "ER ";
0208             }
0209             if (test_fb != emul_fb) {
0210               if (verbose)
0211                 LOG_ERROR << "FB ";
0212             }
0213             if (verbose)
0214               LOG_ERROR << "Checks failed for tower (" << std::dec << test_iEta << ", " << test_iPhi << ") : ("
0215                         << test_et << ", " << test_er << ", " << test_fb << ") != (" << emul_et << ", " << emul_er
0216                         << ", " << emul_fb << ")" << std::endl;
0217             badEvent = true;
0218             badTowerCount++;
0219             if (test_et > 0)
0220               badNonZeroTowerCount++;
0221           }
0222           towerCount++;
0223           if (test_et > 0)
0224             nonZeroTowerCount++;
0225         }
0226         if (!success && test_et == emul_et && test_iPhi == emul_iPhi) {
0227           if (verbose)
0228             LOG_ERROR << "Incidental match for tower (" << std::dec << test_iEta << ", " << test_iPhi << ") : ("
0229                       << test_et << ", " << test_er << ", " << test_fb << ") != (" << emul_iEta << "," << emul_iPhi
0230                       << ") :(" << emul_et << ", " << emul_er << ", " << emul_fb << ")" << std::endl;
0231         }
0232       }
0233     }
0234   }
0235 
0236   // Region Validation
0237 
0238   if (validateRegions) {
0239     UCTGeometry g;
0240     uint32_t testRegionTotET = 0;
0241     uint32_t emulRegionTotET = 0;
0242     for (std::vector<L1CaloRegion>::const_iterator testRegion = testRegions->begin(); testRegion != testRegions->end();
0243          ++testRegion) {
0244       //       uint16_t test_raw = testRegion->raw();
0245       uint32_t test_et = testRegion->et();
0246       testRegionTotET += test_et;
0247       uint32_t test_rEta = testRegion->id().ieta();
0248       uint32_t test_rPhi = testRegion->id().iphi();
0249       //       uint32_t test_iEta = (test_raw >> 12) & 0x3;
0250       //       uint32_t test_iPhi = (test_raw >> 14) & 0x3;
0251       bool test_negativeEta = false;
0252       int test_cEta = (test_rEta - 11) * 4 + 1;  //test_iEta + 1;
0253       if (test_rEta < 11) {
0254         test_negativeEta = true;
0255         test_cEta = -((10 - test_rEta) * 4 + 1);  //test_iEta + 1);
0256       }
0257       int test_cPhi = test_rPhi * 4 + 1;  //test_iPhi + 1;
0258       uint32_t test_crate = g.getCrate(test_cEta, test_cPhi);
0259       uint32_t test_card = g.getCard(test_cEta, test_cPhi);
0260       uint32_t test_region = g.getRegion(test_cEta, test_cPhi);
0261       for (std::vector<L1CaloRegion>::const_iterator emulRegion = emulRegions->begin();
0262            emulRegion != emulRegions->end();
0263            ++emulRegion) {
0264         //   uint16_t emul_raw = emulRegion->raw();
0265         uint32_t emul_et = emulRegion->et();
0266         if (testRegion == testRegions->begin())
0267           emulRegionTotET += emul_et;  // increment only once!
0268         uint32_t emul_rEta = emulRegion->id().ieta();
0269         uint32_t emul_rPhi = emulRegion->id().iphi();
0270         //   uint32_t emul_iEta = (emul_raw >> 12) & 0x3;
0271         //   uint32_t emul_iPhi = (emul_raw >> 14) & 0x3;
0272         bool emul_negativeEta = false;
0273         int emul_cEta = (emul_rEta - 11) * 4 + 1;  //emul_iEta + 1;
0274         if (emul_rEta < 11) {
0275           emul_negativeEta = true;
0276           emul_cEta = -((10 - emul_rEta) * 4 + 1);  //emul_iEta + 1);
0277         }
0278         int emul_cPhi = emul_rPhi * 4 + 1;  //emul_iPhi + 1;
0279         uint32_t emul_crate = g.getCrate(emul_cEta, emul_cPhi);
0280         uint32_t emul_card = g.getCard(emul_cEta, emul_cPhi);
0281         uint32_t emul_region = g.getRegion(emul_cEta, emul_cPhi);
0282         bool success = true;
0283         if (test_rEta == emul_rEta && test_rPhi == emul_rPhi) {
0284           if (test_et != emul_et)
0285             success = false;
0286           //if(test_iEta != emul_iEta) success = false;
0287           //if(test_iPhi != emul_iPhi) success = false;
0288           if (!success) {
0289             if (verbose)
0290               LOG_ERROR << "Checks failed for region (" << std::dec << test_rEta << ", " << test_rPhi << ") ("
0291                         << test_negativeEta << ", " << test_crate << ", " << test_card << ", " << test_region
0292                         << ", "
0293                         //             << test_iEta << ", "
0294                         //                      << test_iPhi << ", "
0295                         << test_et << ") != (" << emul_negativeEta << ", " << emul_crate << ", " << emul_card << ", "
0296                         << emul_region
0297                         << ", "
0298                         //             << emul_iEta << ", "
0299                         //             << emul_iPhi << ", "
0300                         << emul_et << ")" << std::endl;
0301             badEvent = true;
0302             badRegionCount++;
0303             if (test_et > 0) {
0304               badNonZeroRegionCount++;
0305               nbRegion[test_rEta]++;
0306               nbCard[test_rPhi]++;
0307             } else {
0308               zbRegion[test_rEta]++;
0309               zbCard[test_rPhi]++;
0310             }
0311           } else {
0312             if (test_et > 0) {
0313               ngRegion[test_rEta]++;
0314               ngCard[test_rPhi]++;
0315               if (verbose)
0316                 LOG_ERROR << "Checks passed for region (" << std::dec << test_rEta << ", " << test_rPhi << ") ("
0317                           << test_negativeEta << ", " << test_crate << ", " << test_card << ", " << test_region
0318                           << ", "
0319                           //               << test_iEta << ", "
0320                           //                      << test_iPhi << ", "
0321                           << test_et << ") == (" << emul_negativeEta << ", " << emul_crate << ", " << emul_card << ", "
0322                           << emul_region
0323                           << ", "
0324                           //               << emul_iEta << ", "
0325                           //               << emul_iPhi << ", "
0326                           << emul_et << ")" << std::endl;
0327             } else {
0328               zgRegion[test_rEta]++;
0329               zgCard[test_rPhi]++;
0330             }
0331           }
0332           regionCount++;
0333           if (test_et > 0)
0334             nonZeroRegionCount++;
0335         }
0336         if (!success && test_et == emul_et) {  // && test_iPhi == emul_iPhi) {
0337           if (verbose)
0338             LOG_ERROR << "Incidental match for region (" << std::dec << test_rEta << ", " << test_rPhi
0339                       << ", "
0340                       //                 << test_iEta << ", "
0341                       //                 << test_iPhi << ", "
0342                       << test_et << ") != (" << emul_rEta << ", " << emul_rPhi
0343                       << ", "
0344                       //                 << emul_iEta << ", "
0345                       //                 << emul_iPhi << ", "
0346                       << emul_et << ")" << std::endl;
0347         }
0348       }
0349     }
0350     uint32_t emulTowerTotET = 0;
0351     for (std::vector<CaloTower>::const_iterator emulTower = emulTowers->begin(theBX);
0352          emulTower != emulTowers->end(theBX);
0353          ++emulTower) {
0354       int twr_et = emulTower->hwPt();
0355       int twr_cEta = emulTower->hwEta();
0356       int twr_cPhi = emulTower->hwPhi();
0357       uint32_t twr_region = g.getRegion(twr_cEta, twr_cPhi);
0358       uint32_t twr_gEta = 10 - twr_region;
0359       if (twr_cEta > 0)
0360         twr_gEta = twr_region + 11;
0361       uint32_t twr_gPhi = g.getUCTRegionPhiIndex(twr_cPhi);
0362       if (badEvent && twr_et > 0) {
0363         if (verbose)
0364           LOG_ERROR << "Non-zero tower in region (" << twr_gEta << ", " << twr_gPhi << ") "
0365                     << "(cEta, cPhi, et) = (" << twr_cEta << ", " << twr_cPhi << ", " << twr_et << ")" << std::endl;
0366       }
0367       if (std::abs(twr_cEta) <= 28)
0368         emulTowerTotET += twr_et;  // Exclude HF towers for now
0369     }
0370     // Increment counters for emulated total tower ET comparison with total region ET
0371     if (emulTowerTotET < emulRegionTotET)
0372       tLrEmulTotET++;
0373     else if (emulTowerTotET > emulRegionTotET)
0374       tGrEmulTotET++;
0375     else
0376       tErEmulTotET++;
0377     // Increment counters for emulated total region ET comparison with region test ET
0378     if (testRegionTotET < emulRegionTotET)
0379       tLeTotET++;
0380     else if (testRegionTotET > emulRegionTotET)
0381       tGeTotET++;
0382     else
0383       tEeTotET++;
0384   }
0385 
0386   // Event counters
0387 
0388   if (badEvent)
0389     badEventCount++;
0390   eventCount++;
0391 }
0392 
0393 // ------------ method called once each job just before starting event loop  ------------
0394 void L1TCaloLayer1Validator::beginJob() {}
0395 
0396 // ------------ method called once each job just after ending the event loop  ------------
0397 void L1TCaloLayer1Validator::endJob() {
0398   if (validateTowers)
0399     LOG_ERROR << "L1TCaloLayer1Validator: Summary is Non-Zero Bad Tower / Bad Tower / Event Count = ("
0400               << badNonZeroTowerCount << " of " << nonZeroTowerCount << ") / (" << badTowerCount << " of " << towerCount
0401               << ") / (" << badEventCount << " of " << eventCount << ")" << std::endl;
0402   if (validateRegions) {
0403     LOG_ERROR << "L1TCaloLayer1Validator: Summary is Non-Zero Bad Region / Bad Region / Event Count = ("
0404               << badNonZeroRegionCount << " of " << nonZeroRegionCount << ") / (" << badRegionCount << " of "
0405               << regionCount << ") / (" << badEventCount << " of " << eventCount << ")" << std::endl;
0406     LOG_ERROR << "L1TCaloLayer1Validator reTa, non-zero-good / non-zero-bad / zero-good / zero-bad region[rEta] = "
0407               << std::endl;
0408     for (uint32_t r = 0; r < 22; r++)
0409       LOG_ERROR << r << ", " << ngRegion[r] << " / " << nbRegion[r] << " / " << zgRegion[r] << " / " << zbRegion[r]
0410                 << std::endl;
0411     LOG_ERROR << "L1TCaloLayer1Validator rPhi, non-zero-good / non-zero-bad / zero-good / zero-bad region[rPhi] = "
0412               << std::endl;
0413     for (uint32_t r = 0; r < 18; r++)
0414       LOG_ERROR << r << ", " << ngCard[r] << " / " << nbCard[r] << " / " << zgCard[r] << " / " << zbCard[r]
0415                 << std::endl;
0416     LOG_ERROR << "L1TCaloLayer1Validator : Total ET emulator tower vs region; less / equal / greater counts: "
0417               << tLrEmulTotET << " / " << tErEmulTotET << " / " << tGrEmulTotET << std::endl;
0418     LOG_ERROR << "L1TCaloLayer1Validator : Total ET region test vs emulator; less / equal / greater counts: "
0419               << tLeTotET << " / " << tEeTotET << " / " << tGeTotET << std::endl;
0420   }
0421 }
0422 
0423 // ------------ method called when starting to processes a run  ------------
0424 /*
0425 void 
0426 L1TCaloLayer1Validator::beginRun(edm::Run const&, edm::EventSetup const&)
0427 {
0428 }
0429 */
0430 
0431 // ------------ method called when ending the processing of a run  ------------
0432 /*
0433 void 
0434 L1TCaloLayer1Validator::endRun(edm::Run const&, edm::EventSetup const&)
0435 {
0436 }
0437 */
0438 
0439 // ------------ method called when starting to processes a luminosity block  ------------
0440 /*
0441 void 
0442 L1TCaloLayer1Validator::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0443 {
0444 }
0445 */
0446 
0447 // ------------ method called when ending the processing of a luminosity block  ------------
0448 /*
0449 void 
0450 L1TCaloLayer1Validator::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0451 {
0452 }
0453 */
0454 
0455 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0456 void L1TCaloLayer1Validator::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0457   //The following says we do not know what parameters are allowed so do no validation
0458   // Please change this to state exactly what you do use, even if it is no parameters
0459   edm::ParameterSetDescription desc;
0460   desc.setUnknown();
0461   descriptions.addDefault(desc);
0462 }
0463 
0464 //define this as a plug-in
0465 DEFINE_FWK_MODULE(L1TCaloLayer1Validator);