ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/Selection.cc
Revision: 1.23
Committed: Tue May 1 16:39:10 2012 UTC (13 years ago) by khahn
Content type: text/plain
Branch: MAIN
Changes since 1.22: +5 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 khahn 1.19 #include "SelectionStatus.h"
2     #include "EventData.h"
3     #include "SimpleLepton.h"
4     #include "EfficiencyWeightsInterface.h"
5 khahn 1.7
6 khahn 1.20 #include "ElectronSelection.h"
7     #include "MuonSelection.h"
8 khahn 1.19 #include "IsolationSelection.h"
9 khahn 1.20 //#include "PassHLT.h"
10 khahn 1.19 #include "Selection.h"
11 khahn 1.15
12 khahn 1.19 #include "ExternData.h"
13     #include "SelectionDefs.h"
14 khahn 1.1
15 khahn 1.22 //--------------------------------------------------------------------------------------------------
16     void fillVetoArrays( ControlFlags & ctrl,
17     const mithep::Array<mithep::Muon> *muonArr,
18     vector< const mithep::Muon*> & muonsToVeto,
19     const mithep::Array<mithep::Electron> *electronArr,
20     vector< const mithep::Electron*> & electronsToVeto,
21     const mithep::Vertex & vtx )
22     //--------------------------------------------------------------------------------------------------
23     {
24     if( ctrl.debug ) cout << "looping for isolation ..." << endl;
25     for(int i=0; i<muonArr->GetEntries(); i++)
26     {
27     const mithep::Muon *mu = (const mithep::Muon*)((*muonArr)[i]);
28     SelectionStatus musel;
29     // musel |= muonCutBasedVeto(ctrl,mu,vtx);
30     musel |= muonDummyVeto(ctrl,mu,vtx);
31     if( !(musel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
32     if(ctrl.debug) cout << "pushing mu for isol veto ... " << endl;
33     muonsToVeto.push_back( mu );
34     }
35     for(int i=0; i<electronArr->GetEntries(); i++)
36     {
37     const mithep::Electron *ele = (const mithep::Electron*)((*electronArr)[i]);
38     SelectionStatus esel;
39     // esel |= electronCutBasedVeto(ctrl,ele,vtx);
40     esel |= electronDummyVeto(ctrl,ele,vtx);
41     if( !(esel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
42     if(ctrl.debug) cout << "pushing ele for isol veto ... " << endl;
43     electronsToVeto.push_back( ele );
44     }
45     if( ctrl.debug ) cout << "done selecting for isolation veto ..." << endl << endl;;
46     }
47    
48 khahn 1.13
49 khahn 1.22 //--------------------------------------------------------------------------------------------------
50 khahn 1.19 EventData apply_HZZ4L_selection(ControlFlags &ctrl, // input control
51 khahn 1.20 const mithep::EventHeader *info, // input event info
52     const mithep::Vertex & vtx,
53     const mithep::Array<mithep::PFCandidate> *pfCandidates,
54     const mithep::Array<mithep::PileupEnergyDensity> *puEnergyDensity,
55     const mithep::Array<mithep::Electron> *electronArr, // input electrons
56     SelectionStatus (*ElectronPreSelector)( ControlFlags &,
57     const mithep::Electron*,
58     const mithep::Vertex &),
59     SelectionStatus (*ElectronIDSelector)( ControlFlags &,
60     const mithep::Electron*,
61     const mithep::Vertex &),
62     SelectionStatus (*ElectronIsoSelector)( ControlFlags &,
63     const mithep::Electron*,
64     const mithep::Vertex &,
65     const mithep::Array<mithep::PFCandidate> *,
66     const mithep::Array<mithep::PileupEnergyDensity> *,
67     mithep::ElectronTools::EElectronEffectiveAreaTarget,
68     vector<const mithep::Muon*>,
69     vector<const mithep::Electron*> ),
70     const mithep::Array<mithep::Muon> *muonArr, // input muons
71     SelectionStatus (*MuonPreSelector)( ControlFlags &,
72     const mithep::Muon*,
73     const mithep::Vertex &,
74     const mithep::Array<mithep::PFCandidate> *),
75     SelectionStatus (*MuonIDSelector)( ControlFlags &,
76     const mithep::Muon*,
77 khahn 1.23 // const mithep::Vertex &),
78     const mithep::Vertex &,
79     const mithep::Array<mithep::PFCandidate> *),
80 khahn 1.20 SelectionStatus (*MuonIsoSelector)( ControlFlags &,
81     const mithep::Muon*,
82     const mithep::Vertex &,
83     const mithep::Array<mithep::PFCandidate> *,
84     const mithep::Array<mithep::PileupEnergyDensity> *,
85     mithep::MuonTools::EMuonEffectiveAreaTarget,
86     vector<const mithep::Muon*>,
87     vector<const mithep::Electron*> )
88     )
89 khahn 1.22 //--------------------------------------------------------------------------------------------------
90 khahn 1.19 {
91 khahn 1.12
92 khahn 1.19 EventData ret;
93 khahn 1.1 unsigned evtfail = 0x0;
94 khahn 1.19 TRandom3 r;
95    
96 khahn 1.5 if( ctrl.debug ) {
97 khahn 1.21 cout << "-----------------------------------------------------------------" << endl;
98     cout << "-----------------------------------------------------------------" << endl;
99 khahn 1.20 cout << "Run: " << info->RunNum()
100     << "\tEvt: " << info->EvtNum()
101     << "\tLumi: " << info->LumiSec()
102 khahn 1.5 << endl;
103 khahn 1.21 cout << "-----------------------------------------------------------------" << endl;
104 khahn 1.5 }
105    
106 khahn 1.1 if( !ctrl.mc ) {
107     // not accounting for overlap atm
108 khahn 1.20 RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());
109 khahn 1.1 if( !(rlrm.HasRunLumi(rl)) ) {
110 khahn 1.5 if( ctrl.debug ) cout << "\tfails JSON" << endl;
111 khahn 1.19 ret.status.setStatus(0);
112     return ret;
113 khahn 1.1 }
114     }
115 khahn 1.20
116 khahn 1.21 mithep::MuonTools::EMuonEffectiveAreaTarget eraMu = mithep::MuonTools::kMuEAFall11MC;
117     mithep::ElectronTools::EElectronEffectiveAreaTarget eraEle = mithep::ElectronTools::kEleEAFall11MC;
118     if( !ctrl.mc ) {
119     eraMu = mithep::MuonTools::kMuEAData2011;
120     eraEle = mithep::ElectronTools::kEleEAData2011;
121 khahn 1.20 }
122 khahn 1.1
123    
124     //********************************************************
125     // Trigger
126     //********************************************************
127 khahn 1.20 //
128     // still have to port this part to bambu
129     //
130     /*
131 khahn 1.1 if( !ctrl.mc ) {
132 khahn 1.19 //if( !(passHLT(info->triggerBits, info->runNum, channel) ) ) {
133     if( !(passHLT(info->triggerBits, info->runNum, 999) ) ) {
134     if( ctrl.debug ) cout << "\tfails trigger" << endl;
135 khahn 1.1 evtfail |= (1<<EVTFAIL_TRIGGER);
136 khahn 1.19 ret.status.setStatus(0);
137     return ret;
138     }
139     }
140 khahn 1.21 */
141    
142 khahn 1.1 if( ctrl.debug ) {
143     cout << "presel nlep: " << muonArr->GetEntries() + electronArr->GetEntries()
144     << "\tnmuon: " << muonArr->GetEntries()
145     << "\tnelectron: " << electronArr->GetEntries()
146     << endl;
147     }
148 khahn 1.21
149 khahn 1.1
150     //********************************************************
151     // Lepton Selection
152     //********************************************************
153     vector<SimpleLepton> lepvec;
154 khahn 1.20
155     vector<const mithep::Muon*> muonsToVeto;
156     vector<const mithep::Electron*> electronsToVeto;
157 khahn 1.22 fillVetoArrays( ctrl, muonArr, muonsToVeto, electronArr, electronsToVeto, vtx );
158 khahn 1.20
159 khahn 1.1 //
160 dkralph 1.3 if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
161 khahn 1.1 //----------------------------------------------------
162 khahn 1.19 for(Int_t i=0; i<muonArr->GetEntries(); i++)
163     {
164 khahn 1.20 const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[i]);
165 khahn 1.19
166     SelectionStatus musel;
167     if(ctrl.debug) cout << "musel.status before anything: " << musel.getStatus() << endl;
168 khahn 1.20 musel |= (*MuonPreSelector)(ctrl,mu,vtx,pfCandidates);
169 khahn 1.19 if(ctrl.debug) cout << "musel.status after presel: " << musel.getStatus() << endl;
170 khahn 1.20 if( !(musel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
171 khahn 1.23 // musel |= (*MuonIDSelector)(ctrl,mu,vtx );
172     musel |= (*MuonIDSelector)(ctrl,mu,vtx,pfCandidates );
173 khahn 1.19 if(ctrl.debug) cout << "musel.status after ID: " << musel.getStatus() << endl;
174 khahn 1.20 musel |= (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,muonsToVeto,electronsToVeto);
175 khahn 1.19 if(ctrl.debug) cout << "musel.status after iso: " << musel.getStatus() << endl;
176    
177     if( ctrl.debug ) {
178 khahn 1.20 cout << "muon:: pt: " << mu->Pt()
179     << "\teta: " << mu->Eta()
180 khahn 1.19 << "\tstatus: " << hex << musel.getStatus() << dec
181     << endl;
182     }
183    
184     if ( musel.pass() ) {
185 khahn 1.22
186 khahn 1.19 SimpleLepton tmplep;
187 khahn 1.20 float pt = mu->Pt();
188 khahn 1.19 tmplep.vecorig->SetPtEtaPhiM(pt,
189 khahn 1.20 mu->Eta(),
190     mu->Phi(),
191     MUON_MASS);
192 khahn 1.19
193     if( ctrl.do_escale_up ) {
194     pt=scale_smear_muon_Up(pt, 1, r);
195     }
196     if( ctrl.do_escale_down ) {
197     pt=scale_smear_muon_Down(pt, 1, r);
198     }
199    
200     tmplep.vec->SetPtEtaPhiM(pt,
201 khahn 1.20 mu->Eta(),
202     mu->Phi(),
203     MUON_MASS);
204 khahn 1.19
205     tmplep.type = 13;
206     tmplep.index = i;
207 khahn 1.20 tmplep.charge = mu->Charge();
208     tmplep.isoTrk = mu->IsoR03SumPt();
209     tmplep.isoEcal = mu->IsoR03EmEt();
210     tmplep.isoHcal = mu->IsoR03HadEt();
211     tmplep.isoPF03 = computePFMuonIso(mu,vtx,pfCandidates,0.3);
212     tmplep.isoPF04 = computePFMuonIso(mu,vtx,pfCandidates,0.4);
213     tmplep.ip3dSig = mu->Ip3dPVSignificance();
214 khahn 1.19 tmplep.is4l = false;
215 khahn 1.20 tmplep.isEB = (fabs(mu->Eta()) < 1.479 ? 1 : 0 );
216 khahn 1.19 tmplep.isTight = musel.tight();
217     tmplep.isLoose = musel.loose();
218     lepvec.push_back(tmplep);
219     if( ctrl.debug ) { cout << "muon passes ... " << endl;}
220     }
221     // }
222     }
223    
224 khahn 1.1
225 khahn 1.19
226     //
227     if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
228     // --------------------------------------------------------------------------------
229     for(Int_t i=0; i<electronArr->GetEntries(); i++)
230     {
231 khahn 1.20 const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);
232 khahn 1.19
233     Bool_t isMuonOverlap = kFALSE;
234     for (int k=0; k<lepvec.size(); ++k) {
235     TVector3 tmplep;
236 khahn 1.20 tmplep.SetPtEtaPhi(ele->Pt(), ele->Eta(), ele->Phi());
237 khahn 1.19 if ( lepvec[k].isLoose && lepvec[k].type == 13 && lepvec[k].vec->Vect().DrEtaPhi(tmplep) < 0.1 ) {
238     if( ctrl.debug ) cout << "-----> isMuonOverlap! " << endl;
239     isMuonOverlap = kTRUE;
240     break;
241     }
242     }
243    
244     SelectionStatus elesel;
245     if( ctrl.debug ) cout << "--> status before anything: " << hex << elesel.getStatus() << dec << endl;
246 khahn 1.20 elesel |= (*ElectronPreSelector)(ctrl,ele,vtx);
247 khahn 1.19 if( ctrl.debug ) cout << "--> status after presel: " << hex << elesel.getStatus() << dec << endl;
248 khahn 1.20 elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
249 khahn 1.19 if( ctrl.debug ) cout << "--> status after ID: " << hex << elesel.getStatus() << dec << endl;
250 khahn 1.20 elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,muonsToVeto,electronsToVeto);
251 khahn 1.19 if( ctrl.debug ) cout << "--> status after iso: " << hex << elesel.getStatus() << dec << endl;
252    
253     if( ctrl.debug ){
254 khahn 1.20 cout << "\tscEt: " << ele->SCluster()->Et()
255     << "\tscEta: " << ele->SCluster()->Eta()
256 khahn 1.19 << "\tstatus: " << hex << elesel.getStatus() << dec
257     << endl;
258     }
259 dkralph 1.3
260 khahn 1.19 if ( elesel.pass() && !isMuonOverlap )
261     {
262     SimpleLepton tmplep;
263    
264 khahn 1.20 float pt = ele->Pt();
265 khahn 1.19 tmplep.vecorig->SetPtEtaPhiM( pt,
266 khahn 1.20 ele->Eta(),
267     ele->Phi(),
268 khahn 1.19 ELECTRON_MASS );
269    
270     if( ctrl.do_escale ) {
271 khahn 1.20 pt=scale_smear_electron(pt, ele->IsEB(), r);
272 khahn 1.19 }
273     if( ctrl.do_escale_up ) {
274 khahn 1.20 pt=scale_smear_electron_Up(pt, ele->IsEB(), r);
275 khahn 1.19 }
276     if( ctrl.do_escale_down ) {
277 khahn 1.20 pt=scale_smear_electron_Down(pt, ele->IsEB(), r);
278 khahn 1.19 }
279 khahn 1.1
280 khahn 1.19
281     tmplep.vec->SetPtEtaPhiM( pt,
282 khahn 1.20 ele->Eta(),
283     ele->Phi(),
284 khahn 1.19 ELECTRON_MASS );
285    
286     tmplep.type = 11;
287     tmplep.index = i;
288 khahn 1.20 tmplep.charge = ele->Charge();
289     tmplep.isoTrk = ele->TrackIsolationDr03();
290     tmplep.isoEcal = ele->EcalRecHitIsoDr03();
291     tmplep.isoHcal = ele->HcalTowerSumEtDr03();
292     tmplep.isoPF03 = computePFEleIso(ele,vtx,pfCandidates,0.3);
293     tmplep.isoPF04 = computePFEleIso(ele,vtx,pfCandidates,0.4);
294     tmplep.ip3dSig = ele->Ip3dPVSignificance();
295 khahn 1.19 tmplep.is4l = false;
296 khahn 1.20 tmplep.isEB = ele->IsEB();
297     tmplep.scID = ele->SCluster()->GetUniqueID();
298 khahn 1.19 tmplep.isTight = elesel.tight();
299     tmplep.isLoose = elesel.loose();
300     lepvec.push_back(tmplep);
301     if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
302     }
303 khahn 1.1 }
304 khahn 1.19
305    
306     //********************************************************
307     // Dump Stuff
308     //********************************************************
309     sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
310     int nmu=0, nele=0;
311     for( int i=0; i<lepvec.size(); i++ ) {
312     if(ctrl.debug) cout << "lepvec :: index: " << i
313     << "\tpt: " << lepvec[i].vec->Pt()
314     << "\ttype: " << lepvec[i].type
315     << endl;
316     if( abs(lepvec[i].type) == 11 ) nele++;
317     else nmu++;
318 khahn 1.1 }
319 khahn 1.19 if( ctrl.debug ) {
320     cout << "postsel nlep: " << lepvec.size()
321     << "\tnmuon: " << nmu
322     << "\tnelectron: " << nele
323 khahn 1.1 << endl;
324     }
325 khahn 1.19
326    
327     //******************************************************************************
328     // Z1 Selection
329     //******************************************************************************
330     int Z1LeptonPlusIndex = -1;
331     int Z1LeptonMinusIndex = -1;
332     double BestZ1Mass = -999;
333     if( ctrl.debug ) { cout << "looking for a Z1 ..." << endl; }
334     for(int i = 0; i < lepvec.size(); ++i) {
335     if( !(lepvec[i].isLoose) ) continue;
336     for(int j = i+1; j < lepvec.size(); ++j) {
337     if( !(lepvec[j].isLoose) ) continue;
338     if( ctrl.debug ) { cout << "\tconsidering leptons " << i << " & " << j << endl; }
339     if (!(lepvec[i].vec->Pt() > 20.0 || lepvec[j].vec->Pt() > 20.0)) continue;
340     if( ctrl.debug ) { cout << "\tat least one is > 20 GeV" << endl; }
341     if (!(lepvec[i].vec->Pt() > 10.0 && lepvec[j].vec->Pt() > 10.0)) continue;
342     if( ctrl.debug ) { cout << "\tthe other is > 10 GeV" << endl; }
343     if (lepvec[i].charge == lepvec[j].charge) continue;
344     if( ctrl.debug ) { cout << "\tthey're opposite charge" << endl; }
345     if (fabs(lepvec[i].type) != fabs(lepvec[j].type)) continue;
346     if( ctrl.debug ) { cout << "\tthey're same flavor" << endl; }
347    
348     //Make Z1 hypothesis
349     TLorentzVector *leptonPlus, *leptonMinus;
350     if ( lepvec[i].charge > 0 ) {
351     leptonPlus = lepvec[i].vec;
352     leptonMinus = lepvec[j].vec;
353     } else {
354     leptonPlus = lepvec[j].vec;
355     leptonMinus = lepvec[i].vec;
356     }
357    
358     float tmpZ1Mass = (*leptonPlus + *leptonMinus).M();
359     if( ctrl.debug ) cout << "Z1 selection, tmpZ1Mass: " << tmpZ1Mass << endl;
360 khahn 1.21 if( tmpZ1Mass > 50 ) {
361 khahn 1.19 if (fabs(tmpZ1Mass - Z_MASS) < fabs(BestZ1Mass - Z_MASS)) {
362     BestZ1Mass = tmpZ1Mass;
363     if( ctrl.debug ) cout << "Z1 selection, new BestZ1Mass: " << BestZ1Mass
364     << "\tdM: " << fabs(BestZ1Mass - Z_MASS)
365     << endl;
366     if (lepvec[i].charge > 0) {
367     Z1LeptonPlusIndex = i;
368     Z1LeptonMinusIndex = j;
369     } else {
370     Z1LeptonPlusIndex = j;
371     Z1LeptonMinusIndex = i;
372     }
373     }
374 khahn 1.13 }
375     }
376     }
377 khahn 1.19 // stop if no Z1 candidate is found
378     if( BestZ1Mass < 0 ) {
379     evtfail |= (1<<EVTFAIL_Z1);
380     //ret.status = evtfail;
381     ret.status.setStatus(0);
382     return ret;
383     }
384 khahn 1.20 if( ctrl.debug ) cout << "\tgot a Z1 ... run: " << info->RunNum() << "\tevt: " << info->EvtNum() << endl;
385 khahn 1.19 if( ctrl.debug ) cout << "\tZ1 plusindex: " << Z1LeptonPlusIndex << "\tminusindex: " << Z1LeptonMinusIndex << endl;
386     TLorentzVector Z1LeptonPlus = *(lepvec[Z1LeptonPlusIndex].vec);
387     TLorentzVector Z1LeptonMinus = *(lepvec[Z1LeptonMinusIndex].vec);
388     TLorentzVector Z1Candidate = Z1LeptonPlus + Z1LeptonMinus;
389    
390    
391     //******************************************************************************
392     // Z1 + l
393     //******************************************************************************
394     if( lepvec.size() < 3 ) {
395     evtfail |= (1<<EVTFAIL_Z1_PLUSL);
396     //ret.status = evtfail;
397     ret.status.setStatus(0);
398     return ret;
399     }
400    
401     //******************************************************************************
402     // 4l/Z2 Selection
403     //******************************************************************************
404     Int_t Z2LeptonPlusIndex = -1;
405     Int_t Z2LeptonMinusIndex = -1;
406     Double_t BestZ2Mass = -1;
407     if( ctrl.debug ) cout << "looking for a Z2 ... out of " << lepvec.size() << " leptons" <<endl;
408     for(int i = 0; i < lepvec.size(); ++i) {
409    
410     if( ctrl.debug) cout << "i: " << i
411     << "\tpt: " << lepvec[i].vec->Pt()
412     << "\ttype: " << lepvec[i].type
413     << endl;
414 khahn 1.1
415 khahn 1.19 if( ctrl.eleSeleScheme == "mediumloose" &&
416     !(lepvec[i].isTight) ) {
417     if( ctrl.debug) cout << "it's not tight, skipping ... " << endl;
418     continue;
419 khahn 1.1 }
420    
421 khahn 1.19 for(int j = i+1; j < lepvec.size(); ++j) {
422     if( ctrl.debug) cout << "\t\tj: " << j
423     << "\tpt: " << lepvec[j].vec->Pt()
424     << "\ttype: " << lepvec[j].type
425     << endl;
426    
427     if( ctrl.eleSeleScheme == "mediumloose" &&
428     !(lepvec[j].isTight) ) {
429     if( ctrl.debug) cout << "it's not tight, skipping ... " << endl;
430     continue;
431     }
432    
433    
434     if (i == Z1LeptonPlusIndex || i == Z1LeptonMinusIndex) {
435     if( ctrl.debug) cout << "\ti matches a Z1 index, skipping ..." << endl;
436     continue; //skip Z1 leptons
437     }
438     if (j == Z1LeptonPlusIndex || j == Z1LeptonMinusIndex) {
439     if( ctrl.debug) cout << "\tj matches a Z1 index, skipping ..." << endl;
440     continue; //skip Z1 leptons
441     }
442     if (lepvec[i].charge == lepvec[j].charge) {
443     if( ctrl.debug) cout << "\ti and j are same sign, skipping ..." << endl;
444     continue; //require opp sign
445     }
446     if (fabs(lepvec[i].type) != fabs(lepvec[j].type)) {
447     if( ctrl.debug) cout << "\ti and j are not same flavor, skipping ..." << endl;
448     continue; //require same flavor
449     }
450    
451    
452     //Make Z2 hypothesis
453     TLorentzVector *leptonPlus, *leptonMinus;
454    
455     if (lepvec[i].charge > 0 ) {
456     leptonPlus = lepvec[i].vec;
457     leptonMinus = lepvec[j].vec;
458     } else {
459     leptonPlus = lepvec[j].vec;
460     leptonMinus = lepvec[i].vec;
461     }
462    
463     TLorentzVector dilepton = *leptonPlus + *leptonMinus;
464     TLorentzVector fourLepton = Z1Candidate + dilepton;
465    
466     if( ctrl.debug ) cout << "dilepton.M() : " << dilepton.M() << endl;
467     if( ctrl.debug ) cout << "fourLepton.M() : " << fourLepton.M() << endl;
468    
469     if (!(dilepton.M() > 12.0)) continue;
470     if (!(fourLepton.M() > 100.0)) continue;
471    
472     //for 4e and 4mu, require at least 1 of the other opp sign lepton pairs have mass > 12
473     if (fabs(lepvec[i].type) == fabs(lepvec[Z1LeptonPlusIndex].type)) {
474     TLorentzVector pair1 = Z1LeptonPlus + *leptonMinus;
475     TLorentzVector pair2 = Z1LeptonMinus + *leptonPlus;
476     if( ctrl.debug ) cout << "pair1: " << pair1.M() << "\tpair2: "<< pair2.M() << endl;
477     if (!(pair1.M() > 12 || pair2.M() > 12)) continue;
478     }
479    
480    
481     //Disambiguiation is done by choosing the pair with the largest ptMax and largest ptMin
482     if (Z2LeptonPlusIndex < 0) {
483 khahn 1.1 if (lepvec[i].charge > 0) {
484 khahn 1.19 Z2LeptonPlusIndex = i;
485     Z2LeptonMinusIndex = j;
486 khahn 1.1 } else {
487 khahn 1.19 Z2LeptonPlusIndex = j;
488     Z2LeptonMinusIndex = i;
489     }
490     } else {
491     Double_t BestPairPtMax = lepvec[Z2LeptonPlusIndex].vec->Pt();
492     Double_t BestPairPtMin = lepvec[Z2LeptonMinusIndex].vec->Pt();
493     if (lepvec[Z2LeptonMinusIndex].vec->Pt() > BestPairPtMax) {
494     BestPairPtMax = lepvec[Z2LeptonMinusIndex].vec->Pt();
495     BestPairPtMin = lepvec[Z2LeptonPlusIndex].vec->Pt();
496     }
497    
498     Double_t CurrentPairPtMax = lepvec[i].vec->Pt();
499     Double_t CurrentPairPtMin = lepvec[j].vec->Pt();
500     if (lepvec[j].vec->Pt() > CurrentPairPtMax) {
501     CurrentPairPtMax = lepvec[j].vec->Pt();
502     CurrentPairPtMin = lepvec[i].vec->Pt();
503 khahn 1.1 }
504    
505 khahn 1.19 if (CurrentPairPtMax > BestPairPtMax) {
506     if (lepvec[i].charge > 0) {
507     Z2LeptonPlusIndex = i;
508     Z2LeptonMinusIndex = j;
509 khahn 1.1 } else {
510 khahn 1.19 Z2LeptonPlusIndex = j;
511     Z2LeptonMinusIndex = i;
512 khahn 1.1 }
513 khahn 1.19 } else if (CurrentPairPtMax == BestPairPtMax) {
514     if (CurrentPairPtMin > BestPairPtMin) {
515     if (lepvec[i].charge > 0) {
516     Z2LeptonPlusIndex = i;
517     Z2LeptonMinusIndex = j;
518 khahn 1.1 } else {
519 khahn 1.19 Z2LeptonPlusIndex = j;
520     Z2LeptonMinusIndex = i;
521     }
522 khahn 1.1 }
523 khahn 1.9 }
524 khahn 1.19 }
525     }
526     }
527    
528     // stop if no Z2 candidate is found
529     if (Z2LeptonPlusIndex == -1) {
530     evtfail |= ( 1<<EVTFAIL_4L );
531     // ret.status = evtfail;
532     ret.status.setStatus(0);
533     return ret;
534     }
535     if( ctrl.debug ) cout << "\tgot a Z2 ..." << endl;
536     if( ctrl.debug ) cout << "\tZ2 plusindex: " << Z2LeptonPlusIndex
537     << "\tminusindex: " << Z2LeptonMinusIndex << endl;
538     TLorentzVector Z2LeptonPlus = *(lepvec[Z2LeptonPlusIndex].vec);
539     TLorentzVector Z2LeptonMinus = *(lepvec[Z2LeptonMinusIndex].vec);
540     TLorentzVector Z2Candidate = Z2LeptonPlus+Z2LeptonMinus;
541     TLorentzVector ZZSystem = Z1Candidate + Z2Candidate;
542     lepvec[Z1LeptonPlusIndex].is4l = true;
543     lepvec[Z1LeptonMinusIndex].is4l = true;
544     lepvec[Z2LeptonPlusIndex].is4l = true;
545     lepvec[Z2LeptonMinusIndex].is4l = true;
546    
547 khahn 1.8
548    
549 khahn 1.19
550     //***************************************************************
551     // remaining kinematic cuts
552     //***************************************************************
553     double Z2massCut=0;
554     if ( ctrl.kinematics == "loose" ) Z2massCut = 12;
555     else if ( ctrl.kinematics == "tight" ) Z2massCut = 20;
556     else { cout << "error! kinematic tightness not defined!" << endl; assert(0); }
557    
558     if ( Z1Candidate.M() > 120 ||
559     Z2Candidate.M() < Z2massCut ||
560     Z2Candidate.M() > 120 ||
561     !(lepvec[Z1LeptonPlusIndex].vec->Pt() > 20.0 || lepvec[Z1LeptonMinusIndex].vec->Pt() > 20.0) ||
562     !(lepvec[Z1LeptonPlusIndex].vec->Pt() > 10.0 && lepvec[Z1LeptonMinusIndex].vec->Pt() > 10.0)
563     ) {
564     evtfail |= (1<<EVTFAIL_KINEMATICS );
565     // ret.status = evtfail;
566     ret.status.setStatus(0);
567     return ret;
568     }
569    
570     unsigned channel;
571     if( lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 11 ) channel=0;
572     if( lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 13 ) channel=1;
573     if( (lepvec[Z1LeptonMinusIndex].type == 11 && lepvec[Z2LeptonMinusIndex].type == 13) ||
574     (lepvec[Z1LeptonMinusIndex].type == 13 && lepvec[Z2LeptonMinusIndex].type == 11)) channel=2;
575    
576    
577    
578    
579 khahn 1.20 if( ctrl.debug ) cout << "run: " << info->RunNum()
580     << "\tevt: " << info->EvtNum()
581 khahn 1.19 << "\tZ1channel: " << lepvec[Z1LeptonMinusIndex].type
582     << "\tZ2channel: " << lepvec[Z2LeptonMinusIndex].type
583     << "\tmZ1: " << Z1Candidate.M()
584     << "\tmZ2: " << Z2Candidate.M()
585     << "\tm4l: " << ZZSystem.M()
586     << "\tevtfail: " << hex << evtfail << dec
587 khahn 1.20 // << "\ttrigbits: " << hex << info->triggerBits << dec
588 khahn 1.19 // << "\ttree: " << inputFiles[q][f]
589     << endl;
590    
591 khahn 1.14
592    
593 khahn 1.19 //***************************************************************
594     // finish
595     //***************************************************************
596    
597     if( !evtfail ) {
598     ret.status.setStatus(SelectionStatus::EVTPASS);
599     ret.Z1leptons.push_back(lepvec[Z1LeptonMinusIndex]);
600     ret.Z1leptons.push_back(lepvec[Z1LeptonPlusIndex]);
601     ret.Z2leptons.push_back(lepvec[Z2LeptonMinusIndex]);
602     ret.Z2leptons.push_back(lepvec[Z2LeptonPlusIndex]);
603     }
604 khahn 1.1
605 khahn 1.19 return ret;
606 khahn 1.1 }
607    
608