ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Vuko/WZAnalysis/src/WZAnalyzer.cc
Revision: 1.56
Committed: Wed Apr 23 14:23:27 2008 UTC (17 years ago) by beaucero
Content type: text/plain
Branch: MAIN
CVS Tags: SB_23Apr08
Changes since 1.55: +42 -156 lines
Log Message:
Add Transverse Mass Calculation + DeltaPhi

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 beaucero 1.56 // $Id: WZAnalyzer.cc,v 1.55 2008/04/22 22:14:59 kkaadze 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 kkaadze 1.55 #include "Vuko/WZAnalysis/interface/AnglesUtil.h"
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 smorovic 1.52 //#include "TVector3.h"
61 vuko 1.1
62     #include <map>
63    
64     //
65     // constants, enums and typedefs
66     //
67    
68     //
69     // static data member definitions
70     //
71    
72     //
73     // constructors and destructor
74     //
75     WZAnalyzer::WZAnalyzer(const edm::ParameterSet& iConfig)
76    
77     {
78     //now do what ever initialization is needed
79    
80 senka 1.16 fOutputFileName = iConfig.getUntrackedParameter<string>("HistOutFile");
81 vuko 1.10 theMCTruthCollection = iConfig.getParameter<edm::InputTag>("genParticles");
82    
83 senka 1.12 // theMCTruthCollection = iConfig.getParameter<edm::InputTag>("genParticleCollection");
84    
85 vuko 1.1 theLooseMuonCollection = iConfig.getParameter<edm::InputTag>("LooseMuons");
86     theGoodMuonCollection = iConfig.getParameter<edm::InputTag>("GoodMuons");
87     theLooseElectronCollection = iConfig.getParameter<edm::InputTag>("LooseElectrons");
88 beaucero 1.56 theAllElectronCollection = iConfig.getParameter<edm::InputTag>("AllElectrons");
89 vuko 1.1 theTightLeptonCollection = iConfig.getParameter<edm::InputTag>("TightLeptons");
90     // theMediumElectronCollection = iConfig.getParameter<edm::InputTag>("LooseElectrons");
91     // theTightElectronCollection = iConfig.getParameter<edm::InputTag>("TightElectrons");
92     // Z's
93     theZeeCollection = iConfig.getParameter<edm::InputTag>("ZtoEE");
94     theZmumuCollection = iConfig.getParameter<edm::InputTag>("ZtoMuMu");
95 vuko 1.3 theZllCollection = iConfig.getParameter<edm::InputTag>("ZtoLL");
96 vuko 1.10
97     theJetCollection = iConfig.getParameter<edm::InputTag>("Jets");
98 vuko 1.26
99     theWeightCollection = iConfig.getParameter<edm::InputTag>("EventWeight");
100 smorovic 1.38 alpgenIDTag = iConfig.getParameter<edm::InputTag>("AlpgenIDTag");
101    
102 smorovic 1.39 getAlpgenID = false;
103     getAlpgenID = iConfig.getParameter<bool>("getAlpgenID");
104    
105 smorovic 1.6 storeHLTresults=false;
106     storeHLTresults = iConfig.getParameter<bool>("storeHLTresults");
107 vuko 1.1
108 vuko 1.26 getEventWeight = false;
109     getEventWeight = iConfig.getParameter<bool>("getEventWeight");
110    
111 smorovic 1.23 triggerResultsTag = iConfig.getParameter<edm::InputTag>("TriggerResults");
112 smorovic 1.6 firstTriggerResult = true;
113 smorovic 1.52
114     findBackJets = false;
115     findBackJets = iConfig.getParameter<bool>("findBackJets");
116 vuko 1.1 }
117    
118    
119     WZAnalyzer::~WZAnalyzer()
120     {
121    
122     // do anything here that needs to be done at desctruction time
123     // (e.g. close files, deallocate resources etc.)
124    
125     }
126    
127    
128     //
129     // member functions
130     //
131    
132     // ------------ method called to for each event ------------
133     void
134     WZAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
135     {
136     using namespace edm;
137     using namespace reco;
138     using namespace std;
139    
140 vuko 1.11 ///////////////////////////////////////
141     //
142     /// EVENT INITIALISATION
143     ///
144    
145 smorovic 1.41 //read run number and event ID number
146     RunNumber = iEvent.id().run();
147     EventID = iEvent.id().event();
148    
149 vuko 1.11 // Reset a few things
150     for (map<string,wzana::LeptonProperties* >::iterator iter = leptonProperties.begin();
151     iter!=leptonProperties.end(); iter++)
152     {
153     iter->second->ResetValues();
154     }
155    
156    
157 vuko 1.1 const Candidate * theZCandidate = 0;
158     const Candidate * theWlepton = 0;
159    
160 vuko 1.11
161     ////////////////////////////////////////
162     // Get lists
163    
164 vuko 1.1 // Z->mumu
165     Handle<CandidateCollection> zmumuCands;
166     iEvent.getByLabel( theZmumuCollection , zmumuCands);
167    
168    
169     // Z->ee
170     Handle<CandidateCollection> zeeCands;
171     iEvent.getByLabel( theZeeCollection , zeeCands);
172    
173 vuko 1.3 // Z->ee
174     Handle<CandidateCollection> zllCands;
175     iEvent.getByLabel( theZllCollection , zllCands);
176    
177 vuko 1.1 // loose electrons
178     Handle<CandidateCollection> looseElectronCands;
179     iEvent.getByLabel( theLooseElectronCollection , looseElectronCands);
180    
181 beaucero 1.56 // All electrons
182     Handle<CandidateCollection> allElectronCands;
183     iEvent.getByLabel( theAllElectronCollection , allElectronCands);
184 vuko 1.1
185     // loose muons
186     Handle<CandidateCollection> looseMuonCands;
187     iEvent.getByLabel( theLooseMuonCollection , looseMuonCands);
188    
189     // good muons
190     Handle<CandidateCollection> goodMuonCands;
191     iEvent.getByLabel( theGoodMuonCollection , goodMuonCands);
192    
193    
194     // tight leptons
195     Handle<CandidateCollection> tightLeptonCands;
196     iEvent.getByLabel( theTightLeptonCollection , tightLeptonCands);
197    
198 vuko 1.10 // jets
199 vuko 1.14
200     Handle<CaloJetCollection> jetCands;
201 vuko 1.10 iEvent.getByLabel( theJetCollection , jetCands);
202    
203 vuko 1.26
204     // event weights (CSA07 soups...)
205     eventWeight = -1;
206    
207     Handle< double> weightHandle;
208 smorovic 1.31 Handle<int> genProcessID;
209 smorovic 1.36 Handle<int> alpgenProcessID;
210 smorovic 1.31 Handle<double> genEventScale;
211    
212 vuko 1.26 if (getEventWeight) {
213 smorovic 1.40
214 vuko 1.26 iEvent.getByLabel (theWeightCollection, weightHandle);
215     if (weightHandle.isValid()) {
216     eventWeight = * weightHandle;
217     }
218 smorovic 1.40
219 smorovic 1.31 iEvent.getByLabel( "genEventProcID", genProcessID );
220 smorovic 1.32 if (genProcessID.isValid()) {
221     processID = *genProcessID;
222 smorovic 1.31 }
223 smorovic 1.40
224 smorovic 1.39 if (processID==4 && getAlpgenID) {
225 smorovic 1.38 iEvent.getByLabel( alpgenIDTag , alpgenProcessID );
226     if (alpgenProcessID.isValid()) {
227     alpgenID = *alpgenProcessID;
228     }
229     } else alpgenID=0;
230    
231    
232 smorovic 1.31 iEvent.getByLabel( "genEventScale", genEventScale );
233 smorovic 1.32 if (genEventScale.isValid()) {
234     eventScale = *genEventScale;
235 smorovic 1.31 }
236 vuko 1.26 }
237 beaucero 1.42
238    
239 smorovic 1.6 // get hold of TriggerResults
240 senka 1.27 Handle<TriggerResults> HLTR; //moja promjena: ovo prebaceno 2 reda nize!
241 senka 1.44 if (storeHLTresults) {
242     // Handle<TriggerResults> HLTR;
243     iEvent.getByLabel(triggerResultsTag,HLTR);
244     if (firstTriggerResult) {
245     firstTriggerResult = false;
246     trigNames.init((edm::TriggerResults&)*HLTR);
247     numTriggers = trigNames.size();
248     }
249     }
250    
251 smorovic 1.6
252 senka 1.44 // MET corrected (P_muons, P_muons_calo_deposit)
253    
254     reco::Particle::LorentzVector MET=computeMET(iEvent, iSetup, looseMuonCands);
255     // MET_energy=MET.energy();
256     MET_energy=MET.energy(); // this is Et!!
257     MET_pt=MET.pt();
258     MET_px=MET.px();
259     MET_py=MET.py();
260     MET_eta=MET.eta();
261 vuko 1.50 MET_phi=MET.phi();
262 senka 1.44
263 kkaadze 1.55 //Correct MET due to electron energy scale corrections
264     reco::Particle::LorentzVector MET_SCCorr = correctMETforSCCorrection(MET, looseElectronCands);
265     MET_Et_SCCorr = MET_SCCorr.energy();
266     MET_pt_SCCorr = MET_SCCorr.pt();
267     MET_phi_SCCorr = MET_SCCorr.phi();
268    
269     reco::Particle::LorentzVector MET_ElCorr = correctMETforElCorrection(MET, looseElectronCands);
270     MET_Et_ElCorr = MET_ElCorr.energy();
271     MET_pt_ElCorr = MET_ElCorr.pt();
272     MET_phi_ElCorr = MET_ElCorr.phi();
273    
274 senka 1.28
275     // selected muons
276 vuko 1.1
277 beaucero 1.35 // cout << "\t # loose mu : " << looseMuonCands->size()
278     // << "\t # tight mu : " << goodMuonCands->size()
279     // << "\t # loose e : " << looseElectronCands->size()
280 beaucero 1.56 // << "\t # tight e : " << allElectronCands->size()
281 beaucero 1.35 // << "\t # tight l : " << tightLeptonCands->size()
282     // << "\t # Z->mumu : " << zmumuCands->size()
283     // << "\t # Z->ee : " << zeeCands->size()
284     // << "\t # Z->ll : " << zllCands->size()
285     // << endl;
286 vuko 1.1
287 senka 1.27 N_looseMuons=0;
288     N_looseElectrons=0;
289     N_looseMuons = looseMuonCands->size();
290     N_looseElectrons = looseElectronCands->size();
291 vuko 1.49 NCaloJets = jetCands->size();
292 senka 1.27
293    
294 vuko 1.1 //
295 vuko 1.7 // Find best Z (in Z->ll collection (merged Z->ee & Z->mumu)
296 vuko 1.1 //
297     ::OverlapChecker overlap;
298    
299 vuko 1.3
300     float dzmass_min = 100.;
301    
302 senka 1.27 n=1; // number of non overlaping Zs
303 vuko 1.3 for(CandidateCollection::const_iterator z1 = zllCands->begin();
304     z1 != zllCands->end(); ++ z1 ) {
305 vuko 1.21
306     // Check that two leptons used to build the Z are not overlapping
307     if (overlap(*(z1->daughter(0)),*(z1->daughter(1))) ) {
308 smorovic 1.32 continue;
309 vuko 1.21 }
310    
311 vuko 1.3 float dzmass = fabs( z1->mass() - 91.188);
312     if (dzmass < dzmass_min) {
313 vuko 1.7 theZCandidate = &(*z1);
314 vuko 1.3 dzmass_min = dzmass;
315     }
316     //
317     //Get back Electrons from Z and W
318     for(CandidateCollection::const_iterator z2 = z1;
319     z2 != zllCands->end(); ++ z2 ) {
320     if (z1 != z2) {
321     if (overlap(*z1,*z2)) {
322     } else {
323 senka 1.27 n++;
324 vuko 1.3 }
325     }
326     }
327     }
328    
329    
330 vuko 1.1 zFlavour = 0;
331     wlFlavour = 0;
332 beaucero 1.35 zMass = -10;
333     zPt = -10;
334     zEta = -10;
335     zPhi = -10;
336 vuko 1.50 nWlElCand = 0;
337     nWlMuCand = 0;
338 vuko 1.1
339 senka 1.9 dPhi_WlZ_reco=-15.;
340     dPhi_WZ_reco=-15.;
341 kkaadze 1.55
342     dPhi_Wl_MET = -15.;
343     dPhi_Wl_MET_SCCorr = -15.;
344     dPhi_Wl_MET_ElCorr = -15.;
345 beaucero 1.56 wlCharge =-10;
346     wlEta = -10;
347     wlPhi = -10;
348     wlTransMass = -10;
349     wlTransMass_SCCorr = -10;
350     wlTransMass_ElCorr = -10;
351    
352 senka 1.15 //---------------
353     // matching(iEvent,looseMuonCands, 13);
354     // matching(iEvent,looseElectronCands, 11);
355     // MatchedGenParticle(&(*looseMuonCands)[0]);
356     //-------------------
357    
358 vuko 1.1 int nwl_candidates=0;
359     if (theZCandidate) {
360    
361    
362     zMass = theZCandidate->mass();
363     zFlavour = abs(theZCandidate->daughter(0)->pdgId());
364     zPt = theZCandidate->pt();
365     zEta = theZCandidate->eta();
366     zPhi = theZCandidate->phi();
367    
368 vuko 1.18 // Sanity check: can we identify the Z daughters with leptons from the loose lists
369    
370     Handle<CandidateCollection> looseLeptonCands;
371     if (zFlavour == 11) {
372     looseLeptonCands = looseElectronCands;
373     } else if (zFlavour == 13) {
374     looseLeptonCands = looseMuonCands;
375     }
376     for (int i=0; i<2; i++) {
377     int noverlaps=0;
378     for(CandidateCollection::const_iterator l = looseLeptonCands->begin();
379     l != looseLeptonCands->end(); l++) {
380     if (overlap(*(theZCandidate->daughter(i)), *l) ) {
381     noverlaps++;
382     }
383     }
384     }
385    
386 senka 1.15 matching(iEvent,looseMuonCands, 13);
387     matching(iEvent,looseElectronCands, 11);
388    
389 vuko 1.4 if (zFlavour == 11) {
390 senka 1.17 //--------------
391 vuko 1.18 leptonProperties["ZEl1"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
392     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
393     leptonProperties["ZEl2"]->FillProperties(theZCandidate->daughter(1), iEvent, iSetup,
394     MatchedGenParticle(theZCandidate->daughter(1)),dR(theZCandidate->daughter(1)));
395 senka 1.17 } else if (zFlavour == 13) {
396     //--------------
397 senka 1.19 const reco::Candidate * mcpart = MatchedGenParticle(theZCandidate->daughter(0));
398 senka 1.17 //--------------
399 vuko 1.18 leptonProperties["Zmu1"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
400     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
401 vuko 1.53 leptonProperties["Zmul"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
402     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
403 vuko 1.18 leptonProperties["Zmu2"]->FillProperties(theZCandidate->daughter(1), iEvent, iSetup,
404     MatchedGenParticle(theZCandidate->daughter(1)),dR(theZCandidate->daughter(1)));
405 senka 1.15
406 vuko 1.4 }
407    
408 vuko 1.1 float max_pt = 0.;
409    
410 senka 1.9 /// Find W lepton
411    
412 vuko 1.1
413     // Now find lepton that will be associated to W
414     // among leptons not used for the Z reconstruction
415     for(CandidateCollection::const_iterator lepton = tightLeptonCands->begin();
416     lepton != tightLeptonCands->end(); lepton++) {
417    
418    
419     if ( overlap(*theZCandidate, *lepton) ) continue; // Ignore if lepton used for the Z
420    
421     nwl_candidates++;
422 vuko 1.50 if (abs(lepton->pdgId()) == 11) {
423     nWlElCand++;
424     } else if (abs(lepton->pdgId()) == 13) {
425     nWlMuCand++;
426     }
427 vuko 1.1
428     // If more than one candidate: choose leading pt
429     if (lepton->pt() > max_pt) {
430     theWlepton = &(*lepton);
431     max_pt = lepton->pt();
432     }
433    
434     if(lepton->hasMasterClone()) {
435 beaucero 1.35 // cout << "SHOUT: TIGHT LEPTON IS SHALLOW COPY !!! (SHOULD NOT BE!) \n";
436 vuko 1.1 }
437     //
438     }
439     if (theWlepton) {
440     wlFlavour = theWlepton->pdgId();
441     wlCharge = theWlepton->charge();
442     wlPt = theWlepton->pt();
443     wlEta = theWlepton->eta();
444     wlPhi = theWlepton->phi();
445 beaucero 1.56 wlTransMass= kinem::TransvMass(theWlepton->pt(),MET.pt(),
446     theWlepton->px(), MET.px(),
447     theWlepton->py(),MET.py());
448 vuko 1.1
449 vuko 1.3 if (abs(wlFlavour) == 11) {
450 senka 1.17 leptonProperties["Wel"]->FillProperties(theWlepton, iEvent, iSetup, MatchedGenParticle(theWlepton),dR(theWlepton));
451 vuko 1.3 } else if (abs(wlFlavour) == 13) {
452 senka 1.17 leptonProperties["Wmu"]->FillProperties(theWlepton, iEvent, iSetup, MatchedGenParticle(theWlepton),dR(theWlepton));
453 vuko 1.3 }
454 senka 1.24
455 beaucero 1.56 dPhi_WlZ_reco=kinem::delta_phi(theWlepton->phi(),theZCandidate->phi());
456     dPhi_WZ_reco=kinem::delta_phi((theWlepton->p4()+MET).phi(),theZCandidate->phi());
457 vuko 1.3
458 kkaadze 1.55 dPhi_Wl_MET = kinem::delta_phi(theWlepton->phi(),MET.phi());
459 beaucero 1.56 dPhi_Wl_MET_SCCorr = kinem::delta_phi(theWlepton->phi(),MET_SCCorr.phi());
460     wlTransMass_SCCorr= kinem::TransvMass(theWlepton->pt(),MET_SCCorr.pt(),
461     theWlepton->px(), MET_SCCorr.px(),
462     theWlepton->py(),MET_SCCorr.py());
463     dPhi_Wl_MET_ElCorr = kinem::delta_phi(theWlepton->phi(),MET_ElCorr.phi());
464     wlTransMass_ElCorr= kinem::TransvMass(theWlepton->pt(),MET_ElCorr.pt(),
465     theWlepton->px(), MET_ElCorr.px(),
466     theWlepton->py(),MET_ElCorr.py());
467 vuko 1.1 }
468 kkaadze 1.55
469 vuko 1.1 }
470 smorovic 1.6
471 vuko 1.10 // Handle <reco::GenParticleCandidateCollection> mccands;
472     Handle<CandidateCollection> mccands;
473     iEvent.getByLabel( theMCTruthCollection,mccands );
474 smorovic 1.6
475 vuko 1.11 collectMCsummary(mccands);
476 smorovic 1.6
477 smorovic 1.8 if (storeHLTresults) {
478    
479 smorovic 1.6 //def: 1:single electron 2:single relaxed 3:double electron 4: double relaxed 5,6,7,8: muon e+mu: 9
480 smorovic 1.8
481 smorovic 1.6 triggerBitmask=0;
482 smorovic 1.52 triggerBitmaskQCD=0;
483 smorovic 1.8
484 smorovic 1.6 for (size_t i=0; i<numTriggers; ++i) {
485    
486     if (!HLTR->wasrun(i)) {
487     continue;
488     }
489     if (HLTR->error(i) ) {
490     continue;
491     }
492     if (HLTR->accept(i)) {
493     //if (triggerNames[i].compare("mcpath")!=0)
494     //TRaccept=true;
495     }else {
496     continue;
497     }
498 smorovic 1.34 if (trigNames.triggerName(i).compare("HLT1Electron")==0) triggerBitmask |= 1;
499     if (trigNames.triggerName(i).compare("HLT1ElectronRelaxed")==0) triggerBitmask |= 2;
500     if (trigNames.triggerName(i).compare("HLT2Electron")==0) triggerBitmask |= 4;
501     if (trigNames.triggerName(i).compare("HLT2ElectronRelaxed")==0) triggerBitmask |= 8;
502    
503     if (trigNames.triggerName(i).compare("HLT1MuonIso")==0) triggerBitmask |= 16;
504     if (trigNames.triggerName(i).compare("HLT1MuonNonIso")==0) triggerBitmask |= 32;
505     if (trigNames.triggerName(i).compare("HLT2MuonNonIso")==0) triggerBitmask |= 64;
506     if (trigNames.triggerName(i).compare("HLT2MuonZ")==0) triggerBitmask |= 128;
507 smorovic 1.6
508 smorovic 1.34 if (trigNames.triggerName(i).compare("HLTXElectronMuon")==0) triggerBitmask |= 256;
509     if (trigNames.triggerName(i).compare("HLTXElectronMuonRelaxed")==0) triggerBitmask |= 512;
510 smorovic 1.47
511     if (trigNames.triggerName(i).compare("CandHLT2MuonIso")==0) triggerBitmask |= 1024;
512 smorovic 1.52
513     //for QCD control sample
514     if (trigNames.triggerName(i).compare("HLT1Jet")==0) triggerBitmaskQCD |= 1;
515     if (trigNames.triggerName(i).compare("HLT2Jet")==0) triggerBitmaskQCD |= 2;
516     if (trigNames.triggerName(i).compare("HLT3Jet")==0) triggerBitmaskQCD |= 4;
517     if (trigNames.triggerName(i).compare("HLT4Jet")==0) triggerBitmaskQCD |= 8;
518     if (trigNames.triggerName(i).compare("HLT2JetAco")==0) triggerBitmaskQCD |= 16;
519     if (trigNames.triggerName(i).compare("HLTXMuonJets")==0) triggerBitmaskQCD |= 32;
520     if (trigNames.triggerName(i).compare("HLT1MET")==0) triggerBitmaskQCD |= 64;
521     if (trigNames.triggerName(i).compare("HLT1Jet1METAco")==0) triggerBitmaskQCD |= 128;
522     if (trigNames.triggerName(i).compare("HLT1Jet1MET")==0) triggerBitmaskQCD |= 256;
523     if (trigNames.triggerName(i).compare("HLT2Jet1MET")==0) triggerBitmaskQCD |= 512;
524     if (trigNames.triggerName(i).compare("HLT3Jet1MET")==0) triggerBitmaskQCD |= 1024;
525     if (trigNames.triggerName(i).compare("HLT4Jet1MET")==0) triggerBitmaskQCD |= 2048;
526     if (trigNames.triggerName(i).compare("HLT1MET1HT")==0) triggerBitmaskQCD |= 4096;
527     if (trigNames.triggerName(i).compare("HLTS2JetAco")==0) triggerBitmaskQCD |= 8192;
528    
529 smorovic 1.6 }
530     }
531 vuko 1.10
532     // Jet properties
533    
534     float max_et = 0.;
535 vuko 1.14 float max2_et = 0.;
536     const Candidate * leadingJet = 0;
537     const Candidate * secondJet = 0;
538 smorovic 1.29
539     bool matchedLept[3]={false,false,false};
540    
541 vuko 1.14 // for(CandidateCollection::const_iterator jet = jetCands->begin();
542 smorovic 1.41 NbJets = 0;
543 beaucero 1.42 NbJetsWithLeptons = 0;
544 smorovic 1.41
545 vuko 1.14 for(CaloJetCollection::const_iterator jet = jetCands->begin();
546 vuko 1.10 jet != jetCands->end(); jet++) {
547 smorovic 1.29
548     //ignore jets which are within dR 0.15 to a WZ lepton
549     {
550 smorovic 1.52
551     float dPhi[3]={-1.0,-1.0,-1.0};
552     float dEta[3]={-1.0,-1.0,-1.0};
553     bool skipJet=false;
554    
555     for (int ct=0;ct<2;ct++) {
556     if (theZCandidate)
557     if (theZCandidate->daughter(ct)->pt()>0
558 beaucero 1.56 && (abs(theZCandidate->daughter(ct)->pdgId())==13
559     || abs(theZCandidate->daughter(ct)->pdgId())==11) ) {
560     dPhi[ct]=kinem::delta_phi(theZCandidate->daughter(ct)->phi(),jet->phi());
561     dEta[ct]=fabs(theZCandidate->daughter(ct)->eta() - jet->eta());
562 smorovic 1.52 }
563     }
564     if (theWlepton)
565     if (theWlepton->pt()>0 && (abs(theWlepton->pdgId())==13 || abs(theWlepton->pdgId())==11 )) {
566 beaucero 1.56 dPhi[2]=kinem::delta_phi(theWlepton->phi(),jet->phi());
567     dEta[2]=fabs(theWlepton->eta() - jet->eta());
568 smorovic 1.52 }
569     for (int k=0;k<3;k++) {
570 beaucero 1.56 if (matchedLept[k] || dEta[k]<0.0) continue;
571 smorovic 1.29
572     float deltaR=sqrt(dPhi[k]*dPhi[k]+dEta[k]*dEta[k]);
573     if (deltaR<0.15) {
574     skipJet=true;
575     matchedLept[k]=true;
576     break;
577     }
578     }
579 beaucero 1.42 if(jet->pt() > 10 && fabs(jet->eta())<2.5 )NbJetsWithLeptons++;
580 vuko 1.49
581     if (skipJet || fabs(jet->eta()) > 3.) continue;
582    
583 beaucero 1.42 if(jet->pt() > 10 && fabs(jet->eta())<2.5 )NbJets++;
584 smorovic 1.29 }
585    
586 vuko 1.49 if (jet->et() > max_et ) {
587     if (leadingJet) {
588     secondJet = leadingJet;
589     max2_et = max_et;
590     }
591     leadingJet = &(*jet);
592     max_et = jet->et();
593    
594     } else {
595     if (jet->et() > max2_et ) {
596     secondJet = &(*jet);
597     max2_et = jet->et();
598     }
599     }
600 vuko 1.10 }
601 smorovic 1.52
602 vuko 1.10 if (leadingJet) {
603 smorovic 1.52 jet1Et = leadingJet->et();
604     jet1Phi = leadingJet->phi();
605     jet1Eta = leadingJet->eta();
606 vuko 1.10
607     } else {
608 smorovic 1.52 jet1Et = -10;
609     jet1Phi = 0.;
610     jet1Eta = 0.;
611 vuko 1.10 }
612 vuko 1.14 if (secondJet) {
613 smorovic 1.52 jet2Et = secondJet->et();
614     jet2Phi = secondJet->phi();
615     jet2Eta = secondJet->eta();
616 vuko 1.14 } else {
617 smorovic 1.52 jet2Et = -10;
618     jet2Phi = 0.;
619     jet2Eta = 0.;
620 vuko 1.14
621     }
622 senka 1.9
623 senka 1.12 // matching:
624    
625     matching(iEvent,looseMuonCands, 13);
626     matching(iEvent,looseElectronCands, 11);
627    
628 senka 1.13 getMother(&(*mccands)[1]);
629 vuko 1.10
630 smorovic 1.41 numberOfElectronTrees = 0;
631    
632     //count number of electron treee entries which will be added
633     for(CandidateCollection::const_iterator el = looseElectronCands->begin();
634     el != looseElectronCands->end(); ++ el ) {
635 smorovic 1.43 if (el->pt()>10 && fabs(el->eta())<2.5) {
636 smorovic 1.41 numberOfElectronTrees++;
637     }
638     }
639    
640 vuko 1.1 wzTree->Fill();
641    
642 vuko 1.20
643     // Fill electrons in a tree
644     for(CandidateCollection::const_iterator el = looseElectronCands->begin();
645     el != looseElectronCands->end(); ++ el ) {
646    
647     electronUse = 0;
648    
649     if (theZCandidate) {
650    
651     if (overlap(*theZCandidate, *el) ) {
652     electronUse = 23;
653     } else if (theWlepton) {
654     if (overlap(*theWlepton, *el) ) {
655     electronUse = 24;
656     }
657 smorovic 1.41 }
658 vuko 1.20 }
659 beaucero 1.42 if (el->pt()>10 && fabs(el->eta())<2.5) {
660     leptonProperties["electron"]->FillProperties(&(*el),
661     iEvent, iSetup,
662     MatchedGenParticle(&(*el)),dR(&(*el)));
663 smorovic 1.52
664     if (findBackJets) {
665    
666     backJet_found=0;
667     backJet_Et=0;
668     backJet_Eta=0;
669     backJet_Phi=0;
670     backJet_maxEInEmTowers=0;
671     backJet_maxEInHadTowers=0;
672     backJet_energyFractionHadronic=0;
673     backJet_emEnergyFraction=0;
674     backJet_hadEnergyInHB=0;
675     backJet_hadEnergyInHO=0;
676     backJet_hadEnergyInHE=0;
677     backJet_hadEnergyInHF=0;
678     backJet_emEnergyInEB=0;
679     backJet_emEnergyInEE=0;
680     backJet_emEnergyInHF=0;
681     backJet_towersArea=0;
682     backJet_n90=0;
683     backJet_n60=0;
684     backJet_NbTracks = 0;
685     backJet_match=0;
686     backJet_matchPt=0;
687     backJet_match_dR=-1.0;
688    
689     float oldDeltaPhi = -1.0;
690    
691     edm::Handle<reco::TrackCollection> BarrelKFTracks;
692     iEvent.getByLabel("ctfWithMaterialTracks",BarrelKFTracks);
693    
694     for (CaloJetCollection::const_iterator jet = jetCands->begin();
695     jet != jetCands->end(); jet++) {
696    
697     int NbTracksInJets = 0;
698    
699     for( reco::TrackCollection::const_iterator KFT = BarrelKFTracks->begin();KFT !=BarrelKFTracks->end(); ++ KFT ){
700    
701 beaucero 1.56 double DPhi = kinem::delta_phi(KFT->phi(),jet->phi());
702    
703 smorovic 1.52 double dR=sqrt( (KFT->eta() - jet->eta())*(KFT->eta() - jet->eta()) + DPhi*DPhi );
704    
705     if (KFT->pt()>2.0 && dR<0.3) NbTracksInJets++;
706    
707     //cout << "pass track eta:" << KFT->eta() << " pt " << KFT->pt() << " dr " << dR << endl;
708    
709     }
710    
711     if (NbTracksInJets<=3) continue;
712    
713 beaucero 1.56 float dPhi = fabs(kinem::delta_phi(jet->phi(),el->phi()) - kinem::PI);
714 smorovic 1.52
715     if (dPhi<0.7 && (dPhi<oldDeltaPhi || oldDeltaPhi<0.0)) {
716     oldDeltaPhi=dPhi;
717    
718     backJet_found=1;
719     backJet_Et=jet->et();
720     backJet_Eta=jet->eta();
721     backJet_Phi=jet->phi();
722     backJet_maxEInEmTowers=jet->maxEInEmTowers();
723     backJet_maxEInHadTowers=jet->maxEInHadTowers();
724     backJet_energyFractionHadronic=jet->energyFractionHadronic();
725     backJet_emEnergyFraction=jet->emEnergyFraction();
726     backJet_hadEnergyInHB=jet->hadEnergyInHB();
727     backJet_hadEnergyInHO=jet->hadEnergyInHO();
728     backJet_hadEnergyInHE=jet->hadEnergyInHE();
729     backJet_hadEnergyInHF=jet->hadEnergyInHF();
730     backJet_emEnergyInEB=jet->emEnergyInEB();
731     backJet_emEnergyInEE=jet->emEnergyInEE();
732     backJet_emEnergyInHF=jet->emEnergyInHF();
733     backJet_towersArea=jet->towersArea();
734     backJet_n90=jet->n90();
735     backJet_n60=jet->n60();
736     //fill variables
737     backJet_NbTracks = NbTracksInJets;
738    
739    
740     //find monte carlo electrons close to the jet
741    
742     float eDR = -1.0;
743     }
744     }
745     }
746    
747 beaucero 1.42 electronTree->Fill();
748    
749     }
750    
751 vuko 1.20 }
752    
753 smorovic 1.52 EventCounter++;
754 vuko 1.1 }
755    
756    
757     // ------------ method called once each job just before starting event loop ------------
758     void
759     WZAnalyzer::beginJob(const edm::EventSetup&)
760     {
761    
762     using namespace wzana;
763    
764 senka 1.16 // theFile = new TFile( "wz.root", "RECREATE" ) ;
765     theFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
766    
767 vuko 1.1
768     wzTree = new TTree("WZTree","WZ informations");
769    
770 vuko 1.20 electronTree = new TTree("ElTree","electron informations");
771    
772 smorovic 1.52 // jetTree = new TTree("JetTree","jet deltaR information");
773    
774 vuko 1.20 leptonProperties["electron"] = new ElectronProperties();
775 vuko 1.1
776 vuko 1.3 leptonProperties["Wel"] = new ElectronProperties();
777     leptonProperties["ZEl1"] = new ElectronProperties();
778     leptonProperties["ZEl2"] = new ElectronProperties();
779    
780     leptonProperties["Wmu"] = new MuonProperties();
781     leptonProperties["Zmu1"] = new MuonProperties();
782     leptonProperties["Zmu2"] = new MuonProperties();
783 vuko 1.1
784 vuko 1.54 leptonProperties["Zmul"] = new MuonProperties(); // SAME COMMENT AS BELOW: TEMPORARY FIX
785 vuko 1.20
786 vuko 1.3 leptonProperties["Wel"]->CreateBranches(wzTree, "WEl_");
787 vuko 1.4 leptonProperties["ZEl1"]->CreateBranches(wzTree, "ZEl1_");
788     leptonProperties["ZEl2"]->CreateBranches(wzTree, "ZEl2_");
789 vuko 1.1
790 vuko 1.54 leptonProperties["Wmu"]->CreateBranches(wzTree, "Wmu_");
791 vuko 1.53
792 vuko 1.54 leptonProperties["Zmu1"]->CreateBranches(wzTree, "Zmu1_");
793 vuko 1.53 // Vuko's NOTE: there was type in the key "Zmul" instead of "Zmu1"
794     // ("L" instead of "one")
795     // I am fixing it but in order not to break everybody's root scripts
796     // I am adding the next line so we have both until all trees
797     // are contain "Zmu1"
798     // when that is the case, the next line can be dropped
799 vuko 1.54 leptonProperties["Zmul"]->CreateBranches(wzTree, "Zmul_");
800     leptonProperties["Zmu2"]->CreateBranches(wzTree, "Zmu2_");
801     leptonProperties["electron"]->CreateBranches(electronTree);
802 senka 1.9
803 vuko 1.1 initialiseTree();
804 smorovic 1.6
805     //prepare HLT TriggerResults branch
806     if (storeHLTresults) {
807     wzTree->Branch("WZ_hltBitmask",&triggerBitmask,"WZ_hltBitmask/I");
808 smorovic 1.52 wzTree->Branch("QCD_hltBitmask",&triggerBitmaskQCD,"QCD_hltBitmask/I");
809 smorovic 1.6
810     }
811 senka 1.9
812     // MET branch
813 senka 1.44 wzTree->Branch("MET_Et",&MET_energy,"MET_Et/F");
814 senka 1.9 wzTree->Branch("MET_pt",&MET_pt,"MET_pt/F");
815     wzTree->Branch("MET_eta",&MET_eta,"MET_eta/F");
816 vuko 1.50 wzTree->Branch("MET_phi",&MET_phi,"MET_eta/F");
817 senka 1.9 wzTree->Branch("dPhi_WlZ_reco",&dPhi_WlZ_reco,"dPhi_WlZ_reco/F");
818     wzTree->Branch("dPhi_WZ_reco",&dPhi_WZ_reco,"dPhi_WZ_reco/F");
819 kkaadze 1.55 wzTree->Branch("dPhi_Wl_MET",&dPhi_Wl_MET,"dPhi_Wl_MET/F");
820    
821     // MET branch after corrections
822     wzTree->Branch("MET_Et_SCCorr",&MET_Et_SCCorr,"MET_Et_SCCorr/F");
823     wzTree->Branch("MET_pt_SCCorr",&MET_pt_SCCorr,"MET_pt_SCCorr/F");
824     wzTree->Branch("MET_phi_SCCorr",&MET_phi_SCCorr,"MET_phi_SCCorr/F");
825     wzTree->Branch("dPhi_Wl_MET_SCCorr",&dPhi_Wl_MET_SCCorr,"dPhi_Wl_MET_SCCorr/F");
826    
827     wzTree->Branch("MET_Et_ElCorr",&MET_Et_ElCorr,"MET_Et_SCCorr/F");
828     wzTree->Branch("MET_pt_ElCorr",&MET_pt_ElCorr,"MET_pt_SCCorr/F");
829     wzTree->Branch("MET_phi_ElCorr",&MET_phi_ElCorr,"MET_phi_SCCorr/F");
830     wzTree->Branch("dPhi_Wl_MET_ElCorr",&dPhi_Wl_MET_ElCorr,"dPhi_Wl_MET_ElCorr/F");
831    
832 beaucero 1.56 wzTree->Branch("WlTransMass", &wlTransMass, "WlTransMass/F");
833     wzTree->Branch("WlTransMass_SCCorr", &wlTransMass_SCCorr, "WlTransMass_SCCorr/F");
834     wzTree->Branch("WlTransMass_ElCorr", &wlTransMass_ElCorr, "WlTransMass_ElCorr/F");
835    
836 senka 1.27
837     // # of non overlaping Zs
838     wzTree->Branch("N_nonOverlaping_Z",&n,"N_nonOverlaping_Z/I");
839     wzTree->Branch("N_looseMuons",&N_looseMuons,"N_looseMuons/I");
840     wzTree->Branch("N_looseElectrons",&N_looseElectrons,"N_looseElectrons/I");
841    
842 smorovic 1.52
843     EventCounter=0;
844 vuko 1.1 }
845    
846     // ------------ method called once each job just after ending the event loop ------------
847     void
848     WZAnalyzer::endJob() {
849    
850     theFile->Write();
851     theFile->Close();
852    
853     }
854    
855    
856     void WZAnalyzer::initialiseTree() {
857 vuko 1.26 // Event properties
858     wzTree->Branch("weight", &eventWeight, "weight/F");
859 smorovic 1.31 wzTree->Branch("processID", &processID, "processID/I");
860 smorovic 1.36 wzTree->Branch("alpgenID", &alpgenID, "alpgenID/I");
861 smorovic 1.48 wzTree->Branch("genEventScale", &eventScale, "genEventScale/F");
862 smorovic 1.41 wzTree->Branch("RunNumber", &RunNumber, "RunNumber/I");
863     wzTree->Branch("EventID", &EventID, "EventID/I");
864 vuko 1.26
865 vuko 1.1 // Z properties
866     wzTree->Branch("Zmass", &zMass, "Zmass/F");
867     wzTree->Branch("ZId", &zFlavour, "Zid/I");
868     wzTree->Branch("ZPt", &zPt, "ZPt/F");
869     wzTree->Branch("ZEta", &zEta, "ZEta/F");
870     wzTree->Branch("ZPhi", &zPhi, "ZPhi/F");
871    
872     // W Properties
873     wzTree->Branch("WlId", &wlFlavour, "Wlid/I");
874     wzTree->Branch("WlCharge", &wlCharge, "WlCharge/I");
875     wzTree->Branch("WlPt", &wlPt, "WlPt/F");
876 vuko 1.50
877     wzTree->Branch("nwlelcand", &nWlElCand, "nwlelcand/I");
878     wzTree->Branch("nwlmucand", &nWlMuCand, "nwlmucand/I");
879    
880 smorovic 1.8
881     wzTree->Branch("MC_leptonZ1_pt", &MCleptZ1_pt,"MC_leptonZ1_pt/F");
882     wzTree->Branch("MC_leptonZ2_pt", &MCleptZ2_pt,"MC_leptonZ2_pt/F");
883     wzTree->Branch("MC_leptonW_pt", &MCleptW_pt, "MC_leptonW_pt/F");
884    
885     wzTree->Branch("MC_leptonZ1_eta", &MCleptZ1_eta,"MC_leptonZ1_eta/F");
886     wzTree->Branch("MC_leptonZ2_eta", &MCleptZ2_eta,"MC_leptonZ2_eta/F");
887     wzTree->Branch("MC_leptonW_eta", &MCleptW_eta, "MC_leptonW_eta/F");
888    
889     wzTree->Branch("MC_leptonZ1_phi", &MCleptZ1_phi,"MC_leptonZ1_phi/F");
890     wzTree->Branch("MC_leptonZ2_phi", &MCleptZ2_phi,"MC_leptonZ2_phi/F");
891     wzTree->Branch("MC_leptonW_phi", &MCleptW_phi, "MC_leptonW_phi/F");
892    
893     wzTree->Branch("MC_leptonZ1_pdgid", &MCleptZ1_pdgid,"MC_leptonZ1_pdgid/I");
894     wzTree->Branch("MC_leptonZ2_pdgid", &MCleptZ2_pdgid,"MC_leptonZ2_pdgid/I");
895     wzTree->Branch("MC_leptonW_pdgid", &MCleptW_pdgid, "MC_leptonW_pdgid/I");
896 vuko 1.14
897     /*
898     wzTree->Branch("MC_leptonW_origin", &MCleptW_pdgid, "MC_leptonW_origin/I");
899     wzTree->Branch("MC_leptonZ1_origin", &MCleptW_pdgid, "MC_leptonZ1_origin/I");
900     wzTree->Branch("MC_leptonZ2_origin", &MCleptW_pdgid, "MC_leptonZ2_origin/I");
901     */
902    
903 smorovic 1.8 wzTree->Branch("MC_TauDecayType_fromZ1", &MC_tauDecayTypeZ1,"MC_TauDecayType_fromZ1/I");
904     wzTree->Branch("MC_TauDecayType_fromZ2", &MC_tauDecayTypeZ2,"MC_TauDecayType_fromZ2/I");
905     wzTree->Branch("MC_TauDecayType_fromW", &MC_tauDecayTypeW, "MC_TauDecayType_fromW/I");
906 vuko 1.10
907 beaucero 1.56 // Jet properties
908 smorovic 1.41 wzTree->Branch("NbJets", &NbJets, "NbJets/I");
909 vuko 1.49 wzTree->Branch("NCaloJets", &NCaloJets,"NCaloJets/I");
910 smorovic 1.41
911 vuko 1.10 wzTree->Branch("Jet1Et", &jet1Et, "Jet1Et/F");
912     wzTree->Branch("Jet1Phi", &jet1Phi, "Jet1Phi/F");
913     wzTree->Branch("Jet1Eta", &jet1Eta, "Jet1Eta/F");
914    
915     wzTree->Branch("Jet2Et", &jet2Et, "Jet2Et/F");
916     wzTree->Branch("Jet2Phi", &jet2Phi, "Jet2Phi/F");
917     wzTree->Branch("Jet2Eta", &jet2Eta, "Jet2Eta/F");
918 smorovic 1.41 wzTree->Branch("ElectronTreesInEvent", &numberOfElectronTrees, "ElectronTreesInEvent/I");
919 smorovic 1.52 wzTree->Branch("EventCounter", &EventCounter, "EventCounter/I");
920 vuko 1.20 //
921     electronTree->Branch("used", &electronUse, "used/I");
922 smorovic 1.40 electronTree->Branch("weight", &eventWeight, "weight/F");
923     electronTree->Branch("processID", &processID, "processID/I");
924     electronTree->Branch("alpgenID", &alpgenID, "alpgenID/I");
925 smorovic 1.48 electronTree->Branch("genEventScale", &eventScale, "genEventScale/F");
926 smorovic 1.41 electronTree->Branch("ElectronTreesInEvent", &numberOfElectronTrees, "ElectronTreesInEvent/I");
927    
928     electronTree->Branch("RunNumber", &RunNumber, "RunNumber/I");
929     electronTree->Branch("EventID", &EventID, "EventID/I");
930 smorovic 1.52 electronTree->Branch("EventCounter", &EventCounter, "EventCounter/I");
931 beaucero 1.42 electronTree->Branch("NbJetsWithLeptons", &NbJetsWithLeptons, "NbJetsWithLeptons/I");
932 smorovic 1.52
933     if (findBackJets) {
934     electronTree->Branch("MET_Et",&MET_energy,"MET_Et/F");
935     electronTree->Branch("MET_pt",&MET_pt,"MET_pt/F");
936     electronTree->Branch("MET_eta",&MET_eta,"MET_eta/F");
937 beaucero 1.56 electronTree->Branch("MET_phi",&MET_phi,"MET_phi/F");
938 smorovic 1.52
939     electronTree->Branch("backJet_found",&backJet_found,"backJet_found/I");
940     electronTree->Branch("backJet_Et",&backJet_Et,"backJet_Et/F");
941     electronTree->Branch("backJet_Eta",&backJet_Eta,"backJet_Eta/F");
942     electronTree->Branch("backJet_Phi",&backJet_Phi,"backJet_Phi/F");
943     electronTree->Branch("backJet_maxEInEmTowers",&backJet_maxEInEmTowers,"backJet_maxEInEmTowers/F");
944     electronTree->Branch("backJet_maxEInHadTowers",&backJet_maxEInHadTowers,"backJet_maxEInHadTowers/F");
945     electronTree->Branch("backJet_energyFractionHadronic",&backJet_energyFractionHadronic,"backJet_energyFractionHadronic/F");
946     electronTree->Branch("backJet_emEnergyFraction",&backJet_emEnergyFraction,"backJet_emEnergyFraction/F");
947     electronTree->Branch("backJet_hadEnergyInHB",&backJet_hadEnergyInHB,"backJet_hadEnergyInHB/F");
948     electronTree->Branch("backJet_hadEnergyInHO",&backJet_hadEnergyInHO,"backJet_hadEnergyInHO/F");
949     electronTree->Branch("backJet_hadEnergyInHE",&backJet_hadEnergyInHE,"backJet_hadEnergyInHE/F");
950     electronTree->Branch("backJet_hadEnergyInHF",&backJet_hadEnergyInHF,"backJet_hadEnergyInHF/F");
951     electronTree->Branch("backJet_emEnergyInEB",&backJet_emEnergyInEB,"backJet_emEnergyInEB/F");
952     electronTree->Branch("backJet_emEnergyInEE",&backJet_emEnergyInEE,"backJet_emEnergyInEE/F");
953     electronTree->Branch("backJet_emEnergyInHF",&backJet_emEnergyInHF,"backJet_emEnergyInHF/F");
954     electronTree->Branch("backJet_towersArea",&backJet_towersArea,"backJet_towersArea/F");
955     electronTree->Branch("backJet_n90",&backJet_n90,"backJet_n90/F");
956     electronTree->Branch("backJet_n60",&backJet_n60,"backJet_n60/F");
957    
958     electronTree->Branch("backJet_NbTracks",&backJet_NbTracks,"backJet_NbTracks/I");
959    
960     electronTree->Branch("backJet_match",&backJet_match,"backJet_match/I");
961     electronTree->Branch("backJet_matchPt",&backJet_matchPt,"backJet_matchPt/F");
962     electronTree->Branch("backJet_match_dR",&backJet_match_dR,"backJet_match_dR/F");
963    
964    
965    
966     }
967 vuko 1.50
968     electronTree->Branch("WZ_hltBitmask",&triggerBitmask,"WZ_hltBitmask/I");
969 smorovic 1.52 electronTree->Branch("QCD_hltBitmask",&triggerBitmaskQCD,"QCD_hltBitmask/I");
970 smorovic 1.8 }
971 vuko 1.1
972 senka 1.9
973 senka 1.28 //////////////////////////////////////////
974     // MET & MET corrections
975     // MET=MET-sum_p(muons)-sum_p(muons calos depositions)
976    
977     reco::Particle::LorentzVector WZAnalyzer::computeMET(const edm::Event& iEvent, const edm::EventSetup& iSetup, Handle<reco::CandidateCollection> MuonCands) {
978 senka 1.9
979     using namespace edm;
980     using namespace reco;
981     using namespace std;
982 senka 1.44
983 beaucero 1.45 double px_MET=0, py_MET=0, Ex_MET=0, Ey_MET=0;
984 senka 1.44 double px,py,pz,pt,Et,Ex,Ey;
985     double px_muons=0;
986     double py_muons=0;
987     double Ex_muons=0;
988     double Ey_muons=0;
989     double Et_muons=0;
990     double Et_ecal;
991     double Et_hcal;
992     double Et_ho;
993     double Et_cal;
994     double Ex_ecal;
995     double Ex_hcal;
996     double Ex_ho;
997     double Ey_ecal;
998     double Ey_hcal;
999     double Ey_ho;
1000     double eta_cal;
1001     double phi_cal;
1002     double tg_theta_pola_ecal;
1003     double tg_theta_pola_hcal;
1004     double tg_theta_pola_ho;
1005     double tg_theta_ecal;
1006     double tg_theta_hcal;
1007     double tg_theta_ho;
1008     double E_ecal;
1009     double E_hcal;
1010     double E_ho;
1011     double me=0.0005;
1012     double sin_theta_ecal, sin_theta_hcal, sin_theta_ho, cos_theta_ecal,cos_theta_hcal,cos_theta_ho;
1013     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;
1014     double Ex_cal=0;
1015     double Ey_cal=0;
1016     double px_cal=0;
1017     double py_cal=0;
1018     double Ex_kon=0;
1019     double Ey_kon=0;
1020    
1021     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
1022     reco::Particle::LorentzVector Muon_p_cal_4v(0,0,0,0);
1023 senka 1.9
1024     Handle<CaloMETCollection> mets;
1025     iEvent.getByLabel("met", mets);
1026 vuko 1.25 // cout << "# METs=" << mets->size() << endl;
1027 senka 1.44
1028 vuko 1.25 if (mets->size() != 1) {
1029 senka 1.44 cout << "ALARM: # METS is not 1: !" << endl;
1030 vuko 1.25 return reco::Particle::LorentzVector(0.,0.,0.,0.);
1031     }
1032 senka 1.44
1033 vuko 1.14 for (CaloMETCollection::const_iterator met = mets->begin();
1034     met!= mets->end(); met++) {
1035 senka 1.44 px_MET=met->px();
1036     py_MET=met->py();
1037     Ex_MET=met->et()*TMath::Cos(met->phi());
1038     Ey_MET=met->et()*TMath::Sin(met->phi());
1039    
1040 vuko 1.14 }
1041 senka 1.44
1042     // sum of p of muons
1043     for (unsigned int i=0; i<MuonCands->size();i++){
1044     px=(*MuonCands)[i].px();
1045     py=(*MuonCands)[i].py();
1046     pz=(*MuonCands)[i].pz();
1047     pt=(*MuonCands)[i].pt();
1048     Et=(*MuonCands)[i].et();
1049     Ex=Et*TMath::Cos((*MuonCands)[i].phi());
1050     Ey=Et*TMath::Sin((*MuonCands)[i].phi());
1051     px_muons=px_muons+px;
1052     py_muons=py_muons+py;
1053     Ex_muons=Ex_muons+Ex;
1054     Ey_muons=Ey_muons+Ey;
1055    
1056     }
1057     Et_muons=TMath::Sqrt(Ex_muons*Ex_muons+Ey_muons*Ey_muons);
1058     Muon_p_4v=reco::Particle::LorentzVector(px_muons,py_muons,0,Et_muons);
1059    
1060     // sum of p of muons left in calorimeters
1061     for (unsigned int i=0; i<MuonCands->size();i++){
1062     cout<<"" << endl;
1063     const reco::Muon* muons=dynamic_cast<const reco::Muon *> (&(*MuonCands)[i]);
1064     Et_ecal=muons->getCalEnergy().emS9;
1065     Et_hcal=muons->getCalEnergy().hadS9;
1066     Et_ho=muons->getCalEnergy().hoS9;
1067     eta_cal=muons->eta();
1068     phi_cal=muons->phi();
1069     tg_theta_pola_ecal=TMath::Exp(-eta_cal);
1070     tg_theta_pola_hcal=TMath::Exp(-eta_cal);
1071     tg_theta_pola_ho=TMath::Exp(-eta_cal);
1072     tg_theta_ecal=2*tg_theta_pola_ecal/(1-tg_theta_pola_ecal*tg_theta_pola_ecal);
1073     tg_theta_hcal=2*tg_theta_pola_hcal/(1-tg_theta_pola_hcal*tg_theta_pola_hcal);
1074     tg_theta_ho=2*tg_theta_pola_ho/(1-tg_theta_pola_ho*tg_theta_pola_ho);
1075     E_ecal=TMath::Abs(Et_ecal*TMath::Sqrt(1+tg_theta_ecal*tg_theta_ecal)/tg_theta_ecal);
1076     E_hcal=TMath::Abs(Et_hcal*TMath::Sqrt(1+tg_theta_hcal*tg_theta_hcal)/tg_theta_hcal);
1077     E_ho=TMath::Abs(Et_ho*TMath::Sqrt(1+tg_theta_ho*tg_theta_ho)/tg_theta_ho);
1078     Ex_ecal=Et_ecal*TMath::Cos(phi_cal);
1079     Ex_hcal=Et_hcal*TMath::Cos(phi_cal);
1080     Ex_ho=Et_ho*TMath::Cos(phi_cal);
1081     Ey_ecal=Et_ecal*TMath::Sin(phi_cal);
1082     Ey_hcal=Et_hcal*TMath::Sin(phi_cal);
1083     Ey_ho=Et_ho*TMath::Sin(phi_cal);
1084     sin_theta_ecal=tg_theta_ecal/TMath::Sqrt(1+tg_theta_ecal*tg_theta_ecal);
1085     sin_theta_hcal=tg_theta_hcal/TMath::Sqrt(1+tg_theta_hcal*tg_theta_hcal);
1086     sin_theta_ho=tg_theta_ho/TMath::Sqrt(1+tg_theta_ho*tg_theta_ho);
1087     cos_theta_ecal=TMath::Sqrt(1-sin_theta_ecal*sin_theta_ecal);
1088     cos_theta_hcal=TMath::Sqrt(1-sin_theta_hcal*sin_theta_hcal);
1089     cos_theta_ho=TMath::Sqrt(1-sin_theta_ho*sin_theta_ho);
1090     if (E_ecal<me){
1091     p_ecal=0;
1092     }
1093     else {
1094     p_ecal=TMath::Sqrt(E_ecal*E_ecal-me*me);
1095     }
1096     if (E_hcal<me){
1097     p_hcal=0;
1098     }
1099     else {
1100     p_hcal=TMath::Sqrt(E_hcal*E_hcal-me*me);
1101     }
1102     if (E_ho<me){
1103     p_ho=0;
1104     }
1105     else {
1106     p_ho=TMath::Sqrt(E_ho*E_ho-me*me);
1107     }
1108 senka 1.28
1109 senka 1.44 pz_ecal=p_ecal*cos_theta_ecal;
1110     pz_hcal=p_hcal*cos_theta_hcal;
1111     pz_ho=p_ho*cos_theta_ho;
1112     pt_ecal=TMath::Abs(p_ecal*sin_theta_ecal);
1113 senka 1.33
1114 senka 1.44 pt_hcal=TMath::Abs(p_hcal*sin_theta_hcal);
1115    
1116     pt_ho=TMath::Abs(p_ho*sin_theta_ho);
1117    
1118     px_ecal=pt_ecal*TMath::Cos(phi_cal);
1119     px_hcal=pt_hcal*TMath::Cos(phi_cal);
1120     px_ho=pt_ho*TMath::Cos(phi_cal);
1121     py_ecal=pt_ecal*TMath::Sin(phi_cal);
1122     py_hcal=pt_hcal*TMath::Sin(phi_cal);
1123     py_ho=pt_ho*TMath::Sin(phi_cal);
1124 senka 1.28
1125 senka 1.44
1126     Ex_cal=Ex_cal+Ex_ecal+Ex_hcal+Ex_ho;
1127     Ey_cal=Ey_cal+Ey_ecal+Ey_hcal+Ey_ho;
1128    
1129     px_cal=px_cal+px_ecal+px_hcal+px_ho;
1130     py_cal=py_cal+py_ecal+py_hcal+py_ho;
1131    
1132 senka 1.28
1133 senka 1.44 }
1134     Et_cal=TMath::Sqrt(Ex_cal*Ex_cal+Ey_cal*Ey_cal);
1135     Muon_p_cal_4v=reco::Particle::LorentzVector(px_cal,py_cal,0, Et_cal);
1136 senka 1.33
1137 senka 1.44 Ex_kon=Ex_MET-Ex_muons+Ex_cal;
1138     Ey_kon=Ey_MET-Ey_muons+Ey_cal;
1139 senka 1.28
1140 senka 1.44 reco::Particle::LorentzVector MET= reco::Particle::LorentzVector(px_MET-px_muons+px_cal,py_MET-py_muons+py_cal,0,TMath::Sqrt(Ex_kon*Ex_kon+Ey_kon*Ey_kon)); // substract p from muons and p of calo muon deposit from MET
1141 senka 1.28
1142     return MET;
1143 senka 1.9
1144     }
1145    
1146 kkaadze 1.55 //MET Corrections from difference between corrected and uncorretced SC
1147     reco::Particle::LorentzVector WZAnalyzer::correctMETforSCCorrection(reco::Particle::LorentzVector MET_p_4v, Handle<reco::CandidateCollection> ElectronCands) {
1148    
1149     double SCRawEnergy = 0;
1150     double SCEnergy = 0;
1151     double deltaE = 0;
1152     double deltaET = 0;
1153     double deltaEx = 0;
1154     double deltaEy = 0;
1155    
1156     reco::Particle::LorentzVector SCCorr_p_4v(0,0,0,0); // sum of correction fraction of ET in (px,py,0,Et)
1157    
1158     //Loop over electron candidates and obtain the difference between uncorr and corr SC
1159     for (unsigned int i =0; i<ElectronCands->size(); ++i) {
1160     const reco::PixelMatchGsfElectron * electron = 0;
1161     if ( (*ElectronCands)[i].hasMasterClone() ) {
1162     reco::CandidateBaseRef master = (*ElectronCands)[i].masterClone();
1163     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*master));
1164     } else {
1165     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*ElectronCands)[i]);
1166     }
1167     const reco::SuperCluster& ElSC = *(electron->superCluster());
1168     SCRawEnergy = ElSC.rawEnergy();
1169     SCEnergy = ElSC.energy();
1170     //b.c. both uncrected and corrected SC clusters are oriented the same way, difference between vectors is just magnitudinal.
1171     deltaE = SCEnergy - SCRawEnergy;
1172     deltaET = deltaE/cosh(ElSC.eta());
1173     deltaEx += deltaET*cos(ElSC.phi());
1174     deltaEy += deltaET*sin(ElSC.phi());
1175     }
1176    
1177     deltaET = 0;
1178     deltaET = sqrt(deltaEx*deltaEx + deltaEy*deltaEy);
1179     SCCorr_p_4v = reco::Particle::LorentzVector(deltaEx, deltaEy, 0, deltaET);
1180     // return SCCorr_p_4v;
1181     return (MET_p_4v - SCCorr_p_4v);
1182     }
1183    
1184    
1185     //MET Corrections from difference between el energy and rawenergy of SC
1186     reco::Particle::LorentzVector WZAnalyzer::correctMETforElCorrection(reco::Particle::LorentzVector MET_p_4v, Handle<reco::CandidateCollection> ElectronCands) {
1187    
1188     double px = 0;
1189     double py = 0;
1190     double pz = 0;
1191     double Ex = 0;
1192     double Ey = 0;
1193     double Et = 0;
1194     double SCRawEnergy = 0;
1195     double SCPt = 0;
1196     double SCEt = 0;
1197     double SCpx = 0;
1198     double SCpy = 0;
1199     double SCEx = 0;
1200     double SCEy = 0;
1201    
1202     const reco::PixelMatchGsfElectron * electron = 0;
1203    
1204     reco::Particle::LorentzVector El_p_4v(0,0,0,0); // in (px,py,0,Et)
1205     reco::Particle::LorentzVector SC_p_4v(0,0,0,0);
1206    
1207     //Loop over electron candidates and obtain the difference between uncorr and corr SC
1208     for (unsigned int i =0; i<ElectronCands->size(); ++i) {
1209    
1210     px += (*ElectronCands)[i].px();
1211     py += (*ElectronCands)[i].py();
1212     pz += (*ElectronCands)[i].pz();
1213     Ex += (*ElectronCands)[i].et()*cos((*ElectronCands)[i].phi());
1214     Ey += (*ElectronCands)[i].et()*sin((*ElectronCands)[i].phi());
1215    
1216     if ( (*ElectronCands)[i].hasMasterClone() ) {
1217     reco::CandidateBaseRef master = (*ElectronCands)[i].masterClone();
1218     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*master));
1219     } else {
1220     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*ElectronCands)[i]);
1221     }
1222     const reco::SuperCluster& ElSC = *(electron->superCluster());
1223     SCRawEnergy = ElSC.rawEnergy();
1224     SCPt = SCRawEnergy/cosh(ElSC.eta());
1225     SCEt = SCRawEnergy/cosh(ElSC.eta());
1226     SCpx += SCPt*cos(ElSC.phi());
1227     SCpy += SCPt*sin(ElSC.phi());
1228     SCEx += SCEt*cos(ElSC.phi());
1229     SCEy += SCEt*sin(ElSC.phi());
1230     }
1231    
1232     Et = sqrt(Ex*Ex + Ey*Ey);
1233     El_p_4v = reco::Particle::LorentzVector(px,py,0,Et);
1234    
1235     SCEt = sqrt(SCEx*SCEx + SCEy * SCEy);
1236     SC_p_4v = reco::Particle::LorentzVector(SCpx,SCpy,0,SCEt);
1237    
1238     reco::Particle::LorentzVector ElCorr_p_4v = El_p_4v - SC_p_4v;
1239     return (MET_p_4v - ElCorr_p_4v);
1240     }
1241    
1242    
1243    
1244 senka 1.12 ////////////////////////
1245     // matching
1246     //
1247    
1248     class MatchingInfo {
1249     public:
1250    
1251     MatchingInfo(float dr, int gen, int reco) : deltaR(dr), genMuon(gen),recoMuon(reco) {}
1252    
1253     bool operator<(const MatchingInfo m) { return deltaR < m.deltaR;}
1254    
1255     float deltaR;
1256     int genMuon;
1257     int recoMuon;
1258    
1259     };
1260    
1261    
1262     bool betterMatch(MatchingInfo m1, MatchingInfo m2)
1263     { return m1.deltaR < m2.deltaR;}
1264    
1265    
1266     // method that gives the vector<MatchingInfo> matching_Infos containing (dR,i,j); i=genParticle index, j=ParticleCollection index:
1267    
1268     void WZAnalyzer::matching(const edm::Event& iEvent, Handle<reco::CandidateCollection> cands, int pdgid){
1269    
1270     using namespace edm;
1271     using namespace reco;
1272     using namespace std;
1273    
1274     //-------------------------
1275     Handle<CandidateCollection> mccands;
1276     iEvent.getByLabel( theMCTruthCollection,mccands );
1277    
1278     vector <GenParticleCandidate*> genparticles;
1279    
1280     for(CandidateCollection::const_iterator p = mccands->begin();
1281     p != mccands->end(); p++) {
1282    
1283     // reco::Candidate* p_tmp = &(*p);
1284     reco::GenParticleCandidate* ptr = (reco::GenParticleCandidate*) &(*p);
1285    
1286     if ( (ptr)->status() == 1
1287     /*&& (ptr)->momentum().perp() > 2.*/ ) { // stable particles with pt>2 only
1288     if ( abs((ptr)->pdgId()) == pdgid ) {
1289     genparticles.push_back((ptr));
1290     //cout << "electron MCT\n";
1291     }
1292     }
1293     }
1294    
1295    
1296     int n1=0;
1297     vector<MatchingInfo> matching_Infos;
1298     for ( unsigned int i=0; i<genparticles.size(); i++ ) // po svim MC muonima
1299     {
1300    
1301     for (unsigned int j = 0; j < cands->size(); j++)// po svim reco muonima
1302     {
1303    
1304     double d_eta2=(*cands)[j].eta()-(genparticles)[i]->eta();
1305     double d_phi=fabs((*cands)[j].phi()-(genparticles)[i]->phi());
1306     double dR_byhand= sqrt(d_eta2*d_eta2+d_phi*d_phi);
1307     double dR=dR_byhand;
1308    
1309     if (dR<0.15){
1310     n1++;
1311     matching_Infos.push_back(MatchingInfo(dR,i,j));
1312     }
1313    
1314     }
1315     }
1316 senka 1.24
1317 senka 1.12 sort(matching_Infos.begin(),matching_Infos.end(),betterMatch); // sorting (dR,i,j)
1318 senka 1.24
1319     if (genparticles.size()!=0 && cands->size()!=0){
1320     // Now exclude combinations using same gen or rec muons
1321     for (std::vector<MatchingInfo>::iterator it=matching_Infos.begin();
1322     it != matching_Infos.end(); it++) {
1323     for (std::vector<MatchingInfo>::iterator it2=matching_Infos.begin();
1324     it2!=it; it2++) {
1325     if ( (it->genMuon == it2->genMuon) || (it->recoMuon == it2->recoMuon) ) {
1326     matching_Infos.erase(it);
1327     it=matching_Infos.begin();
1328     break;
1329     }
1330     }
1331     }
1332     }
1333    
1334 vuko 1.14 // Now put result in vector of pairs
1335    
1336     leptonMatching[pdgid].clear();
1337    
1338     for (vector<MatchingInfo>::iterator match=matching_Infos.begin();
1339 senka 1.16 match !=matching_Infos.end(); match++) { // po tablici dr,i,j
1340 vuko 1.14
1341     pair<const GenParticleCandidate*, const reco::Candidate *> pair;
1342 senka 1.16 // vector<pair,float > matchedParticles;
1343 vuko 1.14 pair.first = genparticles[match->genMuon];
1344     pair.second = & (*cands)[match->recoMuon];
1345 senka 1.16
1346     matchedParticles cestice(genparticles[match->genMuon] ,& (*cands)[match->recoMuon] , match->deltaR);
1347    
1348     leptonMatching[pdgid].push_back(cestice);
1349 senka 1.24
1350 vuko 1.14 }
1351 senka 1.24
1352 senka 1.12 }
1353    
1354 senka 1.9
1355 senka 1.13 // get mother of particle
1356     // returns mother = 1 if mother is Z boson
1357     // returns mother = 2 if mother is W boson
1358     // returns mother = 4 if mother is b
1359     // returns mother = 0 else
1360    
1361 vuko 1.14 WZAnalyzer::LeptonOrigin WZAnalyzer::getMother(const reco::Candidate* genParticle){
1362    
1363     int pdg_id=genParticle->pdgId();
1364 vuko 1.25 // cout << "particle id : " << pdg_id << endl;
1365 senka 1.13
1366     while (genParticle = genParticle->mother() ) { //izvrsava se sve dok ne dodje do nule tj. dok ne trazi majku od protona
1367 vuko 1.25 // cout << "Going up: ";
1368     // cout << "Mother id : " << genParticle->pdgId() << endl;
1369 senka 1.24 if (abs(genParticle->pdgId())!=abs(pdg_id)) {
1370 vuko 1.25 // cout<< " good mother " <<endl;
1371 senka 1.13 if (abs(genParticle->pdgId())==23){ // mother is Z
1372 vuko 1.14 return zboson;
1373 senka 1.13 }
1374     if (abs(genParticle->pdgId())==24) { // mother is W
1375 vuko 1.14 return wboson;
1376 senka 1.13 }
1377     // if (abs(genParticle->pdgId())==23 || abs(genParticle->pdgId())==24) { // mother is W or Z
1378     // WZ_matched=1;
1379     // mother=3;
1380     // }
1381     if ((((abs(genParticle->pdgId()))/100)%10 ==5)||(((abs(genParticle->pdgId()))/1000)%10 ==5 )) { // mother is b
1382 vuko 1.14 return bdecay;
1383 senka 1.13 }
1384 vuko 1.14 if ((((abs(genParticle->pdgId()))/100)%10 ==4)||(((abs(genParticle->pdgId()))/1000)%10 ==4 )) { // mother is c
1385     return cdecay;
1386     }
1387     return other;
1388 senka 1.13 }
1389 vuko 1.20 }
1390    
1391     return other;
1392 senka 1.13 }
1393    
1394 senka 1.15 const reco::Candidate * WZAnalyzer::MatchedGenParticle(const reco::Candidate * daughter){
1395     ::OverlapChecker overlap;
1396     matched_genParticle=0;
1397 senka 1.16
1398     for (map< int,
1399     std::vector< matchedParticles > > ::iterator iter = leptonMatching.begin();
1400     iter!=leptonMatching.end(); iter++) // entire map
1401     {
1402 vuko 1.20 for (unsigned int j=0; j<iter->second.size(); j++){ // entire vector<class<>>
1403 senka 1.16 const reco::Candidate * nesto=iter->second[j].pair.second;
1404     if (overlap(*nesto,*daughter)){
1405     matched_genParticle=iter->second[j].pair.first;
1406     }
1407     }
1408     }
1409     return matched_genParticle;
1410     }
1411    
1412    
1413     float WZAnalyzer::dR(const reco::Candidate * daughter){
1414 vuko 1.18
1415 senka 1.16 ::OverlapChecker overlap;
1416 vuko 1.18
1417 senka 1.19 float delta_r = -10;
1418 senka 1.15 for (map< int,
1419 senka 1.16 std::vector< matchedParticles > > ::iterator iter = leptonMatching.begin();
1420 senka 1.15 iter!=leptonMatching.end(); iter++) // entire map
1421     {
1422 vuko 1.20 for (unsigned int j=0; j<iter->second.size(); j++){ // entire vector<class<>>
1423 senka 1.16 const reco::Candidate * nesto=iter->second[j].pair.second;
1424 senka 1.15 if (overlap(*nesto,*daughter)){
1425 senka 1.16 delta_r=iter->second[j].delta_R;
1426 senka 1.15 }
1427     }
1428     }
1429 senka 1.16 return delta_r;
1430 senka 1.15 }
1431    
1432 vuko 1.11
1433 senka 1.16
1434 vuko 1.10 void WZAnalyzer::collectMCsummary(Handle <reco::CandidateCollection> mccands) {
1435 senka 1.12
1436 vuko 1.11 using namespace reco;
1437    
1438 smorovic 1.8 //collections
1439 senka 1.24
1440 smorovic 1.8 MCleptZ1_pdgid = -1;
1441     MCleptZ2_pdgid = -1;
1442     MCleptW_pdgid = -1;
1443    
1444     MCleptZ1_pt = -1;
1445     MCleptZ2_pt = -1;
1446     MCleptW_pt = -1;
1447    
1448     MCleptZ1_eta = -1;
1449     MCleptZ2_eta = -1;
1450     MCleptW_eta = -1;
1451    
1452     MCleptZ1_phi = -1;
1453     MCleptZ2_phi = -1;
1454     MCleptW_phi = -1;
1455 senka 1.12
1456 smorovic 1.8 vector<reco::GenParticleCandidate*> Tau;
1457     vector<reco::GenParticleCandidate*> StableMuons;
1458     vector<reco::GenParticleCandidate*> StableElectrons;
1459 senka 1.24
1460 smorovic 1.32
1461    
1462 vuko 1.11 for(CandidateCollection::const_iterator p = mccands->begin();
1463     p != mccands->end(); p++) {
1464 vuko 1.1
1465 vuko 1.11 // reco::Candidate* p_tmp = &(*p);
1466     reco::GenParticleCandidate* ptr = (reco::GenParticleCandidate*) &(*p);
1467 smorovic 1.8
1468     if ( (ptr)->status() == 1
1469     /*&& (ptr)->momentum().perp() > 2.*/ ) { // stable particles with pt>2 only
1470     if ( abs((ptr)->pdgId()) == 11 ) {
1471 senka 1.12
1472 smorovic 1.8 StableElectrons.push_back((ptr));
1473     //cout << "electron MCT\n";
1474     }
1475     else if ( abs((ptr)->pdgId()) == 13 ) {
1476 senka 1.12
1477 smorovic 1.8 StableMuons.push_back((ptr)) ;
1478     //cout << "muon MCT\n";
1479     }
1480     }
1481     else if ((ptr)->status() == 2) {
1482     if ( abs((ptr)->pdgId()) == 15 ) {//tau
1483     Tau.push_back((ptr));
1484     }
1485     }
1486     }
1487 senka 1.12
1488 vuko 1.25 // std::cout << "# Electrons : " << StableElectrons.size()
1489     // << "# Muons : " << StableMuons.size() << std::endl
1490     // << "# Tau : " << Tau.size() << std::endl;
1491 senka 1.12
1492 smorovic 1.8
1493     vector<reco::GenParticleCandidate*> * StableLeptons[3] = {&StableElectrons, &StableMuons, &Tau};
1494    
1495 smorovic 1.32 vector<reco::GenParticleCandidate*> TauChildLeptons;
1496    
1497    
1498     //erase electrons and muons from tau from GenparticleCandidate Vector and put to Tau Vector
1499     for (int i=1; i>=0; i--) {
1500     for ( vector<reco::GenParticleCandidate*>::iterator lepton = StableLeptons[i]->begin();
1501     lepton != StableLeptons[i]->end();lepton++) {
1502    
1503     reco::GenParticleCandidate* mcParticleRef = *lepton;
1504    
1505     int parentItr=0;
1506     while ( mcParticleRef->mother()!=0 && parentItr<2) {
1507    
1508     parentItr++;
1509    
1510     mcParticleRef = (reco::GenParticleCandidate*) mcParticleRef->mother();
1511     if (mcParticleRef==0) break;
1512    
1513     //if tau
1514     if (abs((mcParticleRef)->pdgId())==15 ) {
1515     //put into collection
1516     TauChildLeptons.push_back(*lepton);
1517     StableLeptons[i]->erase(lepton);
1518     lepton--;
1519     break;
1520     }
1521     }
1522     }
1523     }
1524    
1525    
1526 smorovic 1.8 bool firstZlept = true;
1527 vuko 1.51 // int MC_tauDecayTypeZ1 = 0;
1528     // int MC_tauDecayTypeZ2 = 0;
1529     // int MC_tauDecayTypeW = 0;
1530     MC_tauDecayTypeZ1 = 0;
1531     MC_tauDecayTypeZ2 = 0;
1532     MC_tauDecayTypeW = 0;
1533 smorovic 1.32
1534    
1535 smorovic 1.8 for (int i=2; i>=0; i--) {
1536     while (StableLeptons[i]->size() > 0) {
1537     float maxPt = 0;
1538     vector<reco::GenParticleCandidate*>::iterator index = StableLeptons[i]->end();
1539    
1540     for ( vector<reco::GenParticleCandidate*>::iterator lepton = StableLeptons[i]->begin();
1541     lepton != StableLeptons[i]->end(); lepton++ ) {
1542 smorovic 1.32
1543 smorovic 1.8 if ((*lepton)->pt() > maxPt) {
1544     maxPt = (*lepton)->pt();
1545     index = lepton;
1546     }
1547     }
1548     bool Zchild = false;
1549     bool Wchild = false;
1550 smorovic 1.32 bool isTau = false;
1551    
1552    
1553 smorovic 1.8 reco::GenParticleCandidate* mcParticleRef = *index;
1554    
1555 smorovic 1.32 if (abs((*index)->pdgId()) == 15) isTau = true;
1556    
1557 smorovic 1.8 //find W/Z mother
1558 smorovic 1.32 int parentItr=0;
1559     while ( mcParticleRef->mother()!=0 && parentItr<2) {
1560    
1561 smorovic 1.8 if (parentItr>=2) break;
1562     parentItr++;
1563     mcParticleRef = (reco::GenParticleCandidate*) mcParticleRef->mother();
1564 smorovic 1.32 if (mcParticleRef==0) break;
1565 smorovic 1.8
1566     if (abs((mcParticleRef)->pdgId())==23 ) {
1567     Zchild=true;
1568     break;
1569     }
1570     if (abs((mcParticleRef)->pdgId())==24 ) {
1571     Wchild=true;
1572     break;
1573     }
1574     }
1575    
1576 smorovic 1.32
1577 smorovic 1.8 if (maxPt >0) {
1578 smorovic 1.32 int * MCtauDecayTypePtr = 0;
1579    
1580 smorovic 1.8 if (Wchild) {
1581     MCleptW_pdgid=(*index)->pdgId();
1582     MCleptW_pt=(float)(*index)->pt();
1583     MCleptW_eta=(float)(*index)->eta();
1584     MCleptW_phi=(float)(*index)->phi();
1585 smorovic 1.32 if (isTau) {
1586     MCtauDecayTypePtr = &MC_tauDecayTypeW;
1587     MC_tauDecayTypeW =3;//default to hadronic decay
1588     }
1589    
1590 smorovic 1.8 }
1591     if (Zchild) {
1592     if (firstZlept) {
1593     firstZlept=false;
1594     MCleptZ1_pdgid=(*index)->pdgId();
1595     MCleptZ1_pt=(float)(*index)->pt();
1596     MCleptZ1_eta=(float)(*index)->eta();
1597     MCleptZ1_phi=(float)(*index)->phi();
1598 smorovic 1.32 if (isTau) {
1599     MCtauDecayTypePtr = &MC_tauDecayTypeZ1;
1600     MC_tauDecayTypeZ1 =3;
1601     }
1602    
1603 smorovic 1.8 }
1604     else {
1605     MCleptZ2_pdgid=(*index)->pdgId();
1606     MCleptZ2_pt=(float)(*index)->pt();
1607     MCleptZ2_eta=(float)(*index)->eta();
1608     MCleptZ2_phi=(float)(*index)->phi();
1609 smorovic 1.32 if (isTau) {
1610     MCtauDecayTypePtr = &MC_tauDecayTypeZ2;
1611     MC_tauDecayTypeZ2 =3;
1612     }
1613    
1614     }
1615     }
1616     //check type of tau decay
1617     if (MCtauDecayTypePtr) {
1618     for( vector<reco::GenParticleCandidate*>::iterator p = TauChildLeptons.begin();p != TauChildLeptons.end(); p++) {
1619     int pitr = 0;
1620     reco::GenParticleCandidate* mcParticleRef = *p;
1621     while (mcParticleRef->mother() && pitr<2) {
1622     pitr++;
1623     mcParticleRef =(reco::GenParticleCandidate*) mcParticleRef->mother();
1624     if (mcParticleRef==0) break;
1625     if (mcParticleRef == *index) {
1626     if (abs((*p)->pdgId()) == 11) *MCtauDecayTypePtr = 1;
1627     if (abs((*p)->pdgId()) == 13) *MCtauDecayTypePtr = 2;
1628     }
1629     }
1630 smorovic 1.8 }
1631 smorovic 1.32 }
1632 smorovic 1.8 }
1633 smorovic 1.32 StableLeptons[i]->erase(index);
1634 smorovic 1.8 }
1635     }
1636     }
1637 vuko 1.1 //define this as a plug-in
1638 vuko 1.2 // DEFINE_FWK_MODULE(WZAnalyzer);
1639 smorovic 1.32