Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:14

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1TriggerDPG/L1Ntuples
0004 // Class:      L1UpgradeTreeProducer
0005 //
0006 /**\class L1UpgradeTreeProducer L1UpgradeTreeProducer.cc L1TriggerDPG/L1Ntuples/src/L1UpgradeTreeProducer.cc
0007 
0008 Description: Produce L1 Extra tree
0009 
0010 Implementation:
0011 
0012 */
0013 //
0014 // Original Author:
0015 //         Created:
0016 // $Id: L1UpgradeTreeProducer.cc,v 1.8 2012/08/29 12:44:03 jbrooke Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // framework
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0030 
0031 // data formats
0032 #include "DataFormats/L1Trigger/interface/EGamma.h"
0033 #include "DataFormats/L1Trigger/interface/Tau.h"
0034 #include "DataFormats/L1Trigger/interface/Jet.h"
0035 #include "DataFormats/L1Trigger/interface/Muon.h"
0036 #include "DataFormats/L1Trigger/interface/MuonShower.h"
0037 #include "DataFormats/L1Trigger/interface/EtSum.h"
0038 
0039 // ROOT output stuff
0040 #include "FWCore/ServiceRegistry/interface/Service.h"
0041 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0042 #include "TTree.h"
0043 
0044 #include "L1Trigger/L1TNtuples/interface/L1AnalysisL1Upgrade.h"
0045 
0046 //
0047 // class declaration
0048 //
0049 
0050 class L1UpgradeTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0051 public:
0052   explicit L1UpgradeTreeProducer(const edm::ParameterSet&);
0053   ~L1UpgradeTreeProducer() override = default;
0054 
0055 private:
0056   void beginJob(void) override;
0057   void analyze(const edm::Event&, const edm::EventSetup&) override;
0058   void endJob() override;
0059 
0060 public:
0061   L1Analysis::L1AnalysisL1Upgrade* l1Upgrade;
0062   L1Analysis::L1AnalysisL1UpgradeDataFormat* l1UpgradeData;
0063 
0064 private:
0065   unsigned maxL1Upgrade_;
0066 
0067   // output file
0068   edm::Service<TFileService> fs_;
0069 
0070   // tree
0071   TTree* tree_;
0072 
0073   // EDM input tags
0074   const edm::EDGetTokenT<l1t::EGammaBxCollection> egToken_;
0075   const edm::EDGetTokenT<l1t::JetBxCollection> jetToken_;
0076   const edm::EDGetTokenT<l1t::EtSumBxCollection> sumToken_;
0077   const edm::EDGetTokenT<l1t::MuonBxCollection> muonToken_;
0078   const edm::EDGetTokenT<l1t::MuonShowerBxCollection> muonShowerToken_;
0079 
0080   const edm::EDGetTokenT<l1t::EtSumBxCollection> sumZDCToken_;
0081 
0082   std::vector<edm::EDGetTokenT<l1t::TauBxCollection>> tauTokens_;
0083 };
0084 
0085 L1UpgradeTreeProducer::L1UpgradeTreeProducer(const edm::ParameterSet& iConfig)
0086     : egToken_(consumes<l1t::EGammaBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("egToken"))),
0087       jetToken_(consumes<l1t::JetBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("jetToken"))),
0088       sumToken_(consumes<l1t::EtSumBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("sumToken"))),
0089       muonToken_(consumes<l1t::MuonBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("muonToken"))),
0090       muonShowerToken_(
0091           consumes<l1t::MuonShowerBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("muonShowerToken"))),
0092       sumZDCToken_(consumes<l1t::EtSumBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("sumZDCToken"))) {
0093   const auto& taus = iConfig.getUntrackedParameter<std::vector<edm::InputTag>>("tauTokens");
0094   for (const auto& tau : taus) {
0095     tauTokens_.push_back(consumes<l1t::TauBxCollection>(tau));
0096   }
0097 
0098   maxL1Upgrade_ = iConfig.getParameter<unsigned int>("maxL1Upgrade");
0099 
0100   l1Upgrade = new L1Analysis::L1AnalysisL1Upgrade();
0101   l1UpgradeData = l1Upgrade->getData();
0102 
0103   usesResource(TFileService::kSharedResource);
0104 
0105   // set up output
0106   tree_ = fs_->make<TTree>("L1UpgradeTree", "L1UpgradeTree");
0107   tree_->Branch("L1Upgrade", "L1Analysis::L1AnalysisL1UpgradeDataFormat", &l1UpgradeData, 32000, 3);
0108 }
0109 
0110 //
0111 // member functions
0112 //
0113 
0114 // ------------ method called to for each event  ------------
0115 void L1UpgradeTreeProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0116   l1Upgrade->Reset();
0117 
0118   edm::Handle<l1t::EGammaBxCollection> eg;
0119   edm::Handle<l1t::JetBxCollection> jet;
0120   edm::Handle<l1t::EtSumBxCollection> sums;
0121   edm::Handle<l1t::MuonBxCollection> muon;
0122   edm::Handle<l1t::MuonShowerBxCollection> muonShower;
0123   edm::Handle<l1t::EtSumBxCollection> sumsZDC;
0124 
0125   iEvent.getByToken(egToken_, eg);
0126   iEvent.getByToken(jetToken_, jet);
0127   iEvent.getByToken(sumToken_, sums);
0128   iEvent.getByToken(muonToken_, muon);
0129   iEvent.getByToken(muonShowerToken_, muonShower);
0130   iEvent.getByToken(sumZDCToken_, sumsZDC);
0131 
0132   if (eg.isValid()) {
0133     l1Upgrade->SetEm(eg, maxL1Upgrade_);
0134   } else {
0135     edm::LogWarning("MissingProduct") << "L1Upgrade Em not found. Branch will not be filled" << std::endl;
0136   }
0137   if (jet.isValid()) {
0138     l1Upgrade->SetJet(jet, maxL1Upgrade_);
0139   } else {
0140     edm::LogWarning("MissingProduct") << "L1Upgrade Jets not found. Branch will not be filled" << std::endl;
0141   }
0142 
0143   if (sums.isValid()) {
0144     l1Upgrade->SetSum(sums, maxL1Upgrade_);
0145   } else {
0146     edm::LogWarning("MissingProduct") << "L1Upgrade EtSums not found. Branch will not be filled" << std::endl;
0147   }
0148 
0149   if (muon.isValid()) {
0150     l1Upgrade->SetMuon(muon, maxL1Upgrade_);
0151   } else {
0152     edm::LogWarning("MissingProduct") << "L1Upgrade Muons not found. Branch will not be filled" << std::endl;
0153   }
0154 
0155   if (muonShower.isValid()) {
0156     l1Upgrade->SetMuonShower(muonShower, maxL1Upgrade_);
0157   } else {
0158     edm::LogWarning("MissingProduct") << "L1Upgrade Muon Showers not found. Branch will not be filled" << std::endl;
0159   }
0160 
0161   if (sumsZDC.isValid()) {
0162     l1Upgrade->SetSumZDC(sumsZDC, maxL1Upgrade_);
0163   } else {
0164     edm::LogWarning("MissingProduct") << "L1Upgrade EtZDCSums not found. Branch will not be filled" << std::endl;
0165   }
0166 
0167   for (auto& tautoken : tauTokens_) {
0168     edm::Handle<l1t::TauBxCollection> tau;
0169     iEvent.getByToken(tautoken, tau);
0170     if (tau.isValid()) {
0171       l1Upgrade->SetTau(tau, maxL1Upgrade_);
0172     } else {
0173       edm::LogWarning("MissingProduct") << "L1Upgrade Tau not found. Branch will not be filled" << std::endl;
0174     }
0175   }
0176 
0177   tree_->Fill();
0178 }
0179 
0180 // ------------ method called once each job just before starting event loop  ------------
0181 void L1UpgradeTreeProducer::beginJob(void) {}
0182 
0183 // ------------ method called once each job just after ending the event loop  ------------
0184 void L1UpgradeTreeProducer::endJob() {}
0185 
0186 //define this as a plug-in
0187 DEFINE_FWK_MODULE(L1UpgradeTreeProducer);