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

Comparing UserCode/MitHzz4l/Selection/src/ReferenceSelection.cc (file contents):
Revision 1.20 by anlevin, Fri Oct 19 18:14:53 2012 UTC vs.
Revision 1.21 by dkralph, Tue Oct 23 11:39:21 2012 UTC

# Line 1 | Line 1
1
2 //***************************************************************************************************
3 //
4 // selection sync'ed with https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsZZ4l2012SummerSync
5 //
6 //***************************************************************************************************
7
1   // system headers
2   #include <map>
3   #include <utility>
# Line 33 | Line 26
26   extern vector<SimpleLepton> failingLeptons;
27   extern vector<SimpleLepton> passingLeptons;
28  
36 extern vector<unsigned> cutvec;
37 extern vector<vector<unsigned> > zcutvec;
38 extern vector<vector<unsigned> > zzcutvec;
29   extern map<unsigned,float>       evtrhoMap;
30   extern bool passes_HLT;
31   extern map<TString, map<TString,int>* > counts;
32 + extern ElectronMomentumCorrection electron_momentum_correction;
33 + extern MuCorr *muCorr;
34  
35 < //
44 < // prototypes
45 < //--------------------------------------------------------------------------------------------------
35 > //----------------------------------------------------------------------------------------
36   void updateSimpleLepton(SimpleLepton &tmplep);
37 < void fillVetoArrays( ControlFlags & ctrl,
48 <                     const mithep::Array<mithep::Muon> *muonArr,    
49 <                     vector< const mithep::Muon*>     & muonsToVeto,
50 <                     const mithep::Array<mithep::Electron> *electronArr,    
51 <                     vector< const mithep::Electron*> & electronsToVeto,
52 <                     const mithep::Vertex * vtx ) ;
53 < //--------------------------------------------------------------------------------------------------
37 > //----------------------------------------------------------------------------------------
38   void increment(TString cutName, int z1type=0, int z2type=0)
39 + //----------------------------------------------------------------------------------------
40 + // increment counters that keep track up event counts at each cut
41   {
42    assert(counts.find(cutName) != counts.end());
43    (*(counts[cutName]))["all"] ++;
# Line 60 | Line 46 | void increment(TString cutName, int z1ty
46      (*(counts[cutName]))[getChannel(z1type,z2type)] ++;
47    }
48   }
63
49   //--------------------------------------------------------------------------------------------------
50   EventData apply_HZZ4L_reference_selection(ControlFlags &ctrl,           // input control
51 <                                           const mithep::EventHeader *info,     // input event info
52 <                                           const mithep::Array<mithep::Vertex>       * vtxArr ,
53 <                                           const mithep::Array<mithep::PFCandidate>  *pfCandidates,
54 <                                           const mithep::Array<mithep::PileupEnergyDensity>  *puEnergyDensity,
55 <                                           const mithep::Array<mithep::Electron> *electronArr,    // input electrons
51 >                                           const EventHeader *info,     // input event info
52 >                                           const Array<Vertex>       * vtxArr ,
53 >                                           const Array<PFCandidate>  *pfCandidates,
54 >                                           const Array<PileupEnergyDensity>  *puEnergyDensity,
55 >                                           const Array<Electron> *electronArr,    // input electrons
56                                             SelectionStatus (*ElectronPreSelector)( ControlFlags &,
57 <                                                                                   const mithep::Electron*,
58 <                                                                                   const mithep::Vertex *),
57 >                                                                                   const Electron*,
58 >                                                                                   const Vertex *),
59                                             SelectionStatus (*ElectronIDSelector)( ControlFlags &,
60 <                                                                                  const mithep::Electron*,
61 <                                                                                  const mithep::Vertex *),
60 >                                                                                  const Electron*,
61 >                                                                                  const 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::PFCandidate*>),
69 <                                           const mithep::Array<mithep::Muon> *muonArr,    // input muons
63 >                                                                                   const Electron*,
64 >                                                                                   const Vertex *,
65 >                                                                                   const Array<PFCandidate> *,
66 >                                                                                   const Array<PileupEnergyDensity> *,
67 >                                                                                   ElectronTools::EElectronEffectiveAreaTarget,
68 >                                                                                   vector<const PFCandidate*>),
69 >                                           const Array<Muon> *muonArr,    // input muons
70                                             SelectionStatus (*MuonPreSelector)( ControlFlags &,
71 <                                                                               const mithep::Muon*,
72 <                                                                               const mithep::Vertex *,
73 <                                                                               const mithep::Array<mithep::PFCandidate> *),
71 >                                                                               const Muon*,
72 >                                                                               const Vertex *,
73 >                                                                               const Array<PFCandidate> *),
74                                             SelectionStatus (*MuonIDSelector)( ControlFlags &,
75 <                                                                              const mithep::Muon*,
76 <                                                                              // const mithep::Vertex &),
77 <                                                                              const mithep::Vertex *,
78 <                                                                              const mithep::Array<mithep::PFCandidate> *),
75 >                                                                              const Muon*,
76 >                                                                              // const Vertex &),
77 >                                                                              const Vertex *,
78 >                                                                              const Array<PFCandidate> *),
79                                             SelectionStatus (*MuonIsoSelector)( ControlFlags &,
80 <                                                                               const mithep::Muon*,
81 <                                                                               const mithep::Vertex *,
82 <                                                                               const mithep::Array<mithep::PFCandidate> *,
83 <                                                                               const mithep::Array<mithep::PileupEnergyDensity> *,
84 <                                                                               mithep::MuonTools::EMuonEffectiveAreaTarget,
85 <                                                                               vector<const mithep::PFCandidate*>)
80 >                                                                               const Muon*,
81 >                                                                               const Vertex *,
82 >                                                                               const Array<PFCandidate> *,
83 >                                                                               const Array<PileupEnergyDensity> *,
84 >                                                                               MuonTools::EMuonEffectiveAreaTarget,
85 >                                                                               vector<const PFCandidate*>)
86                                            )
87   //--------------------------------------------------------------------------------------------------
88 < {      
89 <
88 > {
89 >  increment("start");
90    EventData ret;
106  unsigned evtfail = 0x0;
107  TRandom3 r;
108
91    failingLeptons.clear();
92    passingLeptons.clear();
93  
94 <  mithep::MuonTools::EMuonEffectiveAreaTarget eraMu;
95 <  mithep::ElectronTools::EElectronEffectiveAreaTarget eraEle;
94 >  MuonTools::EMuonEffectiveAreaTarget eraMu;
95 >  ElectronTools::EElectronEffectiveAreaTarget eraEle;
96    getEATargets(ctrl,eraMu,eraEle);
97  
98    if( ctrl.debug ) {
# Line 120 | Line 102 | EventData apply_HZZ4L_reference_selectio
102           << endl;
103    }
104  
105 <  //correct muon momentum
106 <  if(ctrl.correct_muon_momentum){
105 >  // correct muon momentum
106 >  if(ctrl.correct_muon_momentum) {
107 >    assert(muCorr->corr2011 && muCorr->corr2012);
108      for(int i=0; i<muonArr->GetEntries(); i++) {
109 <      const mithep::Muon *const_mu = (mithep::Muon*)((*muonArr)[i]);
110 <      mithep::Muon *mu = const_cast<mithep::Muon*>(const_mu);
111 <      correct_muon_momentum(ctrl, mu,info->RunNum());
129 <
109 >      const Muon *const_mu = (Muon*)((*muonArr)[i]);
110 >      Muon *mu = const_cast<Muon*>(const_mu);
111 >      correct_muon_momentum(ctrl,muCorr,mu,info->RunNum());
112      }
113    }
114  
115 < //   //********************************************************
134 < //   // Skim 0 :
135 < //   //********************************************************
136 < //   int nlep_above_10=0;
137 < //   int nlep_above_20=0;
138 < //   for(int i=0; i<muonArr->GetEntries(); i++)
139 < //     {
140 < //       const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[i]);  
141 <      
142 <    
143 < //       if( !(mu->IsTrackerMuon() || mu->IsGlobalMuon()) ) continue;
144 < //       if( fabs(mu->Eta()) > 2.4 )                        continue;
145 < //       if( mu->Pt() > 10 )  nlep_above_10++;
146 < //       if( mu->Pt() > 20 )  nlep_above_20++;
147 < //     }
148 < //   for(int i=0; i<electronArr->GetEntries(); i++)
149 < //     {
150 < //       const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);        
151 < //       if( fabs(ele->Eta()) > 2.5 )                        continue;
152 < //       if( ele->Pt() > 10 )  nlep_above_10++;
153 < //       if( ele->Pt() > 20 )  nlep_above_20++;
154 < //     }
155 < //   if( (nlep_above_10 > 1 && nlep_above_20 > 0) ) {
156 <    ret.status.selectionBits.flip(PASS_SKIM0);
157 <    cutvec[PASS_SKIM0] +=1;
158 < //   } else {
159 < //     ret.status.setStatus(SelectionStatus::FAIL);
160 < //     return ret;
161 < //   }
162 <
163 <
164 < //   //********************************************************
165 < //   // Skim 0.1 : 1 SF pair with  mLL > 40
166 < //   //********************************************************
167 < //   bool ossf_pair=false;
168 < //   for(int i=0; i<muonArr->GetEntries(); i++)
169 < //     {
170 < //       const mithep::Muon *mu1 = (mithep::Muon*)((*muonArr)[i]);        
171 < //       if( !(mu1->IsTrackerMuon() || mu1->IsGlobalMuon()) ) continue;
172 < //       if( fabs(mu1->Eta()) > 2.4 )                         continue;
173 < //                      if( fabs(mu1->Pt()) < 3 )                         continue;
174 < //       for(int j=i+1; j<muonArr->GetEntries(); j++)
175 < //      {
176 < //        const mithep::Muon *mu2 = (mithep::Muon*)((*muonArr)[j]);        
177 < //        if( !(mu2->IsTrackerMuon() || mu2->IsGlobalMuon()) ) continue;
178 < //        if( fabs(mu2->Eta()) > 2.4 )                         continue;
179 < //              if( fabs(mu2->Pt()) < 3 )                         continue;
180 < //        TLorentzVector v1,v2;
181 < //        v1.SetPtEtaPhiM( mu1->Pt(), mu1->Eta(), mu1->Phi(), MUON_MASS);
182 < //        v2.SetPtEtaPhiM( mu2->Pt(), mu2->Eta(), mu2->Phi(), MUON_MASS);
183 < //        if( (v1+v2).M() >= 40) ossf_pair = true;
184 < //      }
185 < //     }
186 < //   for(int i=0; i<electronArr->GetEntries(); i++)
187 < //     {
188 < //       const mithep::Electron *el1 = (mithep::Electron*)((*electronArr)[i]);        
189 < //       if( fabs(el1->Eta()) > 2.5 )                         continue;
190 < //                if( el1->Pt() < 5 )                         continue;
191 < //       for(int j=i+1; j<electronArr->GetEntries(); j++)
192 < //      {
193 < //        const mithep::Electron *el2 = (mithep::Electron*)((*electronArr)[j]);        
194 < //        if( fabs(el2->Eta()) > 2.5 )                         continue;
195 < //              if( el2->Pt() < 5 )                         continue;
196 < //        TLorentzVector v1,v2;
197 < //        v1.SetPtEtaPhiM( el1->Pt(), el1->Eta(), el1->Phi(), ELECTRON_MASS);
198 < //        v2.SetPtEtaPhiM( el2->Pt(), el2->Eta(), el2->Phi(), ELECTRON_MASS);
199 < //        if( (v1+v2).M() >= 40 ) ossf_pair = true;
200 < //      }
201 < //     }
202 <
203 < //   if( ossf_pair ) {
204 <    ret.status.selectionBits.flip(PASS_SKIM1);
205 <    cutvec[PASS_SKIM1] +=1;
206 < //   } else {
207 < //     ret.status.setStatus(SelectionStatus::FAIL);
208 < //     return ret;
209 < //   }
210 <  
211 <  const mithep::Vertex * vtx;
115 >  const Vertex * vtx;
116    bool goodVertex = setPV( ctrl, vtxArr, vtx );
117 <  if(goodVertex) {
214 <    ret.status.selectionBits.flip(PASS_SKIM2);
215 <    cutvec[PASS_SKIM2] +=1;
216 <  } else {
117 >  if(!goodVertex) {
118      if(ctrl.debug) cout << "found bad vertex" << endl;
119      ret.status.setStatus(SelectionStatus::FAIL);
120      return ret;
121    }
122 <  if(ctrl.debug) {
123 <    cerr << "vtx :: ntrks: " << vtx->NTracksFit() << endl;
223 <    cerr.flush();
224 <  }
122 >  if(ctrl.debug)
123 >    cout << "vtx :: ntrks: " << vtx->NTracksFit() << endl;
124  
125    //***********************************************************
126    // Trigger Selection  
127    //***********************************************************
128    if( passes_HLT ) {
230    ret.status.selectionBits.flip(PASS_TRIGGER);
231    cutvec[PASS_TRIGGER] +=1;
129      increment("trigger");
130    } else {
234    ret.status.setStatus(SelectionStatus::FAIL);
131      if(ctrl.debug) cout << "fails trigger" << endl;
132 +    ret.status.setStatus(SelectionStatus::FAIL);
133      return ret;
134    }
135    
# Line 240 | Line 137 | EventData apply_HZZ4L_reference_selectio
137    // Lepton Selection
138    //***********************************************************
139    vector<SimpleLepton> lepvec;
140 +  vector<const PFCandidate*> photonsToVeto;
141  
244  // empty, reference is not applying additional vetos
245  // vector<const mithep::Muon*> muonsToVeto;
246  // vector<const mithep::Electron*> electronsToVeto;
247  //  fillVetoArrays( ctrl, muonArr, muonsToVeto, electronArr, electronsToVeto, vtx );
248  vector<const mithep::PFCandidate*> photonsToVeto;
249
250
251  //    
142    if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
253  //----------------------------------------------------
143    for(int i=0; i<muonArr->GetEntries(); i++)
144      {
145 <      const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[i]);      
146 <
145 >      const Muon *mu = (Muon*)((*muonArr)[i]);      
146 >      
147        SelectionStatus musel;
148        if(ctrl.debug) cout << "musel.status  before anything: " << musel.getStatus() << endl;
149  
# Line 267 | Line 156 | EventData apply_HZZ4L_reference_selectio
156        if(ctrl.debug) cout << "musel.status  after ID: " << musel.getStatus() << endl;
157        if( ctrl.debug ) cout << endl;
158  
159 +      // if we *do* FSR, isolation is calculated only after FSR recovery
160        if( !(ctrl.doFSR) ) {
161          musel |=  (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);
162          if(ctrl.debug) cout << "musel.status  after iso: " << musel.getStatus() << endl;
273        if( ctrl.debug ) cout << "isomva : " << musel.isoMVA << endl;
274        if( ctrl.debug ) cout << endl;
163        }
164  
165 <      if( ctrl.debug ) {
166 <        cout << "muon:: pt: " << mu->Pt()
279 <             << "\teta: " << mu->Eta()
280 <             << "\tstatus: " << hex << musel.getStatus() << dec
281 <             << endl;
282 <      }
283 <      
165 >      if( ctrl.debug )
166 >        cout << "muon:: pt: " << mu->Pt() << "\teta: " << mu->Eta() << "\tstatus: " << hex << musel.getStatus() << dec << endl;
167  
168        SimpleLepton tmplep;
169 <      float pt = mu->Pt();
287 <      tmplep.vec.SetPtEtaPhiM(pt,
288 <                               mu->Eta(),
289 <                               mu->Phi(),
290 <                               MUON_MASS);
291 <      
169 >      tmplep.vec.SetPtEtaPhiM(mu->Pt(), mu->Eta(), mu->Phi(), MUON_MASS);
170        tmplep.type    = 13;
171        tmplep.index   = i;
172        tmplep.charge  = mu->Charge();
295      tmplep.isoTrk  = mu->IsoR03SumPt();
296      tmplep.isoEcal = mu->IsoR03EmEt();
297      tmplep.isoHcal = mu->IsoR03HadEt();
298      tmplep.isoPF04 = musel.isoPF04;
299      tmplep.chisoPF04 = musel.chisoPF04;
300      tmplep.gaisoPF04 = musel.gaisoPF04;
301      tmplep.neisoPF04 = musel.neisoPF04;
302      // tmplep.isoPF03 = computePFMuonIso(mu,vtx,pfCandidates,0.3);
303      // tmplep.isoPF04 = computePFMuonIso(mu,vtx,pfCandidates,0.4);
173        tmplep.ip3dSig = mu->Ip3dPVSignificance();
174        tmplep.is4l    = false;
175        tmplep.isEB    = (fabs(mu->Eta()) < 1.479 ? 1 : 0 );
307      tmplep.isoMVA  = musel.isoMVA;
308      tmplep.isTight = musel.tight();
176        tmplep.isLoose = musel.loose();
177 <      tmplep.status  = musel;
178 <      tmplep.fsrRecoveryAttempted = false;
179 <      tmplep.isPFMuon = mu->IsPFMuon();
313 <      tmplep.isGlobalMuon = mu->IsGlobalMuon();
177 >      tmplep.isTight = mu->IsPFMuon() || mu->IsGlobalMuon();
178 >      tmplep.status  = musel;    
179 >      tmplep.fsrRecoveryAttempted = false; // NOTE: this is *used* inside FSR.cc
180        lepvec.push_back(tmplep);
181        if( ctrl.debug ) cout << endl;
182      }
317
318  
183      
320    //
184      if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
322    // --------------------------------------------------------------------------------
185      for(int i=0; i<electronArr->GetEntries(); i++)
186        {
187 +        const Electron *const_ele = (Electron*)((*electronArr)[i]);
188 +        Electron *ele = const_cast<Electron*>(const_ele);
189  
190 < //      const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);
191 <        const mithep::Electron *const_ele = (mithep::Electron*)((*electronArr)[i]);
328 <        mithep::Electron *ele = const_cast<mithep::Electron*>(const_ele);
190 >        // evaluate MVA *before* regression correction (but cut on mvaVal *after*)
191 >        double mvaVal = getElectronIDMVAval(ctrl, ele, vtx);
192  
330        SelectionStatus elesel;
331        if( ctrl.debug ) cout << endl;
332        if( ctrl.debug ) cout << "--> status before anything: " << hex << elesel.getStatus() << dec << endl;
333
334        elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
335        if( ctrl.debug ) cout << "--> status after ID: " << hex << elesel.getStatus() << dec << endl;
336        if( ctrl.debug ) cout << endl;
337
338        ElectronMomentumCorrection electron_momentum_correction;
193          electron_momentum_correction.correct_electron_momentum(ctrl, ele,puEnergyDensity->At(0)->RhoKt6PFJets(),vtxArr->GetEntries());
194  
195 <        bool pass = false;
196 <  
343 <        Int_t subdet = 0;
344 <        if (fabs(ele->SCluster()->Eta()) < 0.8) subdet = 0;
345 <        else if (fabs(ele->SCluster()->Eta()) < 1.479) subdet = 1;
346 <        else subdet = 2;
347 <        Int_t ptBin = 0;
348 <        if (ele->Pt() > 10) ptBin = 1;
349 <        
350 <        Int_t MVABin = -1;
351 <        if (subdet == 0 && ptBin == 0) MVABin = 0; // eta<0.8, pt<10
352 <        if (subdet == 1 && ptBin == 0) MVABin = 1; // 0.8<eta<1.479, pt<10
353 <        if (subdet == 2 && ptBin == 0) MVABin = 2; // eta>1.478, pt<10
354 <        if (subdet == 0 && ptBin == 1) MVABin = 3; // eta<0.8, pt>10
355 <        if (subdet == 1 && ptBin == 1) MVABin = 4; // 0.8<eta<1.479, pt>10
356 <        if (subdet == 2 && ptBin == 1) MVABin = 5; // eta>1.478, pt>10    
357 <        
358 <        if( MVABin == 0 && elesel.idMVA > ELE_REFERENCE_IDMVA_CUT_BIN0 ) pass = true;
359 <        if( MVABin == 1 && elesel.idMVA > ELE_REFERENCE_IDMVA_CUT_BIN1 ) pass = true;
360 <        if( MVABin == 2 && elesel.idMVA > ELE_REFERENCE_IDMVA_CUT_BIN2 ) pass = true;
361 <        if( MVABin == 3 && elesel.idMVA > ELE_REFERENCE_IDMVA_CUT_BIN3 ) pass = true;
362 <        if( MVABin == 4 && elesel.idMVA > ELE_REFERENCE_IDMVA_CUT_BIN4 ) pass = true;
363 <        if( MVABin == 5 && elesel.idMVA > ELE_REFERENCE_IDMVA_CUT_BIN5 ) pass = true;
364 <        
365 <        if( pass ) {
366 <          elesel.orStatus(SelectionStatus::LOOSEID);
367 <          elesel.orStatus(SelectionStatus::TIGHTID);
368 <        }      
195 >        SelectionStatus elesel;
196 >        if( ctrl.debug ) cout << "--> status before anything: " << hex << elesel.getStatus() << dec << endl;
197  
198          elesel |= (*ElectronPreSelector)(ctrl,ele,vtx);
199          if( ctrl.debug ) cout << "--> status after presel: " << hex << elesel.getStatus() << dec << endl;
200          if( !(elesel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
373        if( ctrl.debug ) cout << endl;
201  
202 <      if( !(ctrl.doFSR) ) {
203 <        elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
204 <        if( ctrl.debug ) cout << "--> status after iso: " << hex << elesel.getStatus() << dec << endl;
378 <        if( ctrl.debug ) cout << endl;
379 <      }
202 >        // elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
203 >        elesel |= passElectronIDMVA(ctrl, mvaVal, ele);
204 >        if( ctrl.debug ) cout << "--> status after ID: " << hex << elesel.getStatus() << dec << endl;
205  
206 <      if( ctrl.debug ){
207 <        cout << "\tscEt: " << ele->SCluster()->Et()
208 <             << "\tscEta: " << ele->SCluster()->Eta()
209 <             << "\tstatus: " << hex << elesel.getStatus() << dec
210 <             << endl;
211 <      }
212 <      
206 >        if( !(ctrl.doFSR) ) {
207 >          elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
208 >          if( ctrl.debug ) cout << "--> status after iso: " << hex << elesel.getStatus() << dec << endl;
209 >        }
210 >        
211 >        if( ctrl.debug )
212 >          cout << "\tscEt: " << ele->SCluster()->Et()
213 >               << "\tscEta: " << ele->SCluster()->Eta()
214 >               << "\tstatus: " << hex << elesel.getStatus() << dec
215 >               << endl;
216  
217 <      SimpleLepton tmplep;
218 <      float pt = ele->Pt();
219 <      tmplep.vec.SetPtEtaPhiM( pt,
220 <                               ele->Eta(),
221 <                               ele->Phi(),
222 <                               ELECTRON_MASS );
223 <      
224 <      tmplep.type    = 11;
225 <      tmplep.index   = i;
226 <      tmplep.charge  = ele->Charge();
227 <      tmplep.isoTrk  = ele->TrackIsolationDr03();
228 <      tmplep.isoEcal = ele->EcalRecHitIsoDr03();
229 <      tmplep.isoHcal = ele->HcalTowerSumEtDr03();
230 <      tmplep.isoPF04 = elesel.isoPF04;
231 <      tmplep.chisoPF04 = elesel.chisoPF04;
404 <      tmplep.gaisoPF04 = elesel.gaisoPF04;
405 <      tmplep.neisoPF04 = elesel.neisoPF04;
406 <      // tmplep.isoPF03 = computePFEleIso(ele,vtx,pfCandidates,0.3);
407 <      // tmplep.isoPF04 = computePFEleIso(ele,vtx,pfCandidates,0.4);
408 <      tmplep.ip3dSig = ele->Ip3dPVSignificance();
409 <      tmplep.is4l    = false;
410 <      tmplep.isEB    = ele->IsEB();
411 <      tmplep.scID    = ele->SCluster()->GetUniqueID();
412 <      tmplep.isTight = elesel.tight();
413 <      tmplep.isLoose = elesel.loose();
414 <      tmplep.status  = elesel;
415 <      tmplep.idMVA   = elesel.idMVA;
416 <      tmplep.isoMVA  = elesel.isoMVA;
417 <      tmplep.fsrRecoveryAttempted = false;
418 <      tmplep.isPFMuon = false;
419 <      tmplep.isGlobalMuon = false;
420 <      lepvec.push_back(tmplep);
421 <      if( ctrl.debug ) cout << endl;
217 >        SimpleLepton tmplep;
218 >        tmplep.vec.SetPtEtaPhiM( ele->Pt(), ele->Eta(), ele->Phi(), ELECTRON_MASS );
219 >        tmplep.type    = 11;
220 >        tmplep.index   = i;
221 >        tmplep.charge  = ele->Charge();
222 >        tmplep.ip3dSig = ele->Ip3dPVSignificance();
223 >        tmplep.is4l    = false;
224 >        tmplep.isEB    = ele->IsEB();
225 >        tmplep.scID    = ele->SCluster()->GetUniqueID();
226 >        tmplep.isTight = elesel.tight();
227 >        tmplep.isLoose = elesel.loose();
228 >        tmplep.status  = elesel;
229 >        tmplep.fsrRecoveryAttempted = false; // NOTE: this is *used* inside FSR.cc
230 >        lepvec.push_back(tmplep);
231 >        if( ctrl.debug ) cout << endl;
232        }
233 <        
233 >
234      //********************************************************
235      // Dump Stuff
236      //********************************************************
237      sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
428    //    sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_reversept_sort );
238      int nmu=0, nele=0;
239      for( int i=0; i<lepvec.size(); i++ ) {
240        if(ctrl.debug) {
241 <        cout << "lepvec :: evt: " << info->EvtNum()
242 <             << "\tindex: " << i
243 <             << "\ttype: " << lepvec[i].type
244 <             << "\tpt: " << lepvec[i].vec.Pt()
245 <             << "\teta: " << lepvec[i].vec.Eta();
241 >        bitset<16> tmpbits(lepvec[i].status.getStatus());
242 >        cout << "lepvec :: evt: " << setw(8) << info->EvtNum() << " index: " << setw(3) << i << " type: " << setw(4) << lepvec[i].type
243 >             << " pt: " << setw(11) << lepvec[i].vec.Pt() << " eta: " << setw(11) << lepvec[i].vec.Eta() << " status: " << tmpbits;
244 >        if(!ctrl.doFSR)
245 >          cout << "\tpf: " << lepvec[i].status.isoPF04 << "\tch: " << lepvec[i].status.chisoPF04 << "\tga: " << lepvec[i].status.gaisoPF04
246 >               << "\tne: " << lepvec[i].status.neisoPF04 << endl;
247          if( abs(lepvec[i].type) == 11 ) {
248 <          const mithep::Electron *tmpele = (mithep::Electron*)((*electronArr)[lepvec[i].index]);
248 >          const Electron *tmpele = (Electron*)((*electronArr)[lepvec[i].index]);
249            cout << "\tSCeta: " << tmpele->SCluster()->Eta()
250 <               << "\tidMVA: " << lepvec[i].idMVA;
250 >               << "\tidMVA: " << lepvec[i].status.idMVA;
251          }
442        cout << "\tloose: " << lepvec[i].isLoose
443             << "\tpf: " << lepvec[i].isoPF04
444             << "\tch: " << lepvec[i].chisoPF04
445             << "\tga: " << lepvec[i].gaisoPF04
446             << "\tne: " << lepvec[i].neisoPF04 ;
252          cout << endl;
253        }
254        if( abs(lepvec[i].type) == 11 ) nele++;
# Line 457 | Line 262 | EventData apply_HZZ4L_reference_selectio
262      }
263      
264      //********************************************************
265 <    // Step 2: Lepton Cleaning
265 >    // Step 2: Lepton Cross-Cleaning: remove electrons that are next to 'good'ish muons
266      //********************************************************
267      vector<vector<SimpleLepton>::iterator> electrons_to_erase;
268      for (vector<SimpleLepton>::iterator it1=lepvec.begin();
# Line 470 | Line 275 | EventData apply_HZZ4L_reference_selectio
275             it2 != lepvec.end(); it2++ ) {
276          if ( it2 == it1 ) continue;
277          if ( abs(it2->type) != 13 ) continue;
278 +        // from ANL:
279 +        // ??-  if( !it2->status.passPre() || (!it2->isPFMuon && !it2->isGlobalMuon)  )       continue;
280 +        if( !it2->status.passPre() ) continue;
281 +        if( !it2->isTight )       continue; // NOTE: isTight is set to it2->isPFMuon || it2->isGlobalMuon
282  
474        if( !it2->status.passPre() || (!it2->isPFMuon && !it2->isGlobalMuon)  )       continue;
283          TVector3 mvec = it2->vec.Vect();
476        
284          if ( evec.DrEtaPhi(mvec) < 0.05 ) {
285            erase_this_electron=true;
286            break;
# Line 487 | Line 294 | EventData apply_HZZ4L_reference_selectio
294      for( int i=0; i<electrons_to_erase.size(); i++ ) {
295        lepvec.erase(electrons_to_erase[i]);
296      }
490    if( lepvec.size() >= 4 ) {
491      //      ret.status.selectionBits.flip(3);
492    } else {
493      //       ret.status.setStatus(SelectionStatus::FAIL);
494      //       return ret;
495    }
297  
298      //********************************************************
299 <    // Step 3: Good Leptons
299 >    // Step 3: Good Leptons (remove non-id-and-pre'd leptons)
300      //********************************************************
301      vector<double> pt_of_leptons_to_erase;
302      for (int i=0; i<lepvec.size(); i++ ) {
303        bool already_pushed=false;
304        if( !(lepvec[i].status.looseIDAndPre()) ) {
305          pt_of_leptons_to_erase.push_back(lepvec[i].vec.Pt());
505
306          already_pushed = true;
307          if(ctrl.debug)
308            cout << "pushing failed lepton type: " << lepvec[i].type
# Line 532 | Line 332 | EventData apply_HZZ4L_reference_selectio
332      if( ctrl.debug ) cout << "good leptons : " << lepvec.size() << endl;
333  
334      //********************************************************
335 +    //  Ghost Removal
336 +    //********************************************************
337 +    vector<vector<SimpleLepton>::iterator> leptons_to_erase;
338 +    for (vector<SimpleLepton>::iterator it1=lepvec.begin(); it1 != lepvec.end(); it1++ ) {
339 +      TVector3 lep1 = it1->vec.Vect();
340 +      
341 +      bool erase_this_lepton=false;
342 +      for (vector<SimpleLepton>::iterator it2=it1+1; it2 != lepvec.end(); it2++ ) {
343 +        TVector3 lep2 = it2->vec.Vect();
344 +        
345 +        if ( lep1.DrEtaPhi(lep2) <= 0.02 ) {
346 +          erase_this_lepton=true;
347 +          break;
348 +        }
349 +      }
350 +      if( erase_this_lepton ) {
351 +        if( ctrl.debug ) cout << "erasing ghost with pt  " <<  it1->vec.Pt() << endl;
352 +        leptons_to_erase.push_back(it1);
353 +      }
354 +    }
355 +    for( int i=0; i<leptons_to_erase.size(); i++ ) {
356 +      lepvec.erase(leptons_to_erase[i]);
357 +    }
358 +
359 +    //********************************************************
360      // Step 4: Z candidate preselection
361      //********************************************************
362 <    std::vector<std::pair<int,int> > ZCandidates;
363 <    std::vector<std::pair<SimpleLepton,SimpleLepton> > ZCandidatesLeptons;
364 <    std::vector<std::pair<SelectionStatus,SelectionStatus> > ZCandidatesSelectionStatus;
362 >    vector<pair<int,int> > ZCandidates;
363 >    vector<pair<SimpleLepton,SimpleLepton> > ZCandidatesLeptons;
364 >    vector<pair<SelectionStatus,SelectionStatus> > ZCandidatesSelectionStatus;
365      for(int i = 0; i < lepvec.size(); ++i) {
366        for(int j = i+1; j < lepvec.size(); ++j) {
367          if( abs(lepvec[i].type) != abs(lepvec[j].type) )      continue;
# Line 548 | Line 373 | EventData apply_HZZ4L_reference_selectio
373          vector<SimpleLepton> lepvec_j = lepvec;
374  
375          if( ctrl.doFSR ) {
376 <            cout << endl;
552 <            cout << "----------------> FSR ("<<i<<","<<j<<") <----------------------" << endl;
376 >          if(ctrl.debug) cout << endl << "----------------> FSR ("<<i<<","<<j<<") <----------------------" << endl;
377            photonsToVeto.clear();
378            float old_pt_i = lepvec[i].vec.Pt();
379            float old_pt_j = lepvec[j].vec.Pt();
380            float old_M  =  Zvec.M();
381            
382 <
559 <          cout << "i: " << i << endl;
382 >          if(ctrl.debug) cout << "i: " << i << endl;
383            if( abs(lepvec[i].type) == 13 ) {
384 <            const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[lepvec[i].index]);      
385 <            mithep::Muon * newmu = const_cast<mithep::Muon *>(mu);
386 <            if( recover_typeI_Photon( ctrl, newmu, i, lepvec_i, pfCandidates, electronArr, &Zvec, photonsToVeto ) ) {
387 <              if(ctrl.debug) cout << "FSR TYPEI :: oldpt: " << old_pt_i
388 <                                  << "\tnewpt: " << lepvec_i[i].vec.Pt()
389 <                                  << "\tindex: " << i
567 <                                  << endl;
568 <              //lepvec[i].fsrRecoveryAttempted=true;
569 <            }
570 <            if( recover_typeII_Photon( ctrl, newmu, i, lepvec_i, pfCandidates ) ) {
571 <              if(ctrl.debug) cout << "FSR TYPEII :: oldpt: " << old_pt_i
572 <                                  << "\tnewpt: " << lepvec_i[i].vec.Pt()
573 <                                  << "\tindex: " << i
574 <                                  << endl;
575 <              //lepvec[i].fsrRecoveryAttempted=true;
576 <            }
384 >            const Muon *mu = (Muon*)((*muonArr)[lepvec[i].index]);      
385 >            Muon * newmu = const_cast<Muon *>(mu);
386 >            if( recover_typeI_Photon( ctrl, ret, newmu, i, lepvec_i, pfCandidates, electronArr, &Zvec, photonsToVeto ) )
387 >              if(ctrl.debug) cout << "  FSR TYPEI :: oldpt: " << old_pt_i << "\tnewpt: " << lepvec_i[i].vec.Pt() << "\tindex: " << i << endl;
388 >            if( recover_typeII_Photon( ctrl, ret, newmu, i, lepvec_i, pfCandidates ) )
389 >              if(ctrl.debug) cout << "  FSR TYPEII :: oldpt: " << old_pt_i << "\tnewpt: " << lepvec_i[i].vec.Pt() << "\tindex: " << i << endl;
390            } else {
391 <            const mithep::Electron *el = (mithep::Electron*)((*electronArr)[lepvec[i].index]);      
392 <            mithep::Electron* newel = const_cast<mithep::Electron*>(el);
393 <            if( recover_typeI_Photon( ctrl, newel, i, lepvec_i, pfCandidates, electronArr, &Zvec, photonsToVeto ) ) {
394 <              if(ctrl.debug) cout << "FSR TYPEI :: oldpt: " << old_pt_i
582 <                                  << "\tnewpt: " << lepvec_i[i].vec.Pt()
583 <                                  << "\tindex: " << i
584 <                                  << endl;
585 <              //lepvec[i].fsrRecoveryAttempted=true;
586 <            }
391 >            const Electron *el = (Electron*)((*electronArr)[lepvec[i].index]);      
392 >            Electron* newel = const_cast<Electron*>(el);
393 >            if( recover_typeI_Photon( ctrl, ret, newel, i, lepvec_i, pfCandidates, electronArr, &Zvec, photonsToVeto ) )
394 >              if(ctrl.debug) cout << "  FSR TYPEI :: oldpt: " << old_pt_i << "\tnewpt: " << lepvec_i[i].vec.Pt() << "\tindex: " << i << endl;
395            }
396  
397 <
398 <          cout << "j: " << j << endl;
591 <          mithep::ChargedParticle *cp;
397 >          if(ctrl.debug) cout << "j: " << j << endl;
398 >          ChargedParticle *cp;
399            if( abs(lepvec[j].type) == 13 ) {
400 <            const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[lepvec[j].index]);      
401 <            mithep::Muon * newmu = const_cast<mithep::Muon *>(mu);
402 <            if( recover_typeI_Photon( ctrl, newmu, j, lepvec_j, pfCandidates, electronArr, &Zvec, photonsToVeto ) ) {
403 <              if(ctrl.debug) cout << "FSR TYPEI :: oldpt: " << old_pt_j
404 <                                  << "\tnewpt: " << lepvec_j[j].vec.Pt()
405 <                                  << "\tindex: " << j
599 <                                  << endl;
600 <
601 <              //lepvec[j].fsrRecoveryAttempted=true;
602 <            }
603 <            if( recover_typeII_Photon( ctrl, newmu, j, lepvec_j, pfCandidates ) ) {
604 <              if(ctrl.debug) cout << "FSR TYPEII :: oldpt: " << old_pt_j
605 <                                  << "\tnewpt: " << lepvec_j[j].vec.Pt()
606 <                                  << "\tindex: " << j
607 <                                  << endl;
608 <              //lepvec[j].fsrRecoveryAttempted=true;
609 <            }
400 >            const Muon *mu = (Muon*)((*muonArr)[lepvec[j].index]);      
401 >            Muon * newmu = const_cast<Muon *>(mu);
402 >            if( recover_typeI_Photon( ctrl, ret, newmu, j, lepvec_j, pfCandidates, electronArr, &Zvec, photonsToVeto ) )
403 >              if(ctrl.debug) cout << "  FSR TYPEI :: oldpt: " << old_pt_j << "\tnewpt: " << lepvec_j[j].vec.Pt() << "\tindex: " << j << endl;
404 >            if( recover_typeII_Photon( ctrl, ret, newmu, j, lepvec_j, pfCandidates ) )
405 >              if(ctrl.debug) cout << "  FSR TYPEII :: oldpt: " << old_pt_j << "\tnewpt: " << lepvec_j[j].vec.Pt() << "\tindex: " << j << endl;
406            } else {
407 <            const mithep::Electron *el = (mithep::Electron*)((*electronArr)[lepvec[j].index]);      
408 <            mithep::Electron* newel = const_cast<mithep::Electron*>(el);
409 <            if( recover_typeI_Photon( ctrl, newel, j, lepvec_j, pfCandidates, electronArr, &Zvec, photonsToVeto ) ) {
410 <              if(ctrl.debug) cout << "FSR TYPEI :: oldpt: " << old_pt_j
615 <                                  << "\tnewpt: " << lepvec_j[j].vec.Pt()
616 <                                  << "\tindex: " << j
617 <                                  << endl;
618 <              // lepvec[j].fsrRecoveryAttempted=true;
619 <            }
407 >            const Electron *el = (Electron*)((*electronArr)[lepvec[j].index]);      
408 >            Electron* newel = const_cast<Electron*>(el);
409 >            if( recover_typeI_Photon( ctrl, ret, newel, j, lepvec_j, pfCandidates, electronArr, &Zvec, photonsToVeto ) )
410 >              if(ctrl.debug) cout << "  FSR TYPEI :: oldpt: " << old_pt_j << "\tnewpt: " << lepvec_j[j].vec.Pt() << "\tindex: " << j << endl;
411            }
412  
413            //
414            // now fix isolation
415            //
625
416            if( abs(lepvec[i].type) == 11 ) {
417 <            const mithep::Electron *el = (mithep::Electron*)((*electronArr)[lepvec_i[i].index]);      
417 >            const Electron *el = (Electron*)((*electronArr)[lepvec_i[i].index]);      
418              lepvec_i[i].status |=
419                (*ElectronIsoSelector)(ctrl,el,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);      
420  
421            } else {
422 <            const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[lepvec_i[i].index]);      
422 >            const Muon *mu = (Muon*)((*muonArr)[lepvec_i[i].index]);      
423              lepvec_i[i].status |=
424                (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);  
425            }
426            updateSimpleLepton(lepvec_i[i]);
427  
428            if( abs(lepvec[j].type) == 11 ) {
429 <            const mithep::Electron *el = (mithep::Electron*)((*electronArr)[lepvec_j[j].index]);      
429 >            const Electron *el = (Electron*)((*electronArr)[lepvec_j[j].index]);      
430              lepvec_j[j].status |=
431                (*ElectronIsoSelector)(ctrl,el,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);      
432            } else {
433 <            const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[lepvec_j[j].index]);      
433 >            const Muon *mu = (Muon*)((*muonArr)[lepvec_j[j].index]);      
434              lepvec_j[j].status |=
435                (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);  
436            }
# Line 649 | Line 439 | EventData apply_HZZ4L_reference_selectio
439            float new_M    =   (lepvec_i[i].vec+lepvec_j[j].vec).M();
440            float new_pt_i = lepvec_i[i].vec.Pt();
441            float new_pt_j = lepvec_j[j].vec.Pt();
442 <          if( ctrl.debug ) {
443 <            cout << "\toldM: " << old_M << "\tnewM:" << new_M << endl;
444 <            cout << "\told_pt_i: " << old_pt_i << "\tnew_pt_i:" << new_pt_i << endl;
445 <            cout << "\told_pt_j: " << old_pt_j << "\tnew_pt_j:" << new_pt_j << endl;
442 >          if( ctrl.debug ) {
443 >            cout << "  ----> post FSR Z:";
444 >            cout << "      oldM: " << old_M << "\tnewM:" << new_M << endl;
445 >            cout << "      old_pt_i: " << old_pt_i << "\tnew_pt_i:" << new_pt_i << endl;
446 >            cout << "      old_pt_j: " << old_pt_j << "\tnew_pt_j:" << new_pt_j << endl;
447            }
448            
449          } // doFSR
450 <        
451 <
452 <        if( !(lepvec_i[i].status.loose()) || !(lepvec_j[j].status.loose()) ) continue;    
453 <        ZCandidates.push_back(std::pair<int,int> (i,j) );
454 <        ZCandidatesLeptons.push_back(std::pair<SimpleLepton,SimpleLepton> (lepvec_i[i],lepvec_j[j]) );
450 >          
451 >        if( !(lepvec_i[i].status.loose()) || !(lepvec_j[j].status.loose()) ) {
452 >          if(ctrl.debug) {
453 >            bitset<16> tmpbits_i(lepvec_i[i].status.getStatus()),tmpbits_j(lepvec_j[j].status.getStatus());
454 >            cout << "  leptons fail selection (i: " << tmpbits_i << ", j: " << tmpbits_j << ")" << endl;
455 >          }
456 >          continue;
457 >        }
458 >        ZCandidates.push_back(pair<int,int> (i,j) );
459 >        ZCandidatesLeptons.push_back(pair<SimpleLepton,SimpleLepton> (lepvec_i[i],lepvec_j[j]) );
460          if( ctrl.debug ) cout << "Z candidate ("<< i << "," << j << ")"
461                                << "\tmass: " << (lepvec_i[i].vec+lepvec_j[j].vec).M() << endl;
462        }
463      }
464      if( ZCandidates.size() > 0 ) {
465        ret.status.selectionBits.flip(PASS_ZCANDIDATE);
466 <      if( ctrl.debug ) cout << "event has >0  Z candidates" << endl;
671 <      cutvec[PASS_ZCANDIDATE] +=1;
466 >      if( ctrl.debug ) cout << "event has >0  Z candidates (" << ZCandidates.size() << " of em)" << endl;
467      } else {
468        ret.status.setStatus(SelectionStatus::FAIL);
469        return ret;
# Line 700 | Line 495 | EventData apply_HZZ4L_reference_selectio
495  
496      cout << "best mZ1:  " << best_Z1_mass << " from ("  <<
497        ZCandidates[best_Z1_index].first << "," << ZCandidates[best_Z1_index].second << ")" << endl;
703    int Z1type;
704    if( abs(ret.Z1leptons[0].type) == 11 ) Z1type=0;
705    else Z1type=1;
706    zcutvec[Z1type][PASS_ZCANDIDATE] +=1;
707
498  
499      //******************************************************************************
500      // Step 6.3 : require Z1 with  40<m<120
501      //******************************************************************************
502      if( Z1vec.M() > 40. && Z1vec.M() < 120. ) {
503        ret.status.selectionBits.flip(PASS_GOODZ1);
714      cutvec[PASS_GOODZ1] +=1;
715      zcutvec[Z1type][PASS_GOODZ1] +=1;
504      } else {
505        ret.status.setStatus(SelectionStatus::FAIL);
506        return ret;
# Line 724 | Line 512 | EventData apply_HZZ4L_reference_selectio
512      if( lepvec.size() >= 4 ) {
513        if( ctrl.debug) cout << "pass4L: "  << info->EvtNum() << endl;
514        ret.status.selectionBits.flip(PASS_4L);
727      cutvec[PASS_4L] +=1;
728      zcutvec[Z1type][PASS_4L] +=1;
515      } else {
516        ret.status.setStatus(SelectionStatus::FAIL);
517        return ret;
# Line 735 | Line 521 | EventData apply_HZZ4L_reference_selectio
521        if(abs(lepvec[i].type) == 11 ) nEl++;
522        if(abs(lepvec[i].type) == 13 ) nMu++;
523      }
738    if( nEl >= 4 )       zzcutvec[0][PASS_4L] +=1;
739    else if( nMu >= 4 )  zzcutvec[1][PASS_4L] +=1;
740    else                 zzcutvec[2][PASS_4L] +=1;
524  
525      //********************************************************
526      // Step 5: ZZ candidates
527      //********************************************************
528      int nZZCandidates=0;
529 <    std::vector<std::pair<int,int> > ZZCandidates;
529 >    vector<pair<int,int> > ZZCandidates;
530      int Z2type;
531 +    if(ctrl.debug) cout << "looping over " << ZCandidates.size() << " Z candidates: " << endl;
532      for(int z2index=0; z2index<ZCandidates.size(); ++z2index) {
533        int z1index = best_Z1_index;
534 <      if ( z2index == z1index ) continue;
535 <      if( ZCandidates[z1index].first  == ZCandidates[z2index].first )   continue;
536 <      if( ZCandidates[z1index].first  == ZCandidates[z2index].second )  continue;
537 <      if( ZCandidates[z1index].second == ZCandidates[z2index].first )   continue;
538 <      if( ZCandidates[z1index].second == ZCandidates[z2index].second )  continue;
755 <
756 <      //ghost removal
757 <      if(mithep::MathUtils::DeltaR(ZCandidatesLeptons[z1index].first.vec.Phi(),ZCandidatesLeptons[z1index].first.vec.Eta(),ZCandidatesLeptons[z2index].first.vec.Phi(),ZCandidatesLeptons[z2index].first.vec.Eta()) < 0.02) continue;
758 <      if(mithep::MathUtils::DeltaR(ZCandidatesLeptons[z1index].first.vec.Phi(),ZCandidatesLeptons[z1index].first.vec.Eta(),ZCandidatesLeptons[z2index].second.vec.Phi(),ZCandidatesLeptons[z2index].second.vec.Eta()) < 0.02) continue;
759 <      if(mithep::MathUtils::DeltaR(ZCandidatesLeptons[z1index].second.vec.Phi(),ZCandidatesLeptons[z1index].second.vec.Eta(),ZCandidatesLeptons[z2index].first.vec.Phi(),ZCandidatesLeptons[z2index].first.vec.Eta()) < 0.02) continue;
760 <      if(mithep::MathUtils::DeltaR(ZCandidatesLeptons[z1index].second.vec.Phi(),ZCandidatesLeptons[z1index].second.vec.Eta(),ZCandidatesLeptons[z2index].second.vec.Phi(),ZCandidatesLeptons[z2index].second.vec.Eta()) < 0.02) continue;
534 >      if ( z2index == z1index )                                         { if(ctrl.debug) cout << "  Z2 candidate failing z2i = z1i" << endl; continue; }
535 >      if( ZCandidates[z1index].first  == ZCandidates[z2index].first )   { if(ctrl.debug) cout << "  Z2 candidate failing icheck1" << endl; continue; }
536 >      if( ZCandidates[z1index].first  == ZCandidates[z2index].second )  { if(ctrl.debug) cout << "  Z2 candidate failing icheck2" << endl; continue; }
537 >      if( ZCandidates[z1index].second == ZCandidates[z2index].first )   { if(ctrl.debug) cout << "  Z2 candidate failing icheck3" << endl; continue; }
538 >      if( ZCandidates[z1index].second == ZCandidates[z2index].second )  { if(ctrl.debug) cout << "  Z2 candidate failing icheck4" << endl; continue; }
539  
540 <      ZZCandidates.push_back(std::pair<int,int> (z1index,z2index));
763 <      //      Z2type = abs(lepvec[ZCandidates[z2index].first].type);
540 >      ZZCandidates.push_back(pair<int,int> (z1index,z2index));
541        Z2type = abs(ZCandidatesLeptons[z2index].first.type);
542      }
543      if( ZZCandidates.size() > 0 ) {
767
544        if( ctrl.debug) cout << "passZZ: "  << info->EvtNum() << endl;
545        ret.status.selectionBits.flip(PASS_ZZCANDIDATE);
770      cutvec[PASS_ZZCANDIDATE] +=1;
546        if( ZZCandidates.size() > 1 ) Z2type=999;
547        if( ctrl.debug ) cout << "nZZcandidates: " << ZZCandidates.size() << endl;
548 <      //      if( ctrl.debug ) {
549 <      cout << "evt:  " << info->EvtNum() << "\tnZZcandidates: " << ZZCandidates.size()
550 <           << "\tZ1f: " << abs(ret.Z1leptons[0].type) << "\tZ2f: " << Z2type << endl;
551 <      cout << "-------------------------------------------------------" << endl;
548 >      if( ctrl.debug ) {
549 >        cout << "evt:  " << info->EvtNum() << "\tnZZcandidates: " << ZZCandidates.size()
550 >             << "\tZ1f: " << abs(ret.Z1leptons[0].type) << "\tZ2f: " << Z2type << endl;
551 >        cout << "------------------------------------------------------- ( un-fsrd )" << endl;
552          for( int l=0; l<lepvec.size(); l++ ) lepvec[l].print();
553          cout << "-------------------------------------------------------" << endl;
554 <        //      }
554 >      }
555      } else {
556        ret.status.setStatus(SelectionStatus::FAIL);
557        return ret;
# Line 789 | Line 564 | EventData apply_HZZ4L_reference_selectio
564      float best_Z2_pt = -1.;
565      for( int i=0; i<ZZCandidates.size(); i++ ) {
566        int z2index = ZZCandidates[i].second;
792      //       TLorentzVector Z2 = (lepvec[ZCandidates[z2index].first].vec) +
793      //        (lepvec[ZCandidates[z2index].second].vec);
567        TLorentzVector Z2 = (ZCandidatesLeptons[z2index].first.vec) +
568          (ZCandidatesLeptons[z2index].second.vec);
569        if( Z2.Pt() > best_Z2_pt ) {
# Line 807 | Line 580 | EventData apply_HZZ4L_reference_selectio
580      int theZ1type = abs(ZCandidatesLeptons[best_Z1_index].first.type);
581      int theZ2type = abs(ZCandidatesLeptons[best_Z2_index].first.type);
582  
583 <    cout << "best mZ2:  " << (ret.Z2leptons[0].vec+ret.Z2leptons[1].vec).M()  << endl;
584 <    int ZZtype;
585 <    if( Z1type == 0 && abs(ret.Z2leptons[0].type) == 11 ) ZZtype=0;
813 <    else if ( Z1type == 1 && abs(ret.Z2leptons[0].type) == 13 ) ZZtype=1;
814 <    else ZZtype=2;
815 <    zzcutvec[ZZtype][PASS_ZZCANDIDATE] += 1;
583 >    if(ctrl.debug) cout << "best mZ2:  " << (ret.Z2leptons[0].vec+ret.Z2leptons[1].vec).M() << " from ("
584 >                        << ZCandidates[best_Z2_index].first << "," << ZCandidates[best_Z2_index].second << ")" << endl;
585 >
586      increment("sfOsHiPt",theZ1type,theZ2type);
587  
588 <    if(ctrl.debug)cout << "ZZ :: evt: " << info->EvtNum()
589 <                       << "\tmZ1: " << (ret.Z1leptons[0].vec+ret.Z1leptons[1].vec).M()  
590 <                       << "\tmZ2: " << (ret.Z2leptons[0].vec+ret.Z2leptons[1].vec).M()  
591 <                       << endl;
588 >    if(ctrl.debug) cout << "ZZ :: evt: " << info->EvtNum()
589 >                        << "\tmZ1: " << (ret.Z1leptons[0].vec+ret.Z1leptons[1].vec).M()  
590 >                        << "\tmZ2: " << (ret.Z2leptons[0].vec+ret.Z2leptons[1].vec).M()  
591 >                        << endl;
592 >
593  
594      //******************************************************************************
595      // Step 6.4 : require Z2 with  4<m<120
# Line 827 | Line 598 | EventData apply_HZZ4L_reference_selectio
598        (ZCandidatesLeptons[best_Z2_index].second.vec);
599      if( Z2vec.M() > 4 && Z2vec.M() < 120 ) {
600        ret.status.selectionBits.flip(PASS_GOODZ2);
830      cutvec[PASS_GOODZ2] +=1;
831      zzcutvec[ZZtype][PASS_GOODZ2] += 1;
601        increment("4<mZ2<120",theZ1type,theZ2type);
602      } else {
603        ret.status.setStatus(SelectionStatus::FAIL);
604        return ret;
605      }
606  
607 +
608      //******************************************************************************
609      // Step 6.1 : any two leptons 20/10
610      //******************************************************************************
# Line 850 | Line 620 | EventData apply_HZZ4L_reference_selectio
620      }
621      if( nlep_above_10 > 1 && nlep_above_20 > 0 ) {
622        ret.status.selectionBits.flip(PASS_ZZ_20_10);
853      cutvec[PASS_ZZ_20_10] +=1;
854      zzcutvec[ZZtype][PASS_ZZ_20_10] += 1;
623        increment("pt>20,10",theZ1type,theZ2type);
624        if( ctrl.debug ) cout << "passess 20/10 ..." << endl;
625      } else {
# Line 859 | Line 627 | EventData apply_HZZ4L_reference_selectio
627        return ret;
628      }
629      
630 +    
631 +
632 +
633      //******************************************************************************
634      // Step 6.5 : resonance killing (4/4)
635      //******************************************************************************
# Line 866 | Line 637 | EventData apply_HZZ4L_reference_selectio
637      for( int i=0; i<zzleptons.size(); i++ ) {
638        for( int j=i+1; j<zzleptons.size(); j++ ) {
639          if( zzleptons[i].charge == zzleptons[j].charge ) continue; // 4/4
640 <        if( (zzleptons[i].vec+zzleptons[j].vec).M() < 4. ) {
640 >        if( (zzleptons[i].vec+zzleptons[j].vec).M() <= 4. ) {
641            resonance = true;
642            break;
643          }
# Line 874 | Line 645 | EventData apply_HZZ4L_reference_selectio
645      }
646      if( !resonance ) {
647        ret.status.selectionBits.flip(PASS_RESONANCE);
877      cutvec[PASS_RESONANCE] +=1;
878      zzcutvec[ZZtype][PASS_RESONANCE] += 1;
648        increment("mll>4",theZ1type,theZ2type);
649        if( ctrl.debug ) cout << "\tpasses resonance killing ... " << endl;
650      } else {
651        ret.status.setStatus(SelectionStatus::FAIL);
652        return ret;
653 <    }    
653 >    }
654 >    
655 >    
656      
657      //******************************************************************************
658      // Step 6.6 : m(4l) > 70 , m(4l) > 100
# Line 891 | Line 662 | EventData apply_HZZ4L_reference_selectio
662        (ZCandidatesLeptons[best_Z2_index].first.vec) +
663        (ZCandidatesLeptons[best_Z2_index].second.vec);
664      
665 +    if(ctrl.debug)
666 +      cout << "forming zz from: "
667 +           << setw(9) << (ZCandidatesLeptons[best_Z1_index].first.vec).Pt()
668 +           << setw(9) << (ZCandidatesLeptons[best_Z1_index].second.vec).Pt()
669 +           << setw(9) << (ZCandidatesLeptons[best_Z2_index].first.vec).Pt()
670 +           << setw(9) << (ZCandidatesLeptons[best_Z2_index].second.vec).Pt() << endl;
671 +
672      if( zzvec.M() > 70. ) {
673        if(ctrl.debug) cout << "passes mzz > 70, mzz: " << zzvec.M() << endl;
674        ret.status.selectionBits.flip(PASS_m4l_GT_70);
897      cutvec[PASS_m4l_GT_70] +=1;
898      zzcutvec[ZZtype][PASS_m4l_GT_70] += 1;
675        increment("m4l>70",theZ1type,theZ2type);
676      } else {
677        ret.status.setStatus(SelectionStatus::FAIL);
678        return ret;
679      }
680 <    
681 <    if( zzvec.M() > 70. &&  (ret.Z2leptons[0].vec+ret.Z2leptons[1].vec).M() > 12) {
682 <      if(ctrl.debug) cout << "passes mzz > 70, mzz: " << zzvec.M() << "\t mZ2 > 12" << endl;
683 <      ret.status.selectionBits.flip(PASS_m4l_GT_100);
908 <      increment("m4l>70,mZ2>12",theZ1type,theZ2type);
680 >
681 >    if( (ret.Z2leptons[0].vec+ret.Z2leptons[1].vec).M() > 12 ){
682 >      if(ctrl.debug) cout << "passes mZ2 > 12" << endl;
683 >      increment("mZ2>12",theZ1type,theZ2type);
684      } else {
685        ret.status.setStatus(SelectionStatus::FAIL);
686        return ret;
687      }
688  
689 <    if( zzvec.M() > 100. &&  (ret.Z2leptons[0].vec+ret.Z2leptons[1].vec).M() > 12) {
690 <      if(ctrl.debug) cout << "passes mzz > 100, mzz: " << zzvec.M() << "\t mZ2 > 12" << endl;
691 <      cutvec[PASS_m4l_GT_100] +=1;
692 <      zzcutvec[ZZtype][PASS_m4l_GT_100] += 1;
693 <      increment("m4l>100,mZ2>12",theZ1type,theZ2type);
694 <    }
689 >    if( zzvec.M() > 100 ) {
690 >      if(ctrl.debug) cout << "passes mzz > 100, mzz: " << zzvec.M() << endl;
691 >      increment("m4l>100",theZ1type,theZ2type);
692 >    } else {
693 >      cout << "NOTE: failed m4l>100 (" << zzvec.M() << "), but saving to ntuple anyway" << endl;
694 >    }
695  
696      //***************************************************************
697      // finish
# Line 928 | Line 703 | EventData apply_HZZ4L_reference_selectio
703          (ZCandidatesLeptons[best_Z2_index].second.vec);
704      TLorentzVector theZZ = theZ1 + theZ2;
705      
706 +    if(ret.fsrPhotons.size() > 0) {
707 +      if(ctrl.debug)
708 +        cout << "  fsr photon! pt: "
709 +             << setw(12) << ret.fsrPhotons[0].vec.Pt()
710 +             << " eta: " << setw(12) << ret.fsrPhotons[0].vec.Eta()
711 +             << " phi: " << setw(12) << ret.fsrPhotons[0].vec.Phi() << endl;
712 +    }
713 +    if(ret.fsrPhotons.size() > 1) {
714 +      if(ctrl.debug)
715 +        cout << "  fsr photon! pt: "
716 +             << setw(12) << ret.fsrPhotons[1].vec.Pt()
717 +             << " eta: " << setw(12) << ret.fsrPhotons[1].vec.Eta()
718 +             << " phi: " << setw(12) << ret.fsrPhotons[1].vec.Phi() << endl;
719 +    }
720      if( ctrl.debug ) cout  << "run: " << info->RunNum()  
721                             << "\tevt: " << info->EvtNum()
722                             << "\tZ1channel: " << theZ1type
# Line 935 | Line 724 | EventData apply_HZZ4L_reference_selectio
724                             << "\tmZ1: " << theZ1.M()
725                             << "\tmZ2: " << theZ2.M()
726                             << "\tm4l: " << theZZ.M()
938                           << "\tevtfail: " << hex << evtfail << dec
939      //                           << "\ttrigbits: " << hex << info->triggerBits << dec
940      //              << "\ttree: " << inputFiles[q][f]
727                             << endl;
728      
729 <    if( !evtfail ) {
944 <      ret.status.setStatus(SelectionStatus::EVTPASS);
945 <      // already done ..
946 <      //       ret.Z1leptons.push_back(lepvec[ZCandidates[best_Z1_index].first]);
947 <      //       ret.Z1leptons.push_back(lepvec[ZCandidates[best_Z1_index].second]);
948 <      //       ret.Z2leptons.push_back(lepvec[ZCandidates[best_Z2_index].first]);
949 <      //       ret.Z2leptons.push_back(lepvec[ZCandidates[best_Z2_index].second]);
950 <    }
729 >    ret.status.setStatus(SelectionStatus::EVTPASS);
730      
731      return ret;
732   }
954 //--------------------------------------------------------------------------------------------------
955 void fillVetoArrays( ControlFlags & ctrl,
956                     const mithep::Array<mithep::Muon> *muonArr,    
957                     vector< const mithep::Muon*>     & muonsToVeto,
958                     const mithep::Array<mithep::Electron> *electronArr,    
959                     vector< const mithep::Electron*> & electronsToVeto,
960                     const mithep::Vertex * vtx )
961 //--------------------------------------------------------------------------------------------------
962 {
963
964  if( ctrl.debug ) cout << "looping for isolation ..." << endl;
965  /*
966  for(int i=0; i<muonArr->GetEntries(); i++)
967    {
968      const mithep::Muon *mu = (const mithep::Muon*)((*muonArr)[i]);      
969      SelectionStatus musel;
970      //      musel |= muonCutBasedVeto(ctrl,mu,vtx);
971      musel |= muonDummyVeto(ctrl,mu,vtx);
972      if( !(musel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
973      if(ctrl.debug) cout << "pushing mu for isol veto ... " << endl;
974      muonsToVeto.push_back( mu );
975    }
976  */
977  for(int i=0; i<electronArr->GetEntries(); i++)
978    {
979      const mithep::Electron *ele = (const mithep::Electron*)((*electronArr)[i]);      
980      SelectionStatus esel;
981      //      esel |= electronCutBasedVeto(ctrl,ele,vtx);
982      esel |= electronDummyVeto(ctrl,ele,vtx);
983      if( !(esel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
984      if(ctrl.debug) cout << "pushing ele for isol veto ... " << endl;
985      electronsToVeto.push_back( ele );
986    }
987  if( ctrl.debug ) cout << "done selecting for isolation veto ..." << endl << endl;;
988 }
989
990
991
992
733   //----------------------------------------------------------------------------
734   void updateSimpleLepton(SimpleLepton &tmplep)
735   //----------------------------------------------------------------------------
736   {
997  tmplep.isoPF04   = tmplep.status.isoPF04;
998  tmplep.chisoPF04 = tmplep.status.chisoPF04;
999  tmplep.gaisoPF04 = tmplep.status.gaisoPF04;
1000  tmplep.neisoPF04 = tmplep.status.neisoPF04;
737    tmplep.isTight = tmplep.status.tight();
738    tmplep.isLoose = tmplep.status.loose();
1003  //  tmplep.fsrRecoveryAttempted = true;
739   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines