ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/Selection.cc
Revision: 1.12
Committed: Sun Oct 23 10:53:01 2011 UTC (13 years, 6 months ago) by khahn
Content type: text/plain
Branch: MAIN
Changes since 1.11: +44 -10 lines
Log Message:
fail fixstatus

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