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.27 by khahn, Mon May 28 16:34:44 2012 UTC vs.
Revision 1.34 by dkralph, Tue Oct 23 10:41:23 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 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 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 250 | Line 170 | bool noIso(ControlFlags &, vector<Simple
170          return true;
171   }
172  
253
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 274 | 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 341 | Line 260 | SelectionStatus muonIsoMVASelection(Cont
260  
261      if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
262  
263 <    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
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());
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;
# Line 360 | 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 372 | 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        
# Line 385 | Line 304 | SelectionStatus muonIsoMVASelection(Cont
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 595 | 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 610 | 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 618 | 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 685 | 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 704 | 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 716 | 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 729 | 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 939 | 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 948 | 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  
957
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,
966 <                    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    extern double gChargedIso;  
888    extern double  gGammaIso;      
889    extern double  gNeutralIso;
973  
974  if( ctrl.debug ) {
975    cout << "muonIsoMVASelection :: muons to veto " << endl;
976    for( int i=0; i<muonsToVeto.size(); i++ ) {
977      const mithep::Muon * vmu = muonsToVeto[i];
978      cout << "\tpt: " << vmu->Pt()
979           << "\teta: " << vmu->Eta()
980           << "\tphi: " << vmu->Phi()
981           << endl;
982    }
983    cout << "muonIsoMVASelection :: electrson to veto " << endl;
984    for( int i=0; i<electronsToVeto.size(); i++ ) {
985      const mithep::Electron * vel = electronsToVeto[i];
986      cout << "\tpt: " << vel->Pt()
987           << "\teta: " << vel->Eta()
988           << "\tphi: " << vel->Phi()
989           << endl;
990    }
991  }
890  
891    //
892    // final iso
# Line 1000 | 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) {
903  
904      if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
905 <    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
1007 <
1008 <    Double_t deta = (mu->Eta() - pf->Eta());
1009 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
1010 <    Double_t dr = mithep::MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
1011 <    if (dr > 0.4) continue;
1012 <
1013 <    if (pf->HasTrackerTrk() && (pf->TrackerTrk() == mu->TrackerTrk()) ) continue;
905 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
906  
907      //
908 <    // Lepton Footprint Removal
908 >    // veto FSR recovered photons
909 >    //
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( vetoPhoton ) continue;
917 >    //
918 >    //
919      //
1018    Bool_t IsLeptonFootprint = kFALSE;
1019    if (dr < 1.0) {
1020
1021      //
1022      // Check for electrons
1023      //
1024      for (Int_t q=0; q < electronsToVeto.size(); ++q) {
1025        const mithep::Electron *tmpele = electronsToVeto[q];
1026        // 4l electron
1027        if( pf->HasTrackerTrk() ) {
1028          if( pf->TrackerTrk() == tmpele->TrackerTrk() )
1029            IsLeptonFootprint = kTRUE;
1030        }
1031        if( pf->HasGsfTrk() ) {
1032          if( pf->GsfTrk() == tmpele->GsfTrk() )
1033            IsLeptonFootprint = kTRUE;
1034        }
1035        // PF charged
1036        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) > 1.479
1037            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015) {
1038          if( ctrl.debug) cout << "\tcharged trk, dR ("
1039                               << mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta())
1040                               << " matches 4L ele ..." << endl;
1041          IsLeptonFootprint = kTRUE;
1042        }
1043        // PF gamma
1044        if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) > 1.479
1045            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08)
1046          IsLeptonFootprint = kTRUE;
1047      } // loop over electrons
920  
921 <      /* KH - comment for sync      
922 <      //
923 <      // Check for muons
924 <      //
1053 <      for (Int_t q=0; q < muonsToVeto.size(); ++q) {
1054 <        const mithep::Muon *tmpmu = muonsToVeto[q];
1055 <        // 4l muon
1056 <        if( pf->HasTrackerTrk() ) {
1057 <          if( pf->TrackerTrk() == tmpmu->TrackerTrk() )
1058 <            IsLeptonFootprint = kTRUE;
1059 <        }
1060 <        // PF charged
1061 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01)
1062 <          IsLeptonFootprint = kTRUE;
1063 <      } // loop over muons
1064 <      */
921 >    Double_t deta = (mu->Eta() - 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 (IsLeptonFootprint)
1067 <      continue;
926 >    if (pf->HasTrackerTrk() && (pf->TrackerTrk() == mu->TrackerTrk()) ) continue;
927  
928      //
929      // Charged Iso
# Line 1073 | Line 932 | double  muonPFIso04(ControlFlags &ctrl,
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;
1076
1077
1078 //       if( pf->HasTrackerTrk() ) {
1079 //      if (abs(pf->TrackerTrk()->DzCorrected(vtx)) > 0.2) continue;
1080 //      if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
1081 //                            << abs(pf->TrackerTrk()->DzCorrected(vtx)) << " "
1082 //                            << dr << endl;
1083 //       }
1084 //       if( pf->HasGsfTrk() ) {
1085 //      if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
1086 //      if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
1087 //                            << abs(pf->GsfTrk()->DzCorrected(vtx)) << " "
1088 //                            << dr << endl;
1089 //       }
1090
1091
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      }
1112    
1113    }
1114    
955    }
956  
957    double rho=0;
958 <  if( (EffectiveAreaVersion == mithep::MuonTools::kMuEAFall11MC) ||
959 <      (EffectiveAreaVersion == mithep::MuonTools::kMuEAData2011) ) {
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  = mithep::MuonTools::kMuEAData2011;
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  = mithep::MuonTools::kMuEAData2011;
972 >    EffectiveAreaVersion  = MuonTools::kMuEAData2012;
973      // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
974    }
975 <  if(ctrl.debug) cout << "rho: " << rho << endl;
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    
1143  return pfIso;
1144 }
1145
1146
1147
1148
1149 //--------------------------------------------------------------------------------------------------
1150 // hacked version
1151 double  muonPFIso04(ControlFlags &ctrl,
1152                    const mithep::Muon * mu,
1153                    const mithep::Vertex * vtx,
1154                    const mithep::Array<mithep::PFCandidate> * fPFCandidates,
1155                    float rho,
1156                    mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
1157                    vector<const mithep::Muon*> muonsToVeto,
1158                    vector<const mithep::Electron*> electronsToVeto)
1159 //--------------------------------------------------------------------------------------------------
1160 {
1161
1162  extern double gChargedIso;  
1163  extern double  gGammaIso;      
1164  extern double  gNeutralIso;
1165  
994    if( ctrl.debug ) {
995 <    cout << "muonIsoMVASelection :: muons to veto " << endl;
996 <    for( int i=0; i<muonsToVeto.size(); i++ ) {
997 <      const mithep::Muon * vmu = muonsToVeto[i];
998 <      cout << "\tpt: " << vmu->Pt()
999 <           << "\teta: " << vmu->Eta()
1172 <           << "\tphi: " << vmu->Phi()
1173 <           << endl;
1174 <    }
1175 <    cout << "muonIsoMVASelection :: electrson to veto " << endl;
1176 <    for( int i=0; i<electronsToVeto.size(); i++ ) {
1177 <      const mithep::Electron * vel = electronsToVeto[i];
1178 <      cout << "\tpt: " << vel->Pt()
1179 <           << "\teta: " << vel->Eta()
1180 <           << "\tphi: " << vel->Phi()
1181 <           << endl;
1182 <    }
1183 <  }
1184 <
1185 <  //
1186 <  // final iso
1187 <  //
1188 <  Double_t fChargedIso  = 0.0;
1189 <  Double_t fGammaIso  = 0.0;
1190 <  Double_t fNeutralHadronIso  = 0.0;
1191 <
1192 <  //
1193 <  //Loop over PF Candidates
1194 <  //
1195 <  for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
1196 <
1197 <    if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
1198 <    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
1199 <
1200 <    Double_t deta = (mu->Eta() - pf->Eta());
1201 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(mu->Phi()),Double_t(pf->Phi()));
1202 <    Double_t dr = mithep::MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
1203 <    if (dr > 0.4) continue;
1204 <
1205 <    if (pf->HasTrackerTrk() && (pf->TrackerTrk() == mu->TrackerTrk()) ) continue;
1206 <
1207 <    //
1208 <    // Lepton Footprint Removal
1209 <    //
1210 <    Bool_t IsLeptonFootprint = kFALSE;
1211 <    if (dr < 1.0) {
1212 <
1213 <      //
1214 <      // Check for electrons
1215 <      //
1216 <      for (Int_t q=0; q < electronsToVeto.size(); ++q) {
1217 <        const mithep::Electron *tmpele = electronsToVeto[q];
1218 <        // 4l electron
1219 <        if( pf->HasTrackerTrk() ) {
1220 <          if( pf->TrackerTrk() == tmpele->TrackerTrk() )
1221 <            IsLeptonFootprint = kTRUE;
1222 <        }
1223 <        if( pf->HasGsfTrk() ) {
1224 <          if( pf->GsfTrk() == tmpele->GsfTrk() )
1225 <            IsLeptonFootprint = kTRUE;
1226 <        }
1227 <        // PF charged
1228 <        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) > 1.479
1229 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015)
1230 <          IsLeptonFootprint = kTRUE;
1231 <        // PF gamma
1232 <        if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) > 1.479
1233 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08)
1234 <          IsLeptonFootprint = kTRUE;
1235 <      } // loop over electrons
1236 <
1237 <      /* KH - comment for sync      
1238 <      //
1239 <      // Check for muons
1240 <      //
1241 <      for (Int_t q=0; q < muonsToVeto.size(); ++q) {
1242 <        const mithep::Muon *tmpmu = muonsToVeto[q];
1243 <        // 4l muon
1244 <        if( pf->HasTrackerTrk() ) {
1245 <          if( pf->TrackerTrk() == tmpmu->TrackerTrk() )
1246 <            IsLeptonFootprint = kTRUE;
1247 <        }
1248 <        // PF charged
1249 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01)
1250 <          IsLeptonFootprint = kTRUE;
1251 <      } // loop over muons
1252 <      */
1253 <
1254 <    if (IsLeptonFootprint)
1255 <      continue;
1256 <
1257 <    //
1258 <    // Charged Iso
1259 <    //
1260 <    if (pf->Charge() != 0 && (pf->HasTrackerTrk()||pf->HasGsfTrk()) ) {
1261 <
1262 <      //if( dr < 0.01 ) continue; // only for muon iso mva?
1263 <      if (abs(pf->PFType()) == PFCandidate::eElectron || abs(pf->PFType()) == PFCandidate::eMuon) continue;
1264 <
1265 <
1266 < //       if( pf->HasTrackerTrk() ) {
1267 < //      if (abs(pf->TrackerTrk()->DzCorrected(vtx)) > 0.2) continue;
1268 < //      if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
1269 < //                            << abs(pf->TrackerTrk()->DzCorrected(vtx)) << " "
1270 < //                            << dr << endl;
1271 < //       }
1272 < //       if( pf->HasGsfTrk() ) {
1273 < //      if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
1274 < //      if( ctrl.debug ) cout << "charged:: " << pf->PFType() << " " << pf->Pt() << " "
1275 < //                            << abs(pf->GsfTrk()->DzCorrected(vtx)) << " "
1276 < //                            << dr << endl;
1277 < //       }
1278 <
1279 <
1280 <      fChargedIso += pf->Pt();
1281 <    }
1282 <
1283 <    //
1284 <    // Gamma Iso
1285 <    //
1286 <    else if (abs(pf->PFType()) == PFCandidate::eGamma) {
1287 <      // KH, add to sync
1288 <      if( pf->Pt() > 0.5 )
1289 <      fGammaIso += pf->Pt();
1290 <    }
1291 <
1292 <    //
1293 <    // Other Neutrals
1294 <    //
1295 <    else {
1296 <      // KH, add to sync
1297 <      if( pf->Pt() > 0.5 )
1298 <        fNeutralHadronIso += pf->Pt();
1299 <    }
1300 <    
1301 <    }
1302 <    
995 >    cout << "    PFiso: " << pfIso
996 >         << "\tfChargedIso: " << fChargedIso
997 >         << "\tfGammaIso: " << fGammaIso
998 >         << "\tfNeutralHadronIso: " << fNeutralHadronIso
999 >         << endl;
1000    }
1304  
1305 //   double rho = 0;
1306 //   if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
1307 //     rho = fPUEnergyDensity->At(0)->Rho();
1308
1309  // WARNING!!!!  
1310  // hardcode for sync ...
1311  EffectiveAreaVersion = muT.kMuEAData2011;
1312  // WARNING!!!!  
1313
1001  
1315  double pfIso = fChargedIso + fmax(0.0,(fGammaIso + fNeutralHadronIso
1316                                        -rho*muT.MuonEffectiveArea(muT.kMuGammaAndNeutralHadronIso04,
1317                                                                   mu->Eta(),EffectiveAreaVersion)));
1318  gChargedIso = fChargedIso;
1319  gGammaIso   = fGammaIso;
1320  gNeutralIso = fNeutralHadronIso;
1321  
1002    return pfIso;
1003   }
1004  
1325
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,
1334 <                                          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 );
1342 <  //  cout << "--------------> setting muon isoPF04 to" << pfIso << endl;
1019 >                              EffectiveAreaVersion, photonsToVeto);
1020    status.isoPF04 = pfIso;
1021    status.chisoPF04 = gChargedIso;
1022    status.gaisoPF04 = gGammaIso;
# Line 1352 | 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;
1357  
1035   }
1036  
1360
1361 //--------------------------------------------------------------------------------------------------
1362 // hacked version
1363 SelectionStatus muonReferenceIsoSelection(ControlFlags &ctrl,
1364                                          const mithep::Muon * mu,
1365                                          const mithep::Vertex * vtx,
1366                                          const mithep::Array<mithep::PFCandidate> * fPFCandidates,
1367                                          float rho,
1368                                          mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion,
1369                                          vector<const mithep::Muon*> muonsToVeto,
1370                                          vector<const mithep::Electron*> electronsToVeto)
1371 //--------------------------------------------------------------------------------------------------
1372 {
1373  
1374  SelectionStatus status;
1375  
1376  double pfIso = muonPFIso04( ctrl, mu, vtx, fPFCandidates, rho,
1377                              EffectiveAreaVersion, muonsToVeto ,electronsToVeto );
1378
1379  status.isoPF04 = pfIso;
1380  status.chisoPF04 = gChargedIso;
1381  status.gaisoPF04 = gGammaIso;
1382  status.neisoPF04 = gNeutralIso;
1383
1384  bool pass = false;
1385  if( (pfIso/mu->Pt()) < MUON_REFERENCE_PFISO_CUT ) pass = true;
1386  
1387  if( pass ) {
1388    status.orStatus(SelectionStatus::LOOSEISO);
1389    status.orStatus(SelectionStatus::TIGHTISO);
1390  }
1391  if(ctrl.debug) cout << "returning status : " << hex << status.getStatus() << dec << endl;
1392  return status;
1393  
1394 }
1395
1396
1397
1398
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 1419 | 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 1483 | 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());
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) {
# Line 1512 | Line 1150 | SelectionStatus electronIsoMVASelection(
1150        //
1151  
1152        for (Int_t q=0; q < electronsToVeto.size(); ++q) {
1153 <        const mithep::Electron *tmpele = electronsToVeto[q];
1154 <        double tmpdr = mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta());
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()  ) {
# Line 1547 | Line 1185 | SelectionStatus electronIsoMVASelection(
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 1556 | 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 1817 | Line 1455 | SelectionStatus electronIsoMVASelection(
1455  
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 1835 | 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 1843 | 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 1907 | 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) {
# Line 1936 | 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 1971 | 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 1980 | 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 2242 | 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  
# Line 2258 | Line 1896 | void initElectronIsoMVA() {
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,
2267 <                      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   {
2270  /*
2271  if( ctrl.debug ) {
2272    cout << "electronIsoMVASelection :: muons to veto " << endl;
2273    for( int i=0; i<muonsToVeto.size(); i++ ) {
2274      const mithep::Muon * vmu = muonsToVeto[i];
2275      cout << "\tpt: " << vmu->Pt()
2276           << "\teta: " << vmu->Eta()
2277           << "\tphi: " << vmu->Phi()
2278           << endl;
2279    }
2280    cout << "electronIsoMVASelection :: electrons to veto " << endl;
2281    for( int i=0; i<electronsToVeto.size(); i++ ) {
2282      const mithep::Electron * vel = electronsToVeto[i];
2283      cout << "\tpt: " << vel->Pt()
2284           << "\teta: " << vel->Eta()
2285           << "\tphi: " << vel->Phi()
2286           << "\ttrk: " << vel->TrackerTrk()
2287           << endl;
2288    }
2289  }
2290  */
1907  
1908    //
1909    // final iso
# Line 2300 | 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) {
1921  
1922 +    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
1923 +
1924 +    //
1925 +    // veto FSR recovered photons
1926 +    //
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( vetoPhoton ) continue;
1934  
2306    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;
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();
2319      
1947        cout << endl;
1948      }
1949  
2323
1950      //
1951      // sync : I don't think theyre doing this ...
1952      //
# Line 2337 | Line 1963 | float electronPFIso04(ControlFlags &ctrl
1963      Bool_t IsLeptonFootprint = kFALSE;
1964      if (dr < 1.0) {
1965  
2340      //
2341      // Check for electrons
2342      //
2343      for (Int_t q=0; q < electronsToVeto.size(); ++q) {
2344        const mithep::Electron *tmpele = electronsToVeto[q];
2345        /*
2346        // 4l electron
2347        if( pf->HasTrackerTrk()  ) {
2348          if( pf->TrackerTrk() == tmpele->TrackerTrk() ) {
2349            if( ctrl.debug) cout << "\tcharged tktrk, matches 4L ele ..." << endl;
2350            IsLeptonFootprint = kTRUE;
2351          }
2352        }
2353        if( pf->HasGsfTrk()  ) {
2354          if( pf->GsfTrk() == tmpele->GsfTrk() ) {
2355            if( ctrl.debug) cout << "\tcharged gsftrk, matches 4L ele ..." << endl;
2356            IsLeptonFootprint = kTRUE;
2357          }
2358        }
2359        */
2360        // PF charged
2361        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) > 1.479
2362            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015) {
2363          if( ctrl.debug) cout << "\tcharged trk, dR matches 4L ele ..." << endl;
2364          IsLeptonFootprint = kTRUE;
2365        }
2366        // PF gamma
2367        if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) > 1.479
2368            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08) {
2369          if( ctrl.debug) cout << "\tPF gamma, matches 4L ele ..." << endl;
2370          IsLeptonFootprint = kTRUE;
2371        }
2372      } // loop over electrons
2373
2374      /* KH - comment for sync            
2375      //
2376      // Check for muons
2377      //
2378      for (Int_t q=0; q < muonsToVeto.size(); ++q) {
2379        const mithep::Muon *tmpmu = muonsToVeto[q];
2380        // 4l muon
2381        if( pf->HasTrackerTrk() ) {
2382          if (pf->TrackerTrk() == tmpmu->TrackerTrk() ){
2383            if( ctrl.debug) cout << "\tmatches 4L mu ..." << endl;
2384            IsLeptonFootprint = kTRUE;
2385          }
2386        }
2387        // PF charged
2388        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01) {
2389          if( ctrl.debug) cout << "\tcharged trk, dR matches 4L mu ..." << endl;
2390          IsLeptonFootprint = kTRUE;
2391        }
2392      } // loop over muons
2393      */
2394
2395    if (IsLeptonFootprint)
2396      continue;
1966  
1967      //
1968      // Charged Iso
1969      //
1970      if (pf->Charge() != 0 && (pf->HasTrackerTrk()||pf->HasGsfTrk()) ) {
1971  
2403 //       if( pf->HasTrackerTrk() )
2404 //      if (abs(pf->TrackerTrk()->DzCorrected(vtx)) > 0.2) continue;
2405 //       if( pf->HasGsfTrk() )
2406 //      if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
2407
1972        // Veto any PFmuon, or PFEle
1973        if (abs(pf->PFType()) == PFCandidate::eElectron || abs(pf->PFType()) == PFCandidate::eMuon) {
1974 <        if( ctrl.debug ) cout << "\t skipping, pf is and ele or mu .." <<endl;
1974 >        if( ctrl.debug ) cout << "    skipping, pf is an ele or mu .." <<endl;
1975          continue;
1976        }
1977  
1978        // Footprint Veto
1979        if (fabs(ele->SCluster()->Eta()) > 1.479 && dr < 0.015) continue;
1980  
1981 <      if( ctrl.debug) cout << "charged:: pt: " << pf->Pt()
1981 >      if( ctrl.debug) cout << "    charged:: pt: " << pf->Pt()
1982                             << "\ttype: " << pf->PFType()
1983                             << "\ttrk: " << pf->TrackerTrk() << endl;
1984  
# Line 2427 | Line 1991 | float electronPFIso04(ControlFlags &ctrl
1991      else if (abs(pf->PFType()) == PFCandidate::eGamma) {
1992  
1993        if (fabs(ele->SCluster()->Eta()) > 1.479) {
1994 <        if (mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta()) < 0.08) continue;
1994 >        if (MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta()) < 0.08) continue;
1995        }
1996 <      if( ctrl.debug) cout << "gamma:: " << pf->Pt() << " "
1996 >
1997 >      assert(ele->HasSuperCluster());
1998 >      if(ele->GsfTrk()->NExpectedHitsInner()>0 && pf->MvaGamma() > 0.99 && pf->HasSCluster() && ele->SCluster() == pf->SCluster())      continue;
1999 >
2000 >
2001 >      if( ctrl.debug) cout << "    gamma:: " << pf->Pt() << " "
2002                             << dr << endl;
2003        // KH, add to sync
2004        //      if( pf->Pt() > 0.5 )
# Line 2440 | Line 2009 | float electronPFIso04(ControlFlags &ctrl
2009      // Neutral Iso
2010      //
2011      else {
2012 <      if( ctrl.debug) cout << "neutral:: " << pf->Pt() << " "
2012 >      if( ctrl.debug) cout << "    neutral:: " << pf->Pt() << " "
2013                             << dr << endl;
2014        // KH, add to sync
2015        //      if( pf->Pt() > 0.5 )
# Line 2453 | Line 2022 | float electronPFIso04(ControlFlags &ctrl
2022  
2023  
2024    double rho=0;
2025 <  if( (EffectiveAreaVersion == mithep::ElectronTools::kEleEAFall11MC) ||
2026 <      (EffectiveAreaVersion == mithep::ElectronTools::kEleEAData2011) ) {
2025 >  if( (EffectiveAreaVersion == ElectronTools::kEleEAFall11MC) ||
2026 >      (EffectiveAreaVersion == ElectronTools::kEleEAData2011) ) {
2027      if (!(isnan(fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25()) ||
2028            isinf(fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25())))
2029        rho = fPUEnergyDensity->At(0)->RhoKt6PFJetsForIso25();
2030      // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
2031 <    EffectiveAreaVersion  = mithep::ElectronTools::kEleEAData2011;
2031 >    EffectiveAreaVersion  = ElectronTools::kEleEAData2011;
2032      // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
2033    } else {
2034      if (!(isnan(fPUEnergyDensity->At(0)->RhoKt6PFJets()) ||
2035            isinf(fPUEnergyDensity->At(0)->RhoKt6PFJets())))
2036        rho = fPUEnergyDensity->At(0)->RhoKt6PFJets();
2037      // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
2038 <    EffectiveAreaVersion  = mithep::ElectronTools::kEleEAData2011;
2038 >    EffectiveAreaVersion  = ElectronTools::kEleEAData2012;
2039      // !!!!!!!!!!!!! TMP HACK FOR SYNC !!!!!!!!!!!!!!!!!!!!!
2040    }
2041 <  if(ctrl.debug) cout << "rho: " << rho << endl;
2041 >  if(ctrl.debug) cout << "    rho: " << rho << endl;
2042  
2043    double pfIso = fChargedIso + fmax(0.0,(fGammaIso + fNeutralHadronIso
2044                                          -rho*eleT.ElectronEffectiveArea(eleT.kEleGammaAndNeutralHadronIso04,
# Line 2479 | Line 2048 | float electronPFIso04(ControlFlags &ctrl
2048    gChargedIso = fChargedIso;
2049    gGammaIso = fGammaIso;
2050    gNeutralIso = fNeutralHadronIso;  
2482  return pfIso;
2483 }
2051  
2052 +  if( ctrl.debug ) {
2053 +    cout << "    PFiso: " << pfIso
2054 +         << "\tfChargedIso: " << fChargedIso
2055 +         << "\tfGammaIso: " << fGammaIso
2056 +         << "\tfNeutralHadronIso: " << fNeutralHadronIso
2057 +         << endl;
2058 +  }
2059  
2060 +  return pfIso;
2061 + }
2062  
2063   //--------------------------------------------------------------------------------------------------
2064 < // hacked version
2065 < float electronPFIso04(ControlFlags &ctrl,
2066 <                      const mithep::Electron * ele,
2067 <                      const mithep::Vertex * vtx,
2068 <                      const mithep::Array<mithep::PFCandidate> * fPFCandidates,
2069 <                      float rho,
2070 <                      mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
2495 <                      vector<const mithep::Muon*> muonsToVeto,
2496 <                      vector<const mithep::Electron*> electronsToVeto)
2064 > SelectionStatus electronReferenceIsoSelection(ControlFlags &ctrl,
2065 >                                              const Electron * ele,
2066 >                                              const Vertex * vtx,
2067 >                                              const Array<PFCandidate> * fPFCandidates,
2068 >                                              const Array<PileupEnergyDensity> * fPUEnergyDensity,
2069 >                                              ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
2070 >                                              vector<const PFCandidate*> photonsToVeto)
2071   //--------------------------------------------------------------------------------------------------
2072 < {
2072 > {
2073  
2074 <  if( ctrl.debug ) {
2075 <    cout << "electronIsoMVASelection :: muons to veto " << endl;
2076 <    for( int i=0; i<muonsToVeto.size(); i++ ) {
2077 <      const mithep::Muon * vmu = muonsToVeto[i];
2078 <      cout << "\tpt: " << vmu->Pt()
2079 <           << "\teta: " << vmu->Eta()
2080 <           << "\tphi: " << vmu->Phi()
2081 <           << endl;
2082 <    }
2083 <    cout << "electronIsoMVASelection :: electrons to veto " << endl;
2084 <    for( int i=0; i<electronsToVeto.size(); i++ ) {
2085 <      const mithep::Electron * vel = electronsToVeto[i];
2086 <      cout << "\tpt: " << vel->Pt()
2087 <           << "\teta: " << vel->Eta()
2088 <           << "\tphi: " << vel->Phi()
2515 <           << "\ttrk: " << vel->TrackerTrk()
2516 <           << endl;
2517 <    }
2074 >  SelectionStatus status;
2075 >
2076 >  double pfIso = electronPFIso04( ctrl, ele, vtx, fPFCandidates, fPUEnergyDensity,
2077 >                                  EffectiveAreaVersion, photonsToVeto);
2078 >  status.isoPF04 = pfIso;
2079 >  status.chisoPF04 = gChargedIso;
2080 >  status.gaisoPF04 = gGammaIso;
2081 >  status.neisoPF04 = gNeutralIso;
2082 >
2083 >  bool pass = false;
2084 >  if( (pfIso/ele->Pt()) < ELECTRON_REFERENCE_PFISO_CUT ) pass = true;
2085 >
2086 >  if( pass ) {
2087 >    status.orStatus(SelectionStatus::LOOSEISO);
2088 >    status.orStatus(SelectionStatus::TIGHTISO);
2089    }
2090 +  if(ctrl.debug)
2091 +    cout << "  --> ele relpfIso: " << pfIso/ele->Pt() << ", returning status : " << hex << status.getStatus() << dec << endl;
2092 +  return status;
2093 + }
2094  
2095 + //--------------------------------------------------------------------------------------------------
2096 + double  dbetaCorrectedIsoDr03(ControlFlags & ctrl,
2097 +                              const PFCandidate * photon,
2098 +                              const Muon * lepton,
2099 +                              const Array<PFCandidate> * fPFCandidates)
2100 + //--------------------------------------------------------------------------------------------------
2101 + {
2102  
2103    //
2104 <  // final iso
2104 >  // final iso
2105    //
2106 <  Double_t fChargedIso = 0.0;
2107 <  Double_t fGammaIso = 0.0;
2108 <  Double_t fNeutralHadronIso = 0.0;
2109 <
2106 >  Double_t fChargedIso  = 0.0;
2107 >  Double_t fGammaIso  = 0.0;
2108 >  Double_t fNeutralHadronIso  = 0.0;
2109 >  Double_t fpfPU  = 0.0;
2110  
2111    //
2112 <  //Loop over PF Candidates
2112 >  // Loop over PF Candidates
2113    //
2114    for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
2115  
2116 <
2117 <    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*fPFCandidates)[k]);
2118 <    Double_t deta = (ele->Eta() - pf->Eta());
2119 <    Double_t dphi = mithep::MathUtils::DeltaPhi(Double_t(ele->Phi()),Double_t(pf->Phi()));
2120 <    Double_t dr = mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta());
2121 <
2122 <    if (dr > 0.4) continue;
2123 <    if( !(PFnoPUflag[k]) ) continue; // my PF no PU hack
2124 <
2125 <    if(ctrl.debug) {
2126 <      cout << "pf :: type: " << pf->PFType() << "\tpt: " << pf->Pt() << "\tdR: " << dr;
2545 <      if( pf->HasTrackerTrk() ) cout << "\tdZ: " << pf->TrackerTrk()->DzCorrected(*vtx)
2546 <                                     << "\ttrk: " << pf->HasTrackerTrk()
2547 <                                     << "\tgsf: " << pf->HasGsfTrk();
2548 <      
2549 <      cout << endl;
2116 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
2117 >    
2118 >    Double_t deta = (photon->Eta() - pf->Eta());
2119 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(photon->Phi()),Double_t(pf->Phi()));
2120 >    Double_t dr = MathUtils::DeltaR(photon->Phi(),photon->Eta(), pf->Phi(), pf->Eta());
2121 >    if (dr > 0.3) continue;
2122 >
2123 >    if( !(PFnoPUflag[k]) && pf->Charge() != 0 ) {
2124 >      if( pf->Pt() >= 0.2 && dr > 0.01 )
2125 >        fpfPU += pf->Pt();
2126 >      continue;
2127      }
2128 <
2552 <
2128 >    
2129      //
2130 <    // sync : I don't think theyre doing this ...
2130 >    // skip this photon
2131      //
2132 <    //     if ( (pf->HasTrackerTrk() && (pf->TrackerTrk() == ele->TrackerTrk())) ||
2133 <    //   (pf->HasGsfTrk() && (pf->GsfTrk() == ele->GsfTrk()))) {
2134 <    //       if( ctrl.debug ) cout << "\tskipping, matches to the electron ..."  << endl;
2135 <    //       continue;
2560 <    //     }
2561 <
2562 <
2132 >    if( abs(pf->PFType()) == PFCandidate::eGamma &&
2133 >        pf->Et() == photon->Et() ) continue;
2134 >    
2135 >      
2136      //
2137 <    // Lepton Footprint Removal
2137 >    // Charged Iso
2138      //
2139 <    Bool_t IsLeptonFootprint = kFALSE;
2140 <    if (dr < 1.0) {
2141 <
2142 <      //
2143 <      // Check for electrons
2144 <      //
2572 <      for (Int_t q=0; q < electronsToVeto.size(); ++q) {
2573 <        const mithep::Electron *tmpele = electronsToVeto[q];
2574 <        /*
2575 <        // 4l electron
2576 <        if( pf->HasTrackerTrk()  ) {
2577 <          if( pf->TrackerTrk() == tmpele->TrackerTrk() ) {
2578 <            if( ctrl.debug) cout << "\tcharged tktrk, matches 4L ele ..." << endl;
2579 <            IsLeptonFootprint = kTRUE;
2580 <          }
2581 <        }
2582 <        if( pf->HasGsfTrk()  ) {
2583 <          if( pf->GsfTrk() == tmpele->GsfTrk() ) {
2584 <            if( ctrl.debug) cout << "\tcharged gsftrk, matches 4L ele ..." << endl;
2585 <            IsLeptonFootprint = kTRUE;
2586 <          }
2587 <        }
2588 <        */
2589 <        // PF charged
2590 <        if (pf->Charge() != 0 && fabs(tmpele->SCluster()->Eta()) > 1.479
2591 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.015) {
2592 <          if( ctrl.debug) cout << "\tcharged trk, dR matches 4L ele ..." << endl;
2593 <          IsLeptonFootprint = kTRUE;
2594 <        }
2595 <        // PF gamma
2596 <        if (abs(pf->PFType()) == PFCandidate::eGamma && fabs(tmpele->SCluster()->Eta()) > 1.479
2597 <            && mithep::MathUtils::DeltaR(tmpele->Phi(),tmpele->Eta(), pf->Phi(), pf->Eta()) < 0.08) {
2598 <          if( ctrl.debug) cout << "\tPF gamma, matches 4L ele ..." << endl;
2599 <          IsLeptonFootprint = kTRUE;
2600 <        }
2601 <      } // loop over electrons
2602 <
2603 <      /* KH - comment for sync            
2604 <      //
2605 <      // Check for muons
2606 <      //
2607 <      for (Int_t q=0; q < muonsToVeto.size(); ++q) {
2608 <        const mithep::Muon *tmpmu = muonsToVeto[q];
2609 <        // 4l muon
2610 <        if( pf->HasTrackerTrk() ) {
2611 <          if (pf->TrackerTrk() == tmpmu->TrackerTrk() ){
2612 <            if( ctrl.debug) cout << "\tmatches 4L mu ..." << endl;
2613 <            IsLeptonFootprint = kTRUE;
2614 <          }
2615 <        }
2616 <        // PF charged
2617 <        if (pf->Charge() != 0 && mithep::MathUtils::DeltaR(tmpmu->Phi(),tmpmu->Eta(), pf->Phi(), pf->Eta()) < 0.01) {
2618 <          if( ctrl.debug) cout << "\tcharged trk, dR matches 4L mu ..." << endl;
2619 <          IsLeptonFootprint = kTRUE;
2620 <        }
2621 <      } // loop over muons
2622 <      */
2623 <
2624 <    if (IsLeptonFootprint)
2625 <      continue;
2626 <
2139 >    if (pf->Charge() != 0 ) {
2140 >      if( dr > 0.01 && pf->Pt() >= 0.2 &&
2141 >          !(pf->TrackerTrk() == lepton->TrackerTrk()) )
2142 >        fChargedIso += pf->Pt();
2143 >    }
2144 >    
2145      //
2146 <    // Charged Iso
2146 >    // Gamma Iso
2147      //
2148 <    if (pf->Charge() != 0 && (pf->HasTrackerTrk()||pf->HasGsfTrk()) ) {
2148 >    else if (abs(pf->PFType()) == PFCandidate::eGamma) {
2149 >      if( pf->Pt() > 0.5 && dr > 0.01)
2150 >        fGammaIso += pf->Pt();
2151 >    }
2152 >    
2153 >    //
2154 >    // Other Neutrals
2155 >    //
2156 >    else {
2157 >      if( pf->Pt() > 0.5 && dr > 0.01)
2158 >        fNeutralHadronIso += pf->Pt();
2159 >    }
2160 >    
2161 >  }
2162 >  
2163 >  if( ctrl.debug ) {
2164 >    cout << "  ---> photon dbetaIso :: " << endl;
2165 >    cout << "\tfChargedIso: " << fChargedIso
2166 >         << "\tfGammaIso: " << fGammaIso
2167 >         << "\tfNeutralHadronIso: " << fNeutralHadronIso
2168 >         << "\tfpfPU: " << fpfPU
2169 >         << endl;
2170 >  }
2171 >  double pfIso = fChargedIso + fGammaIso + fNeutralHadronIso - 0.5*fpfPU;
2172 >  return pfIso/photon->Pt();
2173 > }
2174  
2632 //       if( pf->HasTrackerTrk() )
2633 //      if (abs(pf->TrackerTrk()->DzCorrected(vtx)) > 0.2) continue;
2634 //       if( pf->HasGsfTrk() )
2635 //      if (abs(pf->GsfTrk()->DzCorrected(vtx)) > 0.2) continue;
2175  
2176 <      // Veto any PFmuon, or PFEle
2177 <      if (abs(pf->PFType()) == PFCandidate::eElectron || abs(pf->PFType()) == PFCandidate::eMuon) {
2178 <        if( ctrl.debug ) cout << "\t skipping, pf is and ele or mu .." <<endl;
2179 <        continue;
2180 <      }
2176 > //--------------------------------------------------------------------------------------------------
2177 > double  dbetaCorrectedIsoDr03(ControlFlags & ctrl,
2178 >                              const PFCandidate * photon,
2179 >                              const Electron * lepton,
2180 >                              const Array<PFCandidate> * fPFCandidates)
2181 > //--------------------------------------------------------------------------------------------------
2182 > {
2183  
2184 <      // Footprint Veto
2185 <      if (fabs(ele->SCluster()->Eta()) > 1.479 && dr < 0.015) continue;
2184 >  //
2185 >  // final iso
2186 >  //
2187 >  Double_t fChargedIso  = 0.0;
2188 >  Double_t fGammaIso  = 0.0;
2189 >  Double_t fNeutralHadronIso  = 0.0;
2190 >  Double_t fpfPU  = 0.0;
2191  
2192 <      if( ctrl.debug) cout << "charged:: pt: " << pf->Pt()
2193 <                           << "\ttype: " << pf->PFType()
2194 <                           << "\ttrk: " << pf->TrackerTrk() << endl;
2192 >  //
2193 >  // Loop over PF Candidates
2194 >  //
2195 >  for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
2196  
2197 <      fChargedIso += pf->Pt();
2197 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
2198 >    
2199 >    Double_t deta = (photon->Eta() - pf->Eta());
2200 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(photon->Phi()),Double_t(pf->Phi()));
2201 >    Double_t dr = MathUtils::DeltaR(photon->Phi(),photon->Eta(), pf->Phi(), pf->Eta());
2202 >    if (dr > 0.3) continue;
2203 >
2204 >    if( !(PFnoPUflag[k]) && pf->Charge() != 0 ) {
2205 >      if( pf->Pt() >= 0.2 && dr > 0.01 )
2206 >        fpfPU += pf->Pt();
2207 >      continue;
2208      }
2209 <
2209 >    
2210 >    //
2211 >    // skip this photon
2212 >    //
2213 >    if( abs(pf->PFType()) == PFCandidate::eGamma &&
2214 >        pf->Et() == photon->Et() ) continue;
2215 >    
2216 >      
2217 >    //
2218 >    // Charged Iso
2219 >    //
2220 >    if (pf->Charge() != 0 ) {
2221 >      if( dr > 0.01 && pf->Pt() >= 0.2 &&
2222 >          !(pf->TrackerTrk() == lepton->TrackerTrk()) )
2223 >        fChargedIso += pf->Pt();
2224 >    }
2225 >    
2226      //
2227      // Gamma Iso
2228      //
2229      else if (abs(pf->PFType()) == PFCandidate::eGamma) {
2230 <
2658 <      if (fabs(ele->SCluster()->Eta()) > 1.479) {
2659 <        if (mithep::MathUtils::DeltaR(ele->Phi(),ele->Eta(), pf->Phi(), pf->Eta()) < 0.08) continue;
2660 <      }
2661 <      if( ctrl.debug) cout << "gamma:: " << pf->Pt() << " "
2662 <                           << dr << endl;
2663 <      // KH, add to sync
2664 <      //      if( pf->Pt() > 0.5 )
2230 >      if( pf->Pt() > 0.5 && dr > 0.01)
2231          fGammaIso += pf->Pt();
2232      }
2233 <
2233 >    
2234      //
2235 <    // Neutral Iso
2235 >    // Other Neutrals
2236      //
2237      else {
2238 <      if( ctrl.debug) cout << "neutral:: " << pf->Pt() << " "
2673 <                           << dr << endl;
2674 <      // KH, add to sync
2675 <      //      if( pf->Pt() > 0.5 )
2238 >      if( pf->Pt() > 0.5 && dr > 0.01)
2239          fNeutralHadronIso += pf->Pt();
2240      }
2241 <
2679 <    }
2680 <
2241 >    
2242    }
2243 +  
2244 +  if( ctrl.debug ) {
2245 +    cout << "  ---> photon dbetaIso :: " << endl;
2246 +    cout << "\tfChargedIso: " << fChargedIso
2247 +         << "\tfGammaIso: " << fGammaIso
2248 +         << "\tfNeutralHadronIso: " << fNeutralHadronIso
2249 +         << "\tfpfPU: " << fpfPU
2250 +         << endl;
2251 +  }
2252 +  double pfIso = fChargedIso + fGammaIso + fNeutralHadronIso - 0.5*fpfPU;
2253 +  return pfIso/photon->Pt();
2254 + }
2255  
2683 //   double rho = 0;
2684 //   if (!(isnan(fPUEnergyDensity->At(0)->Rho()) || isinf(fPUEnergyDensity->At(0)->Rho())))
2685 //     rho = fPUEnergyDensity->At(0)->Rho();
2686
2687  // WARNING!!!!  
2688  // hardcode for sync ...
2689  EffectiveAreaVersion = eleT.kEleEAData2011;
2690  // WARNING!!!!  
2691
2692
2693  double pfIso = fChargedIso + fmax(0.0,(fGammaIso + fNeutralHadronIso
2694                                        -rho*eleT.ElectronEffectiveArea(eleT.kEleGammaAndNeutralHadronIso04,
2695                                                                   ele->Eta(),EffectiveAreaVersion)));
2256  
2257  
2698  gChargedIso = fChargedIso;
2699  gGammaIso = fGammaIso;
2700  gNeutralIso = fNeutralHadronIso;  
2701  return pfIso;
2702 }
2258  
2259  
2260   //--------------------------------------------------------------------------------------------------
2261 < SelectionStatus electronReferenceIsoSelection(ControlFlags &ctrl,
2262 <                                              const mithep::Electron * ele,
2263 <                                              const mithep::Vertex * vtx,
2264 <                                              const mithep::Array<mithep::PFCandidate> * fPFCandidates,
2710 <                                              const mithep::Array<mithep::PileupEnergyDensity> * fPUEnergyDensity,
2711 <                                              mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
2712 <                                              vector<const mithep::Muon*> muonsToVeto,
2713 <                                              vector<const mithep::Electron*> electronsToVeto)
2261 > double  nonCorrectedIsoDr03(ControlFlags & ctrl,
2262 >                            const PFCandidate * photon,
2263 >                            const Muon * lepton,
2264 >                            const Array<PFCandidate> * fPFCandidates)
2265   //--------------------------------------------------------------------------------------------------
2266 < {
2266 > {
2267  
2268 <  SelectionStatus status;
2268 >  //
2269 >  // final iso
2270 >  //
2271 >  Double_t fChargedIso  = 0.0;
2272 >  Double_t fGammaIso  = 0.0;
2273 >  Double_t fNeutralHadronIso  = 0.0;
2274 >  Double_t fpfPU  = 0.0;
2275  
2276 <  double pfIso = electronPFIso04( ctrl, ele, vtx, fPFCandidates, fPUEnergyDensity,
2277 <                                  EffectiveAreaVersion, muonsToVeto ,electronsToVeto );
2278 <  //  cout << "--------------> setting electron isoPF04 to " << pfIso << endl;
2279 <  status.isoPF04 = pfIso;
2723 <  status.chisoPF04 = gChargedIso;
2724 <  status.gaisoPF04 = gGammaIso;
2725 <  status.neisoPF04 = gNeutralIso;
2276 >  //
2277 >  // Loop over PF Candidates
2278 >  //
2279 >  for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
2280  
2281 <  bool pass = false;
2728 <  if( (pfIso/ele->Pt()) < ELECTRON_REFERENCE_PFISO_CUT ) pass = true;
2281 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
2282  
2283 <  if( pass ) {
2284 <    status.orStatus(SelectionStatus::LOOSEISO);
2285 <    status.orStatus(SelectionStatus::TIGHTISO);
2283 >    Double_t deta = (photon->Eta() - pf->Eta());
2284 >    Double_t dphi = MathUtils::DeltaPhi(Double_t(photon->Phi()),Double_t(pf->Phi()));
2285 >    Double_t dr = MathUtils::DeltaR(photon->Phi(),photon->Eta(), pf->Phi(), pf->Eta());
2286 >    if (dr > 0.3) continue;
2287 >
2288 >    if( !(PFnoPUflag[k]) && pf->Charge() != 0 ) {
2289 >      if( pf->Pt() >= 0.2 && dr > 0.01 )
2290 >        fpfPU += pf->Pt();
2291 >      continue;
2292 >    }
2293 >    
2294 >    //
2295 >    // skip this photon
2296 >    //
2297 >    if( abs(pf->PFType()) == PFCandidate::eGamma &&
2298 >        pf->Et() == photon->Et() ) continue;
2299 >    
2300 >      
2301 >    //
2302 >    // Charged Iso
2303 >    //
2304 >    if (pf->Charge() != 0 ) {
2305 >      if( dr > 0.01 && pf->Pt() >= 0.2 &&
2306 >          !(pf->TrackerTrk() == lepton->TrackerTrk()) )
2307 >        fChargedIso += pf->Pt();
2308 >    }
2309 >    
2310 >    //
2311 >    // Gamma Iso
2312 >    //
2313 >    else if (abs(pf->PFType()) == PFCandidate::eGamma) {
2314 >      if( pf->Pt() > 0.5 && dr > 0.01)
2315 >        fGammaIso += pf->Pt();
2316 >    }
2317 >    
2318 >    //
2319 >    // Other Neutrals
2320 >    //
2321 >    else {
2322 >      if( pf->Pt() > 0.5 && dr > 0.01)
2323 >        fNeutralHadronIso += pf->Pt();
2324 >    }
2325 >    
2326    }
2327 <  if(ctrl.debug) cout << "returning status : " << hex << status.getStatus() << dec << endl;
2328 <  return status;
2329 <
2327 >  
2328 >  if( ctrl.debug ) {
2329 >    cout << "  ---> photon dbetaIso :: " << endl;
2330 >    cout << "\tfChargedIso: " << fChargedIso
2331 >         << "\tfGammaIso: " << fGammaIso
2332 >         << "\tfNeutralHadronIso: " << fNeutralHadronIso
2333 >         << "\tfpfPU: " << fpfPU
2334 >         << endl;
2335 >  }
2336 >  double pfIso = fChargedIso + fGammaIso + fNeutralHadronIso + fpfPU;
2337 >  return pfIso/photon->Pt();
2338   }
2339  
2340  
2341 +
2342   //--------------------------------------------------------------------------------------------------
2343 < // hacked version
2344 < SelectionStatus electronReferenceIsoSelection(ControlFlags &ctrl,
2345 <                                              const mithep::Electron * ele,
2346 <                                              const mithep::Vertex * vtx,
2745 <                                              const mithep::Array<mithep::PFCandidate> * fPFCandidates,
2746 <                                              float rho,
2747 <                                              mithep::ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaVersion,
2748 <                                              vector<const mithep::Muon*> muonsToVeto,
2749 <                                              vector<const mithep::Electron*> electronsToVeto)
2343 > double  nonCorrectedIsoDr03(ControlFlags & ctrl,
2344 >                            const PFCandidate * photon,
2345 >                            const Electron * lepton,
2346 >                            const Array<PFCandidate> * fPFCandidates)
2347   //--------------------------------------------------------------------------------------------------
2348 < {
2348 > {
2349  
2350 <  SelectionStatus status;
2350 >  //
2351 >  // final iso
2352 >  //
2353 >  Double_t fChargedIso  = 0.0;
2354 >  Double_t fGammaIso  = 0.0;
2355 >  Double_t fNeutralHadronIso  = 0.0;
2356 >  Double_t fpfPU  = 0.0;
2357  
2358 <  double pfIso = electronPFIso04( ctrl, ele, vtx, fPFCandidates, rho,
2359 <                                  EffectiveAreaVersion, muonsToVeto ,electronsToVeto );
2360 <  status.isoPF04 = pfIso;
2361 <  status.chisoPF04 = gChargedIso;
2759 <  status.gaisoPF04 = gGammaIso;
2760 <  status.neisoPF04 = gNeutralIso;
2761 <  bool pass = false;
2762 <  if( (pfIso/ele->Pt()) < ELECTRON_REFERENCE_PFISO_CUT ) pass = true;
2358 >  //
2359 >  // Loop over PF Candidates
2360 >  //
2361 >  for(int k=0; k<fPFCandidates->GetEntries(); ++k) {
2362  
2363 <  if( pass ) {
2765 <    status.orStatus(SelectionStatus::LOOSEISO);
2766 <    status.orStatus(SelectionStatus::TIGHTISO);
2767 <  }
2768 <  if(ctrl.debug) cout << "returning status : " << hex << status.getStatus() << dec << endl;
2769 <  return status;
2363 >    const PFCandidate *pf = (PFCandidate*)((*fPFCandidates)[k]);
2364  
2365 +    Double_t deta = (photon->Eta() - pf->Eta());
2366 +    Double_t dphi = MathUtils::DeltaPhi(Double_t(photon->Phi()),Double_t(pf->Phi()));
2367 +    Double_t dr = MathUtils::DeltaR(photon->Phi(),photon->Eta(), pf->Phi(), pf->Eta());
2368 +    if (dr > 0.3) continue;
2369 +
2370 +    if( !(PFnoPUflag[k]) && pf->Charge() != 0 ) {
2371 +      if( pf->Pt() >= 0.2 && dr > 0.01 )
2372 +        fpfPU += pf->Pt();
2373 +      continue;
2374 +    }
2375 +    
2376 +    //
2377 +    // skip this photon
2378 +    //
2379 +    if( abs(pf->PFType()) == PFCandidate::eGamma &&
2380 +        pf->Et() == photon->Et() ) continue;
2381 +    
2382 +      
2383 +    //
2384 +    // Charged Iso
2385 +    //
2386 +    if (pf->Charge() != 0 ) {
2387 +      if( dr > 0.01 && pf->Pt() >= 0.2 &&
2388 +          !(pf->TrackerTrk() == lepton->TrackerTrk()) )
2389 +        fChargedIso += pf->Pt();
2390 +    }
2391 +    
2392 +    //
2393 +    // Gamma Iso
2394 +    //
2395 +    else if (abs(pf->PFType()) == PFCandidate::eGamma) {
2396 +      if( pf->Pt() > 0.5 && dr > 0.01)
2397 +        fGammaIso += pf->Pt();
2398 +    }
2399 +    
2400 +    //
2401 +    // Other Neutrals
2402 +    //
2403 +    else {
2404 +      if( pf->Pt() > 0.5 && dr > 0.01)
2405 +        fNeutralHadronIso += pf->Pt();
2406 +    }
2407 +    
2408 +  }
2409 +  
2410 +  if( ctrl.debug ) {
2411 +    cout << "photon dbetaIso :: " << endl;
2412 +    cout << "\tfChargedIso: " << fChargedIso
2413 +         << "\tfGammaIso: " << fGammaIso
2414 +         << "\tfNeutralHadronIso: " << fNeutralHadronIso
2415 +         << "\tfpfPU: " << fpfPU
2416 +         << endl;
2417 +  }
2418 +  double pfIso = fChargedIso + fGammaIso + fNeutralHadronIso + fpfPU;
2419 +  return pfIso/photon->Pt();
2420   }
2421 +
2422 +
2423 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines