CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/PatExamples/plugins/PatZjetsJetAnalyzer.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 PatZjetsJetAnalyzer : public edm::EDAnalyzer {
00014 
00015 public:
00016   explicit PatZjetsJetAnalyzer(const edm::ParameterSet&);
00017   ~PatZjetsJetAnalyzer();
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/Jet.h"
00035 
00036 PatZjetsJetAnalyzer::PatZjetsJetAnalyzer(const edm::ParameterSet& iConfig):
00037   histContainer_(),
00038   src_(iConfig.getUntrackedParameter<edm::InputTag>("src"))
00039 {
00040 }
00041 
00042 PatZjetsJetAnalyzer::~PatZjetsJetAnalyzer()
00043 {
00044 }
00045 
00046 void
00047 PatZjetsJetAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00048 {
00049   // get electron collection
00050   edm::Handle<edm::View<pat::Jet> > jets;
00051   iEvent.getByLabel(src_,jets);
00052 
00053   // loop jets
00054   for(edm::View<pat::Jet>::const_iterator ijet=jets->begin(); ijet!=jets->end(); ++ijet){
00055     // fill simple histograms
00056     pat::Jet jet = ijet->correctedJet("had", "uds");
00057     histContainer_["pt"  ]->Fill( jet.pt () );
00058     histContainer_["eta" ]->Fill( jet.eta() );
00059     histContainer_["phi" ]->Fill( jet.phi() );
00060     histContainer_["emf" ]->Fill( jet.emEnergyFraction() );
00061     for(unsigned int i=0; i<jet.getCaloConstituents().size(); ++i){
00062       histContainer_["dEta"]->Fill( jet.getCaloConstituent(i)->eta()-jet.eta() );
00063     }
00064   }
00065 }
00066 
00067 void 
00068 PatZjetsJetAnalyzer::beginJob()
00069 {
00070   // register to the TFileService
00071   edm::Service<TFileService> fs;
00072   
00073   // book histograms:
00074   histContainer_["pt"  ]=fs->make<TH1F>("pt"   , "pt"   ,  150,   0.,  150.);
00075   histContainer_["eta" ]=fs->make<TH1F>("eta"  , "eta"  ,   50,   0.,    5.);
00076   histContainer_["phi" ]=fs->make<TH1F>("phi"  , "phi"  ,   60, 3.14,  3.14);
00077   histContainer_["emf" ]=fs->make<TH1F>("emf"  , "emf"  ,   40,   0.,    1.);
00078   histContainer_["dEta"]=fs->make<TH1F>("dEta" , "dEta" ,   40,   0.,    1.);
00079 }
00080 
00081 void 
00082 PatZjetsJetAnalyzer::endJob() 
00083 {
00084 }
00085 
00086 #include "FWCore/Framework/interface/MakerMacros.h"
00087 DEFINE_FWK_MODULE(PatZjetsJetAnalyzer);