CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/PatExamples/plugins/PatTopSelectionAnalyzer.cc

Go to the documentation of this file.
00001 #include <map>
00002 #include <string>
00003 
00004 #include "TH1.h"
00005 
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/EDAnalyzer.h"
00008 #include "FWCore/Utilities/interface/InputTag.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00012 
00013 class PatTopSelectionAnalyzer : public edm::EDAnalyzer {
00014 
00015 public:
00017   explicit PatTopSelectionAnalyzer(const edm::ParameterSet&);
00019   ~PatTopSelectionAnalyzer();
00020   
00021 private:
00023   virtual void beginJob() ;
00025   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00027   virtual void endJob() ;
00028 
00030   bool booked(const std::string histName) const { return hists_.find(histName.c_str())!=hists_.end(); };
00032   void fill(const std::string histName, double value) const { if(booked(histName.c_str())) hists_.find(histName.c_str())->second->Fill(value); };
00033   
00034   // simple map to contain all histograms; 
00035   // histograms are booked in the beginJob() 
00036   // method
00037   std::map<std::string, TH1F*> hists_; 
00038 
00039   // input tags  
00040   edm::InputTag elecs_;
00041   edm::InputTag muons_;
00042   edm::InputTag jets_;
00043   edm::InputTag met_;
00044 };
00045 
00046 #include "DataFormats/PatCandidates/interface/Electron.h"
00047 #include "DataFormats/PatCandidates/interface/Muon.h"
00048 #include "DataFormats/PatCandidates/interface/Jet.h"
00049 #include "DataFormats/PatCandidates/interface/MET.h"
00050 
00051 PatTopSelectionAnalyzer::PatTopSelectionAnalyzer(const edm::ParameterSet& iConfig):
00052   hists_(),
00053   elecs_(iConfig.getUntrackedParameter<edm::InputTag>("elecs")),
00054   muons_(iConfig.getUntrackedParameter<edm::InputTag>("muons")),
00055   jets_ (iConfig.getUntrackedParameter<edm::InputTag>("jets" )),
00056   met_  (iConfig.getUntrackedParameter<edm::InputTag>("met"  ))
00057 {
00058 }
00059 
00060 PatTopSelectionAnalyzer::~PatTopSelectionAnalyzer()
00061 {
00062 }
00063 
00064 void
00065 PatTopSelectionAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00066 {
00067   // get electron collection
00068   edm::Handle<edm::View<pat::Electron> > elecs;
00069   iEvent.getByLabel(elecs_,elecs);
00070 
00071   // get muon collection
00072   edm::Handle<edm::View<pat::Muon> > muons;
00073   iEvent.getByLabel(muons_,muons);
00074 
00075   // get jet collection
00076   edm::Handle<edm::View<pat::Jet> > jets;
00077   iEvent.getByLabel(jets_,jets);
00078 
00079   // get met collection  
00080   edm::Handle<edm::View<pat::MET> > met;
00081   iEvent.getByLabel(met_,met);
00082 
00083   // fill yield
00084   fill("yield", 0.5);
00085 
00086   // fill quantities for leading elec and elec multiplicity
00087   fill("elecMult", elecs->size());
00088   if(elecs->begin()!=elecs->end()){
00089     fill("elecIso", (elecs->begin()->trackIso()+elecs->begin()->caloIso())/elecs->begin()->pt());
00090     fill("elecPt", elecs->begin()->pt());
00091   }
00092 
00093   // fill quantities for leading muon and muon multiplicity
00094   fill("muonMult", muons->size());
00095   if(muons->begin()!=muons->end()){
00096     fill("muonIso", (muons->begin()->trackIso()+muons->begin()->caloIso())/muons->begin()->pt());
00097     fill("muonPt", muons->begin()->pt());
00098   }
00099 
00100   // fill quantities for leading jets and jet multiplicity
00101   // jet pt is corrected up to L3Absolute
00102   fill("jetMult", jets->size());
00103   if( jets->size()>0 ) fill("jet0Pt", (*jets)[0].pt());
00104   if( jets->size()>1 ) fill("jet1Pt", (*jets)[1].pt());
00105   if( jets->size()>2 ) fill("jet2Pt", (*jets)[2].pt());
00106   if( jets->size()>3 ) fill("jet3Pt", (*jets)[3].pt());
00107 
00108   // fill MET
00109   fill("met", met->empty()?0:(*met)[0].et());
00110 }
00111 
00112 void 
00113 PatTopSelectionAnalyzer::beginJob()
00114 {
00115   // register to the TFileService
00116   edm::Service<TFileService> fs;
00117   
00118   // book histograms:
00119   hists_["yield"   ]=fs->make<TH1F>("yield"   , "electron multiplicity",   1, 0.,   1.);
00120   hists_["elecMult"]=fs->make<TH1F>("elecMult", "electron multiplicity",  10, 0.,  10.);
00121   hists_["elecIso" ]=fs->make<TH1F>("elecIso" , "electron isolation"   ,  20, 0.,   1.);
00122   hists_["elecPt"  ]=fs->make<TH1F>("elecPt"  , "electron pt"          ,  30, 0., 150.);
00123   hists_["muonMult"]=fs->make<TH1F>("muonMult", "muon multiplicity"    ,  10, 0.,  10.);
00124   hists_["muonIso" ]=fs->make<TH1F>("muonIso" , "muon isolation"       ,  20, 0.,   1.);
00125   hists_["muonPt"  ]=fs->make<TH1F>("muonPt"  , "muon pt"              ,  30, 0., 150.);
00126   hists_["jetMult" ]=fs->make<TH1F>("jetMult" , "jet multiplicity"     ,  15, 0.,  15.);
00127   hists_["jet0Pt"  ]=fs->make<TH1F>("jet0Pt"  , "1. leading jet pt"    ,  50, 0., 250.);
00128   hists_["jet1Pt"  ]=fs->make<TH1F>("jet1Pt"  , "1. leading jet pt"    ,  50, 0., 250.);
00129   hists_["jet2Pt"  ]=fs->make<TH1F>("jet2Pt"  , "1. leading jet pt"    ,  50, 0., 200.);
00130   hists_["jet3Pt"  ]=fs->make<TH1F>("jet3Pt"  , "1. leading jet pt"    ,  50, 0., 200.);
00131   hists_["met"     ]=fs->make<TH1F>("met"     , "missing E_{T}"        ,  25, 0., 200.);
00132 }
00133 
00134 void 
00135 PatTopSelectionAnalyzer::endJob() 
00136 {
00137 }
00138 
00139 #include "FWCore/Framework/interface/MakerMacros.h"
00140 DEFINE_FWK_MODULE(PatTopSelectionAnalyzer);