ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/HiPatExamples/plugins/HiPatBasicAnalyzer.cc
Revision: 1.1
Committed: Mon Jul 27 19:43:49 2009 UTC (15 years, 9 months ago) by appeltel
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Error occurred while calculating annotation data.
Log Message:
initial revision

File Contents

# Content
1 #include <map>
2 #include <string>
3 //#include <vector>
4 //#include <sstream>
5 //#include <fstream>
6 //#include <iostream>
7
8 #include <TH1F.h>
9 #include <TH2F.h>
10 //#include <TROOT.h>
11 //#include <TFile.h>
12 //#include <TSystem.h>
13
14 #include "FWCore/Framework/interface/Event.h"
15 #include "FWCore/Framework/interface/EDAnalyzer.h"
16 #include "FWCore/ParameterSet/interface/InputTag.h"
17 #include "FWCore/ParameterSet/interface/ParameterSet.h"
18 #include "FWCore/ServiceRegistry/interface/Service.h"
19 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
20
21
22 class HiPatBasicAnalyzer : public edm::EDAnalyzer {
23
24 public:
25 explicit HiPatBasicAnalyzer(const edm::ParameterSet&);
26 ~HiPatBasicAnalyzer();
27
28 private:
29
30 virtual void beginJob(const edm::EventSetup&) ;
31 virtual void analyze(const edm::Event&, const edm::EventSetup&);
32 virtual void endJob() ;
33
34 // simple map to contain all 1D histograms;
35 // histograms are booked in the beginJob()
36 // method
37 std::map<std::string,TH1F*> histContainer_;
38 // compare muons, jets to genParticles and genJets
39 TH2F* jetPtGenPt_;
40 TH2F* muonPtGenPt_;
41
42 // input tags
43 edm::InputTag photonSrc_;
44 edm::InputTag muonSrc_;
45 edm::InputTag jetSrc_;
46
47 };
48
49 #include "DataFormats/PatCandidates/interface/Muon.h"
50 #include "DataFormats/PatCandidates/interface/Photon.h"
51 #include "DataFormats/PatCandidates/interface/Jet.h"
52 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
53 #include "DataFormats/JetReco/interface/GenJet.h"
54
55 HiPatBasicAnalyzer::HiPatBasicAnalyzer(const edm::ParameterSet& iConfig):
56 histContainer_(),
57 photonSrc_(iConfig.getUntrackedParameter<edm::InputTag>("photonSrc")),
58 muonSrc_(iConfig.getUntrackedParameter<edm::InputTag>("muonSrc")),
59 jetSrc_(iConfig.getUntrackedParameter<edm::InputTag>("jetSrc" ))
60 {
61 }
62
63 HiPatBasicAnalyzer::~HiPatBasicAnalyzer()
64 {
65 }
66
67 void
68 HiPatBasicAnalyzer::beginJob(const edm::EventSetup&)
69 {
70 // register to the TFileService
71 edm::Service<TFileService> fs;
72
73 // book histograms
74 histContainer_["muonPt"] = fs->make<TH1F>("muonPt", "muon pt", 100, 0.,100.);
75 histContainer_["muonEta"] = fs->make<TH1F>("muonEta","muon eta", 100, -3., 3.);
76 histContainer_["muonPhi"] = fs->make<TH1F>("muonPhi","muon phi", 100, -5., 5.);
77
78 histContainer_["photonPt"] = fs->make<TH1F>("photonPt", "photon pt", 100, 0.,100.);
79 histContainer_["photonEta"] = fs->make<TH1F>("photonEta","photon eta", 100, -3., 3.);
80 histContainer_["photonPhi"] = fs->make<TH1F>("photonPhi","photon phi", 100, -5., 5.);
81 histContainer_["photonIsolationCC3"] = fs->make<TH1F>("photonIsolationCC3",
82 "photon isolation variable CC3",
83 100, -10., 10.);
84
85 histContainer_["jetPt"] = fs->make<TH1F>("jetPt", "jet pt", 100, 0.,300.);
86 histContainer_["jetEta"] = fs->make<TH1F>("jetEta","jet eta", 100, -3., 3.);
87 histContainer_["jetPhi"] = fs->make<TH1F>("jetPhi","jet phi", 100, -5., 5.);
88
89 muonPtGenPt_ = fs->make<TH2F>("muonPtGenPt",
90 "matched MC muon pt vs reco muon pt",
91 100, 0.,100.,100,0.,100.);
92
93 jetPtGenPt_ = fs->make<TH2F>("jetPtGenPt",
94 "genJet pt vs matched IC5 jet pt",
95 100, 0.,100.,100,0.,100);
96 }
97
98 void
99 HiPatBasicAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
100 {
101 // get muon collection
102 edm::Handle<edm::View<pat::Muon> > muons;
103 iEvent.getByLabel(muonSrc_,muons);
104
105 // get jet collection
106 edm::Handle<edm::View<pat::Jet> > jets;
107 iEvent.getByLabel(jetSrc_,jets);
108
109 // get photon collection
110 edm::Handle<edm::View<pat::Photon> > photons;
111 iEvent.getByLabel(photonSrc_,photons);
112
113
114
115 // loop muon collection and fill histograms
116 for(edm::View<pat::Muon>::const_iterator muon=muons->begin(); muon!=muons->end(); ++muon){
117 histContainer_["muonPt"]->Fill( muon->pt() );
118 histContainer_["muonEta"]->Fill( muon->eta() );
119 histContainer_["muonPhi"]->Fill( muon->phi() );
120
121 // If there is a matched genParticle to the muon,
122 // get the pt
123 if( muon->genLepton() != NULL )
124 muonPtGenPt_->Fill( muon->genLepton()->pt(), muon->pt() );
125 }
126
127 // loop photon collection and fill histograms
128 for(edm::View<pat::Photon>::const_iterator photon=photons->begin(); photon!=photons->end(); ++photon){
129 histContainer_["photonPt"]->Fill( photon->pt() );
130 histContainer_["photonEta"]->Fill( photon->eta() );
131 histContainer_["photonPhi"]->Fill( photon->phi() );
132 histContainer_["photonIsolationCC3"]->Fill( photon->userFloat("isoCC3") );
133 }
134
135 // loop jet collection and fill histograms
136 for(edm::View<pat::Jet>::const_iterator jet=jets->begin(); jet!=jets->end(); ++jet){
137 histContainer_["jetPt"]->Fill( jet->pt() );
138 histContainer_["jetEta"]->Fill( jet->eta() );
139 histContainer_["jetPhi"]->Fill( jet->phi() );
140
141 // If there is a matched genJet to the jet,
142 // get the pt
143 if( jet->genJet() != NULL )
144 jetPtGenPt_->Fill( jet->genJet()->pt(), jet->pt() );
145 }
146
147 }
148
149
150 void
151 HiPatBasicAnalyzer::endJob()
152 {
153 }
154
155 #include "FWCore/Framework/interface/MakerMacros.h"
156 DEFINE_FWK_MODULE(HiPatBasicAnalyzer);