ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/SSWW/Analysis/SSWWAnal.cc
Revision: 1.1
Committed: Sun Nov 29 16:36:36 2009 UTC (15 years, 5 months ago) by volper
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
test

File Contents

# Content
1 //********GEN***********
2 #include "PhysicsTools/PatAlgos/interface/SSWWAnal.h"
3 #include "FWCore/ServiceRegistry/interface/Service.h"
4 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
5 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
6 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
7 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
8 #include "SimDataFormats/GeneratorProducts/interface/LHECommonBlocks.h"
9 #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
10 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
11 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h"
12 #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
13
14 //****PAT *************
15 #include "DataFormats/Common/interface/Handle.h"
16 #include "DataFormats/Common/interface/RefProd.h"
17 #include "DataFormats/Common/interface/Ref.h"
18
19 #include "DataFormats/Candidate/interface/Particle.h"
20 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
21 #include "AnalysisDataFormats/TopObjects/interface/TtGenEvent.h"
22
23 #include "DataFormats/PatCandidates/interface/Particle.h"
24 #include "DataFormats/PatCandidates/interface/Electron.h"
25 #include "DataFormats/PatCandidates/interface/Muon.h"
26 #include "DataFormats/PatCandidates/interface/Tau.h"
27 #include "DataFormats/PatCandidates/interface/Jet.h"
28 #include "DataFormats/PatCandidates/interface/MET.h"
29 #include "DataFormats/PatCandidates/interface/Photon.h"
30
31 //***** PF************
32 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
33 #include "DataFormats/ParticleFlowCandidate/interface/IsolatedPFCandidate.h"
34 #include "DataFormats/ParticleFlowCandidate/interface/PileUpPFCandidate.h"
35
36 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
37 #include "DataFormats/ParticleFlowCandidate/interface/IsolatedPFCandidateFwd.h"
38 #include "DataFormats/ParticleFlowCandidate/interface/PileUpPFCandidateFwd.h"
39 #include "DataFormats/Common/interface/Wrapper.h"
40
41
42
43 using namespace std;
44 using namespace reco;
45 using namespace edm;
46 using namespace HepMC;
47
48
49
50 SSWWAnal::SSWWAnal(const edm::ParameterSet& iConfig):
51 //histocontainer_(),
52 // particlesFlow to PAT label
53 eleLabel_(iConfig.getUntrackedParameter<edm::InputTag>("electronTag")),
54 muoLabel_(iConfig.getUntrackedParameter<edm::InputTag>("muonTag")),
55 jetLabel_(iConfig.getUntrackedParameter<edm::InputTag>("jetTag")),
56 tauLabel_(iConfig.getUntrackedParameter<edm::InputTag>("tauTag")),
57 metLabel_(iConfig.getUntrackedParameter<edm::InputTag>("metTag")),
58 phoLabel_(iConfig.getUntrackedParameter<edm::InputTag>("photonTag")),
59
60 // standard PAT label
61 eleStandard_(iConfig.getUntrackedParameter<edm::InputTag>("eleStTag")),
62 muStandard_(iConfig.getUntrackedParameter<edm::InputTag>("muStTag")),
63 jetStandard_(iConfig.getUntrackedParameter<edm::InputTag>("jetStTag")),
64 tauStandard_(iConfig.getUntrackedParameter<edm::InputTag>("tauStTag")),
65 metStandard_(iConfig.getUntrackedParameter<edm::InputTag>("metStTag")),
66 phoStandard_(iConfig.getUntrackedParameter<edm::InputTag>("phoStTag"))
67
68 {
69
70
71 mcEvent = iConfig.getUntrackedParameter<InputTag>("MCEvent",std::string(""));
72 }
73
74
75 void SSWWAnal::beginJob( const edm::EventSetup& )
76 {
77 //edm::Service<TFileService> fs; // defined in .h
78
79
80 AnalysisTree = fs->make<TTree>("AnalysisTree","myAnalysis");
81
82 jetTree = fs->make<TTree>("jetTree","myAnalysis");
83 AnalysisTree->Branch("EventKind",&EventKind,"EventKind/I");
84 jetTree->Branch("pfJetEt",&pfJetEt,"pfJetEt/F");
85 jetTree->Branch("stJetEt",&stJetEt,"stJetEt/F");
86 AnalysisTree->Branch("muon1Pt",&muon1Pt,"muon1Pt/F");
87 AnalysisTree->Branch("muon2Pt",&muon2Pt,"muon2Pt/F");
88
89 h_mupt2 = fs->make<TH1D> ("h_mupt2","h_mupt2",100,0,200.);
90 h_mupt1 = fs->make<TH1D> ("h_mupt1","h_mupt1",100,0,200.);
91 h_muonEtaPt = fs->make<TH2D> ("h_muonEtaPt","h_muonEtaPt",100,-3.,3.,100,0,100.);
92 h_eleEtaPt =fs->make<TH2D>("h_eleEtaPt","h_eleEtaPt",100,-3.,3.,10,0,10.);
93 h_HT = fs->make<TH1D> ("h_HT","h_HT",50,0,1000.);
94 h_HTjet = fs->make<TH1D> ("h_HTjet","h_HTjet",50,0,1000.);
95 h_dPhiMuMET = fs->make<TH1D> ("h_dPhiMuMET","h_dPhiMuMET",50,-4.,4.);
96 h_njets = fs->make<TH1D> ("h_njets","h_njets",50,0,50.);
97 // gen
98 h_genEleEta = fs->make<TH1D> ("h_genEleEta","h_genEleEta",50,-5.,5.);
99 h_genMuEta = fs->make<TH1D> ("h_genMuEta","h_genMuEta",50,-5.,5.);
100 h_genElePt = fs->make<TH1D> ("h_genElePt","h_genElePt",50,0.,200.);
101 h_genMuPt = fs->make<TH1D> ("h_genMuPt","h_genMuPt",50,0.,200.);
102
103
104 return ;
105 }
106
107
108 void SSWWAnal::endJob()
109 {
110 TFile &tfile = fs->file();
111 tfile.ls();
112 return ;
113 }
114
115 SSWWAnal::~SSWWAnal()
116 {
117
118 // do anything here that needs to be done at destruction time
119 // (e.g. close files, deallocate resources etc.)
120
121
122 }
123
124 //void SSWWAnal::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
125 //{
126
127 void SSWWAnal::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
128 {
129
130
131 //=== GENERATION INFO==============================
132 /*************************************************************
133 //========================== LHE information =====================
134
135 edm::Handle<LHEEventProduct> lheProd;
136 iEvent.getByLabel("source", lheProd);
137
138
139 const lhef::HEPEUP & hepeup = lheProd->hepeup();
140
141 //========================== HepMC information =====================
142
143 iEvent.getByLabel( "generator" , EvtHandle);
144 const HepMC::GenEvent* Evt = EvtHandle->GetEvent() ;
145 EventKind = Evt->signal_process_id();
146
147 //cout <<"EventKind "<<EventKind<<endl;
148
149
150 std::vector<HepMC::GenParticle*> genPart;
151 std::vector<HepMC::GenVertex*> genVertex;
152
153 int nvert=0;
154 for (HepMC::GenEvent::vertex_const_iterator vit = Evt->vertices_begin();
155 vit != Evt->vertices_end(); ++vit) {
156 nvert++;
157 // cout<<nvert<< " id "<< (*vit)->id()<< " n part out "<<(*vit)->particles_out_size()<<endl;
158 }
159
160
161
162 int nhepmc=0;
163 for (HepMC::GenEvent::particle_const_iterator it = Evt->particles_begin();
164 it != Evt->particles_end(); ++it) {
165 nhepmc++;
166 // cout <<nhepmc <<" (*it)->status() "<< (*it)->status() << " (*it)->pdg_id() "<<(*it)->pdg_id()<<endl;
167 // if ((*it)->status() == 3) {
168 int abs_id = abs((*it)->pdg_id());
169 if (abs_id==24){
170 const HepMC::GenParticle * isW = (*it);
171 HepMC::GenVertex* outVertex = (*it)->end_vertex();
172 int numChildren = outVertex->particles_out_size();
173 // cout <<"W "<<(*it)->pdg_id()<<" numChildren "<<numChildren<<endl;
174 if(numChildren==2){
175 for(GenVertex::particles_out_const_iterator
176 Wdau = outVertex->particles_out_const_begin();
177 Wdau != outVertex->particles_out_const_end(); Wdau++){
178 cout <<" Wdau.pdgId() "<< (*Wdau)->pdg_id()<<endl;
179
180 if(abs((*Wdau)->pdg_id())==11){ // hepmc part has no eta(), pt(),.. methods
181 // float eleEta=(*Wdau)->eta();
182 //float elePt=(*Wdau)->pt();
183 //h_genEleEta->Fill(eleEta);
184 //h_genElePt->Fill(elePt);
185 }
186 if(abs((*Wdau)->pdg_id())==13){
187 //float muEta=(*Wdau)->eta();
188 //float muPt=(*Wdau)->pt();
189 //h_genMuEta->Fill(muEta);
190 //h_genMuPt->Fill(muPt);
191 }
192 }
193 }
194 //const genPart *isW = &(*it) ;
195 }
196 //if (abs_id==11 || abs_id==13 || abs_id==15) {
197 //cout <<"lep "<<(*it)->pdg_id()<<endl;
198 // float lepEta=(*it)->Eta();
199 //float lepPt=(*it)->Pt();
200 // h_lepEtaPt->Draw(lepEta,lepPt);
201 //}
202 }
203 *************************************************************
204 */
205 //========Gen Particles ===========================
206
207 int igen=0;
208 int motherRef=0;
209 int dauRef;
210 int n_WW=0;
211 int n_jj=0;
212 Handle<reco::GenParticleCollection> genParticles;
213 iEvent.getByLabel("genParticles", genParticles);
214 for( size_t i = 0; i < genParticles->size(); ++ i ) {
215 const reco::Candidate& p = (*genParticles)[ i ];
216 // cout <<"pdgid " <<p.pdgId()<<" status "<<p.status()<<
217 // " Ndau "<< p.numberOfDaughters() <<
218 // " Nmom "<< p.numberOfMothers()<< endl ;
219 const reco::Candidate *mom = p.mother();
220 // if(abs(p.pdgId())==24)cout <<" W "<<p.pdgId()<<endl;
221
222 if(abs(p.pdgId())==24 && p.numberOfDaughters()==2){
223 for(size_t dd=0; dd<p.numberOfDaughters(); dd++){
224 const reco::Candidate *Wdau = p.daughter(dd);
225 cout <<"Wdau->pdgid() "<< Wdau->pdgId()<<endl;
226 if(abs(Wdau->pdgId())==11){ // hepmc part non ha eta() e pt()
227 float eleEta=Wdau->eta();
228 float elePt=Wdau->pt();
229 h_genEleEta->Fill(eleEta);
230 h_genElePt->Fill(elePt);
231 //cout <<" ele's mother "<< Wdau->mother()->pdgId()<<endl;
232 }
233 if(abs(Wdau->pdgId())==13){
234 float muEta=Wdau->eta();
235 float muPt=Wdau->pt();
236 h_genMuEta->Fill(muEta);
237 h_genMuPt->Fill(muPt);
238 // cout <<" mu's mother "<< Wdau->mother()->pdgId()<<endl;
239 }
240 }
241 }
242 }
243
244
245 //=============== RECO ==================================
246 using namespace edm;
247 //===============================================
248 //======= PF2PAT============================
249 edm::Handle<edm::View<pat::Muon> > Muons;
250 iEvent.getByLabel(muoLabel_, Muons );
251
252 edm::Handle<edm::View<pat::Jet> > Jets;
253 iEvent.getByLabel(jetLabel_,Jets );
254
255 edm::Handle<edm::View<pat::Electron> > Elecs;
256 iEvent.getByLabel(eleLabel_,Elecs );
257
258 edm::Handle<edm::View<pat::MET> > Mets ;
259 iEvent.getByLabel(metLabel_, Mets );
260
261 edm::Handle<edm::View<pat::Photon> > Phots ;
262 iEvent.getByLabel(phoLabel_, Phots );
263
264 edm::Handle<edm::View<pat::Tau> > Taus ;
265 iEvent.getByLabel(tauLabel_, Taus );
266
267 //===============================================
268 //============= STANDARD PAT ====================
269 edm::Handle<edm::View<pat::Muon> > stMuons;
270 iEvent.getByLabel(muStandard_, stMuons );
271
272 edm::Handle<edm::View<pat::Jet> > stJets;
273 iEvent.getByLabel(jetStandard_,stJets );
274
275 edm::Handle<edm::View<pat::Electron> > stElecs;
276 iEvent.getByLabel(eleStandard_,stElecs );
277
278 edm::Handle<edm::View<pat::MET> > stMets ;
279 iEvent.getByLabel(metStandard_, stMets );
280
281 edm::Handle<edm::View<pat::Photon> > stPhots ;
282 iEvent.getByLabel(phoStandard_, stPhots );
283
284 edm::Handle<edm::View<pat::Tau> > stTaus ;
285 iEvent.getByLabel(tauStandard_, stTaus );
286 //=================================================
287
288 cout <<"Nelecs "<< Elecs->size()<<"\t Nmuons " << Muons->size()<<"\t Njets " << Jets->size()<<endl;
289 float dPhi_mumet=9999;
290 float HT=0;
291 float Minv=0;
292
293 float HTjet=0;
294 float Meff = 0;
295
296 size_t njets=0;
297 for(edm::View<pat::Jet>::const_iterator jet_iter = Jets->begin(); jet_iter!=Jets->end(); ++jet_iter){
298 njets++;
299 // cout <<"PF jet "<<njets<<" ET "<<jet_iter->et()<<endl;
300 HT += jet_iter->et();
301 pfJetEt=jet_iter->et();
302 jetTree->Fill();
303 }
304
305 for(edm::View<pat::Jet>::const_iterator jet_iter = stJets->begin(); jet_iter!=stJets->end(); ++jet_iter){
306 njets++;
307 ///cout <<"STANDARD jet "<<njets<<" ET "<<jet_iter->et()<<endl;
308 stJetEt=jet_iter->et();
309 jetTree->Fill();
310 }
311 h_njets->Fill(njets);
312 HTjet=HT;
313
314 float metPhi=0;
315 h_HTjet->Fill(HTjet);
316
317 // enum = UncorrectionType
318
319 float uncorType = pat::MET::uncorrALL;
320 for(edm::View<pat::MET>::const_iterator met_iter = Mets->begin(); met_iter!=Mets->end(); ++met_iter){
321 //enum uncor = met_iter->UncorrectionType();
322 HT += met_iter->et();
323 metPhi=met_iter->phi();
324
325 // cout <<"uncorr met "<< met_iter->uncorrectedPt()<< " corre met "<< met_iter->et()<<endl;
326 }
327
328 for(edm::View<pat::Electron>::const_iterator ele_iter = Elecs->begin(); ele_iter!=Elecs->end(); ++ele_iter){
329 HT += ele_iter->et();
330 h_eleEtaPt->Fill(ele_iter->eta(),ele_iter->pt());
331 }
332
333 float muonPhi=0;
334 int imu=0;
335 float mupt1=0;
336 float mupt2=0;
337 for(edm::View<pat::Muon>::const_iterator mu_iter = Muons->begin(); mu_iter!=Muons->end(); ++mu_iter){
338 HT += mu_iter->et();
339 h_muonEtaPt->Fill(mu_iter->eta(),mu_iter->pt());
340 muonPhi=mu_iter->phi();
341 if(imu==0){
342 muon1Pt=mu_iter->pt();
343 h_mupt1->Fill(mu_iter->pt());
344 }
345 if(imu==1){
346 muon2Pt=mu_iter->pt();
347 h_mupt2->Fill(mu_iter->pt());
348 }
349 imu++;
350 }
351
352 dPhi_mumet= muonPhi-metPhi;
353 h_dPhiMuMET->Fill(dPhi_mumet);
354 h_HT->Fill(HT);
355
356 AnalysisTree->Fill();
357
358 }
359 DEFINE_FWK_MODULE(SSWWAnal);
360
361