CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/PhysicsTools/PatExamples/src/PatMuonAnalyzer.cc

Go to the documentation of this file.
00001 #include "DataFormats/Common/interface/Handle.h"
00002 #include "DataFormats/MuonReco/interface/Muon.h"
00003 #include "DataFormats/PatCandidates/interface/Muon.h"
00004 #include "PhysicsTools/PatExamples/interface/PatMuonAnalyzer.h"
00005 
00006 
00008 PatMuonAnalyzer::PatMuonAnalyzer(const edm::ParameterSet& cfg, TFileDirectory& fs): 
00009   edm::BasicAnalyzer::BasicAnalyzer(cfg, fs),
00010   muons_(cfg.getParameter<edm::InputTag>("muons"))
00011 {
00012   hists_["muonPt"  ] = fs.make<TH1F>("muonPt"  , "pt"  ,  100,  0., 300.);
00013   hists_["muonEta" ] = fs.make<TH1F>("muonEta" , "eta" ,  100, -3.,   3.);
00014   hists_["muonPhi" ] = fs.make<TH1F>("muonPhi" , "phi" ,  100, -5.,   5.); 
00015 }
00016 
00018 void 
00019 PatMuonAnalyzer::analyze(const edm::EventBase& event)
00020 {
00021   // define what muon you are using; this is necessary as FWLite is not 
00022   // capable of reading edm::Views
00023   using pat::Muon;
00024 
00025   // Handle to the muon collection
00026   edm::Handle<std::vector<Muon> > muons;
00027   event.getByLabel(muons_, muons);
00028 
00029   // loop muon collection and fill histograms
00030   for(std::vector<Muon>::const_iterator mu1=muons->begin(); mu1!=muons->end(); ++mu1){
00031     hists_["muonPt" ]->Fill( mu1->pt () );
00032     hists_["muonEta"]->Fill( mu1->eta() );
00033     hists_["muonPhi"]->Fill( mu1->phi() );
00034   }
00035 }