CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/PhysicsTools/PatExamples/plugins/PatZjetsElectronAnalyzer.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 PatZjetsElectronAnalyzer : public edm::EDAnalyzer {
00014 
00015 public:
00016   explicit PatZjetsElectronAnalyzer(const edm::ParameterSet&);
00017   ~PatZjetsElectronAnalyzer();
00018   
00019 private:
00020 
00021   virtual void beginJob() ;
00022   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00023   virtual void endJob() ;
00024   
00025   // simple map to contain all histograms; 
00026   // histograms are booked in the beginJob() 
00027   // method
00028   std::map<std::string,TH1F*> histContainer_; 
00029 
00030   // input tags  
00031   edm::InputTag src_;
00032 };
00033 
00034 #include "DataFormats/PatCandidates/interface/Electron.h"
00035 
00036 PatZjetsElectronAnalyzer::PatZjetsElectronAnalyzer(const edm::ParameterSet& iConfig):
00037   histContainer_(),
00038   src_(iConfig.getUntrackedParameter<edm::InputTag>("src"))
00039 {
00040 }
00041 
00042 PatZjetsElectronAnalyzer::~PatZjetsElectronAnalyzer()
00043 {
00044 }
00045 
00046 void
00047 PatZjetsElectronAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00048 {
00049   // get electron collection
00050   edm::Handle<edm::View<pat::Electron> > elecs;
00051   iEvent.getByLabel(src_,elecs);
00052 
00053   // loop electrons
00054   for(edm::View<pat::Electron>::const_iterator elec=elecs->begin(); elec!=elecs->end(); ++elec){
00055     // fill simple histograms
00056     histContainer_["pt"  ]->Fill( elec->pt () );
00057     histContainer_["eta" ]->Fill( elec->eta() );
00058     histContainer_["phi" ]->Fill( elec->phi() );
00059     histContainer_["iso" ]->Fill((elec->trackIso()+elec->caloIso())/elec->pt() );
00060     histContainer_["eop" ]->Fill( elec->eSeedClusterOverP() );
00061     histContainer_["clus"]->Fill( elec->e1x5()/elec->e5x5() );
00062     // fill enegry flow histogram for isolation
00063     for(int bin=1; bin<=histContainer_["dr"]->GetNbinsX(); ++bin){
00064       double lowerEdge = histContainer_["dr"]->GetBinLowEdge(bin);
00065       double upperEdge = histContainer_["dr"]->GetBinLowEdge(bin)+histContainer_["dr"]->GetBinWidth(bin);
00066       histContainer_["dr"]->Fill(histContainer_["dr"]->GetBinCenter(bin), elec->trackIsoDeposit()->depositWithin(upperEdge) - elec->trackIsoDeposit()->depositWithin(lowerEdge));
00067     }
00068     // fill electron id histograms
00069     if( elec->electronID("eidRobustLoose") > 0.5 )
00070       histContainer_["eIDs" ]->Fill(0);
00071     if( elec->electronID("eidRobustTight") > 0.5 )
00072       histContainer_["eIDs" ]->Fill(1);
00073     if( elec->electronID("eidLoose"      ) > 0.5 )
00074       histContainer_["eIDs" ]->Fill(2);
00075     if( elec->electronID("eidTight"      ) > 0.5 )
00076       histContainer_["eIDs" ]->Fill(3);
00077     if( elec->electronID("eidRobustHighEnergy") > 0.5 )
00078       histContainer_["eIDs" ]->Fill(4);
00079   }
00080 }
00081 
00082 void 
00083 PatZjetsElectronAnalyzer::beginJob()
00084 {
00085   // register to the TFileService
00086   edm::Service<TFileService> fs;
00087   
00088   // book histograms:
00089   histContainer_["pt"  ]=fs->make<TH1F>("pt"   , "pt"   ,  150,   0.,  150.);
00090   histContainer_["eta" ]=fs->make<TH1F>("eta"  , "eta"  ,   50,   0.,    5.);
00091   histContainer_["phi" ]=fs->make<TH1F>("phi"  , "phi"  ,   60, 3.14,  3.14);
00092   histContainer_["iso" ]=fs->make<TH1F>("iso"  , "iso"  ,   30,   0.,   10.);
00093   histContainer_["dr"  ]=fs->make<TH1F>("dr"   , "dr"   ,   40,   0.,    1.);
00094   histContainer_["eop" ]=fs->make<TH1F>("eop"  , "eop"  ,   40,   0.,    1.);
00095   histContainer_["clus"]=fs->make<TH1F>("clus" , "clus" ,   40,   0.,    1.);
00096   histContainer_["eIDs"]=fs->make<TH1F>("eIDs" , "eIDS" ,    5,   0.,    5.);
00097 }
00098 
00099 void 
00100 PatZjetsElectronAnalyzer::endJob() 
00101 {
00102 }
00103 
00104 #include "FWCore/Framework/interface/MakerMacros.h"
00105 DEFINE_FWK_MODULE(PatZjetsElectronAnalyzer);