ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/Selection.cc
Revision: 1.16
Committed: Mon Nov 7 05:28:06 2011 UTC (13 years, 6 months ago) by khahn
Content type: text/plain
Branch: MAIN
Changes since 1.15: +1 -1 lines
Log Message:
fixed ks muon selection

File Contents

# User Rev Content
1 khahn 1.1 #include "Selection.h"
2     #include "PassHLT.h"
3 khahn 1.7
4     #include "SiMVAElectronSelection.h"
5    
6 khahn 1.1 #include "HZZCiCElectronSelection.h"
7 dkralph 1.3 #include "HZZLikelihoodElectronSelection.h"
8 dkralph 1.4 #include "HZZBDTElectronSelection.h"
9 khahn 1.1 #include "RunLumiRangeMap.h"
10 khahn 1.13 #include "EfficiencyWeightsInterface.h"
11 khahn 1.1
12 dkralph 1.2 RunLumiRangeMap rlrm;
13 khahn 1.15 TH1D * hpu;
14    
15 khahn 1.1
16 khahn 1.13 // #include "TH2D.h"
17     // extern TH2D * h_mu_eff_idiso_2011a;
18     // extern TH2D * h_mu_eff_idiso_s11;
19     // extern TH2D * h_mu_effdata_trigger_doublemu7_2011a;
20     // extern TH2D * h_mu_effdata_trigger_doublemu13_8_leading_2011a;
21     // extern TH2D * h_mu_effdata_trigger_doublemu13_8_trailing_2011a;
22    
23     // unsigned getGenChannel(mithep::TGenInfo * ginfo) {
24     // int gchannel=-1;
25     // if( abs(ginfo->id_1_a) == EGenType::kElectron && abs(ginfo->id_1_b) == EGenType::kElectron ) gchannel=0;
26     // else if( abs(ginfo->id_1_a) == EGenType::kMuon && abs(ginfo->id_1_b) == EGenType::kMuon ) gchannel=1;
27     // else if( (abs(ginfo->id_1_a) == EGenType::kElectron && abs(ginfo->id_1_b) == EGenType::kMuon) ||
28     // (abs(ginfo->id_1_a) == EGenType::kMuon && abs(ginfo->id_1_b) == EGenType::kElectron) ) gchannel=2;
29 khahn 1.12
30 khahn 1.13 // return gchannel;
31     // };
32    
33     void initRunLumiRangeMap() {
34     rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
35     // rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
36     rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
37     rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));
38     rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));
39 khahn 1.15 TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Run2011A.root");
40     hpu = (TH1D*)(puf->Get("puWeights"));
41 khahn 1.12 };
42    
43 khahn 1.13 void initRunLumiRangeMap(RunLumiRangeMap &rlrm) {
44     cout << "adding JSONS ... " << endl;
45 khahn 1.1 rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
46 khahn 1.11 // rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
47     rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
48 khahn 1.1 rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));
49     rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));
50     };
51    
52 khahn 1.13 // unsigned fails_HZZ4L_selection(ControlFlags &ctrl, // input control
53     // mithep::TEventInfo *info, // input event inof
54     // TClonesArray *electronArr, // input electrons
55     // TClonesArray *muonArr, // input muons
56     // double eventweight, // weight
57     // TTree * passtuple ) {
58 khahn 1.1
59 khahn 1.13 // fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, NULL );
60 khahn 1.1
61 khahn 1.13 // };
62 khahn 1.1
63 khahn 1.12
64    
65 khahn 1.13 // unsigned fails_HZZ4L_selection(ControlFlags &ctrl, // input control
66     // mithep::TEventInfo *info, // input event inof
67     // TClonesArray *electronArr, // input electrons
68     // TClonesArray *muonArr, // input muons
69     // double eventweight, // weight
70     // LabVectors *l ) {
71 khahn 1.1
72 khahn 1.13 // fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, NULL, l );
73 khahn 1.1
74 khahn 1.13 // };
75 khahn 1.1
76    
77     unsigned fails_HZZ4L_selection(ControlFlags &ctrl, // input control
78 khahn 1.12 mithep::TGenInfo *ginfo , // input gen info
79     mithep::TEventInfo *info, // input event info
80     TClonesArray *electronArr, // input electrons
81     TClonesArray *muonArr, // input muons
82     double eventweight, // weight
83     TTree * passtuple ) {
84    
85 khahn 1.13 fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, NULL, NULL );
86 khahn 1.12
87     };
88    
89 khahn 1.13 unsigned fails_HZZ4L_selection(ControlFlags &ctrl, // input control
90     mithep::TEventInfo *info, // input event info
91     TClonesArray *electronArr, // input electrons
92     TClonesArray *muonArr, // input muons
93     double eventweight, // weight
94     TTree * passtuple,
95     LabVectors * l ) {
96     fails_HZZ4L_selection( ctrl, info, electronArr, muonArr, eventweight, passtuple, l, NULL );
97     }
98    
99 khahn 1.12
100     unsigned fails_HZZ4L_selection(ControlFlags &ctrl, // input control
101     mithep::TEventInfo *info, // input event info
102 khahn 1.1 TClonesArray *electronArr, // input electrons
103     TClonesArray *muonArr, // input muons
104 dkralph 1.2 double eventweight, // weight
105 khahn 1.5 TTree * passtuple,
106 khahn 1.13 LabVectors * l=NULL,
107     TClonesArray *jetArr=NULL ) { // output ntuple
108 khahn 1.1
109     unsigned evtfail = 0x0;
110 khahn 1.12 unsigned gchannel=0xdeaddead;
111    
112 khahn 1.13 // if( ctrl.mc && ginfo != NULL ) {
113     // gchannel = getGenChannel(ginfo);
114     // }
115 khahn 1.1
116 khahn 1.5
117     if( ctrl.debug ) {
118     cout << "Run: " << info->runNum
119     << "\tEvt: " << info->evtNum
120     << "\tLumi: " << info->lumiSec
121     << endl;
122     }
123    
124 khahn 1.15 unsigned npu; double npuw;
125 khahn 1.1 if( !ctrl.mc ) {
126     // not accounting for overlap atm
127 dkralph 1.2 RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec);
128 khahn 1.1 if( !(rlrm.HasRunLumi(rl)) ) {
129 khahn 1.5 if( ctrl.debug ) cout << "\tfails JSON" << endl;
130 khahn 1.1 evtfail |= (1<<EVTFAIL_JSON);
131     return evtfail;
132     }
133 khahn 1.15 } else {
134     npu = info->nPU;
135     npuw = hpu->GetBinContent(hpu->FindBin(npu));
136 khahn 1.1 }
137    
138    
139 khahn 1.5
140 khahn 1.1
141    
142     //********************************************************
143     // Trigger
144     //********************************************************
145     if( !ctrl.mc ) {
146     // if( !(passHLT(info->triggerBits, info->runNum, channel) ) ) {
147 khahn 1.13 // if( !(passHLT(info->triggerBits, info->runNum, 999) ) ) {
148     // evtfail |= (1<<EVTFAIL_TRIGGER);
149     // return evtfail;
150     // }
151 khahn 1.1 } else {
152     if( !(passHLTMC(info->triggerBits)) ) {
153     evtfail |= (1<<EVTFAIL_TRIGGER);
154     return evtfail;
155     }
156     // cout << "MC trigger bits: " << hex << info->triggerBits << dec << endl;
157     }
158    
159     if( ctrl.debug ) {
160     cout << "presel nlep: " << muonArr->GetEntries() + electronArr->GetEntries()
161     << "\tnmuon: " << muonArr->GetEntries()
162     << "\tnelectron: " << electronArr->GetEntries()
163     << endl;
164     }
165    
166     //********************************************************
167     // Lepton Selection
168     //********************************************************
169     vector<SimpleLepton> lepvec;
170    
171     //
172 dkralph 1.3 if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
173 khahn 1.1 //----------------------------------------------------
174     for(Int_t i=0; i<muonArr->GetEntries(); i++) {
175     const mithep::TMuon *mu = (mithep::TMuon*)((*muonArr)[i]);
176 khahn 1.11 unsigned muonfail;
177     if( ctrl.muSele == "ksWW" )
178 khahn 1.16 muonfail = passKSMuonSelection(mu);
179 khahn 1.11 else
180     muonfail = passMuonSelectionZZ(mu);
181 khahn 1.1 if( ctrl.debug ) {
182     cout << "muon:: pt: " << mu->pt
183     << "\teta: " << mu->eta
184     << "\tmask: 0x" << hex << muonfail << dec
185     << endl;
186     }
187     if ( !muonfail ) {
188     SimpleLepton tmplep;
189 khahn 1.14
190     float pt = mu->pt;
191     if( ctrl.do_escale_up ) pt*=(1.01);
192     if( ctrl.do_escale_down ) pt*=(0.99);
193    
194     tmplep.vec.SetPtEtaPhiM(pt,
195 khahn 1.1 mu->eta,
196     mu->phi,
197     105.658369e-3);
198 khahn 1.14
199 khahn 1.1 tmplep.type = 13;
200     tmplep.index = i;
201     tmplep.charge = mu->q;
202     tmplep.isoTrk = mu->trkIso03;
203     tmplep.isoEcal = mu->emIso03;
204     tmplep.isoHcal = mu->hadIso03;
205 khahn 1.11 tmplep.isoPF03 = mu->pfIso03;
206 khahn 1.8 tmplep.isoPF04 = mu->pfIso04;
207 khahn 1.1 tmplep.ip3dSig = mu->ip3dSig;
208     tmplep.is4l = false;
209     tmplep.isEB = (fabs(mu->eta) < 1.479 ? 1 : 0 );
210     lepvec.push_back(tmplep);
211     if( ctrl.debug ) { cout << "muon passes ... " << endl;}
212     }
213     }
214    
215     if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
216 dkralph 1.3
217 khahn 1.1 //----------------------------------------------------
218     for(Int_t i=0; i<electronArr->GetEntries(); i++) {
219     const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]);
220    
221 khahn 1.13 if( !(isEleFO(ctrl,ele) ) ) continue;
222     if( ele->pt < 7 ) continue; //move this to ID
223    
224 khahn 1.1 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].type == 13 && lepvec[k].vec.Vect().DrEtaPhi(tmplep) < 0.1 ) {
229 dkralph 1.3 if( ctrl.debug ) cout << "-----> isMuonOverlap! " << endl;
230 khahn 1.1 isMuonOverlap = kTRUE;
231     break;
232     }
233     }
234    
235 khahn 1.11 unsigned FAIL=0, isEleTight=0;
236    
237 dkralph 1.4 unsigned failsCIC=0;
238 khahn 1.11 CICStruct ciccuts_tight, ciccuts_medium, ciccuts_loose;
239 dkralph 1.4 if(ctrl.eleSele=="cic") {
240 khahn 1.11 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 khahn 1.12 failsCIC = ( failsCICLoose > 0 && failsCICMedium > 0 );
246 khahn 1.11 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 dkralph 1.4 FAIL = failsCIC;
254     }
255 khahn 1.11
256 dkralph 1.4 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 khahn 1.11 unsigned failsBDT=0;
264 dkralph 1.4 if(ctrl.eleSele=="bdt") {
265 khahn 1.11 if( ctrl.eleSeleScheme == "mediumloose" ) {
266     unsigned failsBDTMedium = failsBDTSelection(ctrl,"medium",ele);
267     unsigned failsBDTLoose = failsBDTSelection(ctrl,"loose",ele);
268 khahn 1.12 failsBDT = ( failsBDTLoose > 0 && failsBDTMedium > 0 );
269 khahn 1.11 if( !failsBDTMedium ) isEleTight=1;
270     } else {
271     failsBDT = failsBDTSelection(ctrl,"tight",ele);
272     if( !failsBDT ) isEleTight=1;
273     }
274 dkralph 1.4 FAIL = failsBDT;
275     }
276 khahn 1.7
277 dkralph 1.3
278 khahn 1.1 if( ctrl.debug ){
279     cout << "CIC category: " << cicCategory(ele)
280 dkralph 1.3 << "\tlikelihood: " << ele->likelihood
281     << "\tFAIL: 0x" << hex << FAIL << dec
282     << "\tfailsCIC: 0x" << hex << failsCIC << dec
283     << "\tfailsLike: 0x" << hex << failsLike << dec
284 dkralph 1.4 << "\tfailsBDT: 0x" << hex << failsBDT << dec
285 khahn 1.1 << "\tscEt: " << ele->scEt
286 dkralph 1.3 << "\tscEta: " << ele->scEta
287     << "\tncluster: " << ele->ncluster
288 khahn 1.1 << endl;
289     }
290 dkralph 1.3 if ( !FAIL && !isMuonOverlap ) {
291 khahn 1.1 SimpleLepton tmplep;
292 khahn 1.14
293     float pt = ele->pt;
294     if( ctrl.do_escale_up ) pt*=(1.02);
295     if( ctrl.do_escale_down ) pt*=(0.98);
296    
297     tmplep.vec.SetPtEtaPhiM( pt,
298 khahn 1.1 ele->eta,
299     ele->phi,
300     0.51099892e-3 );
301     tmplep.type = 11;
302     tmplep.index = i;
303     tmplep.charge = ele->q;
304     tmplep.isoTrk = ele->trkIso03;
305     tmplep.isoEcal = ele->emIso03;
306     tmplep.isoHcal = ele->hadIso03;
307 khahn 1.11 tmplep.isoPF03 = ele->pfIso03;
308 khahn 1.8 tmplep.isoPF04 = ele->pfIso04;
309 khahn 1.1 tmplep.ip3dSig = ele->ip3dSig;
310     tmplep.is4l = false;
311 khahn 1.11 tmplep.isTight = isEleTight;
312 khahn 1.1 tmplep.isEB = ele->isEB;
313     lepvec.push_back(tmplep);
314     if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
315     }
316     }
317    
318     sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
319    
320 khahn 1.13 for( int i=0; i<lepvec.size(); i++ ) {
321     //
322     // check for a matched btagged jet
323     //
324     lepvec[i].tche = -1;
325     lepvec[i].tchp = -1;
326     lepvec[i].csv = -1;
327     lepvec[i].csvMva = -1;
328    
329     if( jetArr != NULL ) {
330     for(int k=0; k<jetArr->GetEntries(); k++) {
331     const mithep::TJet *jet = (mithep::TJet*)((*jetArr)[k]);
332     TVector3 jvec;
333     jvec.SetPtEtaPhi(jet->pt, jet->eta, jet->phi);
334     if( jvec.DrEtaPhi( lepvec[i].vec.Vect()) < 0.2 ) {
335     lepvec[i].tche = jet->tche;
336     lepvec[i].tchp = jet->tchp;
337     lepvec[i].csv = jet->csv;
338     lepvec[i].csvMva = jet->csvMva;
339     }
340     }
341     }
342     }
343    
344 khahn 1.1 int nmu=0, nele=0;
345     for( int i=0; i<lepvec.size(); i++ ) {
346     if( abs(lepvec[i].type) == 11 ) nele++;
347     else nmu++;
348     }
349     if( ctrl.debug ) {
350     cout << "postsel nlep: " << lepvec.size()
351     << "\tnmuon: " << nmu
352     << "\tnelectron: " << nele
353     << endl;
354     }
355    
356     //******************************************************************************
357     //Z1 Selection
358     //******************************************************************************
359     int Z1LeptonPlusIndex = -1;
360     int Z1LeptonMinusIndex = -1;
361     double BestZ1Mass = -999;
362     if( ctrl.debug ) { cout << "looking for a Z1 ..." << endl; }
363     for(int i = 0; i < lepvec.size(); ++i) {
364     for(int j = i+1; j < lepvec.size(); ++j) {
365     if( ctrl.debug ) { cout << "\tconsidering leptons " << i << " & " << j << endl; }
366     if (!(lepvec[i].vec.Pt() > 20.0 || lepvec[j].vec.Pt() > 20.0)) continue;
367     if( ctrl.debug ) { cout << "\tat least one is > 20 GeV" << endl; }
368     if (!(lepvec[i].vec.Pt() > 10.0 && lepvec[j].vec.Pt() > 10.0)) continue;
369     if( ctrl.debug ) { cout << "\tthe other is > 10 GeV" << endl; }
370     if (lepvec[i].charge == lepvec[j].charge) continue;
371     if( ctrl.debug ) { cout << "\tthey're opposite charge" << endl; }
372     if (fabs(lepvec[i].type) != fabs(lepvec[j].type)) continue;
373     if( ctrl.debug ) { cout << "\tthey're same flavor" << endl; }
374    
375     //Make Z1 hypothesis
376     TLorentzVector leptonPlus, leptonMinus;
377     if ( lepvec[i].charge > 0 ) {
378     leptonPlus = lepvec[i].vec;
379     leptonMinus = lepvec[j].vec;
380     } else {
381     leptonPlus = lepvec[j].vec;
382     leptonMinus = lepvec[i].vec;
383     }
384    
385     float tmpZ1Mass = (leptonPlus+leptonMinus).M();
386 dkralph 1.3 if( ctrl.debug ) cout << "Z1 selection, tmpZ1Mass: " << tmpZ1Mass << endl;
387 khahn 1.1 if( tmpZ1Mass > 60 ) {
388     if (fabs(tmpZ1Mass - 91.1876) < fabs(BestZ1Mass - 91.1876)) {
389     BestZ1Mass = tmpZ1Mass;
390 dkralph 1.3 if( ctrl.debug ) cout << "Z1 selection, new BestZ1Mass: " << BestZ1Mass
391 khahn 1.1 << "\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     }
403     }
404     // stop if no Z1 candidate is found
405     if( BestZ1Mass < 0 ) {
406     evtfail |= (1<<EVTFAIL_Z1);
407     return evtfail;
408     }
409 dkralph 1.3 if( ctrl.debug ) cout << "\tgot a Z1 ... run: " << info->runNum << "\tevt: " << info->evtNum << endl;
410     if( ctrl.debug ) cout << "\tZ1 plusindex: " << Z1LeptonPlusIndex << "\tminusindex: " << Z1LeptonMinusIndex << endl;
411 khahn 1.1 TLorentzVector Z1LeptonPlus = lepvec[Z1LeptonPlusIndex].vec;
412     TLorentzVector Z1LeptonMinus = lepvec[Z1LeptonMinusIndex].vec;
413     TLorentzVector Z1Candidate = Z1LeptonPlus + Z1LeptonMinus;
414     if( l != NULL ) {
415     l->vecz1 = Z1Candidate;
416     l->vecl1p = Z1LeptonPlus;
417     l->vecl1m = Z1LeptonMinus;
418     }
419    
420     //******************************************************************************
421     // Z1 + l
422     //******************************************************************************
423     if( lepvec.size() < 3 ) {
424     evtfail |= (1<<EVTFAIL_Z1_PLUSL);
425     return evtfail;
426     }
427    
428     //******************************************************************************
429     // 4l/Z2 Selection
430     //******************************************************************************
431     Int_t Z2LeptonPlusIndex = -1;
432     Int_t Z2LeptonMinusIndex = -1;
433     Double_t BestZ2Mass = -1;
434 dkralph 1.3 if( ctrl.debug ) cout << "looking for a Z2 ... out of " << lepvec.size() << " leptons" <<endl;
435 khahn 1.1 for(int i = 0; i < lepvec.size(); ++i) {
436 khahn 1.11 if( abs(lepvec[i].type) == 11 &&
437     ctrl.eleSeleScheme == "mediumloose" &&
438     !(lepvec[i].isTight) ) continue;
439    
440 khahn 1.1 for(int j = i+1; j < lepvec.size(); ++j) {
441 khahn 1.11 if( abs(lepvec[j].type) == 11 &&
442     ctrl.eleSeleScheme == "mediumloose" &&
443     !(lepvec[j].isTight) ) continue;
444    
445 khahn 1.1 // cout << "i: " << i << "\tj: " << j << endl;
446     if (i == Z1LeptonPlusIndex || i == Z1LeptonMinusIndex) {
447     // cout << "\ti matches a Z1 index, skipping ..." << endl;
448     continue; //skip Z1 leptons
449     }
450     if (j == Z1LeptonPlusIndex || j == Z1LeptonMinusIndex) {
451     // cout << "\tj matches a Z1 index, skipping ..." << endl;
452     continue; //skip Z1 leptons
453     }
454     if (lepvec[i].charge == lepvec[j].charge) {
455     // cout << "\ti and j are same sign, skipping ..." << endl;
456     continue; //require opp sign
457     }
458     if (fabs(lepvec[i].type) != fabs(lepvec[j].type)) {
459     // cout << "\ti and j are not same flavor, skipping ..." << endl;
460     continue; //require same flavor
461     }
462    
463    
464     //Make Z2 hypothesis
465     TLorentzVector leptonPlus, leptonMinus;
466    
467     if (lepvec[i].charge > 0 ) {
468     leptonPlus = lepvec[i].vec;
469     leptonMinus = lepvec[j].vec;
470     } else {
471     leptonPlus = lepvec[j].vec;
472     leptonMinus = lepvec[i].vec;
473     }
474    
475     TLorentzVector dilepton = leptonPlus+leptonMinus;
476     TLorentzVector fourLepton = Z1Candidate + dilepton;
477    
478 dkralph 1.3 if( ctrl.debug ) cout << "dilepton.M() : " << dilepton.M() << endl;
479     if( ctrl.debug ) cout << "fourLepton.M() : " << fourLepton.M() << endl;
480 khahn 1.1
481     if (!(dilepton.M() > 12.0)) continue;
482     if (!(fourLepton.M() > 100.0)) continue;
483    
484 khahn 1.11 /*
485 khahn 1.1 //for 4e and 4mu, require at least 1 of the other opp sign lepton pairs have mass > 12
486     if (fabs(lepvec[i].type) == fabs(lepvec[Z1LeptonPlusIndex].type)) {
487     TLorentzVector pair1 = Z1LeptonPlus+leptonMinus;
488     TLorentzVector pair2 = Z1LeptonMinus+leptonPlus;
489 dkralph 1.3 if( ctrl.debug ) cout << "pair1: " << pair1.M() << "\tpair2: "<< pair2.M() << endl;
490 khahn 1.1 if (!(pair1.M() > 12 || pair2.M() > 12)) continue;
491     }
492 khahn 1.11 */
493    
494 khahn 1.1 //Disambiguiation is done by choosing the pair with the largest ptMax and largest ptMin
495     if (Z2LeptonPlusIndex < 0) {
496     if (lepvec[i].charge > 0) {
497     Z2LeptonPlusIndex = i;
498     Z2LeptonMinusIndex = j;
499     } else {
500     Z2LeptonPlusIndex = j;
501     Z2LeptonMinusIndex = i;
502     }
503     } else {
504     Double_t BestPairPtMax = lepvec[Z2LeptonPlusIndex].vec.Pt();
505     Double_t BestPairPtMin = lepvec[Z2LeptonMinusIndex].vec.Pt();
506     if (lepvec[Z2LeptonMinusIndex].vec.Pt() > BestPairPtMax) {
507     BestPairPtMax = lepvec[Z2LeptonMinusIndex].vec.Pt();
508     BestPairPtMin = lepvec[Z2LeptonPlusIndex].vec.Pt();
509     }
510    
511     Double_t CurrentPairPtMax = lepvec[i].vec.Pt();
512     Double_t CurrentPairPtMin = lepvec[j].vec.Pt();
513     if (lepvec[j].vec.Pt() > CurrentPairPtMax) {
514     CurrentPairPtMax = lepvec[j].vec.Pt();
515     CurrentPairPtMin = lepvec[i].vec.Pt();
516     }
517    
518     if (CurrentPairPtMax > BestPairPtMax) {
519     if (lepvec[i].charge > 0) {
520     Z2LeptonPlusIndex = i;
521     Z2LeptonMinusIndex = j;
522     } else {
523     Z2LeptonPlusIndex = j;
524     Z2LeptonMinusIndex = i;
525     }
526     } else if (CurrentPairPtMax == BestPairPtMax) {
527     if (CurrentPairPtMin > BestPairPtMin) {
528     if (lepvec[i].charge > 0) {
529     Z2LeptonPlusIndex = i;
530     Z2LeptonMinusIndex = j;
531     } else {
532     Z2LeptonPlusIndex = j;
533     Z2LeptonMinusIndex = i;
534     }
535     }
536     }
537     }
538     }
539     }
540    
541     // stop if no Z2 candidate is found
542     if (Z2LeptonPlusIndex == -1) {
543     evtfail |= ( 1<<EVTFAIL_4L );
544     return evtfail;
545     // h_evtfail->Fill( evtfail );
546     // cout << "evtfail: " << hex << evtfail << dec << endl;
547     // continue;
548     }
549 dkralph 1.3 if( ctrl.debug ) cout << "\tgot a Z2 ..." << endl;
550     if( ctrl.debug ) cout << "\tZ2 plusindex: " << Z2LeptonPlusIndex
551     << "\tminusindex: " << Z2LeptonMinusIndex << endl;
552 khahn 1.1 TLorentzVector Z2LeptonPlus = lepvec[Z2LeptonPlusIndex].vec;
553     TLorentzVector Z2LeptonMinus = lepvec[Z2LeptonMinusIndex].vec;
554     TLorentzVector Z2Candidate = Z2LeptonPlus+Z2LeptonMinus;
555     TLorentzVector ZZSystem = Z1Candidate + Z2Candidate;
556     if( l != NULL ) {
557     l->vecz2 = Z2Candidate;
558     l->vecl2p = Z2LeptonPlus;
559     l->vecl2m = Z2LeptonMinus;
560     l->vec4l = ZZSystem;
561     }
562     lepvec[Z1LeptonPlusIndex].is4l = true;
563     lepvec[Z1LeptonMinusIndex].is4l = true;
564     lepvec[Z2LeptonPlusIndex].is4l = true;
565     lepvec[Z2LeptonMinusIndex].is4l = true;
566    
567     //***************************************************************
568     // Isolation
569     //***************************************************************
570     bool failiso=false;
571    
572 khahn 1.10 if( ctrl.isoScheme == "pf" ) {
573 khahn 1.1
574 khahn 1.8 for( int i=0; i<lepvec.size(); i++ ) {
575 khahn 1.11
576 khahn 1.8 if( !(lepvec[i].is4l) ) continue;
577 khahn 1.11
578 khahn 1.8 if( abs(lepvec[i].type) == 11 ) {
579 khahn 1.11 float reliso = lepvec[i].isoPF04/lepvec[i].vec.Pt();
580     if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_ELE_LOOSE_EB_HIGHPT ) {
581     failiso = true;
582     break;
583     }
584     if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_ELE_LOOSE_EB_LOWPT ) {
585     failiso = true;
586     break;
587     }
588     if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_ELE_LOOSE_EE_HIGHPT ) {
589     failiso = true;
590     break;
591     }
592     if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_ELE_LOOSE_EE_LOWPT ) {
593 khahn 1.8 failiso = true;
594     break;
595     }
596     }
597 khahn 1.11
598 khahn 1.8 if( abs(lepvec[i].type) == 13 ) {
599 khahn 1.11
600 khahn 1.14 /*
601 khahn 1.11 float reliso = lepvec[i].isoPF03/lepvec[i].vec.Pt();
602 khahn 1.12 if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EB_HIGHPT ) { //0.13
603 khahn 1.8 failiso = true;
604     break;
605     }
606 khahn 1.12 if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EB_LOWPT ) { //0.06
607 khahn 1.8 failiso = true;
608     break;
609     }
610 khahn 1.12 if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EE_HIGHPT ) { //0.09
611 khahn 1.8 failiso = true;
612     break;
613     }
614 khahn 1.12 if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EE_LOWPT ) { //0.05
615 khahn 1.8 failiso = true;
616     break;
617     }
618 khahn 1.14 */
619 khahn 1.8 }
620 khahn 1.9 }
621 khahn 1.10 } else if ( ctrl.isoScheme == "pairwise" ) {
622 khahn 1.8 float rho = info->rho;
623     for( int i=0; i<lepvec.size(); i++ ) {
624     if( !(lepvec[i].is4l) ) continue;
625 khahn 1.1 float effArea_ecal_i, effArea_hcal_i;
626     if( lepvec[i].isEB ) {
627     if( lepvec[i].type == 11 ) {
628     effArea_ecal_i = 0.101;
629     effArea_hcal_i = 0.021;
630     } else {
631     effArea_ecal_i = 0.074;
632     effArea_hcal_i = 0.022;
633     }
634     } else {
635     if( lepvec[i].type == 11 ) {
636     effArea_ecal_i = 0.046;
637     effArea_hcal_i = 0.040;
638     } else {
639     effArea_ecal_i = 0.045;
640     effArea_hcal_i = 0.030;
641     }
642     }
643     float isoEcal_corr_i = lepvec[i].isoEcal - (effArea_ecal_i*rho);
644     float isoHcal_corr_i = lepvec[i].isoHcal - (effArea_hcal_i*rho);
645     for( int j=i+1; j<lepvec.size(); j++ ) {
646     if( !(lepvec[j].is4l) ) continue;
647     float effArea_ecal_j, effArea_hcal_j;
648     if( lepvec[j].isEB ) {
649     if( lepvec[j].type == 11 ) {
650     effArea_ecal_j = 0.101;
651     effArea_hcal_j = 0.021;
652     } else {
653     effArea_ecal_j = 0.074;
654     effArea_hcal_j = 0.022;
655     }
656     } else {
657     if( lepvec[j].type == 11 ) {
658     effArea_ecal_j = 0.046;
659     effArea_hcal_j = 0.040;
660     } else {
661     effArea_ecal_j = 0.045;
662     effArea_hcal_j = 0.030;
663     }
664     }
665     float isoEcal_corr_j = lepvec[j].isoEcal - (effArea_ecal_j*rho);
666     float isoHcal_corr_j = lepvec[j].isoHcal - (effArea_hcal_j*rho);
667     float RIso_i = (lepvec[i].isoTrk+isoEcal_corr_i+isoHcal_corr_i)/lepvec[i].vec.Pt();
668     float RIso_j = (lepvec[j].isoTrk+isoEcal_corr_j+isoHcal_corr_j)/lepvec[j].vec.Pt();
669     float comboIso = RIso_i + RIso_j;
670     if( info->evtNum == 1038911933 ) {
671     float tmpdR = lepvec[i].vec.DrEtaPhi(lepvec[j].vec);
672     cout << "i: " << i
673     << "\tdR: " << tmpdR
674     << "\trho: " << rho
675     << "\tRIso_i: " << RIso_i
676     << "\ttkrel: " << lepvec[i].isoTrk/lepvec[i].vec.Pt()
677     << "\tecalrel: " << lepvec[i].isoEcal/lepvec[i].vec.Pt()
678     << "\tecalrelcor: " << isoEcal_corr_i/lepvec[i].vec.Pt()
679     << "\thcalrel: " << lepvec[i].isoHcal/lepvec[i].vec.Pt()
680     << "\thcalrelcor: " << isoHcal_corr_i/lepvec[i].vec.Pt()
681     << "\tpt_i: " << lepvec[i].vec.Pt()
682     << "\tj: " << j
683     << "\tRIso_j: " << RIso_j
684     << "\ttkrel: " << lepvec[j].isoTrk/lepvec[j].vec.Pt()
685     << "\tecalrel: " << lepvec[j].isoEcal/lepvec[j].vec.Pt()
686     << "\tecalrelcor: " << isoEcal_corr_j/lepvec[j].vec.Pt()
687     << "\thcalrel: " << lepvec[j].isoHcal/lepvec[j].vec.Pt()
688     << "\thcalrelcor: " << isoHcal_corr_j/lepvec[j].vec.Pt()
689     << "\tpt_j: " << lepvec[j].vec.Pt()
690     << "\tcombo: " << comboIso
691     << endl;
692     cout.flush();
693     }
694     if( comboIso > 0.35 ) {
695 dkralph 1.3 if( ctrl.debug ) cout << "combo failing for indices: " << i << "," << j << endl;
696 khahn 1.1 failiso = true;
697     // break;
698     }
699     }
700 khahn 1.9 }
701 khahn 1.1 }
702 khahn 1.8
703    
704 khahn 1.1 if( failiso ) {
705     evtfail |= ( 1<<EVTFAIL_ISOLATION );
706     return evtfail;
707     //h_evtfail->Fill( evtfail, eventweight );
708     // h_evtfail->Fill( evtfail );
709     // cout << "evtfail: " << hex << evtfail << dec << endl;
710     // continue;
711     }
712    
713     //***************************************************************
714     // IP significance
715     //***************************************************************
716     bool failip = false;
717     for( int i=0; i<lepvec.size(); i++ ) {
718     if( !(lepvec[i].is4l) ) continue;
719     if( lepvec[i].ip3dSig > 4 ) {
720     failip=true;
721     break;
722     }
723     }
724     if( failip ) {
725     evtfail |= (1<<EVTFAIL_IP );
726     return evtfail;
727     //h_evtfail->Fill( evtfail, eventweight );
728     // h_evtfail->Fill( evtfail );
729     // cout << "evtfail: " << hex << evtfail << dec << endl;
730     // continue;
731     }
732    
733     //***************************************************************
734     // remaining kinematic cuts
735     //***************************************************************
736 dkralph 1.3 double Z2massCut=0;
737     if ( ctrl.kinematics == "loose" ) Z2massCut = 12;
738     else if ( ctrl.kinematics == "tight" ) Z2massCut = 20;
739     else { cout << "error! kinematic tightness not defined!" << endl; assert(0); }
740    
741     if ( Z1Candidate.M() > 120 ||
742     Z2Candidate.M() < Z2massCut ||
743     Z2Candidate.M() > 120 ||
744 khahn 1.1 !(lepvec[Z1LeptonPlusIndex].vec.Pt() > 20.0 || lepvec[Z1LeptonMinusIndex].vec.Pt() > 20.0) ||
745     !(lepvec[Z1LeptonPlusIndex].vec.Pt() > 10.0 && lepvec[Z1LeptonMinusIndex].vec.Pt() > 10.0)
746     ) {
747     evtfail |= (1<<EVTFAIL_KINEMATICS );
748     return evtfail;
749     //h_evtfail->Fill( evtfail, eventweight );
750     // h_evtfail->Fill( evtfail );
751     // cout << "evtfail: " << hex << evtfail << dec << endl;
752     // continue;
753     }
754    
755 khahn 1.12 unsigned channel;
756 khahn 1.1 if( lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 11 ) channel=0;
757     if( lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 13 ) channel=1;
758     if( (lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 13) ||
759     (lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 11)) channel=2;
760    
761    
762 khahn 1.13 double w_offline=-1, werr_offline=0;
763     double w_online=-1, werr_online=0;
764 khahn 1.5
765 khahn 1.13 if( ctrl.mc ) {
766    
767     vector< pair <double,double> > wlegs; // pair here is eff & err
768     vector< pair <float,float> > mvec; // pair here is eta & pt
769 khahn 1.14 // now deal with medium vs loose
770     // vector< pair <float,float> > evec; // pair here is eta & pt
771     vector< pair< bool, pair <float,float> > > evec; // pair here is eta & pt
772 khahn 1.13
773     for( int k=0; k<lepvec.size(); k++ ) {
774     if( !(lepvec[k].is4l) ) continue;
775     if( abs(lepvec[k].type) == 13 ) {
776     mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
777     wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
778     lepvec[k].vec.Pt() ) );
779     } else {
780 khahn 1.14
781     // now deal with medium vs loose
782     // evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
783    
784     std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
785     evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
786    
787 khahn 1.13 wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
788     lepvec[k].vec.Pt() ) );
789     }
790     }
791    
792     pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
793     w_offline = offpair.first;
794     werr_offline = offpair.second;
795    
796     pair<double,double> onpair = getOnlineEfficiencyWeight( mvec, evec );
797     w_online = onpair.first;
798     werr_online = onpair.second;
799 khahn 1.14
800 khahn 1.13 } // if mc
801    
802    
803     if( l != NULL ) {
804     l->vec4l = ZZSystem;
805     l->vecz1 = Z1Candidate;
806     l->vecz2 = Z2Candidate;
807     l->vecl1p = lepvec[Z1LeptonPlusIndex].vec;
808     l->vecl1m = lepvec[Z1LeptonMinusIndex].vec;
809     l->vecl2p = lepvec[Z2LeptonPlusIndex].vec;
810     l->vecl2m = lepvec[Z2LeptonMinusIndex].vec;
811     }
812 khahn 1.1 if( passtuple != NULL ) {
813 khahn 1.5 unsigned run = info->runNum;
814     unsigned evt = info->evtNum;
815     unsigned lumi = info->lumiSec;
816     unsigned chan = channel;
817 khahn 1.7 double w = eventweight;
818 khahn 1.5 float mZ1 = Z1Candidate.M() ;
819     float mZ2 = Z2Candidate.M() ;
820     float m4l = ZZSystem.M() ;
821     float pt4l = ZZSystem.Pt() ;
822 khahn 1.11 unsigned tZ1 = abs(lepvec[Z1LeptonMinusIndex].type);
823     unsigned tZ2 = abs(lepvec[Z2LeptonMinusIndex].type);
824 khahn 1.13 float l3tche = lepvec[Z2LeptonMinusIndex].tche;
825     float l4tche = lepvec[Z2LeptonPlusIndex].tche;
826     float l3tchp = lepvec[Z2LeptonMinusIndex].tchp;
827     float l4tchp = lepvec[Z2LeptonPlusIndex].tchp;
828     float l3csv = lepvec[Z2LeptonMinusIndex].csv;
829     float l4csv = lepvec[Z2LeptonPlusIndex].csv;
830     float l3csvMva = lepvec[Z2LeptonMinusIndex].csvMva;
831     float l4csvMva = lepvec[Z2LeptonPlusIndex].csvMva;
832    
833    
834 khahn 1.12 passtuple->SetBranchAddress("channel", &channel);
835 khahn 1.5 passtuple->SetBranchAddress("run", &run);
836     passtuple->SetBranchAddress("evt", &evt);
837     passtuple->SetBranchAddress("lumi", &lumi);
838     passtuple->SetBranchAddress("mZ1", &mZ1);
839     passtuple->SetBranchAddress("mZ2", &mZ2);
840 khahn 1.11 passtuple->SetBranchAddress("tZ1", &tZ1);
841     passtuple->SetBranchAddress("tZ2", &tZ2);
842 khahn 1.5 passtuple->SetBranchAddress("m4l", &m4l);
843     passtuple->SetBranchAddress("pt4l", &pt4l);
844 khahn 1.7 passtuple->SetBranchAddress("w", &w);
845 khahn 1.13 if( ctrl.mc ) {
846     passtuple->SetBranchAddress("woff", &w_offline );
847     passtuple->SetBranchAddress("werroff", &werr_offline );
848     passtuple->SetBranchAddress("won", &w_online );
849     passtuple->SetBranchAddress("werron", &werr_online );
850 khahn 1.15 passtuple->SetBranchAddress("npu", &npu );
851     passtuple->SetBranchAddress("npuw", &npuw );
852     passtuple->SetBranchAddress("gchannel", &gchannel);
853 khahn 1.13 }
854     if( ctrl.btag ) {
855     passtuple->SetBranchAddress("l3tche", &l3tche);
856     passtuple->SetBranchAddress("l4tche", &l4tche);
857     passtuple->SetBranchAddress("l3tchp", &l3tchp);
858     passtuple->SetBranchAddress("l4tchp", &l4tchp);
859     passtuple->SetBranchAddress("l3csv", &l3csv);
860     passtuple->SetBranchAddress("l4csv", &l4csv);
861     passtuple->SetBranchAddress("l3csvMva", &l3csvMva);
862     passtuple->SetBranchAddress("l4csvMva", &l4csvMva);
863     }
864    
865 khahn 1.5 passtuple->Fill( );
866 khahn 1.1 }
867    
868 dkralph 1.3 if( ctrl.debug ) cout << "run: " << info->runNum
869 khahn 1.1 << "\tevt: " << info->evtNum
870     << "\tZ1channel: " << lepvec[Z1LeptonMinusIndex].type
871     << "\tZ2channel: " << lepvec[Z2LeptonMinusIndex].type
872     << "\tmZ1: " << Z1Candidate.M()
873     << "\tmZ2: " << Z2Candidate.M()
874     << "\tm4l: " << ZZSystem.M()
875     << "\tevtfail: " << hex << evtfail << dec
876     << "\ttrigbits: " << hex << info->triggerBits << dec
877     // << "\ttree: " << inputFiles[q][f]
878     << endl;
879    
880     return evtfail;
881    
882     }
883    
884    
885    
886    
887