ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Vuko/WZAnalysis/src/WZAnalyzer.cc
Revision: 1.64
Committed: Thu Sep 11 15:01:55 2008 UTC (16 years, 7 months ago) by smorovic
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.63: +15 -15 lines
Log Message:
HLT1Jet -> HLT1jet (again)

File Contents

# User Rev Content
1 vuko 1.1 // -*- C++ -*-
2     //
3     // Package: WZAnalyzer
4     // Class: WZAnalyzer
5     //
6 vuko 1.2 /**\class WZAnalyzer WZAnalyzer.cc Vuko/WZAnalysis/src/WZAnalyzer.cc
7 vuko 1.1
8     Description: <one line class summary>
9    
10     Implementation:
11     <Notes on implementation>
12     */
13     //
14     // Original Author: Vuko Brigljevic
15     // Created: Fri Nov 9 11:07:27 CET 2007
16 smorovic 1.64 // $Id: WZAnalyzer.cc,v 1.63 2008/08/25 15:51:29 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 kkaadze 1.63 #include "HLTrigger/HLTexample/interface/HLTAnalFilt.h"
43     #include "DataFormats/HLTReco/interface/HLTFilterObject.h"
44 vuko 1.1 //--- muon AOD:
45     #include "DataFormats/JetReco/interface/CaloJetCollection.h"
46     #include "DataFormats/EgammaCandidates/interface/Electron.h"
47     #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
48     #include "DataFormats/MuonReco/interface/MuonFwd.h"
49     #include "DataFormats/MuonReco/interface/Muon.h"
50 senka 1.28 #include "DataFormats/MuonReco/interface/MuIsoDeposit.h"
51 vuko 1.1 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
52     #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
53     #include "DataFormats/EgammaCandidates/interface/PixelMatchGsfElectron.h"
54    
55 senka 1.9 #include "DataFormats/METReco/interface/CaloMET.h"
56    
57 vuko 1.1
58     #include "TFile.h"
59     #include "TH1F.h"
60     #include "TH2F.h"
61     #include "TTree.h"
62 smorovic 1.52 //#include "TVector3.h"
63 vuko 1.1
64     #include <map>
65    
66     //
67     // constants, enums and typedefs
68     //
69    
70     //
71     // static data member definitions
72     //
73    
74     //
75     // constructors and destructor
76     //
77     WZAnalyzer::WZAnalyzer(const edm::ParameterSet& iConfig)
78    
79     {
80     //now do what ever initialization is needed
81 kkaadze 1.58 // Recreate = iConfig.getUntrackedParameter<bool>("SecondRound");
82     treeNumber = iConfig.getUntrackedParameter<int>("treeNumber");
83 senka 1.16 fOutputFileName = iConfig.getUntrackedParameter<string>("HistOutFile");
84 vuko 1.10 theMCTruthCollection = iConfig.getParameter<edm::InputTag>("genParticles");
85    
86 senka 1.12 // theMCTruthCollection = iConfig.getParameter<edm::InputTag>("genParticleCollection");
87    
88 vuko 1.1 theLooseMuonCollection = iConfig.getParameter<edm::InputTag>("LooseMuons");
89     theGoodMuonCollection = iConfig.getParameter<edm::InputTag>("GoodMuons");
90     theLooseElectronCollection = iConfig.getParameter<edm::InputTag>("LooseElectrons");
91 beaucero 1.56 theAllElectronCollection = iConfig.getParameter<edm::InputTag>("AllElectrons");
92 vuko 1.1 theTightLeptonCollection = iConfig.getParameter<edm::InputTag>("TightLeptons");
93     // theMediumElectronCollection = iConfig.getParameter<edm::InputTag>("LooseElectrons");
94     // theTightElectronCollection = iConfig.getParameter<edm::InputTag>("TightElectrons");
95     // Z's
96     theZeeCollection = iConfig.getParameter<edm::InputTag>("ZtoEE");
97     theZmumuCollection = iConfig.getParameter<edm::InputTag>("ZtoMuMu");
98 vuko 1.3 theZllCollection = iConfig.getParameter<edm::InputTag>("ZtoLL");
99 vuko 1.10
100     theJetCollection = iConfig.getParameter<edm::InputTag>("Jets");
101 vuko 1.26
102     theWeightCollection = iConfig.getParameter<edm::InputTag>("EventWeight");
103 smorovic 1.38 alpgenIDTag = iConfig.getParameter<edm::InputTag>("AlpgenIDTag");
104    
105 smorovic 1.39 getAlpgenID = false;
106     getAlpgenID = iConfig.getParameter<bool>("getAlpgenID");
107    
108 smorovic 1.6 storeHLTresults=false;
109     storeHLTresults = iConfig.getParameter<bool>("storeHLTresults");
110 vuko 1.1
111 vuko 1.26 getEventWeight = false;
112     getEventWeight = iConfig.getParameter<bool>("getEventWeight");
113    
114 smorovic 1.23 triggerResultsTag = iConfig.getParameter<edm::InputTag>("TriggerResults");
115 smorovic 1.6 firstTriggerResult = true;
116 smorovic 1.52
117     findBackJets = false;
118     findBackJets = iConfig.getParameter<bool>("findBackJets");
119 kkaadze 1.63
120     // hltObj_ = iConfig.getParameter<edm::InputTag>("hltObjInputTag");
121    
122     getHLTjetList_ = false;
123     if (getHLTjetList_ = iConfig.getParameter<bool>("getHLTjetList")) {
124     HLT4jetFilterTag_ = iConfig.getParameter<edm::InputTag>("HLT4jetFilterTag");
125     HLT3jetFilterTag_ = iConfig.getParameter<edm::InputTag>("HLT3jetFilterTag");
126     HLT2jetFilterTag_ = iConfig.getParameter<edm::InputTag>("HLT2jetFilterTag");
127     HLT1jetFilterTag_ = iConfig.getParameter<edm::InputTag>("HLT1jetFilterTag");
128     HLT1PE1jetFilterTag_ = iConfig.getParameter<edm::InputTag>("HLT1PE1jetFilterTag");
129     HLT1PE3jetFilterTag_ = iConfig.getParameter<edm::InputTag>("HLT1PE3jetFilterTag");
130     HLT1PE5jetFilterTag_ = iConfig.getParameter<edm::InputTag>("HLT1PE5jetFilterTag");
131     HLT1PE7jetFilterTag_ = iConfig.getParameter<edm::InputTag>("HLT1PE7jetFilterTag");
132     }
133    
134 vuko 1.1 }
135    
136     WZAnalyzer::~WZAnalyzer()
137     {
138    
139     // do anything here that needs to be done at desctruction time
140     // (e.g. close files, deallocate resources etc.)
141    
142     }
143    
144    
145     //
146     // member functions
147     //
148    
149     // ------------ method called to for each event ------------
150     void
151     WZAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
152     {
153     using namespace edm;
154     using namespace reco;
155     using namespace std;
156    
157 vuko 1.11 ///////////////////////////////////////
158     //
159     /// EVENT INITIALISATION
160     ///
161    
162 smorovic 1.41 //read run number and event ID number
163     RunNumber = iEvent.id().run();
164     EventID = iEvent.id().event();
165    
166 vuko 1.11 // Reset a few things
167     for (map<string,wzana::LeptonProperties* >::iterator iter = leptonProperties.begin();
168     iter!=leptonProperties.end(); iter++)
169     {
170     iter->second->ResetValues();
171     }
172    
173    
174 vuko 1.1 const Candidate * theZCandidate = 0;
175     const Candidate * theWlepton = 0;
176    
177 vuko 1.11
178     ////////////////////////////////////////
179     // Get lists
180    
181 vuko 1.1 // Z->mumu
182     Handle<CandidateCollection> zmumuCands;
183     iEvent.getByLabel( theZmumuCollection , zmumuCands);
184    
185    
186     // Z->ee
187     Handle<CandidateCollection> zeeCands;
188     iEvent.getByLabel( theZeeCollection , zeeCands);
189    
190 vuko 1.3 // Z->ee
191     Handle<CandidateCollection> zllCands;
192     iEvent.getByLabel( theZllCollection , zllCands);
193    
194 vuko 1.1 // loose electrons
195     Handle<CandidateCollection> looseElectronCands;
196     iEvent.getByLabel( theLooseElectronCollection , looseElectronCands);
197    
198 beaucero 1.56 // All electrons
199     Handle<CandidateCollection> allElectronCands;
200     iEvent.getByLabel( theAllElectronCollection , allElectronCands);
201 vuko 1.1
202     // loose muons
203     Handle<CandidateCollection> looseMuonCands;
204     iEvent.getByLabel( theLooseMuonCollection , looseMuonCands);
205    
206     // good muons
207     Handle<CandidateCollection> goodMuonCands;
208     iEvent.getByLabel( theGoodMuonCollection , goodMuonCands);
209    
210    
211     // tight leptons
212     Handle<CandidateCollection> tightLeptonCands;
213     iEvent.getByLabel( theTightLeptonCollection , tightLeptonCands);
214    
215 vuko 1.10 // jets
216 vuko 1.14
217     Handle<CaloJetCollection> jetCands;
218 vuko 1.10 iEvent.getByLabel( theJetCollection , jetCands);
219    
220 vuko 1.26
221     // event weights (CSA07 soups...)
222     eventWeight = -1;
223    
224     Handle< double> weightHandle;
225 smorovic 1.31 Handle<int> genProcessID;
226 smorovic 1.36 Handle<int> alpgenProcessID;
227 smorovic 1.31 Handle<double> genEventScale;
228    
229 vuko 1.26 if (getEventWeight) {
230 smorovic 1.40
231 vuko 1.26 iEvent.getByLabel (theWeightCollection, weightHandle);
232     if (weightHandle.isValid()) {
233     eventWeight = * weightHandle;
234     }
235 smorovic 1.40
236 smorovic 1.31 iEvent.getByLabel( "genEventProcID", genProcessID );
237 smorovic 1.32 if (genProcessID.isValid()) {
238     processID = *genProcessID;
239 smorovic 1.31 }
240 smorovic 1.40
241 smorovic 1.39 if (processID==4 && getAlpgenID) {
242 smorovic 1.38 iEvent.getByLabel( alpgenIDTag , alpgenProcessID );
243     if (alpgenProcessID.isValid()) {
244     alpgenID = *alpgenProcessID;
245     }
246     } else alpgenID=0;
247    
248    
249 smorovic 1.31 iEvent.getByLabel( "genEventScale", genEventScale );
250 smorovic 1.32 if (genEventScale.isValid()) {
251     eventScale = *genEventScale;
252 smorovic 1.31 }
253 vuko 1.26 }
254 beaucero 1.42
255    
256 smorovic 1.6 // get hold of TriggerResults
257 senka 1.27 Handle<TriggerResults> HLTR; //moja promjena: ovo prebaceno 2 reda nize!
258 senka 1.44 if (storeHLTresults) {
259     // Handle<TriggerResults> HLTR;
260     iEvent.getByLabel(triggerResultsTag,HLTR);
261     if (firstTriggerResult) {
262     firstTriggerResult = false;
263     trigNames.init((edm::TriggerResults&)*HLTR);
264     numTriggers = trigNames.size();
265     }
266     }
267    
268 smorovic 1.6
269 senka 1.44 // MET corrected (P_muons, P_muons_calo_deposit)
270    
271     reco::Particle::LorentzVector MET=computeMET(iEvent, iSetup, looseMuonCands);
272     // MET_energy=MET.energy();
273     MET_energy=MET.energy(); // this is Et!!
274     MET_pt=MET.pt();
275     MET_px=MET.px();
276     MET_py=MET.py();
277     MET_eta=MET.eta();
278 vuko 1.50 MET_phi=MET.phi();
279 senka 1.44
280 kkaadze 1.61 //Correct MET due to SC energy scale corrections
281 kkaadze 1.55 reco::Particle::LorentzVector MET_SCCorr = correctMETforSCCorrection(MET, looseElectronCands);
282     MET_Et_SCCorr = MET_SCCorr.energy();
283     MET_pt_SCCorr = MET_SCCorr.pt();
284     MET_phi_SCCorr = MET_SCCorr.phi();
285    
286 kkaadze 1.61 //Correct MET due to electron energy scale corrections
287 kkaadze 1.55 reco::Particle::LorentzVector MET_ElCorr = correctMETforElCorrection(MET, looseElectronCands);
288     MET_Et_ElCorr = MET_ElCorr.energy();
289     MET_pt_ElCorr = MET_ElCorr.pt();
290     MET_phi_ElCorr = MET_ElCorr.phi();
291    
292 senka 1.28
293     // selected muons
294 vuko 1.1
295 beaucero 1.35 // cout << "\t # loose mu : " << looseMuonCands->size()
296     // << "\t # tight mu : " << goodMuonCands->size()
297     // << "\t # loose e : " << looseElectronCands->size()
298 beaucero 1.56 // << "\t # tight e : " << allElectronCands->size()
299 beaucero 1.35 // << "\t # tight l : " << tightLeptonCands->size()
300     // << "\t # Z->mumu : " << zmumuCands->size()
301     // << "\t # Z->ee : " << zeeCands->size()
302     // << "\t # Z->ll : " << zllCands->size()
303     // << endl;
304 vuko 1.1
305 senka 1.27 N_looseMuons=0;
306     N_looseElectrons=0;
307 kkaadze 1.61 N_allElectrons=0;
308 senka 1.27 N_looseMuons = looseMuonCands->size();
309     N_looseElectrons = looseElectronCands->size();
310 kkaadze 1.61 N_allElectrons = allElectronCands->size();
311 vuko 1.49 NCaloJets = jetCands->size();
312 kkaadze 1.61
313 vuko 1.1 //
314 vuko 1.7 // Find best Z (in Z->ll collection (merged Z->ee & Z->mumu)
315 vuko 1.1 //
316     ::OverlapChecker overlap;
317    
318 vuko 1.3
319     float dzmass_min = 100.;
320    
321 senka 1.27 n=1; // number of non overlaping Zs
322 vuko 1.3 for(CandidateCollection::const_iterator z1 = zllCands->begin();
323     z1 != zllCands->end(); ++ z1 ) {
324 vuko 1.21
325     // Check that two leptons used to build the Z are not overlapping
326     if (overlap(*(z1->daughter(0)),*(z1->daughter(1))) ) {
327 smorovic 1.32 continue;
328 vuko 1.21 }
329    
330 vuko 1.3 float dzmass = fabs( z1->mass() - 91.188);
331     if (dzmass < dzmass_min) {
332 vuko 1.7 theZCandidate = &(*z1);
333 vuko 1.3 dzmass_min = dzmass;
334     }
335     //
336     //Get back Electrons from Z and W
337     for(CandidateCollection::const_iterator z2 = z1;
338     z2 != zllCands->end(); ++ z2 ) {
339     if (z1 != z2) {
340     if (overlap(*z1,*z2)) {
341     } else {
342 senka 1.27 n++;
343 vuko 1.3 }
344     }
345     }
346     }
347    
348    
349 vuko 1.1 zFlavour = 0;
350     wlFlavour = 0;
351 beaucero 1.35 zMass = -10;
352     zPt = -10;
353     zEta = -10;
354     zPhi = -10;
355 vuko 1.50 nWlElCand = 0;
356     nWlMuCand = 0;
357 vuko 1.1
358 senka 1.9 dPhi_WlZ_reco=-15.;
359     dPhi_WZ_reco=-15.;
360 kkaadze 1.55
361     dPhi_Wl_MET = -15.;
362     dPhi_Wl_MET_SCCorr = -15.;
363     dPhi_Wl_MET_ElCorr = -15.;
364 beaucero 1.56 wlCharge =-10;
365     wlEta = -10;
366     wlPhi = -10;
367     wlTransMass = -10;
368     wlTransMass_SCCorr = -10;
369     wlTransMass_ElCorr = -10;
370 kkaadze 1.62 forElectronFakeRate = -10;
371     forMuonFakeRate = -10;
372 kkaadze 1.61
373 kkaadze 1.63
374 senka 1.15 //---------------
375     // matching(iEvent,looseMuonCands, 13);
376     // matching(iEvent,looseElectronCands, 11);
377     // MatchedGenParticle(&(*looseMuonCands)[0]);
378     //-------------------
379    
380 vuko 1.1 int nwl_candidates=0;
381     if (theZCandidate) {
382    
383    
384     zMass = theZCandidate->mass();
385     zFlavour = abs(theZCandidate->daughter(0)->pdgId());
386     zPt = theZCandidate->pt();
387     zEta = theZCandidate->eta();
388     zPhi = theZCandidate->phi();
389    
390 vuko 1.18 // Sanity check: can we identify the Z daughters with leptons from the loose lists
391    
392     Handle<CandidateCollection> looseLeptonCands;
393     if (zFlavour == 11) {
394     looseLeptonCands = looseElectronCands;
395     } else if (zFlavour == 13) {
396     looseLeptonCands = looseMuonCands;
397     }
398     for (int i=0; i<2; i++) {
399     int noverlaps=0;
400     for(CandidateCollection::const_iterator l = looseLeptonCands->begin();
401     l != looseLeptonCands->end(); l++) {
402     if (overlap(*(theZCandidate->daughter(i)), *l) ) {
403     noverlaps++;
404     }
405     }
406     }
407    
408 senka 1.15 matching(iEvent,looseMuonCands, 13);
409     matching(iEvent,looseElectronCands, 11);
410    
411 vuko 1.4 if (zFlavour == 11) {
412 senka 1.17 //--------------
413 vuko 1.18 leptonProperties["ZEl1"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
414     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
415     leptonProperties["ZEl2"]->FillProperties(theZCandidate->daughter(1), iEvent, iSetup,
416     MatchedGenParticle(theZCandidate->daughter(1)),dR(theZCandidate->daughter(1)));
417 senka 1.17 } else if (zFlavour == 13) {
418     //--------------
419 senka 1.19 const reco::Candidate * mcpart = MatchedGenParticle(theZCandidate->daughter(0));
420 senka 1.17 //--------------
421 vuko 1.18 leptonProperties["Zmu1"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
422     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
423 vuko 1.53 leptonProperties["Zmul"]->FillProperties(theZCandidate->daughter(0), iEvent, iSetup,
424     MatchedGenParticle(theZCandidate->daughter(0)),dR(theZCandidate->daughter(0)));
425 vuko 1.18 leptonProperties["Zmu2"]->FillProperties(theZCandidate->daughter(1), iEvent, iSetup,
426     MatchedGenParticle(theZCandidate->daughter(1)),dR(theZCandidate->daughter(1)));
427 kkaadze 1.61
428 vuko 1.4 }
429 kkaadze 1.61
430 vuko 1.1 float max_pt = 0.;
431 kkaadze 1.61
432     // Find W lepton
433    
434    
435 vuko 1.1 // Now find lepton that will be associated to W
436     // among leptons not used for the Z reconstruction
437     for(CandidateCollection::const_iterator lepton = tightLeptonCands->begin();
438     lepton != tightLeptonCands->end(); lepton++) {
439 kkaadze 1.61
440    
441 vuko 1.1 if ( overlap(*theZCandidate, *lepton) ) continue; // Ignore if lepton used for the Z
442 kkaadze 1.61
443 vuko 1.1 nwl_candidates++;
444 vuko 1.50 if (abs(lepton->pdgId()) == 11) {
445     nWlElCand++;
446     } else if (abs(lepton->pdgId()) == 13) {
447     nWlMuCand++;
448     }
449 vuko 1.1
450     // If more than one candidate: choose leading pt
451     if (lepton->pt() > max_pt) {
452     theWlepton = &(*lepton);
453     max_pt = lepton->pt();
454     }
455 kkaadze 1.61
456 vuko 1.1 if(lepton->hasMasterClone()) {
457 beaucero 1.35 // cout << "SHOUT: TIGHT LEPTON IS SHALLOW COPY !!! (SHOULD NOT BE!) \n";
458 vuko 1.1 }
459     //
460     }
461     if (theWlepton) {
462     wlFlavour = theWlepton->pdgId();
463     wlCharge = theWlepton->charge();
464     wlPt = theWlepton->pt();
465     wlEta = theWlepton->eta();
466     wlPhi = theWlepton->phi();
467 beaucero 1.56 wlTransMass= kinem::TransvMass(theWlepton->pt(),MET.pt(),
468     theWlepton->px(), MET.px(),
469     theWlepton->py(),MET.py());
470 kkaadze 1.61
471 vuko 1.3 if (abs(wlFlavour) == 11) {
472 senka 1.17 leptonProperties["Wel"]->FillProperties(theWlepton, iEvent, iSetup, MatchedGenParticle(theWlepton),dR(theWlepton));
473 vuko 1.3 } else if (abs(wlFlavour) == 13) {
474 senka 1.17 leptonProperties["Wmu"]->FillProperties(theWlepton, iEvent, iSetup, MatchedGenParticle(theWlepton),dR(theWlepton));
475 vuko 1.3 }
476 kkaadze 1.61
477 beaucero 1.56 dPhi_WlZ_reco=kinem::delta_phi(theWlepton->phi(),theZCandidate->phi());
478     dPhi_WZ_reco=kinem::delta_phi((theWlepton->p4()+MET).phi(),theZCandidate->phi());
479 kkaadze 1.61
480 kkaadze 1.55 dPhi_Wl_MET = kinem::delta_phi(theWlepton->phi(),MET.phi());
481 beaucero 1.56 dPhi_Wl_MET_SCCorr = kinem::delta_phi(theWlepton->phi(),MET_SCCorr.phi());
482     wlTransMass_SCCorr= kinem::TransvMass(theWlepton->pt(),MET_SCCorr.pt(),
483 kkaadze 1.61 theWlepton->px(), MET_SCCorr.px(),
484     theWlepton->py(),MET_SCCorr.py());
485 beaucero 1.56 dPhi_Wl_MET_ElCorr = kinem::delta_phi(theWlepton->phi(),MET_ElCorr.phi());
486     wlTransMass_ElCorr= kinem::TransvMass(theWlepton->pt(),MET_ElCorr.pt(),
487 kkaadze 1.61 theWlepton->px(), MET_ElCorr.px(),
488     theWlepton->py(),MET_ElCorr.py());
489 vuko 1.1 }
490 kkaadze 1.55
491 vuko 1.1 }
492 smorovic 1.6
493 kkaadze 1.61
494 kkaadze 1.62 // Piece of code to select events with only one muon candidate for e-fakerate : KETI
495 kkaadze 1.61 else { // if ( !theZCandidate ) {
496     matching(iEvent,looseMuonCands, 13);
497     matching(iEvent,allElectronCands, 11);
498 kkaadze 1.62 matching(iEvent,looseElectronCands, 11);
499 kkaadze 1.61
500     const CandidateCollection* electronCands = allElectronCands.product();
501 kkaadze 1.62 const CandidateCollection* looseElCands = looseElectronCands.product();
502 kkaadze 1.61 const CandidateCollection* muonCands = looseMuonCands.product();
503 kkaadze 1.62
504     //Look at event with only one Global Muon and at least one GSF electron after Amb Resolver (for electron FakeRate)
505     //On Tree level all Muon selection nees to be applied in order this to be Good Muon
506     if ( N_looseMuons == 1 && allElectronCands->size() > 0 ) {
507     forElectronFakeRate = 1;
508     //Muon is supposly W candidate ( BUT not necessarily )
509 kkaadze 1.61 leptonProperties["Wmu"] ->FillProperties(&(*muonCands)[0], iEvent, iSetup,
510     MatchedGenParticle( &(*muonCands)[0]), dR(&(*muonCands)[0]));
511 kkaadze 1.62 theWlepton = &(*looseMuonCands->begin());
512     wlTransMass= kinem::TransvMass(theWlepton->pt(),MET.pt(),
513     theWlepton->px(), MET.px(),
514     theWlepton->py(),MET.py());
515    
516     //Fill Lepton Properties for first electron as ZEl1
517     leptonProperties["ZEl1"] ->FillProperties(&(*electronCands)[0], iEvent, iSetup,
518     MatchedGenParticle( &(*electronCands)[0]), dR(&(*electronCands)[0]));
519     //If Second GSF electrons is also found ( meaning, both b jets decayed sami-leptonicaly )
520     //Fill lepton Properies as ZEl2
521     if ( allElectronCands->size() > 1 ) {
522     leptonProperties["ZEl2"] ->FillProperties(&(*electronCands)[1], iEvent, iSetup,
523     MatchedGenParticle( &(*electronCands)[1]), dR(&(*electronCands)[1]));
524     }
525     }
526     //Look at event with only one electron satisfying WZLoose Selection and at least one global Muon
527     if ( N_looseElectrons == 1 && looseMuonCands->size() > 0 ) {
528     forMuonFakeRate = 1;
529     //Electron can be assumed from W ( as it has passed Loose selection )
530     leptonProperties["Wel"]->FillProperties(&(*looseElCands)[0], iEvent, iSetup,
531     MatchedGenParticle( &(*looseElCands)[0]), dR(&(*looseElCands)[0]));
532     theWlepton = &(*looseElectronCands->begin());
533     wlTransMass= kinem::TransvMass(theWlepton->pt(),MET.pt(),
534     theWlepton->px(), MET.px(),
535     theWlepton->py(),MET.py());
536    
537     // Fill Lepton Properties for first muon as Zmu1
538     leptonProperties["Zmu1"] ->FillProperties(&(*muonCands)[0], iEvent, iSetup,
539     MatchedGenParticle( &(*muonCands)[0]), dR(&(*muonCands)[0]));
540     //If second muons is also found, fill Lepton Properties for second muon as Zmu2
541     if ( looseMuonCands->size() > 1 ) {
542     leptonProperties["Zmu2"] ->FillProperties(&(*muonCands)[1], iEvent, iSetup,
543 kkaadze 1.61 MatchedGenParticle( &(*muonCands)[1]), dR(&(*muonCands)[1]));
544     }
545     }
546     }
547    
548 vuko 1.10 // Handle <reco::GenParticleCandidateCollection> mccands;
549     Handle<CandidateCollection> mccands;
550     iEvent.getByLabel( theMCTruthCollection,mccands );
551 smorovic 1.6
552 vuko 1.11 collectMCsummary(mccands);
553 kkaadze 1.63
554    
555     bool hlt1JetPassed = false;
556     bool hlt2JetPassed = false;
557     bool hlt3JetPassed = false;
558     bool hlt4JetPassed = false;
559     bool hlt1JetPE1Passed = false;
560     bool hlt1JetPE3Passed = false;
561     bool hlt1JetPE5Passed = false;
562     bool hlt1JetPE7Passed = false;
563 smorovic 1.6
564 smorovic 1.8 if (storeHLTresults) {
565    
566 smorovic 1.6 //def: 1:single electron 2:single relaxed 3:double electron 4: double relaxed 5,6,7,8: muon e+mu: 9
567 smorovic 1.8
568 smorovic 1.6 triggerBitmask=0;
569 smorovic 1.52 triggerBitmaskQCD=0;
570 smorovic 1.8
571 smorovic 1.6 for (size_t i=0; i<numTriggers; ++i) {
572    
573     if (!HLTR->wasrun(i)) {
574     continue;
575     }
576     if (HLTR->error(i) ) {
577     continue;
578     }
579     if (HLTR->accept(i)) {
580     //if (triggerNames[i].compare("mcpath")!=0)
581     //TRaccept=true;
582     }else {
583     continue;
584     }
585 smorovic 1.34 if (trigNames.triggerName(i).compare("HLT1Electron")==0) triggerBitmask |= 1;
586     if (trigNames.triggerName(i).compare("HLT1ElectronRelaxed")==0) triggerBitmask |= 2;
587     if (trigNames.triggerName(i).compare("HLT2Electron")==0) triggerBitmask |= 4;
588     if (trigNames.triggerName(i).compare("HLT2ElectronRelaxed")==0) triggerBitmask |= 8;
589    
590     if (trigNames.triggerName(i).compare("HLT1MuonIso")==0) triggerBitmask |= 16;
591     if (trigNames.triggerName(i).compare("HLT1MuonNonIso")==0) triggerBitmask |= 32;
592     if (trigNames.triggerName(i).compare("HLT2MuonNonIso")==0) triggerBitmask |= 64;
593     if (trigNames.triggerName(i).compare("HLT2MuonZ")==0) triggerBitmask |= 128;
594 smorovic 1.6
595 smorovic 1.34 if (trigNames.triggerName(i).compare("HLTXElectronMuon")==0) triggerBitmask |= 256;
596     if (trigNames.triggerName(i).compare("HLTXElectronMuonRelaxed")==0) triggerBitmask |= 512;
597 smorovic 1.47
598     if (trigNames.triggerName(i).compare("CandHLT2MuonIso")==0) triggerBitmask |= 1024;
599 smorovic 1.52
600     //for QCD control sample
601 smorovic 1.64 if (trigNames.triggerName(i).compare("HLT1jet")==0) {
602 kkaadze 1.63 triggerBitmaskQCD |= 1;
603     hlt1JetPassed = true;
604     }
605 smorovic 1.64 if (trigNames.triggerName(i).compare("HLT2jet")==0) {
606 kkaadze 1.63 triggerBitmaskQCD |= 2;
607     hlt2JetPassed = true;
608     }
609 smorovic 1.64 if (trigNames.triggerName(i).compare("HLT3jet")==0) {
610 kkaadze 1.63 triggerBitmaskQCD |= 4;
611     hlt3JetPassed = true;
612     }
613 smorovic 1.64 if (trigNames.triggerName(i).compare("HLT4jet")==0) {
614 kkaadze 1.63 triggerBitmaskQCD |= 8;
615     hlt4JetPassed = true;
616     }
617 smorovic 1.64 if (trigNames.triggerName(i).compare("HLT2jetAco")==0) triggerBitmaskQCD |= 16;
618 smorovic 1.52 if (trigNames.triggerName(i).compare("HLTXMuonJets")==0) triggerBitmaskQCD |= 32;
619     if (trigNames.triggerName(i).compare("HLT1MET")==0) triggerBitmaskQCD |= 64;
620 smorovic 1.64 if (trigNames.triggerName(i).compare("HLT1jet1METAco")==0) triggerBitmaskQCD |= 128;
621     if (trigNames.triggerName(i).compare("HLT1jet1MET")==0) triggerBitmaskQCD |= 256;
622     if (trigNames.triggerName(i).compare("HLT2jet1MET")==0) triggerBitmaskQCD |= 512;
623     if (trigNames.triggerName(i).compare("HLT3jet1MET")==0) triggerBitmaskQCD |= 1024;
624     if (trigNames.triggerName(i).compare("HLT4jet1MET")==0) triggerBitmaskQCD |= 2048;
625 smorovic 1.52 if (trigNames.triggerName(i).compare("HLT1MET1HT")==0) triggerBitmaskQCD |= 4096;
626 smorovic 1.64 if (trigNames.triggerName(i).compare("HLTS2jetAco")==0) triggerBitmaskQCD |= 8192;
627     if (trigNames.triggerName(i).compare("HLT1jetPE1")==0) {
628 kkaadze 1.63 triggerBitmaskQCD |= 16384;
629     hlt1JetPE1Passed = true;
630     }
631 smorovic 1.64 if (trigNames.triggerName(i).compare("HLT1jetPE3")==0) {
632 kkaadze 1.63 triggerBitmaskQCD |= 32768;
633     hlt1JetPE3Passed = true;
634     }
635 smorovic 1.64 if (trigNames.triggerName(i).compare("HLT1jetPE5")==0) {
636 kkaadze 1.63 triggerBitmaskQCD |= 65536;
637     hlt1JetPE5Passed = true;
638     }
639     if (trigNames.triggerName(i).compare("CandHLT1jetPE7")==0) {
640     triggerBitmaskQCD |= 131072;
641     hlt1JetPE7Passed = true;
642     }
643 smorovic 1.6 }
644     }
645 kkaadze 1.63
646     //initialize HLT Jet Properties
647     hlt1JetPt = -1.;
648     hlt1JetEta = -11.;
649     hlt1JetPhi = -11.;
650     hlt2JetPt = -1.;
651     hlt2JetEta = -11.;
652     hlt2JetPhi = -11.;
653     hlt3JetPt = -1.;
654     hlt3JetEta = -11.;
655     hlt3JetPhi = -11.;
656     hlt4JetPt = -1.;
657     hlt4JetEta = -11.;
658     hlt4JetPhi = -11.;
659    
660     // Handle<reco::HLTFilterObjectWithRefs> hltJets;
661     // iEvent.getByLabel(hltObj_,hltJets);
662     //BEGIN: Select HLT Objects
663     reco::HLTFilterObjectWithRefs::const_iterator idx1,idx2,idx3;
664     /*
665     if (hlt4JetPassed) {
666     Handle<reco::HLTFilterObjectWithRefs> hltJets;
667     iEvent.getByLabel(HLT4jetFilterTag_,hltJets);
668     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
669     itr != hltJets->end(); ++itr) {
670     if (itr->pt() < hlt1JetPt) continue;
671     hlt1JetPt=itr->pt();
672     hlt1JetEta=itr->eta();
673     hlt1JetPhi=itr->phi();
674     idx1=itr;
675    
676     }
677     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
678     itr != hltJets->end(); ++itr) {
679     if (itr->pt() < hlt2JetPt || itr == idx1) continue;
680     hlt2JetPt=itr->pt();
681     hlt2JetEta=itr->eta();
682     hlt2JetPhi=itr->phi();
683     idx2=itr;
684     }
685     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
686     itr != hltJets->end(); ++itr) {
687     if (itr->pt() < hlt3JetPt || itr==idx1 || itr==idx2) continue;
688     hlt3JetPt=itr->pt();
689     hlt3JetEta=itr->eta();
690     hlt3JetPhi=itr->phi();
691     idx3=itr;
692     }
693     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
694     itr != hltJets->end(); ++itr) {
695     if (itr->pt() < hlt4JetPt || itr==idx1 || itr==idx2 || itr==idx3) continue;
696     hlt4JetPt=itr->pt();
697     hlt4JetEta=itr->eta();
698     hlt4JetPhi=itr->phi();
699     }
700     } else if (hlt3JetPassed) {
701     Handle<reco::HLTFilterObjectWithRefs> hltJets;
702     iEvent.getByLabel(HLT3jetFilterTag_,hltJets);
703     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
704     itr != hltJets->end(); ++itr) {
705     if (itr->pt() < hlt1JetPt) continue;
706     hlt1JetPt=itr->pt();
707     hlt1JetEta=itr->eta();
708     hlt1JetPhi=itr->phi();
709     idx1=itr;
710     }
711     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
712     itr != hltJets->end(); ++itr) {
713     if (itr->pt() < hlt2JetPt || itr==idx1) continue;
714     hlt2JetPt=itr->pt();
715     hlt2JetEta=itr->eta();
716     hlt2JetPhi=itr->phi();
717     idx2=itr;
718     }
719     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
720     itr != hltJets->end(); ++itr) {
721     if (itr->pt() < hlt3JetPt || itr==idx1 || itr==idx2) continue;
722     hlt3JetPt=itr->pt();
723     hlt3JetEta=itr->eta();
724     hlt3JetPhi=itr->phi();
725     }
726     } else if (hlt2JetPassed) {
727     Handle<reco::HLTFilterObjectWithRefs> hltJets;
728     iEvent.getByLabel(HLT2jetFilterTag_,hltJets);
729     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
730     itr != hltJets->end(); ++itr) {
731     if (itr->pt() < hlt1JetPt) continue;
732     hlt1JetPt=itr->pt();
733     hlt1JetEta=itr->eta();
734     hlt1JetPhi=itr->phi();
735     idx1=itr;
736     }
737     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
738     itr != hltJets->end(); ++itr) {
739     if (itr->pt() < hlt2JetPt || itr==idx1) continue;
740     hlt2JetPt=itr->pt();
741     hlt2JetEta=itr->eta();
742     hlt2JetPhi=itr->phi();
743     }
744     }
745     */
746    
747     bool onlineJetFound = false;
748     if (hlt1JetPE7Passed) {
749     Handle<reco::HLTFilterObjectWithRefs> hltJets;
750     iEvent.getByLabel(HLT1PE7jetFilterTag_, hltJets);
751     // std::cout << "Online(PE7) Jets size: " << hltJets->size() << std::endl;
752     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
753     itr != hltJets->end(); ++itr) {
754     //Sort HLT jets by PT. Though from log file I noticed HLT jets are already ordered by PT
755     if (itr->pt() < hlt1JetPt) continue;
756     hlt1JetPt=itr->pt();
757     hlt1JetEta=itr->eta();
758     hlt1JetPhi=itr->phi();
759     onlineJetFound = true;
760     // std::cout << "HLT Jet PT : ETA : PHI : " << hlt1JetPt << " " << hlt1JetEta << " " << hlt1JetPhi << std::endl;
761     }
762     }else if (hlt1JetPE5Passed) {
763     Handle<reco::HLTFilterObjectWithRefs> hltJets;
764     iEvent.getByLabel(HLT1PE5jetFilterTag_,hltJets);
765     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
766     itr != hltJets->end(); ++itr) {
767     if (itr->pt() < hlt1JetPt) continue;
768     hlt1JetPt=itr->pt();
769     hlt1JetEta=itr->eta();
770     hlt1JetPhi=itr->phi();
771     onlineJetFound = true;
772     }
773     }else if (hlt1JetPE3Passed) {
774     Handle<reco::HLTFilterObjectWithRefs> hltJets;
775     iEvent.getByLabel(HLT1PE3jetFilterTag_,hltJets);
776     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
777     itr != hltJets->end(); ++itr) {
778     if (itr->pt() < hlt1JetPt) continue;
779     hlt1JetPt=itr->pt();
780     hlt1JetEta=itr->eta();
781     hlt1JetPhi=itr->phi();
782     onlineJetFound = true;
783     }
784     }else if (hlt1JetPE1Passed) {
785     Handle<reco::HLTFilterObjectWithRefs> hltJets;
786     iEvent.getByLabel(HLT1PE1jetFilterTag_,hltJets);
787     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
788     itr != hltJets->end(); ++itr) {
789     if (itr->pt() < hlt1JetPt) continue;
790     hlt1JetPt=itr->pt();
791     hlt1JetEta=itr->eta();
792     hlt1JetPhi=itr->phi();
793     onlineJetFound = true;
794     }
795     } else if (hlt1JetPassed) {
796     Handle<reco::HLTFilterObjectWithRefs> hltJets;
797     iEvent.getByLabel(HLT1jetFilterTag_,hltJets);
798     for(reco::HLTFilterObjectWithRefs::const_iterator itr = hltJets->begin();
799     itr != hltJets->end(); ++itr) {
800     if (itr->pt() < hlt1JetPt) continue;
801     hlt1JetPt=itr->pt();
802     hlt1JetEta=itr->eta();
803     hlt1JetPhi=itr->phi();
804     onlineJetFound = true;
805     }
806     }
807     //END: Select HLT Objects
808    
809     CaloJetCollection::const_iterator matchedjet = jetCands->end();
810     //KETI: Jet properties
811     if (onlineJetFound ) {
812     const Candidate * matchedJet = 0;
813     // std::cout << "Offline Jets size " << jetCands->size() << std::endl;
814    
815     for(CaloJetCollection::const_iterator jet = jetCands->begin(); jet != jetCands->end(); ++jet) {
816     // std::cout << "Offline Jet PT : ETA : PHI : " << jet->pt() << " " << jet->eta() << " " << jet->phi() << std::endl;
817     double dR = sqrt(kinem::delta_phi(hlt1JetPhi,jet->phi())*kinem::delta_phi(hlt1JetPhi,jet->phi())
818     +kinem::delta_eta(hlt1JetEta,jet->eta())*kinem::delta_eta(hlt1JetEta,jet->eta()));
819     if ( dR > 0.1 ) continue;
820     matchedjet = jet;
821     break;
822     }
823     }
824    
825     Jet1Pt = -10;
826     Jet1Eta = -10;
827     Jet1Phi = -10;
828     if ( matchedjet != jetCands->end() ) {
829     Jet1Pt = matchedjet->pt();
830     Jet1Eta = matchedjet->eta();
831     Jet1Phi = matchedjet->phi();
832    
833     //Look for electrons in event
834     matching(iEvent,allElectronCands, 11);
835     const CandidateCollection* electronCands = allElectronCands.product();
836    
837     bool El1 = false;
838     bool El2 = false;
839     bool El3 = false;
840     bool El4 = false;
841     bool El5 = false;
842     //Loop over all electrons and mark ones away from jet
843     for ( unsigned int i=0; i < allElectronCands->size(); ++i ) {
844     double deltaR = sqrt(kinem::delta_phi((*electronCands)[i].phi(),Jet1Phi)*kinem::delta_phi((*electronCands)[i].phi(),Jet1Phi)
845     +kinem::delta_eta((*electronCands)[i].eta(),Jet1Eta)*kinem::delta_eta((*electronCands)[i].eta(),Jet1Eta));
846    
847     if ( deltaR > 1.0 ){
848     if ( !El1 ) {
849     El1 = true;
850     leptonProperties["El1"]->FillProperties(&(*electronCands)[i],iEvent,iSetup,
851     MatchedGenParticle(&(*electronCands)[i]),dR(&(*electronCands)[i]));
852     } else if ( El1 && !El2 ) {
853     El2 = true;
854     leptonProperties["El2"]->FillProperties(&(*electronCands)[i],iEvent,iSetup,
855     MatchedGenParticle(&(*electronCands)[i]),dR(&(*electronCands)[i]));
856     } else if ( El1 && El2 && !El3 ) {
857     El3 = true;
858     leptonProperties["El3"]->FillProperties(&(*electronCands)[i],iEvent,iSetup,
859     MatchedGenParticle(&(*electronCands)[i]),dR(&(*electronCands)[i]));
860     }
861     } else {
862     if ( !El4 ) {
863     El4 = true;
864     leptonProperties["El4"]->FillProperties(&(*electronCands)[i],iEvent,iSetup,
865     MatchedGenParticle(&(*electronCands)[i]),dR(&(*electronCands)[i]));
866     } else if ( El4 && !El5 ) {
867     El5 = true;
868     leptonProperties["El5"]->FillProperties(&(*electronCands)[i],iEvent,iSetup,
869     MatchedGenParticle(&(*electronCands)[i]),dR(&(*electronCands)[i]));
870     }
871     }
872     }
873     }
874 vuko 1.10
875    
876     float max_et = 0.;
877 vuko 1.14 float max2_et = 0.;
878     const Candidate * leadingJet = 0;
879     const Candidate * secondJet = 0;
880 smorovic 1.29
881     bool matchedLept[3]={false,false,false};
882    
883 vuko 1.14 // for(CandidateCollection::const_iterator jet = jetCands->begin();
884 smorovic 1.41 NbJets = 0;
885 beaucero 1.42 NbJetsWithLeptons = 0;
886 smorovic 1.41
887 vuko 1.14 for(CaloJetCollection::const_iterator jet = jetCands->begin();
888 vuko 1.10 jet != jetCands->end(); jet++) {
889 smorovic 1.29
890     //ignore jets which are within dR 0.15 to a WZ lepton
891     {
892 smorovic 1.52
893     float dPhi[3]={-1.0,-1.0,-1.0};
894     float dEta[3]={-1.0,-1.0,-1.0};
895     bool skipJet=false;
896    
897     for (int ct=0;ct<2;ct++) {
898     if (theZCandidate)
899     if (theZCandidate->daughter(ct)->pt()>0
900 beaucero 1.56 && (abs(theZCandidate->daughter(ct)->pdgId())==13
901     || abs(theZCandidate->daughter(ct)->pdgId())==11) ) {
902     dPhi[ct]=kinem::delta_phi(theZCandidate->daughter(ct)->phi(),jet->phi());
903     dEta[ct]=fabs(theZCandidate->daughter(ct)->eta() - jet->eta());
904 smorovic 1.52 }
905     }
906     if (theWlepton)
907     if (theWlepton->pt()>0 && (abs(theWlepton->pdgId())==13 || abs(theWlepton->pdgId())==11 )) {
908 beaucero 1.56 dPhi[2]=kinem::delta_phi(theWlepton->phi(),jet->phi());
909     dEta[2]=fabs(theWlepton->eta() - jet->eta());
910 smorovic 1.52 }
911     for (int k=0;k<3;k++) {
912 beaucero 1.56 if (matchedLept[k] || dEta[k]<0.0) continue;
913 smorovic 1.29
914     float deltaR=sqrt(dPhi[k]*dPhi[k]+dEta[k]*dEta[k]);
915     if (deltaR<0.15) {
916     skipJet=true;
917     matchedLept[k]=true;
918     break;
919     }
920     }
921 beaucero 1.42 if(jet->pt() > 10 && fabs(jet->eta())<2.5 )NbJetsWithLeptons++;
922 vuko 1.49
923     if (skipJet || fabs(jet->eta()) > 3.) continue;
924    
925 beaucero 1.42 if(jet->pt() > 10 && fabs(jet->eta())<2.5 )NbJets++;
926 smorovic 1.29 }
927    
928 vuko 1.49 if (jet->et() > max_et ) {
929     if (leadingJet) {
930     secondJet = leadingJet;
931     max2_et = max_et;
932     }
933     leadingJet = &(*jet);
934     max_et = jet->et();
935    
936     } else {
937     if (jet->et() > max2_et ) {
938     secondJet = &(*jet);
939     max2_et = jet->et();
940     }
941     }
942 vuko 1.10 }
943 smorovic 1.52
944 vuko 1.10 if (leadingJet) {
945 smorovic 1.52 jet1Et = leadingJet->et();
946     jet1Phi = leadingJet->phi();
947     jet1Eta = leadingJet->eta();
948 vuko 1.10
949     } else {
950 smorovic 1.52 jet1Et = -10;
951     jet1Phi = 0.;
952     jet1Eta = 0.;
953 vuko 1.10 }
954 vuko 1.14 if (secondJet) {
955 smorovic 1.52 jet2Et = secondJet->et();
956     jet2Phi = secondJet->phi();
957     jet2Eta = secondJet->eta();
958 vuko 1.14 } else {
959 smorovic 1.52 jet2Et = -10;
960     jet2Phi = 0.;
961     jet2Eta = 0.;
962 vuko 1.14
963     }
964 senka 1.9
965 senka 1.12 // matching:
966    
967     matching(iEvent,looseMuonCands, 13);
968     matching(iEvent,looseElectronCands, 11);
969    
970 senka 1.13 getMother(&(*mccands)[1]);
971 vuko 1.10
972 smorovic 1.41 numberOfElectronTrees = 0;
973    
974     //count number of electron treee entries which will be added
975     for(CandidateCollection::const_iterator el = looseElectronCands->begin();
976     el != looseElectronCands->end(); ++ el ) {
977 smorovic 1.43 if (el->pt()>10 && fabs(el->eta())<2.5) {
978 smorovic 1.41 numberOfElectronTrees++;
979     }
980     }
981    
982 kkaadze 1.61 cout << "Before filling the tree number = " << treeNumber << endl;
983 kkaadze 1.63 qcdTree->Fill();
984 vuko 1.1 wzTree->Fill();
985    
986 vuko 1.20 // Fill electrons in a tree
987     for(CandidateCollection::const_iterator el = looseElectronCands->begin();
988     el != looseElectronCands->end(); ++ el ) {
989 kkaadze 1.62
990 vuko 1.20 electronUse = 0;
991 kkaadze 1.62
992 vuko 1.20 if (theZCandidate) {
993     if (overlap(*theZCandidate, *el) ) {
994     electronUse = 23;
995     } else if (theWlepton) {
996     if (overlap(*theWlepton, *el) ) {
997     electronUse = 24;
998     }
999 smorovic 1.41 }
1000 vuko 1.20 }
1001 beaucero 1.42 if (el->pt()>10 && fabs(el->eta())<2.5) {
1002     leptonProperties["electron"]->FillProperties(&(*el),
1003     iEvent, iSetup,
1004     MatchedGenParticle(&(*el)),dR(&(*el)));
1005 kkaadze 1.62
1006 smorovic 1.52 if (findBackJets) {
1007 kkaadze 1.62
1008 smorovic 1.52 backJet_found=0;
1009     backJet_Et=0;
1010     backJet_Eta=0;
1011     backJet_Phi=0;
1012     backJet_maxEInEmTowers=0;
1013     backJet_maxEInHadTowers=0;
1014     backJet_energyFractionHadronic=0;
1015     backJet_emEnergyFraction=0;
1016     backJet_hadEnergyInHB=0;
1017     backJet_hadEnergyInHO=0;
1018     backJet_hadEnergyInHE=0;
1019     backJet_hadEnergyInHF=0;
1020     backJet_emEnergyInEB=0;
1021     backJet_emEnergyInEE=0;
1022     backJet_emEnergyInHF=0;
1023     backJet_towersArea=0;
1024     backJet_n90=0;
1025     backJet_n60=0;
1026     backJet_NbTracks = 0;
1027     backJet_match=0;
1028     backJet_matchPt=0;
1029     backJet_match_dR=-1.0;
1030    
1031     float oldDeltaPhi = -1.0;
1032    
1033     edm::Handle<reco::TrackCollection> BarrelKFTracks;
1034     iEvent.getByLabel("ctfWithMaterialTracks",BarrelKFTracks);
1035    
1036     for (CaloJetCollection::const_iterator jet = jetCands->begin();
1037     jet != jetCands->end(); jet++) {
1038    
1039     int NbTracksInJets = 0;
1040     for( reco::TrackCollection::const_iterator KFT = BarrelKFTracks->begin();KFT !=BarrelKFTracks->end(); ++ KFT ){
1041 beaucero 1.56 double DPhi = kinem::delta_phi(KFT->phi(),jet->phi());
1042 kkaadze 1.62 double dR=sqrt( (KFT->eta() - jet->eta())*(KFT->eta() - jet->eta()) + DPhi*DPhi );
1043    
1044     if (KFT->pt()>2.0 && dR<0.3) NbTracksInJets++;
1045     //cout << "pass track eta:" << KFT->eta() << " pt " << KFT->pt() << " dr " << dR << endl;
1046 smorovic 1.52 }
1047    
1048     if (NbTracksInJets<=3) continue;
1049 beaucero 1.56 float dPhi = fabs(kinem::delta_phi(jet->phi(),el->phi()) - kinem::PI);
1050 smorovic 1.52 if (dPhi<0.7 && (dPhi<oldDeltaPhi || oldDeltaPhi<0.0)) {
1051     oldDeltaPhi=dPhi;
1052    
1053     backJet_found=1;
1054     backJet_Et=jet->et();
1055     backJet_Eta=jet->eta();
1056     backJet_Phi=jet->phi();
1057     backJet_maxEInEmTowers=jet->maxEInEmTowers();
1058     backJet_maxEInHadTowers=jet->maxEInHadTowers();
1059     backJet_energyFractionHadronic=jet->energyFractionHadronic();
1060     backJet_emEnergyFraction=jet->emEnergyFraction();
1061     backJet_hadEnergyInHB=jet->hadEnergyInHB();
1062     backJet_hadEnergyInHO=jet->hadEnergyInHO();
1063     backJet_hadEnergyInHE=jet->hadEnergyInHE();
1064     backJet_hadEnergyInHF=jet->hadEnergyInHF();
1065     backJet_emEnergyInEB=jet->emEnergyInEB();
1066     backJet_emEnergyInEE=jet->emEnergyInEE();
1067     backJet_emEnergyInHF=jet->emEnergyInHF();
1068     backJet_towersArea=jet->towersArea();
1069     backJet_n90=jet->n90();
1070     backJet_n60=jet->n60();
1071     //fill variables
1072     backJet_NbTracks = NbTracksInJets;
1073     //find monte carlo electrons close to the jet
1074     float eDR = -1.0;
1075     }
1076     }
1077     }
1078 beaucero 1.42 electronTree->Fill();
1079     }
1080    
1081 vuko 1.20 }
1082    
1083 kkaadze 1.63
1084 smorovic 1.52 EventCounter++;
1085 vuko 1.1 }
1086    
1087    
1088     // ------------ method called once each job just before starting event loop ------------
1089     void
1090     WZAnalyzer::beginJob(const edm::EventSetup&)
1091     {
1092    
1093     using namespace wzana;
1094 vuko 1.60 theFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
1095 kkaadze 1.58 // theFile = new TFile( "wz.root","UPDATE") ;
1096 vuko 1.60
1097     //cout << "Tree Number " << treeNumber << endl;
1098 kkaadze 1.61 if ( treeNumber == 0 ) {
1099     wzTree = new TTree("WZTree","WZ Tree ");
1100     electronTree = new TTree("ElTree","electron information");
1101 kkaadze 1.63 qcdTree = new TTree("qcdTree","QCD information");
1102 kkaadze 1.61 } else if ( treeNumber == 1 ) {
1103 vuko 1.60 wzTree = new TTree("WZTree1","WZ number 1");
1104     electronTree = new TTree("ElTree1","electron information");
1105     } else if ( treeNumber == 2 ) {
1106     wzTree = new TTree("WZTree2","WZ number 2");
1107     electronTree = new TTree("ElTree2","electron information");
1108 kkaadze 1.58 } else if ( treeNumber == 3 ){
1109 vuko 1.60 wzTree = new TTree("WZTree3","WZ number 3");
1110     electronTree = new TTree("ElTree3","electron information");
1111 kkaadze 1.58 } else if (treeNumber == 4 ) {
1112 vuko 1.60 wzTree = new TTree("WZTree4","WZ number 4");
1113     electronTree = new TTree("ElTree4","electron information");
1114 kkaadze 1.58 } else if ( treeNumber == 5 ) {
1115 vuko 1.60 wzTree = new TTree("WZTree5","WZ number 5");
1116     electronTree = new TTree("ElTree5","electron information");
1117 kkaadze 1.58 } else if ( treeNumber == 6 ) {
1118 vuko 1.60 wzTree = new TTree("WZTree6","WZ number 6");
1119     electronTree = new TTree("ElTree6","electron information");
1120 kkaadze 1.58 } else if ( treeNumber == 7 ) {
1121 vuko 1.60 wzTree = new TTree("WZTree7","WZ number 7");
1122     electronTree = new TTree("ElTree7","electron information");
1123 kkaadze 1.58 } else if ( treeNumber == 8 ) {
1124 vuko 1.60 wzTree = new TTree("WZTree8","WZ number 8");
1125     electronTree = new TTree("ElTree8","electron information");
1126 kkaadze 1.58 } else { //( treeNumber == 9 ) {
1127 vuko 1.60 wzTree = new TTree("WZTree9","WZ number 9");
1128     electronTree = new TTree("ElTree9","electron information");
1129 kkaadze 1.58 }
1130 vuko 1.1
1131 vuko 1.60
1132 vuko 1.20
1133 smorovic 1.52 // jetTree = new TTree("JetTree","jet deltaR information");
1134    
1135 vuko 1.20 leptonProperties["electron"] = new ElectronProperties();
1136 vuko 1.1
1137 vuko 1.3 leptonProperties["Wel"] = new ElectronProperties();
1138     leptonProperties["ZEl1"] = new ElectronProperties();
1139     leptonProperties["ZEl2"] = new ElectronProperties();
1140    
1141     leptonProperties["Wmu"] = new MuonProperties();
1142     leptonProperties["Zmu1"] = new MuonProperties();
1143     leptonProperties["Zmu2"] = new MuonProperties();
1144 vuko 1.1
1145 vuko 1.54 leptonProperties["Zmul"] = new MuonProperties(); // SAME COMMENT AS BELOW: TEMPORARY FIX
1146 vuko 1.20
1147 vuko 1.3 leptonProperties["Wel"]->CreateBranches(wzTree, "WEl_");
1148 vuko 1.4 leptonProperties["ZEl1"]->CreateBranches(wzTree, "ZEl1_");
1149     leptonProperties["ZEl2"]->CreateBranches(wzTree, "ZEl2_");
1150 vuko 1.60
1151 vuko 1.54 leptonProperties["Wmu"]->CreateBranches(wzTree, "Wmu_");
1152 vuko 1.60
1153 vuko 1.54 leptonProperties["Zmu1"]->CreateBranches(wzTree, "Zmu1_");
1154 vuko 1.60
1155 vuko 1.54 leptonProperties["Zmul"]->CreateBranches(wzTree, "Zmul_");
1156     leptonProperties["Zmu2"]->CreateBranches(wzTree, "Zmu2_");
1157     leptonProperties["electron"]->CreateBranches(electronTree);
1158 vuko 1.60
1159     initialiseTree();
1160 senka 1.9
1161 smorovic 1.6
1162     //prepare HLT TriggerResults branch
1163     if (storeHLTresults) {
1164 vuko 1.60 wzTree->Branch("WZ_hltBitmask",&triggerBitmask,"WZ_hltBitmask/I");
1165     wzTree->Branch("QCD_hltBitmask",&triggerBitmaskQCD,"QCD_hltBitmask/I");
1166 smorovic 1.6 }
1167 senka 1.9
1168     // MET branch
1169 senka 1.44 wzTree->Branch("MET_Et",&MET_energy,"MET_Et/F");
1170 senka 1.9 wzTree->Branch("MET_pt",&MET_pt,"MET_pt/F");
1171     wzTree->Branch("MET_eta",&MET_eta,"MET_eta/F");
1172 vuko 1.50 wzTree->Branch("MET_phi",&MET_phi,"MET_eta/F");
1173 senka 1.9 wzTree->Branch("dPhi_WlZ_reco",&dPhi_WlZ_reco,"dPhi_WlZ_reco/F");
1174     wzTree->Branch("dPhi_WZ_reco",&dPhi_WZ_reco,"dPhi_WZ_reco/F");
1175 kkaadze 1.55 wzTree->Branch("dPhi_Wl_MET",&dPhi_Wl_MET,"dPhi_Wl_MET/F");
1176 vuko 1.60
1177 kkaadze 1.55 // MET branch after corrections
1178     wzTree->Branch("MET_Et_SCCorr",&MET_Et_SCCorr,"MET_Et_SCCorr/F");
1179     wzTree->Branch("MET_pt_SCCorr",&MET_pt_SCCorr,"MET_pt_SCCorr/F");
1180     wzTree->Branch("MET_phi_SCCorr",&MET_phi_SCCorr,"MET_phi_SCCorr/F");
1181     wzTree->Branch("dPhi_Wl_MET_SCCorr",&dPhi_Wl_MET_SCCorr,"dPhi_Wl_MET_SCCorr/F");
1182 vuko 1.60
1183 kkaadze 1.55 wzTree->Branch("MET_Et_ElCorr",&MET_Et_ElCorr,"MET_Et_SCCorr/F");
1184     wzTree->Branch("MET_pt_ElCorr",&MET_pt_ElCorr,"MET_pt_SCCorr/F");
1185     wzTree->Branch("MET_phi_ElCorr",&MET_phi_ElCorr,"MET_phi_SCCorr/F");
1186     wzTree->Branch("dPhi_Wl_MET_ElCorr",&dPhi_Wl_MET_ElCorr,"dPhi_Wl_MET_ElCorr/F");
1187 vuko 1.60
1188 beaucero 1.56 wzTree->Branch("WlTransMass", &wlTransMass, "WlTransMass/F");
1189     wzTree->Branch("WlTransMass_SCCorr", &wlTransMass_SCCorr, "WlTransMass_SCCorr/F");
1190     wzTree->Branch("WlTransMass_ElCorr", &wlTransMass_ElCorr, "WlTransMass_ElCorr/F");
1191 vuko 1.60
1192    
1193 senka 1.27 // # of non overlaping Zs
1194     wzTree->Branch("N_nonOverlaping_Z",&n,"N_nonOverlaping_Z/I");
1195     wzTree->Branch("N_looseMuons",&N_looseMuons,"N_looseMuons/I");
1196     wzTree->Branch("N_looseElectrons",&N_looseElectrons,"N_looseElectrons/I");
1197 kkaadze 1.61 wzTree->Branch("N_allElectrons",&N_allElectrons,"N_allElectrons/I");
1198 senka 1.27
1199 kkaadze 1.61 //for electron fakerate study
1200 kkaadze 1.62 wzTree->Branch("forElectronFakeRate",&forElectronFakeRate, "forElectronFakeRate/I");
1201     wzTree->Branch("forMuonFakeRate",&forMuonFakeRate, "forMuonFakeRate/I");
1202 kkaadze 1.61
1203 smorovic 1.52 EventCounter=0;
1204 kkaadze 1.63
1205     //Store HLT object info in different tree
1206    
1207     leptonProperties["El1"] = new ElectronProperties();
1208     leptonProperties["El2"] = new ElectronProperties();
1209     leptonProperties["El3"] = new ElectronProperties();
1210     leptonProperties["El4"] = new ElectronProperties();
1211     leptonProperties["El5"] = new ElectronProperties();
1212    
1213     // leptonProperties["Mu1"] = new ElectronProperties();
1214     // leptonProperties["Mu2"] = new ElectronProperties();
1215     // leptonProperties["Mu3"] = new ElectronProperties();
1216    
1217     leptonProperties["El1"]->CreateBranches(qcdTree, "El1_");
1218     leptonProperties["El2"]->CreateBranches(qcdTree, "El2_");
1219     leptonProperties["El3"]->CreateBranches(qcdTree, "El3_");
1220     leptonProperties["El4"]->CreateBranches(qcdTree, "El4_");
1221     leptonProperties["El5"]->CreateBranches(qcdTree, "El5_");
1222    
1223     // leptonProperties["Mu1"]->CreateBranches(qcdTree, "Mu1_");
1224     // leptonProperties["Mu2"]->CreateBranches(qcdTree, "Mu2_");
1225     // leptonProperties["Mu3"]->CreateBranches(qcdTree, "Mu3_");
1226    
1227    
1228     qcdTree->Branch("NbHltJet", &NbHltJet, "NbHltJet/I");
1229     qcdTree->Branch("hltJet4Pt", &hlt4JetPt, "hltJet4Pt/F");
1230     qcdTree->Branch("hltJet4Eta",&hlt4JetEta,"hltJet4Eta/F");
1231     qcdTree->Branch("hltJet4Phi",&hlt4JetPhi,"hltJet4Phi/F");
1232    
1233     qcdTree->Branch("hltJet3Pt", &hlt3JetPt, "hltJet3Pt/F");
1234     qcdTree->Branch("hltJet3Eta",&hlt3JetEta,"hltJet3Eta/F");
1235     qcdTree->Branch("hltJet3Phi",&hlt3JetPhi,"hltJet3Phi/F");
1236    
1237     qcdTree->Branch("hltJet2Pt", &hlt2JetPt, "hltJet2Pt/F");
1238     qcdTree->Branch("hltJet2Eta",&hlt2JetEta,"hltJet2Eta/F");
1239     qcdTree->Branch("hltJet2Phi",&hlt2JetPhi,"hltJet2Phi/F");
1240    
1241     qcdTree->Branch("hltJet1Pt", &hlt1JetPt, "hltJet1Pt/F");
1242     qcdTree->Branch("hltJet1Eta",&hlt1JetEta,"hltJet1Eta/F");
1243     qcdTree->Branch("hltJet1Phi",&hlt1JetPhi,"hltJet1Phi/F");
1244    
1245     qcdTree->Branch("Jet1Pt", &Jet1Pt, "Jet1Pt/F");
1246     qcdTree->Branch("Jet1Eta", &Jet1Eta, "Jet1Eta/F");
1247     qcdTree->Branch("Jet1Phi", &Jet1Phi, "Jet1Phi/F");
1248    
1249     qcdTree->Branch("weight", &eventWeight, "weight/F");
1250     qcdTree->Branch("processID", &processID, "processID/I");
1251     qcdTree->Branch("alpgenID", &alpgenID, "alpgenID/I");
1252     qcdTree->Branch("genEventScale", &eventScale, "genEventScale/F");
1253     qcdTree->Branch("RunNumber", &RunNumber, "RunNumber/I");
1254     qcdTree->Branch("EventID", &EventID, "EventID/I");
1255     qcdTree->Branch("WZ_hltBitmask",&triggerBitmask,"WZ_hltBitmask/I");
1256     qcdTree->Branch("QCD_hltBitmask",&triggerBitmaskQCD,"QCD_hltBitmask/I");
1257 vuko 1.1 }
1258    
1259     // ------------ method called once each job just after ending the event loop ------------
1260     void
1261     WZAnalyzer::endJob() {
1262 vuko 1.60 // cout << "In the end job with treeNumber = " << treeNumber << endl;
1263 vuko 1.1 theFile->Write();
1264     theFile->Close();
1265 vuko 1.60
1266 vuko 1.1 }
1267    
1268    
1269     void WZAnalyzer::initialiseTree() {
1270 vuko 1.26 // Event properties
1271     wzTree->Branch("weight", &eventWeight, "weight/F");
1272 smorovic 1.31 wzTree->Branch("processID", &processID, "processID/I");
1273 smorovic 1.36 wzTree->Branch("alpgenID", &alpgenID, "alpgenID/I");
1274 smorovic 1.48 wzTree->Branch("genEventScale", &eventScale, "genEventScale/F");
1275 smorovic 1.41 wzTree->Branch("RunNumber", &RunNumber, "RunNumber/I");
1276     wzTree->Branch("EventID", &EventID, "EventID/I");
1277 vuko 1.26
1278 vuko 1.1 // Z properties
1279     wzTree->Branch("Zmass", &zMass, "Zmass/F");
1280     wzTree->Branch("ZId", &zFlavour, "Zid/I");
1281     wzTree->Branch("ZPt", &zPt, "ZPt/F");
1282     wzTree->Branch("ZEta", &zEta, "ZEta/F");
1283     wzTree->Branch("ZPhi", &zPhi, "ZPhi/F");
1284    
1285     // W Properties
1286     wzTree->Branch("WlId", &wlFlavour, "Wlid/I");
1287     wzTree->Branch("WlCharge", &wlCharge, "WlCharge/I");
1288     wzTree->Branch("WlPt", &wlPt, "WlPt/F");
1289 vuko 1.50
1290     wzTree->Branch("nwlelcand", &nWlElCand, "nwlelcand/I");
1291     wzTree->Branch("nwlmucand", &nWlMuCand, "nwlmucand/I");
1292    
1293 smorovic 1.8
1294     wzTree->Branch("MC_leptonZ1_pt", &MCleptZ1_pt,"MC_leptonZ1_pt/F");
1295     wzTree->Branch("MC_leptonZ2_pt", &MCleptZ2_pt,"MC_leptonZ2_pt/F");
1296     wzTree->Branch("MC_leptonW_pt", &MCleptW_pt, "MC_leptonW_pt/F");
1297    
1298     wzTree->Branch("MC_leptonZ1_eta", &MCleptZ1_eta,"MC_leptonZ1_eta/F");
1299     wzTree->Branch("MC_leptonZ2_eta", &MCleptZ2_eta,"MC_leptonZ2_eta/F");
1300     wzTree->Branch("MC_leptonW_eta", &MCleptW_eta, "MC_leptonW_eta/F");
1301    
1302     wzTree->Branch("MC_leptonZ1_phi", &MCleptZ1_phi,"MC_leptonZ1_phi/F");
1303     wzTree->Branch("MC_leptonZ2_phi", &MCleptZ2_phi,"MC_leptonZ2_phi/F");
1304     wzTree->Branch("MC_leptonW_phi", &MCleptW_phi, "MC_leptonW_phi/F");
1305    
1306     wzTree->Branch("MC_leptonZ1_pdgid", &MCleptZ1_pdgid,"MC_leptonZ1_pdgid/I");
1307     wzTree->Branch("MC_leptonZ2_pdgid", &MCleptZ2_pdgid,"MC_leptonZ2_pdgid/I");
1308     wzTree->Branch("MC_leptonW_pdgid", &MCleptW_pdgid, "MC_leptonW_pdgid/I");
1309 vuko 1.14
1310     /*
1311     wzTree->Branch("MC_leptonW_origin", &MCleptW_pdgid, "MC_leptonW_origin/I");
1312     wzTree->Branch("MC_leptonZ1_origin", &MCleptW_pdgid, "MC_leptonZ1_origin/I");
1313     wzTree->Branch("MC_leptonZ2_origin", &MCleptW_pdgid, "MC_leptonZ2_origin/I");
1314     */
1315    
1316 smorovic 1.8 wzTree->Branch("MC_TauDecayType_fromZ1", &MC_tauDecayTypeZ1,"MC_TauDecayType_fromZ1/I");
1317     wzTree->Branch("MC_TauDecayType_fromZ2", &MC_tauDecayTypeZ2,"MC_TauDecayType_fromZ2/I");
1318     wzTree->Branch("MC_TauDecayType_fromW", &MC_tauDecayTypeW, "MC_TauDecayType_fromW/I");
1319 vuko 1.10
1320 beaucero 1.56 // Jet properties
1321 smorovic 1.41 wzTree->Branch("NbJets", &NbJets, "NbJets/I");
1322 vuko 1.49 wzTree->Branch("NCaloJets", &NCaloJets,"NCaloJets/I");
1323 smorovic 1.41
1324 vuko 1.10 wzTree->Branch("Jet1Et", &jet1Et, "Jet1Et/F");
1325     wzTree->Branch("Jet1Phi", &jet1Phi, "Jet1Phi/F");
1326     wzTree->Branch("Jet1Eta", &jet1Eta, "Jet1Eta/F");
1327    
1328     wzTree->Branch("Jet2Et", &jet2Et, "Jet2Et/F");
1329     wzTree->Branch("Jet2Phi", &jet2Phi, "Jet2Phi/F");
1330     wzTree->Branch("Jet2Eta", &jet2Eta, "Jet2Eta/F");
1331 smorovic 1.41 wzTree->Branch("ElectronTreesInEvent", &numberOfElectronTrees, "ElectronTreesInEvent/I");
1332 smorovic 1.52 wzTree->Branch("EventCounter", &EventCounter, "EventCounter/I");
1333 vuko 1.20 //
1334     electronTree->Branch("used", &electronUse, "used/I");
1335 smorovic 1.40 electronTree->Branch("weight", &eventWeight, "weight/F");
1336     electronTree->Branch("processID", &processID, "processID/I");
1337     electronTree->Branch("alpgenID", &alpgenID, "alpgenID/I");
1338 smorovic 1.48 electronTree->Branch("genEventScale", &eventScale, "genEventScale/F");
1339 smorovic 1.41 electronTree->Branch("ElectronTreesInEvent", &numberOfElectronTrees, "ElectronTreesInEvent/I");
1340    
1341     electronTree->Branch("RunNumber", &RunNumber, "RunNumber/I");
1342     electronTree->Branch("EventID", &EventID, "EventID/I");
1343 smorovic 1.52 electronTree->Branch("EventCounter", &EventCounter, "EventCounter/I");
1344 beaucero 1.42 electronTree->Branch("NbJetsWithLeptons", &NbJetsWithLeptons, "NbJetsWithLeptons/I");
1345 smorovic 1.52
1346     if (findBackJets) {
1347     electronTree->Branch("MET_Et",&MET_energy,"MET_Et/F");
1348     electronTree->Branch("MET_pt",&MET_pt,"MET_pt/F");
1349     electronTree->Branch("MET_eta",&MET_eta,"MET_eta/F");
1350 beaucero 1.56 electronTree->Branch("MET_phi",&MET_phi,"MET_phi/F");
1351 smorovic 1.52
1352     electronTree->Branch("backJet_found",&backJet_found,"backJet_found/I");
1353     electronTree->Branch("backJet_Et",&backJet_Et,"backJet_Et/F");
1354     electronTree->Branch("backJet_Eta",&backJet_Eta,"backJet_Eta/F");
1355     electronTree->Branch("backJet_Phi",&backJet_Phi,"backJet_Phi/F");
1356     electronTree->Branch("backJet_maxEInEmTowers",&backJet_maxEInEmTowers,"backJet_maxEInEmTowers/F");
1357     electronTree->Branch("backJet_maxEInHadTowers",&backJet_maxEInHadTowers,"backJet_maxEInHadTowers/F");
1358     electronTree->Branch("backJet_energyFractionHadronic",&backJet_energyFractionHadronic,"backJet_energyFractionHadronic/F");
1359     electronTree->Branch("backJet_emEnergyFraction",&backJet_emEnergyFraction,"backJet_emEnergyFraction/F");
1360     electronTree->Branch("backJet_hadEnergyInHB",&backJet_hadEnergyInHB,"backJet_hadEnergyInHB/F");
1361     electronTree->Branch("backJet_hadEnergyInHO",&backJet_hadEnergyInHO,"backJet_hadEnergyInHO/F");
1362     electronTree->Branch("backJet_hadEnergyInHE",&backJet_hadEnergyInHE,"backJet_hadEnergyInHE/F");
1363     electronTree->Branch("backJet_hadEnergyInHF",&backJet_hadEnergyInHF,"backJet_hadEnergyInHF/F");
1364     electronTree->Branch("backJet_emEnergyInEB",&backJet_emEnergyInEB,"backJet_emEnergyInEB/F");
1365     electronTree->Branch("backJet_emEnergyInEE",&backJet_emEnergyInEE,"backJet_emEnergyInEE/F");
1366     electronTree->Branch("backJet_emEnergyInHF",&backJet_emEnergyInHF,"backJet_emEnergyInHF/F");
1367     electronTree->Branch("backJet_towersArea",&backJet_towersArea,"backJet_towersArea/F");
1368     electronTree->Branch("backJet_n90",&backJet_n90,"backJet_n90/F");
1369     electronTree->Branch("backJet_n60",&backJet_n60,"backJet_n60/F");
1370    
1371     electronTree->Branch("backJet_NbTracks",&backJet_NbTracks,"backJet_NbTracks/I");
1372    
1373     electronTree->Branch("backJet_match",&backJet_match,"backJet_match/I");
1374     electronTree->Branch("backJet_matchPt",&backJet_matchPt,"backJet_matchPt/F");
1375     electronTree->Branch("backJet_match_dR",&backJet_match_dR,"backJet_match_dR/F");
1376    
1377    
1378    
1379     }
1380 vuko 1.50
1381     electronTree->Branch("WZ_hltBitmask",&triggerBitmask,"WZ_hltBitmask/I");
1382 smorovic 1.52 electronTree->Branch("QCD_hltBitmask",&triggerBitmaskQCD,"QCD_hltBitmask/I");
1383 smorovic 1.8 }
1384 vuko 1.1
1385 senka 1.9
1386 senka 1.28 //////////////////////////////////////////
1387     // MET & MET corrections
1388     // MET=MET-sum_p(muons)-sum_p(muons calos depositions)
1389    
1390     reco::Particle::LorentzVector WZAnalyzer::computeMET(const edm::Event& iEvent, const edm::EventSetup& iSetup, Handle<reco::CandidateCollection> MuonCands) {
1391 senka 1.9
1392     using namespace edm;
1393     using namespace reco;
1394     using namespace std;
1395 senka 1.44
1396 beaucero 1.45 double px_MET=0, py_MET=0, Ex_MET=0, Ey_MET=0;
1397 senka 1.44 double px,py,pz,pt,Et,Ex,Ey;
1398     double px_muons=0;
1399     double py_muons=0;
1400     double Ex_muons=0;
1401     double Ey_muons=0;
1402     double Et_muons=0;
1403     double Et_ecal;
1404     double Et_hcal;
1405     double Et_ho;
1406     double Et_cal;
1407     double Ex_ecal;
1408     double Ex_hcal;
1409     double Ex_ho;
1410     double Ey_ecal;
1411     double Ey_hcal;
1412     double Ey_ho;
1413     double eta_cal;
1414     double phi_cal;
1415     double tg_theta_pola_ecal;
1416     double tg_theta_pola_hcal;
1417     double tg_theta_pola_ho;
1418     double tg_theta_ecal;
1419     double tg_theta_hcal;
1420     double tg_theta_ho;
1421     double E_ecal;
1422     double E_hcal;
1423     double E_ho;
1424     double me=0.0005;
1425     double sin_theta_ecal, sin_theta_hcal, sin_theta_ho, cos_theta_ecal,cos_theta_hcal,cos_theta_ho;
1426     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;
1427     double Ex_cal=0;
1428     double Ey_cal=0;
1429     double px_cal=0;
1430     double py_cal=0;
1431     double Ex_kon=0;
1432     double Ey_kon=0;
1433    
1434     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
1435     reco::Particle::LorentzVector Muon_p_cal_4v(0,0,0,0);
1436 senka 1.9
1437     Handle<CaloMETCollection> mets;
1438     iEvent.getByLabel("met", mets);
1439 vuko 1.25 // cout << "# METs=" << mets->size() << endl;
1440 senka 1.44
1441 vuko 1.25 if (mets->size() != 1) {
1442 senka 1.44 cout << "ALARM: # METS is not 1: !" << endl;
1443 vuko 1.25 return reco::Particle::LorentzVector(0.,0.,0.,0.);
1444     }
1445 senka 1.44
1446 vuko 1.14 for (CaloMETCollection::const_iterator met = mets->begin();
1447     met!= mets->end(); met++) {
1448 senka 1.44 px_MET=met->px();
1449     py_MET=met->py();
1450     Ex_MET=met->et()*TMath::Cos(met->phi());
1451     Ey_MET=met->et()*TMath::Sin(met->phi());
1452    
1453 vuko 1.14 }
1454 senka 1.44
1455     // sum of p of muons
1456     for (unsigned int i=0; i<MuonCands->size();i++){
1457     px=(*MuonCands)[i].px();
1458     py=(*MuonCands)[i].py();
1459     pz=(*MuonCands)[i].pz();
1460     pt=(*MuonCands)[i].pt();
1461     Et=(*MuonCands)[i].et();
1462     Ex=Et*TMath::Cos((*MuonCands)[i].phi());
1463     Ey=Et*TMath::Sin((*MuonCands)[i].phi());
1464     px_muons=px_muons+px;
1465     py_muons=py_muons+py;
1466     Ex_muons=Ex_muons+Ex;
1467     Ey_muons=Ey_muons+Ey;
1468    
1469     }
1470     Et_muons=TMath::Sqrt(Ex_muons*Ex_muons+Ey_muons*Ey_muons);
1471     Muon_p_4v=reco::Particle::LorentzVector(px_muons,py_muons,0,Et_muons);
1472    
1473     // sum of p of muons left in calorimeters
1474     for (unsigned int i=0; i<MuonCands->size();i++){
1475     cout<<"" << endl;
1476     const reco::Muon* muons=dynamic_cast<const reco::Muon *> (&(*MuonCands)[i]);
1477     Et_ecal=muons->getCalEnergy().emS9;
1478     Et_hcal=muons->getCalEnergy().hadS9;
1479     Et_ho=muons->getCalEnergy().hoS9;
1480     eta_cal=muons->eta();
1481     phi_cal=muons->phi();
1482     tg_theta_pola_ecal=TMath::Exp(-eta_cal);
1483     tg_theta_pola_hcal=TMath::Exp(-eta_cal);
1484     tg_theta_pola_ho=TMath::Exp(-eta_cal);
1485     tg_theta_ecal=2*tg_theta_pola_ecal/(1-tg_theta_pola_ecal*tg_theta_pola_ecal);
1486     tg_theta_hcal=2*tg_theta_pola_hcal/(1-tg_theta_pola_hcal*tg_theta_pola_hcal);
1487     tg_theta_ho=2*tg_theta_pola_ho/(1-tg_theta_pola_ho*tg_theta_pola_ho);
1488     E_ecal=TMath::Abs(Et_ecal*TMath::Sqrt(1+tg_theta_ecal*tg_theta_ecal)/tg_theta_ecal);
1489     E_hcal=TMath::Abs(Et_hcal*TMath::Sqrt(1+tg_theta_hcal*tg_theta_hcal)/tg_theta_hcal);
1490     E_ho=TMath::Abs(Et_ho*TMath::Sqrt(1+tg_theta_ho*tg_theta_ho)/tg_theta_ho);
1491     Ex_ecal=Et_ecal*TMath::Cos(phi_cal);
1492     Ex_hcal=Et_hcal*TMath::Cos(phi_cal);
1493     Ex_ho=Et_ho*TMath::Cos(phi_cal);
1494     Ey_ecal=Et_ecal*TMath::Sin(phi_cal);
1495     Ey_hcal=Et_hcal*TMath::Sin(phi_cal);
1496     Ey_ho=Et_ho*TMath::Sin(phi_cal);
1497     sin_theta_ecal=tg_theta_ecal/TMath::Sqrt(1+tg_theta_ecal*tg_theta_ecal);
1498     sin_theta_hcal=tg_theta_hcal/TMath::Sqrt(1+tg_theta_hcal*tg_theta_hcal);
1499     sin_theta_ho=tg_theta_ho/TMath::Sqrt(1+tg_theta_ho*tg_theta_ho);
1500     cos_theta_ecal=TMath::Sqrt(1-sin_theta_ecal*sin_theta_ecal);
1501     cos_theta_hcal=TMath::Sqrt(1-sin_theta_hcal*sin_theta_hcal);
1502     cos_theta_ho=TMath::Sqrt(1-sin_theta_ho*sin_theta_ho);
1503     if (E_ecal<me){
1504     p_ecal=0;
1505     }
1506     else {
1507     p_ecal=TMath::Sqrt(E_ecal*E_ecal-me*me);
1508     }
1509     if (E_hcal<me){
1510     p_hcal=0;
1511     }
1512     else {
1513     p_hcal=TMath::Sqrt(E_hcal*E_hcal-me*me);
1514     }
1515     if (E_ho<me){
1516     p_ho=0;
1517     }
1518     else {
1519     p_ho=TMath::Sqrt(E_ho*E_ho-me*me);
1520     }
1521 senka 1.28
1522 senka 1.44 pz_ecal=p_ecal*cos_theta_ecal;
1523     pz_hcal=p_hcal*cos_theta_hcal;
1524     pz_ho=p_ho*cos_theta_ho;
1525     pt_ecal=TMath::Abs(p_ecal*sin_theta_ecal);
1526 senka 1.33
1527 senka 1.44 pt_hcal=TMath::Abs(p_hcal*sin_theta_hcal);
1528    
1529     pt_ho=TMath::Abs(p_ho*sin_theta_ho);
1530    
1531     px_ecal=pt_ecal*TMath::Cos(phi_cal);
1532     px_hcal=pt_hcal*TMath::Cos(phi_cal);
1533     px_ho=pt_ho*TMath::Cos(phi_cal);
1534     py_ecal=pt_ecal*TMath::Sin(phi_cal);
1535     py_hcal=pt_hcal*TMath::Sin(phi_cal);
1536     py_ho=pt_ho*TMath::Sin(phi_cal);
1537 senka 1.28
1538 senka 1.44
1539     Ex_cal=Ex_cal+Ex_ecal+Ex_hcal+Ex_ho;
1540     Ey_cal=Ey_cal+Ey_ecal+Ey_hcal+Ey_ho;
1541    
1542     px_cal=px_cal+px_ecal+px_hcal+px_ho;
1543     py_cal=py_cal+py_ecal+py_hcal+py_ho;
1544    
1545 senka 1.28
1546 senka 1.44 }
1547     Et_cal=TMath::Sqrt(Ex_cal*Ex_cal+Ey_cal*Ey_cal);
1548     Muon_p_cal_4v=reco::Particle::LorentzVector(px_cal,py_cal,0, Et_cal);
1549 senka 1.33
1550 senka 1.44 Ex_kon=Ex_MET-Ex_muons+Ex_cal;
1551     Ey_kon=Ey_MET-Ey_muons+Ey_cal;
1552 senka 1.28
1553 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
1554 senka 1.28
1555     return MET;
1556 senka 1.9
1557     }
1558    
1559 kkaadze 1.55 //MET Corrections from difference between corrected and uncorretced SC
1560     reco::Particle::LorentzVector WZAnalyzer::correctMETforSCCorrection(reco::Particle::LorentzVector MET_p_4v, Handle<reco::CandidateCollection> ElectronCands) {
1561    
1562     double SCRawEnergy = 0;
1563     double SCEnergy = 0;
1564     double deltaE = 0;
1565     double deltaET = 0;
1566     double deltaEx = 0;
1567     double deltaEy = 0;
1568    
1569     reco::Particle::LorentzVector SCCorr_p_4v(0,0,0,0); // sum of correction fraction of ET in (px,py,0,Et)
1570    
1571     //Loop over electron candidates and obtain the difference between uncorr and corr SC
1572     for (unsigned int i =0; i<ElectronCands->size(); ++i) {
1573     const reco::PixelMatchGsfElectron * electron = 0;
1574     if ( (*ElectronCands)[i].hasMasterClone() ) {
1575     reco::CandidateBaseRef master = (*ElectronCands)[i].masterClone();
1576     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*master));
1577     } else {
1578     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*ElectronCands)[i]);
1579     }
1580     const reco::SuperCluster& ElSC = *(electron->superCluster());
1581     SCRawEnergy = ElSC.rawEnergy();
1582     SCEnergy = ElSC.energy();
1583     //b.c. both uncrected and corrected SC clusters are oriented the same way, difference between vectors is just magnitudinal.
1584     deltaE = SCEnergy - SCRawEnergy;
1585     deltaET = deltaE/cosh(ElSC.eta());
1586     deltaEx += deltaET*cos(ElSC.phi());
1587     deltaEy += deltaET*sin(ElSC.phi());
1588     }
1589    
1590     deltaET = 0;
1591     deltaET = sqrt(deltaEx*deltaEx + deltaEy*deltaEy);
1592     SCCorr_p_4v = reco::Particle::LorentzVector(deltaEx, deltaEy, 0, deltaET);
1593     // return SCCorr_p_4v;
1594     return (MET_p_4v - SCCorr_p_4v);
1595     }
1596    
1597    
1598     //MET Corrections from difference between el energy and rawenergy of SC
1599     reco::Particle::LorentzVector WZAnalyzer::correctMETforElCorrection(reco::Particle::LorentzVector MET_p_4v, Handle<reco::CandidateCollection> ElectronCands) {
1600    
1601     double px = 0;
1602     double py = 0;
1603     double pz = 0;
1604     double Ex = 0;
1605     double Ey = 0;
1606     double Et = 0;
1607     double SCRawEnergy = 0;
1608     double SCPt = 0;
1609     double SCEt = 0;
1610     double SCpx = 0;
1611     double SCpy = 0;
1612     double SCEx = 0;
1613     double SCEy = 0;
1614    
1615     const reco::PixelMatchGsfElectron * electron = 0;
1616    
1617     reco::Particle::LorentzVector El_p_4v(0,0,0,0); // in (px,py,0,Et)
1618     reco::Particle::LorentzVector SC_p_4v(0,0,0,0);
1619    
1620     //Loop over electron candidates and obtain the difference between uncorr and corr SC
1621     for (unsigned int i =0; i<ElectronCands->size(); ++i) {
1622    
1623     px += (*ElectronCands)[i].px();
1624     py += (*ElectronCands)[i].py();
1625     pz += (*ElectronCands)[i].pz();
1626     Ex += (*ElectronCands)[i].et()*cos((*ElectronCands)[i].phi());
1627     Ey += (*ElectronCands)[i].et()*sin((*ElectronCands)[i].phi());
1628    
1629     if ( (*ElectronCands)[i].hasMasterClone() ) {
1630     reco::CandidateBaseRef master = (*ElectronCands)[i].masterClone();
1631     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*master));
1632     } else {
1633     electron = dynamic_cast<const reco::PixelMatchGsfElectron *>(&(*ElectronCands)[i]);
1634     }
1635     const reco::SuperCluster& ElSC = *(electron->superCluster());
1636     SCRawEnergy = ElSC.rawEnergy();
1637     SCPt = SCRawEnergy/cosh(ElSC.eta());
1638     SCEt = SCRawEnergy/cosh(ElSC.eta());
1639     SCpx += SCPt*cos(ElSC.phi());
1640     SCpy += SCPt*sin(ElSC.phi());
1641     SCEx += SCEt*cos(ElSC.phi());
1642     SCEy += SCEt*sin(ElSC.phi());
1643     }
1644    
1645     Et = sqrt(Ex*Ex + Ey*Ey);
1646     El_p_4v = reco::Particle::LorentzVector(px,py,0,Et);
1647    
1648     SCEt = sqrt(SCEx*SCEx + SCEy * SCEy);
1649     SC_p_4v = reco::Particle::LorentzVector(SCpx,SCpy,0,SCEt);
1650    
1651     reco::Particle::LorentzVector ElCorr_p_4v = El_p_4v - SC_p_4v;
1652     return (MET_p_4v - ElCorr_p_4v);
1653     }
1654    
1655    
1656    
1657 senka 1.12 ////////////////////////
1658     // matching
1659     //
1660    
1661     class MatchingInfo {
1662     public:
1663    
1664     MatchingInfo(float dr, int gen, int reco) : deltaR(dr), genMuon(gen),recoMuon(reco) {}
1665    
1666     bool operator<(const MatchingInfo m) { return deltaR < m.deltaR;}
1667    
1668     float deltaR;
1669     int genMuon;
1670     int recoMuon;
1671    
1672     };
1673    
1674    
1675     bool betterMatch(MatchingInfo m1, MatchingInfo m2)
1676     { return m1.deltaR < m2.deltaR;}
1677    
1678    
1679     // method that gives the vector<MatchingInfo> matching_Infos containing (dR,i,j); i=genParticle index, j=ParticleCollection index:
1680    
1681     void WZAnalyzer::matching(const edm::Event& iEvent, Handle<reco::CandidateCollection> cands, int pdgid){
1682    
1683     using namespace edm;
1684     using namespace reco;
1685     using namespace std;
1686    
1687     //-------------------------
1688     Handle<CandidateCollection> mccands;
1689     iEvent.getByLabel( theMCTruthCollection,mccands );
1690    
1691     vector <GenParticleCandidate*> genparticles;
1692    
1693     for(CandidateCollection::const_iterator p = mccands->begin();
1694     p != mccands->end(); p++) {
1695    
1696     // reco::Candidate* p_tmp = &(*p);
1697     reco::GenParticleCandidate* ptr = (reco::GenParticleCandidate*) &(*p);
1698    
1699     if ( (ptr)->status() == 1
1700     /*&& (ptr)->momentum().perp() > 2.*/ ) { // stable particles with pt>2 only
1701     if ( abs((ptr)->pdgId()) == pdgid ) {
1702     genparticles.push_back((ptr));
1703     //cout << "electron MCT\n";
1704     }
1705     }
1706     }
1707    
1708    
1709     int n1=0;
1710     vector<MatchingInfo> matching_Infos;
1711     for ( unsigned int i=0; i<genparticles.size(); i++ ) // po svim MC muonima
1712     {
1713    
1714     for (unsigned int j = 0; j < cands->size(); j++)// po svim reco muonima
1715     {
1716    
1717     double d_eta2=(*cands)[j].eta()-(genparticles)[i]->eta();
1718 smorovic 1.57 //double d_phi=fabs((*cands)[j].phi()-(genparticles)[i]->phi());
1719     double d_phi= kinem::delta_phi((*cands)[j].phi(),(genparticles)[i]->phi()) ;
1720 senka 1.12 double dR_byhand= sqrt(d_eta2*d_eta2+d_phi*d_phi);
1721     double dR=dR_byhand;
1722    
1723     if (dR<0.15){
1724     n1++;
1725     matching_Infos.push_back(MatchingInfo(dR,i,j));
1726     }
1727    
1728     }
1729     }
1730 senka 1.24
1731 senka 1.12 sort(matching_Infos.begin(),matching_Infos.end(),betterMatch); // sorting (dR,i,j)
1732 senka 1.24
1733     if (genparticles.size()!=0 && cands->size()!=0){
1734     // Now exclude combinations using same gen or rec muons
1735     for (std::vector<MatchingInfo>::iterator it=matching_Infos.begin();
1736     it != matching_Infos.end(); it++) {
1737     for (std::vector<MatchingInfo>::iterator it2=matching_Infos.begin();
1738     it2!=it; it2++) {
1739     if ( (it->genMuon == it2->genMuon) || (it->recoMuon == it2->recoMuon) ) {
1740     matching_Infos.erase(it);
1741     it=matching_Infos.begin();
1742     break;
1743     }
1744     }
1745     }
1746     }
1747    
1748 vuko 1.14 // Now put result in vector of pairs
1749    
1750     leptonMatching[pdgid].clear();
1751    
1752     for (vector<MatchingInfo>::iterator match=matching_Infos.begin();
1753 senka 1.16 match !=matching_Infos.end(); match++) { // po tablici dr,i,j
1754 vuko 1.14
1755     pair<const GenParticleCandidate*, const reco::Candidate *> pair;
1756 senka 1.16 // vector<pair,float > matchedParticles;
1757 vuko 1.14 pair.first = genparticles[match->genMuon];
1758     pair.second = & (*cands)[match->recoMuon];
1759 senka 1.16
1760     matchedParticles cestice(genparticles[match->genMuon] ,& (*cands)[match->recoMuon] , match->deltaR);
1761    
1762     leptonMatching[pdgid].push_back(cestice);
1763 senka 1.24
1764 vuko 1.14 }
1765 senka 1.24
1766 senka 1.12 }
1767    
1768 senka 1.9
1769 senka 1.13 // get mother of particle
1770     // returns mother = 1 if mother is Z boson
1771     // returns mother = 2 if mother is W boson
1772     // returns mother = 4 if mother is b
1773     // returns mother = 0 else
1774    
1775 vuko 1.14 WZAnalyzer::LeptonOrigin WZAnalyzer::getMother(const reco::Candidate* genParticle){
1776    
1777     int pdg_id=genParticle->pdgId();
1778 vuko 1.25 // cout << "particle id : " << pdg_id << endl;
1779 senka 1.13
1780     while (genParticle = genParticle->mother() ) { //izvrsava se sve dok ne dodje do nule tj. dok ne trazi majku od protona
1781 vuko 1.25 // cout << "Going up: ";
1782     // cout << "Mother id : " << genParticle->pdgId() << endl;
1783 senka 1.24 if (abs(genParticle->pdgId())!=abs(pdg_id)) {
1784 vuko 1.25 // cout<< " good mother " <<endl;
1785 senka 1.13 if (abs(genParticle->pdgId())==23){ // mother is Z
1786 vuko 1.14 return zboson;
1787 senka 1.13 }
1788     if (abs(genParticle->pdgId())==24) { // mother is W
1789 vuko 1.14 return wboson;
1790 senka 1.13 }
1791     // if (abs(genParticle->pdgId())==23 || abs(genParticle->pdgId())==24) { // mother is W or Z
1792     // WZ_matched=1;
1793     // mother=3;
1794     // }
1795     if ((((abs(genParticle->pdgId()))/100)%10 ==5)||(((abs(genParticle->pdgId()))/1000)%10 ==5 )) { // mother is b
1796 vuko 1.14 return bdecay;
1797 senka 1.13 }
1798 vuko 1.14 if ((((abs(genParticle->pdgId()))/100)%10 ==4)||(((abs(genParticle->pdgId()))/1000)%10 ==4 )) { // mother is c
1799     return cdecay;
1800     }
1801     return other;
1802 senka 1.13 }
1803 vuko 1.20 }
1804    
1805     return other;
1806 senka 1.13 }
1807    
1808 senka 1.15 const reco::Candidate * WZAnalyzer::MatchedGenParticle(const reco::Candidate * daughter){
1809     ::OverlapChecker overlap;
1810     matched_genParticle=0;
1811 senka 1.16
1812     for (map< int,
1813     std::vector< matchedParticles > > ::iterator iter = leptonMatching.begin();
1814     iter!=leptonMatching.end(); iter++) // entire map
1815     {
1816 kkaadze 1.61 cout << " loop over map " << endl;
1817     cout << iter->second.size() << endl;
1818 vuko 1.20 for (unsigned int j=0; j<iter->second.size(); j++){ // entire vector<class<>>
1819 kkaadze 1.61 cout << " nesto " << endl;
1820 senka 1.16 const reco::Candidate * nesto=iter->second[j].pair.second;
1821     if (overlap(*nesto,*daughter)){
1822     matched_genParticle=iter->second[j].pair.first;
1823     }
1824     }
1825     }
1826     return matched_genParticle;
1827     }
1828    
1829    
1830     float WZAnalyzer::dR(const reco::Candidate * daughter){
1831 vuko 1.18
1832 senka 1.16 ::OverlapChecker overlap;
1833 vuko 1.18
1834 senka 1.19 float delta_r = -10;
1835 senka 1.15 for (map< int,
1836 senka 1.16 std::vector< matchedParticles > > ::iterator iter = leptonMatching.begin();
1837 senka 1.15 iter!=leptonMatching.end(); iter++) // entire map
1838     {
1839 vuko 1.20 for (unsigned int j=0; j<iter->second.size(); j++){ // entire vector<class<>>
1840 senka 1.16 const reco::Candidate * nesto=iter->second[j].pair.second;
1841 senka 1.15 if (overlap(*nesto,*daughter)){
1842 senka 1.16 delta_r=iter->second[j].delta_R;
1843 senka 1.15 }
1844     }
1845     }
1846 senka 1.16 return delta_r;
1847 senka 1.15 }
1848    
1849 vuko 1.11
1850 senka 1.16
1851 vuko 1.10 void WZAnalyzer::collectMCsummary(Handle <reco::CandidateCollection> mccands) {
1852 senka 1.12
1853 vuko 1.11 using namespace reco;
1854    
1855 smorovic 1.8 //collections
1856 senka 1.24
1857 smorovic 1.8 MCleptZ1_pdgid = -1;
1858     MCleptZ2_pdgid = -1;
1859     MCleptW_pdgid = -1;
1860    
1861     MCleptZ1_pt = -1;
1862     MCleptZ2_pt = -1;
1863     MCleptW_pt = -1;
1864    
1865     MCleptZ1_eta = -1;
1866     MCleptZ2_eta = -1;
1867     MCleptW_eta = -1;
1868    
1869     MCleptZ1_phi = -1;
1870     MCleptZ2_phi = -1;
1871     MCleptW_phi = -1;
1872 senka 1.12
1873 smorovic 1.8 vector<reco::GenParticleCandidate*> Tau;
1874     vector<reco::GenParticleCandidate*> StableMuons;
1875     vector<reco::GenParticleCandidate*> StableElectrons;
1876 senka 1.24
1877 smorovic 1.32
1878    
1879 vuko 1.11 for(CandidateCollection::const_iterator p = mccands->begin();
1880     p != mccands->end(); p++) {
1881 vuko 1.1
1882 vuko 1.11 // reco::Candidate* p_tmp = &(*p);
1883     reco::GenParticleCandidate* ptr = (reco::GenParticleCandidate*) &(*p);
1884 smorovic 1.8
1885     if ( (ptr)->status() == 1
1886     /*&& (ptr)->momentum().perp() > 2.*/ ) { // stable particles with pt>2 only
1887     if ( abs((ptr)->pdgId()) == 11 ) {
1888 senka 1.12
1889 smorovic 1.8 StableElectrons.push_back((ptr));
1890     //cout << "electron MCT\n";
1891     }
1892     else if ( abs((ptr)->pdgId()) == 13 ) {
1893 senka 1.12
1894 smorovic 1.8 StableMuons.push_back((ptr)) ;
1895     //cout << "muon MCT\n";
1896     }
1897     }
1898     else if ((ptr)->status() == 2) {
1899     if ( abs((ptr)->pdgId()) == 15 ) {//tau
1900     Tau.push_back((ptr));
1901     }
1902     }
1903     }
1904 senka 1.12
1905 vuko 1.25 // std::cout << "# Electrons : " << StableElectrons.size()
1906     // << "# Muons : " << StableMuons.size() << std::endl
1907     // << "# Tau : " << Tau.size() << std::endl;
1908 senka 1.12
1909 smorovic 1.8
1910     vector<reco::GenParticleCandidate*> * StableLeptons[3] = {&StableElectrons, &StableMuons, &Tau};
1911    
1912 smorovic 1.32 vector<reco::GenParticleCandidate*> TauChildLeptons;
1913    
1914    
1915     //erase electrons and muons from tau from GenparticleCandidate Vector and put to Tau Vector
1916     for (int i=1; i>=0; i--) {
1917     for ( vector<reco::GenParticleCandidate*>::iterator lepton = StableLeptons[i]->begin();
1918     lepton != StableLeptons[i]->end();lepton++) {
1919    
1920     reco::GenParticleCandidate* mcParticleRef = *lepton;
1921    
1922     int parentItr=0;
1923     while ( mcParticleRef->mother()!=0 && parentItr<2) {
1924    
1925     parentItr++;
1926    
1927     mcParticleRef = (reco::GenParticleCandidate*) mcParticleRef->mother();
1928     if (mcParticleRef==0) break;
1929    
1930     //if tau
1931     if (abs((mcParticleRef)->pdgId())==15 ) {
1932     //put into collection
1933     TauChildLeptons.push_back(*lepton);
1934     StableLeptons[i]->erase(lepton);
1935     lepton--;
1936     break;
1937     }
1938     }
1939     }
1940     }
1941    
1942    
1943 smorovic 1.8 bool firstZlept = true;
1944 vuko 1.51 // int MC_tauDecayTypeZ1 = 0;
1945     // int MC_tauDecayTypeZ2 = 0;
1946     // int MC_tauDecayTypeW = 0;
1947     MC_tauDecayTypeZ1 = 0;
1948     MC_tauDecayTypeZ2 = 0;
1949     MC_tauDecayTypeW = 0;
1950 smorovic 1.32
1951    
1952 smorovic 1.8 for (int i=2; i>=0; i--) {
1953     while (StableLeptons[i]->size() > 0) {
1954     float maxPt = 0;
1955     vector<reco::GenParticleCandidate*>::iterator index = StableLeptons[i]->end();
1956    
1957     for ( vector<reco::GenParticleCandidate*>::iterator lepton = StableLeptons[i]->begin();
1958     lepton != StableLeptons[i]->end(); lepton++ ) {
1959 smorovic 1.32
1960 smorovic 1.8 if ((*lepton)->pt() > maxPt) {
1961     maxPt = (*lepton)->pt();
1962     index = lepton;
1963     }
1964     }
1965     bool Zchild = false;
1966     bool Wchild = false;
1967 smorovic 1.32 bool isTau = false;
1968    
1969    
1970 smorovic 1.8 reco::GenParticleCandidate* mcParticleRef = *index;
1971    
1972 smorovic 1.32 if (abs((*index)->pdgId()) == 15) isTau = true;
1973    
1974 smorovic 1.8 //find W/Z mother
1975 smorovic 1.32 int parentItr=0;
1976     while ( mcParticleRef->mother()!=0 && parentItr<2) {
1977    
1978 smorovic 1.8 if (parentItr>=2) break;
1979     parentItr++;
1980     mcParticleRef = (reco::GenParticleCandidate*) mcParticleRef->mother();
1981 smorovic 1.32 if (mcParticleRef==0) break;
1982 smorovic 1.8
1983     if (abs((mcParticleRef)->pdgId())==23 ) {
1984     Zchild=true;
1985     break;
1986     }
1987     if (abs((mcParticleRef)->pdgId())==24 ) {
1988     Wchild=true;
1989     break;
1990     }
1991     }
1992    
1993 smorovic 1.32
1994 smorovic 1.8 if (maxPt >0) {
1995 smorovic 1.32 int * MCtauDecayTypePtr = 0;
1996    
1997 smorovic 1.8 if (Wchild) {
1998     MCleptW_pdgid=(*index)->pdgId();
1999     MCleptW_pt=(float)(*index)->pt();
2000     MCleptW_eta=(float)(*index)->eta();
2001     MCleptW_phi=(float)(*index)->phi();
2002 smorovic 1.32 if (isTau) {
2003     MCtauDecayTypePtr = &MC_tauDecayTypeW;
2004     MC_tauDecayTypeW =3;//default to hadronic decay
2005     }
2006    
2007 smorovic 1.8 }
2008     if (Zchild) {
2009     if (firstZlept) {
2010     firstZlept=false;
2011     MCleptZ1_pdgid=(*index)->pdgId();
2012     MCleptZ1_pt=(float)(*index)->pt();
2013     MCleptZ1_eta=(float)(*index)->eta();
2014     MCleptZ1_phi=(float)(*index)->phi();
2015 smorovic 1.32 if (isTau) {
2016     MCtauDecayTypePtr = &MC_tauDecayTypeZ1;
2017     MC_tauDecayTypeZ1 =3;
2018     }
2019    
2020 smorovic 1.8 }
2021     else {
2022     MCleptZ2_pdgid=(*index)->pdgId();
2023     MCleptZ2_pt=(float)(*index)->pt();
2024     MCleptZ2_eta=(float)(*index)->eta();
2025     MCleptZ2_phi=(float)(*index)->phi();
2026 smorovic 1.32 if (isTau) {
2027     MCtauDecayTypePtr = &MC_tauDecayTypeZ2;
2028     MC_tauDecayTypeZ2 =3;
2029     }
2030    
2031     }
2032     }
2033     //check type of tau decay
2034     if (MCtauDecayTypePtr) {
2035     for( vector<reco::GenParticleCandidate*>::iterator p = TauChildLeptons.begin();p != TauChildLeptons.end(); p++) {
2036     int pitr = 0;
2037     reco::GenParticleCandidate* mcParticleRef = *p;
2038     while (mcParticleRef->mother() && pitr<2) {
2039     pitr++;
2040     mcParticleRef =(reco::GenParticleCandidate*) mcParticleRef->mother();
2041     if (mcParticleRef==0) break;
2042     if (mcParticleRef == *index) {
2043     if (abs((*p)->pdgId()) == 11) *MCtauDecayTypePtr = 1;
2044     if (abs((*p)->pdgId()) == 13) *MCtauDecayTypePtr = 2;
2045     }
2046     }
2047 smorovic 1.8 }
2048 smorovic 1.32 }
2049 smorovic 1.8 }
2050 smorovic 1.32 StableLeptons[i]->erase(index);
2051 smorovic 1.8 }
2052     }
2053     }
2054 vuko 1.1 //define this as a plug-in
2055 vuko 1.2 // DEFINE_FWK_MODULE(WZAnalyzer);
2056 smorovic 1.32