Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-04 23:36:05

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1TriggerDPG/L1Ntuples
0004 // Class:      L1EventTreeProducer
0005 //
0006 /**\class L1EventTreeProducer L1EventTreeProducer.cc L1TriggerDPG/L1Ntuples/src/L1EventTreeProducer.cc
0007 
0008 Description: Produce L1 Extra tree
0009 
0010 Implementation:
0011      
0012 */
0013 //
0014 // Original Author:
0015 //         Created:
0016 // $Id: L1EventTreeProducer.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/EtSum.h"
0037 
0038 // ROOT output stuff
0039 #include "FWCore/ServiceRegistry/interface/Service.h"
0040 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0041 #include "TTree.h"
0042 
0043 #include "L1Trigger/L1TNtuples/interface/L1AnalysisEvent.h"
0044 
0045 //
0046 // class declaration
0047 //
0048 
0049 class L1EventTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0050 public:
0051   explicit L1EventTreeProducer(const edm::ParameterSet&);
0052   ~L1EventTreeProducer() override = default;
0053 
0054 private:
0055   void beginJob(void) override;
0056   void analyze(const edm::Event&, const edm::EventSetup&) override;
0057   void endJob() override;
0058 
0059 public:
0060   std::unique_ptr<L1Analysis::L1AnalysisEvent> l1Event;
0061   L1Analysis::L1AnalysisEventDataFormat* l1EventData;
0062 
0063 private:
0064   // output file
0065   edm::Service<TFileService> fs_;
0066 
0067   // tree
0068   TTree* tree_;
0069 
0070   // EDM input tags
0071   const edm::EDGetTokenT<edm::TriggerResults> hltSource_;
0072 };
0073 
0074 L1EventTreeProducer::L1EventTreeProducer(const edm::ParameterSet& iConfig)
0075     : hltSource_(consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("hltSource"))) {
0076   std::string puMCFile = iConfig.getUntrackedParameter<std::string>("puMCFile", "");
0077   std::string puMCHist = iConfig.getUntrackedParameter<std::string>("puMCHist", "pileup");
0078   std::string puDataFile = iConfig.getUntrackedParameter<std::string>("puDataFile", "");
0079   std::string puDataHist = iConfig.getUntrackedParameter<std::string>("puDataHist", "pileup");
0080 
0081   usesResource(TFileService::kSharedResource);
0082 
0083   bool useAvgVtx = iConfig.getUntrackedParameter<bool>("useAvgVtx", true);
0084   double maxAllowedWeight = iConfig.getUntrackedParameter<double>("maxAllowedWeight", -1);
0085 
0086   l1Event = std::make_unique<L1Analysis::L1AnalysisEvent>(
0087       puMCFile, puMCHist, puDataFile, puDataHist, useAvgVtx, maxAllowedWeight, consumesCollector());
0088   l1EventData = l1Event->getData();
0089 
0090   // set up output
0091   tree_ = fs_->make<TTree>("L1EventTree", "L1EventTree");
0092   tree_->Branch("Event", "L1Analysis::L1AnalysisEventDataFormat", &l1EventData, 32000, 3);
0093 }
0094 
0095 //
0096 // member functions
0097 //
0098 
0099 // ------------ method called to for each event  ------------
0100 void L1EventTreeProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0101   if (!hltSource_.isUninitialized()) {
0102     l1Event->Reset();
0103     l1Event->Set(iEvent, hltSource_);
0104   }
0105   tree_->Fill();
0106 }
0107 
0108 // ------------ method called once each job just before starting event loop  ------------
0109 void L1EventTreeProducer::beginJob(void) {}
0110 
0111 // ------------ method called once each job just after ending the event loop  ------------
0112 void L1EventTreeProducer::endJob() {}
0113 
0114 //define this as a plug-in
0115 DEFINE_FWK_MODULE(L1EventTreeProducer);