ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/Selection.cc
(Generate patch)

Comparing UserCode/MitHzz4l/Selection/src/Selection.cc (file contents):
Revision 1.16 by khahn, Mon Nov 7 05:28:06 2011 UTC vs.
Revision 1.19 by khahn, Mon Feb 13 09:47:12 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines