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:      L1JetRecoTreeProducer
0005 //
0006 /**\class L1JetRecoTreeProducer L1JetRecoTreeProducer.cc L1Trigger/L1TNtuples/src/L1JetRecoTreeProducer.cc
0007 
0008  Description: Produces tree containing reco quantities
0009 
0010 
0011 */
0012 
0013 // system include files
0014 #include <memory>
0015 
0016 // framework
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/Framework/interface/EDAnalyzer.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 
0026 //electrons
0027 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0028 
0029 // ROOT output stuff
0030 #include "FWCore/ServiceRegistry/interface/Service.h"
0031 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0032 #include "TH1.h"
0033 #include "TTree.h"
0034 #include "TF1.h"
0035 
0036 //local  data formats
0037 #include "L1Trigger/L1TNtuples/interface/L1AnalysisRecoElectron.h"
0038 
0039 //
0040 // class declaration
0041 //
0042 
0043 class L1ElectronRecoTreeProducer : public edm::EDAnalyzer {
0044 public:
0045   explicit L1ElectronRecoTreeProducer(const edm::ParameterSet&);
0046   ~L1ElectronRecoTreeProducer() override;
0047 
0048 private:
0049   void beginJob(void) override;
0050   void analyze(const edm::Event&, const edm::EventSetup&) override;
0051   void endJob() override;
0052 
0053 public:
0054   L1Analysis::L1AnalysisRecoElectron* electron;
0055 
0056   L1Analysis::L1AnalysisRecoElectronDataFormat* electron_data;
0057 
0058 private:
0059   // output file
0060   edm::Service<TFileService> fs_;
0061 
0062   // tree
0063   TTree* tree_;
0064 
0065   // EDM input tags
0066   //edm::EDGetToken ElectronToken_;
0067   // edm::EDGetToken<edm::View<reco::GsfElectron>> ElectronToken_;
0068   edm::EDGetTokenT<reco::GsfElectronCollection> ElectronToken_;
0069   edm::EDGetTokenT<edm::ValueMap<bool> > ElectronVetoIdMapToken_;
0070   edm::EDGetTokenT<edm::ValueMap<bool> > ElectronLooseIdMapToken_;
0071   edm::EDGetTokenT<edm::ValueMap<bool> > ElectronMediumIdMapToken_;
0072   edm::EDGetTokenT<edm::ValueMap<bool> > ElectronTightIdMapToken_;
0073 
0074   // debug stuff
0075   bool electronsMissing_;
0076   unsigned int maxElectron_;
0077 };
0078 
0079 L1ElectronRecoTreeProducer::L1ElectronRecoTreeProducer(const edm::ParameterSet& iConfig) : electronsMissing_(false) {
0080   maxElectron_ = iConfig.getParameter<unsigned int>("maxElectron");
0081   //ElectronToken_ = mayConsume<edm::View<reco::GsfElectron> >(iConfig.getUntrackedParameter("ElectronToken",edm::InputTag("gedGsfElectrons")));
0082   ElectronToken_ = consumes<reco::GsfElectronCollection>(
0083       iConfig.getUntrackedParameter("ElectronToken", edm::InputTag("gedGsfElectrons")));
0084 
0085   /*RhoToken_ = consumes<double>(iConfig.getUntrackedParameter("RhoToken",edm::InputTag("fixedGridRhoFastjetAllCalo")));
0086   vtxToken_          = mayConsume<reco::VertexCollection>(iConfig.getUntrackedParameter("vtxToken",edm::InputTag("offlinePrimaryVertices")));
0087   conversionsToken_ = mayConsume< reco::ConversionCollection >(iConfig.getUntrackedParameter("conversionsToken",edm::InputTag("conversions")));
0088   beamSpotToken_ = mayConsume< reco::BeamSpot>(iConfig.getUntrackedParameter("beamSpotToken",edm::InputTag("offlineBeamSpot")));*/
0089 
0090   ElectronVetoIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter(
0091       "eleVetoIdMapToken", edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto")));
0092   ElectronLooseIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter(
0093       "eleLooseIdMapToken", edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose")));
0094   ElectronMediumIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter(
0095       "eleMediumIdMapToken", edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium")));
0096   ElectronTightIdMapToken_ = consumes<edm::ValueMap<bool> >(iConfig.getUntrackedParameter(
0097       "eleTightIdMapToken", edm::InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight")));
0098 
0099   electron = new L1Analysis::L1AnalysisRecoElectron();
0100   electron_data = electron->getData();
0101 
0102   tree_ = fs_->make<TTree>("ElectronRecoTree", "ElectronRecoTree");
0103   tree_->Branch("Electron", "L1Analysis::L1AnalysisRecoElectronDataFormat", &electron_data, 32000, 3);
0104 }
0105 
0106 L1ElectronRecoTreeProducer::~L1ElectronRecoTreeProducer() {
0107   // do anything here that needs to be done at desctruction time
0108   // (e.g. close files, deallocate resources etc.)
0109 }
0110 
0111 //
0112 // member functions
0113 //
0114 
0115 // ------------ method called to for each event  ------------
0116 void L1ElectronRecoTreeProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0117   electron->Reset();
0118   //edm::Handle<edm::View<reco::GsfElectron> > recoElectrons;
0119   //iEvent.getByToken(ElectronToken_, recoElectrons);
0120   edm::Handle<reco::GsfElectronCollection> recoElectrons;
0121   iEvent.getByToken(ElectronToken_, recoElectrons);
0122 
0123   std::vector<edm::Handle<edm::ValueMap<bool> > > eleVIDDecisionHandles(4);
0124 
0125   iEvent.getByToken(ElectronVetoIdMapToken_, eleVIDDecisionHandles[0]);
0126   iEvent.getByToken(ElectronLooseIdMapToken_, eleVIDDecisionHandles[1]);
0127   iEvent.getByToken(ElectronMediumIdMapToken_, eleVIDDecisionHandles[2]);
0128   iEvent.getByToken(ElectronTightIdMapToken_, eleVIDDecisionHandles[3]);
0129 
0130   if (recoElectrons.isValid() && eleVIDDecisionHandles[0].isValid() && eleVIDDecisionHandles[1].isValid() &&
0131       eleVIDDecisionHandles[2].isValid() && eleVIDDecisionHandles[3].isValid()) {
0132     electron->SetElectron(iEvent, iSetup, recoElectrons, eleVIDDecisionHandles, maxElectron_);
0133   } else {
0134     if (!electronsMissing_) {
0135       edm::LogWarning("MissingProduct") << "CaloJets not found.  Branch will not be filled" << std::endl;
0136     }
0137     electronsMissing_ = true;
0138   }
0139 
0140   tree_->Fill();
0141 }
0142 
0143 // ------------ method called once each job just before starting event loop  ------------
0144 void L1ElectronRecoTreeProducer::beginJob(void) {}
0145 
0146 // ------------ method called once each job just after ending the event loop  ------------
0147 void L1ElectronRecoTreeProducer::endJob() {}
0148 
0149 //define this as a plug-in
0150 DEFINE_FWK_MODULE(L1ElectronRecoTreeProducer);