ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/WZSelection.cc
Revision: 1.1
Committed: Mon Feb 13 09:42:21 2012 UTC (13 years, 3 months ago) by khahn
Content type: text/plain
Branch: MAIN
CVS Tags: synced_FSR_2, synced_FSR, synched2, synched
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "WZSelection.h"
2 #include "PassHLT.h"
3
4 #include "SiMVAElectronSelection.h"
5
6 #include "HZZCiCElectronSelection.h"
7 #include "HZZLikelihoodElectronSelection.h"
8 #include "HZZBDTElectronSelection.h"
9 #include "RunLumiRangeMap.h"
10 #include "EfficiencyWeightsInterface.h"
11
12 extern RunLumiRangeMap rlrm;
13 extern TH1D * hpu;
14 extern TRandom3 r;
15
16 // lumi avg
17
18 extern double escale_EB_2011A;// = -0.00398*(2.2/4.7) -0.00884*(2.5/4.7);
19 extern double escale_EE_2011A;// = -0.01096*(2.2/4.7) +0.01499*(2.5/4.7);
20 extern double esmear_EB_2011A;// = 0.01513*(2.2/4.7) +0.01586*(2.5/4.7);
21 extern double esmear_EE_2011A;// = 0.04464*(2.2/4.7) +0.04321*(2.5/4.7);
22
23 extern double escale_EB_2011A_errup;// = -(0.00398+0.00008)*(2.2/4.7) -(0.00884+0.00007)*(2.5/4.7);
24 extern double escale_EE_2011A_errup;// = -(0.01096+0.00033)*(2.2/4.7) +(0.01499-0.00033)*(2.5/4.7);
25 extern double esmear_EB_2011A_errup;// = (0.01513+0.00266)*(2.2/4.7) +(0.01586+0.00263)*(2.5/4.7);
26 extern double esmear_EE_2011A_errup;// = (0.04464+0.00710)*(2.2/4.7) +(0.04321+0.00714)*(2.5/4.7);
27
28 extern double escale_EB_2011A_errdown;// = -(0.00398-0.00008)*(2.2/4.7) -(0.00884-0.00007)*(2.5/4.7);
29 extern double escale_EE_2011A_errdown;// = -(0.01096-0.00033)*(2.2/4.7) +(0.01499+0.00033)*(2.5/4.7);
30 extern double esmear_EB_2011A_errdown;// = (0.01513-0.00266)*(2.2/4.7) +(0.01586-0.00263)*(2.5/4.7);
31 extern double esmear_EE_2011A_errdown;// = (0.04464-0.00710)*(2.2/4.7) +(0.04321-0.00714)*(2.5/4.7);
32
33 extern double escale_EB_2011B;// = -0.00398*(2.2/4.7) -0.00884*(2.5/4.7);
34 extern double escale_EE_2011B;// = -0.01096*(2.2/4.7) +0.01499*(2.5/4.7);
35 extern double esmear_EB_2011B;// = 0.01513*(2.2/4.7) +0.01586*(2.5/4.7);
36 extern double esmear_EE_2011B;// = 0.04464*(2.2/4.7) +0.04321*(2.5/4.7);
37
38 extern double escale_EB_2011B_errup;// = -(0.00398+0.00008)*(2.2/4.7) -(0.00884+0.00007)*(2.5/4.7);
39 extern double escale_EE_2011B_errup;// = -(0.01096+0.00033)*(2.2/4.7) +(0.01499-0.00033)*(2.5/4.7);
40 extern double esmear_EB_2011B_errup;// = (0.01513+0.00266)*(2.2/4.7) +(0.01586+0.00263)*(2.5/4.7);
41 extern double esmear_EE_2011B_errup;// = (0.04464+0.00710)*(2.2/4.7) +(0.04321+0.00714)*(2.5/4.7);
42
43 extern double escale_EB_2011B_errdown;// = -(0.00398-0.00008)*(2.2/4.7) -(0.00884-0.00007)*(2.5/4.7);
44 extern double escale_EE_2011B_errdown;// = -(0.01096-0.00033)*(2.2/4.7) +(0.01499+0.00033)*(2.5/4.7);
45 extern double esmear_EB_2011B_errdown;// = (0.01513-0.00266)*(2.2/4.7) +(0.01586-0.00263)*(2.5/4.7);
46 extern double esmear_EE_2011B_errdown;// = (0.04464-0.00710)*(2.2/4.7) +(0.04321-0.00714)*(2.5/4.7);
47
48 // +/- 1% for muons, no additional smearing
49 extern float scale_smear_muon_Up( float pt, bool isEB, TRandom3 &r );
50 extern float scale_smear_muon_Down( float pt, bool isEB, TRandom3 &r );
51 extern float scale_smear_electron_Down( float pt, bool isEB, TRandom3 &r );
52 extern float scale_smear_electron_Up( float pt, bool isEB, TRandom3 &r );
53 extern float scale_smear_electron( float pt, bool isEB, TRandom3 &r );
54 extern bool failEleIso(SimpleLepton lep);
55
56 float calc_mT(float iPt1,float iPt2,float iPhi1,float iPhi2) {
57 float lPx = iPt1*cos(iPhi1)+iPt2*cos(iPhi2);
58 float lPy = iPt1*sin(iPhi1)+iPt2*sin(iPhi2);
59 return sqrt((iPt1+iPt2)*(iPt1+iPt2)-lPx*lPx-lPy*lPy);
60 };
61
62 unsigned fails_WZ3L_selection(ControlFlags &ctrl, // input control
63 mithep::TGenInfo *ginfo , // input gen info
64 mithep::TEventInfo *info, // input event info
65 TClonesArray *electronArr, // input electrons
66 TClonesArray *muonArr, // input muons
67 double eventweight, // weight
68 TTree * passtuple ) {
69
70 fails_WZ3L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, NULL, NULL );
71
72 };
73
74 unsigned fails_WZ3L_selection(ControlFlags &ctrl, // input control
75 mithep::TEventInfo *info, // input event info
76 TClonesArray *electronArr, // input electrons
77 TClonesArray *muonArr, // input muons
78 double eventweight, // weight
79 TTree * passtuple,
80 LabVectors * l ) {
81 fails_WZ3L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, l, NULL );
82 }
83
84
85 unsigned fails_WZ3L_selection(ControlFlags &ctrl, // input control
86 mithep::TEventInfo *info, // input event info
87 TClonesArray *electronArr, // input electrons
88 TClonesArray *muonArr, // input muons
89 double eventweight, // weight
90 TTree * passtuple,
91 LabVectors * l=NULL,
92 TClonesArray *jetArr=NULL ) { // output ntuple
93
94 unsigned evtfail = 0x0;
95 unsigned gchannel=0xdeaddead;
96
97
98 // if( ctrl.mc && ginfo != NULL ) {
99 // gchannel = getGenChannel(ginfo);
100 // }
101
102
103 if( ctrl.debug ) {
104 cout << "Run: " << info->runNum
105 << "\tEvt: " << info->evtNum
106 << "\tLumi: " << info->lumiSec
107 << endl;
108 }
109
110 unsigned npu; double npuw;
111 if( !ctrl.mc ) {
112 // not accounting for overlap atm
113 RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec);
114 if( !(rlrm.HasRunLumi(rl)) ) {
115 if( ctrl.debug ) cout << "\tfails JSON" << endl;
116 evtfail |= (1<<EVTFAIL_JSON);
117 return evtfail;
118 }
119 } else {
120 npu = info->nPU;
121 npuw = hpu->GetBinContent(hpu->FindBin(npu));
122 }
123
124
125
126
127
128 //********************************************************
129 // Trigger
130 //********************************************************
131 if( !ctrl.mc ) {
132 //if( !(passHLT(info->triggerBits, info->runNum, channel) ) ) {
133 if( !(passHLT(info->triggerBits, info->runNum, 999) ) ) {
134 if( ctrl.debug ) cout << "\tfails trigger" << endl;
135 evtfail |= (1<<EVTFAIL_TRIGGER);
136 return evtfail;
137 }
138 }
139
140 if( ctrl.debug ) {
141 cout << "presel nlep: " << muonArr->GetEntries() + electronArr->GetEntries()
142 << "\tnmuon: " << muonArr->GetEntries()
143 << "\tnelectron: " << electronArr->GetEntries()
144 << endl;
145 }
146
147 //********************************************************
148 // Lepton Selection
149 //********************************************************
150 vector<SimpleLepton> lepvec;
151
152 //
153 if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
154 //----------------------------------------------------
155 for(Int_t i=0; i<muonArr->GetEntries(); i++) {
156 const mithep::TMuon *mu = (mithep::TMuon*)((*muonArr)[i]);
157 unsigned muonfail;
158 if( ctrl.muSele == "ksWW" )
159 muonfail = passKSMuonSelection(mu);
160 else
161 muonfail = passMuonSelectionZZ(mu);
162 if( ctrl.debug ) {
163 cout << "muon:: pt: " << mu->pt
164 << "\teta: " << mu->eta
165 << "\tisorel: " << mu->pfIso03/mu->pt
166 << "\tmask: 0x" << hex << muonfail << dec
167 << endl;
168 }
169
170 #ifdef Z2FO
171 if ( isMuFO(mu) ) {
172 #else
173 if ( !muonfail ) {
174 #endif
175 SimpleLepton tmplep;
176
177 float pt = mu->pt;
178 if( ctrl.do_escale_up ) {
179 pt=scale_smear_muon_Up(pt, 1, r);
180 }
181 if( ctrl.do_escale_down ) {
182 pt=scale_smear_muon_Down(pt, 1, r);
183 }
184 // if( ctrl.do_escale_up ) pt*=(1.01);
185 // if( ctrl.do_escale_down ) pt*=(0.99);
186
187 tmplep.vec.SetPtEtaPhiM(pt,
188 mu->eta,
189 mu->phi,
190 105.658369e-3);
191
192 tmplep.type = 13;
193 tmplep.index = i;
194 tmplep.charge = mu->q;
195 tmplep.isoTrk = mu->trkIso03;
196 tmplep.isoEcal = mu->emIso03;
197 tmplep.isoHcal = mu->hadIso03;
198 tmplep.isoPF03 = mu->pfIso03;
199 tmplep.isoPF04 = mu->pfIso04;
200 tmplep.ip3dSig = mu->ip3dSig;
201 tmplep.is4l = false;
202 tmplep.isEB = (fabs(mu->eta) < 1.479 ? 1 : 0 );
203 tmplep.isTight = (muonfail > 0 ? 0 : 1 );
204 tmplep.isLoose = (muonfail > 0 ? 0 : 1 );
205 tmplep.tightCutsApplied = false;
206 lepvec.push_back(tmplep);
207 if( ctrl.debug ) { cout << "muon passes ... " << endl;}
208 }
209 }
210
211 if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
212
213 //----------------------------------------------------
214 for(Int_t i=0; i<electronArr->GetEntries(); i++) {
215 const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]);
216
217 if( !(isEleFO(ctrl,ele) ) ) continue;
218 // TMP tigheter
219 if( ele->isConv ) continue;
220 if( !(ele->isEcalDriven) ) continue;
221 // TMP tigheter
222 if( ele->pt < 7 ) continue; //move this to ID
223
224 Bool_t isMuonOverlap = kFALSE;
225 for (int k=0; k<lepvec.size(); ++k) {
226 TVector3 tmplep;
227 tmplep.SetPtEtaPhi(ele->pt, ele->eta, ele->phi);
228 if ( lepvec[k].isLoose && lepvec[k].type == 13 && lepvec[k].vec.Vect().DrEtaPhi(tmplep) < 0.1 ) {
229 if( ctrl.debug ) cout << "-----> isMuonOverlap! " << endl;
230 isMuonOverlap = kTRUE;
231 break;
232 }
233 }
234
235 unsigned FAIL=0, isEleTight=0, isEleLoose=0;
236
237 unsigned failsCIC=0;
238 CICStruct ciccuts_tight, ciccuts_medium, ciccuts_loose;
239 if(ctrl.eleSele=="cic") {
240 if( ctrl.eleSeleScheme == "mediumloose" ) {
241 ciccuts_medium = getCiCCuts("medium");
242 unsigned failsCICMedium = failsCicSelection(ctrl, ele, ciccuts_medium, ctrl.kinematics);
243 ciccuts_loose = getCiCCuts("loose");
244 unsigned failsCICLoose = failsCicSelection(ctrl, ele, ciccuts_loose, ctrl.kinematics);
245 failsCIC = ( failsCICLoose > 0 && failsCICMedium > 0 );
246 if( !failsCICMedium ) isEleTight=1;
247 }
248 else {
249 ciccuts_tight = getCiCCuts(ctrl.eleSeleScheme);
250 failsCIC = failsCicSelection(ctrl, ele, ciccuts_tight, ctrl.kinematics);
251 if( !failsCIC ) isEleTight=1;
252 }
253 FAIL = failsCIC;
254 }
255
256 LikStruct likcuts;
257 unsigned failsLike=0;
258 if(ctrl.eleSele=="lik") {
259 likcuts = getLikCuts(ctrl.eleSeleScheme);
260 failsLike = failsLikelihoodSelection(ele, likcuts, ctrl.kinematics);
261 FAIL = failsLike;
262 }
263 unsigned failsBDT=0;
264 if(ctrl.eleSele=="bdt") {
265 if( ctrl.eleSeleScheme == "mediumloose" ) {
266 unsigned failsBDTMedium = failsBDTSelection(ctrl,"medium",ele);
267 unsigned failsBDTLoose = failsBDTSelection(ctrl,"loose",ele);
268 failsBDT = ( failsBDTLoose > 0 && failsBDTMedium > 0 );
269 if( !failsBDTMedium ) isEleTight=1;
270 if( !failsBDTLoose ) isEleLoose=1;
271 } else {
272 failsBDT = failsBDTSelection(ctrl,"tight",ele);
273 if( !failsBDT ) isEleTight=1;
274 }
275 FAIL = failsBDT;
276 }
277
278
279 if( ctrl.debug ){
280 cout << "CIC category: " << cicCategory(ele)
281 << "\tlikelihood: " << ele->likelihood
282 << "\tFAIL: 0x" << hex << FAIL << dec
283 << "\tfailsCIC: 0x" << hex << failsCIC << dec
284 << "\tfailsLike: 0x" << hex << failsLike << dec
285 << "\tfailsBDT: 0x" << hex << failsBDT << dec
286 << "\tscEt: " << ele->scEt
287 << "\tscEta: " << ele->scEta
288 << "\tncluster: " << ele->ncluster
289 << "\tisorel: " << ele->pfIso04/ele->pt
290 << endl;
291 }
292 if ( !FAIL && !isMuonOverlap ) {
293 SimpleLepton tmplep;
294
295 float pt = ele->pt;
296
297 if( ctrl.do_escale ) {
298 pt=scale_smear_electron(pt, ele->isEB, r);
299 }
300 if( ctrl.do_escale_up ) {
301 pt=scale_smear_electron_Up(pt, ele->isEB, r);
302 }
303 if( ctrl.do_escale_down ) {
304 pt=scale_smear_electron_Down(pt, ele->isEB, r);
305 }
306
307 if( pt < 7. ) continue;
308 tmplep.vec.SetPtEtaPhiM( pt,
309 ele->eta,
310 ele->phi,
311 0.51099892e-3 );
312
313
314 tmplep.type = 11;
315 tmplep.index = i;
316 tmplep.charge = ele->q;
317 tmplep.isoTrk = ele->trkIso03;
318 tmplep.isoEcal = ele->emIso03;
319 tmplep.isoHcal = ele->hadIso03;
320 tmplep.isoPF03 = ele->pfIso03;
321 tmplep.isoPF04 = ele->pfIso04;
322 tmplep.ip3dSig = ele->ip3dSig;
323 tmplep.is4l = false;
324 tmplep.tightCutsApplied = false;
325 tmplep.isEB = ele->isEB;
326 tmplep.scID = ele->scID;
327 // tmplep.isTight = isEleTight;
328 tmplep.isTight = isEleTight;
329 if( failEleIso(tmplep) ) continue;
330 lepvec.push_back(tmplep);
331 if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
332 }
333 }
334
335 sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
336
337 int nmu=0, nele=0;
338 for( int i=0; i<lepvec.size(); i++ ) {
339 if(ctrl.debug) cout << "lepvec :: index: " << i
340 << "\tpt: " << lepvec[i].vec.Pt()
341 << "\ttype: " << lepvec[i].type
342 << endl;
343 if( abs(lepvec[i].type) == 11 ) nele++;
344 else nmu++;
345 }
346 if( ctrl.debug ) {
347 cout << "postsel nlep: " << lepvec.size()
348 << "\tnmuon: " << nmu
349 << "\tnelectron: " << nele
350 << endl;
351 }
352
353 //******************************************************************************
354 //Z1 Selection
355 //******************************************************************************
356 int Z1LeptonPlusIndex = -1;
357 int Z1LeptonMinusIndex = -1;
358 double BestZ1Mass = -999;
359 if( ctrl.debug ) { cout << "looking for a Z1 ..." << endl; }
360 for(int i = 0; i < lepvec.size(); ++i) {
361 if( !(lepvec[i].isLoose ||lepvec[i].isTight ) ) continue;
362 for(int j = i+1; j < lepvec.size(); ++j) {
363 if( !(lepvec[j].isLoose || lepvec[j].isTight) ) continue;
364 if( ctrl.debug ) { cout << "\tconsidering leptons " << i << " & " << j << endl; }
365 if (!(lepvec[i].vec.Pt() > 20.0 || lepvec[j].vec.Pt() > 20.0)) continue;
366 if( ctrl.debug ) { cout << "\tat least one is > 20 GeV" << endl; }
367 if (!(lepvec[i].vec.Pt() > 10.0 && lepvec[j].vec.Pt() > 10.0)) continue;
368 if( ctrl.debug ) { cout << "\tthe other is > 10 GeV" << endl; }
369 if (lepvec[i].charge == lepvec[j].charge) continue;
370 if( ctrl.debug ) { cout << "\tthey're opposite charge" << endl; }
371 if (fabs(lepvec[i].type) != fabs(lepvec[j].type)) continue;
372 if( ctrl.debug ) { cout << "\tthey're same flavor" << endl; }
373
374 //Make Z1 hypothesis
375 TLorentzVector leptonPlus, leptonMinus;
376 if ( lepvec[i].charge > 0 ) {
377 leptonPlus = lepvec[i].vec;
378 leptonMinus = lepvec[j].vec;
379 } else {
380 leptonPlus = lepvec[j].vec;
381 leptonMinus = lepvec[i].vec;
382 }
383
384 float tmpZ1Mass = (leptonPlus+leptonMinus).M();
385 if( ctrl.debug ) cout << "Z1 selection, tmpZ1Mass: " << tmpZ1Mass << endl;
386 // TMP
387 // if( tmpZ1Mass > 60 ) {
388 if (fabs(tmpZ1Mass - 91.1876) < fabs(BestZ1Mass - 91.1876)) {
389 BestZ1Mass = tmpZ1Mass;
390 if( ctrl.debug ) cout << "Z1 selection, new BestZ1Mass: " << BestZ1Mass
391 << "\tdM: " << fabs(BestZ1Mass - 91.1876)
392 << endl;
393 if (lepvec[i].charge > 0) {
394 Z1LeptonPlusIndex = i;
395 Z1LeptonMinusIndex = j;
396 } else {
397 Z1LeptonPlusIndex = j;
398 Z1LeptonMinusIndex = i;
399 }
400 }
401 // }
402 // TMP
403 }
404 }
405 // stop if no Z1 candidate is found
406 if( BestZ1Mass < 0 ) {
407 evtfail |= (1<<EVTFAIL_Z1);
408 return evtfail;
409 }
410 if( ctrl.debug ) cout << "\tgot a Z1 ... run: " << info->runNum << "\tevt: " << info->evtNum << endl;
411 if( ctrl.debug ) cout << "\tZ1 plusindex: " << Z1LeptonPlusIndex << "\tminusindex: " << Z1LeptonMinusIndex << endl;
412 TLorentzVector Z1LeptonPlus = lepvec[Z1LeptonPlusIndex].vec;
413 TLorentzVector Z1LeptonMinus = lepvec[Z1LeptonMinusIndex].vec;
414 lepvec[Z1LeptonPlusIndex].is4l = true;
415 lepvec[Z1LeptonMinusIndex].is4l = true;
416 TLorentzVector Z1Candidate = Z1LeptonPlus + Z1LeptonMinus;
417 if( l != NULL ) {
418 l->vecz1 = Z1Candidate;
419 l->vecl1p = Z1LeptonPlus;
420 l->vecl1m = Z1LeptonMinus;
421 }
422
423 //******************************************************************************
424 // Z1 + l
425 //******************************************************************************
426 int l3LeptonIndex;
427 if( lepvec.size() < 3 ) {
428 evtfail |= (1<<EVTFAIL_Z1_PLUSL);
429 return evtfail;
430 }
431 unsigned nothers=0;
432 unsigned ntight=0;
433 for( int i=0; i<lepvec.size(); i++ ) {
434 if( i != Z1LeptonPlusIndex && i!= Z1LeptonMinusIndex ) {
435 if ( lepvec[i].isTight ) {
436 lepvec[i].is4l = true;
437 lepvec[i].tightCutsApplied = true;
438 l3LeptonIndex = i ;
439 ntight++;
440 } else {
441 nothers++;
442 }
443 }
444 }
445 if( ntight != 1 ) {
446 evtfail |= (1<<EVTFAIL_Z1_PLUSL);
447 return evtfail;
448 }
449
450 //***************************************************************
451 // Isolation
452 //***************************************************************
453 bool failiso=false;
454
455 if( ctrl.isoScheme == "pf" ) {
456
457 for( int i=0; i<lepvec.size(); i++ ) {
458
459 if( !(lepvec[i].is4l) ) continue;
460
461 if( abs(lepvec[i].type) == 11 ) {
462 /*
463 float reliso = lepvec[i].isoPF04/lepvec[i].vec.Pt();
464 if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_ELE_LOOSE_EB_HIGHPT ) {
465 failiso = true;
466 break;
467 }
468 if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_ELE_LOOSE_EB_LOWPT ) {
469 failiso = true;
470 break;
471 }
472 if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_ELE_LOOSE_EE_HIGHPT ) {
473 failiso = true;
474 break;
475 }
476 if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_ELE_LOOSE_EE_LOWPT ) {
477 failiso = true;
478 break;
479 }
480 */
481 }
482
483 if( abs(lepvec[i].type) == 13 ) {
484
485 /*
486 float reliso = lepvec[i].isoPF03/lepvec[i].vec.Pt();
487 if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EB_HIGHPT ) { //0.13
488 failiso = true;
489 break;
490 }
491 if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EB_LOWPT ) { //0.06
492 failiso = true;
493 break;
494 }
495 if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EE_HIGHPT ) { //0.09
496 failiso = true;
497 break;
498 }
499 if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EE_LOWPT ) { //0.05
500 failiso = true;
501 break;
502 }
503 */
504 }
505 }
506 } else if ( ctrl.isoScheme == "pairwise" ) {
507 float rho = info->rho;
508 for( int i=0; i<lepvec.size(); i++ ) {
509 if( !(lepvec[i].is4l) ) continue;
510 float effArea_ecal_i, effArea_hcal_i;
511 if( lepvec[i].isEB ) {
512 if( lepvec[i].type == 11 ) {
513 effArea_ecal_i = 0.101;
514 effArea_hcal_i = 0.021;
515 } else {
516 effArea_ecal_i = 0.074;
517 effArea_hcal_i = 0.022;
518 }
519 } else {
520 if( lepvec[i].type == 11 ) {
521 effArea_ecal_i = 0.046;
522 effArea_hcal_i = 0.040;
523 } else {
524 effArea_ecal_i = 0.045;
525 effArea_hcal_i = 0.030;
526 }
527 }
528 float isoEcal_corr_i = lepvec[i].isoEcal - (effArea_ecal_i*rho);
529 float isoHcal_corr_i = lepvec[i].isoHcal - (effArea_hcal_i*rho);
530 for( int j=i+1; j<lepvec.size(); j++ ) {
531 if( !(lepvec[j].is4l) ) continue;
532 float effArea_ecal_j, effArea_hcal_j;
533 if( lepvec[j].isEB ) {
534 if( lepvec[j].type == 11 ) {
535 effArea_ecal_j = 0.101;
536 effArea_hcal_j = 0.021;
537 } else {
538 effArea_ecal_j = 0.074;
539 effArea_hcal_j = 0.022;
540 }
541 } else {
542 if( lepvec[j].type == 11 ) {
543 effArea_ecal_j = 0.046;
544 effArea_hcal_j = 0.040;
545 } else {
546 effArea_ecal_j = 0.045;
547 effArea_hcal_j = 0.030;
548 }
549 }
550 float isoEcal_corr_j = lepvec[j].isoEcal - (effArea_ecal_j*rho);
551 float isoHcal_corr_j = lepvec[j].isoHcal - (effArea_hcal_j*rho);
552 float RIso_i = (lepvec[i].isoTrk+isoEcal_corr_i+isoHcal_corr_i)/lepvec[i].vec.Pt();
553 float RIso_j = (lepvec[j].isoTrk+isoEcal_corr_j+isoHcal_corr_j)/lepvec[j].vec.Pt();
554 float comboIso = RIso_i + RIso_j;
555 if( info->evtNum == 1038911933 ) {
556 float tmpdR = lepvec[i].vec.DrEtaPhi(lepvec[j].vec);
557 cout << "i: " << i
558 << "\tdR: " << tmpdR
559 << "\trho: " << rho
560 << "\tRIso_i: " << RIso_i
561 << "\ttkrel: " << lepvec[i].isoTrk/lepvec[i].vec.Pt()
562 << "\tecalrel: " << lepvec[i].isoEcal/lepvec[i].vec.Pt()
563 << "\tecalrelcor: " << isoEcal_corr_i/lepvec[i].vec.Pt()
564 << "\thcalrel: " << lepvec[i].isoHcal/lepvec[i].vec.Pt()
565 << "\thcalrelcor: " << isoHcal_corr_i/lepvec[i].vec.Pt()
566 << "\tpt_i: " << lepvec[i].vec.Pt()
567 << "\tj: " << j
568 << "\tRIso_j: " << RIso_j
569 << "\ttkrel: " << lepvec[j].isoTrk/lepvec[j].vec.Pt()
570 << "\tecalrel: " << lepvec[j].isoEcal/lepvec[j].vec.Pt()
571 << "\tecalrelcor: " << isoEcal_corr_j/lepvec[j].vec.Pt()
572 << "\thcalrel: " << lepvec[j].isoHcal/lepvec[j].vec.Pt()
573 << "\thcalrelcor: " << isoHcal_corr_j/lepvec[j].vec.Pt()
574 << "\tpt_j: " << lepvec[j].vec.Pt()
575 << "\tcombo: " << comboIso
576 << endl;
577 cout.flush();
578 }
579 if( comboIso > 0.35 ) {
580 if( ctrl.debug ) cout << "combo failing for indices: " << i << "," << j << endl;
581 failiso = true;
582 // break;
583 }
584 }
585 }
586 }
587
588
589 for( int i=0; i<lepvec.size(); i++ ) {
590
591 if( !(lepvec[i].is4l) ) continue;
592 if(ctrl.debug) cout << "checking iso for index: " << i;
593 if( abs(lepvec[i].type) == 11 ) {
594 float reliso= lepvec[i].isoPF04/lepvec[i].vec.Pt();
595 if(ctrl.debug) cout << ", reliso: " << reliso;
596 } else {
597 float reliso= lepvec[i].isoPF03/lepvec[i].vec.Pt();
598 if(ctrl.debug) cout << ", reliso: " << reliso;
599 }
600 if( ctrl.debug ) cout << endl;
601 }
602
603 if( failiso ) {
604 evtfail |= ( 1<<EVTFAIL_ISOLATION );
605 return evtfail;
606 if(ctrl.debug) cout << "failing iso ... " << endl;
607 //h_evtfail->Fill( evtfail, eventweight );
608 // h_evtfail->Fill( evtfail );
609 // cout << "evtfail: " << hex << evtfail << dec << endl;
610 // continue;
611 }
612
613
614 //***************************************************************
615 // IP significance
616 //***************************************************************
617 bool failip = false;
618 for( int i=0; i<lepvec.size(); i++ ) {
619 if( !(lepvec[i].is4l) ) continue;
620 if( fabs(lepvec[i].ip3dSig) > 4 ) {
621 failip=true;
622 break;
623 }
624 }
625 if( failip ) {
626 evtfail |= (1<<EVTFAIL_IP );
627 return evtfail;
628 //h_evtfail->Fill( evtfail, eventweight );
629 // h_evtfail->Fill( evtfail );
630 // cout << "evtfail: " << hex << evtfail << dec << endl;
631 // continue;
632 }
633
634 //***************************************************************
635 // remaining kinematic cuts
636 //***************************************************************
637 double Z2massCut=0;
638 if ( ctrl.kinematics == "loose" ) Z2massCut = 12;
639 else if ( ctrl.kinematics == "tight" ) Z2massCut = 20;
640 else { cout << "error! kinematic tightness not defined!" << endl; assert(0); }
641
642 if ( Z1Candidate.M() > 120 ||
643 !(lepvec[Z1LeptonPlusIndex].vec.Pt() > 20.0 || lepvec[Z1LeptonMinusIndex].vec.Pt() > 20.0) ||
644 !(lepvec[Z1LeptonPlusIndex].vec.Pt() > 10.0 && lepvec[Z1LeptonMinusIndex].vec.Pt() > 10.0)
645 ) {
646 evtfail |= (1<<EVTFAIL_KINEMATICS );
647 return evtfail;
648 //h_evtfail->Fill( evtfail, eventweight );
649 // h_evtfail->Fill( evtfail );
650 // cout << "evtfail: " << hex << evtfail << dec << endl;
651 // continue;
652 }
653
654 unsigned channel;
655 if( lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[l3LeptonIndex].type == 11 ) channel=0;
656 if( lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[l3LeptonIndex].type == 13 ) channel=1;
657 if( (lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[l3LeptonIndex].type == 13) ||
658 (lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[l3LeptonIndex].type == 11)) channel=2;
659
660
661 double w_offline=-1, werr_offline=0;
662 double w_online=-1, werr_online=0;
663
664 if( ctrl.mc ) {
665
666 vector< pair <double,double> > wlegs; // pair here is eff & err
667 vector< pair <float,float> > mvec; // pair here is eta & pt
668 // now deal with medium vs loose
669 // vector< pair <float,float> > evec; // pair here is eta & pt
670 vector< pair< bool, pair <float,float> > > evec; // pair here is eta & pt
671
672 for( int k=0; k<lepvec.size(); k++ ) {
673 if ( !lepvec[k].is4l ) continue;
674 if( abs(lepvec[k].type) == 13 ) {
675 mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
676 wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
677 lepvec[k].vec.Pt() ) );
678 } else {
679
680 // now deal with medium vs loose
681 // evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
682
683 std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
684 evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].tightCutsApplied, tmppair) );
685
686 wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
687 lepvec[k].vec.Pt(),
688 lepvec[k].isTight ) );
689 }
690 }
691
692 pair<double,double> offpair = getOfflineEfficiencyWeightWZ( wlegs );
693 w_offline = offpair.first;
694 werr_offline = offpair.second;
695
696 pair<double,double> onpair = getOnlineEfficiencyWeightWZ( mvec, evec );
697 w_online = onpair.first;
698 werr_online = onpair.second;
699 } // if mc
700
701
702 if( l != NULL ) {
703 l->vecz1 = Z1Candidate;
704 l->vecl1p = lepvec[Z1LeptonPlusIndex].vec;
705 l->vecl1m = lepvec[Z1LeptonMinusIndex].vec;
706 }
707
708 if( passtuple != NULL ) {
709 float mZ1c=-1; float mZ2c=-1;
710 unsigned run = info->runNum;
711 unsigned evt = info->evtNum;
712 unsigned lumi = info->lumiSec;
713 unsigned chan = channel;
714 double w = eventweight;
715 float mZ1 = Z1Candidate.M() ;
716 unsigned tZ1 = abs(lepvec[Z1LeptonMinusIndex].type);
717 unsigned tl3 = abs(lepvec[l3LeptonIndex].type);
718 float l3pt = lepvec[l3LeptonIndex].vec.Pt();
719 float l3eta = lepvec[l3LeptonIndex].vec.Eta();
720 float l3phi = lepvec[l3LeptonIndex].vec.Phi();
721 float l3isorel = lepvec[l3LeptonIndex].isoPF03/lepvec[l3LeptonIndex].vec.Pt();
722 float met = info->pfMET;
723 float metphi = info->pfMETphi;
724 float mt = calc_mT( l3pt, met, l3phi, metphi );
725 TLorentzVector v3l = Z1Candidate + lepvec[l3LeptonIndex].vec;
726 float m3l = v3l.M();
727 float mt3l = calc_mT( v3l.Pt(), met, v3l.Phi(), metphi );
728 passtuple->SetBranchAddress("channel", &channel);
729 passtuple->SetBranchAddress("run", &run);
730 passtuple->SetBranchAddress("evt", &evt);
731 passtuple->SetBranchAddress("lumi", &lumi);
732 passtuple->SetBranchAddress("mZ1", &mZ1);
733 passtuple->SetBranchAddress("tZ1", &tZ1);
734 passtuple->SetBranchAddress("tl3", &tl3);
735 passtuple->SetBranchAddress("w", &w);
736 passtuple->SetBranchAddress("l3isorel", &l3isorel);
737 passtuple->SetBranchAddress("l3pt", &l3pt);
738 passtuple->SetBranchAddress("l3eta", &l3eta);
739 passtuple->SetBranchAddress("l3phi", &l3phi);
740 passtuple->SetBranchAddress("met", &met);
741 passtuple->SetBranchAddress("metphi", &metphi);
742 passtuple->SetBranchAddress("mt", &mt);
743 passtuple->SetBranchAddress("mt3l", &mt3l);
744 passtuple->SetBranchAddress("m3l", &m3l);
745 passtuple->SetBranchAddress("nothers", &nothers);
746 if( ctrl.mc ) {
747 passtuple->SetBranchAddress("won", &w_online);
748 passtuple->SetBranchAddress("werron", &werr_online);
749 passtuple->SetBranchAddress("woff", &w_offline);
750 passtuple->SetBranchAddress("werroff", &werr_offline);
751 passtuple->SetBranchAddress("npuw", &npuw);
752 }
753 passtuple->Fill( );
754 }
755
756 if( ctrl.debug ) cout << "run: " << info->runNum
757 << "\tevt: " << info->evtNum
758 << "\tZ1channel: " << lepvec[Z1LeptonMinusIndex].type
759 << "\tl3channel: " << lepvec[l3LeptonIndex].type
760 << "\tmZ1: " << Z1Candidate.M()
761 << "\tmet: " << info->pfMET
762 << "\tevtfail: " << hex << evtfail << dec
763 << "\ttrigbits: " << hex << info->triggerBits << dec
764 // << "\ttree: " << inputFiles[q][f]
765 << endl;
766
767 return evtfail;
768
769 }
770
771
772
773
774