ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Vuko/WZAnalysis/src/WZAnalyzer.cc
Revision: 1.29
Committed: Mon Jan 21 13:29:26 2008 UTC (17 years, 3 months ago) by smorovic
Content type: text/plain
Branch: MAIN
Changes since 1.28: +43 -2 lines
Log Message:
add jet rejection if DeltaR(jet,WZlepton)<0.15

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 smorovic 1.29 // $Id: WZAnalyzer.cc,v 1.28 2008/01/15 12:45:45 senka Exp $
17 vuko 1.1 //
18     //
19    
20    
21 senka 1.19
22 vuko 1.1 // system include files
23     #include <memory>
24    
25     // user include files
26     #include "FWCore/Framework/interface/Frameworkfwd.h"
27     #include "FWCore/Framework/interface/EDAnalyzer.h"
28    
29     #include "FWCore/Framework/interface/Event.h"
30     #include "FWCore/Framework/interface/MakerMacros.h"
31    
32     #include "FWCore/ParameterSet/interface/ParameterSet.h"
33    
34 vuko 1.2 #include "Vuko/WZAnalysis/interface/WZAnalyzer.h"
35 vuko 1.1 #include "DataFormats/Candidate/interface/OverlapChecker.h"
36    
37 vuko 1.2 #include "Vuko/WZAnalysis/interface/ElectronProperties.h"
38 vuko 1.3 #include "Vuko/WZAnalysis/interface/MuonProperties.h"
39 vuko 1.1
40 smorovic 1.6 #include "DataFormats/Common/interface/TriggerResults.h"
41 vuko 1.1
42     //--- muon AOD:
43     #include "DataFormats/JetReco/interface/CaloJetCollection.h"
44     #include "DataFormats/EgammaCandidates/interface/Electron.h"
45     #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
46     #include "DataFormats/MuonReco/interface/MuonFwd.h"
47     #include "DataFormats/MuonReco/interface/Muon.h"
48 senka 1.28 #include "DataFormats/MuonReco/interface/MuIsoDeposit.h"
49 vuko 1.1 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
50     #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
51     #include "DataFormats/EgammaCandidates/interface/PixelMatchGsfElectron.h"
52    
53 senka 1.9 #include "DataFormats/METReco/interface/CaloMET.h"
54    
55 vuko 1.1
56     #include "TFile.h"
57     #include "TH1F.h"
58     #include "TH2F.h"
59     #include "TTree.h"
60    
61     #include <map>
62    
63     //
64     // constants, enums and typedefs
65     //
66    
67     //
68     // static data member definitions
69     //
70    
71     //
72     // constructors and destructor
73     //
74     WZAnalyzer::WZAnalyzer(const edm::ParameterSet& iConfig)
75    
76     {
77     //now do what ever initialization is needed
78    
79 senka 1.16 fOutputFileName = iConfig.getUntrackedParameter<string>("HistOutFile");
80 vuko 1.10 theMCTruthCollection = iConfig.getParameter<edm::InputTag>("genParticles");
81    
82 senka 1.12 // theMCTruthCollection = iConfig.getParameter<edm::InputTag>("genParticleCollection");
83    
84 vuko 1.1 theLooseMuonCollection = iConfig.getParameter<edm::InputTag>("LooseMuons");
85     theGoodMuonCollection = iConfig.getParameter<edm::InputTag>("GoodMuons");
86     theLooseElectronCollection = iConfig.getParameter<edm::InputTag>("LooseElectrons");
87     theGoodElectronCollection = iConfig.getParameter<edm::InputTag>("GoodElectrons");
88     theTightLeptonCollection = iConfig.getParameter<edm::InputTag>("TightLeptons");
89     // theMediumElectronCollection = iConfig.getParameter<edm::InputTag>("LooseElectrons");
90     // theTightElectronCollection = iConfig.getParameter<edm::InputTag>("TightElectrons");
91     // Z's
92     theZeeCollection = iConfig.getParameter<edm::InputTag>("ZtoEE");
93     theZmumuCollection = iConfig.getParameter<edm::InputTag>("ZtoMuMu");
94 vuko 1.3 theZllCollection = iConfig.getParameter<edm::InputTag>("ZtoLL");
95 vuko 1.10
96     theJetCollection = iConfig.getParameter<edm::InputTag>("Jets");
97 vuko 1.26
98     theWeightCollection = iConfig.getParameter<edm::InputTag>("EventWeight");
99 smorovic 1.6
100     storeHLTresults=false;
101     storeHLTresults = iConfig.getParameter<bool>("storeHLTresults");
102 vuko 1.1
103 vuko 1.26 getEventWeight = false;
104     getEventWeight = iConfig.getParameter<bool>("getEventWeight");
105    
106 smorovic 1.23 triggerResultsTag = iConfig.getParameter<edm::InputTag>("TriggerResults");
107 smorovic 1.6 firstTriggerResult = true;
108 vuko 1.1 }
109    
110    
111     WZAnalyzer::~WZAnalyzer()
112     {
113    
114     // do anything here that needs to be done at desctruction time
115     // (e.g. close files, deallocate resources etc.)
116    
117     }
118    
119    
120     //
121     // member functions
122     //
123    
124     // ------------ method called to for each event ------------
125     void
126     WZAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
127     {
128     using namespace edm;
129     using namespace reco;
130     using namespace std;
131    
132 vuko 1.11 ///////////////////////////////////////
133     //
134     /// EVENT INITIALISATION
135     ///
136    
137     // Reset a few things
138    
139     for (map<string,wzana::LeptonProperties* >::iterator iter = leptonProperties.begin();
140     iter!=leptonProperties.end(); iter++)
141     {
142     iter->second->ResetValues();
143     }
144    
145    
146 vuko 1.1 const Candidate * theZCandidate = 0;
147     const Candidate * theWlepton = 0;
148    
149 vuko 1.11
150 senka 1.12 // Tau.clear();
151     // StableMuons.clear();
152     // StableElectrons.clear();
153    
154 vuko 1.11
155     ////////////////////////////////////////
156     // Get lists
157    
158 vuko 1.1 // Z->mumu
159     Handle<CandidateCollection> zmumuCands;
160     iEvent.getByLabel( theZmumuCollection , zmumuCands);
161    
162    
163     // Z->ee
164     Handle<CandidateCollection> zeeCands;
165     iEvent.getByLabel( theZeeCollection , zeeCands);
166    
167 vuko 1.3 // Z->ee
168     Handle<CandidateCollection> zllCands;
169     iEvent.getByLabel( theZllCollection , zllCands);
170    
171 vuko 1.1 // loose electrons
172     Handle<CandidateCollection> looseElectronCands;
173     iEvent.getByLabel( theLooseElectronCollection , looseElectronCands);
174    
175     // good electrons
176     Handle<CandidateCollection> goodElectronCands;
177     iEvent.getByLabel( theGoodElectronCollection , goodElectronCands);
178    
179     // loose muons
180     Handle<CandidateCollection> looseMuonCands;
181     iEvent.getByLabel( theLooseMuonCollection , looseMuonCands);
182    
183     // good muons
184     Handle<CandidateCollection> goodMuonCands;
185     iEvent.getByLabel( theGoodMuonCollection , goodMuonCands);
186    
187    
188     // tight leptons
189     Handle<CandidateCollection> tightLeptonCands;
190     iEvent.getByLabel( theTightLeptonCollection , tightLeptonCands);
191    
192 vuko 1.10 // jets
193 vuko 1.14
194     Handle<CaloJetCollection> jetCands;
195     //CandidateCollection> jetCands;
196 vuko 1.10 iEvent.getByLabel( theJetCollection , jetCands);
197    
198 vuko 1.26
199    
200     // event weights (CSA07 soups...)
201     eventWeight = -1;
202    
203     Handle< double> weightHandle;
204     if (getEventWeight) {
205     iEvent.getByLabel (theWeightCollection, weightHandle);
206     if (weightHandle.isValid()) {
207     eventWeight = * weightHandle;
208     }
209     }
210    
211    
212    
213 smorovic 1.6 // get hold of TriggerResults
214 senka 1.27 Handle<TriggerResults> HLTR; //moja promjena: ovo prebaceno 2 reda nize!
215 smorovic 1.6 if (storeHLTresults) {
216 senka 1.27 // Handle<TriggerResults> HLTR;
217 smorovic 1.23 iEvent.getByLabel(triggerResultsTag,HLTR);
218 vuko 1.7 if (firstTriggerResult) {
219     firstTriggerResult = false;
220     triggerNames= HLTR->getTriggerNames();
221     numTriggers = triggerNames.size();
222     }
223 smorovic 1.6
224 vuko 1.7 }
225 vuko 1.1
226 senka 1.9
227 senka 1.28 // MET corrected (P_muons, P_muons_calo_deposit)
228 vuko 1.1
229 senka 1.28 reco::Particle::LorentzVector MET=computeMET(iEvent, iSetup, looseMuonCands);
230     MET_energy=MET.energy();
231     MET_pt=MET.pt();
232     MET_eta=MET.eta();
233    
234 vuko 1.1
235 senka 1.28 // selected muons
236 vuko 1.1
237     cout << "\t # loose mu : " << looseMuonCands->size()
238     << "\t # tight mu : " << goodMuonCands->size()
239     << "\t # loose e : " << looseElectronCands->size()
240     << "\t # tight e : " << goodElectronCands->size()
241     << "\t # tight l : " << tightLeptonCands->size()
242     << "\t # Z->mumu : " << zmumuCands->size()
243     << "\t # Z->ee : " << zeeCands->size()
244 vuko 1.7 << "\t # Z->ll : " << zllCands->size()
245 vuko 1.1 << endl;
246    
247 senka 1.27 N_looseMuons=0;
248     N_looseElectrons=0;
249     N_looseMuons = looseMuonCands->size();
250     N_looseElectrons = looseElectronCands->size();
251    
252    
253 vuko 1.1 //
254 vuko 1.7 // Find best Z (in Z->ll collection (merged Z->ee & Z->mumu)
255 vuko 1.1 //
256     ::OverlapChecker overlap;
257    
258 vuko 1.3
259     float dzmass_min = 100.;
260    
261 senka 1.27 n=1; // number of non overlaping Zs
262 vuko 1.3 for(CandidateCollection::const_iterator z1 = zllCands->begin();
263     z1 != zllCands->end(); ++ z1 ) {
264 vuko 1.21
265     // Check that two leptons used to build the Z are not overlapping
266     if (overlap(*(z1->daughter(0)),*(z1->daughter(1))) ) {
267     cout << "Reject Z candidate: built with overlapping leptons - flavour : "
268     << z1->daughter(0)->pdgId() << endl;
269     continue;
270     }
271    
272 vuko 1.3 float dzmass = fabs( z1->mass() - 91.188);
273     if (dzmass < dzmass_min) {
274 vuko 1.7 theZCandidate = &(*z1);
275 vuko 1.3 dzmass_min = dzmass;
276     }
277     //
278     //Get back Electrons from Z and W
279     for(CandidateCollection::const_iterator z2 = z1;
280     z2 != zllCands->end(); ++ z2 ) {
281     if (z1 != z2) {
282     if (overlap(*z1,*z2)) {
283 vuko 1.7 cout << "Overlap between two Z of flavour "
284     << z1->daughter(0)->pdgId() << "\t"
285     << z2->daughter(0)->pdgId() << "\t"
286     << endl;
287 vuko 1.3 } else {
288     cout << "NON OVERLAPPING Zs " << endl;
289 senka 1.27 n++;
290 vuko 1.3 }
291     }
292     }
293     }
294    
295    
296 vuko 1.1 zFlavour = 0;
297     wlFlavour = 0;
298    
299 senka 1.9 dPhi_WlZ_reco=-15.;
300     dPhi_WZ_reco=-15.;
301 vuko 1.4
302 vuko 1.3
303 senka 1.15 //---------------
304     // cout<<"??????????????????? before MatchedGenParticle(&(*looseMuonCands)[0]);" <<endl;
305     // matching(iEvent,looseMuonCands, 13);
306     // matching(iEvent,looseElectronCands, 11);
307     // MatchedGenParticle(&(*looseMuonCands)[0]);
308     //-------------------
309    
310 vuko 1.1 int nwl_candidates=0;
311     if (theZCandidate) {
312    
313    
314     zMass = theZCandidate->mass();
315     zFlavour = abs(theZCandidate->daughter(0)->pdgId());
316     zPt = theZCandidate->pt();
317     zEta = theZCandidate->eta();
318     zPhi = theZCandidate->phi();
319    
320 vuko 1.18 // Sanity check: can we identify the Z daughters with leptons from the loose lists
321    
322     Handle<CandidateCollection> looseLeptonCands;
323     if (zFlavour == 11) {
324     looseLeptonCands = looseElectronCands;
325     } else if (zFlavour == 13) {
326     looseLeptonCands = looseMuonCands;
327     }
328     for (int i=0; i<2; i++) {
329     int noverlaps=0;
330     for(CandidateCollection::const_iterator l = looseLeptonCands->begin();
331     l != looseLeptonCands->end(); l++) {
332     if (overlap(*(theZCandidate->daughter(i)), *l) ) {
333 vuko 1.25 // cout << "found overlap: pt = " << l->pt()
334     // << "\t eta = " << l->eta()
335     // << "\t phi = " << l->phi()
336     // << "\t compared to : pt " << theZCandidate->daughter(i)->pt()
337     // << "\t eta = " << theZCandidate->daughter(i)->eta()
338     // << "\t phi = " << theZCandidate->daughter(i)->phi()
339     // << endl;
340 vuko 1.18 noverlaps++;
341     }
342     }
343 vuko 1.25 // cout << "Z Flavour : " << zFlavour
344     // << "\t # overlaps for daughter " << i << " : " << noverlaps
345     // << "\t (out of " << looseLeptonCands->size() << " possible) "
346     // << endl;
347 vuko 1.18 }
348    
349 senka 1.15 matching(iEvent,looseMuonCands, 13);
350     matching(iEvent,looseElectronCands, 11);
351    
352 vuko 1.4 if (zFlavour == 11) {
353 vuko 1.25 // cout << " filling Z lepton electron properties \n";
354     // if (theZCandidate->daughter(0)) cout << " found Z daughter \n";
355 senka 1.17 //--------------
356 vuko 1.18 leptonProperties["ZEl1"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
357     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
358     leptonProperties["ZEl2"]->FillProperties(theZCandidate->daughter(1), iEvent, iSetup,
359     MatchedGenParticle(theZCandidate->daughter(1)),dR(theZCandidate->daughter(1)));
360 senka 1.17 } else if (zFlavour == 13) {
361     //--------------
362 vuko 1.25 // cout << " filling Z lepton muon properties \n";
363     // if (theZCandidate->daughter(0)) cout << "found Z daughter \n";
364 senka 1.19 const reco::Candidate * mcpart = MatchedGenParticle(theZCandidate->daughter(0));
365     if (mcpart) {
366 senka 1.22 // cout << "GenPt = genParticle->pt()="<< mcpart->pt() <<"\n";
367 senka 1.19 } else {
368     cout << "NO MATCHED GEN PARTICLE \n";
369     }
370 senka 1.24 // cout << "dR="<< dR(theZCandidate->daughter(0))<<"\n";
371 senka 1.17 //--------------
372 vuko 1.18 leptonProperties["Zmu1"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
373     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
374     leptonProperties["Zmu2"]->FillProperties(theZCandidate->daughter(1), iEvent, iSetup,
375     MatchedGenParticle(theZCandidate->daughter(1)),dR(theZCandidate->daughter(1)));
376 senka 1.15
377 vuko 1.4 }
378    
379 vuko 1.1 float max_pt = 0.;
380    
381 senka 1.9 /// Find W lepton
382    
383 vuko 1.1
384     // Now find lepton that will be associated to W
385     // among leptons not used for the Z reconstruction
386     for(CandidateCollection::const_iterator lepton = tightLeptonCands->begin();
387     lepton != tightLeptonCands->end(); lepton++) {
388    
389    
390     if ( overlap(*theZCandidate, *lepton) ) continue; // Ignore if lepton used for the Z
391    
392     nwl_candidates++;
393    
394     // If more than one candidate: choose leading pt
395     if (lepton->pt() > max_pt) {
396     theWlepton = &(*lepton);
397     max_pt = lepton->pt();
398     }
399    
400     if(lepton->hasMasterClone()) {
401     cout << "SHOUT: TIGHT LEPTON IS SHALLOW COPY !!! (SHOULD NOT BE!) \n";
402     }
403     //
404     }
405     if (theWlepton) {
406     wlFlavour = theWlepton->pdgId();
407     wlCharge = theWlepton->charge();
408     wlPt = theWlepton->pt();
409     wlEta = theWlepton->eta();
410     wlPhi = theWlepton->phi();
411    
412 senka 1.9 cout << "found W lepton \n";
413 vuko 1.1
414 vuko 1.3 if (abs(wlFlavour) == 11) {
415 senka 1.17 leptonProperties["Wel"]->FillProperties(theWlepton, iEvent, iSetup, MatchedGenParticle(theWlepton),dR(theWlepton));
416 vuko 1.3 } else if (abs(wlFlavour) == 13) {
417 vuko 1.25 // cout << "found W lepton: it is a muon \n";
418 senka 1.17 leptonProperties["Wmu"]->FillProperties(theWlepton, iEvent, iSetup, MatchedGenParticle(theWlepton),dR(theWlepton));
419 vuko 1.3 }
420 senka 1.24
421 senka 1.9 dPhi_WlZ_reco=acos(cos(theWlepton->phi()-theZCandidate->phi()));
422     dPhi_WZ_reco=acos(cos((theWlepton->p4()+MET).phi()-theZCandidate->phi()));
423 vuko 1.3
424 vuko 1.20 // const reco::Muon * muon = dynamic_cast<const reco::Muon *>(&(*theWlepton));
425     // if(muon != 0) { /* it's a valid muon */
426     // cout << "lepton is a muon \n" << endl;
427     // }
428     // const reco::PixelMatchGsfElectron * electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*theWlepton));
429     // if (electron != 0) {
430     // cout << "lepton is an electron \n" << endl;
431     // }
432 vuko 1.1 }
433    
434     }
435 smorovic 1.6
436 vuko 1.10 // Handle <reco::GenParticleCandidateCollection> mccands;
437     Handle<CandidateCollection> mccands;
438     iEvent.getByLabel( theMCTruthCollection,mccands );
439 smorovic 1.6
440 vuko 1.11 collectMCsummary(mccands);
441 smorovic 1.6
442 smorovic 1.8 if (storeHLTresults) {
443    
444 smorovic 1.6 //def: 1:single electron 2:single relaxed 3:double electron 4: double relaxed 5,6,7,8: muon e+mu: 9
445 smorovic 1.8
446 smorovic 1.6 triggerBitmask=0;
447 smorovic 1.8
448 smorovic 1.6 for (size_t i=0; i<numTriggers; ++i) {
449    
450     // cout << "trigName" << triggerNames[i] << "wasRUN:" << HLTR->wasrun(i) << "error " << HLTR->error(i)
451     // << " accept" << HLTR->accept(i) << "\n";
452    
453     if (!HLTR->wasrun(i)) {
454     //cout << "trigger not run? "<< triggerNames[i] << "\n";
455     continue;
456     }
457     if (HLTR->error(i) ) {
458     //cout << "error trigger: "<< triggerNames[i] <<"\n";
459     continue;
460     }
461     if (HLTR->accept(i)) {
462     //if (triggerNames[i].compare("mcpath")!=0)
463     //TRaccept=true;
464     }else {
465     continue;
466     }
467    
468     if (triggerNames[i].compare("HLT1Electron")==0) triggerBitmask |= 1;
469     if (triggerNames[i].compare("HLT1ElectronRelaxed")==0) triggerBitmask |= 2;
470     if (triggerNames[i].compare("HLT2Electron")==0) triggerBitmask |= 4;
471     if (triggerNames[i].compare("HLT2ElectronRelaxed")==0) triggerBitmask |= 8;
472    
473     if (triggerNames[i].compare("HLT1MuonIso")==0) triggerBitmask |= 16;
474     if (triggerNames[i].compare("HLT1MuonNonIso")==0) triggerBitmask |= 32;
475     if (triggerNames[i].compare("HLT2MuonNonIso")==0) triggerBitmask |= 64;
476     if (triggerNames[i].compare("HLT2MuonZ")==0) triggerBitmask |= 128;
477    
478     if (triggerNames[i].compare("HLTXElectronMuon")==0) triggerBitmask |= 256;
479     if (triggerNames[i].compare("HLTXElectronMuonRelaxed")==0) triggerBitmask |= 512;
480     }
481     }
482 vuko 1.10
483    
484     // Jet properties
485    
486     float max_et = 0.;
487 vuko 1.14 float max2_et = 0.;
488     const Candidate * leadingJet = 0;
489     const Candidate * secondJet = 0;
490 smorovic 1.29
491     bool matchedLept[3]={false,false,false};
492    
493 vuko 1.14 // for(CandidateCollection::const_iterator jet = jetCands->begin();
494     for(CaloJetCollection::const_iterator jet = jetCands->begin();
495 vuko 1.10 jet != jetCands->end(); jet++) {
496 smorovic 1.29
497     //ignore jets which are within dR 0.15 to a WZ lepton
498     {
499     float dPhi[3]={-1.0,-1.0,-1.0};
500     float dEta[3]={-1.0,-1.0,-1.0};
501     bool skipJet=false;
502    
503     for (int ct=0;ct<2;ct++) {
504     if (theZCandidate->daughter(ct)->pt()>0
505     && (abs(theZCandidate->daughter(ct)->pdgId())==13
506     || abs(theZCandidate->daughter(ct)->pdgId())==11) ) {
507    
508     dPhi[ct]=fabs(theZCandidate->daughter(ct)->phi() - jet->phi());
509     dEta[ct]=fabs(theZCandidate->daughter(ct)->eta() - jet->eta());
510     }
511     }
512    
513     if (theWlepton->pt()>0 && (abs(theWlepton->pdgId())==13 || abs(theWlepton->pdgId())==11 )) {
514     dPhi[2]=fabs(theWlepton->phi() - jet->phi());
515     dEta[2]=fabs(theWlepton->eta() - jet->eta());
516     }
517    
518     for (int k=0;k<3;k++) {
519     if (matchedLept[k] || dPhi[k]<0.0 || dEta[k]<0.0) continue;
520    
521     while (dPhi[k]>6.28318531) dPhi[k]-= 6.28318531;
522     if (dPhi[k]>3.14159265) dPhi[k]= 6.28318531-dPhi[k];
523    
524     float deltaR=sqrt(dPhi[k]*dPhi[k]+dEta[k]*dEta[k]);
525     if (deltaR<0.15) {
526     skipJet=true;
527     matchedLept[k]=true;
528     break;
529     }
530     }
531     if (skipJet) continue;
532     }
533    
534 vuko 1.10 if (jet->et() > max_et ) {
535 vuko 1.14 if (leadingJet) {
536     secondJet = leadingJet;
537     max2_et = max_et;
538     }
539 vuko 1.10 leadingJet = &(*jet);
540     max_et = jet->et();
541 smorovic 1.29
542 vuko 1.14 } else {
543     if (jet->et() > max2_et ) {
544     secondJet = &(*jet);
545     max2_et = jet->et();
546     }
547 vuko 1.10 }
548     }
549     if (leadingJet) {
550     jet1Et = leadingJet->et();
551 vuko 1.14 jet1Phi = leadingJet->phi();
552 vuko 1.10 jet1Eta = leadingJet->eta();
553    
554     } else {
555     jet1Et = -10;
556     jet1Phi = 0.;
557     jet1Eta = 0.;
558     }
559 vuko 1.14 if (secondJet) {
560     jet2Et = secondJet->et();
561     jet2Phi = secondJet->phi();
562     jet2Eta = secondJet->eta();
563     } else {
564     jet2Et = -10;
565     jet2Phi = 0.;
566     jet2Eta = 0.;
567    
568     }
569 senka 1.9
570 senka 1.12 // matching:
571    
572     matching(iEvent,looseMuonCands, 13);
573     matching(iEvent,looseElectronCands, 11);
574    
575 senka 1.13 getMother(&(*mccands)[1]);
576 vuko 1.10
577 vuko 1.1 wzTree->Fill();
578    
579 vuko 1.20
580    
581     // Fill electrons in a tree
582    
583     for(CandidateCollection::const_iterator el = looseElectronCands->begin();
584     el != looseElectronCands->end(); ++ el ) {
585    
586     electronUse = 0;
587    
588     if (theZCandidate) {
589    
590     if (overlap(*theZCandidate, *el) ) {
591     electronUse = 23;
592     } else if (theWlepton) {
593     if (overlap(*theWlepton, *el) ) {
594     electronUse = 24;
595     }
596     leptonProperties["electron"]->FillProperties(&(*el),
597     iEvent, iSetup,
598     MatchedGenParticle(&(*el)),dR(&(*el)));
599     electronTree->Fill();
600    
601     }
602     }
603     }
604    
605    
606 vuko 1.1 }
607    
608    
609     // ------------ method called once each job just before starting event loop ------------
610     void
611     WZAnalyzer::beginJob(const edm::EventSetup&)
612     {
613    
614     using namespace wzana;
615    
616 senka 1.16 // theFile = new TFile( "wz.root", "RECREATE" ) ;
617     theFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
618    
619 vuko 1.1
620     wzTree = new TTree("WZTree","WZ informations");
621    
622 vuko 1.20 electronTree = new TTree("ElTree","electron informations");
623    
624     leptonProperties["electron"] = new ElectronProperties();
625 vuko 1.1
626 vuko 1.3 leptonProperties["Wel"] = new ElectronProperties();
627     leptonProperties["ZEl1"] = new ElectronProperties();
628     leptonProperties["ZEl2"] = new ElectronProperties();
629    
630     leptonProperties["Wmu"] = new MuonProperties();
631     leptonProperties["Zmu1"] = new MuonProperties();
632     leptonProperties["Zmu2"] = new MuonProperties();
633 vuko 1.1
634 vuko 1.20
635 vuko 1.3 leptonProperties["Wel"]->CreateBranches(wzTree, "WEl_");
636 vuko 1.4 leptonProperties["ZEl1"]->CreateBranches(wzTree, "ZEl1_");
637     leptonProperties["ZEl2"]->CreateBranches(wzTree, "ZEl2_");
638 vuko 1.1
639 senka 1.9 leptonProperties["Wmu"] ->CreateBranches(wzTree, "Wmu_");
640     leptonProperties["Zmu1"] ->CreateBranches(wzTree, "Zmul_");
641     leptonProperties["Zmu2"] ->CreateBranches(wzTree, "Zmu2_");
642 vuko 1.20 leptonProperties["electron"] ->CreateBranches(electronTree);
643 senka 1.9
644 vuko 1.1 initialiseTree();
645 smorovic 1.6
646     //prepare HLT TriggerResults branch
647     if (storeHLTresults) {
648     wzTree->Branch("WZ_hltBitmask",&triggerBitmask,"WZ_hltBitmask/I");
649    
650     }
651 senka 1.9
652     // MET branch
653     wzTree->Branch("MET_energy",&MET_energy,"MET_energy/F");
654     wzTree->Branch("MET_pt",&MET_pt,"MET_pt/F");
655     wzTree->Branch("MET_eta",&MET_eta,"MET_eta/F");
656     wzTree->Branch("dPhi_WlZ_reco",&dPhi_WlZ_reco,"dPhi_WlZ_reco/F");
657     wzTree->Branch("dPhi_WZ_reco",&dPhi_WZ_reco,"dPhi_WZ_reco/F");
658 senka 1.27
659     // # of non overlaping Zs
660     wzTree->Branch("N_nonOverlaping_Z",&n,"N_nonOverlaping_Z/I");
661     wzTree->Branch("N_looseMuons",&N_looseMuons,"N_looseMuons/I");
662     wzTree->Branch("N_looseElectrons",&N_looseElectrons,"N_looseElectrons/I");
663    
664 vuko 1.1 }
665    
666     // ------------ method called once each job just after ending the event loop ------------
667     void
668     WZAnalyzer::endJob() {
669    
670     theFile->Write();
671     theFile->Close();
672    
673     }
674    
675    
676     void WZAnalyzer::initialiseTree() {
677    
678 vuko 1.26
679     // Event properties
680     wzTree->Branch("weight", &eventWeight, "weight/F");
681    
682 vuko 1.1 // Z properties
683     wzTree->Branch("Zmass", &zMass, "Zmass/F");
684     wzTree->Branch("ZId", &zFlavour, "Zid/I");
685     wzTree->Branch("ZPt", &zPt, "ZPt/F");
686     wzTree->Branch("ZEta", &zEta, "ZEta/F");
687     wzTree->Branch("ZPhi", &zPhi, "ZPhi/F");
688    
689     // W Properties
690     wzTree->Branch("WlId", &wlFlavour, "Wlid/I");
691     wzTree->Branch("WlCharge", &wlCharge, "WlCharge/I");
692     wzTree->Branch("WlPt", &wlPt, "WlPt/F");
693 smorovic 1.8
694     wzTree->Branch("MC_leptonZ1_pt", &MCleptZ1_pt,"MC_leptonZ1_pt/F");
695     wzTree->Branch("MC_leptonZ2_pt", &MCleptZ2_pt,"MC_leptonZ2_pt/F");
696     wzTree->Branch("MC_leptonW_pt", &MCleptW_pt, "MC_leptonW_pt/F");
697    
698     wzTree->Branch("MC_leptonZ1_eta", &MCleptZ1_eta,"MC_leptonZ1_eta/F");
699     wzTree->Branch("MC_leptonZ2_eta", &MCleptZ2_eta,"MC_leptonZ2_eta/F");
700     wzTree->Branch("MC_leptonW_eta", &MCleptW_eta, "MC_leptonW_eta/F");
701    
702     wzTree->Branch("MC_leptonZ1_phi", &MCleptZ1_phi,"MC_leptonZ1_phi/F");
703     wzTree->Branch("MC_leptonZ2_phi", &MCleptZ2_phi,"MC_leptonZ2_phi/F");
704     wzTree->Branch("MC_leptonW_phi", &MCleptW_phi, "MC_leptonW_phi/F");
705    
706     wzTree->Branch("MC_leptonZ1_pdgid", &MCleptZ1_pdgid,"MC_leptonZ1_pdgid/I");
707     wzTree->Branch("MC_leptonZ2_pdgid", &MCleptZ2_pdgid,"MC_leptonZ2_pdgid/I");
708     wzTree->Branch("MC_leptonW_pdgid", &MCleptW_pdgid, "MC_leptonW_pdgid/I");
709 vuko 1.14
710     /*
711     wzTree->Branch("MC_leptonW_origin", &MCleptW_pdgid, "MC_leptonW_origin/I");
712     wzTree->Branch("MC_leptonZ1_origin", &MCleptW_pdgid, "MC_leptonZ1_origin/I");
713     wzTree->Branch("MC_leptonZ2_origin", &MCleptW_pdgid, "MC_leptonZ2_origin/I");
714     */
715    
716 smorovic 1.8 wzTree->Branch("MC_TauDecayType_fromZ1", &MC_tauDecayTypeZ1,"MC_TauDecayType_fromZ1/I");
717     wzTree->Branch("MC_TauDecayType_fromZ2", &MC_tauDecayTypeZ2,"MC_TauDecayType_fromZ2/I");
718     wzTree->Branch("MC_TauDecayType_fromW", &MC_tauDecayTypeW, "MC_TauDecayType_fromW/I");
719 vuko 1.10
720     // MET properties
721    
722     // Jet properties
723     wzTree->Branch("Jet1Et", &jet1Et, "Jet1Et/F");
724     wzTree->Branch("Jet1Phi", &jet1Phi, "Jet1Phi/F");
725     wzTree->Branch("Jet1Eta", &jet1Eta, "Jet1Eta/F");
726    
727     wzTree->Branch("Jet2Et", &jet2Et, "Jet2Et/F");
728     wzTree->Branch("Jet2Phi", &jet2Phi, "Jet2Phi/F");
729     wzTree->Branch("Jet2Eta", &jet2Eta, "Jet2Eta/F");
730    
731 vuko 1.20 //
732     electronTree->Branch("used", &electronUse, "used/I");
733 vuko 1.10
734 smorovic 1.8 }
735 vuko 1.1
736 senka 1.9
737 senka 1.28 //////////////////////////////////////////
738     // MET & MET corrections
739     // MET=MET-sum_p(muons)-sum_p(muons calos depositions)
740    
741     reco::Particle::LorentzVector WZAnalyzer::computeMET(const edm::Event& iEvent, const edm::EventSetup& iSetup, Handle<reco::CandidateCollection> MuonCands) {
742 senka 1.9
743     using namespace edm;
744     using namespace reco;
745     using namespace std;
746    
747     Handle<CaloMETCollection> mets;
748     iEvent.getByLabel("met", mets);
749 vuko 1.25 // cout << "# METs=" << mets->size() << endl;
750    
751     if (mets->size() != 1) {
752     cout << "ALARM: # METS is not 1: !" << endl;
753     return reco::Particle::LorentzVector(0.,0.,0.,0.);
754     }
755    
756 vuko 1.14 for (CaloMETCollection::const_iterator met = mets->begin();
757     met!= mets->end(); met++) {
758 vuko 1.25 // cout << "MET: E = " << met->energy()
759     // << "\t Pt = " << met->pt()
760     // <<endl;
761 vuko 1.14 }
762 senka 1.28
763     // sum of p of muons
764     reco::Particle::LorentzVector Muon_p(0,0,0,0); // sum of muons 4-vectors
765     reco::Particle::LorentzVector Muon_p_4v(0,0,0,0); // sum of muons 4-vectors in (px,py,0,Et), since MET looks like that
766     double px=0;
767     double py=0;
768     double pz=0;
769     double Et=0;
770    
771     for (unsigned int i=0; i<MuonCands->size();i++){
772     Muon_p=Muon_p+(*MuonCands)[i].p4();
773     px=(*MuonCands)[i].px();
774     py=(*MuonCands)[i].py();
775     pz=(*MuonCands)[i].pz();
776     Et=(*MuonCands)[i].et();
777     Muon_p_4v=Muon_p_4v+reco::Particle::LorentzVector(px,py,0,Et);
778     }
779     // cout<< "####### sum Muon_p="<< Muon_p<<endl;
780     // cout<< "####### sum Muon_p correct="<< Muon_p_4v<<endl;
781     // sum of p of muons left in calorimeters
782     reco::Particle::LorentzVector Muon_p_cal(0,0,0,0); // sum of muons depositions 4-vectors
783     reco::Particle::LorentzVector Muon_p_cal_4v(0,0,0,0); // sum of muons depositions 4-vectors in (px,py,0,Et), since MET looks like that
784     edm::Handle<reco::MuIsoDepositAssociationMap> ecalIso;
785     iEvent.getByLabel("muGlobalIsoDepositCalByAssociatorTowers","ecal", ecalIso);
786     edm::Handle<reco::MuIsoDepositAssociationMap> hcalIso;
787     iEvent.getByLabel("muGlobalIsoDepositCalByAssociatorTowers","hcal", hcalIso);
788     edm::Handle<reco::MuIsoDepositAssociationMap> hocalIso;
789     iEvent.getByLabel("muGlobalIsoDepositCalByAssociatorTowers","ho", hocalIso);
790    
791     float Et_ecal;
792     float Et_hcal;
793     float Et_ho;
794     double eta_ecal;
795     double eta_hcal;
796     double eta_ho;
797     double phi_ecal;
798     double phi_hcal;
799     double phi_ho;
800     double tg_theta_pola_ecal;
801     double tg_theta_pola_hcal;
802     double tg_theta_pola_ho;
803     double tg_theta_ecal;
804     double tg_theta_hcal;
805     double tg_theta_ho;
806     double E_ecal;
807     double E_hcal;
808     double E_ho;
809     double me=0.0005;
810     double sin_theta_ecal, sin_theta_hcal, sin_theta_ho, cos_theta_ecal,cos_theta_hcal,cos_theta_ho;
811     double p_ecal, p_hcal,p_ho, pt_ecal,pt_hcal,pt_ho, px_ecal,px_hcal,px_ho, py_ecal,py_hcal,py_ho, pz_ecal,pz_hcal,pz_ho;
812    
813     for (unsigned int i=0; i<MuonCands->size();i++){
814     Et_ecal=-2.;
815     Et_hcal=-2.;
816     Et_ho=-2.;
817     eta_ecal=-2.;
818     eta_hcal=-2.;
819     eta_ho=-2.;
820     phi_ecal=-2.;
821     phi_hcal=-2.;
822     phi_ho=-2.;
823     const reco::Muon* muons=dynamic_cast<const reco::Muon *> (&(*MuonCands)[i]);
824     const reco::MuIsoDeposit& depEcal = (*ecalIso)[muons->combinedMuon()];
825     const reco::MuIsoDeposit& depHcal = (*hcalIso)[muons->combinedMuon()];
826     const reco::MuIsoDeposit& depHOcal = (*hocalIso)[muons->combinedMuon()];
827     Et_ecal=depEcal.muonEnergy();
828     Et_hcal=depHcal.muonEnergy();
829     Et_ho=depHOcal.muonEnergy();
830     eta_ecal=depEcal.eta();
831     eta_hcal=depHcal.eta();
832     eta_ho=depHOcal.eta();
833     phi_ecal=depEcal.phi();
834     phi_hcal=depHcal.phi();
835     phi_ho=depHOcal.phi();
836     tg_theta_pola_ecal=TMath::Exp(-eta_ecal);
837     tg_theta_pola_hcal=TMath::Exp(-eta_hcal);
838     tg_theta_pola_ho=TMath::Exp(-eta_ho);
839     tg_theta_ecal=2*tg_theta_pola_ecal/(1-tg_theta_pola_ecal*tg_theta_pola_ecal);
840     tg_theta_hcal=2*tg_theta_pola_hcal/(1-tg_theta_pola_hcal*tg_theta_pola_hcal);
841     tg_theta_ho=2*tg_theta_pola_ho/(1-tg_theta_pola_ho*tg_theta_pola_ho);
842     E_ecal=TMath::Abs(Et_ecal*TMath::Sqrt(1+tg_theta_ecal*tg_theta_ecal)/tg_theta_ecal);
843     E_hcal=TMath::Abs(Et_hcal*TMath::Sqrt(1+tg_theta_hcal*tg_theta_hcal)/tg_theta_hcal);
844     E_ho=TMath::Abs(Et_ho*TMath::Sqrt(1+tg_theta_ho*tg_theta_ho)/tg_theta_ho);
845     sin_theta_ecal=tg_theta_ecal/TMath::Sqrt(1+tg_theta_ecal*tg_theta_ecal);
846     sin_theta_hcal=tg_theta_hcal/TMath::Sqrt(1+tg_theta_hcal*tg_theta_hcal);
847     sin_theta_ho=tg_theta_ho/TMath::Sqrt(1+tg_theta_ho*tg_theta_ho);
848     cos_theta_ecal=TMath::Sqrt(1-sin_theta_ecal*sin_theta_ecal);
849     cos_theta_hcal=TMath::Sqrt(1-sin_theta_hcal*sin_theta_hcal);
850     cos_theta_ho=TMath::Sqrt(1-sin_theta_ho*sin_theta_ho);
851     if (E_ecal<me){
852     p_ecal=0;
853     }
854     else {
855     p_ecal=TMath::Sqrt(E_ecal*E_ecal-me*me);
856     }
857     if (E_hcal<me){
858     p_hcal=0;
859     }
860     else {
861     p_hcal=TMath::Sqrt(E_hcal*E_hcal-me*me);
862     }
863     if (E_ho<me){
864     p_ho=0;
865     }
866     else {
867     p_ho=TMath::Sqrt(E_ho*E_ho-me*me);
868     }
869    
870     pz_ecal=p_ecal*cos_theta_ecal;
871     pz_hcal=p_hcal*cos_theta_hcal;
872     pz_ho=p_ho*cos_theta_ho;
873     pt_ecal=TMath::Abs(p_ecal*sin_theta_ecal);
874     pt_hcal=TMath::Abs(p_hcal*sin_theta_hcal);
875     pt_ho=TMath::Abs(p_ho*sin_theta_ho);
876     px_ecal=pt_ecal*TMath::Cos(phi_ecal);
877     px_hcal=pt_hcal*TMath::Cos(phi_hcal);
878     px_ho=pt_ho*TMath::Cos(phi_ho);
879     py_ecal=pt_ecal*TMath::Sin(phi_ecal);
880     py_hcal=pt_hcal*TMath::Sin(phi_hcal);
881     py_ho=pt_ho*TMath::Sin(phi_ho);
882    
883     Muon_p_cal=Muon_p_cal + reco::Particle::LorentzVector(px_ecal+px_hcal+px_ho,py_ecal+py_hcal+py_ho,pz_ecal+pz_hcal+pz_ho,E_ecal+E_hcal+E_ho);
884     Muon_p_cal_4v=Muon_p_cal_4v + reco::Particle::LorentzVector(px_ecal+px_hcal+px_ho,py_ecal+py_hcal+py_ho,0,Et_ecal+Et_hcal+Et_ho);
885     }
886    
887     reco::Particle::LorentzVector MET=mets->begin()->p4()-Muon_p_4v-Muon_p_cal_4v; // substract p from muons and p of calo muon deposit from MET
888     // cout <<" MET no corrections"<<mets->begin()->p4() << endl;
889     // cout <<" MET with corrections"<< MET << endl;
890    
891     return MET;
892 senka 1.9
893     }
894    
895 senka 1.12 ////////////////////////
896     // matching
897     //
898    
899     class MatchingInfo {
900     public:
901    
902     MatchingInfo(float dr, int gen, int reco) : deltaR(dr), genMuon(gen),recoMuon(reco) {}
903    
904     bool operator<(const MatchingInfo m) { return deltaR < m.deltaR;}
905    
906     float deltaR;
907     int genMuon;
908     int recoMuon;
909    
910     };
911    
912    
913     bool betterMatch(MatchingInfo m1, MatchingInfo m2)
914     { return m1.deltaR < m2.deltaR;}
915    
916    
917     // method that gives the vector<MatchingInfo> matching_Infos containing (dR,i,j); i=genParticle index, j=ParticleCollection index:
918    
919     void WZAnalyzer::matching(const edm::Event& iEvent, Handle<reco::CandidateCollection> cands, int pdgid){
920    
921     using namespace edm;
922     using namespace reco;
923     using namespace std;
924    
925     //-------------------------
926     Handle<CandidateCollection> mccands;
927     iEvent.getByLabel( theMCTruthCollection,mccands );
928    
929     vector <GenParticleCandidate*> genparticles;
930    
931     for(CandidateCollection::const_iterator p = mccands->begin();
932     p != mccands->end(); p++) {
933    
934     // reco::Candidate* p_tmp = &(*p);
935     reco::GenParticleCandidate* ptr = (reco::GenParticleCandidate*) &(*p);
936    
937     if ( (ptr)->status() == 1
938     /*&& (ptr)->momentum().perp() > 2.*/ ) { // stable particles with pt>2 only
939     if ( abs((ptr)->pdgId()) == pdgid ) {
940     genparticles.push_back((ptr));
941     //cout << "electron MCT\n";
942     }
943     }
944     }
945    
946    
947     int n1=0;
948     vector<MatchingInfo> matching_Infos;
949     for ( unsigned int i=0; i<genparticles.size(); i++ ) // po svim MC muonima
950     {
951    
952     for (unsigned int j = 0; j < cands->size(); j++)// po svim reco muonima
953     {
954    
955     double d_eta2=(*cands)[j].eta()-(genparticles)[i]->eta();
956     double d_phi=fabs((*cands)[j].phi()-(genparticles)[i]->phi());
957     double dR_byhand= sqrt(d_eta2*d_eta2+d_phi*d_phi);
958     double dR=dR_byhand;
959    
960     if (dR<0.15){
961     n1++;
962     matching_Infos.push_back(MatchingInfo(dR,i,j));
963     }
964    
965     }
966     }
967 senka 1.24
968 senka 1.12 sort(matching_Infos.begin(),matching_Infos.end(),betterMatch); // sorting (dR,i,j)
969 senka 1.24
970     if (genparticles.size()!=0 && cands->size()!=0){
971     // Now exclude combinations using same gen or rec muons
972     for (std::vector<MatchingInfo>::iterator it=matching_Infos.begin();
973     it != matching_Infos.end(); it++) {
974     for (std::vector<MatchingInfo>::iterator it2=matching_Infos.begin();
975     it2!=it; it2++) {
976     if ( (it->genMuon == it2->genMuon) || (it->recoMuon == it2->recoMuon) ) {
977     matching_Infos.erase(it);
978     it=matching_Infos.begin();
979     break;
980     }
981     }
982     }
983     }
984    
985 vuko 1.14 // Now put result in vector of pairs
986    
987     leptonMatching[pdgid].clear();
988    
989     for (vector<MatchingInfo>::iterator match=matching_Infos.begin();
990 senka 1.16 match !=matching_Infos.end(); match++) { // po tablici dr,i,j
991 vuko 1.14
992     pair<const GenParticleCandidate*, const reco::Candidate *> pair;
993 senka 1.16 // vector<pair,float > matchedParticles;
994 vuko 1.14 pair.first = genparticles[match->genMuon];
995     pair.second = & (*cands)[match->recoMuon];
996 senka 1.16
997     matchedParticles cestice(genparticles[match->genMuon] ,& (*cands)[match->recoMuon] , match->deltaR);
998    
999     leptonMatching[pdgid].push_back(cestice);
1000 senka 1.24
1001 vuko 1.14 }
1002 senka 1.24
1003 senka 1.12 }
1004    
1005 senka 1.9
1006 senka 1.13 // get mother of particle
1007     // returns mother = 1 if mother is Z boson
1008     // returns mother = 2 if mother is W boson
1009     // returns mother = 4 if mother is b
1010     // returns mother = 0 else
1011    
1012 vuko 1.14 WZAnalyzer::LeptonOrigin WZAnalyzer::getMother(const reco::Candidate* genParticle){
1013    
1014     int pdg_id=genParticle->pdgId();
1015 vuko 1.25 // cout << "particle id : " << pdg_id << endl;
1016 senka 1.13
1017     while (genParticle = genParticle->mother() ) { //izvrsava se sve dok ne dodje do nule tj. dok ne trazi majku od protona
1018 vuko 1.25 // cout << "Going up: ";
1019     // cout << "Mother id : " << genParticle->pdgId() << endl;
1020 senka 1.24 if (abs(genParticle->pdgId())!=abs(pdg_id)) {
1021 vuko 1.25 // cout<< " good mother " <<endl;
1022 senka 1.13 if (abs(genParticle->pdgId())==23){ // mother is Z
1023 vuko 1.14 return zboson;
1024 senka 1.13 }
1025     if (abs(genParticle->pdgId())==24) { // mother is W
1026 vuko 1.14 return wboson;
1027 senka 1.13 }
1028     // if (abs(genParticle->pdgId())==23 || abs(genParticle->pdgId())==24) { // mother is W or Z
1029     // WZ_matched=1;
1030     // mother=3;
1031     // }
1032     if ((((abs(genParticle->pdgId()))/100)%10 ==5)||(((abs(genParticle->pdgId()))/1000)%10 ==5 )) { // mother is b
1033 vuko 1.14 return bdecay;
1034 senka 1.13 }
1035 vuko 1.14 if ((((abs(genParticle->pdgId()))/100)%10 ==4)||(((abs(genParticle->pdgId()))/1000)%10 ==4 )) { // mother is c
1036     return cdecay;
1037     }
1038     return other;
1039 senka 1.13 }
1040 vuko 1.20 }
1041    
1042     return other;
1043 senka 1.13 }
1044    
1045 senka 1.15 const reco::Candidate * WZAnalyzer::MatchedGenParticle(const reco::Candidate * daughter){
1046     ::OverlapChecker overlap;
1047     matched_genParticle=0;
1048 senka 1.16
1049     for (map< int,
1050     std::vector< matchedParticles > > ::iterator iter = leptonMatching.begin();
1051     iter!=leptonMatching.end(); iter++) // entire map
1052     {
1053 vuko 1.20 for (unsigned int j=0; j<iter->second.size(); j++){ // entire vector<class<>>
1054 senka 1.16 const reco::Candidate * nesto=iter->second[j].pair.second;
1055     if (overlap(*nesto,*daughter)){
1056     matched_genParticle=iter->second[j].pair.first;
1057     }
1058     }
1059     }
1060     return matched_genParticle;
1061     }
1062    
1063    
1064     float WZAnalyzer::dR(const reco::Candidate * daughter){
1065 vuko 1.18
1066 senka 1.16 ::OverlapChecker overlap;
1067 vuko 1.18
1068 senka 1.19 float delta_r = -10;
1069 senka 1.15 for (map< int,
1070 senka 1.16 std::vector< matchedParticles > > ::iterator iter = leptonMatching.begin();
1071 senka 1.15 iter!=leptonMatching.end(); iter++) // entire map
1072     {
1073 vuko 1.20 for (unsigned int j=0; j<iter->second.size(); j++){ // entire vector<class<>>
1074 senka 1.16 const reco::Candidate * nesto=iter->second[j].pair.second;
1075 senka 1.15 if (overlap(*nesto,*daughter)){
1076 senka 1.16 delta_r=iter->second[j].delta_R;
1077 senka 1.15 }
1078     }
1079     }
1080 senka 1.16 return delta_r;
1081 senka 1.15 }
1082    
1083 vuko 1.11
1084 senka 1.16
1085 vuko 1.10 void WZAnalyzer::collectMCsummary(Handle <reco::CandidateCollection> mccands) {
1086 senka 1.12
1087 vuko 1.11 using namespace reco;
1088    
1089 smorovic 1.8 //collections
1090 senka 1.24
1091 smorovic 1.8 MCleptZ1_pdgid = -1;
1092     MCleptZ2_pdgid = -1;
1093     MCleptW_pdgid = -1;
1094    
1095     MCleptZ1_pt = -1;
1096     MCleptZ2_pt = -1;
1097     MCleptW_pt = -1;
1098    
1099     MCleptZ1_eta = -1;
1100     MCleptZ2_eta = -1;
1101     MCleptW_eta = -1;
1102    
1103     MCleptZ1_phi = -1;
1104     MCleptZ2_phi = -1;
1105     MCleptW_phi = -1;
1106 senka 1.12
1107 smorovic 1.8 vector<reco::GenParticleCandidate*> Tau;
1108     vector<reco::GenParticleCandidate*> StableMuons;
1109     vector<reco::GenParticleCandidate*> StableElectrons;
1110 senka 1.24
1111 vuko 1.11 for(CandidateCollection::const_iterator p = mccands->begin();
1112     p != mccands->end(); p++) {
1113 vuko 1.1
1114 vuko 1.11 // reco::Candidate* p_tmp = &(*p);
1115     reco::GenParticleCandidate* ptr = (reco::GenParticleCandidate*) &(*p);
1116 smorovic 1.8
1117     if ( (ptr)->status() == 1
1118     /*&& (ptr)->momentum().perp() > 2.*/ ) { // stable particles with pt>2 only
1119     if ( abs((ptr)->pdgId()) == 11 ) {
1120 senka 1.12
1121 smorovic 1.8 StableElectrons.push_back((ptr));
1122     //cout << "electron MCT\n";
1123     }
1124     else if ( abs((ptr)->pdgId()) == 13 ) {
1125 senka 1.12
1126 smorovic 1.8 StableMuons.push_back((ptr)) ;
1127     //cout << "muon MCT\n";
1128     }
1129     }
1130     else if ((ptr)->status() == 2) {
1131     if ( abs((ptr)->pdgId()) == 15 ) {//tau
1132     Tau.push_back((ptr));
1133     }
1134     }
1135     }
1136 senka 1.12
1137 vuko 1.25 // std::cout << "# Electrons : " << StableElectrons.size()
1138     // << "# Muons : " << StableMuons.size() << std::endl
1139     // << "# Tau : " << Tau.size() << std::endl;
1140 senka 1.12
1141 smorovic 1.8
1142     vector<reco::GenParticleCandidate*> * StableLeptons[3] = {&StableElectrons, &StableMuons, &Tau};
1143    
1144     bool firstZlept = true;
1145     MC_tauDecayTypeZ1 = 0;
1146     MC_tauDecayTypeZ2 = 0;
1147     MC_tauDecayTypeW = 0;
1148    
1149    
1150     for (int i=2; i>=0; i--) {
1151     while (StableLeptons[i]->size() > 0) {
1152     float maxPt = 0;
1153     vector<reco::GenParticleCandidate*>::iterator index = StableLeptons[i]->end();
1154    
1155     for ( vector<reco::GenParticleCandidate*>::iterator lepton = StableLeptons[i]->begin();
1156     lepton != StableLeptons[i]->end(); lepton++ ) {
1157    
1158     if ((*lepton)->pt() > maxPt) {
1159     maxPt = (*lepton)->pt();
1160     index = lepton;
1161     }
1162     }
1163     int parentItr=0;
1164     bool Zchild = false;
1165     bool Wchild = false;
1166     bool Tauchild = false;
1167    
1168     reco::GenParticleCandidate* mcParticleRef = *index;
1169    
1170     //find W/Z mother
1171     while ( mcParticleRef->mother()!=0) {
1172    
1173     if (parentItr>=2) break;
1174     parentItr++;
1175     mcParticleRef = (reco::GenParticleCandidate*) mcParticleRef->mother();
1176     if (mcParticleRef->mother()==0) break;
1177    
1178     //if tau
1179     if (abs((mcParticleRef)->pdgId())==15 ) {
1180     Tauchild=true;
1181     break;
1182     }
1183    
1184     if (abs((mcParticleRef)->pdgId())==23 ) {
1185     Zchild=true;
1186     break;
1187     }
1188     if (abs((mcParticleRef)->pdgId())==24 ) {
1189     Wchild=true;
1190     break;
1191     }
1192     }
1193    
1194     if (maxPt >0) {
1195     if (Tauchild) {
1196     parentItr = 0;
1197     while (mcParticleRef->mother()!=0) {
1198     if (parentItr>=2) break;
1199     parentItr++;
1200     mcParticleRef = (reco::GenParticleCandidate*) mcParticleRef->mother();
1201     if (mcParticleRef->mother()==0) break;
1202    
1203     if (abs((mcParticleRef)->pdgId())==23 ) {
1204     if (MCleptZ1_pt == float(mcParticleRef->pt())
1205     && MCleptZ1_eta == float(mcParticleRef->eta())
1206     && MCleptZ1_phi == float(mcParticleRef->phi()) )
1207     MC_tauDecayTypeZ1 = i;
1208     else MC_tauDecayTypeZ2 = i;
1209     break;
1210     }
1211     if (abs((mcParticleRef)->pdgId())==24 ) {
1212     MC_tauDecayTypeW = i;
1213     break;
1214     }
1215     }
1216     }
1217    
1218     if (Wchild) {
1219     MCleptW_pdgid=(*index)->pdgId();
1220     MCleptW_pt=(float)(*index)->pt();
1221     MCleptW_eta=(float)(*index)->eta();
1222     MCleptW_phi=(float)(*index)->phi();
1223     if (abs(MCleptW_pdgid)==15) MC_tauDecayTypeW =3;//default to hadronic decay
1224     }
1225     if (Zchild) {
1226     if (firstZlept) {
1227     firstZlept=false;
1228     MCleptZ1_pdgid=(*index)->pdgId();
1229     MCleptZ1_pt=(float)(*index)->pt();
1230     MCleptZ1_eta=(float)(*index)->eta();
1231     MCleptZ1_phi=(float)(*index)->phi();
1232     if (abs(MCleptZ1_pdgid)==15) MC_tauDecayTypeZ1 =3;
1233     }
1234     else {
1235     MCleptZ2_pdgid=(*index)->pdgId();
1236     MCleptZ2_pt=(float)(*index)->pt();
1237     MCleptZ2_eta=(float)(*index)->eta();
1238     MCleptZ2_phi=(float)(*index)->phi();
1239     if (abs(MCleptZ2_pdgid)==15) MC_tauDecayTypeZ2 =3;
1240     }
1241     }
1242     StableLeptons[i]->erase(index);
1243     }
1244     }
1245     }
1246 vuko 1.25 // std::cout << "# Electrons end: " << StableElectrons.size()
1247     // << "# Muons end: " << StableMuons.size() << std::endl
1248     // << "# Tau end: " << Tau.size() << std::endl;
1249 vuko 1.1
1250 smorovic 1.8 }
1251 vuko 1.1 //define this as a plug-in
1252 vuko 1.2 // DEFINE_FWK_MODULE(WZAnalyzer);