ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Vuko/WZAnalysis/src/WZAnalyzer.cc
Revision: 1.3
Committed: Fri Nov 23 14:34:37 2007 UTC (17 years, 5 months ago) by vuko
Content type: text/plain
Branch: MAIN
Changes since 1.2: +61 -10 lines
Log Message:
Adding muon properties and base class LeptonProperties

File Contents

# User Rev Content
1 vuko 1.1 // -*- C++ -*-
2     //
3     // Package: WZAnalyzer
4     // Class: WZAnalyzer
5     //
6 vuko 1.2 /**\class WZAnalyzer WZAnalyzer.cc Vuko/WZAnalysis/src/WZAnalyzer.cc
7 vuko 1.1
8     Description: <one line class summary>
9    
10     Implementation:
11     <Notes on implementation>
12     */
13     //
14     // Original Author: Vuko Brigljevic
15     // Created: Fri Nov 9 11:07:27 CET 2007
16 vuko 1.3 // $Id: WZAnalyzer.cc,v 1.2 2007/11/22 09:12:56 vuko Exp $
17 vuko 1.1 //
18     //
19    
20    
21     // system include files
22     #include <memory>
23    
24     // user include files
25     #include "FWCore/Framework/interface/Frameworkfwd.h"
26     #include "FWCore/Framework/interface/EDAnalyzer.h"
27    
28     #include "FWCore/Framework/interface/Event.h"
29     #include "FWCore/Framework/interface/MakerMacros.h"
30    
31     #include "FWCore/ParameterSet/interface/ParameterSet.h"
32    
33 vuko 1.2 #include "Vuko/WZAnalysis/interface/WZAnalyzer.h"
34 vuko 1.1 #include "DataFormats/Candidate/interface/OverlapChecker.h"
35    
36 vuko 1.2 #include "Vuko/WZAnalysis/interface/ElectronProperties.h"
37 vuko 1.3 #include "Vuko/WZAnalysis/interface/MuonProperties.h"
38 vuko 1.1
39    
40     //--- muon AOD:
41     #include "DataFormats/JetReco/interface/CaloJetCollection.h"
42     #include "DataFormats/EgammaCandidates/interface/Electron.h"
43     #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
44     #include "DataFormats/MuonReco/interface/MuonFwd.h"
45     #include "DataFormats/MuonReco/interface/Muon.h"
46     #include "DataFormats/EgammaReco/interface/BasicCluster.h"
47     #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
48     #include "DataFormats/EgammaCandidates/interface/PixelMatchGsfElectron.h"
49    
50    
51     #include "TFile.h"
52     #include "TH1F.h"
53     #include "TH2F.h"
54     #include "TTree.h"
55    
56     #include <map>
57    
58     //
59     // constants, enums and typedefs
60     //
61    
62     //
63     // static data member definitions
64     //
65    
66     //
67     // constructors and destructor
68     //
69     WZAnalyzer::WZAnalyzer(const edm::ParameterSet& iConfig)
70    
71     {
72     //now do what ever initialization is needed
73    
74     theLooseMuonCollection = iConfig.getParameter<edm::InputTag>("LooseMuons");
75     theGoodMuonCollection = iConfig.getParameter<edm::InputTag>("GoodMuons");
76     theLooseElectronCollection = iConfig.getParameter<edm::InputTag>("LooseElectrons");
77     theGoodElectronCollection = iConfig.getParameter<edm::InputTag>("GoodElectrons");
78     theTightLeptonCollection = iConfig.getParameter<edm::InputTag>("TightLeptons");
79     // theMediumElectronCollection = iConfig.getParameter<edm::InputTag>("LooseElectrons");
80     // theTightElectronCollection = iConfig.getParameter<edm::InputTag>("TightElectrons");
81     // Z's
82     theZeeCollection = iConfig.getParameter<edm::InputTag>("ZtoEE");
83     theZmumuCollection = iConfig.getParameter<edm::InputTag>("ZtoMuMu");
84 vuko 1.3 theZllCollection = iConfig.getParameter<edm::InputTag>("ZtoLL");
85 vuko 1.1
86     }
87    
88    
89     WZAnalyzer::~WZAnalyzer()
90     {
91    
92     // do anything here that needs to be done at desctruction time
93     // (e.g. close files, deallocate resources etc.)
94    
95     }
96    
97    
98     //
99     // member functions
100     //
101    
102     // ------------ method called to for each event ------------
103     void
104     WZAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
105     {
106     using namespace edm;
107     using namespace reco;
108     using namespace std;
109    
110    
111     #ifdef THIS_IS_AN_EVENT_EXAMPLE
112     Handle<ExampleData> pIn;
113     iEvent.getByLabel("example",pIn);
114     #endif
115    
116     #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
117     ESHandle<SetupData> pSetup;
118     iSetup.get<SetupRecord>().get(pSetup);
119     #endif
120    
121     const Candidate * theZCandidate = 0;
122 vuko 1.3 const Candidate * theZCandidate2= 0;
123 vuko 1.1 const Candidate * theWlepton = 0;
124    
125     // Z->mumu
126     Handle<CandidateCollection> zmumuCands;
127     iEvent.getByLabel( theZmumuCollection , zmumuCands);
128    
129    
130     // Z->ee
131     Handle<CandidateCollection> zeeCands;
132     iEvent.getByLabel( theZeeCollection , zeeCands);
133    
134 vuko 1.3 // Z->ee
135     Handle<CandidateCollection> zllCands;
136     iEvent.getByLabel( theZllCollection , zllCands);
137    
138 vuko 1.1 // loose electrons
139     Handle<CandidateCollection> looseElectronCands;
140     iEvent.getByLabel( theLooseElectronCollection , looseElectronCands);
141    
142     // good electrons
143     Handle<CandidateCollection> goodElectronCands;
144     iEvent.getByLabel( theGoodElectronCollection , goodElectronCands);
145    
146     // loose muons
147     Handle<CandidateCollection> looseMuonCands;
148     iEvent.getByLabel( theLooseMuonCollection , looseMuonCands);
149    
150     // good muons
151     Handle<CandidateCollection> goodMuonCands;
152     iEvent.getByLabel( theGoodMuonCollection , goodMuonCands);
153    
154    
155     // tight leptons
156     Handle<CandidateCollection> tightLeptonCands;
157     iEvent.getByLabel( theTightLeptonCollection , tightLeptonCands);
158    
159    
160     // Reset a few things
161    
162 vuko 1.3 for (map<string,wzana::LeptonProperties* >::iterator iter = leptonProperties.begin();
163     iter!=leptonProperties.end(); iter++)
164 vuko 1.1 {
165     iter->second->ResetValues();
166     }
167    
168     // selected muons
169    
170    
171     //
172    
173     int nzee = zeeCands->size();
174     int nzmumu = zmumuCands->size();
175    
176     cout << "\t # loose mu : " << looseMuonCands->size()
177     << "\t # tight mu : " << goodMuonCands->size()
178     << "\t # loose e : " << looseElectronCands->size()
179     << "\t # tight e : " << goodElectronCands->size()
180     << "\t # tight l : " << tightLeptonCands->size()
181     << "\t # Z->mumu : " << zmumuCands->size()
182     << "\t # Z->ee : " << zeeCands->size()
183     << endl;
184    
185     Handle<CandidateCollection> zCands[2] = {zeeCands,zmumuCands};
186    
187     //
188     // Find best Z
189     //
190     ::OverlapChecker overlap;
191    
192     if (zeeCands->size() == 0 || zmumuCands->size() == 0) {
193     // Veto if both Z->ee and Z->mumu cands found
194    
195     float dzmass_min = 100.;
196    
197     for (int i=0; i<2; i++) {
198    
199     if (zCands[i]->size() > 0) {
200     theZCandidate = &(*(zCands[i]))[0];
201     }
202    
203     if (zCands[i]->size() > 1) {
204     for(CandidateCollection::const_iterator z1 = zCands[i]->begin();
205     z1 != zCands[i]->end(); ++ z1 ) {
206     float dzmass = fabs( z1->mass() - 91.188);
207     if (dzmass < dzmass_min) {
208     theZCandidate = &(*z1);
209     dzmass_min = dzmass;
210     }
211     //
212     //Get back Electrons from Z and W
213     for(CandidateCollection::const_iterator z2 = z1;
214     z2 != zCands[i]->end(); ++ z2 ) {
215     if (z1 != z2) {
216     if (overlap(*z1,*z2)) {
217     cout << "Overlap between two Z of flavour " << i << endl;
218     }
219     }
220     }
221    
222     }
223     }
224     }
225     }
226    
227 vuko 1.3
228     // Do the same with the collection
229    
230    
231     float dzmass_min = 100.;
232    
233     for(CandidateCollection::const_iterator z1 = zllCands->begin();
234     z1 != zllCands->end(); ++ z1 ) {
235     float dzmass = fabs( z1->mass() - 91.188);
236     if (dzmass < dzmass_min) {
237     theZCandidate2 = &(*z1);
238     dzmass_min = dzmass;
239     }
240     //
241     //Get back Electrons from Z and W
242     for(CandidateCollection::const_iterator z2 = z1;
243     z2 != zllCands->end(); ++ z2 ) {
244     if (z1 != z2) {
245     if (overlap(*z1,*z2)) {
246     cout << "Overlap between two Z of flavour " << endl;
247     } else {
248     cout << "NON OVERLAPPING Zs " << endl;
249     }
250     }
251     }
252     }
253    
254    
255 vuko 1.1 zFlavour = 0;
256     wlFlavour = 0;
257    
258 vuko 1.3 if (theZCandidate == theZCandidate2) {
259     cout << "SAME Z cand found \n";
260     } else {
261     cout << "DIFFERENT Z cand found \n";
262     }
263    
264    
265 vuko 1.1 int nwl_candidates=0;
266     if (theZCandidate) {
267    
268    
269     zMass = theZCandidate->mass();
270     zFlavour = abs(theZCandidate->daughter(0)->pdgId());
271     zPt = theZCandidate->pt();
272     zEta = theZCandidate->eta();
273     zPhi = theZCandidate->phi();
274    
275     float max_pt = 0.;
276    
277    
278     // Now find lepton that will be associated to W
279     // among leptons not used for the Z reconstruction
280     for(CandidateCollection::const_iterator lepton = tightLeptonCands->begin();
281     lepton != tightLeptonCands->end(); lepton++) {
282    
283    
284     if ( overlap(*theZCandidate, *lepton) ) continue; // Ignore if lepton used for the Z
285    
286     nwl_candidates++;
287    
288     // If more than one candidate: choose leading pt
289     if (lepton->pt() > max_pt) {
290     theWlepton = &(*lepton);
291     max_pt = lepton->pt();
292     }
293    
294     int id = lepton->pdgId();
295     cout << "Tight lepton: " << id << endl;
296    
297     if(lepton->hasMasterClone()) {
298     cout << "SHOUT: TIGHT LEPTON IS SHALLOW COPY !!! (SHOULD NOT BE!) \n";
299     }
300     //
301     }
302     if (theWlepton) {
303     wlFlavour = theWlepton->pdgId();
304     wlCharge = theWlepton->charge();
305     wlPt = theWlepton->pt();
306     wlEta = theWlepton->eta();
307     wlPhi = theWlepton->phi();
308    
309    
310 vuko 1.3 if (abs(wlFlavour) == 11) {
311     leptonProperties["Wel"]->FillProperties(theWlepton, iEvent, iSetup);
312     } else if (abs(wlFlavour) == 13) {
313     leptonProperties["Wmu"]->FillProperties(theWlepton, iEvent, iSetup);
314     }
315    
316    
317 vuko 1.1 const reco::Muon * muon = dynamic_cast<const reco::Muon *>(&(*theWlepton));
318     if(muon != 0) { /* it's a valid muon */
319     cout << "lepton is a muon \n" << endl;
320     }
321     const reco::PixelMatchGsfElectron * electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*theWlepton));
322     if(electron != 0) { /* it's a valid electron */
323     cout << "lepton is an electron \n" << endl;
324     elWTree->Fill();
325     }
326     }
327    
328     }
329     wzTree->Fill();
330    
331     }
332    
333    
334     // ------------ method called once each job just before starting event loop ------------
335     void
336     WZAnalyzer::beginJob(const edm::EventSetup&)
337     {
338    
339     using namespace wzana;
340    
341     theFile = new TFile( "wz.root", "RECREATE" ) ;
342    
343     wzTree = new TTree("WZTree","WZ informations");
344    
345     elWTree = new TTree("WElTree","W electron informations");
346    
347 vuko 1.3 leptonProperties["Wel"] = new ElectronProperties();
348     leptonProperties["ZEl1"] = new ElectronProperties();
349     leptonProperties["ZEl2"] = new ElectronProperties();
350    
351     leptonProperties["Wmu"] = new MuonProperties();
352     leptonProperties["Zmu1"] = new MuonProperties();
353     leptonProperties["Zmu2"] = new MuonProperties();
354 vuko 1.1
355 vuko 1.3 leptonProperties["Wel"]->CreateBranches(wzTree, "WEl_");
356     leptonProperties["Wel"]->CreateBranches(elWTree,"ElW_");
357 vuko 1.1
358     initialiseTree();
359     }
360    
361     // ------------ method called once each job just after ending the event loop ------------
362     void
363     WZAnalyzer::endJob() {
364    
365     theFile->Write();
366     theFile->Close();
367    
368     }
369    
370    
371     void WZAnalyzer::initialiseTree() {
372    
373     // Z properties
374     wzTree->Branch("Zmass", &zMass, "Zmass/F");
375     wzTree->Branch("ZId", &zFlavour, "Zid/I");
376     wzTree->Branch("ZPt", &zPt, "ZPt/F");
377     wzTree->Branch("ZEta", &zEta, "ZEta/F");
378     wzTree->Branch("ZPhi", &zPhi, "ZPhi/F");
379    
380    
381     // W Properties
382     wzTree->Branch("WlId", &wlFlavour, "Wlid/I");
383     wzTree->Branch("WlCharge", &wlCharge, "WlCharge/I");
384     wzTree->Branch("WlPt", &wlPt, "WlPt/F");
385    
386     }
387    
388    
389     //define this as a plug-in
390 vuko 1.2 // DEFINE_FWK_MODULE(WZAnalyzer);