Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:00

0001 // -*- C++ -*-
0002 //
0003 // L1TSummary:  produce command line visible summary of L1T system
0004 //
0005 
0006 #include <iostream>
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "DataFormats/L1Trigger/interface/EGamma.h"
0014 #include "DataFormats/L1Trigger/interface/Tau.h"
0015 #include "DataFormats/L1Trigger/interface/Jet.h"
0016 #include "DataFormats/L1Trigger/interface/Muon.h"
0017 #include "DataFormats/L1Trigger/interface/EtSum.h"
0018 
0019 using namespace std;
0020 using namespace edm;
0021 using namespace l1t;
0022 
0023 class L1TSummary : public one::EDAnalyzer<> {
0024 public:
0025   explicit L1TSummary(const ParameterSet&);
0026 
0027   static void fillDescriptions(ConfigurationDescriptions& descriptions);
0028 
0029 private:
0030   void beginJob() override;
0031   void analyze(Event const&, EventSetup const&) override;
0032   void endJob() override;
0033 
0034   // Tag string to mark summary with:
0035   string tag_;
0036 
0037   // Checks to perform:
0038   bool egCheck_;
0039   bool tauCheck_;
0040   bool jetCheck_;
0041   bool sumCheck_;
0042   bool muonCheck_;
0043   bool bxZeroOnly_;
0044 
0045   // EDM tokens:
0046   edm::EDGetTokenT<EGammaBxCollection> egToken_;
0047   std::vector<edm::EDGetTokenT<TauBxCollection>> tauTokens_;
0048   edm::EDGetTokenT<JetBxCollection> jetToken_;
0049   edm::EDGetTokenT<EtSumBxCollection> sumToken_;
0050   edm::EDGetTokenT<MuonBxCollection> muonToken_;
0051 
0052   // keep a tally for summary:
0053   int egCount_;
0054   int tauCount_;
0055   int jetCount_;
0056   int sumCount_;
0057   int muonCount_;
0058 };
0059 
0060 L1TSummary::L1TSummary(const ParameterSet& iConfig) {
0061   // InputTag barrelTfInputTag = iConfig.getParameter<InputTag>("barrelTFInput");
0062   // InputTag overlapTfInputTag = iConfig.getParameter<InputTag>("overlapTFInput");
0063   // InputTag forwardTfInputTag = iConfig.getParameter<InputTag>("forwardTFInput");
0064   //m_barrelTfInputToken = consumes<MicroGMTConfiguration::InputCollection>(iConfig.getParameter<InputTag>("bmtfDigis"));
0065 
0066   tag_ = iConfig.getParameter<string>("tag");
0067 
0068   egCheck_ = iConfig.getParameter<bool>("egCheck");
0069   tauCheck_ = iConfig.getParameter<bool>("tauCheck");
0070   jetCheck_ = iConfig.getParameter<bool>("jetCheck");
0071   sumCheck_ = iConfig.getParameter<bool>("sumCheck");
0072   muonCheck_ = iConfig.getParameter<bool>("muonCheck");
0073   bxZeroOnly_ = iConfig.getParameter<bool>("bxZeroOnly");
0074 
0075   //cout << "L1T Summary for " << tag << "\n";
0076   //cout << "DEBUG:  egCheck:    " << egCheck_ << "\n";
0077   //cout << "DEBUG:  tauCheck:   " << tauCheck_ << "\n";
0078   //cout << "DEBUG:  jetCheck:   " << jetCheck_ << "\n";
0079   //cout << "DEBUG:  sumCheck:   " << sumCheck_ << "\n";
0080   //cout << "DEBUG:  muonCheck:  " << muonCheck_ << "\n";
0081 
0082   if (egCheck_) {
0083     egToken_ = consumes<EGammaBxCollection>(iConfig.getParameter<InputTag>("egToken"));
0084   }
0085   if (tauCheck_) {
0086     const auto& taus = iConfig.getParameter<std::vector<edm::InputTag>>("tauTokens");
0087     for (const auto& tau : taus) {
0088       tauTokens_.push_back(consumes<l1t::TauBxCollection>(tau));
0089     }
0090   }
0091   if (jetCheck_) {
0092     jetToken_ = consumes<JetBxCollection>(iConfig.getParameter<InputTag>("jetToken"));
0093   }
0094   if (sumCheck_) {
0095     sumToken_ = consumes<EtSumBxCollection>(iConfig.getParameter<InputTag>("sumToken"));
0096   }
0097   if (muonCheck_) {
0098     muonToken_ = consumes<MuonBxCollection>(iConfig.getParameter<InputTag>("muonToken"));
0099   }
0100 
0101   egCount_ = 0;
0102   tauCount_ = 0;
0103   jetCount_ = 0;
0104   sumCount_ = 0;
0105   muonCount_ = 0;
0106 }
0107 
0108 void L1TSummary::analyze(Event const& iEvent, EventSetup const& iSetup) {
0109   cout << "L1TSummary Module output for " << tag_ << "\n";
0110   if (egCheck_) {
0111     Handle<EGammaBxCollection> XTMP;
0112     iEvent.getByToken(egToken_, XTMP);
0113     if (XTMP.isValid()) {
0114       cout << "INFO:  L1T found e-gamma collection.\n";
0115       for (int ibx = XTMP->getFirstBX(); ibx <= XTMP->getLastBX(); ++ibx) {
0116         for (auto it = XTMP->begin(ibx); it != XTMP->end(ibx); it++) {
0117           if (bxZeroOnly_ && (ibx != 0))
0118             continue;
0119           if (it->et() > 0) {
0120             egCount_++;
0121             cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi()
0122                  << "\n";
0123           }
0124         }
0125       }
0126     } else {
0127       LogWarning("MissingProduct") << "L1Upgrade e-gamma's not found." << std::endl;
0128     }
0129   }
0130 
0131   if (tauCheck_) {
0132     for (auto& tautoken : tauTokens_) {
0133       Handle<TauBxCollection> XTMP;
0134       iEvent.getByToken(tautoken, XTMP);
0135       if (XTMP.isValid()) {
0136         cout << "INFO:  L1T found tau collection.\n";
0137         for (int ibx = XTMP->getFirstBX(); ibx <= XTMP->getLastBX(); ++ibx) {
0138           for (auto it = XTMP->begin(ibx); it != XTMP->end(ibx); it++) {
0139             if (it->et() > 0) {
0140               if (bxZeroOnly_ && (ibx != 0))
0141                 continue;
0142               tauCount_++;
0143               cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi()
0144                    << "\n";
0145             }
0146           }
0147         }
0148       } else {
0149         LogWarning("MissingProduct") << "L1Upgrade tau's not found." << std::endl;
0150       }
0151     }
0152   }
0153 
0154   if (jetCheck_) {
0155     Handle<JetBxCollection> XTMP;
0156     iEvent.getByToken(jetToken_, XTMP);
0157     if (XTMP.isValid()) {
0158       cout << "INFO:  L1T found jet collection.\n";
0159       for (int ibx = XTMP->getFirstBX(); ibx <= XTMP->getLastBX(); ++ibx) {
0160         for (auto it = XTMP->begin(ibx); it != XTMP->end(ibx); it++) {
0161           if (it->et() > 0) {
0162             if (bxZeroOnly_ && (ibx != 0))
0163               continue;
0164             jetCount_++;
0165             cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi()
0166                  << "\n";
0167           }
0168         }
0169       }
0170     } else {
0171       LogWarning("MissingProduct") << "L1T upgrade jets not found." << std::endl;
0172     }
0173   }
0174 
0175   if (sumCheck_) {
0176     Handle<EtSumBxCollection> XTMP;
0177     iEvent.getByToken(sumToken_, XTMP);
0178     if (XTMP.isValid()) {
0179       cout << "INFO:  L1T found sum collection.\n";
0180       for (int ibx = XTMP->getFirstBX(); ibx <= XTMP->getLastBX(); ++ibx) {
0181         for (auto it = XTMP->begin(ibx); it != XTMP->end(ibx); it++) {
0182           //if (it->et() > 0) {
0183           if (bxZeroOnly_ && (ibx != 0))
0184             continue;
0185           sumCount_++;
0186           cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi()
0187                << " type:  " << it->getType() << "\n";
0188           //}
0189         }
0190       }
0191     } else {
0192       LogWarning("MissingProduct") << "L1T upgrade sums not found." << std::endl;
0193     }
0194   }
0195 
0196   if (muonCheck_) {
0197     Handle<MuonBxCollection> XTMP;
0198     iEvent.getByToken(muonToken_, XTMP);
0199     if (XTMP.isValid()) {
0200       cout << "INFO:  L1T found muon collection.\n";
0201       for (int ibx = XTMP->getFirstBX(); ibx <= XTMP->getLastBX(); ++ibx) {
0202         for (auto it = XTMP->begin(ibx); it != XTMP->end(ibx); it++) {
0203           if (it->et() > 0) {
0204             if (bxZeroOnly_ && (ibx != 0))
0205               continue;
0206             muonCount_++;
0207             cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi()
0208                  << "\n";
0209           }
0210         }
0211       }
0212     } else {
0213       LogWarning("MissingProduct") << "L1T upgrade muons not found." << std::endl;
0214     }
0215   }
0216 }
0217 
0218 void L1TSummary::beginJob() { cout << "INFO:  L1TSummary module beginJob called.\n"; }
0219 
0220 void L1TSummary::endJob() {
0221   cout << "INFO:  L1T Summary for " << tag_ << "\n";
0222   cout << "INFO: count of non-zero candidates for each type follows:\n";
0223   if (egCheck_)
0224     cout << "eg:    " << egCount_ << "\n";
0225   if (tauCheck_)
0226     cout << "tau:   " << tauCount_ << "\n";
0227   if (jetCheck_)
0228     cout << "jet:   " << jetCount_ << "\n";
0229   if (sumCheck_)
0230     cout << "sum:   " << sumCount_ << "\n";
0231   if (muonCheck_)
0232     cout << "muon:  " << muonCount_ << "\n";
0233 }
0234 
0235 void L1TSummary::fillDescriptions(ConfigurationDescriptions& descriptions) {
0236   //The following says we do not know what parameters are allowed so do no validation
0237   // Please change this to state exactly what you do use, even if it is no parameters
0238   ParameterSetDescription desc;
0239   desc.setUnknown();
0240   descriptions.addDefault(desc);
0241 }
0242 
0243 DEFINE_FWK_MODULE(L1TSummary);