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

Comparing UserCode/MitHzz4l/LeptonSelection/src/IsolationSelection.cc (file contents):
Revision 1.20 by khahn, Mon May 14 18:01:02 2012 UTC vs.
Revision 1.35 by dkralph, Mon Dec 17 17:12:27 2012 UTC

# Line 9 | Line 9
9   #include "ElectronTools.h"
10   #include "ElectronIDMVA.h"
11  
12 < using namespace mithep;
13 <
14 < mithep::MuonIDMVA     * muIsoMVA;
15 < mithep::MuonTools       muT;
16 < mithep::ElectronIDMVA * eleIsoMVA;
17 < mithep::ElectronTools   eleT;
12 > MuonIDMVA     * muIsoMVA;
13 > MuonTools       muT;
14 > ElectronIDMVA * eleIsoMVA;
15 > ElectronTools   eleT;
16  
17   // global hack to sync
18   double gChargedIso;
# Line 24 | Line 22 | double gNeutralIso;
22   extern vector<bool> PFnoPUflag;
23  
24   //--------------------------------------------------------------------------------------------------
25 < Float_t computePFMuonIso(const mithep::Muon *muon,
26 <                         const mithep::Vertex & vtx,
27 <                         const mithep::Array<mithep::PFCandidate> * fPFCandidates,
25 > Float_t computePFMuonIso(const Muon *muon,
26 >                         const Vertex * vtx,
27 >                         const Array<PFCandidate> * fPFCandidates,
28                           const Double_t dRMax)
29   //--------------------------------------------------------------------------------------------------
30   {
# Line 34 | Line 32 | Float_t computePFMuonIso(const mithep::M
32    const Double_t neuPtMin = 1.0;
33    const Double_t dzMax    = 0.1;
34      
35 <  Double_t zLepton = (muon->BestTrk()) ? muon->BestTrk()->DzCorrected(vtx) : 0.0;
35 >  Double_t zLepton = (muon->BestTrk()) ? muon->BestTrk()->DzCorrected(*vtx) : 0.0;
36    
37    Float_t iso=0;
38    for(UInt_t ipf=0; ipf<fPFCandidates->GetEntries(); ipf++) {
# Line 46 | Line 44 | Float_t computePFMuonIso(const mithep::M
44      if(pfcand->TrackerTrk() && muon->TrackerTrk() && (pfcand->TrackerTrk()==muon->TrackerTrk())) continue;
45      
46      // dz cut
47 <    Double_t dz = (pfcand->BestTrk()) ? fabs(pfcand->BestTrk()->DzCorrected(vtx) - zLepton) : 0;
47 >    Double_t dz = (pfcand->BestTrk()) ? fabs(pfcand->BestTrk()->DzCorrected(*vtx) - zLepton) : 0;
48      if(dz >= dzMax) continue;
49      
50      // check iso cone
# Line 59 | Line 57 | Float_t computePFMuonIso(const mithep::M
57   }
58  
59   //--------------------------------------------------------------------------------------------------
60 < Float_t computePFEleIso(const mithep::Electron *electron,
61 <                        const mithep::Vertex & fVertex,
62 <                        const mithep::Array<mithep::PFCandidate> * fPFCandidates,
60 > Float_t computePFEleIso(const Electron *electron,
61 >                        const Vertex * fVertex,
62 >                        const Array<PFCandidate> * fPFCandidates,
63                          const Double_t dRMax)
64   //--------------------------------------------------------------------------------------------------
65   {
# Line 69 | Line 67 | Float_t computePFEleIso(const mithep::El
67    const Double_t neuPtMin = 1.0;
68    const Double_t dzMax    = 0.1;
69      
70 <  Double_t zLepton = (electron->BestTrk()) ? electron->BestTrk()->DzCorrected(fVertex) : 0.0;
70 >  Double_t zLepton = (electron->BestTrk()) ? electron->BestTrk()->DzCorrected(*fVertex) : 0.0;
71    
72    Float_t iso=0;
73    for(UInt_t ipf=0; ipf<fPFCandidates->GetEntries(); ipf++) {
# Line 78 | Line 76 | Float_t computePFEleIso(const mithep::El
76      if(!pfcand->HasTrk() && (pfcand->Pt()<=neuPtMin)) continue;  // pT cut on neutral particles
77      
78      // dz cut
79 <    Double_t dz = (pfcand->BestTrk()) ? fabs(pfcand->BestTrk()->DzCorrected(fVertex) - zLepton) : 0;
79 >    Double_t dz = (pfcand->BestTrk()) ? fabs(pfcand->BestTrk()->DzCorrected(*fVertex) - zLepton) : 0;
80      if(dz >= dzMax) continue;
81      
82      // remove THE electron
# Line 101 | Line 99 | Float_t computePFEleIso(const mithep::El
99    
100    return iso;
101   };
104
105 //--------------------------------------------------------------------------------------------------
106 bool pairwiseIsoSelection( ControlFlags &ctrl,
107                           vector<SimpleLepton> &lepvec,
108                           float rho )
109 //--------------------------------------------------------------------------------------------------
110 {
111
112  bool passiso=true;
113
114  for( int i=0; i<lepvec.size(); i++ )
115    {
116      
117      if( !(lepvec[i].is4l) ) continue;
118      
119      float effArea_ecal_i, effArea_hcal_i;
120      if( lepvec[i].isEB ) {
121        if( lepvec[i].type == 11 ) {
122          effArea_ecal_i = 0.101;
123          effArea_hcal_i = 0.021;
124        } else {
125          effArea_ecal_i = 0.074;
126          effArea_hcal_i = 0.022;
127        }
128      } else {
129        if( lepvec[i].type == 11 ) {
130          effArea_ecal_i = 0.046;
131          effArea_hcal_i = 0.040;
132        } else {
133          effArea_ecal_i = 0.045;
134          effArea_hcal_i = 0.030;
135        }
136      }
137      
138      float isoEcal_corr_i = lepvec[i].isoEcal - (effArea_ecal_i*rho);
139      float isoHcal_corr_i = lepvec[i].isoHcal - (effArea_hcal_i*rho);
140
141      for( int j=i+1; j<lepvec.size(); j++ )
142        {
143
144          if( !(lepvec[j].is4l) ) continue;
145
146          float effArea_ecal_j, effArea_hcal_j;
147          if( lepvec[j].isEB ) {
148            if( lepvec[j].type == 11 ) {
149              effArea_ecal_j = 0.101;
150              effArea_hcal_j = 0.021;
151            } else {
152              effArea_ecal_j = 0.074;
153              effArea_hcal_j = 0.022;
154            }
155          } else {
156            if( lepvec[j].type == 11 ) {
157              effArea_ecal_j = 0.046;
158              effArea_hcal_j = 0.040;
159            } else {
160              effArea_ecal_j = 0.045;
161              effArea_hcal_j = 0.030;
162            }
163          }
164
165          float isoEcal_corr_j = lepvec[j].isoEcal - (effArea_ecal_j*rho);
166          float isoHcal_corr_j = lepvec[j].isoHcal - (effArea_hcal_j*rho);
167          float RIso_i = (lepvec[i].isoTrk+isoEcal_corr_i+isoHcal_corr_i)/lepvec[i].vec.Pt();
168          float RIso_j = (lepvec[j].isoTrk+isoEcal_corr_j+isoHcal_corr_j)/lepvec[j].vec.Pt();      
169          float comboIso = RIso_i + RIso_j;
170          
171          if( comboIso > 0.35 ) {
172            if( ctrl.debug ) cout << "combo failing for indices: " << i << "," << j << endl;
173            passiso = false;
174            return passiso;
175          }
176        }
177    }
178  
179  return passiso;
180 }
181
102   //--------------------------------------------------------------------------------------------------
103   SelectionStatus muonIsoSelection(ControlFlags &ctrl,
104 <                                 const mithep::Muon * mu,
105 <                                 const mithep::Vertex & vtx,
106 <                                 const mithep::Array<mithep::PFCandidate> * fPFCandidateCol   )
104 >                                 const Muon * mu,
105 >                                 const Vertex * vtx,
106 >                                 const Array<PFCandidate> * fPFCandidateCol   )
107   //--------------------------------------------------------------------------------------------------
108   {
109    float reliso = computePFMuonIso(mu,vtx,fPFCandidateCol,0.3)/mu->Pt();
# Line 211 | Line 131 | SelectionStatus muonIsoSelection(Control
131  
132   //--------------------------------------------------------------------------------------------------
133   SelectionStatus electronIsoSelection(ControlFlags &ctrl,
134 <                                     const mithep::Electron * ele,
135 <                                     const mithep::Vertex &fVertex,
136 <                                     const mithep::Array<mithep::PFCandidate> * fPFCandidates)
134 >                                     const Electron * ele,
135 >                                     const Vertex *fVertex,
136 >                                     const Array<PFCandidate> * fPFCandidates)
137   //--------------------------------------------------------------------------------------------------
138   {
139  
# Line 227 | Line 147 | SelectionStatus electronIsoSelection(Con
147    if( ele->IsEB() && ele->Pt() < 20 && reliso > PFISO_ELE_LOOSE_EB_LOWPT ) {
148      failiso = true;
149    }
230  if(ctrl.debug) cout << "before iso check ..." << endl;
150    if( !(ele->IsEB()) && ele->Pt() > 20 && reliso > PFISO_ELE_LOOSE_EE_HIGHPT ) {
232    if(ctrl.debug) cout << "\tit fails ..." << endl;
151      failiso = true;
152    }
153    if( !(ele->IsEB()) && ele->Pt() < 20 && reliso > PFISO_ELE_LOOSE_EE_LOWPT ) {
# Line 254 | Line 172 | bool noIso(ControlFlags &, vector<Simple
172  
173   //--------------------------------------------------------------------------------------------------
174   SelectionStatus muonIsoMVASelection(ControlFlags &ctrl,
175 <                                    const mithep::Muon * mu,
176 <                                    const mithep::Vertex & vtx,
177 <                                    const mithep::Array<mithep::PFCandidate> * fPFCandidates,
178 <                                    const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
179 <                                    mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
180 <                                    vector<const mithep::Muon*> muonsToVeto,
181 <                                    vector<const mithep::Electron*> electronsToVeto)
175 >                                    const Muon * mu,
176 >                                    const Vertex * vtx,
177 >                                    const Array<PFCandidate> * fPFCandidates,
178 >                                    const Array<PileupEnergyDensity> * fPUEnergyDensity,
179 >                                    MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
180 >                                    vector<const Muon*> muonsToVeto,
181 >                                    vector<const Electron*> electronsToVeto)
182   //--------------------------------------------------------------------------------------------------
183   {
184  
185    if( ctrl.debug ) {
186      cout << "muonIsoMVASelection :: muons to veto " << endl;
187      for( int i=0; i<muonsToVeto.size(); i++ ) {
188 <      const mithep::Muon * vmu = muonsToVeto[i];
188 >      const Muon * vmu = muonsToVeto[i];
189        cout << "\tpt: " << vmu->Pt()
190             << "\teta: " << vmu->Eta()
191             << "\tphi: " << vmu->Phi()
# Line 275 | Line 193 | SelectionStatus muonIsoMVASelection(Cont
193      }
194      cout << "muonIsoMVASelection :: electrson to veto " << endl;
195      for( int i=0; i<electronsToVeto.size(); i++ ) {
196 <      const mithep::Electron * vel = electronsToVeto[i];
196 >      const Electron * vel = electronsToVeto[i];
197        cout << "\tpt: " << vel->Pt()
198             << "\teta: " << vel->Eta()
199             << "\tphi: " << vel->Phi()
# Line 339 | Line 257 | SelectionStatus muonIsoMVASelection(Cont
257    //Loop over PF Candidates
258    //
259    for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
260 <    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
260 >
261 >    if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
262 >
263 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
264  
265      Double_t deta = (mu->Eta() - pf->Eta());
266 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
267 <    Double_t dr = mithep::MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
268 <    if (dr > 0.5) continue;
348 <    if (dr < 0.01) continue;
266 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
267 >    Double_t dr = MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
268 >    if (dr > 1.0) continue;
269  
270      if (pf->HasTrackerTrk() && (pf->TrackerTrk() == mu->TrackerTrk()) ) continue;
271  
# Line 359 | Line 279 | SelectionStatus muonIsoMVASelection(Cont
279        // Check for electrons
280        //
281        for (Int_t q=0; q < electronsToVeto.size(); ++q) {
282 <        const mithep::Electron *tmpele = electronsToVeto[q];
282 >        const Electron *tmpele = electronsToVeto[q];
283          // 4l electron
284          if( pf->HasTrackerTrk() ) {
285            if( pf->TrackerTrk() == tmpele->TrackerTrk() )
# Line 371 | Line 291 | SelectionStatus muonIsoMVASelection(Cont
291          }
292          // PF charged
293          if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) >= 1.479
294 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015)
294 >            && MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015)
295            IsLeptonFootprint = kTRUE;
296          // PF gamma
297          if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) >= 1.479
298 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08)
298 >            && MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08)
299            IsLeptonFootprint = kTRUE;
300        } // loop over electrons
301        
302 <      /*
302 >      /* KH - commented for sync
303        //
304        // Check for muons
305        //
306        for (Int_t q=0; q < muonsToVeto.size(); ++q) {
307 <        const mithep::Muon *tmpmu = muonsToVeto[q];
307 >        const Muon *tmpmu = muonsToVeto[q];
308          // 4l muon
309          if( pf->HasTrackerTrk() ) {
310            if( pf->TrackerTrk() == tmpmu->TrackerTrk() )
311              IsLeptonFootprint = kTRUE;
312          }
313          // PF charged
314 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01)
314 >        if (pf->Charge() != 0 && MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01)
315            IsLeptonFootprint = kTRUE;
316        } // loop over muons
317        */
# Line 413 | Line 333 | SelectionStatus muonIsoMVASelection(Cont
333   //                            << abs(pf->TrackerTrk()->DzCorrected(vtx)) << " "
334   //                            << dr << endl;
335   //       }
336 <
336 > //       if( pf->HasGsfTrk() ) {
337 > //      if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
338 > //      if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
339 > //                            << abs(pf->GsfTrk()->DzCorrected(vtx)) << " "
340 > //                            << dr << endl;
341 > //       }
342  
343        // Footprint Veto
344        if (dr < 0.1) tmpChargedIso_DR0p0To0p1 += pf->Pt();
# Line 460 | Line 385 | SelectionStatus muonIsoMVASelection(Cont
385  
386  
387    double rho = 0;
388 < //   if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
389 < //     rho = fPUEnergyDensity->At(0)->Rho();
390 <  if (!(isnan(fPUEnergyDensity->At(0)->RhoLowEta()) || isinf(fPUEnergyDensity->At(0)->RhoLowEta())))
391 <    rho = fPUEnergyDensity->At(0)->RhoLowEta();
388 >  if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
389 >    rho = fPUEnergyDensity->At(0)->Rho();
390 >
391 > //   if (!(isnan(fPUEnergyDensity->At(0)->RhoLowEta()) || isinf(fPUEnergyDensity->At(0)->RhoLowEta())))
392 > //     rho = fPUEnergyDensity->At(0)->RhoLowEta();
393    
394    // WARNING!!!!  
395    // hardcode for sync ...
# Line 547 | Line 473 | SelectionStatus muonIsoMVASelection(Cont
473  
474    pass = false;
475    if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
476 <      && fabs(mu->Eta()) <= 1.5 && mu->Pt() <= 10 && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_BIN0)   pass = true;
476 >      && fabs(mu->Eta()) <= 1.5 && mu->Pt() <= 10 && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_OPT_BIN0)   pass = true;
477    else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
478 <           && fabs(mu->Eta()) <= 1.5 && mu->Pt() > 10 && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_BIN1)  pass = true;
478 >           && fabs(mu->Eta()) <= 1.5 && mu->Pt() > 10 && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_OPT_BIN1)  pass = true;
479    else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
480 <           && fabs(mu->Eta()) > 1.5 && mu->Pt() <= 10 && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_BIN2)  pass = true;
480 >           && fabs(mu->Eta()) > 1.5 && mu->Pt() <= 10 && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_OPT_BIN2)  pass = true;
481    else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
482 <           && fabs(mu->Eta()) > 1.5 && mu->Pt() > 10 && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_BIN3)  pass = true;
483 <  else if( !(mu->IsGlobalMuon()) && mu->IsTrackerMuon() && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_BIN4)  pass = true;
484 <  else if( mu->IsGlobalMuon() && !(mu->IsTrackerMuon()) && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_BIN5)  pass = true;
482 >           && fabs(mu->Eta()) > 1.5 && mu->Pt() > 10 && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_OPT_BIN3)  pass = true;
483 >  else if( !(mu->IsGlobalMuon()) && mu->IsTrackerMuon() && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_OPT_BIN4)  pass = true;
484 >  else if( mu->IsGlobalMuon() && !(mu->IsTrackerMuon()) && mvaval >= MUON_ISOMVA_LOOSE_FORPFID_CUT_OPT_BIN5)  pass = true;
485    if( pass ) status.orStatus(SelectionStatus::LOOSEISO);
486  
487 +  /*
488    pass = false;
489    if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
490        && fabs(mu->Eta()) <= 1.5 && mu->Pt() <= 10 && mvaval >= MUON_ISOMVA_TIGHT_FORPFID_CUT_BIN0)   pass = true;
# Line 570 | Line 497 | SelectionStatus muonIsoMVASelection(Cont
497    else if( !(mu->IsGlobalMuon()) && mu->IsTrackerMuon() && mvaval >= MUON_ISOMVA_TIGHT_FORPFID_CUT_BIN4)  pass = true;
498    else if( mu->IsGlobalMuon() && !(mu->IsTrackerMuon()) && mvaval >= MUON_ISOMVA_TIGHT_FORPFID_CUT_BIN5)  pass = true;
499    if( pass ) status.orStatus(SelectionStatus::TIGHTISO);
500 +  */
501  
502    //  pass &= (fChargedIso_DR0p0To0p1 + fChargedIso_DR0p1To0p2 + fChargedIso_DR0p2To0p3 < 0.7);
503  
504 <  if(ctrl.debug) cout << "returning status : " << hex << status.getStatus() << dec << endl;
504 >  status.isoMVA = mvaval;
505 >
506 >  if(ctrl.debug)  {
507 >    cout << "returning status : " << hex << status.getStatus() << dec << endl;
508 >    cout << "MVAVAL : " << status.isoMVA << endl;
509 >  }
510    return status;
511  
512   }
# Line 581 | Line 514 | SelectionStatus muonIsoMVASelection(Cont
514  
515   //--------------------------------------------------------------------------------------------------
516   SelectionStatus muonIsoMVASelection(ControlFlags &ctrl,
517 <                                    const mithep::Muon * mu,
518 <                                    const mithep::Vertex & vtx,
519 <                                    const mithep::Array<mithep::PFCandidate> * fPFCandidates,
517 >                                    const Muon * mu,
518 >                                    const Vertex * vtx,
519 >                                    const Array<PFCandidate> * fPFCandidates,
520                                      float rho,
521 <                                    //const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
522 <                                    mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
523 <                                    vector<const mithep::Muon*> muonsToVeto,
524 <                                    vector<const mithep::Electron*> electronsToVeto)
521 >                                    //const Array<PileupEnergyDensity> * fPUEnergyDensity,
522 >                                    MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
523 >                                    vector<const Muon*> muonsToVeto,
524 >                                    vector<const Electron*> electronsToVeto)
525   //--------------------------------------------------------------------------------------------------
526   // hacked version
527   {
# Line 596 | Line 529 | SelectionStatus muonIsoMVASelection(Cont
529    if( ctrl.debug ) {
530      cout << "muonIsoMVASelection :: muons to veto " << endl;
531      for( int i=0; i<muonsToVeto.size(); i++ ) {
532 <      const mithep::Muon * vmu = muonsToVeto[i];
532 >      const Muon * vmu = muonsToVeto[i];
533        cout << "\tpt: " << vmu->Pt()
534             << "\teta: " << vmu->Eta()
535             << "\tphi: " << vmu->Phi()
# Line 604 | Line 537 | SelectionStatus muonIsoMVASelection(Cont
537      }
538      cout << "muonIsoMVASelection :: electrson to veto " << endl;
539      for( int i=0; i<electronsToVeto.size(); i++ ) {
540 <      const mithep::Electron * vel = electronsToVeto[i];
540 >      const Electron * vel = electronsToVeto[i];
541        cout << "\tpt: " << vel->Pt()
542             << "\teta: " << vel->Eta()
543             << "\tphi: " << vel->Phi()
# Line 671 | Line 604 | SelectionStatus muonIsoMVASelection(Cont
604  
605      if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
606  
607 <    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
607 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
608  
609      Double_t deta = (mu->Eta() - pf->Eta());
610 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
611 <    Double_t dr = mithep::MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
610 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
611 >    Double_t dr = MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
612      if (dr > 1.0) continue;
613  
614      if (pf->HasTrackerTrk() && (pf->TrackerTrk() == mu->TrackerTrk()) ) continue;
# Line 690 | Line 623 | SelectionStatus muonIsoMVASelection(Cont
623        // Check for electrons
624        //
625        for (Int_t q=0; q < electronsToVeto.size(); ++q) {
626 <        const mithep::Electron *tmpele = electronsToVeto[q];
626 >        const Electron *tmpele = electronsToVeto[q];
627          // 4l electron
628          if( pf->HasTrackerTrk() ) {
629            if( pf->TrackerTrk() == tmpele->TrackerTrk() )
# Line 702 | Line 635 | SelectionStatus muonIsoMVASelection(Cont
635          }
636          // PF charged
637          if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) >= 1.479
638 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015)
638 >            && MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015)
639            IsLeptonFootprint = kTRUE;
640          // PF gamma
641          if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) >= 1.479
642 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08)
642 >            && MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08)
643            IsLeptonFootprint = kTRUE;
644        } // loop over electrons
645        
# Line 715 | Line 648 | SelectionStatus muonIsoMVASelection(Cont
648        // Check for muons
649        //
650        for (Int_t q=0; q < muonsToVeto.size(); ++q) {
651 <        const mithep::Muon *tmpmu = muonsToVeto[q];
651 >        const Muon *tmpmu = muonsToVeto[q];
652          // 4l muon
653          if( pf->HasTrackerTrk() ) {
654            if( pf->TrackerTrk() == tmpmu->TrackerTrk() )
655              IsLeptonFootprint = kTRUE;
656          }
657          // PF charged
658 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01)
658 >        if (pf->Charge() != 0 && MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01)
659            IsLeptonFootprint = kTRUE;
660        } // loop over muons
661        */
# Line 925 | Line 858 | SelectionStatus muonIsoMVASelection(Cont
858   //--------------------------------------------------------------------------------------------------
859   void initMuonIsoMVA() {
860   //--------------------------------------------------------------------------------------------------
861 <  muIsoMVA = new mithep::MuonIDMVA();
861 >  muIsoMVA = new MuonIDMVA();
862    vector<string> weightFiles;
863    weightFiles.push_back("./data/MuonIsoMVAWeights/MuonIsoMVA_BDTG_V0_barrel_lowpt.weights.xml");
864    weightFiles.push_back("./data/MuonIsoMVAWeights/MuonIsoMVA_BDTG_V0_barrel_highpt.weights.xml");
# Line 934 | Line 867 | void initMuonIsoMVA() {
867    weightFiles.push_back("./data/MuonIsoMVAWeights/MuonIsoMVA_BDTG_V0_tracker.weights.xml");
868    weightFiles.push_back("./data/MuonIsoMVAWeights/MuonIsoMVA_BDTG_V0_global.weights.xml");
869    muIsoMVA->Initialize( "MuonIsoMVA",
870 <                        mithep::MuonIDMVA::kIsoRingsV0,
870 >                        MuonIDMVA::kIsoRingsV0,
871                          kTRUE, weightFiles);
872   }
873  
874  
875 +
876   //--------------------------------------------------------------------------------------------------
877   double  muonPFIso04(ControlFlags &ctrl,
878 <                    const mithep::Muon * mu,
879 <                    const mithep::Vertex & vtx,
880 <                    const mithep::Array<mithep::PFCandidate> * fPFCandidates,
881 <                    const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
882 <                    mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
883 <                    vector<const mithep::Muon*> muonsToVeto,
950 <                    vector<const mithep::Electron*> electronsToVeto)
878 >                    const Muon * mu,
879 >                    const Vertex * vtx,
880 >                    const Array<PFCandidate> * fPFCandidates,
881 >                    const Array<PileupEnergyDensity> * fPUEnergyDensity,
882 >                    MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
883 >                    vector<const PFCandidate*> photonsToVeto)
884   //--------------------------------------------------------------------------------------------------
885   {
886 <  
887 <  if( ctrl.debug ) {
888 <    cout << "muonIsoMVASelection :: muons to veto " << endl;
889 <    for( int i=0; i<muonsToVeto.size(); i++ ) {
957 <      const mithep::Muon * vmu = muonsToVeto[i];
958 <      cout << "\tpt: " << vmu->Pt()
959 <           << "\teta: " << vmu->Eta()
960 <           << "\tphi: " << vmu->Phi()
961 <           << endl;
962 <    }
963 <    cout << "muonIsoMVASelection :: electrson to veto " << endl;
964 <    for( int i=0; i<electronsToVeto.size(); i++ ) {
965 <      const mithep::Electron * vel = electronsToVeto[i];
966 <      cout << "\tpt: " << vel->Pt()
967 <           << "\teta: " << vel->Eta()
968 <           << "\tphi: " << vel->Phi()
969 <           << endl;
970 <    }
971 <  }
886 >
887 >  extern double gChargedIso;  
888 >  extern double  gGammaIso;      
889 >  extern double  gNeutralIso;
890  
891    //
892    // final iso
# Line 980 | Line 898 | double  muonPFIso04(ControlFlags &ctrl,
898    //
899    //Loop over PF Candidates
900    //
901 +  if(ctrl.debug) cout << "  muonPFIso04(): ----> " << endl;
902    for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
984    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
985
986    Double_t deta = (mu->Eta() - pf->Eta());
987    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
988    Double_t dr = mithep::MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
989    if (dr > 0.4) continue;
990
991    if (pf->HasTrackerTrk() && (pf->TrackerTrk() == mu->TrackerTrk()) ) continue;
903  
904 <    //
905 <    // Lepton Footprint Removal
995 <    //
996 <    Bool_t IsLeptonFootprint = kFALSE;
997 <    if (dr < 1.0) {
998 <
999 <      //
1000 <      // Check for electrons
1001 <      //
1002 <      for (Int_t q=0; q < electronsToVeto.size(); ++q) {
1003 <        const mithep::Electron *tmpele = electronsToVeto[q];
1004 <        // 4l electron
1005 <        if( pf->HasTrackerTrk() ) {
1006 <          if( pf->TrackerTrk() == tmpele->TrackerTrk() )
1007 <            IsLeptonFootprint = kTRUE;
1008 <        }
1009 <        if( pf->HasGsfTrk() ) {
1010 <          if( pf->GsfTrk() == tmpele->GsfTrk() )
1011 <            IsLeptonFootprint = kTRUE;
1012 <        }
1013 <        // PF charged
1014 <        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) > 1.479
1015 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015)
1016 <          IsLeptonFootprint = kTRUE;
1017 <        // PF gamma
1018 <        if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) > 1.479
1019 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08)
1020 <          IsLeptonFootprint = kTRUE;
1021 <      } // loop over electrons
1022 <
1023 <      // KH, comment to sync
1024 <      /*
1025 <      //
1026 <      // Check for muons
1027 <      //
1028 <      for (Int_t q=0; q < muonsToVeto.size(); ++q) {
1029 <        const mithep::Muon *tmpmu = muonsToVeto[q];
1030 <        // 4l muon
1031 <        if( pf->HasTrackerTrk() ) {
1032 <          if( pf->TrackerTrk() == tmpmu->TrackerTrk() )
1033 <            IsLeptonFootprint = kTRUE;
1034 <        }
1035 <        // PF charged
1036 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01)
1037 <          IsLeptonFootprint = kTRUE;
1038 <      } // loop over muons
1039 <      */
1040 <
1041 <    if (IsLeptonFootprint)
1042 <      continue;
904 >    if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
905 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
906  
907      //
908 <    // Charged Iso
908 >    // veto FSR recovered photons
909      //
910 <    if (pf->Charge() != 0 ) {
911 <
912 <      //if( dr < 0.01 ) continue; // only for muon iso mva?
913 <      if (abs(pf->PFType()) == PFCandidate::eElectron || abs(pf->PFType()) == PFCandidate::eMuon) continue;
914 <
1052 <      if( pf->HasTrackerTrk() ) {
1053 <        if (abs(pf->TrackerTrk()->DzCorrected(vtx)) > 0.2) continue;
1054 <        if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
1055 <                              << abs(pf->TrackerTrk()->DzCorrected(vtx)) << " "
1056 <                              << dr << endl;
910 >    bool vetoPhoton = false;
911 >    for( int p=0; p<photonsToVeto.size(); p++ ) {
912 >      if( pf == photonsToVeto[p] ) {
913 >        vetoPhoton = true;
914 >        break;
915        }
916 <      if( pf->HasGsfTrk() ) {
1059 <        if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
1060 <        if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
1061 <                              << abs(pf->GsfTrk()->DzCorrected(vtx)) << " "
1062 <                              << dr << endl;
1063 <      }
1064 <
1065 <
1066 <      fChargedIso += pf->Pt();
1067 <    }
1068 <
1069 <    //
1070 <    // Gamma Iso
916 >    } if( vetoPhoton ) continue;
917      //
1072    else if (abs(pf->PFType()) == PFCandidate::eGamma) {
1073      // KH, add to sync
1074      if( pf->Pt() > 0.5 )
1075      fGammaIso += pf->Pt();
1076    }
1077
918      //
1079    // Other Neutrals
919      //
1081    else {
1082      // KH, add to sync
1083      if( pf->Pt() > 0.5 )
1084        fNeutralHadronIso += pf->Pt();
1085    }
1086    
1087    }
1088    
1089  }
1090  
1091  double rho = 0;
1092  //   if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
1093  //     rho = fPUEnergyDensity->At(0)->Rho();
1094  if (!(isnan(fPUEnergyDensity->At(0)->RhoLowEta()) || isinf(fPUEnergyDensity->At(0)->RhoLowEta())))
1095    rho = fPUEnergyDensity->At(0)->RhoLowEta();
1096
1097  // WARNING!!!!  
1098  // hardcode for sync ...
1099  EffectiveAreaVersion = muT.kMuEAData2011;
1100  // WARNING!!!!  
1101
1102
1103  double pfIso = fChargedIso + fmax(0.0,(fGammaIso + fNeutralHadronIso
1104                                        -rho*muT.MuonEffectiveArea(muT.kMuGammaAndNeutralHadronIso04,
1105                                                                   mu->Eta(),EffectiveAreaVersion)));
1106
1107  gChargedIso = fChargedIso;
1108  gGammaIso = fGammaIso;
1109  gNeutralIso = fNeutralHadronIso;  
1110  return pfIso;
1111 }
1112
1113
1114 //--------------------------------------------------------------------------------------------------
1115 // hacked version
1116 double  muonPFIso04(ControlFlags &ctrl,
1117                    const mithep::Muon * mu,
1118                    const mithep::Vertex & vtx,
1119                    const mithep::Array<mithep::PFCandidate> * fPFCandidates,
1120                    float rho,
1121                    mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
1122                    vector<const mithep::Muon*> muonsToVeto,
1123                    vector<const mithep::Electron*> electronsToVeto)
1124 //--------------------------------------------------------------------------------------------------
1125 {
1126
1127  extern double gChargedIso;  
1128  extern double  gGammaIso;      
1129  extern double  gNeutralIso;
1130  
1131  if( ctrl.debug ) {
1132    cout << "muonIsoMVASelection :: muons to veto " << endl;
1133    for( int i=0; i<muonsToVeto.size(); i++ ) {
1134      const mithep::Muon * vmu = muonsToVeto[i];
1135      cout << "\tpt: " << vmu->Pt()
1136           << "\teta: " << vmu->Eta()
1137           << "\tphi: " << vmu->Phi()
1138           << endl;
1139    }
1140    cout << "muonIsoMVASelection :: electrson to veto " << endl;
1141    for( int i=0; i<electronsToVeto.size(); i++ ) {
1142      const mithep::Electron * vel = electronsToVeto[i];
1143      cout << "\tpt: " << vel->Pt()
1144           << "\teta: " << vel->Eta()
1145           << "\tphi: " << vel->Phi()
1146           << endl;
1147    }
1148  }
1149
1150  //
1151  // final iso
1152  //
1153  Double_t fChargedIso  = 0.0;
1154  Double_t fGammaIso  = 0.0;
1155  Double_t fNeutralHadronIso  = 0.0;
1156
1157  //
1158  //Loop over PF Candidates
1159  //
1160  for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
1161
1162    if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
1163    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
920  
921      Double_t deta = (mu->Eta() - pf->Eta());
922 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
923 <    Double_t dr = mithep::MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
922 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
923 >    Double_t dr = MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
924      if (dr > 0.4) continue;
925  
926      if (pf->HasTrackerTrk() && (pf->TrackerTrk() == mu->TrackerTrk()) ) continue;
927  
928      //
1173    // Lepton Footprint Removal
1174    //
1175    Bool_t IsLeptonFootprint = kFALSE;
1176    if (dr < 1.0) {
1177
1178      //
1179      // Check for electrons
1180      //
1181      for (Int_t q=0; q < electronsToVeto.size(); ++q) {
1182        const mithep::Electron *tmpele = electronsToVeto[q];
1183        // 4l electron
1184        if( pf->HasTrackerTrk() ) {
1185          if( pf->TrackerTrk() == tmpele->TrackerTrk() )
1186            IsLeptonFootprint = kTRUE;
1187        }
1188        if( pf->HasGsfTrk() ) {
1189          if( pf->GsfTrk() == tmpele->GsfTrk() )
1190            IsLeptonFootprint = kTRUE;
1191        }
1192        // PF charged
1193        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) > 1.479
1194            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015)
1195          IsLeptonFootprint = kTRUE;
1196        // PF gamma
1197        if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) > 1.479
1198            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08)
1199          IsLeptonFootprint = kTRUE;
1200      } // loop over electrons
1201
1202      /* KH - comment for sync      
1203      //
1204      // Check for muons
1205      //
1206      for (Int_t q=0; q < muonsToVeto.size(); ++q) {
1207        const mithep::Muon *tmpmu = muonsToVeto[q];
1208        // 4l muon
1209        if( pf->HasTrackerTrk() ) {
1210          if( pf->TrackerTrk() == tmpmu->TrackerTrk() )
1211            IsLeptonFootprint = kTRUE;
1212        }
1213        // PF charged
1214        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01)
1215          IsLeptonFootprint = kTRUE;
1216      } // loop over muons
1217      */
1218
1219    if (IsLeptonFootprint)
1220      continue;
1221
1222    //
929      // Charged Iso
930      //
931      if (pf->Charge() != 0 && (pf->HasTrackerTrk()||pf->HasGsfTrk()) ) {
932  
933        //if( dr < 0.01 ) continue; // only for muon iso mva?
934        if (abs(pf->PFType()) == PFCandidate::eElectron || abs(pf->PFType()) == PFCandidate::eMuon) continue;
1229
1230
1231 //       if( pf->HasTrackerTrk() ) {
1232 //      if (abs(pf->TrackerTrk()->DzCorrected(vtx)) > 0.2) continue;
1233 //      if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
1234 //                            << abs(pf->TrackerTrk()->DzCorrected(vtx)) << " "
1235 //                            << dr << endl;
1236 //       }
1237 //       if( pf->HasGsfTrk() ) {
1238 //      if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
1239 //      if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
1240 //                            << abs(pf->GsfTrk()->DzCorrected(vtx)) << " "
1241 //                            << dr << endl;
1242 //       }
1243
1244
935        fChargedIso += pf->Pt();
936      }
937 <
937 >    
938      //
939      // Gamma Iso
940      //
941      else if (abs(pf->PFType()) == PFCandidate::eGamma) {
942        // KH, add to sync
943 <      if( pf->Pt() > 0.5 )
943 >      if( pf->Pt() > 0.5 && dr > 0.01)
944        fGammaIso += pf->Pt();
945      }
946 <
946 >    
947      //
948      // Other Neutrals
949      //
950      else {
951 <      // KH, add to sync
952 <      if( pf->Pt() > 0.5 )
951 >    
952 >      if( pf->Pt() > 0.5  && dr > 0.01)
953          fNeutralHadronIso += pf->Pt();
954      }
1265    
1266    }
1267    
955    }
1269  
1270 //   double rho = 0;
1271 //   if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
1272 //     rho = fPUEnergyDensity->At(0)->Rho();
1273
1274  // WARNING!!!!  
1275  // hardcode for sync ...
1276  EffectiveAreaVersion = muT.kMuEAData2011;
1277  // WARNING!!!!  
956  
957 +  double rho=0;
958 +  if( (EffectiveAreaVersion == MuonTools::kMuEAFall11MC) ||
959 +      (EffectiveAreaVersion == MuonTools::kMuEAData2011) ) {
960 +    if (!(isnan(fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25()) ||
961 +          isinf(fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25())))
962 +      rho = fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25();
963 +    //rho = fPUEnergyDensity->At(0)->Rho();
964 +    // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
965 +    EffectiveAreaVersion  = MuonTools::kMuEAData2011;
966 +    // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
967 +  } else {
968 +    if (!(isnan(fPUEnergyDensity->At(0)->RhoKt6PFJetsCentralNeutral()) ||
969 +          isinf(fPUEnergyDensity->At(0)->RhoKt6PFJetsCentralNeutral())))
970 +      rho = fPUEnergyDensity->At(0)->RhoKt6PFJetsCentralNeutral();
971 +    // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
972 +    EffectiveAreaVersion  = MuonTools::kMuEAData2012;
973 +    // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
974 +  }
975 +  // if(ctrl.debug) cout << "    rho: " << rho << endl;
976 +
977 +  TLorentzVector  tmpvec;
978 +  tmpvec.SetPtEtaPhiM(mu->Pt(),mu->Eta(),mu->Phi(),mu->Mass());
979 +  for( int p=0; p<photonsToVeto.size(); p++ ) {
980 +    const PFCandidate * pf  = photonsToVeto[p];
981 +    TLorentzVector pfvec;
982 +    pfvec.SetPtEtaPhiM(pf->Pt(),pf->Eta(),pf->Phi(),0.);
983 +    tmpvec += pfvec;
984 +  }
985  
986    double pfIso = fChargedIso + fmax(0.0,(fGammaIso + fNeutralHadronIso
987                                          -rho*muT.MuonEffectiveArea(muT.kMuGammaAndNeutralHadronIso04,
988 <                                                                   mu->Eta(),EffectiveAreaVersion)));
988 >                                                                   //tmpvec.Eta(),EffectiveAreaVersion)));
989 >                                                                   mu->Eta(),EffectiveAreaVersion)));
990    gChargedIso = fChargedIso;
991    gGammaIso   = fGammaIso;
992    gNeutralIso = fNeutralHadronIso;
993    
994 +  if( ctrl.debug ) {
995 +    cout << "    PFiso: " << pfIso
996 +         << setw(9) << setprecision(4) << fChargedIso
997 +         << setw(9) << setprecision(4) << fGammaIso
998 +         << setw(9) << setprecision(4) << fNeutralHadronIso
999 +         << endl;
1000 +  }
1001 +
1002    return pfIso;
1003   }
1004  
1290
1005   //--------------------------------------------------------------------------------------------------
1006   SelectionStatus muonReferenceIsoSelection(ControlFlags &ctrl,
1007 <                                          const mithep::Muon * mu,
1008 <                                          const mithep::Vertex & vtx,
1009 <                                          const mithep::Array<mithep::PFCandidate> * fPFCandidates,
1010 <                                          const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
1011 <                                          mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
1012 <                                          vector<const mithep::Muon*> muonsToVeto,
1299 <                                          vector<const mithep::Electron*> electronsToVeto)
1007 >                                          const Muon * mu,
1008 >                                          const Vertex * vtx,
1009 >                                          const Array<PFCandidate> * fPFCandidates,
1010 >                                          const Array<PileupEnergyDensity> * fPUEnergyDensity,
1011 >                                          MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
1012 >                                          vector<const PFCandidate*> photonsToVeto)
1013   //--------------------------------------------------------------------------------------------------
1014   {
1015    
1016    SelectionStatus status;
1017  
1018    double pfIso = muonPFIso04( ctrl, mu, vtx, fPFCandidates, fPUEnergyDensity,
1019 <                              EffectiveAreaVersion, muonsToVeto ,electronsToVeto );
1307 <  //  cout << "--------------> setting muon isoPF04 to" << pfIso << endl;
1308 <  status.isoPF04 = pfIso;
1309 <  status.chisoPF04 = gChargedIso;
1310 <  status.gaisoPF04 = gGammaIso;
1311 <  status.neisoPF04 = gNeutralIso;
1312 <
1313 <  bool pass = false;
1314 <  if( (pfIso/mu->Pt()) < MUON_REFERENCE_PFISO_CUT ) pass = true;
1315 <  
1316 <  if( pass ) {
1317 <    status.orStatus(SelectionStatus::LOOSEISO);
1318 <    status.orStatus(SelectionStatus::TIGHTISO);
1319 <  }
1320 <  if(ctrl.debug) cout << "returning status : " << hex << status.getStatus() << dec << endl;
1321 <  return status;
1322 <  
1323 < }
1324 <
1325 <
1326 < //--------------------------------------------------------------------------------------------------
1327 < // hacked version
1328 < SelectionStatus muonReferenceIsoSelection(ControlFlags &ctrl,
1329 <                                          const mithep::Muon * mu,
1330 <                                          const mithep::Vertex & vtx,
1331 <                                          const mithep::Array<mithep::PFCandidate> * fPFCandidates,
1332 <                                          float rho,
1333 <                                          mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
1334 <                                          vector<const mithep::Muon*> muonsToVeto,
1335 <                                          vector<const mithep::Electron*> electronsToVeto)
1336 < //--------------------------------------------------------------------------------------------------
1337 < {
1338 <  
1339 <  SelectionStatus status;
1340 <  
1341 <  double pfIso = muonPFIso04( ctrl, mu, vtx, fPFCandidates, rho,
1342 <                              EffectiveAreaVersion, muonsToVeto ,electronsToVeto );
1343 <
1019 >                              EffectiveAreaVersion, photonsToVeto);
1020    status.isoPF04 = pfIso;
1021    status.chisoPF04 = gChargedIso;
1022    status.gaisoPF04 = gGammaIso;
# Line 1353 | Line 1029 | SelectionStatus muonReferenceIsoSelectio
1029      status.orStatus(SelectionStatus::LOOSEISO);
1030      status.orStatus(SelectionStatus::TIGHTISO);
1031    }
1032 <  if(ctrl.debug) cout << "returning status : " << hex << status.getStatus() << dec << endl;
1032 >  if(ctrl.debug)
1033 >    cout << "  --> mu relpfIso: " << pfIso/mu->Pt() << ", returning status : " << hex << status.getStatus() << dec << endl;
1034    return status;
1358  
1035   }
1036  
1361
1362
1037   //--------------------------------------------------------------------------------------------------
1038   SelectionStatus electronIsoMVASelection(ControlFlags &ctrl,
1039 <                                        const mithep::Electron * ele,
1040 <                                        const mithep::Vertex & vtx,
1041 <                                        const mithep::Array<mithep::PFCandidate> * fPFCandidates,
1042 <                                        const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
1043 <                                        mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
1044 <                                        vector<const mithep::Muon*> muonsToVeto,
1045 <                                        vector<const mithep::Electron*> electronsToVeto)
1039 >                                        const Electron * ele,
1040 >                                        const Vertex * vtx,
1041 >                                        const Array<PFCandidate> * fPFCandidates,
1042 >                                        const Array<PileupEnergyDensity> * fPUEnergyDensity,
1043 >                                        ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
1044 >                                        vector<const Muon*> muonsToVeto,
1045 >                                        vector<const Electron*> electronsToVeto)
1046   //--------------------------------------------------------------------------------------------------
1047   {
1048  
1049    if( ctrl.debug ) {
1050      cout << "electronIsoMVASelection :: muons to veto " << endl;
1051      for( int i=0; i<muonsToVeto.size(); i++ ) {
1052 <      const mithep::Muon * vmu = muonsToVeto[i];
1052 >      const Muon * vmu = muonsToVeto[i];
1053        cout << "\tpt: " << vmu->Pt()
1054             << "\teta: " << vmu->Eta()
1055             << "\tphi: " << vmu->Phi()
# Line 1383 | Line 1057 | SelectionStatus electronIsoMVASelection(
1057      }
1058      cout << "electronIsoMVASelection :: electrson to veto " << endl;
1059      for( int i=0; i<electronsToVeto.size(); i++ ) {
1060 <      const mithep::Electron * vel = electronsToVeto[i];
1060 >      const Electron * vel = electronsToVeto[i];
1061        cout << "\tpt: " << vel->Pt()
1062             << "\teta: " << vel->Eta()
1063             << "\tphi: " << vel->Phi()
# Line 1402 | Line 1076 | SelectionStatus electronIsoMVASelection(
1076    Double_t tmpChargedIso_DR0p2To0p3  = 0;
1077    Double_t tmpChargedIso_DR0p3To0p4  = 0;
1078    Double_t tmpChargedIso_DR0p4To0p5  = 0;
1405  Double_t tmpChargedIso_DR0p5To0p7  = 0;
1079  
1080    Double_t tmpGammaIso_DR0p0To0p1  = 0;
1081    Double_t tmpGammaIso_DR0p1To0p2  = 0;
1082    Double_t tmpGammaIso_DR0p2To0p3  = 0;
1083    Double_t tmpGammaIso_DR0p3To0p4  = 0;
1084    Double_t tmpGammaIso_DR0p4To0p5  = 0;
1085 <  Double_t tmpGammaIso_DR0p5To0p7  = 0;
1085 >
1086  
1087    Double_t tmpNeutralHadronIso_DR0p0To0p1  = 0;
1088    Double_t tmpNeutralHadronIso_DR0p1To0p2  = 0;
1089    Double_t tmpNeutralHadronIso_DR0p2To0p3  = 0;
1090    Double_t tmpNeutralHadronIso_DR0p3To0p4  = 0;
1091    Double_t tmpNeutralHadronIso_DR0p4To0p5  = 0;
1419  Double_t tmpNeutralHadronIso_DR0p5To0p7  = 0;
1092  
1093          
1094  
# Line 1449 | Line 1121 | SelectionStatus electronIsoMVASelection(
1121  
1122      if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
1123  
1124 <    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
1124 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
1125      Double_t deta = (ele->Eta() - pf->Eta());
1126 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(ele->Phi()),Double_t(pf->Phi()));
1127 <    Double_t dr = mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta());
1128 <    if (dr > 0.5) continue;
1126 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(ele->Phi()),Double_t(pf->Phi()));
1127 >    Double_t dr = MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta());
1128 >    if (dr > 1.0) continue;
1129 >
1130      if(ctrl.debug) {
1131        cout << "pf :: type: " << pf->PFType() << "\tpt: " << pf->Pt();
1132 <      if( pf->HasTrackerTrk() ) cout << "\tdZ: " << pf->TrackerTrk()->DzCorrected(vtx);
1132 >      if( pf->HasTrackerTrk() ) cout << "\tdZ: " << pf->TrackerTrk()->DzCorrected(*vtx);
1133        cout << endl;
1134      }
1135  
# Line 1471 | Line 1144 | SelectionStatus electronIsoMVASelection(
1144      Bool_t IsLeptonFootprint = kFALSE;
1145      if (dr < 1.0) {
1146  
1147 +
1148        //
1149        // Check for electrons
1150        //
1151 +
1152        for (Int_t q=0; q < electronsToVeto.size(); ++q) {
1153 <        const mithep::Electron *tmpele = electronsToVeto[q];
1153 >        const Electron *tmpele = electronsToVeto[q];
1154 >        double tmpdr = MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta());
1155 >
1156          // 4l electron
1157          if( pf->HasTrackerTrk()  ) {
1158            if( pf->TrackerTrk() == tmpele->TrackerTrk() ) {
# Line 1490 | Line 1167 | SelectionStatus electronIsoMVASelection(
1167            }
1168          }
1169          // PF charged
1170 <        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) >= 1.479
1494 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015) {
1170 >        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) >= 1.479 && tmpdr < 0.015) {
1171            if( ctrl.debug) cout << "\tcharged trk, dR matches 4L ele ..." << endl;
1172            IsLeptonFootprint = kTRUE;
1173          }
1174          // PF gamma
1175          if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) >= 1.479
1176 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08) {
1176 >            && tmpdr < 0.08) {
1177            if( ctrl.debug) cout << "\tPF gamma, matches 4L ele ..." << endl;
1178            IsLeptonFootprint = kTRUE;
1179          }
1180        } // loop over electrons
1181  
1182 +
1183        /* KH - comment for sync            
1184        //
1185        // Check for muons
1186        //
1187        for (Int_t q=0; q < muonsToVeto.size(); ++q) {
1188 <        const mithep::Muon *tmpmu = muonsToVeto[q];
1188 >        const Muon *tmpmu = muonsToVeto[q];
1189          // 4l muon
1190          if( pf->HasTrackerTrk() ) {
1191            if (pf->TrackerTrk() == tmpmu->TrackerTrk() ){
# Line 1517 | Line 1194 | SelectionStatus electronIsoMVASelection(
1194            }
1195          }
1196          // PF charged
1197 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01) {
1197 >        if (pf->Charge() != 0 && MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01) {
1198            if( ctrl.debug) cout << "\tcharged trk, dR matches 4L mu ..." << endl;
1199            IsLeptonFootprint = kTRUE;
1200          }
# Line 1553 | Line 1230 | SelectionStatus electronIsoMVASelection(
1230        if (dr >= 0.2 && dr < 0.3) tmpChargedIso_DR0p2To0p3 += pf->Pt();
1231        if (dr >= 0.3 && dr < 0.4) tmpChargedIso_DR0p3To0p4 += pf->Pt();
1232        if (dr >= 0.4 && dr < 0.5) tmpChargedIso_DR0p4To0p5 += pf->Pt();
1556      if (dr >= 0.5 && dr < 0.7) tmpChargedIso_DR0p5To0p7 += pf->Pt();
1233  
1234      }
1235  
# Line 1562 | Line 1238 | SelectionStatus electronIsoMVASelection(
1238      //
1239      else if (abs(pf->PFType()) == PFCandidate::eGamma) {
1240  
1241 <      if (fabs(ele->SCluster()->Eta()) > 1.479) {
1566 <        if (mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta()) < 0.08) continue;
1567 <      }
1241 >      if (fabs(ele->SCluster()->Eta()) > 1.479 && dr < 0.08) continue;
1242  
1243        if( ctrl.debug) cout << "gamma:: " << pf->Pt() << " "
1244                             << dr << endl;
# Line 1574 | Line 1248 | SelectionStatus electronIsoMVASelection(
1248        if (dr >= 0.2 && dr < 0.3) tmpGammaIso_DR0p2To0p3 += pf->Pt();
1249        if (dr >= 0.3 && dr < 0.4) tmpGammaIso_DR0p3To0p4 += pf->Pt();
1250        if (dr >= 0.4 && dr < 0.5) tmpGammaIso_DR0p4To0p5 += pf->Pt();
1577      if (dr >= 0.5 && dr < 0.7) tmpGammaIso_DR0p5To0p7 += pf->Pt();
1578
1251      }
1252  
1253      //
# Line 1589 | Line 1261 | SelectionStatus electronIsoMVASelection(
1261        if (dr >= 0.2 && dr < 0.3) tmpNeutralHadronIso_DR0p2To0p3 += pf->Pt();
1262        if (dr >= 0.3 && dr < 0.4) tmpNeutralHadronIso_DR0p3To0p4 += pf->Pt();
1263        if (dr >= 0.4 && dr < 0.5) tmpNeutralHadronIso_DR0p4To0p5 += pf->Pt();
1592      if (dr >= 0.5 && dr < 0.7) tmpNeutralHadronIso_DR0p5To0p7 += pf->Pt();
1264      }
1265  
1266      }
# Line 1602 | Line 1273 | SelectionStatus electronIsoMVASelection(
1273    fChargedIso_DR0p3To0p4   = fmin((tmpChargedIso_DR0p3To0p4)/ele->Pt(), 2.5);
1274    fChargedIso_DR0p4To0p5   = fmin((tmpChargedIso_DR0p4To0p5)/ele->Pt(), 2.5);
1275  
1276 <  double rho = 0;
1277 < //   if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
1278 < //     rho = fPUEnergyDensity->At(0)->Rho();
1279 <  if (!(isnan(fPUEnergyDensity->At(0)->RhoLowEta()) || isinf(fPUEnergyDensity->At(0)->RhoLowEta())))
1280 <    rho = fPUEnergyDensity->At(0)->RhoLowEta();
1276 >  if(ctrl.debug) {
1277 >    cout << "fChargedIso_DR0p0To0p1 : " << fChargedIso_DR0p0To0p1  << endl;
1278 >    cout << "fChargedIso_DR0p1To0p2 : " << fChargedIso_DR0p1To0p2  << endl;
1279 >    cout << "fChargedIso_DR0p2To0p3 : " << fChargedIso_DR0p2To0p3  << endl;
1280 >    cout << "fChargedIso_DR0p3To0p4 : " << fChargedIso_DR0p3To0p4  << endl;
1281 >    cout << "fChargedIso_DR0p4To0p5 : " << fChargedIso_DR0p4To0p5  << endl;
1282 >  }
1283 >
1284  
1285 +  double rho = 0;
1286 +  if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
1287 +    rho = fPUEnergyDensity->At(0)->Rho();
1288 +  //   if (!(isnan(fPUEnergyDensity->At(0)->RhoLowEta()) || isinf(fPUEnergyDensity->At(0)->RhoLowEta())))
1289 +  //     rho = fPUEnergyDensity->At(0)->RhoLowEta();
1290 +  
1291    // WARNING!!!!  
1292    // hardcode for sync ...
1293 <  //  EffectiveAreaVersion = eleT.kEleEAData2011;
1614 <  EffectiveAreaVersion = eleT.kEleEAFall11MC;
1293 >  EffectiveAreaVersion = eleT.kEleEAData2011;
1294    // WARNING!!!!  
1295  
1296    if( ctrl.debug) {
# Line 1668 | Line 1347 | SelectionStatus electronIsoMVASelection(
1347                               ,0.0);
1348  
1349  
1350 +  if( ctrl.debug) {
1351 +    cout << "fGammaIso_DR0p0To0p1: " << fGammaIso_DR0p0To0p1 << endl;
1352 +    cout << "fGammaIso_DR0p1To0p2: " << fGammaIso_DR0p1To0p2 << endl;
1353 +    cout << "fGammaIso_DR0p2To0p3: " << fGammaIso_DR0p2To0p3 << endl;
1354 +    cout << "fGammaIso_DR0p3To0p4: " << fGammaIso_DR0p3To0p4 << endl;
1355 +    cout << "fGammaIso_DR0p4To0p5: " << fGammaIso_DR0p4To0p5 << endl;
1356 +  }
1357 +
1358    fNeutralHadronIso_DR0p0To0p1 = fmax(fmin((tmpNeutralHadronIso_DR0p0To0p1
1359                                            -rho*eleT.ElectronEffectiveArea(eleT.kEleNeutralHadronIsoDR0p0To0p1,
1360                                                                   ele->SCluster()->Eta(),EffectiveAreaVersion))/ele->Pt()
# Line 1694 | Line 1381 | SelectionStatus electronIsoMVASelection(
1381                                           , 2.5)
1382                                       , 0.0);
1383  
1384 +  if( ctrl.debug) {
1385 +    cout << "fNeutralHadronIso_DR0p0To0p1: " << fNeutralHadronIso_DR0p0To0p1 << endl;
1386 +    cout << "fNeutralHadronIso_DR0p1To0p2: " << fNeutralHadronIso_DR0p1To0p2 << endl;
1387 +    cout << "fNeutralHadronIso_DR0p2To0p3: " << fNeutralHadronIso_DR0p2To0p3 << endl;
1388 +    cout << "fNeutralHadronIso_DR0p3To0p4: " << fNeutralHadronIso_DR0p3To0p4 << endl;
1389 +    cout << "fNeutralHadronIso_DR0p4To0p5: " << fNeutralHadronIso_DR0p4To0p5 << endl;
1390 +  }
1391 +
1392    double mvaval = eleIsoMVA->MVAValue_IsoRings( ele->Pt(),
1393                                                  ele->SCluster()->Eta(),
1394                                                  fChargedIso_DR0p0To0p1,
# Line 1714 | Line 1409 | SelectionStatus electronIsoMVASelection(
1409                                                  ctrl.debug);
1410  
1411    SelectionStatus status;
1412 +  status.isoMVA = mvaval;
1413    bool pass = false;
1414  
1415    Int_t subdet = 0;
1416    if (fabs(ele->SCluster()->Eta()) < 0.8) subdet = 0;
1417    else if (fabs(ele->SCluster()->Eta()) < 1.479) subdet = 1;
1418    else subdet = 2;
1419 +
1420    Int_t ptBin = 0;
1421 <  if (ele->Pt() > 10.0) ptBin = 1;
1421 >  if (ele->Pt() >= 10.0) ptBin = 1;
1422    
1423    Int_t MVABin = -1;
1424    if (subdet == 0 && ptBin == 0) MVABin = 0;
# Line 1732 | Line 1429 | SelectionStatus electronIsoMVASelection(
1429    if (subdet == 2 && ptBin == 1) MVABin = 5;
1430  
1431    pass = false;
1432 <  if( MVABin == 0 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_BIN0 ) pass = true;
1433 <  if( MVABin == 1 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_BIN1 ) pass = true;
1434 <  if( MVABin == 2 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_BIN2 ) pass = true;
1435 <  if( MVABin == 3 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_BIN3 ) pass = true;
1436 <  if( MVABin == 4 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_BIN4 ) pass = true;
1437 <  if( MVABin == 5 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_BIN5 ) pass = true;
1432 >  if( MVABin == 0 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_OPT_BIN0 ) pass = true;
1433 >  if( MVABin == 1 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_OPT_BIN1 ) pass = true;
1434 >  if( MVABin == 2 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_OPT_BIN2 ) pass = true;
1435 >  if( MVABin == 3 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_OPT_BIN3 ) pass = true;
1436 >  if( MVABin == 4 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_OPT_BIN4 ) pass = true;
1437 >  if( MVABin == 5 && mvaval > ELECTRON_LOOSE_ISOMVA_CUT_OPT_BIN5 ) pass = true;
1438 >  //  pass &= (fChargedIso_DR0p0To0p1 + fChargedIso_DR0p1To0p2 + fChargedIso_DR0p2To0p3 < 0.7);
1439    if( pass ) status.orStatus(SelectionStatus::LOOSEISO);
1440  
1441   //   pass = false;
# Line 1755 | Line 1453 | SelectionStatus electronIsoMVASelection(
1453   }
1454  
1455  
1758
1456   //--------------------------------------------------------------------------------------------------
1457   SelectionStatus electronIsoMVASelection(ControlFlags &ctrl,
1458 <                                        const mithep::Electron * ele,
1459 <                                        const mithep::Vertex & vtx,
1460 <                                        const mithep::Array<mithep::PFCandidate> * fPFCandidates,
1458 >                                        const Electron * ele,
1459 >                                        const Vertex * vtx,
1460 >                                        const Array<PFCandidate> * fPFCandidates,
1461                                          float rho,
1462 <                                        //const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
1463 <                                        mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
1464 <                                        vector<const mithep::Muon*> muonsToVeto,
1465 <                                        vector<const mithep::Electron*> electronsToVeto)
1462 >                                        //const Array<PileupEnergyDensity> * fPUEnergyDensity,
1463 >                                        ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
1464 >                                        vector<const Muon*> muonsToVeto,
1465 >                                        vector<const Electron*> electronsToVeto)
1466   //--------------------------------------------------------------------------------------------------
1467   // hacked version
1468   {
# Line 1776 | Line 1473 | SelectionStatus electronIsoMVASelection(
1473    if( ctrl.debug ) {
1474      cout << "electronIsoMVASelection :: muons to veto " << endl;
1475      for( int i=0; i<muonsToVeto.size(); i++ ) {
1476 <      const mithep::Muon * vmu = muonsToVeto[i];
1476 >      const Muon * vmu = muonsToVeto[i];
1477        cout << "\tpt: " << vmu->Pt()
1478             << "\teta: " << vmu->Eta()
1479             << "\tphi: " << vmu->Phi()
# Line 1784 | Line 1481 | SelectionStatus electronIsoMVASelection(
1481      }
1482      cout << "electronIsoMVASelection :: electrson to veto " << endl;
1483      for( int i=0; i<electronsToVeto.size(); i++ ) {
1484 <      const mithep::Electron * vel = electronsToVeto[i];
1484 >      const Electron * vel = electronsToVeto[i];
1485        cout << "\tpt: " << vel->Pt()
1486             << "\teta: " << vel->Eta()
1487             << "\tphi: " << vel->Phi()
# Line 1848 | Line 1545 | SelectionStatus electronIsoMVASelection(
1545  
1546      if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
1547  
1548 <    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
1548 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
1549      Double_t deta = (ele->Eta() - pf->Eta());
1550 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(ele->Phi()),Double_t(pf->Phi()));
1551 <    Double_t dr = mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta());
1550 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(ele->Phi()),Double_t(pf->Phi()));
1551 >    Double_t dr = MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta());
1552      if (dr > 1.0) continue;
1553  
1554      if(ctrl.debug) {
1555        cout << "pf :: type: " << pf->PFType() << "\tpt: " << pf->Pt();
1556 <      if( pf->HasTrackerTrk() ) cout << "\tdZ: " << pf->TrackerTrk()->DzCorrected(vtx);
1556 >      if( pf->HasTrackerTrk() ) cout << "\tdZ: " << pf->TrackerTrk()->DzCorrected(*vtx);
1557        cout << endl;
1558      }
1559  
# Line 1877 | Line 1574 | SelectionStatus electronIsoMVASelection(
1574        //
1575  
1576        for (Int_t q=0; q < electronsToVeto.size(); ++q) {
1577 <        const mithep::Electron *tmpele = electronsToVeto[q];
1578 <        double tmpdr = mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta());
1577 >        const Electron *tmpele = electronsToVeto[q];
1578 >        double tmpdr = MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta());
1579  
1580          // 4l electron
1581          if( pf->HasTrackerTrk()  ) {
# Line 1912 | Line 1609 | SelectionStatus electronIsoMVASelection(
1609        // Check for muons
1610        //
1611        for (Int_t q=0; q < muonsToVeto.size(); ++q) {
1612 <        const mithep::Muon *tmpmu = muonsToVeto[q];
1612 >        const Muon *tmpmu = muonsToVeto[q];
1613          // 4l muon
1614          if( pf->HasTrackerTrk() ) {
1615            if (pf->TrackerTrk() == tmpmu->TrackerTrk() ){
# Line 1921 | Line 1618 | SelectionStatus electronIsoMVASelection(
1618            }
1619          }
1620          // PF charged
1621 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01) {
1621 >        if (pf->Charge() != 0 && MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01) {
1622            if( ctrl.debug) cout << "\tcharged trk, dR matches 4L mu ..." << endl;
1623            IsLeptonFootprint = kTRUE;
1624          }
# Line 2183 | Line 1880 | SelectionStatus electronIsoMVASelection(
1880   //--------------------------------------------------------------------------------------------------
1881   void initElectronIsoMVA() {
1882   //--------------------------------------------------------------------------------------------------
1883 <  eleIsoMVA = new mithep::ElectronIDMVA();
1883 >  eleIsoMVA = new ElectronIDMVA();
1884    vector<string> weightFiles;
1885    weightFiles.push_back("../MitPhysics/data/ElectronMVAWeights/ElectronIso_BDTG_V0_BarrelPt5To10.weights.xml");
1886    weightFiles.push_back("../MitPhysics/data/ElectronMVAWeights/ElectronIso_BDTG_V0_EndcapPt5To10.weights.xml");
1887    weightFiles.push_back("../MitPhysics/data/ElectronMVAWeights/ElectronIso_BDTG_V0_BarrelPt10ToInf.weights.xml");
1888    weightFiles.push_back("../MitPhysics/data/ElectronMVAWeights/ElectronIso_BDTG_V0_EndcapPt10ToInf.weights.xml");
1889    eleIsoMVA->Initialize( "ElectronIsoMVA",
1890 <                        mithep::ElectronIDMVA::kIsoRingsV0,
1890 >                        ElectronIDMVA::kIsoRingsV0,
1891                          kTRUE, weightFiles);
1892   }
1893  
1894  
1895  
1896 +
1897   //--------------------------------------------------------------------------------------------------
1898   float electronPFIso04(ControlFlags &ctrl,
1899 <                                const mithep::Electron * ele,
1900 <                                const mithep::Vertex & vtx,
1901 <                                const mithep::Array<mithep::PFCandidate> * fPFCandidates,
1902 <                                const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
1903 <                                mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
1904 <                                vector<const mithep::Muon*> muonsToVeto,
2207 <                                vector<const mithep::Electron*> electronsToVeto)
1899 >                      const Electron * ele,
1900 >                      const Vertex * vtx,
1901 >                      const Array<PFCandidate> * fPFCandidates,
1902 >                      const Array<PileupEnergyDensity> * fPUEnergyDensity,
1903 >                      ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
1904 >                      vector<const PFCandidate*> photonsToVeto)        
1905   //--------------------------------------------------------------------------------------------------
1906   {
1907  
2211  if( ctrl.debug ) {
2212    cout << "electronIsoMVASelection :: muons to veto " << endl;
2213    for( int i=0; i<muonsToVeto.size(); i++ ) {
2214      const mithep::Muon * vmu = muonsToVeto[i];
2215      cout << "\tpt: " << vmu->Pt()
2216           << "\teta: " << vmu->Eta()
2217           << "\tphi: " << vmu->Phi()
2218           << endl;
2219    }
2220    cout << "electronIsoMVASelection :: electrson to veto " << endl;
2221    for( int i=0; i<electronsToVeto.size(); i++ ) {
2222      const mithep::Electron * vel = electronsToVeto[i];
2223      cout << "\tpt: " << vel->Pt()
2224           << "\teta: " << vel->Eta()
2225           << "\tphi: " << vel->Phi()
2226           << "\ttrk: " << vel->TrackerTrk()
2227           << endl;
2228    }
2229  }
2230
2231
1908    //
1909    // final iso
1910    //
# Line 2240 | Line 1916 | float electronPFIso04(ControlFlags &ctrl
1916    //
1917    //Loop over PF Candidates
1918    //
1919 +  if(ctrl.debug) cout << "  electronPFIso04(): ----> " << endl;
1920    for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
2244    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
2245    Double_t deta = (ele->Eta() - pf->Eta());
2246    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(ele->Phi()),Double_t(pf->Phi()));
2247    Double_t dr = mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta());
2248    if (dr >= 0.4) continue;
2249    if(ctrl.debug) {
2250      cout << "pf :: type: " << pf->PFType() << "\tpt: " << pf->Pt();
2251      if( pf->HasTrackerTrk() ) cout << "\tdZ: " << pf->TrackerTrk()->DzCorrected(vtx);
2252      cout << endl;
2253    }
1921  
1922 <
2256 <    if ( (pf->HasTrackerTrk() && (pf->TrackerTrk() == ele->TrackerTrk())) ||
2257 <         (pf->HasGsfTrk() && (pf->GsfTrk() == ele->GsfTrk()))) continue;
2258 <    
1922 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
1923  
1924      //
1925 <    // Lepton Footprint Removal
1925 >    // veto FSR recovered photons
1926      //
1927 <    Bool_t IsLeptonFootprint = kFALSE;
1928 <    if (dr < 1.0) {
1929 <
1930 <      //
1931 <      // Check for electrons
2268 <      //
2269 <      for (Int_t q=0; q < electronsToVeto.size(); ++q) {
2270 <        const mithep::Electron *tmpele = electronsToVeto[q];
2271 <        // 4l electron
2272 <        if( pf->HasTrackerTrk()  ) {
2273 <          if( pf->TrackerTrk() == tmpele->TrackerTrk() ) {
2274 <            if( ctrl.debug) cout << "\tcharged tktrk, matches 4L ele ..." << endl;
2275 <            IsLeptonFootprint = kTRUE;
2276 <          }
2277 <        }
2278 <        if( pf->HasGsfTrk()  ) {
2279 <          if( pf->GsfTrk() == tmpele->GsfTrk() ) {
2280 <            if( ctrl.debug) cout << "\tcharged gsftrk, matches 4L ele ..." << endl;
2281 <            IsLeptonFootprint = kTRUE;
2282 <          }
2283 <        }
2284 <        // PF charged
2285 <        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) > 1.479
2286 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015) {
2287 <          if( ctrl.debug) cout << "\tcharged trk, dR matches 4L ele ..." << endl;
2288 <          IsLeptonFootprint = kTRUE;
2289 <        }
2290 <        // PF gamma
2291 <        if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) > 1.479
2292 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08) {
2293 <          if( ctrl.debug) cout << "\tPF gamma, matches 4L ele ..." << endl;
2294 <          IsLeptonFootprint = kTRUE;
2295 <        }
2296 <      } // loop over electrons
2297 <
2298 <
2299 <      //
2300 <      // Check for muons
2301 <      //
2302 <      for (Int_t q=0; q < muonsToVeto.size(); ++q) {
2303 <        const mithep::Muon *tmpmu = muonsToVeto[q];
2304 <        // 4l muon
2305 <        if( pf->HasTrackerTrk() ) {
2306 <          if (pf->TrackerTrk() == tmpmu->TrackerTrk() ){
2307 <            if( ctrl.debug) cout << "\tmatches 4L mu ..." << endl;
2308 <            IsLeptonFootprint = kTRUE;
2309 <          }
2310 <        }
2311 <        // PF charged
2312 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01) {
2313 <          if( ctrl.debug) cout << "\tcharged trk, dR matches 4L mu ..." << endl;
2314 <          IsLeptonFootprint = kTRUE;
2315 <        }
2316 <      } // loop over muons
2317 <
2318 <
2319 <    if (IsLeptonFootprint)
2320 <      continue;
2321 <
2322 <    //
2323 <    // Charged Iso
2324 <    //
2325 <    if (pf->Charge() != 0 ) {
2326 <
2327 <      if( pf->HasTrackerTrk() )
2328 <        if (abs(pf->TrackerTrk()->DzCorrected(vtx)) > 0.2) continue;
2329 <      if( pf->HasGsfTrk() )
2330 <        if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
2331 <
2332 <      // Veto any PFmuon, or PFEle
2333 <      if (abs(pf->PFType()) == PFCandidate::eElectron || abs(pf->PFType()) == PFCandidate::eMuon) continue;
2334 <
2335 <      // Footprint Veto
2336 <      if (fabs(ele->SCluster()->Eta()) > 1.479 && dr < 0.015) continue;
2337 <
2338 <      if( ctrl.debug) cout << "charged:: pt: " << pf->Pt()
2339 <                           << "\ttype: " << pf->PFType()
2340 <                           << "\ttrk: " << pf->TrackerTrk() << endl;
2341 <
2342 <      fChargedIso += pf->Pt();
2343 <    }
2344 <
2345 <    //
2346 <    // Gamma Iso
2347 <    //
2348 <    else if (abs(pf->PFType()) == PFCandidate::eGamma) {
2349 <
2350 <      if (fabs(ele->SCluster()->Eta()) > 1.479) {
2351 <        if (mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta()) < 0.08) continue;
1927 >    bool vetoPhoton = false;
1928 >    for( int p=0; p<photonsToVeto.size(); p++ ) {
1929 >      if( pf == photonsToVeto[p] ) {
1930 >        vetoPhoton = true;
1931 >        break;
1932        }
1933 <      if( ctrl.debug) cout << "gamma:: " << pf->Pt() << " "
2354 <                           << dr << endl;
2355 <      // KH, add to sync
2356 <      //      if( pf->Pt() > 0.5 )
2357 <        fGammaIso += pf->Pt();
2358 <    }
2359 <
2360 <    //
2361 <    // Neutral Iso
2362 <    //
2363 <    else {
2364 <      if( ctrl.debug) cout << "neutral:: " << pf->Pt() << " "
2365 <                           << dr << endl;
2366 <      // KH, add to sync
2367 <      //      if( pf->Pt() > 0.5 )
2368 <        fNeutralHadronIso += pf->Pt();
2369 <    }
2370 <
2371 <    }
2372 <
2373 <  }
2374 <
2375 <  double rho = 0;
2376 < //   if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
2377 < //     rho = fPUEnergyDensity->At(0)->Rho();
2378 <  if (!(isnan(fPUEnergyDensity->At(0)->RhoLowEta()) || isinf(fPUEnergyDensity->At(0)->RhoLowEta())))
2379 <    rho = fPUEnergyDensity->At(0)->RhoLowEta();
2380 <
2381 <  // WARNING!!!!  
2382 <  // hardcode for sync ...
2383 <  EffectiveAreaVersion = eleT.kEleEAData2011;
2384 <  // WARNING!!!!  
2385 <
2386 <
2387 <  double pfIso = fChargedIso + fmax(0.0,(fGammaIso + fNeutralHadronIso
2388 <                                        -rho*eleT.ElectronEffectiveArea(eleT.kEleGammaAndNeutralHadronIso04,
2389 <                                                                   ele->Eta(),EffectiveAreaVersion)));
2390 <
2391 <  gChargedIso = fChargedIso;
2392 <  gGammaIso = fGammaIso;
2393 <  gNeutralIso = fNeutralHadronIso;  
2394 <
2395 <  return pfIso;
2396 < }
2397 <
2398 < //--------------------------------------------------------------------------------------------------
2399 < // hacked version
2400 < float electronPFIso04(ControlFlags &ctrl,
2401 <                      const mithep::Electron * ele,
2402 <                      const mithep::Vertex & vtx,
2403 <                      const mithep::Array<mithep::PFCandidate> * fPFCandidates,
2404 <                      float rho,
2405 <                      mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
2406 <                      vector<const mithep::Muon*> muonsToVeto,
2407 <                      vector<const mithep::Electron*> electronsToVeto)
2408 < //--------------------------------------------------------------------------------------------------
2409 < {
2410 <
2411 <  if( ctrl.debug ) {
2412 <    cout << "electronIsoMVASelection :: muons to veto " << endl;
2413 <    for( int i=0; i<muonsToVeto.size(); i++ ) {
2414 <      const mithep::Muon * vmu = muonsToVeto[i];
2415 <      cout << "\tpt: " << vmu->Pt()
2416 <           << "\teta: " << vmu->Eta()
2417 <           << "\tphi: " << vmu->Phi()
2418 <           << endl;
2419 <    }
2420 <    cout << "electronIsoMVASelection :: electrons to veto " << endl;
2421 <    for( int i=0; i<electronsToVeto.size(); i++ ) {
2422 <      const mithep::Electron * vel = electronsToVeto[i];
2423 <      cout << "\tpt: " << vel->Pt()
2424 <           << "\teta: " << vel->Eta()
2425 <           << "\tphi: " << vel->Phi()
2426 <           << "\ttrk: " << vel->TrackerTrk()
2427 <           << endl;
2428 <    }
2429 <  }
2430 <
2431 <
2432 <  //
2433 <  // final iso
2434 <  //
2435 <  Double_t fChargedIso = 0.0;
2436 <  Double_t fGammaIso = 0.0;
2437 <  Double_t fNeutralHadronIso = 0.0;
2438 <
2439 <
2440 <  //
2441 <  //Loop over PF Candidates
2442 <  //
2443 <  for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
2444 <
1933 >    } if( vetoPhoton ) continue;
1934  
2446    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
1935      Double_t deta = (ele->Eta() - pf->Eta());
1936 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(ele->Phi()),Double_t(pf->Phi()));
1937 <    Double_t dr = mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta());
1936 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(ele->Phi()),Double_t(pf->Phi()));
1937 >    Double_t dr = MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta());
1938  
1939      if (dr > 0.4) continue;
1940      if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
1941  
1942 <    if(ctrl.debug) {
1943 <      cout << "pf :: type: " << pf->PFType() << "\tpt: " << pf->Pt() << "\tdR: " << dr;
1944 <      if( pf->HasTrackerTrk() ) cout << "\tdZ: " << pf->TrackerTrk()->DzCorrected(vtx)
1945 <                                     << "\ttrk: " << pf->HasTrackerTrk()
1946 <                                     << "\tgsf: " << pf->HasGsfTrk();
1947 <      
1948 <      cout << endl;
2461 <    }
2462 <
2463 <
2464 <    //
2465 <    // sync : I don't think theyre doing this ...
2466 <    //
2467 <    //     if ( (pf->HasTrackerTrk() && (pf->TrackerTrk() == ele->TrackerTrk())) ||
2468 <    //   (pf->HasGsfTrk() && (pf->GsfTrk() == ele->GsfTrk()))) {
2469 <    //       if( ctrl.debug ) cout << "\tskipping, matches to the electron ..."  << endl;
2470 <    //       continue;
2471 <    //     }
2472 <
1942 >    // if(ctrl.debug) {
1943 >    //   cout << "    pf :: type: " << pf->PFType() << "\tpt: " << pf->Pt() << "\tdR: " << dr;
1944 >    //   if( pf->HasTrackerTrk() ) cout << "\tdZ: " << pf->TrackerTrk()->DzCorrected(*vtx)
1945 >    //                               << "\ttrk: " << pf->HasTrackerTrk()
1946 >    //                               << "\tgsf: " << pf->HasGsfTrk();
1947 >    //   cout << endl;
1948 >    // }
1949  
1950      //
1951      // Lepton Footprint Removal
# Line 2477 | Line 1953 | float electronPFIso04(ControlFlags &ctrl
1953      Bool_t IsLeptonFootprint = kFALSE;
1954      if (dr < 1.0) {
1955  
2480      //
2481      // Check for electrons
2482      //
2483      for (Int_t q=0; q < electronsToVeto.size(); ++q) {
2484        const mithep::Electron *tmpele = electronsToVeto[q];
2485        /*
2486        // 4l electron
2487        if( pf->HasTrackerTrk()  ) {
2488          if( pf->TrackerTrk() == tmpele->TrackerTrk() ) {
2489            if( ctrl.debug) cout << "\tcharged tktrk, matches 4L ele ..." << endl;
2490            IsLeptonFootprint = kTRUE;
2491          }
2492        }
2493        if( pf->HasGsfTrk()  ) {
2494          if( pf->GsfTrk() == tmpele->GsfTrk() ) {
2495            if( ctrl.debug) cout << "\tcharged gsftrk, matches 4L ele ..." << endl;
2496            IsLeptonFootprint = kTRUE;
2497          }
2498        }
2499        */
2500        // PF charged
2501        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) > 1.479
2502            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015) {
2503          if( ctrl.debug) cout << "\tcharged trk, dR matches 4L ele ..." << endl;
2504          IsLeptonFootprint = kTRUE;
2505        }
2506        // PF gamma
2507        if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) > 1.479
2508            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08) {
2509          if( ctrl.debug) cout << "\tPF gamma, matches 4L ele ..." << endl;
2510          IsLeptonFootprint = kTRUE;
2511        }
2512      } // loop over electrons
2513
2514      /* KH - comment for sync            
2515      //
2516      // Check for muons
2517      //
2518      for (Int_t q=0; q < muonsToVeto.size(); ++q) {
2519        const mithep::Muon *tmpmu = muonsToVeto[q];
2520        // 4l muon
2521        if( pf->HasTrackerTrk() ) {
2522          if (pf->TrackerTrk() == tmpmu->TrackerTrk() ){
2523            if( ctrl.debug) cout << "\tmatches 4L mu ..." << endl;
2524            IsLeptonFootprint = kTRUE;
2525          }
2526        }
2527        // PF charged
2528        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01) {
2529          if( ctrl.debug) cout << "\tcharged trk, dR matches 4L mu ..." << endl;
2530          IsLeptonFootprint = kTRUE;
2531        }
2532      } // loop over muons
2533      */
2534
2535    if (IsLeptonFootprint)
2536      continue;
1956  
1957      //
1958      // Charged Iso
1959      //
1960      if (pf->Charge() != 0 && (pf->HasTrackerTrk()||pf->HasGsfTrk()) ) {
1961  
2543 //       if( pf->HasTrackerTrk() )
2544 //      if (abs(pf->TrackerTrk()->DzCorrected(vtx)) > 0.2) continue;
2545 //       if( pf->HasGsfTrk() )
2546 //      if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
2547
1962        // Veto any PFmuon, or PFEle
1963        if (abs(pf->PFType()) == PFCandidate::eElectron || abs(pf->PFType()) == PFCandidate::eMuon) {
1964 <         cout << "\t skipping, pf is and ele or mu .." <<endl;
1964 >        // if( ctrl.debug ) cout << "    skipping, pf is an ele or mu .." <<endl;
1965          continue;
1966        }
1967  
1968        // Footprint Veto
1969        if (fabs(ele->SCluster()->Eta()) > 1.479 && dr < 0.015) continue;
1970  
1971 <      if( ctrl.debug) cout << "charged:: pt: " << pf->Pt()
1972 <                           << "\ttype: " << pf->PFType()
1973 <                           << "\ttrk: " << pf->TrackerTrk() << endl;
1971 >      // if( ctrl.debug) cout << "    charged:: pt: " << pf->Pt()
1972 >      //                           << "\ttype: " << pf->PFType()
1973 >      //                           << "\ttrk: " << pf->TrackerTrk() << endl;
1974  
1975        fChargedIso += pf->Pt();
1976      }
# Line 2567 | Line 1981 | float electronPFIso04(ControlFlags &ctrl
1981      else if (abs(pf->PFType()) == PFCandidate::eGamma) {
1982  
1983        if (fabs(ele->SCluster()->Eta()) > 1.479) {
1984 <        if (mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta()) < 0.08) continue;
1984 >        if (MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta()) < 0.08) continue;
1985        }
1986 <      if( ctrl.debug) cout << "gamma:: " << pf->Pt() << " "
1987 <                           << dr << endl;
1988 <      // KH, add to sync
1989 <      //      if( pf->Pt() > 0.5 )
1990 <        fGammaIso += pf->Pt();
1986 >
1987 >      assert(ele->HasSuperCluster());
1988 >      if(ele->GsfTrk()->NExpectedHitsInner()>0 && pf->MvaGamma() > 0.99 && pf->HasSCluster() && ele->SCluster() == pf->SCluster())      continue;
1989 >
1990 >
1991 >      // if( ctrl.debug) cout << "    gamma:: " << pf->Pt() << " "
1992 >      //                           << dr << endl;
1993 >
1994 >      fGammaIso += pf->Pt();
1995      }
1996  
1997      //
1998      // Neutral Iso
1999      //
2000      else {
2001 <      if( ctrl.debug) cout << "neutral:: " << pf->Pt() << " "
2002 <                           << dr << endl;
2003 <      // KH, add to sync
2586 <      //      if( pf->Pt() > 0.5 )
2587 <        fNeutralHadronIso += pf->Pt();
2001 >      // if( ctrl.debug) cout << "    neutral:: " << pf->Pt() << " "
2002 >      //                           << dr << endl;
2003 >      fNeutralHadronIso += pf->Pt();
2004      }
2005  
2006      }
2007  
2008    }
2009  
2594 //   double rho = 0;
2595 //   if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
2596 //     rho = fPUEnergyDensity->At(0)->Rho();
2597
2598  // WARNING!!!!  
2599  // hardcode for sync ...
2600  EffectiveAreaVersion = eleT.kEleEAData2011;
2601  // WARNING!!!!  
2010  
2011 +  double rho=0;
2012 +  if( (EffectiveAreaVersion == ElectronTools::kEleEAFall11MC) ||
2013 +      (EffectiveAreaVersion == ElectronTools::kEleEAData2011) ) {
2014 +    if (!(isnan(fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25()) ||
2015 +          isinf(fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25())))
2016 +      rho = fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25();
2017 +    // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
2018 +    EffectiveAreaVersion  = ElectronTools::kEleEAData2011;
2019 +    // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
2020 +  } else {
2021 +    if (!(isnan(fPUEnergyDensity->At(0)->RhoKt6PFJets()) ||
2022 +          isinf(fPUEnergyDensity->At(0)->RhoKt6PFJets())))
2023 +      rho = fPUEnergyDensity->At(0)->RhoKt6PFJets();
2024 +    // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
2025 +    EffectiveAreaVersion  = ElectronTools::kEleEAData2012;
2026 +    // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
2027 +  }
2028 +  // if(ctrl.debug) cout << "    rho: " << rho << endl;
2029  
2030    double pfIso = fChargedIso + fmax(0.0,(fGammaIso + fNeutralHadronIso
2031                                          -rho*eleT.ElectronEffectiveArea(eleT.kEleGammaAndNeutralHadronIso04,
# Line 2609 | Line 2035 | float electronPFIso04(ControlFlags &ctrl
2035    gChargedIso = fChargedIso;
2036    gGammaIso = fGammaIso;
2037    gNeutralIso = fNeutralHadronIso;  
2038 +
2039 +  if( ctrl.debug ) {
2040 +    cout << "    PFiso: " << pfIso
2041 +         << setw(6) << setprecision(4) << fChargedIso
2042 +         << setw(6) << setprecision(4) << fGammaIso
2043 +         << setw(6) << setprecision(4) << fNeutralHadronIso
2044 +         << endl;
2045 +  }
2046 +
2047    return pfIso;
2048   }
2049  
2615
2050   //--------------------------------------------------------------------------------------------------
2051   SelectionStatus electronReferenceIsoSelection(ControlFlags &ctrl,
2052 <                                              const mithep::Electron * ele,
2053 <                                              const mithep::Vertex & vtx,
2054 <                                              const mithep::Array<mithep::PFCandidate> * fPFCandidates,
2055 <                                              const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
2056 <                                              mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
2057 <                                              vector<const mithep::Muon*> muonsToVeto,
2624 <                                              vector<const mithep::Electron*> electronsToVeto)
2052 >                                              const Electron * ele,
2053 >                                              const Vertex * vtx,
2054 >                                              const Array<PFCandidate> * fPFCandidates,
2055 >                                              const Array<PileupEnergyDensity> * fPUEnergyDensity,
2056 >                                              ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
2057 >                                              vector<const PFCandidate*> photonsToVeto)
2058   //--------------------------------------------------------------------------------------------------
2059   {
2060  
2061    SelectionStatus status;
2062  
2063    double pfIso = electronPFIso04( ctrl, ele, vtx, fPFCandidates, fPUEnergyDensity,
2064 <                                  EffectiveAreaVersion, muonsToVeto ,electronsToVeto );
2632 <  //  cout << "--------------> setting electron isoPF04 to " << pfIso << endl;
2064 >                                  EffectiveAreaVersion, photonsToVeto);
2065    status.isoPF04 = pfIso;
2066    status.chisoPF04 = gChargedIso;
2067    status.gaisoPF04 = gGammaIso;
# Line 2642 | Line 2074 | SelectionStatus electronReferenceIsoSele
2074      status.orStatus(SelectionStatus::LOOSEISO);
2075      status.orStatus(SelectionStatus::TIGHTISO);
2076    }
2077 <  if(ctrl.debug) cout << "returning status : " << hex << status.getStatus() << dec << endl;
2077 >  if(ctrl.debug)
2078 >    cout << "  --> ele relpfIso: " << pfIso/ele->Pt() << ", returning status : " << hex << status.getStatus() << dec << endl;
2079    return status;
2647
2080   }
2649
2650
2081   //--------------------------------------------------------------------------------------------------
2082 < // hacked version
2083 < SelectionStatus electronReferenceIsoSelection(ControlFlags &ctrl,
2084 <                                              const mithep::Electron * ele,
2085 <                                              const mithep::Vertex & vtx,
2086 <                                              const mithep::Array<mithep::PFCandidate> * fPFCandidates,
2657 <                                              float rho,
2658 <                                              mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
2659 <                                              vector<const mithep::Muon*> muonsToVeto,
2660 <                                              vector<const mithep::Electron*> electronsToVeto)
2082 > double  isoDr03ForFsr(ControlFlags & ctrl,
2083 >                      const PFCandidate * photon,
2084 >                      const ChargedParticle * lep,
2085 >                      const Array<PFCandidate> * fPFCandidates,
2086 >                      bool doDBetaCorr)
2087   //--------------------------------------------------------------------------------------------------
2088 < {
2088 > {
2089  
2090 <  SelectionStatus status;
2090 >  //
2091 >  // final iso
2092 >  //
2093 >  Double_t fChargedIso  = 0.0;
2094 >  Double_t fGammaIso  = 0.0;
2095 >  Double_t fNeutralHadronIso  = 0.0;
2096 >  Double_t fpfPU  = 0.0;
2097  
2098 <  double pfIso = electronPFIso04( ctrl, ele, vtx, fPFCandidates, rho,
2099 <                                  EffectiveAreaVersion, muonsToVeto ,electronsToVeto );
2100 <  status.isoPF04 = pfIso;
2101 <  status.chisoPF04 = gChargedIso;
2670 <  status.gaisoPF04 = gGammaIso;
2671 <  status.neisoPF04 = gNeutralIso;
2672 <  bool pass = false;
2673 <  if( (pfIso/ele->Pt()) < ELECTRON_REFERENCE_PFISO_CUT ) pass = true;
2098 >  //
2099 >  // Loop over PF Candidates
2100 >  //
2101 >  for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
2102  
2103 <  if( pass ) {
2676 <    status.orStatus(SelectionStatus::LOOSEISO);
2677 <    status.orStatus(SelectionStatus::TIGHTISO);
2678 <  }
2679 <  if(ctrl.debug) cout << "returning status : " << hex << status.getStatus() << dec << endl;
2680 <  return status;
2103 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
2104  
2105 +    Double_t deta = (photon->Eta() - pf->Eta());
2106 +    Double_t dphi = MathUtils::DeltaPhi(Double_t(photon->Phi()),Double_t(pf->Phi()));
2107 +    Double_t dr = MathUtils::DeltaR(photon->Phi(),photon->Eta(), pf->Phi(), pf->Eta());
2108 +    if (dr > 0.3) continue;
2109 +
2110 +    if( !(PFnoPUflag[k]) && pf->Charge() != 0 ) {
2111 +      if( pf->Pt() >= 0.2 && dr > 0.01 )
2112 +        fpfPU += pf->Pt();
2113 +      continue;
2114 +    }
2115 +    
2116 +    //
2117 +    // skip this photon
2118 +    //
2119 +    if( abs(pf->PFType()) == PFCandidate::eGamma &&
2120 +        pf->Et() == photon->Et() ) continue;
2121 +    
2122 +      
2123 +    //
2124 +    // Charged Iso
2125 +    //
2126 +    if (pf->Charge() != 0 ) {
2127 +      if( dr > 0.01 && pf->Pt() >= 0.2 &&
2128 +          !(pf->TrackerTrk() == lep->TrackerTrk()) )
2129 +        fChargedIso += pf->Pt();
2130 +    }
2131 +    
2132 +    //
2133 +    // Gamma Iso
2134 +    //
2135 +    else if (abs(pf->PFType()) == PFCandidate::eGamma) {
2136 +      if( pf->Pt() > 0.5 && dr > 0.01)
2137 +        fGammaIso += pf->Pt();
2138 +    }
2139 +    
2140 +    //
2141 +    // Other Neutrals
2142 +    //
2143 +    else {
2144 +      if( pf->Pt() > 0.5 && dr > 0.01)
2145 +        fNeutralHadronIso += pf->Pt();
2146 +    }
2147 +    
2148 +  }
2149 +  
2150 +  if(ctrl.debug) cout << "      isoDr03ForFsr: " << setw(12) << fChargedIso << setw(12) << fGammaIso << setw(12) << fNeutralHadronIso << setw(12) << fpfPU << endl;
2151 +  double pfIso = fChargedIso + fGammaIso + fNeutralHadronIso + (doDBetaCorr ? -0.5 : 1)*fpfPU;
2152 +  return pfIso/photon->Pt();
2153   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines