Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:30

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/L1TNtuples
0004 // Class:      L1ExtraTreeProducer
0005 //
0006 /**\class L1ExtraTreeProducer L1ExtraTreeProducer.cc L1Trigger/L1TNtuples/src/L1ExtraTreeProducer.cc
0007 
0008 Description: Produce L1 Extra tree
0009 
0010 Implementation:
0011      
0012 */
0013 //
0014 // Original Author:  Alex Tapper
0015 //         Created:
0016 // $Id: L1ExtraTreeProducer.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/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/L1EmParticleFwd.h"
0033 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
0034 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
0035 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
0036 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
0037 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
0038 #include "DataFormats/L1Trigger/interface/L1EtMissParticleFwd.h"
0039 #include "DataFormats/L1Trigger/interface/L1EtMissParticle.h"
0040 #include "DataFormats/L1Trigger/interface/L1HFRingsFwd.h"
0041 #include "DataFormats/L1Trigger/interface/L1HFRings.h"
0042 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0043 
0044 // ROOT output stuff
0045 #include "FWCore/ServiceRegistry/interface/Service.h"
0046 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0047 #include "TTree.h"
0048 
0049 #include "L1Trigger/L1TNtuples/interface/L1AnalysisL1Extra.h"
0050 
0051 //
0052 // class declaration
0053 //
0054 
0055 class L1ExtraTreeProducer : public edm::EDAnalyzer {
0056 public:
0057   explicit L1ExtraTreeProducer(const edm::ParameterSet&);
0058   ~L1ExtraTreeProducer() override;
0059 
0060 private:
0061   void beginJob(void) override;
0062   void analyze(const edm::Event&, const edm::EventSetup&) override;
0063   void endJob() override;
0064 
0065 public:
0066   L1Analysis::L1AnalysisL1Extra* l1Extra;
0067   L1Analysis::L1AnalysisL1ExtraDataFormat* l1ExtraData;
0068 
0069 private:
0070   unsigned maxL1Extra_;
0071 
0072   // output file
0073   edm::Service<TFileService> fs_;
0074 
0075   // tree
0076   TTree* tree_;
0077 
0078   // EDM input tags
0079   edm::EDGetTokenT<l1extra::L1EmParticleCollection> nonIsoEmToken_;
0080   edm::EDGetTokenT<l1extra::L1EmParticleCollection> isoEmToken_;
0081   edm::EDGetTokenT<l1extra::L1JetParticleCollection> tauJetToken_;
0082   edm::EDGetTokenT<l1extra::L1JetParticleCollection> isoTauJetToken_;
0083   edm::EDGetTokenT<l1extra::L1JetParticleCollection> cenJetToken_;
0084   edm::EDGetTokenT<l1extra::L1JetParticleCollection> fwdJetToken_;
0085   edm::EDGetTokenT<l1extra::L1MuonParticleCollection> muonToken_;
0086   edm::EDGetTokenT<l1extra::L1EtMissParticleCollection> metToken_;
0087   edm::EDGetTokenT<l1extra::L1EtMissParticleCollection> mhtToken_;
0088   edm::EDGetTokenT<l1extra::L1HFRingsCollection> hfRingsToken_;
0089 };
0090 
0091 L1ExtraTreeProducer::L1ExtraTreeProducer(const edm::ParameterSet& iConfig) {
0092   nonIsoEmToken_ = consumes<l1extra::L1EmParticleCollection>(
0093       iConfig.getUntrackedParameter("nonIsoEmToken", edm::InputTag("l1extraParticles:NonIsolated")));
0094   isoEmToken_ = consumes<l1extra::L1EmParticleCollection>(
0095       iConfig.getUntrackedParameter("isoEmToken", edm::InputTag("l1extraParticles:Isolated")));
0096   tauJetToken_ = consumes<l1extra::L1JetParticleCollection>(
0097       iConfig.getUntrackedParameter("tauJetToken", edm::InputTag("l1extraParticles:Tau")));
0098   isoTauJetToken_ = consumes<l1extra::L1JetParticleCollection>(
0099       iConfig.getUntrackedParameter("isoTauJetToken", edm::InputTag("l1extraParticles:IsoTau")));
0100   cenJetToken_ = consumes<l1extra::L1JetParticleCollection>(
0101       iConfig.getUntrackedParameter("cenJetToken", edm::InputTag("l1extraParticles:Central")));
0102   fwdJetToken_ = consumes<l1extra::L1JetParticleCollection>(
0103       iConfig.getUntrackedParameter("fwdJetToken", edm::InputTag("l1extraParticles:Forward")));
0104   muonToken_ = consumes<l1extra::L1MuonParticleCollection>(
0105       iConfig.getUntrackedParameter("muonToken", edm::InputTag("l1extraParticles")));
0106   metToken_ = consumes<l1extra::L1EtMissParticleCollection>(
0107       iConfig.getUntrackedParameter("metToken", edm::InputTag("l1extraParticles:MET")));
0108   mhtToken_ = consumes<l1extra::L1EtMissParticleCollection>(
0109       iConfig.getUntrackedParameter("mhtToken", edm::InputTag("l1extraParticles:MHT")));
0110   hfRingsToken_ = consumes<l1extra::L1HFRingsCollection>(
0111       iConfig.getUntrackedParameter("hfRingsToken", edm::InputTag("l1extraParticles")));
0112 
0113   maxL1Extra_ = iConfig.getParameter<unsigned int>("maxL1Extra");
0114 
0115   l1Extra = new L1Analysis::L1AnalysisL1Extra();
0116   l1ExtraData = l1Extra->getData();
0117 
0118   // set up output
0119   tree_ = fs_->make<TTree>("L1ExtraTree", "L1ExtraTree");
0120   tree_->Branch("L1Extra", "L1Analysis::L1AnalysisL1ExtraDataFormat", &l1ExtraData, 32000, 3);
0121 }
0122 
0123 L1ExtraTreeProducer::~L1ExtraTreeProducer() {
0124   // do anything here that needs to be done at desctruction time
0125   // (e.g. close files, deallocate resources etc.)
0126 }
0127 
0128 //
0129 // member functions
0130 //
0131 
0132 // ------------ method called to for each event  ------------
0133 void L1ExtraTreeProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0134   l1Extra->Reset();
0135 
0136   edm::Handle<l1extra::L1EmParticleCollection> isoEm;
0137   edm::Handle<l1extra::L1EmParticleCollection> nonIsoEm;
0138   edm::Handle<l1extra::L1JetParticleCollection> cenJet;
0139   edm::Handle<l1extra::L1JetParticleCollection> fwdJet;
0140   edm::Handle<l1extra::L1JetParticleCollection> tauJet;
0141   edm::Handle<l1extra::L1JetParticleCollection> isoTauJet;
0142   edm::Handle<l1extra::L1MuonParticleCollection> muon;
0143   ;
0144   edm::Handle<l1extra::L1EtMissParticleCollection> mets;
0145   edm::Handle<l1extra::L1EtMissParticleCollection> mhts;
0146   edm::Handle<l1extra::L1HFRingsCollection> hfRings;
0147 
0148   iEvent.getByToken(nonIsoEmToken_, nonIsoEm);
0149   iEvent.getByToken(isoEmToken_, isoEm);
0150   iEvent.getByToken(tauJetToken_, tauJet);
0151   iEvent.getByToken(isoTauJetToken_, isoTauJet);
0152   iEvent.getByToken(cenJetToken_, cenJet);
0153   iEvent.getByToken(fwdJetToken_, fwdJet);
0154   iEvent.getByToken(muonToken_, muon);
0155   iEvent.getByToken(metToken_, mets);
0156   iEvent.getByToken(mhtToken_, mhts);
0157   iEvent.getByToken(hfRingsToken_, hfRings);
0158 
0159   if (isoEm.isValid()) {
0160     l1Extra->SetIsoEm(isoEm, maxL1Extra_);
0161   } else {
0162     edm::LogWarning("MissingProduct") << "L1Extra Iso Em not found. Branch will not be filled" << std::endl;
0163   }
0164 
0165   if (nonIsoEm.isValid()) {
0166     l1Extra->SetNonIsoEm(nonIsoEm, maxL1Extra_);
0167   } else {
0168     edm::LogWarning("MissingProduct") << "L1Extra Non Iso Em not found. Branch will not be filled" << std::endl;
0169   }
0170 
0171   if (cenJet.isValid()) {
0172     l1Extra->SetCenJet(cenJet, maxL1Extra_);
0173   } else {
0174     edm::LogWarning("MissingProduct") << "L1Extra Central Jets not found. Branch will not be filled" << std::endl;
0175   }
0176 
0177   if (tauJet.isValid()) {
0178     l1Extra->SetTauJet(tauJet, maxL1Extra_);
0179   } else {
0180     edm::LogWarning("MissingProduct") << "L1Extra Tau Jets not found. Branch will not be filled" << std::endl;
0181   }
0182 
0183   if (isoTauJet.isValid()) {
0184     l1Extra->SetIsoTauJet(isoTauJet, maxL1Extra_);
0185   } else {
0186     edm::LogWarning("MissingProduct") << "L1Extra Iso Tau Jets not found. Branch will not be filled" << std::endl;
0187   }
0188 
0189   if (fwdJet.isValid()) {
0190     l1Extra->SetFwdJet(fwdJet, maxL1Extra_);
0191   } else {
0192     edm::LogWarning("MissingProduct") << "L1Extra Forward Jets not found. Branch will not be filled" << std::endl;
0193   }
0194 
0195   if (muon.isValid()) {
0196     l1Extra->SetMuon(muon, maxL1Extra_);
0197   } else {
0198     edm::LogWarning("MissingProduct") << "L1Extra Muons not found. Branch will not be filled" << std::endl;
0199   }
0200 
0201   if (mets.isValid()) {
0202     l1Extra->SetMet(mets);
0203   } else {
0204     edm::LogWarning("MissingProduct") << "L1Extra MET not found. Branch will not be filled" << std::endl;
0205   }
0206 
0207   if (mhts.isValid()) {
0208     l1Extra->SetMht(mhts);
0209   } else {
0210     edm::LogWarning("MissingProduct") << "L1Extra MHT not found. Branch will not be filled" << std::endl;
0211   }
0212 
0213   if (hfRings.isValid()) {
0214     l1Extra->SetHFring(hfRings);
0215   } else {
0216     edm::LogWarning("MissingProduct") << "L1Extra HF Rings not found. Branch will not be filled" << std::endl;
0217   }
0218 
0219   tree_->Fill();
0220 }
0221 
0222 // ------------ method called once each job just before starting event loop  ------------
0223 void L1ExtraTreeProducer::beginJob(void) {}
0224 
0225 // ------------ method called once each job just after ending the event loop  ------------
0226 void L1ExtraTreeProducer::endJob() {}
0227 
0228 //define this as a plug-in
0229 DEFINE_FWK_MODULE(L1ExtraTreeProducer);