ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/Selection.cc
Revision: 1.13
Committed: Sun Oct 30 15:12:30 2011 UTC (13 years, 6 months ago) by khahn
Content type: text/plain
Branch: MAIN
Changes since 1.12: +157 -42 lines
Log Message:
*** empty log message ***

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     tmplep.vec.SetPtEtaPhiM(mu->pt,
182     mu->eta,
183     mu->phi,
184     105.658369e-3);
185     tmplep.type = 13;
186     tmplep.index = i;
187     tmplep.charge = mu->q;
188     tmplep.isoTrk = mu->trkIso03;
189     tmplep.isoEcal = mu->emIso03;
190     tmplep.isoHcal = mu->hadIso03;
191 khahn 1.11 tmplep.isoPF03 = mu->pfIso03;
192 khahn 1.8 tmplep.isoPF04 = mu->pfIso04;
193 khahn 1.1 tmplep.ip3dSig = mu->ip3dSig;
194     tmplep.is4l = false;
195     tmplep.isEB = (fabs(mu->eta) < 1.479 ? 1 : 0 );
196     lepvec.push_back(tmplep);
197     if( ctrl.debug ) { cout << "muon passes ... " << endl;}
198     }
199     }
200    
201     if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
202 dkralph 1.3
203 khahn 1.1 //----------------------------------------------------
204     for(Int_t i=0; i<electronArr->GetEntries(); i++) {
205     const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]);
206    
207 khahn 1.13 if( !(isEleFO(ctrl,ele) ) ) continue;
208     if( ele->pt < 7 ) continue; //move this to ID
209    
210 khahn 1.1 Bool_t isMuonOverlap = kFALSE;
211     for (int k=0; k<lepvec.size(); ++k) {
212     TVector3 tmplep;
213     tmplep.SetPtEtaPhi(ele->pt, ele->eta, ele->phi);
214     if ( lepvec[k].type == 13 && lepvec[k].vec.Vect().DrEtaPhi(tmplep) < 0.1 ) {
215 dkralph 1.3 if( ctrl.debug ) cout << "-----> isMuonOverlap! " << endl;
216 khahn 1.1 isMuonOverlap = kTRUE;
217     break;
218     }
219     }
220    
221 khahn 1.11 unsigned FAIL=0, isEleTight=0;
222    
223 dkralph 1.4 unsigned failsCIC=0;
224 khahn 1.11 CICStruct ciccuts_tight, ciccuts_medium, ciccuts_loose;
225 dkralph 1.4 if(ctrl.eleSele=="cic") {
226 khahn 1.11 if( ctrl.eleSeleScheme == "mediumloose" ) {
227     ciccuts_medium = getCiCCuts("medium");
228     unsigned failsCICMedium = failsCicSelection(ctrl, ele, ciccuts_medium, ctrl.kinematics);
229     ciccuts_loose = getCiCCuts("loose");
230     unsigned failsCICLoose = failsCicSelection(ctrl, ele, ciccuts_loose, ctrl.kinematics);
231 khahn 1.12 failsCIC = ( failsCICLoose > 0 && failsCICMedium > 0 );
232 khahn 1.11 if( !failsCICMedium ) isEleTight=1;
233     }
234     else {
235     ciccuts_tight = getCiCCuts(ctrl.eleSeleScheme);
236     failsCIC = failsCicSelection(ctrl, ele, ciccuts_tight, ctrl.kinematics);
237     if( !failsCIC ) isEleTight=1;
238     }
239 dkralph 1.4 FAIL = failsCIC;
240     }
241 khahn 1.11
242 dkralph 1.4 LikStruct likcuts;
243     unsigned failsLike=0;
244     if(ctrl.eleSele=="lik") {
245     likcuts = getLikCuts(ctrl.eleSeleScheme);
246     failsLike = failsLikelihoodSelection(ele, likcuts, ctrl.kinematics);
247     FAIL = failsLike;
248     }
249 khahn 1.11 unsigned failsBDT=0;
250 dkralph 1.4 if(ctrl.eleSele=="bdt") {
251 khahn 1.11 if( ctrl.eleSeleScheme == "mediumloose" ) {
252     unsigned failsBDTMedium = failsBDTSelection(ctrl,"medium",ele);
253     unsigned failsBDTLoose = failsBDTSelection(ctrl,"loose",ele);
254 khahn 1.12 failsBDT = ( failsBDTLoose > 0 && failsBDTMedium > 0 );
255 khahn 1.11 if( !failsBDTMedium ) isEleTight=1;
256     } else {
257     failsBDT = failsBDTSelection(ctrl,"tight",ele);
258     if( !failsBDT ) isEleTight=1;
259     }
260 dkralph 1.4 FAIL = failsBDT;
261     }
262 khahn 1.7
263 dkralph 1.3
264 khahn 1.1 if( ctrl.debug ){
265     cout << "CIC category: " << cicCategory(ele)
266 dkralph 1.3 << "\tlikelihood: " << ele->likelihood
267     << "\tFAIL: 0x" << hex << FAIL << dec
268     << "\tfailsCIC: 0x" << hex << failsCIC << dec
269     << "\tfailsLike: 0x" << hex << failsLike << dec
270 dkralph 1.4 << "\tfailsBDT: 0x" << hex << failsBDT << dec
271 khahn 1.1 << "\tscEt: " << ele->scEt
272 dkralph 1.3 << "\tscEta: " << ele->scEta
273     << "\tncluster: " << ele->ncluster
274 khahn 1.1 << endl;
275     }
276 dkralph 1.3 if ( !FAIL && !isMuonOverlap ) {
277 khahn 1.1 SimpleLepton tmplep;
278     tmplep.vec.SetPtEtaPhiM( ele->pt,
279     ele->eta,
280     ele->phi,
281     0.51099892e-3 );
282     tmplep.type = 11;
283     tmplep.index = i;
284     tmplep.charge = ele->q;
285     tmplep.isoTrk = ele->trkIso03;
286     tmplep.isoEcal = ele->emIso03;
287     tmplep.isoHcal = ele->hadIso03;
288 khahn 1.11 tmplep.isoPF03 = ele->pfIso03;
289 khahn 1.8 tmplep.isoPF04 = ele->pfIso04;
290 khahn 1.1 tmplep.ip3dSig = ele->ip3dSig;
291     tmplep.is4l = false;
292 khahn 1.11 tmplep.isTight = isEleTight;
293 khahn 1.1 tmplep.isEB = ele->isEB;
294     lepvec.push_back(tmplep);
295     if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
296     }
297     }
298    
299     sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
300    
301 khahn 1.13 for( int i=0; i<lepvec.size(); i++ ) {
302     //
303     // check for a matched btagged jet
304     //
305     lepvec[i].tche = -1;
306     lepvec[i].tchp = -1;
307     lepvec[i].csv = -1;
308     lepvec[i].csvMva = -1;
309    
310     if( jetArr != NULL ) {
311     for(int k=0; k<jetArr->GetEntries(); k++) {
312     const mithep::TJet *jet = (mithep::TJet*)((*jetArr)[k]);
313     TVector3 jvec;
314     jvec.SetPtEtaPhi(jet->pt, jet->eta, jet->phi);
315     if( jvec.DrEtaPhi( lepvec[i].vec.Vect()) < 0.2 ) {
316     lepvec[i].tche = jet->tche;
317     lepvec[i].tchp = jet->tchp;
318     lepvec[i].csv = jet->csv;
319     lepvec[i].csvMva = jet->csvMva;
320     }
321     }
322     }
323     }
324    
325 khahn 1.1 int nmu=0, nele=0;
326     for( int i=0; i<lepvec.size(); i++ ) {
327     if( abs(lepvec[i].type) == 11 ) nele++;
328     else nmu++;
329     }
330     if( ctrl.debug ) {
331     cout << "postsel nlep: " << lepvec.size()
332     << "\tnmuon: " << nmu
333     << "\tnelectron: " << nele
334     << endl;
335     }
336    
337     //******************************************************************************
338     //Z1 Selection
339     //******************************************************************************
340     int Z1LeptonPlusIndex = -1;
341     int Z1LeptonMinusIndex = -1;
342     double BestZ1Mass = -999;
343     if( ctrl.debug ) { cout << "looking for a Z1 ..." << endl; }
344     for(int i = 0; i < lepvec.size(); ++i) {
345     for(int j = i+1; j < lepvec.size(); ++j) {
346     if( ctrl.debug ) { cout << "\tconsidering leptons " << i << " & " << j << endl; }
347     if (!(lepvec[i].vec.Pt() > 20.0 || lepvec[j].vec.Pt() > 20.0)) continue;
348     if( ctrl.debug ) { cout << "\tat least one is > 20 GeV" << endl; }
349     if (!(lepvec[i].vec.Pt() > 10.0 && lepvec[j].vec.Pt() > 10.0)) continue;
350     if( ctrl.debug ) { cout << "\tthe other is > 10 GeV" << endl; }
351     if (lepvec[i].charge == lepvec[j].charge) continue;
352     if( ctrl.debug ) { cout << "\tthey're opposite charge" << endl; }
353     if (fabs(lepvec[i].type) != fabs(lepvec[j].type)) continue;
354     if( ctrl.debug ) { cout << "\tthey're same flavor" << endl; }
355    
356     //Make Z1 hypothesis
357     TLorentzVector leptonPlus, leptonMinus;
358     if ( lepvec[i].charge > 0 ) {
359     leptonPlus = lepvec[i].vec;
360     leptonMinus = lepvec[j].vec;
361     } else {
362     leptonPlus = lepvec[j].vec;
363     leptonMinus = lepvec[i].vec;
364     }
365    
366     float tmpZ1Mass = (leptonPlus+leptonMinus).M();
367 dkralph 1.3 if( ctrl.debug ) cout << "Z1 selection, tmpZ1Mass: " << tmpZ1Mass << endl;
368 khahn 1.1 if( tmpZ1Mass > 60 ) {
369     if (fabs(tmpZ1Mass - 91.1876) < fabs(BestZ1Mass - 91.1876)) {
370     BestZ1Mass = tmpZ1Mass;
371 dkralph 1.3 if( ctrl.debug ) cout << "Z1 selection, new BestZ1Mass: " << BestZ1Mass
372 khahn 1.1 << "\tdM: " << fabs(BestZ1Mass - 91.1876)
373     << endl;
374     if (lepvec[i].charge > 0) {
375     Z1LeptonPlusIndex = i;
376     Z1LeptonMinusIndex = j;
377     } else {
378     Z1LeptonPlusIndex = j;
379     Z1LeptonMinusIndex = i;
380     }
381     }
382     }
383     }
384     }
385     // stop if no Z1 candidate is found
386     if( BestZ1Mass < 0 ) {
387     evtfail |= (1<<EVTFAIL_Z1);
388     return evtfail;
389     }
390 dkralph 1.3 if( ctrl.debug ) cout << "\tgot a Z1 ... run: " << info->runNum << "\tevt: " << info->evtNum << endl;
391     if( ctrl.debug ) cout << "\tZ1 plusindex: " << Z1LeptonPlusIndex << "\tminusindex: " << Z1LeptonMinusIndex << endl;
392 khahn 1.1 TLorentzVector Z1LeptonPlus = lepvec[Z1LeptonPlusIndex].vec;
393     TLorentzVector Z1LeptonMinus = lepvec[Z1LeptonMinusIndex].vec;
394     TLorentzVector Z1Candidate = Z1LeptonPlus + Z1LeptonMinus;
395     if( l != NULL ) {
396     l->vecz1 = Z1Candidate;
397     l->vecl1p = Z1LeptonPlus;
398     l->vecl1m = Z1LeptonMinus;
399     }
400    
401     //******************************************************************************
402     // Z1 + l
403     //******************************************************************************
404     if( lepvec.size() < 3 ) {
405     evtfail |= (1<<EVTFAIL_Z1_PLUSL);
406     return evtfail;
407     }
408    
409     //******************************************************************************
410     // 4l/Z2 Selection
411     //******************************************************************************
412     Int_t Z2LeptonPlusIndex = -1;
413     Int_t Z2LeptonMinusIndex = -1;
414     Double_t BestZ2Mass = -1;
415 dkralph 1.3 if( ctrl.debug ) cout << "looking for a Z2 ... out of " << lepvec.size() << " leptons" <<endl;
416 khahn 1.1 for(int i = 0; i < lepvec.size(); ++i) {
417 khahn 1.11 if( abs(lepvec[i].type) == 11 &&
418     ctrl.eleSeleScheme == "mediumloose" &&
419     !(lepvec[i].isTight) ) continue;
420    
421 khahn 1.1 for(int j = i+1; j < lepvec.size(); ++j) {
422 khahn 1.11 if( abs(lepvec[j].type) == 11 &&
423     ctrl.eleSeleScheme == "mediumloose" &&
424     !(lepvec[j].isTight) ) continue;
425    
426 khahn 1.1 // cout << "i: " << i << "\tj: " << j << endl;
427     if (i == Z1LeptonPlusIndex || i == Z1LeptonMinusIndex) {
428     // cout << "\ti matches a Z1 index, skipping ..." << endl;
429     continue; //skip Z1 leptons
430     }
431     if (j == Z1LeptonPlusIndex || j == Z1LeptonMinusIndex) {
432     // cout << "\tj matches a Z1 index, skipping ..." << endl;
433     continue; //skip Z1 leptons
434     }
435     if (lepvec[i].charge == lepvec[j].charge) {
436     // cout << "\ti and j are same sign, skipping ..." << endl;
437     continue; //require opp sign
438     }
439     if (fabs(lepvec[i].type) != fabs(lepvec[j].type)) {
440     // cout << "\ti and j are not same flavor, skipping ..." << endl;
441     continue; //require same flavor
442     }
443    
444    
445     //Make Z2 hypothesis
446     TLorentzVector leptonPlus, leptonMinus;
447    
448     if (lepvec[i].charge > 0 ) {
449     leptonPlus = lepvec[i].vec;
450     leptonMinus = lepvec[j].vec;
451     } else {
452     leptonPlus = lepvec[j].vec;
453     leptonMinus = lepvec[i].vec;
454     }
455    
456     TLorentzVector dilepton = leptonPlus+leptonMinus;
457     TLorentzVector fourLepton = Z1Candidate + dilepton;
458    
459 dkralph 1.3 if( ctrl.debug ) cout << "dilepton.M() : " << dilepton.M() << endl;
460     if( ctrl.debug ) cout << "fourLepton.M() : " << fourLepton.M() << endl;
461 khahn 1.1
462     if (!(dilepton.M() > 12.0)) continue;
463     if (!(fourLepton.M() > 100.0)) continue;
464    
465 khahn 1.11 /*
466 khahn 1.1 //for 4e and 4mu, require at least 1 of the other opp sign lepton pairs have mass > 12
467     if (fabs(lepvec[i].type) == fabs(lepvec[Z1LeptonPlusIndex].type)) {
468     TLorentzVector pair1 = Z1LeptonPlus+leptonMinus;
469     TLorentzVector pair2 = Z1LeptonMinus+leptonPlus;
470 dkralph 1.3 if( ctrl.debug ) cout << "pair1: " << pair1.M() << "\tpair2: "<< pair2.M() << endl;
471 khahn 1.1 if (!(pair1.M() > 12 || pair2.M() > 12)) continue;
472     }
473 khahn 1.11 */
474    
475 khahn 1.1 //Disambiguiation is done by choosing the pair with the largest ptMax and largest ptMin
476     if (Z2LeptonPlusIndex < 0) {
477     if (lepvec[i].charge > 0) {
478     Z2LeptonPlusIndex = i;
479     Z2LeptonMinusIndex = j;
480     } else {
481     Z2LeptonPlusIndex = j;
482     Z2LeptonMinusIndex = i;
483     }
484     } else {
485     Double_t BestPairPtMax = lepvec[Z2LeptonPlusIndex].vec.Pt();
486     Double_t BestPairPtMin = lepvec[Z2LeptonMinusIndex].vec.Pt();
487     if (lepvec[Z2LeptonMinusIndex].vec.Pt() > BestPairPtMax) {
488     BestPairPtMax = lepvec[Z2LeptonMinusIndex].vec.Pt();
489     BestPairPtMin = lepvec[Z2LeptonPlusIndex].vec.Pt();
490     }
491    
492     Double_t CurrentPairPtMax = lepvec[i].vec.Pt();
493     Double_t CurrentPairPtMin = lepvec[j].vec.Pt();
494     if (lepvec[j].vec.Pt() > CurrentPairPtMax) {
495     CurrentPairPtMax = lepvec[j].vec.Pt();
496     CurrentPairPtMin = lepvec[i].vec.Pt();
497     }
498    
499     if (CurrentPairPtMax > BestPairPtMax) {
500     if (lepvec[i].charge > 0) {
501     Z2LeptonPlusIndex = i;
502     Z2LeptonMinusIndex = j;
503     } else {
504     Z2LeptonPlusIndex = j;
505     Z2LeptonMinusIndex = i;
506     }
507     } else if (CurrentPairPtMax == BestPairPtMax) {
508     if (CurrentPairPtMin > BestPairPtMin) {
509     if (lepvec[i].charge > 0) {
510     Z2LeptonPlusIndex = i;
511     Z2LeptonMinusIndex = j;
512     } else {
513     Z2LeptonPlusIndex = j;
514     Z2LeptonMinusIndex = i;
515     }
516     }
517     }
518     }
519     }
520     }
521    
522     // stop if no Z2 candidate is found
523     if (Z2LeptonPlusIndex == -1) {
524     evtfail |= ( 1<<EVTFAIL_4L );
525     return evtfail;
526     // h_evtfail->Fill( evtfail );
527     // cout << "evtfail: " << hex << evtfail << dec << endl;
528     // continue;
529     }
530 dkralph 1.3 if( ctrl.debug ) cout << "\tgot a Z2 ..." << endl;
531     if( ctrl.debug ) cout << "\tZ2 plusindex: " << Z2LeptonPlusIndex
532     << "\tminusindex: " << Z2LeptonMinusIndex << endl;
533 khahn 1.1 TLorentzVector Z2LeptonPlus = lepvec[Z2LeptonPlusIndex].vec;
534     TLorentzVector Z2LeptonMinus = lepvec[Z2LeptonMinusIndex].vec;
535     TLorentzVector Z2Candidate = Z2LeptonPlus+Z2LeptonMinus;
536     TLorentzVector ZZSystem = Z1Candidate + Z2Candidate;
537     if( l != NULL ) {
538     l->vecz2 = Z2Candidate;
539     l->vecl2p = Z2LeptonPlus;
540     l->vecl2m = Z2LeptonMinus;
541     l->vec4l = ZZSystem;
542     }
543     lepvec[Z1LeptonPlusIndex].is4l = true;
544     lepvec[Z1LeptonMinusIndex].is4l = true;
545     lepvec[Z2LeptonPlusIndex].is4l = true;
546     lepvec[Z2LeptonMinusIndex].is4l = true;
547    
548     //***************************************************************
549     // Isolation
550     //***************************************************************
551     bool failiso=false;
552    
553 khahn 1.10 if( ctrl.isoScheme == "pf" ) {
554 khahn 1.1
555 khahn 1.8 for( int i=0; i<lepvec.size(); i++ ) {
556 khahn 1.11
557 khahn 1.8 if( !(lepvec[i].is4l) ) continue;
558 khahn 1.11
559 khahn 1.8 if( abs(lepvec[i].type) == 11 ) {
560 khahn 1.11 float reliso = lepvec[i].isoPF04/lepvec[i].vec.Pt();
561     if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_ELE_LOOSE_EB_HIGHPT ) {
562     failiso = true;
563     break;
564     }
565     if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_ELE_LOOSE_EB_LOWPT ) {
566     failiso = true;
567     break;
568     }
569     if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_ELE_LOOSE_EE_HIGHPT ) {
570     failiso = true;
571     break;
572     }
573     if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_ELE_LOOSE_EE_LOWPT ) {
574 khahn 1.8 failiso = true;
575     break;
576     }
577     }
578 khahn 1.11
579 khahn 1.8 if( abs(lepvec[i].type) == 13 ) {
580 khahn 1.11
581     float reliso = lepvec[i].isoPF03/lepvec[i].vec.Pt();
582 khahn 1.12 if( lepvec[i].isEB && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EB_HIGHPT ) { //0.13
583 khahn 1.8 failiso = true;
584     break;
585     }
586 khahn 1.12 if( lepvec[i].isEB && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EB_LOWPT ) { //0.06
587 khahn 1.8 failiso = true;
588     break;
589     }
590 khahn 1.12 if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() > 20 && reliso > PFISO_MU_LOOSE_EE_HIGHPT ) { //0.09
591 khahn 1.8 failiso = true;
592     break;
593     }
594 khahn 1.12 if( !(lepvec[i].isEB) && lepvec[i].vec.Pt() < 20 && reliso > PFISO_MU_LOOSE_EE_LOWPT ) { //0.05
595 khahn 1.8 failiso = true;
596     break;
597     }
598     }
599 khahn 1.9 }
600 khahn 1.10 } else if ( ctrl.isoScheme == "pairwise" ) {
601 khahn 1.8 float rho = info->rho;
602     for( int i=0; i<lepvec.size(); i++ ) {
603     if( !(lepvec[i].is4l) ) continue;
604 khahn 1.1 float effArea_ecal_i, effArea_hcal_i;
605     if( lepvec[i].isEB ) {
606     if( lepvec[i].type == 11 ) {
607     effArea_ecal_i = 0.101;
608     effArea_hcal_i = 0.021;
609     } else {
610     effArea_ecal_i = 0.074;
611     effArea_hcal_i = 0.022;
612     }
613     } else {
614     if( lepvec[i].type == 11 ) {
615     effArea_ecal_i = 0.046;
616     effArea_hcal_i = 0.040;
617     } else {
618     effArea_ecal_i = 0.045;
619     effArea_hcal_i = 0.030;
620     }
621     }
622     float isoEcal_corr_i = lepvec[i].isoEcal - (effArea_ecal_i*rho);
623     float isoHcal_corr_i = lepvec[i].isoHcal - (effArea_hcal_i*rho);
624     for( int j=i+1; j<lepvec.size(); j++ ) {
625     if( !(lepvec[j].is4l) ) continue;
626     float effArea_ecal_j, effArea_hcal_j;
627     if( lepvec[j].isEB ) {
628     if( lepvec[j].type == 11 ) {
629     effArea_ecal_j = 0.101;
630     effArea_hcal_j = 0.021;
631     } else {
632     effArea_ecal_j = 0.074;
633     effArea_hcal_j = 0.022;
634     }
635     } else {
636     if( lepvec[j].type == 11 ) {
637     effArea_ecal_j = 0.046;
638     effArea_hcal_j = 0.040;
639     } else {
640     effArea_ecal_j = 0.045;
641     effArea_hcal_j = 0.030;
642     }
643     }
644     float isoEcal_corr_j = lepvec[j].isoEcal - (effArea_ecal_j*rho);
645     float isoHcal_corr_j = lepvec[j].isoHcal - (effArea_hcal_j*rho);
646     float RIso_i = (lepvec[i].isoTrk+isoEcal_corr_i+isoHcal_corr_i)/lepvec[i].vec.Pt();
647     float RIso_j = (lepvec[j].isoTrk+isoEcal_corr_j+isoHcal_corr_j)/lepvec[j].vec.Pt();
648     float comboIso = RIso_i + RIso_j;
649     if( info->evtNum == 1038911933 ) {
650     float tmpdR = lepvec[i].vec.DrEtaPhi(lepvec[j].vec);
651     cout << "i: " << i
652     << "\tdR: " << tmpdR
653     << "\trho: " << rho
654     << "\tRIso_i: " << RIso_i
655     << "\ttkrel: " << lepvec[i].isoTrk/lepvec[i].vec.Pt()
656     << "\tecalrel: " << lepvec[i].isoEcal/lepvec[i].vec.Pt()
657     << "\tecalrelcor: " << isoEcal_corr_i/lepvec[i].vec.Pt()
658     << "\thcalrel: " << lepvec[i].isoHcal/lepvec[i].vec.Pt()
659     << "\thcalrelcor: " << isoHcal_corr_i/lepvec[i].vec.Pt()
660     << "\tpt_i: " << lepvec[i].vec.Pt()
661     << "\tj: " << j
662     << "\tRIso_j: " << RIso_j
663     << "\ttkrel: " << lepvec[j].isoTrk/lepvec[j].vec.Pt()
664     << "\tecalrel: " << lepvec[j].isoEcal/lepvec[j].vec.Pt()
665     << "\tecalrelcor: " << isoEcal_corr_j/lepvec[j].vec.Pt()
666     << "\thcalrel: " << lepvec[j].isoHcal/lepvec[j].vec.Pt()
667     << "\thcalrelcor: " << isoHcal_corr_j/lepvec[j].vec.Pt()
668     << "\tpt_j: " << lepvec[j].vec.Pt()
669     << "\tcombo: " << comboIso
670     << endl;
671     cout.flush();
672     }
673     if( comboIso > 0.35 ) {
674 dkralph 1.3 if( ctrl.debug ) cout << "combo failing for indices: " << i << "," << j << endl;
675 khahn 1.1 failiso = true;
676     // break;
677     }
678     }
679 khahn 1.9 }
680 khahn 1.1 }
681 khahn 1.8
682    
683 khahn 1.1 if( failiso ) {
684     evtfail |= ( 1<<EVTFAIL_ISOLATION );
685     return evtfail;
686     //h_evtfail->Fill( evtfail, eventweight );
687     // h_evtfail->Fill( evtfail );
688     // cout << "evtfail: " << hex << evtfail << dec << endl;
689     // continue;
690     }
691    
692     //***************************************************************
693     // IP significance
694     //***************************************************************
695     bool failip = false;
696     for( int i=0; i<lepvec.size(); i++ ) {
697     if( !(lepvec[i].is4l) ) continue;
698     if( lepvec[i].ip3dSig > 4 ) {
699     failip=true;
700     break;
701     }
702     }
703     if( failip ) {
704     evtfail |= (1<<EVTFAIL_IP );
705     return evtfail;
706     //h_evtfail->Fill( evtfail, eventweight );
707     // h_evtfail->Fill( evtfail );
708     // cout << "evtfail: " << hex << evtfail << dec << endl;
709     // continue;
710     }
711    
712     //***************************************************************
713     // remaining kinematic cuts
714     //***************************************************************
715 dkralph 1.3 double Z2massCut=0;
716     if ( ctrl.kinematics == "loose" ) Z2massCut = 12;
717     else if ( ctrl.kinematics == "tight" ) Z2massCut = 20;
718     else { cout << "error! kinematic tightness not defined!" << endl; assert(0); }
719    
720     if ( Z1Candidate.M() > 120 ||
721     Z2Candidate.M() < Z2massCut ||
722     Z2Candidate.M() > 120 ||
723 khahn 1.1 !(lepvec[Z1LeptonPlusIndex].vec.Pt() > 20.0 || lepvec[Z1LeptonMinusIndex].vec.Pt() > 20.0) ||
724     !(lepvec[Z1LeptonPlusIndex].vec.Pt() > 10.0 && lepvec[Z1LeptonMinusIndex].vec.Pt() > 10.0)
725     ) {
726     evtfail |= (1<<EVTFAIL_KINEMATICS );
727     return evtfail;
728     //h_evtfail->Fill( evtfail, eventweight );
729     // h_evtfail->Fill( evtfail );
730     // cout << "evtfail: " << hex << evtfail << dec << endl;
731     // continue;
732     }
733    
734 khahn 1.12 unsigned channel;
735 khahn 1.1 if( lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 11 ) channel=0;
736     if( lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 13 ) channel=1;
737     if( (lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 13) ||
738     (lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 11)) channel=2;
739    
740    
741 khahn 1.13 double w_offline=-1, werr_offline=0;
742     double w_online=-1, werr_online=0;
743 khahn 1.5
744 khahn 1.13 if( ctrl.mc ) {
745    
746     vector< pair <double,double> > wlegs; // pair here is eff & err
747     vector< pair <float,float> > mvec; // pair here is eta & pt
748     vector< pair <float,float> > evec; // pair here is eta & pt
749    
750     for( int k=0; k<lepvec.size(); k++ ) {
751     if( !(lepvec[k].is4l) ) continue;
752     if( abs(lepvec[k].type) == 13 ) {
753     mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
754     wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
755     lepvec[k].vec.Pt() ) );
756     } else {
757     evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
758     wlegs.push_back( elePerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
759     lepvec[k].vec.Pt() ) );
760     // wlegs.push_back( pair<double,double> (1.,0.) );
761     }
762     }
763    
764     pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
765     w_offline = offpair.first;
766     werr_offline = offpair.second;
767    
768     pair<double,double> onpair = getOnlineEfficiencyWeight( mvec, evec );
769     w_online = onpair.first;
770     werr_online = onpair.second;
771     } // if mc
772    
773    
774     if( l != NULL ) {
775     l->vec4l = ZZSystem;
776     l->vecz1 = Z1Candidate;
777     l->vecz2 = Z2Candidate;
778     l->vecl1p = lepvec[Z1LeptonPlusIndex].vec;
779     l->vecl1m = lepvec[Z1LeptonMinusIndex].vec;
780     l->vecl2p = lepvec[Z2LeptonPlusIndex].vec;
781     l->vecl2m = lepvec[Z2LeptonMinusIndex].vec;
782     }
783 khahn 1.1 if( passtuple != NULL ) {
784 khahn 1.5 unsigned run = info->runNum;
785     unsigned evt = info->evtNum;
786     unsigned lumi = info->lumiSec;
787     unsigned chan = channel;
788 khahn 1.7 double w = eventweight;
789 khahn 1.5 float mZ1 = Z1Candidate.M() ;
790     float mZ2 = Z2Candidate.M() ;
791     float m4l = ZZSystem.M() ;
792     float pt4l = ZZSystem.Pt() ;
793 khahn 1.11 unsigned tZ1 = abs(lepvec[Z1LeptonMinusIndex].type);
794     unsigned tZ2 = abs(lepvec[Z2LeptonMinusIndex].type);
795 khahn 1.13 float l3tche = lepvec[Z2LeptonMinusIndex].tche;
796     float l4tche = lepvec[Z2LeptonPlusIndex].tche;
797     float l3tchp = lepvec[Z2LeptonMinusIndex].tchp;
798     float l4tchp = lepvec[Z2LeptonPlusIndex].tchp;
799     float l3csv = lepvec[Z2LeptonMinusIndex].csv;
800     float l4csv = lepvec[Z2LeptonPlusIndex].csv;
801     float l3csvMva = lepvec[Z2LeptonMinusIndex].csvMva;
802     float l4csvMva = lepvec[Z2LeptonPlusIndex].csvMva;
803    
804    
805 khahn 1.12 passtuple->SetBranchAddress("channel", &channel);
806 khahn 1.5 passtuple->SetBranchAddress("run", &run);
807     passtuple->SetBranchAddress("evt", &evt);
808     passtuple->SetBranchAddress("lumi", &lumi);
809     passtuple->SetBranchAddress("mZ1", &mZ1);
810     passtuple->SetBranchAddress("mZ2", &mZ2);
811 khahn 1.11 passtuple->SetBranchAddress("tZ1", &tZ1);
812     passtuple->SetBranchAddress("tZ2", &tZ2);
813 khahn 1.5 passtuple->SetBranchAddress("m4l", &m4l);
814     passtuple->SetBranchAddress("pt4l", &pt4l);
815 khahn 1.7 passtuple->SetBranchAddress("w", &w);
816 khahn 1.13 if( ctrl.mc ) {
817     passtuple->SetBranchAddress("woff", &w_offline );
818     passtuple->SetBranchAddress("werroff", &werr_offline );
819     passtuple->SetBranchAddress("won", &w_online );
820     passtuple->SetBranchAddress("werron", &werr_online );
821     }
822     if( ctrl.btag ) {
823     passtuple->SetBranchAddress("l3tche", &l3tche);
824     passtuple->SetBranchAddress("l4tche", &l4tche);
825     passtuple->SetBranchAddress("l3tchp", &l3tchp);
826     passtuple->SetBranchAddress("l4tchp", &l4tchp);
827     passtuple->SetBranchAddress("l3csv", &l3csv);
828     passtuple->SetBranchAddress("l4csv", &l4csv);
829     passtuple->SetBranchAddress("l3csvMva", &l3csvMva);
830     passtuple->SetBranchAddress("l4csvMva", &l4csvMva);
831     }
832    
833 khahn 1.12 if( ctrl.mc ) passtuple->SetBranchAddress("gchannel", &gchannel);
834 khahn 1.5 passtuple->Fill( );
835 khahn 1.13
836 khahn 1.1 }
837    
838 dkralph 1.3 if( ctrl.debug ) cout << "run: " << info->runNum
839 khahn 1.1 << "\tevt: " << info->evtNum
840     << "\tZ1channel: " << lepvec[Z1LeptonMinusIndex].type
841     << "\tZ2channel: " << lepvec[Z2LeptonMinusIndex].type
842     << "\tmZ1: " << Z1Candidate.M()
843     << "\tmZ2: " << Z2Candidate.M()
844     << "\tm4l: " << ZZSystem.M()
845     << "\tevtfail: " << hex << evtfail << dec
846     << "\ttrigbits: " << hex << info->triggerBits << dec
847     // << "\ttree: " << inputFiles[q][f]
848     << endl;
849    
850     return evtfail;
851    
852     }
853    
854    
855    
856    
857