ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Vuko/WZAnalysis/src/WZAnalyzer.cc
Revision: 1.36
Committed: Fri Feb 1 15:07:23 2008 UTC (17 years, 3 months ago) by smorovic
Content type: text/plain
Branch: MAIN
CVS Tags: srecko_1_02_08
Changes since 1.35: +7 -1 lines
Log Message:
add alpgen ID

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