Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-13 01:32:11

0001 // -*- C++ -*-
0002 //
0003 // L1TBasicDemo:  demonstrate basic access of L1T objects
0004 //
0005 
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "DataFormats/L1Trigger/interface/EGamma.h"
0013 #include "DataFormats/L1Trigger/interface/Tau.h"
0014 #include "DataFormats/L1Trigger/interface/Jet.h"
0015 #include "DataFormats/L1Trigger/interface/Muon.h"
0016 #include "DataFormats/L1Trigger/interface/EtSum.h"
0017 #include "DataFormats/L1Trigger/interface/EtSumHelper.h"
0018 
0019 // leaving out the following namespaces, so namespaces are explicit in the demo code:
0020 // using namespace l1t;
0021 // using namespace edm;
0022 
0023 class L1TBasicDemo : public edm::global::EDAnalyzer<> {
0024 public:
0025   explicit L1TBasicDemo(const edm::ParameterSet&);
0026 
0027   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0028 
0029 private:
0030   void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0031 
0032   // EDM tokens:
0033   edm::EDGetTokenT<l1t::EGammaBxCollection> egToken_;
0034   edm::EDGetTokenT<l1t::TauBxCollection> tauToken_;
0035   edm::EDGetTokenT<l1t::JetBxCollection> jetToken_;
0036   edm::EDGetTokenT<l1t::EtSumBxCollection> sumToken_;
0037   edm::EDGetTokenT<l1t::MuonBxCollection> muonToken_;
0038 
0039   int trigger_bx_only;
0040 };
0041 
0042 L1TBasicDemo::L1TBasicDemo(const edm::ParameterSet& iConfig) {
0043   egToken_ = consumes<l1t::EGammaBxCollection>(iConfig.getParameter<edm::InputTag>("EgTag"));
0044   tauToken_ = consumes<l1t::TauBxCollection>(iConfig.getParameter<edm::InputTag>("TauTag"));
0045   jetToken_ = consumes<l1t::JetBxCollection>(iConfig.getParameter<edm::InputTag>("JetTag"));
0046   sumToken_ = consumes<l1t::EtSumBxCollection>(iConfig.getParameter<edm::InputTag>("SumTag"));
0047   muonToken_ = consumes<l1t::MuonBxCollection>(iConfig.getParameter<edm::InputTag>("MuonTag"));
0048   trigger_bx_only = iConfig.getParameter<bool>("UseTriggerBxOnly");
0049 }
0050 
0051 void L1TBasicDemo::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const& iSetup) const {
0052   cout << "INFO:  dumping EGamma BX collection:\n";
0053   edm::Handle<l1t::EGammaBxCollection> eg;
0054   iEvent.getByToken(egToken_, eg);
0055   if (eg.isValid()) {
0056     for (int ibx = eg->getFirstBX(); ibx <= eg->getLastBX(); ++ibx) {
0057       if (trigger_bx_only && (ibx != 0))
0058         continue;
0059       for (auto it = eg->begin(ibx); it != eg->end(ibx); it++) {
0060         if (it->et() == 0)
0061           continue;  // if you don't care about L1T candidates with zero ET.
0062         cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi() << "\n";
0063       }
0064     }
0065   } else {
0066     edm::LogWarning("MissingProduct") << "L1Upgrade e-gamma bx collection not found." << std::endl;
0067   }
0068 
0069   cout << "INFO:  dumping Tau BX collection:\n";
0070   edm::Handle<l1t::TauBxCollection> tau;
0071   iEvent.getByToken(tauToken_, tau);
0072   if (tau.isValid()) {
0073     for (int ibx = tau->getFirstBX(); ibx <= tau->getLastBX(); ++ibx) {
0074       if (trigger_bx_only && (ibx != 0))
0075         continue;
0076       for (auto it = tau->begin(ibx); it != tau->end(ibx); it++) {
0077         if (it->et() == 0)
0078           continue;  // if you don't care about L1T candidates with zero ET.
0079         cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi() << "\n";
0080       }
0081     }
0082   } else {
0083     edm::LogWarning("MissingProduct") << "L1Upgrade tau bx collection not found." << std::endl;
0084   }
0085 
0086   cout << "INFO:  dumping Jet BX collection:\n";
0087   edm::Handle<l1t::JetBxCollection> jet;
0088   iEvent.getByToken(jetToken_, jet);
0089   if (jet.isValid()) {
0090     for (int ibx = jet->getFirstBX(); ibx <= jet->getLastBX(); ++ibx) {
0091       if (trigger_bx_only && (ibx != 0))
0092         continue;
0093       for (auto it = jet->begin(ibx); it != jet->end(ibx); it++) {
0094         if (it->et() == 0)
0095           continue;  // if you don't care about L1T candidates with zero ET.
0096         cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi() << "\n";
0097       }
0098     }
0099   } else {
0100     edm::LogWarning("MissingProduct") << "L1Upgrade jet bx collection not found." << std::endl;
0101   }
0102 
0103   cout << "INFO:  dumping EtSum BX collection:\n";
0104   edm::Handle<l1t::EtSumBxCollection> sum;
0105   iEvent.getByToken(sumToken_, sum);
0106   if (sum.isValid()) {
0107     l1t::EtSumHelper hsum(sum);
0108     cout << "met:     " << hsum.MissingEt() << "\n";
0109     cout << "met phi: " << hsum.MissingEtPhi() << "\n";
0110     cout << "mht:     " << hsum.MissingHt() << "\n";
0111     cout << "mht phi: " << hsum.MissingHtPhi() << "\n";
0112     cout << "sum et:  " << hsum.TotalEt() << "\n";
0113     cout << "sum ht:  " << hsum.TotalHt() << "\n";
0114   } else {
0115     edm::LogWarning("MissingProduct") << "L1Upgrade sum bx collection not found." << std::endl;
0116   }
0117 
0118   cout << "INFO:  dumping Muon BX collection:\n";
0119   edm::Handle<l1t::MuonBxCollection> muon;
0120   iEvent.getByToken(muonToken_, muon);
0121   if (muon.isValid()) {
0122     for (int ibx = muon->getFirstBX(); ibx <= muon->getLastBX(); ++ibx) {
0123       if (trigger_bx_only && (ibx != 0))
0124         continue;
0125       for (auto it = muon->begin(ibx); it != muon->end(ibx); it++) {
0126         if (it->et() == 0)
0127           continue;  // if you don't care about L1T candidates with zero ET.
0128         cout << "bx:  " << ibx << "  et:  " << it->et() << "  eta:  " << it->eta() << "  phi:  " << it->phi() << "\n";
0129       }
0130     }
0131   } else {
0132     edm::LogWarning("MissingProduct") << "L1Upgrade muon bx collection not found." << std::endl;
0133   }
0134 }
0135 
0136 void L1TBasicDemo::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0137   //The following says we do not know what parameters are allowed so do no validation
0138   // Please change this to state exactly what you do use, even if it is no parameters
0139   edm::ParameterSetDescription desc;
0140   desc.setUnknown();
0141   descriptions.addDefault(desc);
0142 }
0143 
0144 DEFINE_FWK_MODULE(L1TBasicDemo);