ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/Selection.cc
Revision: 1.14
Committed: Tue Nov 1 19:15:53 2011 UTC (13 years, 6 months ago) by khahn
Content type: text/plain
Branch: MAIN
Changes since 1.13: +26 -5 lines
Log Message:
deal with medium/loose ele scale factors and energy scale

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