ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Vuko/WZAnalysis/src/WZAnalyzer.cc
Revision: 1.55
Committed: Tue Apr 22 22:14:59 2008 UTC (17 years ago) by kkaadze
Content type: text/plain
Branch: MAIN
CVS Tags: keti_Apr22_01
Changes since 1.54: +137 -3 lines
Log Message:
Addted MET corrections due to electron energy scale corrections

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 kkaadze 1.55 // $Id: WZAnalyzer.cc,v 1.54 2008/04/10 18:34:40 vuko 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     theGoodElectronCollection = iConfig.getParameter<edm::InputTag>("GoodElectrons");
89     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     // good electrons
182     Handle<CandidateCollection> goodElectronCands;
183     iEvent.getByLabel( theGoodElectronCollection , goodElectronCands);
184    
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     // << "\t # tight e : " << goodElectronCands->size()
281     // << "\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 vuko 1.4
346 vuko 1.3
347 senka 1.15 //---------------
348     // matching(iEvent,looseMuonCands, 13);
349     // matching(iEvent,looseElectronCands, 11);
350     // MatchedGenParticle(&(*looseMuonCands)[0]);
351     //-------------------
352    
353 vuko 1.1 int nwl_candidates=0;
354     if (theZCandidate) {
355    
356    
357     zMass = theZCandidate->mass();
358     zFlavour = abs(theZCandidate->daughter(0)->pdgId());
359     zPt = theZCandidate->pt();
360     zEta = theZCandidate->eta();
361     zPhi = theZCandidate->phi();
362    
363 vuko 1.18 // Sanity check: can we identify the Z daughters with leptons from the loose lists
364    
365     Handle<CandidateCollection> looseLeptonCands;
366     if (zFlavour == 11) {
367     looseLeptonCands = looseElectronCands;
368     } else if (zFlavour == 13) {
369     looseLeptonCands = looseMuonCands;
370     }
371     for (int i=0; i<2; i++) {
372     int noverlaps=0;
373     for(CandidateCollection::const_iterator l = looseLeptonCands->begin();
374     l != looseLeptonCands->end(); l++) {
375     if (overlap(*(theZCandidate->daughter(i)), *l) ) {
376     noverlaps++;
377     }
378     }
379     }
380    
381 senka 1.15 matching(iEvent,looseMuonCands, 13);
382     matching(iEvent,looseElectronCands, 11);
383    
384 vuko 1.4 if (zFlavour == 11) {
385 senka 1.17 //--------------
386 vuko 1.18 leptonProperties["ZEl1"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
387     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
388     leptonProperties["ZEl2"]->FillProperties(theZCandidate->daughter(1), iEvent, iSetup,
389     MatchedGenParticle(theZCandidate->daughter(1)),dR(theZCandidate->daughter(1)));
390 senka 1.17 } else if (zFlavour == 13) {
391     //--------------
392 senka 1.19 const reco::Candidate * mcpart = MatchedGenParticle(theZCandidate->daughter(0));
393 senka 1.17 //--------------
394 vuko 1.18 leptonProperties["Zmu1"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
395     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
396 vuko 1.53 leptonProperties["Zmul"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
397     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
398 vuko 1.18 leptonProperties["Zmu2"]->FillProperties(theZCandidate->daughter(1), iEvent, iSetup,
399     MatchedGenParticle(theZCandidate->daughter(1)),dR(theZCandidate->daughter(1)));
400 senka 1.15
401 vuko 1.4 }
402    
403 vuko 1.1 float max_pt = 0.;
404    
405 senka 1.9 /// Find W lepton
406    
407 vuko 1.1
408     // Now find lepton that will be associated to W
409     // among leptons not used for the Z reconstruction
410     for(CandidateCollection::const_iterator lepton = tightLeptonCands->begin();
411     lepton != tightLeptonCands->end(); lepton++) {
412    
413    
414     if ( overlap(*theZCandidate, *lepton) ) continue; // Ignore if lepton used for the Z
415    
416     nwl_candidates++;
417 vuko 1.50 if (abs(lepton->pdgId()) == 11) {
418     nWlElCand++;
419     } else if (abs(lepton->pdgId()) == 13) {
420     nWlMuCand++;
421     }
422 vuko 1.1
423     // If more than one candidate: choose leading pt
424     if (lepton->pt() > max_pt) {
425     theWlepton = &(*lepton);
426     max_pt = lepton->pt();
427     }
428    
429     if(lepton->hasMasterClone()) {
430 beaucero 1.35 // cout << "SHOUT: TIGHT LEPTON IS SHALLOW COPY !!! (SHOULD NOT BE!) \n";
431 vuko 1.1 }
432     //
433     }
434     if (theWlepton) {
435     wlFlavour = theWlepton->pdgId();
436     wlCharge = theWlepton->charge();
437     wlPt = theWlepton->pt();
438     wlEta = theWlepton->eta();
439     wlPhi = theWlepton->phi();
440    
441 vuko 1.3 if (abs(wlFlavour) == 11) {
442 senka 1.17 leptonProperties["Wel"]->FillProperties(theWlepton, iEvent, iSetup, MatchedGenParticle(theWlepton),dR(theWlepton));
443 vuko 1.3 } else if (abs(wlFlavour) == 13) {
444 senka 1.17 leptonProperties["Wmu"]->FillProperties(theWlepton, iEvent, iSetup, MatchedGenParticle(theWlepton),dR(theWlepton));
445 vuko 1.3 }
446 senka 1.24
447 senka 1.9 dPhi_WlZ_reco=acos(cos(theWlepton->phi()-theZCandidate->phi()));
448     dPhi_WZ_reco=acos(cos((theWlepton->p4()+MET).phi()-theZCandidate->phi()));
449 vuko 1.3
450 kkaadze 1.55 dPhi_Wl_MET = kinem::delta_phi(theWlepton->phi(),MET.phi());
451     // std::cout << "dPhi_Wl_MET " << dPhi_Wl_MET << std::endl;
452     if ( abs(wlFlavour) == 11) {
453     dPhi_Wl_MET_SCCorr = kinem::delta_phi(theWlepton->phi(),MET_SCCorr.phi());
454     // std::cout << "dPhi_Wl_MET_SCCorr " << dPhi_Wl_MET_SCCorr << std::endl;
455     dPhi_Wl_MET_ElCorr = kinem::delta_phi(theWlepton->phi(),MET_ElCorr.phi());
456     // std::cout << "dPhi_Wl_MET_ElCorr " << dPhi_Wl_MET_ElCorr << std::endl;
457     }
458 vuko 1.1 }
459 kkaadze 1.55
460 vuko 1.1 }
461 smorovic 1.6
462 vuko 1.10 // Handle <reco::GenParticleCandidateCollection> mccands;
463     Handle<CandidateCollection> mccands;
464     iEvent.getByLabel( theMCTruthCollection,mccands );
465 smorovic 1.6
466 vuko 1.11 collectMCsummary(mccands);
467 smorovic 1.6
468 smorovic 1.8 if (storeHLTresults) {
469    
470 smorovic 1.6 //def: 1:single electron 2:single relaxed 3:double electron 4: double relaxed 5,6,7,8: muon e+mu: 9
471 smorovic 1.8
472 smorovic 1.6 triggerBitmask=0;
473 smorovic 1.52 triggerBitmaskQCD=0;
474 smorovic 1.8
475 smorovic 1.6 for (size_t i=0; i<numTriggers; ++i) {
476    
477     if (!HLTR->wasrun(i)) {
478     continue;
479     }
480     if (HLTR->error(i) ) {
481     continue;
482     }
483     if (HLTR->accept(i)) {
484     //if (triggerNames[i].compare("mcpath")!=0)
485     //TRaccept=true;
486     }else {
487     continue;
488     }
489 smorovic 1.34 if (trigNames.triggerName(i).compare("HLT1Electron")==0) triggerBitmask |= 1;
490     if (trigNames.triggerName(i).compare("HLT1ElectronRelaxed")==0) triggerBitmask |= 2;
491     if (trigNames.triggerName(i).compare("HLT2Electron")==0) triggerBitmask |= 4;
492     if (trigNames.triggerName(i).compare("HLT2ElectronRelaxed")==0) triggerBitmask |= 8;
493    
494     if (trigNames.triggerName(i).compare("HLT1MuonIso")==0) triggerBitmask |= 16;
495     if (trigNames.triggerName(i).compare("HLT1MuonNonIso")==0) triggerBitmask |= 32;
496     if (trigNames.triggerName(i).compare("HLT2MuonNonIso")==0) triggerBitmask |= 64;
497     if (trigNames.triggerName(i).compare("HLT2MuonZ")==0) triggerBitmask |= 128;
498 smorovic 1.6
499 smorovic 1.34 if (trigNames.triggerName(i).compare("HLTXElectronMuon")==0) triggerBitmask |= 256;
500     if (trigNames.triggerName(i).compare("HLTXElectronMuonRelaxed")==0) triggerBitmask |= 512;
501 smorovic 1.47
502     if (trigNames.triggerName(i).compare("CandHLT2MuonIso")==0) triggerBitmask |= 1024;
503 smorovic 1.52
504     //for QCD control sample
505     if (trigNames.triggerName(i).compare("HLT1Jet")==0) triggerBitmaskQCD |= 1;
506     if (trigNames.triggerName(i).compare("HLT2Jet")==0) triggerBitmaskQCD |= 2;
507     if (trigNames.triggerName(i).compare("HLT3Jet")==0) triggerBitmaskQCD |= 4;
508     if (trigNames.triggerName(i).compare("HLT4Jet")==0) triggerBitmaskQCD |= 8;
509     if (trigNames.triggerName(i).compare("HLT2JetAco")==0) triggerBitmaskQCD |= 16;
510     if (trigNames.triggerName(i).compare("HLTXMuonJets")==0) triggerBitmaskQCD |= 32;
511     if (trigNames.triggerName(i).compare("HLT1MET")==0) triggerBitmaskQCD |= 64;
512     if (trigNames.triggerName(i).compare("HLT1Jet1METAco")==0) triggerBitmaskQCD |= 128;
513     if (trigNames.triggerName(i).compare("HLT1Jet1MET")==0) triggerBitmaskQCD |= 256;
514     if (trigNames.triggerName(i).compare("HLT2Jet1MET")==0) triggerBitmaskQCD |= 512;
515     if (trigNames.triggerName(i).compare("HLT3Jet1MET")==0) triggerBitmaskQCD |= 1024;
516     if (trigNames.triggerName(i).compare("HLT4Jet1MET")==0) triggerBitmaskQCD |= 2048;
517     if (trigNames.triggerName(i).compare("HLT1MET1HT")==0) triggerBitmaskQCD |= 4096;
518     if (trigNames.triggerName(i).compare("HLTS2JetAco")==0) triggerBitmaskQCD |= 8192;
519    
520 smorovic 1.6 }
521     }
522 vuko 1.10
523     // Jet properties
524    
525     float max_et = 0.;
526 vuko 1.14 float max2_et = 0.;
527     const Candidate * leadingJet = 0;
528     const Candidate * secondJet = 0;
529 smorovic 1.29
530     bool matchedLept[3]={false,false,false};
531    
532 vuko 1.14 // for(CandidateCollection::const_iterator jet = jetCands->begin();
533 smorovic 1.41 NbJets = 0;
534 beaucero 1.42 NbJetsWithLeptons = 0;
535 smorovic 1.52 /*
536     int *NbTracksInJet =0;
537     if (jetCands->size()>0) NbTracksInJet = new int[jetCands->size()];
538 smorovic 1.41
539 smorovic 1.52 int jetCntr=0;
540     */
541 vuko 1.14 for(CaloJetCollection::const_iterator jet = jetCands->begin();
542 vuko 1.10 jet != jetCands->end(); jet++) {
543 smorovic 1.29
544     //ignore jets which are within dR 0.15 to a WZ lepton
545     {
546 smorovic 1.52 /*
547     NbTracksInJet[jetCntr]=0;
548    
549     if (findBackJets) {
550    
551     // TVector3 p3Jet = TVector3(jet->p4().px(),jet->p4().py(),jet->p4().pz());
552     int nbTrackDR[NR_DR_INTERVALS];
553     double IsoTrackDR[NR_DR_INTERVALS];
554    
555     for (int i=0; i<wzana::ElectronProperties::nr_dr_cones;i++) {
556     IsoTrack[i] = -10;
557     NbTracks[i] = -10;
558     nbTrackDR[i] = 0;
559     IsoTrackDR[i] = 0;
560     }
561    
562    
563     edm::Handle<reco::TrackCollection> BarrelKFTracks;
564     iEvent.getByLabel("ctfWithMaterialTracks",BarrelKFTracks);
565    
566     for( reco::TrackCollection::const_iterator KFT = BarrelKFTracks->begin();KFT !=BarrelKFTracks->end(); ++ KFT ){
567    
568     double DPhi = fabs(KFT->phi()-jet->phi());
569     while (DPhi>6.28318531) DPhi-= 6.28318531;
570     if (DPhi>3.14159265) DPhi= 6.28318531-DPhi;
571    
572     double dR=sqrt( (KFT->eta() - jet->eta())*(KFT->eta() - jet->eta()) + DPhi*DPhi );
573    
574     if(KFT->pt()<1.5)continue;
575    
576     if (KFT->pt()>2.0 && dR<0.3) NbTracksInJet[jetCntr]++;
577    
578     cout << "pass track eta:" << KFT->eta() << " pt " << KFT->pt() << " dr " << dR << endl;
579    
580     for (int icone=0; icone<wzana::ElectronProperties::nr_dr_cones; icone++) {
581     double limit =wzana::ElectronProperties::DR_Cone_Limits[icone];
582     if ( dR < limit ){
583     cout << " match " << dR << " limit" << limit <<endl;
584     nbTrackDR[icone]++;
585     IsoTrackDR[icone] += KFT->pt();
586     } else break;
587    
588 smorovic 1.32 }
589 smorovic 1.29 }
590 smorovic 1.52
591     for (int icone=0; icone<wzana::ElectronProperties::nr_dr_cones; icone++) {
592     NbTracks[icone] = nbTrackDR[icone];
593     IsoTrack[icone] = IsoTrackDR[icone];
594     }
595    
596     backJet_Et=jet->et();
597     backJet_Eta=jet->eta();
598     backJet_Phi=jet->phi();
599     backJet_maxEInEmTowers=jet->maxEInEmTowers();
600     backJet_maxEInHadTowers=jet->maxEInHadTowers();
601     backJet_energyFractionHadronic=jet->energyFractionHadronic();
602     backJet_emEnergyFraction=jet->emEnergyFraction();
603     backJet_hadEnergyInHB=jet->hadEnergyInHB();
604     backJet_hadEnergyInHO=jet->hadEnergyInHO();
605     backJet_hadEnergyInHE=jet->hadEnergyInHE();
606     backJet_hadEnergyInHF=jet->hadEnergyInHF();
607     backJet_emEnergyInEB=jet->emEnergyInEB();
608     backJet_emEnergyInEE=jet->emEnergyInEE();
609     backJet_emEnergyInHF=jet->emEnergyInHF();
610     backJet_towersArea=jet->towersArea();
611     backJet_n90=jet->n90();
612     backJet_n60=jet->n60();
613     backJet_NbTracks=NbTracksInJet[jetCntr];
614    
615     jetTree->Fill();
616    
617     jetCntr++;
618     }
619     */
620    
621     float dPhi[3]={-1.0,-1.0,-1.0};
622     float dEta[3]={-1.0,-1.0,-1.0};
623     bool skipJet=false;
624    
625     for (int ct=0;ct<2;ct++) {
626     if (theZCandidate)
627     if (theZCandidate->daughter(ct)->pt()>0
628     && (abs(theZCandidate->daughter(ct)->pdgId())==13
629     || abs(theZCandidate->daughter(ct)->pdgId())==11) ) {
630     dPhi[ct]=fabs(theZCandidate->daughter(ct)->phi() - jet->phi());
631     dEta[ct]=fabs(theZCandidate->daughter(ct)->eta() - jet->eta());
632     }
633     }
634     if (theWlepton)
635     if (theWlepton->pt()>0 && (abs(theWlepton->pdgId())==13 || abs(theWlepton->pdgId())==11 )) {
636     dPhi[2]=fabs(theWlepton->phi() - jet->phi());
637     dEta[2]=fabs(theWlepton->eta() - jet->eta());
638     }
639     for (int k=0;k<3;k++) {
640     if (matchedLept[k] || dPhi[k]<0.0 || dEta[k]<0.0) continue;
641 smorovic 1.29
642     while (dPhi[k]>6.28318531) dPhi[k]-= 6.28318531;
643     if (dPhi[k]>3.14159265) dPhi[k]= 6.28318531-dPhi[k];
644    
645     float deltaR=sqrt(dPhi[k]*dPhi[k]+dEta[k]*dEta[k]);
646     if (deltaR<0.15) {
647     skipJet=true;
648     matchedLept[k]=true;
649     break;
650     }
651     }
652 beaucero 1.42 if(jet->pt() > 10 && fabs(jet->eta())<2.5 )NbJetsWithLeptons++;
653 vuko 1.49
654     if (skipJet || fabs(jet->eta()) > 3.) continue;
655    
656 beaucero 1.42 if(jet->pt() > 10 && fabs(jet->eta())<2.5 )NbJets++;
657 smorovic 1.29 }
658    
659 vuko 1.49 if (jet->et() > max_et ) {
660     if (leadingJet) {
661     secondJet = leadingJet;
662     max2_et = max_et;
663     }
664     leadingJet = &(*jet);
665     max_et = jet->et();
666    
667     } else {
668     if (jet->et() > max2_et ) {
669     secondJet = &(*jet);
670     max2_et = jet->et();
671     }
672     }
673 vuko 1.10 }
674 smorovic 1.52
675 vuko 1.10 if (leadingJet) {
676 smorovic 1.52 jet1Et = leadingJet->et();
677     jet1Phi = leadingJet->phi();
678     jet1Eta = leadingJet->eta();
679 vuko 1.10
680     } else {
681 smorovic 1.52 jet1Et = -10;
682     jet1Phi = 0.;
683     jet1Eta = 0.;
684 vuko 1.10 }
685 vuko 1.14 if (secondJet) {
686 smorovic 1.52 jet2Et = secondJet->et();
687     jet2Phi = secondJet->phi();
688     jet2Eta = secondJet->eta();
689 vuko 1.14 } else {
690 smorovic 1.52 jet2Et = -10;
691     jet2Phi = 0.;
692     jet2Eta = 0.;
693 vuko 1.14
694     }
695 senka 1.9
696 senka 1.12 // matching:
697    
698     matching(iEvent,looseMuonCands, 13);
699     matching(iEvent,looseElectronCands, 11);
700    
701 senka 1.13 getMother(&(*mccands)[1]);
702 vuko 1.10
703 smorovic 1.41 numberOfElectronTrees = 0;
704    
705     //count number of electron treee entries which will be added
706     for(CandidateCollection::const_iterator el = looseElectronCands->begin();
707     el != looseElectronCands->end(); ++ el ) {
708 smorovic 1.43 if (el->pt()>10 && fabs(el->eta())<2.5) {
709 smorovic 1.41 numberOfElectronTrees++;
710     }
711     }
712    
713 vuko 1.1 wzTree->Fill();
714    
715 vuko 1.20
716     // Fill electrons in a tree
717     for(CandidateCollection::const_iterator el = looseElectronCands->begin();
718     el != looseElectronCands->end(); ++ el ) {
719    
720     electronUse = 0;
721    
722     if (theZCandidate) {
723    
724     if (overlap(*theZCandidate, *el) ) {
725     electronUse = 23;
726     } else if (theWlepton) {
727     if (overlap(*theWlepton, *el) ) {
728     electronUse = 24;
729     }
730 smorovic 1.41 }
731 vuko 1.20 }
732 beaucero 1.42 if (el->pt()>10 && fabs(el->eta())<2.5) {
733     leptonProperties["electron"]->FillProperties(&(*el),
734     iEvent, iSetup,
735     MatchedGenParticle(&(*el)),dR(&(*el)));
736 smorovic 1.52
737     if (findBackJets) {
738    
739     backJet_found=0;
740     backJet_Et=0;
741     backJet_Eta=0;
742     backJet_Phi=0;
743     backJet_maxEInEmTowers=0;
744     backJet_maxEInHadTowers=0;
745     backJet_energyFractionHadronic=0;
746     backJet_emEnergyFraction=0;
747     backJet_hadEnergyInHB=0;
748     backJet_hadEnergyInHO=0;
749     backJet_hadEnergyInHE=0;
750     backJet_hadEnergyInHF=0;
751     backJet_emEnergyInEB=0;
752     backJet_emEnergyInEE=0;
753     backJet_emEnergyInHF=0;
754     backJet_towersArea=0;
755     backJet_n90=0;
756     backJet_n60=0;
757     backJet_NbTracks = 0;
758     backJet_match=0;
759     backJet_matchPt=0;
760     backJet_match_dR=-1.0;
761    
762     float oldDeltaPhi = -1.0;
763    
764     edm::Handle<reco::TrackCollection> BarrelKFTracks;
765     iEvent.getByLabel("ctfWithMaterialTracks",BarrelKFTracks);
766    
767     for (CaloJetCollection::const_iterator jet = jetCands->begin();
768     jet != jetCands->end(); jet++) {
769    
770     int NbTracksInJets = 0;
771    
772     for( reco::TrackCollection::const_iterator KFT = BarrelKFTracks->begin();KFT !=BarrelKFTracks->end(); ++ KFT ){
773    
774     double DPhi = fabs(KFT->phi()-jet->phi());
775     while (DPhi>6.28318531) DPhi-= 6.28318531;
776     if (DPhi>3.14159265) DPhi= 6.28318531-DPhi;
777    
778     double dR=sqrt( (KFT->eta() - jet->eta())*(KFT->eta() - jet->eta()) + DPhi*DPhi );
779    
780     if (KFT->pt()>2.0 && dR<0.3) NbTracksInJets++;
781    
782     //cout << "pass track eta:" << KFT->eta() << " pt " << KFT->pt() << " dr " << dR << endl;
783    
784     }
785    
786     if (NbTracksInJets<=3) continue;
787    
788     float dPhi = fabs(jet->phi()-el->phi());
789     while (dPhi>6.28318531) dPhi-=6.28318531;
790     if (dPhi>3.14159265) dPhi= 6.28318531-dPhi;
791     dPhi = 3.14159265 - dPhi;
792    
793     if (dPhi<0.7 && (dPhi<oldDeltaPhi || oldDeltaPhi<0.0)) {
794     oldDeltaPhi=dPhi;
795    
796     backJet_found=1;
797     backJet_Et=jet->et();
798     backJet_Eta=jet->eta();
799     backJet_Phi=jet->phi();
800     backJet_maxEInEmTowers=jet->maxEInEmTowers();
801     backJet_maxEInHadTowers=jet->maxEInHadTowers();
802     backJet_energyFractionHadronic=jet->energyFractionHadronic();
803     backJet_emEnergyFraction=jet->emEnergyFraction();
804     backJet_hadEnergyInHB=jet->hadEnergyInHB();
805     backJet_hadEnergyInHO=jet->hadEnergyInHO();
806     backJet_hadEnergyInHE=jet->hadEnergyInHE();
807     backJet_hadEnergyInHF=jet->hadEnergyInHF();
808     backJet_emEnergyInEB=jet->emEnergyInEB();
809     backJet_emEnergyInEE=jet->emEnergyInEE();
810     backJet_emEnergyInHF=jet->emEnergyInHF();
811     backJet_towersArea=jet->towersArea();
812     backJet_n90=jet->n90();
813     backJet_n60=jet->n60();
814     //fill variables
815     backJet_NbTracks = NbTracksInJets;
816    
817    
818     //find monte carlo electrons close to the jet
819    
820     float eDR = -1.0;
821     }
822     }
823     }
824    
825 beaucero 1.42 electronTree->Fill();
826    
827     }
828    
829 vuko 1.20 }
830    
831 smorovic 1.52 /* if (jetCands->size()>0)
832     delete NbTracksInJet;
833     */
834     EventCounter++;
835 vuko 1.1 }
836    
837    
838     // ------------ method called once each job just before starting event loop ------------
839     void
840     WZAnalyzer::beginJob(const edm::EventSetup&)
841     {
842    
843     using namespace wzana;
844    
845 senka 1.16 // theFile = new TFile( "wz.root", "RECREATE" ) ;
846     theFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
847    
848 vuko 1.1
849     wzTree = new TTree("WZTree","WZ informations");
850    
851 vuko 1.20 electronTree = new TTree("ElTree","electron informations");
852    
853 smorovic 1.52 // jetTree = new TTree("JetTree","jet deltaR information");
854    
855 vuko 1.20 leptonProperties["electron"] = new ElectronProperties();
856 vuko 1.1
857 vuko 1.3 leptonProperties["Wel"] = new ElectronProperties();
858     leptonProperties["ZEl1"] = new ElectronProperties();
859     leptonProperties["ZEl2"] = new ElectronProperties();
860    
861     leptonProperties["Wmu"] = new MuonProperties();
862     leptonProperties["Zmu1"] = new MuonProperties();
863     leptonProperties["Zmu2"] = new MuonProperties();
864 vuko 1.1
865 vuko 1.54 leptonProperties["Zmul"] = new MuonProperties(); // SAME COMMENT AS BELOW: TEMPORARY FIX
866 vuko 1.20
867 vuko 1.3 leptonProperties["Wel"]->CreateBranches(wzTree, "WEl_");
868 vuko 1.4 leptonProperties["ZEl1"]->CreateBranches(wzTree, "ZEl1_");
869     leptonProperties["ZEl2"]->CreateBranches(wzTree, "ZEl2_");
870 vuko 1.1
871 vuko 1.54 leptonProperties["Wmu"]->CreateBranches(wzTree, "Wmu_");
872 vuko 1.53
873 vuko 1.54 leptonProperties["Zmu1"]->CreateBranches(wzTree, "Zmu1_");
874 vuko 1.53 // Vuko's NOTE: there was type in the key "Zmul" instead of "Zmu1"
875     // ("L" instead of "one")
876     // I am fixing it but in order not to break everybody's root scripts
877     // I am adding the next line so we have both until all trees
878     // are contain "Zmu1"
879     // when that is the case, the next line can be dropped
880 vuko 1.54 leptonProperties["Zmul"]->CreateBranches(wzTree, "Zmul_");
881     leptonProperties["Zmu2"]->CreateBranches(wzTree, "Zmu2_");
882     leptonProperties["electron"]->CreateBranches(electronTree);
883 senka 1.9
884 vuko 1.1 initialiseTree();
885 smorovic 1.6
886     //prepare HLT TriggerResults branch
887     if (storeHLTresults) {
888     wzTree->Branch("WZ_hltBitmask",&triggerBitmask,"WZ_hltBitmask/I");
889 smorovic 1.52 wzTree->Branch("QCD_hltBitmask",&triggerBitmaskQCD,"QCD_hltBitmask/I");
890 smorovic 1.6
891     }
892 senka 1.9
893     // MET branch
894 senka 1.44 wzTree->Branch("MET_Et",&MET_energy,"MET_Et/F");
895 senka 1.9 wzTree->Branch("MET_pt",&MET_pt,"MET_pt/F");
896     wzTree->Branch("MET_eta",&MET_eta,"MET_eta/F");
897 vuko 1.50 wzTree->Branch("MET_phi",&MET_phi,"MET_eta/F");
898 senka 1.9 wzTree->Branch("dPhi_WlZ_reco",&dPhi_WlZ_reco,"dPhi_WlZ_reco/F");
899     wzTree->Branch("dPhi_WZ_reco",&dPhi_WZ_reco,"dPhi_WZ_reco/F");
900 kkaadze 1.55 wzTree->Branch("dPhi_Wl_MET",&dPhi_Wl_MET,"dPhi_Wl_MET/F");
901    
902     // MET branch after corrections
903     wzTree->Branch("MET_Et_SCCorr",&MET_Et_SCCorr,"MET_Et_SCCorr/F");
904     wzTree->Branch("MET_pt_SCCorr",&MET_pt_SCCorr,"MET_pt_SCCorr/F");
905     wzTree->Branch("MET_phi_SCCorr",&MET_phi_SCCorr,"MET_phi_SCCorr/F");
906     wzTree->Branch("dPhi_Wl_MET_SCCorr",&dPhi_Wl_MET_SCCorr,"dPhi_Wl_MET_SCCorr/F");
907    
908     wzTree->Branch("MET_Et_ElCorr",&MET_Et_ElCorr,"MET_Et_SCCorr/F");
909     wzTree->Branch("MET_pt_ElCorr",&MET_pt_ElCorr,"MET_pt_SCCorr/F");
910     wzTree->Branch("MET_phi_ElCorr",&MET_phi_ElCorr,"MET_phi_SCCorr/F");
911     wzTree->Branch("dPhi_Wl_MET_ElCorr",&dPhi_Wl_MET_ElCorr,"dPhi_Wl_MET_ElCorr/F");
912    
913 senka 1.27
914     // # of non overlaping Zs
915     wzTree->Branch("N_nonOverlaping_Z",&n,"N_nonOverlaping_Z/I");
916     wzTree->Branch("N_looseMuons",&N_looseMuons,"N_looseMuons/I");
917     wzTree->Branch("N_looseElectrons",&N_looseElectrons,"N_looseElectrons/I");
918    
919 smorovic 1.52
920     EventCounter=0;
921 vuko 1.1 }
922    
923     // ------------ method called once each job just after ending the event loop ------------
924     void
925     WZAnalyzer::endJob() {
926    
927     theFile->Write();
928     theFile->Close();
929    
930     }
931    
932    
933     void WZAnalyzer::initialiseTree() {
934 vuko 1.26 // Event properties
935     wzTree->Branch("weight", &eventWeight, "weight/F");
936 smorovic 1.31 wzTree->Branch("processID", &processID, "processID/I");
937 smorovic 1.36 wzTree->Branch("alpgenID", &alpgenID, "alpgenID/I");
938 smorovic 1.48 wzTree->Branch("genEventScale", &eventScale, "genEventScale/F");
939 smorovic 1.41 wzTree->Branch("RunNumber", &RunNumber, "RunNumber/I");
940     wzTree->Branch("EventID", &EventID, "EventID/I");
941 vuko 1.26
942 vuko 1.1 // Z properties
943     wzTree->Branch("Zmass", &zMass, "Zmass/F");
944     wzTree->Branch("ZId", &zFlavour, "Zid/I");
945     wzTree->Branch("ZPt", &zPt, "ZPt/F");
946     wzTree->Branch("ZEta", &zEta, "ZEta/F");
947     wzTree->Branch("ZPhi", &zPhi, "ZPhi/F");
948    
949     // W Properties
950     wzTree->Branch("WlId", &wlFlavour, "Wlid/I");
951     wzTree->Branch("WlCharge", &wlCharge, "WlCharge/I");
952     wzTree->Branch("WlPt", &wlPt, "WlPt/F");
953 vuko 1.50
954     wzTree->Branch("nwlelcand", &nWlElCand, "nwlelcand/I");
955     wzTree->Branch("nwlmucand", &nWlMuCand, "nwlmucand/I");
956    
957 smorovic 1.8
958     wzTree->Branch("MC_leptonZ1_pt", &MCleptZ1_pt,"MC_leptonZ1_pt/F");
959     wzTree->Branch("MC_leptonZ2_pt", &MCleptZ2_pt,"MC_leptonZ2_pt/F");
960     wzTree->Branch("MC_leptonW_pt", &MCleptW_pt, "MC_leptonW_pt/F");
961    
962     wzTree->Branch("MC_leptonZ1_eta", &MCleptZ1_eta,"MC_leptonZ1_eta/F");
963     wzTree->Branch("MC_leptonZ2_eta", &MCleptZ2_eta,"MC_leptonZ2_eta/F");
964     wzTree->Branch("MC_leptonW_eta", &MCleptW_eta, "MC_leptonW_eta/F");
965    
966     wzTree->Branch("MC_leptonZ1_phi", &MCleptZ1_phi,"MC_leptonZ1_phi/F");
967     wzTree->Branch("MC_leptonZ2_phi", &MCleptZ2_phi,"MC_leptonZ2_phi/F");
968     wzTree->Branch("MC_leptonW_phi", &MCleptW_phi, "MC_leptonW_phi/F");
969    
970     wzTree->Branch("MC_leptonZ1_pdgid", &MCleptZ1_pdgid,"MC_leptonZ1_pdgid/I");
971     wzTree->Branch("MC_leptonZ2_pdgid", &MCleptZ2_pdgid,"MC_leptonZ2_pdgid/I");
972     wzTree->Branch("MC_leptonW_pdgid", &MCleptW_pdgid, "MC_leptonW_pdgid/I");
973 vuko 1.14
974     /*
975     wzTree->Branch("MC_leptonW_origin", &MCleptW_pdgid, "MC_leptonW_origin/I");
976     wzTree->Branch("MC_leptonZ1_origin", &MCleptW_pdgid, "MC_leptonZ1_origin/I");
977     wzTree->Branch("MC_leptonZ2_origin", &MCleptW_pdgid, "MC_leptonZ2_origin/I");
978     */
979    
980 smorovic 1.8 wzTree->Branch("MC_TauDecayType_fromZ1", &MC_tauDecayTypeZ1,"MC_TauDecayType_fromZ1/I");
981     wzTree->Branch("MC_TauDecayType_fromZ2", &MC_tauDecayTypeZ2,"MC_TauDecayType_fromZ2/I");
982     wzTree->Branch("MC_TauDecayType_fromW", &MC_tauDecayTypeW, "MC_TauDecayType_fromW/I");
983 vuko 1.10
984     // MET properties
985    
986     // Jet properties
987 smorovic 1.41 wzTree->Branch("NbJets", &NbJets, "NbJets/I");
988 vuko 1.49 wzTree->Branch("NCaloJets", &NCaloJets,"NCaloJets/I");
989 smorovic 1.41
990 vuko 1.10 wzTree->Branch("Jet1Et", &jet1Et, "Jet1Et/F");
991     wzTree->Branch("Jet1Phi", &jet1Phi, "Jet1Phi/F");
992     wzTree->Branch("Jet1Eta", &jet1Eta, "Jet1Eta/F");
993    
994     wzTree->Branch("Jet2Et", &jet2Et, "Jet2Et/F");
995     wzTree->Branch("Jet2Phi", &jet2Phi, "Jet2Phi/F");
996     wzTree->Branch("Jet2Eta", &jet2Eta, "Jet2Eta/F");
997 smorovic 1.41 wzTree->Branch("ElectronTreesInEvent", &numberOfElectronTrees, "ElectronTreesInEvent/I");
998 smorovic 1.52 wzTree->Branch("EventCounter", &EventCounter, "EventCounter/I");
999 vuko 1.20 //
1000     electronTree->Branch("used", &electronUse, "used/I");
1001 smorovic 1.40 electronTree->Branch("weight", &eventWeight, "weight/F");
1002     electronTree->Branch("processID", &processID, "processID/I");
1003     electronTree->Branch("alpgenID", &alpgenID, "alpgenID/I");
1004 smorovic 1.48 electronTree->Branch("genEventScale", &eventScale, "genEventScale/F");
1005 smorovic 1.41 electronTree->Branch("ElectronTreesInEvent", &numberOfElectronTrees, "ElectronTreesInEvent/I");
1006    
1007     electronTree->Branch("RunNumber", &RunNumber, "RunNumber/I");
1008     electronTree->Branch("EventID", &EventID, "EventID/I");
1009 smorovic 1.52 electronTree->Branch("EventCounter", &EventCounter, "EventCounter/I");
1010 beaucero 1.42 electronTree->Branch("NbJetsWithLeptons", &NbJetsWithLeptons, "NbJetsWithLeptons/I");
1011 smorovic 1.52
1012     if (findBackJets) {
1013     electronTree->Branch("MET_Et",&MET_energy,"MET_Et/F");
1014     electronTree->Branch("MET_pt",&MET_pt,"MET_pt/F");
1015     electronTree->Branch("MET_eta",&MET_eta,"MET_eta/F");
1016    
1017     electronTree->Branch("backJet_found",&backJet_found,"backJet_found/I");
1018     electronTree->Branch("backJet_Et",&backJet_Et,"backJet_Et/F");
1019     electronTree->Branch("backJet_Eta",&backJet_Eta,"backJet_Eta/F");
1020     electronTree->Branch("backJet_Phi",&backJet_Phi,"backJet_Phi/F");
1021     electronTree->Branch("backJet_maxEInEmTowers",&backJet_maxEInEmTowers,"backJet_maxEInEmTowers/F");
1022     electronTree->Branch("backJet_maxEInHadTowers",&backJet_maxEInHadTowers,"backJet_maxEInHadTowers/F");
1023     electronTree->Branch("backJet_energyFractionHadronic",&backJet_energyFractionHadronic,"backJet_energyFractionHadronic/F");
1024     electronTree->Branch("backJet_emEnergyFraction",&backJet_emEnergyFraction,"backJet_emEnergyFraction/F");
1025     electronTree->Branch("backJet_hadEnergyInHB",&backJet_hadEnergyInHB,"backJet_hadEnergyInHB/F");
1026     electronTree->Branch("backJet_hadEnergyInHO",&backJet_hadEnergyInHO,"backJet_hadEnergyInHO/F");
1027     electronTree->Branch("backJet_hadEnergyInHE",&backJet_hadEnergyInHE,"backJet_hadEnergyInHE/F");
1028     electronTree->Branch("backJet_hadEnergyInHF",&backJet_hadEnergyInHF,"backJet_hadEnergyInHF/F");
1029     electronTree->Branch("backJet_emEnergyInEB",&backJet_emEnergyInEB,"backJet_emEnergyInEB/F");
1030     electronTree->Branch("backJet_emEnergyInEE",&backJet_emEnergyInEE,"backJet_emEnergyInEE/F");
1031     electronTree->Branch("backJet_emEnergyInHF",&backJet_emEnergyInHF,"backJet_emEnergyInHF/F");
1032     electronTree->Branch("backJet_towersArea",&backJet_towersArea,"backJet_towersArea/F");
1033     electronTree->Branch("backJet_n90",&backJet_n90,"backJet_n90/F");
1034     electronTree->Branch("backJet_n60",&backJet_n60,"backJet_n60/F");
1035    
1036     electronTree->Branch("backJet_NbTracks",&backJet_NbTracks,"backJet_NbTracks/I");
1037    
1038     electronTree->Branch("backJet_match",&backJet_match,"backJet_match/I");
1039     electronTree->Branch("backJet_matchPt",&backJet_matchPt,"backJet_matchPt/F");
1040     electronTree->Branch("backJet_match_dR",&backJet_match_dR,"backJet_match_dR/F");
1041    
1042    
1043    
1044     /*
1045     //define Jet Tree
1046     for (int icone=0; icone<wzana::ElectronProperties::nr_dr_cones; icone++) {
1047     int drcone = lroundf(100*wzana::ElectronProperties::DR_Cone_Limits[icone]);
1048     ostringstream os;
1049     os << "0";
1050     if (drcone<10) os << "0";
1051     os << drcone;
1052    
1053     std::string suffix2 = os.str();
1054    
1055     jetTree->Branch(("jet_IsoTrackDR_"+suffix2).c_str(),&IsoTrack[icone],("jet_IsoTrackDRi_"+suffix2+"/F").c_str());
1056     jetTree->Branch(("jet_NbTracks_"+suffix2).c_str(),&NbTracks[icone],("jet_NbTracks_"+suffix2+"/I").c_str());
1057     }
1058    
1059    
1060     jetTree->Branch("backJet_Et",&backJet_Et,"backJet_Et/F");
1061     jetTree->Branch("backJet_Eta",&backJet_Eta,"backJet_Eta/F");
1062     jetTree->Branch("backJet_Phi",&backJet_Phi,"backJet_Phi/F");
1063     jetTree->Branch("backJet_maxEInEmTowers",&backJet_maxEInEmTowers,"backJet_maxEInEmTowers/F");
1064     jetTree->Branch("backJet_maxEInHadTowers",&backJet_maxEInHadTowers,"backJet_maxEInHadTowers/F");
1065     jetTree->Branch("backJet_energyFractionHadronic",&backJet_energyFractionHadronic,"backJet_energyFractionHadronic/F");
1066     jetTree->Branch("backJet_emEnergyFraction",&backJet_emEnergyFraction,"backJet_emEnergyFraction/F");
1067     jetTree->Branch("backJet_hadEnergyInHB",&backJet_hadEnergyInHB,"backJet_hadEnergyInHB/F");
1068     jetTree->Branch("backJet_hadEnergyInHO",&backJet_hadEnergyInHO,"backJet_hadEnergyInHO/F");
1069     jetTree->Branch("backJet_hadEnergyInHE",&backJet_hadEnergyInHE,"backJet_hadEnergyInHE/F");
1070     jetTree->Branch("backJet_hadEnergyInHF",&backJet_hadEnergyInHF,"backJet_hadEnergyInHF/F");
1071     jetTree->Branch("backJet_emEnergyInEB",&backJet_emEnergyInEB,"backJet_emEnergyInEB/F");
1072     jetTree->Branch("backJet_emEnergyInEE",&backJet_emEnergyInEE,"backJet_emEnergyInEE/F");
1073     jetTree->Branch("backJet_emEnergyInHF",&backJet_emEnergyInHF,"backJet_emEnergyInHF/F");
1074     jetTree->Branch("backJet_towersArea",&backJet_towersArea,"backJet_towersArea/F");
1075     jetTree->Branch("backJet_n90",&backJet_n90,"backJet_n90/F");
1076     jetTree->Branch("backJet_n60",&backJet_n60,"backJet_n60/F");
1077     jetTree->Branch("backJet_NbTracks",&backJet_NbTracks,"backJet_NbTracks/I");
1078     jetTree->Branch("EventCounter", &EventCounter, "EventCounter/I");
1079     */
1080     }
1081 vuko 1.50
1082     electronTree->Branch("WZ_hltBitmask",&triggerBitmask,"WZ_hltBitmask/I");
1083 smorovic 1.52 electronTree->Branch("QCD_hltBitmask",&triggerBitmaskQCD,"QCD_hltBitmask/I");
1084 smorovic 1.8 }
1085 vuko 1.1
1086 senka 1.9
1087 senka 1.28 //////////////////////////////////////////
1088     // MET & MET corrections
1089     // MET=MET-sum_p(muons)-sum_p(muons calos depositions)
1090    
1091     reco::Particle::LorentzVector WZAnalyzer::computeMET(const edm::Event& iEvent, const edm::EventSetup& iSetup, Handle<reco::CandidateCollection> MuonCands) {
1092 senka 1.9
1093     using namespace edm;
1094     using namespace reco;
1095     using namespace std;
1096 senka 1.44
1097 beaucero 1.45 double px_MET=0, py_MET=0, Ex_MET=0, Ey_MET=0;
1098 senka 1.44 double px,py,pz,pt,Et,Ex,Ey;
1099     double px_muons=0;
1100     double py_muons=0;
1101     double Ex_muons=0;
1102     double Ey_muons=0;
1103     double Et_muons=0;
1104     double Et_ecal;
1105     double Et_hcal;
1106     double Et_ho;
1107     double Et_cal;
1108     double Ex_ecal;
1109     double Ex_hcal;
1110     double Ex_ho;
1111     double Ey_ecal;
1112     double Ey_hcal;
1113     double Ey_ho;
1114     double eta_cal;
1115     double phi_cal;
1116     double tg_theta_pola_ecal;
1117     double tg_theta_pola_hcal;
1118     double tg_theta_pola_ho;
1119     double tg_theta_ecal;
1120     double tg_theta_hcal;
1121     double tg_theta_ho;
1122     double E_ecal;
1123     double E_hcal;
1124     double E_ho;
1125     double me=0.0005;
1126     double sin_theta_ecal, sin_theta_hcal, sin_theta_ho, cos_theta_ecal,cos_theta_hcal,cos_theta_ho;
1127     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;
1128     double Ex_cal=0;
1129     double Ey_cal=0;
1130     double px_cal=0;
1131     double py_cal=0;
1132     double Ex_kon=0;
1133     double Ey_kon=0;
1134    
1135     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
1136     reco::Particle::LorentzVector Muon_p_cal_4v(0,0,0,0);
1137 senka 1.9
1138     Handle<CaloMETCollection> mets;
1139     iEvent.getByLabel("met", mets);
1140 vuko 1.25 // cout << "# METs=" << mets->size() << endl;
1141 senka 1.44
1142 vuko 1.25 if (mets->size() != 1) {
1143 senka 1.44 cout << "ALARM: # METS is not 1: !" << endl;
1144 vuko 1.25 return reco::Particle::LorentzVector(0.,0.,0.,0.);
1145     }
1146 senka 1.44
1147 vuko 1.14 for (CaloMETCollection::const_iterator met = mets->begin();
1148     met!= mets->end(); met++) {
1149 senka 1.44 px_MET=met->px();
1150     py_MET=met->py();
1151     Ex_MET=met->et()*TMath::Cos(met->phi());
1152     Ey_MET=met->et()*TMath::Sin(met->phi());
1153    
1154 vuko 1.14 }
1155 senka 1.44
1156     // sum of p of muons
1157     for (unsigned int i=0; i<MuonCands->size();i++){
1158     px=(*MuonCands)[i].px();
1159     py=(*MuonCands)[i].py();
1160     pz=(*MuonCands)[i].pz();
1161     pt=(*MuonCands)[i].pt();
1162     Et=(*MuonCands)[i].et();
1163     Ex=Et*TMath::Cos((*MuonCands)[i].phi());
1164     Ey=Et*TMath::Sin((*MuonCands)[i].phi());
1165     px_muons=px_muons+px;
1166     py_muons=py_muons+py;
1167     Ex_muons=Ex_muons+Ex;
1168     Ey_muons=Ey_muons+Ey;
1169    
1170     }
1171     Et_muons=TMath::Sqrt(Ex_muons*Ex_muons+Ey_muons*Ey_muons);
1172     Muon_p_4v=reco::Particle::LorentzVector(px_muons,py_muons,0,Et_muons);
1173    
1174     // sum of p of muons left in calorimeters
1175     for (unsigned int i=0; i<MuonCands->size();i++){
1176     cout<<"" << endl;
1177     const reco::Muon* muons=dynamic_cast<const reco::Muon *> (&(*MuonCands)[i]);
1178     Et_ecal=muons->getCalEnergy().emS9;
1179     Et_hcal=muons->getCalEnergy().hadS9;
1180     Et_ho=muons->getCalEnergy().hoS9;
1181     eta_cal=muons->eta();
1182     phi_cal=muons->phi();
1183     tg_theta_pola_ecal=TMath::Exp(-eta_cal);
1184     tg_theta_pola_hcal=TMath::Exp(-eta_cal);
1185     tg_theta_pola_ho=TMath::Exp(-eta_cal);
1186     tg_theta_ecal=2*tg_theta_pola_ecal/(1-tg_theta_pola_ecal*tg_theta_pola_ecal);
1187     tg_theta_hcal=2*tg_theta_pola_hcal/(1-tg_theta_pola_hcal*tg_theta_pola_hcal);
1188     tg_theta_ho=2*tg_theta_pola_ho/(1-tg_theta_pola_ho*tg_theta_pola_ho);
1189     E_ecal=TMath::Abs(Et_ecal*TMath::Sqrt(1+tg_theta_ecal*tg_theta_ecal)/tg_theta_ecal);
1190     E_hcal=TMath::Abs(Et_hcal*TMath::Sqrt(1+tg_theta_hcal*tg_theta_hcal)/tg_theta_hcal);
1191     E_ho=TMath::Abs(Et_ho*TMath::Sqrt(1+tg_theta_ho*tg_theta_ho)/tg_theta_ho);
1192     Ex_ecal=Et_ecal*TMath::Cos(phi_cal);
1193     Ex_hcal=Et_hcal*TMath::Cos(phi_cal);
1194     Ex_ho=Et_ho*TMath::Cos(phi_cal);
1195     Ey_ecal=Et_ecal*TMath::Sin(phi_cal);
1196     Ey_hcal=Et_hcal*TMath::Sin(phi_cal);
1197     Ey_ho=Et_ho*TMath::Sin(phi_cal);
1198     sin_theta_ecal=tg_theta_ecal/TMath::Sqrt(1+tg_theta_ecal*tg_theta_ecal);
1199     sin_theta_hcal=tg_theta_hcal/TMath::Sqrt(1+tg_theta_hcal*tg_theta_hcal);
1200     sin_theta_ho=tg_theta_ho/TMath::Sqrt(1+tg_theta_ho*tg_theta_ho);
1201     cos_theta_ecal=TMath::Sqrt(1-sin_theta_ecal*sin_theta_ecal);
1202     cos_theta_hcal=TMath::Sqrt(1-sin_theta_hcal*sin_theta_hcal);
1203     cos_theta_ho=TMath::Sqrt(1-sin_theta_ho*sin_theta_ho);
1204     if (E_ecal<me){
1205     p_ecal=0;
1206     }
1207     else {
1208     p_ecal=TMath::Sqrt(E_ecal*E_ecal-me*me);
1209     }
1210     if (E_hcal<me){
1211     p_hcal=0;
1212     }
1213     else {
1214     p_hcal=TMath::Sqrt(E_hcal*E_hcal-me*me);
1215     }
1216     if (E_ho<me){
1217     p_ho=0;
1218     }
1219     else {
1220     p_ho=TMath::Sqrt(E_ho*E_ho-me*me);
1221     }
1222 senka 1.28
1223 senka 1.44 pz_ecal=p_ecal*cos_theta_ecal;
1224     pz_hcal=p_hcal*cos_theta_hcal;
1225     pz_ho=p_ho*cos_theta_ho;
1226     pt_ecal=TMath::Abs(p_ecal*sin_theta_ecal);
1227 senka 1.33
1228 senka 1.44 pt_hcal=TMath::Abs(p_hcal*sin_theta_hcal);
1229    
1230     pt_ho=TMath::Abs(p_ho*sin_theta_ho);
1231    
1232     px_ecal=pt_ecal*TMath::Cos(phi_cal);
1233     px_hcal=pt_hcal*TMath::Cos(phi_cal);
1234     px_ho=pt_ho*TMath::Cos(phi_cal);
1235     py_ecal=pt_ecal*TMath::Sin(phi_cal);
1236     py_hcal=pt_hcal*TMath::Sin(phi_cal);
1237     py_ho=pt_ho*TMath::Sin(phi_cal);
1238 senka 1.28
1239 senka 1.44
1240     Ex_cal=Ex_cal+Ex_ecal+Ex_hcal+Ex_ho;
1241     Ey_cal=Ey_cal+Ey_ecal+Ey_hcal+Ey_ho;
1242    
1243     px_cal=px_cal+px_ecal+px_hcal+px_ho;
1244     py_cal=py_cal+py_ecal+py_hcal+py_ho;
1245    
1246 senka 1.28
1247 senka 1.44 }
1248     Et_cal=TMath::Sqrt(Ex_cal*Ex_cal+Ey_cal*Ey_cal);
1249     Muon_p_cal_4v=reco::Particle::LorentzVector(px_cal,py_cal,0, Et_cal);
1250 senka 1.33
1251 senka 1.44 Ex_kon=Ex_MET-Ex_muons+Ex_cal;
1252     Ey_kon=Ey_MET-Ey_muons+Ey_cal;
1253 senka 1.28
1254 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
1255 senka 1.28
1256     return MET;
1257 senka 1.9
1258     }
1259    
1260 kkaadze 1.55 //MET Corrections from difference between corrected and uncorretced SC
1261     reco::Particle::LorentzVector WZAnalyzer::correctMETforSCCorrection(reco::Particle::LorentzVector MET_p_4v, Handle<reco::CandidateCollection> ElectronCands) {
1262    
1263     double SCRawEnergy = 0;
1264     double SCEnergy = 0;
1265     double deltaE = 0;
1266     double deltaET = 0;
1267     double deltaEx = 0;
1268     double deltaEy = 0;
1269    
1270     reco::Particle::LorentzVector SCCorr_p_4v(0,0,0,0); // sum of correction fraction of ET in (px,py,0,Et)
1271    
1272     //Loop over electron candidates and obtain the difference between uncorr and corr SC
1273     for (unsigned int i =0; i<ElectronCands->size(); ++i) {
1274     const reco::PixelMatchGsfElectron * electron = 0;
1275     if ( (*ElectronCands)[i].hasMasterClone() ) {
1276     reco::CandidateBaseRef master = (*ElectronCands)[i].masterClone();
1277     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*master));
1278     } else {
1279     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*ElectronCands)[i]);
1280     }
1281     const reco::SuperCluster& ElSC = *(electron->superCluster());
1282     SCRawEnergy = ElSC.rawEnergy();
1283     SCEnergy = ElSC.energy();
1284     //b.c. both uncrected and corrected SC clusters are oriented the same way, difference between vectors is just magnitudinal.
1285     deltaE = SCEnergy - SCRawEnergy;
1286     deltaET = deltaE/cosh(ElSC.eta());
1287     deltaEx += deltaET*cos(ElSC.phi());
1288     deltaEy += deltaET*sin(ElSC.phi());
1289     }
1290    
1291     deltaET = 0;
1292     deltaET = sqrt(deltaEx*deltaEx + deltaEy*deltaEy);
1293     SCCorr_p_4v = reco::Particle::LorentzVector(deltaEx, deltaEy, 0, deltaET);
1294     // return SCCorr_p_4v;
1295     return (MET_p_4v - SCCorr_p_4v);
1296     }
1297    
1298    
1299     //MET Corrections from difference between el energy and rawenergy of SC
1300     reco::Particle::LorentzVector WZAnalyzer::correctMETforElCorrection(reco::Particle::LorentzVector MET_p_4v, Handle<reco::CandidateCollection> ElectronCands) {
1301    
1302     double px = 0;
1303     double py = 0;
1304     double pz = 0;
1305     double Ex = 0;
1306     double Ey = 0;
1307     double Et = 0;
1308     double SCRawEnergy = 0;
1309     double SCPt = 0;
1310     double SCEt = 0;
1311     double SCpx = 0;
1312     double SCpy = 0;
1313     double SCEx = 0;
1314     double SCEy = 0;
1315    
1316     const reco::PixelMatchGsfElectron * electron = 0;
1317    
1318     reco::Particle::LorentzVector El_p_4v(0,0,0,0); // in (px,py,0,Et)
1319     reco::Particle::LorentzVector SC_p_4v(0,0,0,0);
1320    
1321     //Loop over electron candidates and obtain the difference between uncorr and corr SC
1322     for (unsigned int i =0; i<ElectronCands->size(); ++i) {
1323    
1324     px += (*ElectronCands)[i].px();
1325     py += (*ElectronCands)[i].py();
1326     pz += (*ElectronCands)[i].pz();
1327     Ex += (*ElectronCands)[i].et()*cos((*ElectronCands)[i].phi());
1328     Ey += (*ElectronCands)[i].et()*sin((*ElectronCands)[i].phi());
1329    
1330     if ( (*ElectronCands)[i].hasMasterClone() ) {
1331     reco::CandidateBaseRef master = (*ElectronCands)[i].masterClone();
1332     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*master));
1333     } else {
1334     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*ElectronCands)[i]);
1335     }
1336     const reco::SuperCluster& ElSC = *(electron->superCluster());
1337     SCRawEnergy = ElSC.rawEnergy();
1338     SCPt = SCRawEnergy/cosh(ElSC.eta());
1339     SCEt = SCRawEnergy/cosh(ElSC.eta());
1340     SCpx += SCPt*cos(ElSC.phi());
1341     SCpy += SCPt*sin(ElSC.phi());
1342     SCEx += SCEt*cos(ElSC.phi());
1343     SCEy += SCEt*sin(ElSC.phi());
1344     }
1345    
1346     Et = sqrt(Ex*Ex + Ey*Ey);
1347     El_p_4v = reco::Particle::LorentzVector(px,py,0,Et);
1348    
1349     SCEt = sqrt(SCEx*SCEx + SCEy * SCEy);
1350     SC_p_4v = reco::Particle::LorentzVector(SCpx,SCpy,0,SCEt);
1351    
1352     reco::Particle::LorentzVector ElCorr_p_4v = El_p_4v - SC_p_4v;
1353     return (MET_p_4v - ElCorr_p_4v);
1354     }
1355    
1356    
1357    
1358 senka 1.12 ////////////////////////
1359     // matching
1360     //
1361    
1362     class MatchingInfo {
1363     public:
1364    
1365     MatchingInfo(float dr, int gen, int reco) : deltaR(dr), genMuon(gen),recoMuon(reco) {}
1366    
1367     bool operator<(const MatchingInfo m) { return deltaR < m.deltaR;}
1368    
1369     float deltaR;
1370     int genMuon;
1371     int recoMuon;
1372    
1373     };
1374    
1375    
1376     bool betterMatch(MatchingInfo m1, MatchingInfo m2)
1377     { return m1.deltaR < m2.deltaR;}
1378    
1379    
1380     // method that gives the vector<MatchingInfo> matching_Infos containing (dR,i,j); i=genParticle index, j=ParticleCollection index:
1381    
1382     void WZAnalyzer::matching(const edm::Event& iEvent, Handle<reco::CandidateCollection> cands, int pdgid){
1383    
1384     using namespace edm;
1385     using namespace reco;
1386     using namespace std;
1387    
1388     //-------------------------
1389     Handle<CandidateCollection> mccands;
1390     iEvent.getByLabel( theMCTruthCollection,mccands );
1391    
1392     vector <GenParticleCandidate*> genparticles;
1393    
1394     for(CandidateCollection::const_iterator p = mccands->begin();
1395     p != mccands->end(); p++) {
1396    
1397     // reco::Candidate* p_tmp = &(*p);
1398     reco::GenParticleCandidate* ptr = (reco::GenParticleCandidate*) &(*p);
1399    
1400     if ( (ptr)->status() == 1
1401     /*&& (ptr)->momentum().perp() > 2.*/ ) { // stable particles with pt>2 only
1402     if ( abs((ptr)->pdgId()) == pdgid ) {
1403     genparticles.push_back((ptr));
1404     //cout << "electron MCT\n";
1405     }
1406     }
1407     }
1408    
1409    
1410     int n1=0;
1411     vector<MatchingInfo> matching_Infos;
1412     for ( unsigned int i=0; i<genparticles.size(); i++ ) // po svim MC muonima
1413     {
1414    
1415     for (unsigned int j = 0; j < cands->size(); j++)// po svim reco muonima
1416     {
1417    
1418     double d_eta2=(*cands)[j].eta()-(genparticles)[i]->eta();
1419     double d_phi=fabs((*cands)[j].phi()-(genparticles)[i]->phi());
1420     double dR_byhand= sqrt(d_eta2*d_eta2+d_phi*d_phi);
1421     double dR=dR_byhand;
1422    
1423     if (dR<0.15){
1424     n1++;
1425     matching_Infos.push_back(MatchingInfo(dR,i,j));
1426     }
1427    
1428     }
1429     }
1430 senka 1.24
1431 senka 1.12 sort(matching_Infos.begin(),matching_Infos.end(),betterMatch); // sorting (dR,i,j)
1432 senka 1.24
1433     if (genparticles.size()!=0 && cands->size()!=0){
1434     // Now exclude combinations using same gen or rec muons
1435     for (std::vector<MatchingInfo>::iterator it=matching_Infos.begin();
1436     it != matching_Infos.end(); it++) {
1437     for (std::vector<MatchingInfo>::iterator it2=matching_Infos.begin();
1438     it2!=it; it2++) {
1439     if ( (it->genMuon == it2->genMuon) || (it->recoMuon == it2->recoMuon) ) {
1440     matching_Infos.erase(it);
1441     it=matching_Infos.begin();
1442     break;
1443     }
1444     }
1445     }
1446     }
1447    
1448 vuko 1.14 // Now put result in vector of pairs
1449    
1450     leptonMatching[pdgid].clear();
1451    
1452     for (vector<MatchingInfo>::iterator match=matching_Infos.begin();
1453 senka 1.16 match !=matching_Infos.end(); match++) { // po tablici dr,i,j
1454 vuko 1.14
1455     pair<const GenParticleCandidate*, const reco::Candidate *> pair;
1456 senka 1.16 // vector<pair,float > matchedParticles;
1457 vuko 1.14 pair.first = genparticles[match->genMuon];
1458     pair.second = & (*cands)[match->recoMuon];
1459 senka 1.16
1460     matchedParticles cestice(genparticles[match->genMuon] ,& (*cands)[match->recoMuon] , match->deltaR);
1461    
1462     leptonMatching[pdgid].push_back(cestice);
1463 senka 1.24
1464 vuko 1.14 }
1465 senka 1.24
1466 senka 1.12 }
1467    
1468 senka 1.9
1469 senka 1.13 // get mother of particle
1470     // returns mother = 1 if mother is Z boson
1471     // returns mother = 2 if mother is W boson
1472     // returns mother = 4 if mother is b
1473     // returns mother = 0 else
1474    
1475 vuko 1.14 WZAnalyzer::LeptonOrigin WZAnalyzer::getMother(const reco::Candidate* genParticle){
1476    
1477     int pdg_id=genParticle->pdgId();
1478 vuko 1.25 // cout << "particle id : " << pdg_id << endl;
1479 senka 1.13
1480     while (genParticle = genParticle->mother() ) { //izvrsava se sve dok ne dodje do nule tj. dok ne trazi majku od protona
1481 vuko 1.25 // cout << "Going up: ";
1482     // cout << "Mother id : " << genParticle->pdgId() << endl;
1483 senka 1.24 if (abs(genParticle->pdgId())!=abs(pdg_id)) {
1484 vuko 1.25 // cout<< " good mother " <<endl;
1485 senka 1.13 if (abs(genParticle->pdgId())==23){ // mother is Z
1486 vuko 1.14 return zboson;
1487 senka 1.13 }
1488     if (abs(genParticle->pdgId())==24) { // mother is W
1489 vuko 1.14 return wboson;
1490 senka 1.13 }
1491     // if (abs(genParticle->pdgId())==23 || abs(genParticle->pdgId())==24) { // mother is W or Z
1492     // WZ_matched=1;
1493     // mother=3;
1494     // }
1495     if ((((abs(genParticle->pdgId()))/100)%10 ==5)||(((abs(genParticle->pdgId()))/1000)%10 ==5 )) { // mother is b
1496 vuko 1.14 return bdecay;
1497 senka 1.13 }
1498 vuko 1.14 if ((((abs(genParticle->pdgId()))/100)%10 ==4)||(((abs(genParticle->pdgId()))/1000)%10 ==4 )) { // mother is c
1499     return cdecay;
1500     }
1501     return other;
1502 senka 1.13 }
1503 vuko 1.20 }
1504    
1505     return other;
1506 senka 1.13 }
1507    
1508 senka 1.15 const reco::Candidate * WZAnalyzer::MatchedGenParticle(const reco::Candidate * daughter){
1509     ::OverlapChecker overlap;
1510     matched_genParticle=0;
1511 senka 1.16
1512     for (map< int,
1513     std::vector< matchedParticles > > ::iterator iter = leptonMatching.begin();
1514     iter!=leptonMatching.end(); iter++) // entire map
1515     {
1516 vuko 1.20 for (unsigned int j=0; j<iter->second.size(); j++){ // entire vector<class<>>
1517 senka 1.16 const reco::Candidate * nesto=iter->second[j].pair.second;
1518     if (overlap(*nesto,*daughter)){
1519     matched_genParticle=iter->second[j].pair.first;
1520     }
1521     }
1522     }
1523     return matched_genParticle;
1524     }
1525    
1526    
1527     float WZAnalyzer::dR(const reco::Candidate * daughter){
1528 vuko 1.18
1529 senka 1.16 ::OverlapChecker overlap;
1530 vuko 1.18
1531 senka 1.19 float delta_r = -10;
1532 senka 1.15 for (map< int,
1533 senka 1.16 std::vector< matchedParticles > > ::iterator iter = leptonMatching.begin();
1534 senka 1.15 iter!=leptonMatching.end(); iter++) // entire map
1535     {
1536 vuko 1.20 for (unsigned int j=0; j<iter->second.size(); j++){ // entire vector<class<>>
1537 senka 1.16 const reco::Candidate * nesto=iter->second[j].pair.second;
1538 senka 1.15 if (overlap(*nesto,*daughter)){
1539 senka 1.16 delta_r=iter->second[j].delta_R;
1540 senka 1.15 }
1541     }
1542     }
1543 senka 1.16 return delta_r;
1544 senka 1.15 }
1545    
1546 vuko 1.11
1547 senka 1.16
1548 vuko 1.10 void WZAnalyzer::collectMCsummary(Handle <reco::CandidateCollection> mccands) {
1549 senka 1.12
1550 vuko 1.11 using namespace reco;
1551    
1552 smorovic 1.8 //collections
1553 senka 1.24
1554 smorovic 1.8 MCleptZ1_pdgid = -1;
1555     MCleptZ2_pdgid = -1;
1556     MCleptW_pdgid = -1;
1557    
1558     MCleptZ1_pt = -1;
1559     MCleptZ2_pt = -1;
1560     MCleptW_pt = -1;
1561    
1562     MCleptZ1_eta = -1;
1563     MCleptZ2_eta = -1;
1564     MCleptW_eta = -1;
1565    
1566     MCleptZ1_phi = -1;
1567     MCleptZ2_phi = -1;
1568     MCleptW_phi = -1;
1569 senka 1.12
1570 smorovic 1.8 vector<reco::GenParticleCandidate*> Tau;
1571     vector<reco::GenParticleCandidate*> StableMuons;
1572     vector<reco::GenParticleCandidate*> StableElectrons;
1573 senka 1.24
1574 smorovic 1.32
1575    
1576 vuko 1.11 for(CandidateCollection::const_iterator p = mccands->begin();
1577     p != mccands->end(); p++) {
1578 vuko 1.1
1579 vuko 1.11 // reco::Candidate* p_tmp = &(*p);
1580     reco::GenParticleCandidate* ptr = (reco::GenParticleCandidate*) &(*p);
1581 smorovic 1.8
1582     if ( (ptr)->status() == 1
1583     /*&& (ptr)->momentum().perp() > 2.*/ ) { // stable particles with pt>2 only
1584     if ( abs((ptr)->pdgId()) == 11 ) {
1585 senka 1.12
1586 smorovic 1.8 StableElectrons.push_back((ptr));
1587     //cout << "electron MCT\n";
1588     }
1589     else if ( abs((ptr)->pdgId()) == 13 ) {
1590 senka 1.12
1591 smorovic 1.8 StableMuons.push_back((ptr)) ;
1592     //cout << "muon MCT\n";
1593     }
1594     }
1595     else if ((ptr)->status() == 2) {
1596     if ( abs((ptr)->pdgId()) == 15 ) {//tau
1597     Tau.push_back((ptr));
1598     }
1599     }
1600     }
1601 senka 1.12
1602 vuko 1.25 // std::cout << "# Electrons : " << StableElectrons.size()
1603     // << "# Muons : " << StableMuons.size() << std::endl
1604     // << "# Tau : " << Tau.size() << std::endl;
1605 senka 1.12
1606 smorovic 1.8
1607     vector<reco::GenParticleCandidate*> * StableLeptons[3] = {&StableElectrons, &StableMuons, &Tau};
1608    
1609 smorovic 1.32 vector<reco::GenParticleCandidate*> TauChildLeptons;
1610    
1611    
1612     //erase electrons and muons from tau from GenparticleCandidate Vector and put to Tau Vector
1613     for (int i=1; i>=0; i--) {
1614     for ( vector<reco::GenParticleCandidate*>::iterator lepton = StableLeptons[i]->begin();
1615     lepton != StableLeptons[i]->end();lepton++) {
1616    
1617     reco::GenParticleCandidate* mcParticleRef = *lepton;
1618    
1619     int parentItr=0;
1620     while ( mcParticleRef->mother()!=0 && parentItr<2) {
1621    
1622     parentItr++;
1623    
1624     mcParticleRef = (reco::GenParticleCandidate*) mcParticleRef->mother();
1625     if (mcParticleRef==0) break;
1626    
1627     //if tau
1628     if (abs((mcParticleRef)->pdgId())==15 ) {
1629     //put into collection
1630     TauChildLeptons.push_back(*lepton);
1631     StableLeptons[i]->erase(lepton);
1632     lepton--;
1633     break;
1634     }
1635     }
1636     }
1637     }
1638    
1639    
1640 smorovic 1.8 bool firstZlept = true;
1641 vuko 1.51 // int MC_tauDecayTypeZ1 = 0;
1642     // int MC_tauDecayTypeZ2 = 0;
1643     // int MC_tauDecayTypeW = 0;
1644     MC_tauDecayTypeZ1 = 0;
1645     MC_tauDecayTypeZ2 = 0;
1646     MC_tauDecayTypeW = 0;
1647 smorovic 1.32
1648    
1649 smorovic 1.8 for (int i=2; i>=0; i--) {
1650     while (StableLeptons[i]->size() > 0) {
1651     float maxPt = 0;
1652     vector<reco::GenParticleCandidate*>::iterator index = StableLeptons[i]->end();
1653    
1654     for ( vector<reco::GenParticleCandidate*>::iterator lepton = StableLeptons[i]->begin();
1655     lepton != StableLeptons[i]->end(); lepton++ ) {
1656 smorovic 1.32
1657 smorovic 1.8 if ((*lepton)->pt() > maxPt) {
1658     maxPt = (*lepton)->pt();
1659     index = lepton;
1660     }
1661     }
1662     bool Zchild = false;
1663     bool Wchild = false;
1664 smorovic 1.32 bool isTau = false;
1665    
1666    
1667 smorovic 1.8 reco::GenParticleCandidate* mcParticleRef = *index;
1668    
1669 smorovic 1.32 if (abs((*index)->pdgId()) == 15) isTau = true;
1670    
1671 smorovic 1.8 //find W/Z mother
1672 smorovic 1.32 int parentItr=0;
1673     while ( mcParticleRef->mother()!=0 && parentItr<2) {
1674    
1675 smorovic 1.8 if (parentItr>=2) break;
1676     parentItr++;
1677     mcParticleRef = (reco::GenParticleCandidate*) mcParticleRef->mother();
1678 smorovic 1.32 if (mcParticleRef==0) break;
1679 smorovic 1.8
1680     if (abs((mcParticleRef)->pdgId())==23 ) {
1681     Zchild=true;
1682     break;
1683     }
1684     if (abs((mcParticleRef)->pdgId())==24 ) {
1685     Wchild=true;
1686     break;
1687     }
1688     }
1689    
1690 smorovic 1.32
1691 smorovic 1.8 if (maxPt >0) {
1692 smorovic 1.32 int * MCtauDecayTypePtr = 0;
1693    
1694 smorovic 1.8 if (Wchild) {
1695     MCleptW_pdgid=(*index)->pdgId();
1696     MCleptW_pt=(float)(*index)->pt();
1697     MCleptW_eta=(float)(*index)->eta();
1698     MCleptW_phi=(float)(*index)->phi();
1699 smorovic 1.32 if (isTau) {
1700     MCtauDecayTypePtr = &MC_tauDecayTypeW;
1701     MC_tauDecayTypeW =3;//default to hadronic decay
1702     }
1703    
1704 smorovic 1.8 }
1705     if (Zchild) {
1706     if (firstZlept) {
1707     firstZlept=false;
1708     MCleptZ1_pdgid=(*index)->pdgId();
1709     MCleptZ1_pt=(float)(*index)->pt();
1710     MCleptZ1_eta=(float)(*index)->eta();
1711     MCleptZ1_phi=(float)(*index)->phi();
1712 smorovic 1.32 if (isTau) {
1713     MCtauDecayTypePtr = &MC_tauDecayTypeZ1;
1714     MC_tauDecayTypeZ1 =3;
1715     }
1716    
1717 smorovic 1.8 }
1718     else {
1719     MCleptZ2_pdgid=(*index)->pdgId();
1720     MCleptZ2_pt=(float)(*index)->pt();
1721     MCleptZ2_eta=(float)(*index)->eta();
1722     MCleptZ2_phi=(float)(*index)->phi();
1723 smorovic 1.32 if (isTau) {
1724     MCtauDecayTypePtr = &MC_tauDecayTypeZ2;
1725     MC_tauDecayTypeZ2 =3;
1726     }
1727    
1728     }
1729     }
1730     //check type of tau decay
1731     if (MCtauDecayTypePtr) {
1732     for( vector<reco::GenParticleCandidate*>::iterator p = TauChildLeptons.begin();p != TauChildLeptons.end(); p++) {
1733     int pitr = 0;
1734     reco::GenParticleCandidate* mcParticleRef = *p;
1735     while (mcParticleRef->mother() && pitr<2) {
1736     pitr++;
1737     mcParticleRef =(reco::GenParticleCandidate*) mcParticleRef->mother();
1738     if (mcParticleRef==0) break;
1739     if (mcParticleRef == *index) {
1740     if (abs((*p)->pdgId()) == 11) *MCtauDecayTypePtr = 1;
1741     if (abs((*p)->pdgId()) == 13) *MCtauDecayTypePtr = 2;
1742     }
1743     }
1744 smorovic 1.8 }
1745 smorovic 1.32 }
1746 smorovic 1.8 }
1747 smorovic 1.32 StableLeptons[i]->erase(index);
1748 smorovic 1.8 }
1749     }
1750     }
1751 vuko 1.1 //define this as a plug-in
1752 vuko 1.2 // DEFINE_FWK_MODULE(WZAnalyzer);
1753 smorovic 1.32