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

Comparing UserCode/MitHzz4l/NonMCBackground/src/SelectionEMU.cc (file contents):
Revision 1.2 by khahn, Tue Feb 14 21:29:18 2012 UTC vs.
Revision 1.6 by dkralph, Wed Jun 13 14:11:22 2012 UTC

# Line 1 | Line 1
1 + //***************************************************************************************************
2 + //
3 + // selection sync'ed with https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsZZ4l2012SummerSync
4 + //
5 + //***************************************************************************************************
6 +
7 + // system headers
8 + #include <map>
9 + #include <utility>
10 +
11 + // mit headers
12 + #include "Vertex.h"
13 +
14 + // 4L stuff
15   #include "SelectionStatus.h"
16   #include "EventData.h"
17   #include "SimpleLepton.h"
18   #include "EfficiencyWeightsInterface.h"
19 <
20 < #include "HZZBDTElectronSelection.h"
19 > #include "ElectronSelection.h"
20 > #include "MuonSelection.h"
21   #include "IsolationSelection.h"
8 #include "PassHLT.h"
22   #include "SelectionEMU.h"
23 <
24 < #include "ExternData.h"
23 > #include "ReferenceSelection.h"
24 > #include "Selection.h"
25 > #include "CommonDefs.h"
26   #include "SelectionDefs.h"
27 + #include "FSR.h"
28 + #include "SelectionFuncs.h"
29  
30  
31 + extern vector<SimpleLepton> failingLeptons;
32 + extern vector<SimpleLepton> passingLeptons;
33  
34 < // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35 < // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
36 < EventData apply_EMU_selection(ControlFlags &ctrl,           // input control
37 <                              mithep::TEventInfo *info,     // input event info
38 <                              TClonesArray *electronArr,    // input electrons
39 <                              SelectionStatus (*ElectronPreSelector)( ControlFlags &, const mithep::TElectron*),
40 <                              SelectionStatus (*ElectronIDSelector)( ControlFlags &, const mithep::TElectron*),
41 <                              SelectionStatus (*ElectronIsoSelector)( ControlFlags &, const mithep::TElectron*),
42 <                              TClonesArray *muonArr,         // input muons
43 <                              SelectionStatus (*MuonPreSelector)( ControlFlags &, const mithep::TMuon*),
44 <                              SelectionStatus (*MuonIDSelector)( ControlFlags &, const mithep::TMuon*),
45 <                              SelectionStatus (*MuonIsoSelector)( ControlFlags &, const mithep::TMuon*) )
46 < // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
47 < // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34 > //--------------------------------------------------------------------------------------------------
35 > EventData apply_HZZ4L_EMU_selection(ControlFlags &ctrl,           // input control
36 >                                        const mithep::EventHeader *info,     // input event info
37 >                                        const mithep::Array<mithep::Vertex>       * vtxArr ,
38 >                                        const mithep::Array<mithep::PFCandidate>  *pfCandidates,
39 >                                        const mithep::Array<mithep::PileupEnergyDensity>  *puEnergyDensity,
40 >                                        const mithep::Array<mithep::Electron> *electronArr,    // input electrons
41 >                                        SelectionStatus (*ElectronPreSelector)( ControlFlags &,
42 >                                                                                const mithep::Electron*,
43 >                                                                                const mithep::Vertex *),
44 >                                        SelectionStatus (*ElectronIDSelector)( ControlFlags &,
45 >                                                                               const mithep::Electron*,
46 >                                                                               const mithep::Vertex *),
47 >                                        SelectionStatus (*ElectronIsoSelector)( ControlFlags &,
48 >                                                                                const mithep::Electron*,
49 >                                                                                const mithep::Vertex *,
50 >                                                                                const mithep::Array<mithep::PFCandidate> *,
51 >                                                                                const mithep::Array<mithep::PileupEnergyDensity> *,
52 >                                                                                mithep::ElectronTools::EElectronEffectiveAreaTarget,
53 >                                                                                vector<const mithep::PFCandidate*>),
54 >                                        const mithep::Array<mithep::Muon> *muonArr,    // input muons
55 >                                        SelectionStatus (*MuonPreSelector)( ControlFlags &,
56 >                                                                            const mithep::Muon*,
57 >                                                                            const mithep::Vertex *,
58 >                                                                            const mithep::Array<mithep::PFCandidate> *),
59 >                                        SelectionStatus (*MuonIDSelector)( ControlFlags &,
60 >                                                                           const mithep::Muon*,
61 >                                                                           // const mithep::Vertex &),
62 >                                                                           const mithep::Vertex *,
63 >                                                                           const mithep::Array<mithep::PFCandidate> *),
64 >                                        SelectionStatus (*MuonIsoSelector)( ControlFlags &,
65 >                                                                            const mithep::Muon*,
66 >                                                                            const mithep::Vertex *,
67 >                                                                            const mithep::Array<mithep::PFCandidate> *,
68 >                                                                            const mithep::Array<mithep::PileupEnergyDensity> *,
69 >                                                                            mithep::MuonTools::EMuonEffectiveAreaTarget,
70 >                                                                            vector<const mithep::PFCandidate*>)
71 >                                        )
72 > //--------------------------------------------------------------------------------------------------
73   {      
74  
75    EventData ret;
76    unsigned evtfail = 0x0;
77    TRandom3 r;
35  
36  if( ctrl.debug ) {
37    cout << "Run: " << info->runNum
38         << "\tEvt: " << info->evtNum
39         << "\tLumi: " << info->lumiSec
40         << endl;
41  }
78  
79 <  if( !ctrl.mc ) {
80 <    // not accounting for overlap atm
45 <    RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec);      
46 <    if( !(rlrm.HasRunLumi(rl)) )  {
47 <      if( ctrl.debug ) cout << "\tfails JSON" << endl;
48 <      ret.status.setStatus(0);
49 <      return ret;
50 <    }
51 <  }
52 <  
53 <  
54 <  //********************************************************
55 <  // Trigger
56 <  //********************************************************
57 < //   if( !ctrl.mc ) {
58 < //     if( !(passHLTSingleMuon(info->triggerBits) )  ) {
59 < //       if( ctrl.debug ) cout << "\tfails trigger" << endl;
60 < //       evtfail |= (1<<EVTFAIL_TRIGGER);
61 < //       ret.status.setStatus(0);
62 < //       return ret;
63 < //     }        
64 < //   }
65 <  if( ctrl.debug ) {
66 <    cout << "presel nlep: " << muonArr->GetEntries() + electronArr->GetEntries()
67 <         << "\tnmuon: "    << muonArr->GetEntries()
68 <         << "\tnelectron: " << electronArr->GetEntries()
69 <         << endl;
70 <  }
79 >  failingLeptons.clear();
80 >  passingLeptons.clear();
81  
82 <  //********************************************************
83 <  // Lepton Selection
84 <  //********************************************************
85 <  vector<SimpleLepton> lepvec;
86 <  if( muonArr->GetEntries() != 1 && electronArr->GetEntries() != 1 ) {
87 <    ret.status.setStatus(0);
82 >  mithep::MuonTools::EMuonEffectiveAreaTarget eraMu;
83 >  mithep::ElectronTools::EElectronEffectiveAreaTarget eraEle;
84 >  getEATargets(ctrl,eraMu,eraEle);
85 >
86 >  const mithep::Vertex * vtx;
87 >  bool goodVertex = setPV( ctrl, vtxArr, vtx );
88 >  if(goodVertex) {
89 >    ret.status.selectionBits.flip(PASS_SKIM2);
90 >  } else {
91 >    if(ctrl.debug) cout << "found bad vertex" << endl;
92 >    ret.status.setStatus(SelectionStatus::FAIL);
93      return ret;
94    }
95  
96 <  //    
96 >  //***********************************************************
97 >  // Lepton Selection
98 >  //***********************************************************
99 >  vector<SimpleLepton> lepvec;
100 >  vector<const mithep::PFCandidate*> photonsToVeto;
101 >
102 >
103    if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
104    //----------------------------------------------------
105 <  for(Int_t i=0; i<muonArr->GetEntries(); i++)
105 >  for(int i=0; i<muonArr->GetEntries(); i++)
106      {
107 <      const mithep::TMuon *mu = (mithep::TMuon*)((*muonArr)[i]);      
107 >      const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[i]);      
108        
109        SelectionStatus musel;
110 <      if(ctrl.debug) cout << "musel.status  before anything: " << musel.getStatus() << endl;
111 <      musel |= (*MuonPreSelector)(ctrl,mu);
112 <      if(ctrl.debug) cout << "musel.status  after presel: " << musel.getStatus() << endl;
113 <      musel |= (*MuonIDSelector)(ctrl,mu);
114 <      if(ctrl.debug) cout << "musel.status  after ID: " << musel.getStatus() << endl;
115 <      musel |= (*MuonIsoSelector)(ctrl,mu);
116 <      if(ctrl.debug) cout << "musel.status  after iso: " << musel.getStatus() << endl;
117 <
97 <      if( ctrl.debug ) {
98 <        cout << "muon:: pt: " << mu->pt
99 <             << "\teta: " << mu->eta
100 <             << "\tisorel: " <<  mu->pfIso03/mu->pt
101 <             << "\tstatus: " << hex << musel.getStatus() << dec
102 <             << endl;
110 >
111 >      musel |= (*MuonPreSelector)(ctrl,mu,vtx,pfCandidates);
112 >      if( !(musel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
113 >
114 >      musel |= (*MuonIDSelector)(ctrl,mu,vtx,pfCandidates );
115 >
116 >      if( !(ctrl.doFSR) ) {
117 >        musel |=  (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);
118        }
119 +
120 +      SimpleLepton tmplep;
121 +      float pt = mu->Pt();
122 +      tmplep.vec.SetPtEtaPhiM(pt,
123 +                               mu->Eta(),
124 +                               mu->Phi(),
125 +                               MUON_MASS);
126        
127 <      if ( musel.pass() ) {
127 >      tmplep.type    = 13;
128 >      tmplep.index   = i;
129 >      tmplep.charge  = mu->Charge();
130 >      tmplep.isoTrk  = mu->IsoR03SumPt();
131 >      tmplep.isoEcal = mu->IsoR03EmEt();
132 >      tmplep.isoHcal = mu->IsoR03HadEt();
133 >      tmplep.isoPF04 = musel.isoPF04;
134 >      tmplep.chisoPF04 = musel.chisoPF04;
135 >      tmplep.gaisoPF04 = musel.gaisoPF04;
136 >      tmplep.neisoPF04 = musel.neisoPF04;
137 >      // tmplep.isoPF03 = computePFMuonIso(mu,vtx,pfCandidates,0.3);
138 >      // tmplep.isoPF04 = computePFMuonIso(mu,vtx,pfCandidates,0.4);
139 >      tmplep.ip3dSig = mu->Ip3dPVSignificance();
140 >      tmplep.is4l    = false;
141 >      tmplep.isEB    = (fabs(mu->Eta()) < 1.479 ? 1 : 0 );
142 >      tmplep.isoMVA  = musel.isoMVA;
143 >      tmplep.isTight = musel.tight();
144 >      tmplep.isLoose = musel.loose();
145 >      tmplep.status  = musel;    
146 >      tmplep.fsrRecoveryAttempted = false;
147 >      SelectionStatus tmpstat = PassWwMuonSel(mu,vtx,pfCandidates);
148 >      tmplep.tightCutsApplied = tmpstat.tight();
149 >      lepvec.push_back(tmplep);
150 >      if( ctrl.debug ) cout << endl;
151 >    }
152  
153 <        SimpleLepton tmplep;
154 <        float pt = mu->pt;
155 <        tmplep.vecorig->SetPtEtaPhiM(pt,
156 <                                    mu->eta,
157 <                                    mu->phi,
158 <                                    MUON_MASS);
153 >    if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
154 >    // --------------------------------------------------------------------------------
155 >    for(int i=0; i<electronArr->GetEntries(); i++)
156 >      {
157 >        const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);
158 >
159 >        SelectionStatus elesel;
160          
161 <        if( ctrl.do_escale_up ) {
162 <          pt=scale_smear_muon_Up(pt, 1,  r);
163 <        }
164 <        if( ctrl.do_escale_down ) {
165 <          pt=scale_smear_muon_Down(pt, 1,  r);
161 >        elesel |= (*ElectronPreSelector)(ctrl,ele,vtx);
162 >        if( !(elesel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
163 >        
164 >        elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
165 >        
166 >        if( !(ctrl.doFSR) ) {
167 >          elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
168          }
169          
170 <        tmplep.vec->SetPtEtaPhiM(pt,
171 <                                mu->eta,
172 <                                mu->phi,
173 <                                MUON_MASS);
170 >        SimpleLepton tmplep;
171 >        float pt = ele->Pt();
172 >        tmplep.vec.SetPtEtaPhiM( pt,
173 >                                 ele->Eta(),
174 >                                 ele->Phi(),
175 >                                 ELECTRON_MASS );
176          
177 <        tmplep.type    = 13;
177 >        tmplep.type    = 11;
178          tmplep.index   = i;
179 <        tmplep.charge  = mu->q;
180 <        tmplep.isoTrk  = mu->trkIso03;
181 <        tmplep.isoEcal = mu->emIso03;
182 <        tmplep.isoHcal = mu->hadIso03;
183 <        tmplep.isoPF03 = mu->pfIso03;
184 <        tmplep.isoPF04 = mu->pfIso04;
185 <        tmplep.ip3dSig = mu->ip3dSig;
179 >        tmplep.charge  = ele->Charge();
180 >        tmplep.isoTrk  = ele->TrackIsolationDr03();
181 >        tmplep.isoEcal = ele->EcalRecHitIsoDr03();
182 >        tmplep.isoHcal = ele->HcalTowerSumEtDr03();
183 >        tmplep.isoPF04 = elesel.isoPF04;
184 >        tmplep.chisoPF04 = elesel.chisoPF04;
185 >        tmplep.gaisoPF04 = elesel.gaisoPF04;
186 >        tmplep.neisoPF04 = elesel.neisoPF04;
187 >        // tmplep.isoPF03 = computePFEleIso(ele,vtx,pfCandidates,0.3);
188 >        // tmplep.isoPF04 = computePFEleIso(ele,vtx,pfCandidates,0.4);
189 >        tmplep.ip3dSig = ele->Ip3dPVSignificance();
190          tmplep.is4l    = false;
191 <        tmplep.isEB    = (fabs(mu->eta) < 1.479 ? 1 : 0 );
192 <        tmplep.isTight = musel.tight();
193 <        tmplep.isLoose = musel.loose();
191 >        tmplep.isEB    = ele->IsEB();
192 >        tmplep.scID    = ele->SCluster()->GetUniqueID();
193 >        tmplep.isTight = elesel.tight();
194 >        tmplep.isLoose = elesel.loose();
195 >        tmplep.status  = elesel;
196 >        tmplep.idMVA   = elesel.idMVA;
197 >        tmplep.isoMVA  = elesel.isoMVA;
198 >        tmplep.fsrRecoveryAttempted = false;
199 >        SelectionStatus tmpstat = electronTagSelection(ele,vtx,pfCandidates);
200 >        tmplep.tightCutsApplied   = tmpstat.tight();
201          lepvec.push_back(tmplep);
202 <        if( ctrl.debug ) { cout << "muon passes ... " << endl;}
202 >        if( ctrl.debug ) cout << endl;
203        }
204 <      //  }
205 <    }    
206 <  
207 <  
208 <    
209 <    //
210 <    if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
211 <    // --------------------------------------------------------------------------------
212 <    for(Int_t i=0; i<electronArr->GetEntries(); i++)
213 <      {
214 <        const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]);
215 <        
216 <        Bool_t isMuonOverlap = kFALSE;
217 <        for (int k=0; k<lepvec.size(); ++k) {
218 <          TVector3 tmplep;
219 <          tmplep.SetPtEtaPhi(ele->pt, ele->eta, ele->phi);
220 <          if ( abs(lepvec[k].type == 13) && lepvec[k].vec->Vect().DrEtaPhi(tmplep) < 0.15 ) {
159 <            if( ctrl.debug ) cout << "-----> isMuonOverlap! " << endl;
160 <            isMuonOverlap = kTRUE;
161 <            break;
162 <          }
163 <        }
204 >
205 >    sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
206 >
207 >    //********************************************************
208 >    // Step 2: Lepton Cleaning
209 >    //********************************************************
210 >    vector<vector<SimpleLepton>::iterator> electrons_to_erase;
211 >    for (vector<SimpleLepton>::iterator it1=lepvec.begin(); it1 != lepvec.end(); it1++ ) {
212 >      if ( abs(it1->type) != 11 ) continue;
213 >      TVector3 evec = it1->vec.Vect();
214 >      
215 >      bool erase_this_electron=false;
216 >      for (vector<SimpleLepton>::iterator it2=lepvec.begin(); it2 != lepvec.end(); it2++ ) {
217 >        if ( it2 == it1 )                       continue;
218 >        if ( abs(it2->type) != 13 )             continue;
219 >        if( !(it2->status.looseIDAndPre()) )    continue;
220 >        TVector3 mvec = it2->vec.Vect();
221          
222 <        SelectionStatus elesel;
223 <        elesel |= (*ElectronPreSelector)(ctrl,ele);
224 <        elesel |= (*ElectronIDSelector)(ctrl,ele);
168 <        elesel |= (*ElectronIsoSelector)(ctrl,ele);
169 <        if( elesel.getStatus() & SelectionStatus::PRESELECTION )
170 <          elesel.setStatus(SelectionStatus::LOOSESELECTION);
171 <
172 <        if( ctrl.debug ){
173 <          cout << "\tscEt: " << ele->scEt
174 <               << "\tscEta: " << ele->scEta
175 <               << "\tncluster: " << ele->ncluster
176 <               << "\tisorel: " <<  ele->pfIso04/ele->pt
177 <               << "\tstatus: " << hex << elesel.getStatus() << dec
178 <               << endl;
222 >        if ( evec.DrEtaPhi(mvec) < 0.05 ) {
223 >          erase_this_electron=true;
224 >          break;
225          }
180
181        if ( elesel.pass() && !isMuonOverlap )
182          {
183            SimpleLepton tmplep;
184            
185            float pt = ele->pt;
186            tmplep.vecorig->SetPtEtaPhiM( pt,
187                                          ele->eta,
188                                          ele->phi,
189                                          ELECTRON_MASS );
190            
191            if( ctrl.do_escale ) {
192              pt=scale_smear_electron(pt, ele->isEB, r);
193            }
194            if( ctrl.do_escale_up ) {
195              pt=scale_smear_electron_Up(pt, ele->isEB,  r);
196            }
197            if( ctrl.do_escale_down ) {
198              pt=scale_smear_electron_Down(pt, ele->isEB,  r);
199            }
200
201            
202            tmplep.vec->SetPtEtaPhiM( pt,
203                                      ele->eta,
204                                      ele->phi,
205                                      ELECTRON_MASS );
206            
207            tmplep.type    = 11;
208            tmplep.index   = i;
209            tmplep.charge  = ele->q;
210            tmplep.isoTrk  = ele->trkIso03;
211            tmplep.isoEcal = ele->emIso03;
212            tmplep.isoHcal = ele->hadIso03;
213            tmplep.isoPF03 = ele->pfIso03;
214            tmplep.isoPF04 = ele->pfIso04;
215            tmplep.ip3dSig = ele->ip3dSig;
216            tmplep.is4l    = false;
217            tmplep.isEB    = ele->isEB;
218            tmplep.scID    = ele->scID;
219            tmplep.isTight = elesel.tight();
220            tmplep.isLoose = elesel.pass();
221            lepvec.push_back(tmplep);
222            if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
223          }
226        }
227 <    
228 <    
227 >      if( erase_this_electron )
228 >        electrons_to_erase.push_back(it1);
229 >    }
230 >    for( int i=0; i<electrons_to_erase.size(); i++ ) {
231 >      lepvec.erase(electrons_to_erase[i]);
232 >    }
233 >
234      //********************************************************
235 <    // Dump Stuff
235 >    // Step 3: Good Leptons
236      //********************************************************
237 <    sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
238 <    int nmu=0, nele=0;
239 <    for( int i=0; i<lepvec.size(); i++ ) {
240 <      if(ctrl.debug) cout << "lepvec :: index: " << i
241 <                          << "\tpt: " << lepvec[i].vec->Pt()
242 <                          << "\ttype: " << lepvec[i].type
243 <                          << endl;
244 <      if( abs(lepvec[i].type) == 11 ) nele++;
245 <      else nmu++;
237 >    vector<double> pt_of_leptons_to_erase;
238 >    for (int i=0; i<lepvec.size(); i++ ) {
239 >      bool already_pushed=false;
240 >      if( !(lepvec[i].status.loose()) ) {
241 >        pt_of_leptons_to_erase.push_back(lepvec[i].vec.Pt());
242 >        already_pushed = true;
243 >        failingLeptons.push_back(lepvec[i]); // these should pass preselection
244 >      } else {
245 >        passingLeptons.push_back(lepvec[i]);
246 >      }
247 > #ifndef SYNC
248 >      if( !already_pushed && fabs(lepvec[i].ip3dSig)>4 )  
249 >        pt_of_leptons_to_erase.push_back(lepvec[i].vec.Pt());
250 > #endif      
251      }
252 <    if( ctrl.debug ) {
253 <      cout << "postsel nlep: " << lepvec.size()
254 <           << "\tnmuon: " << nmu
255 <           << "\tnelectron: " << nele
256 <           << endl;
252 >    for( int i=0; i<pt_of_leptons_to_erase.size(); i++ ) {
253 >      for( vector<SimpleLepton>::iterator it=lepvec.begin(); it != lepvec.end(); it++ ) {
254 >        SimpleLepton flep = *it;
255 >        if( flep.vec.Pt() != pt_of_leptons_to_erase[i] ) continue;
256 >        lepvec.erase(it);
257 >        break;
258 >      }
259      }
260 <    
247 <    
260 >
261      //******************************************************************************
262 <    // Selection
262 >    // W + (OF SS lepton) Selection
263      //******************************************************************************
264 <    float bestMass=-1; int best_mu_index=-1, best_ele_index=-1;
265 <    for(int i = 0; i<lepvec.size(); i++) {      // get a tight muon
266 <      if( abs(lepvec[i].type) != 13 ) continue;
267 <      if( !(lepvec[i].isTight) ) continue;
268 <      //      if( lepvec[i].vec->Pt() < 35 ) continue;
269 <      if( ctrl.debug ) cout << "got a muon, index: " << i << endl;
270 <
271 <      for(int j = 0; j<lepvec.size(); j++) {     // get a loose electron
272 <        if( j == i ) continue;
260 <        if( abs(lepvec[j].type) != 11 ) continue;
261 <        if( !(lepvec[j].isLoose) ) continue;
262 <        if (lepvec[i].charge == lepvec[j].charge) continue;          
263 <        //      if (lepvec[i].charge != lepvec[j].charge) continue;          
264 <        if( ctrl.debug ) cout << "got a electron, index: " << j << endl;
265 <
266 <        float tmpMass = ( *(lepvec[i].vec) + *(lepvec[j].vec) ).M();
267 <        if( ctrl.debug ) cout << "tmp vs best :: " << tmpMass << "," << bestMass << endl;
268 <        if( tmpMass > bestMass ) {
269 <          bestMass = tmpMass;
270 <          best_mu_index=i;
271 <          best_ele_index=j;
272 <        }
273 <
264 >    if(ctrl.fakeScheme.Contains("emu-")) {
265 >      if(has_ssof_lepton(ctrl)) {
266 >        ret.status.setStatus(SelectionStatus::EVTPASS);
267 >        ret.Z1leptons.push_back(passingLeptons[0]);
268 >        ret.Z1leptons.push_back(passingLeptons[0]);
269 >        ret.Z2leptons.push_back(passingLeptons[0]);
270 >        ret.Z2leptons.push_back(passingLeptons[0]);
271 >      } else {
272 >        ret.status.setStatus(SelectionStatus::FAIL);
273        }
275    }
276
277    if( bestMass > 0 ) {
278      if( ctrl.debug ) cout << "EMU candidate, mass : " << bestMass << endl;
279      if( lepvec[best_ele_index].isTight )
280        ret.status.setStatus(SelectionStatus::TIGHTSELECTION);
281      else
282        ret.status.setStatus(SelectionStatus::LOOSESELECTION);
283      ret.Z1leptons.push_back(lepvec[best_mu_index]);
284      ret.Z1leptons.push_back(lepvec[best_ele_index]);
285      ret.Z2leptons.push_back(lepvec[best_mu_index]);
286      ret.Z2leptons.push_back(lepvec[best_ele_index]);
274        return ret;
275      }
289
290    ret.status.setStatus(0);
291    return ret;
292
276   }
277  
278 + // //----------------------------------------------------------------------------
279 + // //
280 + // // Get primary vertices
281 + // // Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
282 + // // NOTE: if no PV is found from fitting tracks, the beamspot is used
283 + // //
284 + // //----------------------------------------------------------------------------
285 + // bool setPV(ControlFlags ctrl,
286 + //         const mithep::Array<mithep::Vertex> * vtxArr,
287 + //         const mithep::Vertex* &vtx)
288 + // //----------------------------------------------------------------------------
289 + // {
290 +
291 + //   const mithep::Vertex *bestPV = 0;    
292 + //   float best_sumpt=-1;
293 +
294 + //   // good PV requirements
295 + //   const UInt_t   fMinNTracksFit = 0;
296 + //   const Double_t fMinNdof       = 4;
297 + //   const Double_t fMaxAbsZ       = 24;
298 + //   const Double_t fMaxRho        = 2;
299 +  
300 + //   for(int i=0; i<vtxArr->GetEntries(); ++i) {
301 + //     const mithep::Vertex *pv = (mithep::Vertex*)(vtxArr->At(i));
302 + //     if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
303 +    
304 + //     // Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
305 + //     if(!pv->IsValid())                                continue;
306 + //     if(pv->NTracksFit()       < fMinNTracksFit)       continue;
307 + //     if(pv->Ndof()              < fMinNdof)         continue;
308 + //     if(fabs(pv->Z()) > fMaxAbsZ)                   continue;
309 + //     if(pv->Position().Rho()   > fMaxRho)           continue;    
310 +    
311 + //     // take the first ...
312 + //     bestPV = pv;
313 + //     break;
314 +
315 + //     // this never reached ...    
316 + //     float tmp_sumpt=0;
317 + //     for( int t=0; t<pv->NTracks(); t++ )
318 + //       tmp_sumpt += pv->Trk(t)->Pt();
319 +    
320 + //     if( tmp_sumpt > best_sumpt  ) {
321 + //       bestPV = pv;
322 + //       best_sumpt = tmp_sumpt;
323 + //       if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
324 + //     }
325 + //   }
326 +        
327 + //   // sync
328 + //   if(!bestPV)
329 + //     return false;
330 + //   else {    
331 + //     vtx = bestPV;
332 + //     return true;
333 + //   }  
334 + // };
335 + //----------------------------------------------------------------------------------------
336 + bool has_ssof_lepton(ControlFlags &ctrl)
337 + {
338 +  bool has_ssof=false;
339 +  for(unsigned iw=0; iw<passingLeptons.size(); iw++) {
340 +    SimpleLepton w_lep = passingLeptons[iw];
341 +    //????????????????????????????????????????????????????????????????????????????????????????
342 +    // this is applied in skim (skim also applies ww muon id)
343 +    // if(abs(w_lep.type) == 11) {
344 +    //   if( !(w_lep.tightCutsApplied) )
345 +    //  continue;
346 +    // }
347 +    //????????????????????????????????????????????????????????????????????????????????????????
348 +    for(unsigned ifake=0; ifake<failingLeptons.size(); ifake++) {
349 +      SimpleLepton fake_lep = failingLeptons[ifake];
350 +      if(abs(fake_lep.type) == abs(w_lep.type)) continue;
351 +      if(fake_lep.charge != w_lep.charge) continue;
352 +      has_ssof = true;
353 +    }
354 +    for(unsigned ipass=0; ipass<passingLeptons.size(); ipass++) {
355 +      if(ipass == iw) continue;
356 +      SimpleLepton pass_lep = passingLeptons[ipass];
357 +      if(abs(pass_lep.type) == abs(w_lep.type)) continue;
358 +      if(pass_lep.charge != w_lep.charge) continue;
359 +      has_ssof = true;
360 +    }
361 +  }
362  
363 +  return has_ssof;
364 + }
365 + // //----------------------------------------------------------------------------------------
366 + // void getEATargets(ControlFlags &ctrl, mithep::MuonTools::EMuonEffectiveAreaTarget &eraMu, mithep::ElectronTools::EElectronEffectiveAreaTarget &eraEle)
367 + // {
368 + //   if( !ctrl.mc && ctrl.era == 2011 ) {
369 + //     eraMu  = mithep::MuonTools::kMuEAData2011;
370 + //     eraEle = mithep::ElectronTools::kEleEAData2011;
371 + //   } else if( !ctrl.mc && ctrl.era == 2012 ) {
372 + //     eraMu  = mithep::MuonTools::kMuEAData2012;
373 + //     eraEle = mithep::ElectronTools::kEleEAData2012;
374 + //   } else if( ctrl.mc && ctrl.era == 2011 ) {
375 + //     eraMu  = mithep::MuonTools::kMuEAFall11MC;
376 + //     eraEle = mithep::ElectronTools::kEleEAFall11MC;
377 + //   } else if( ctrl.mc && ctrl.era == 2012 ) {
378 + //     eraMu  = mithep::MuonTools::kMuEAData2012;
379 + //     eraEle = mithep::ElectronTools::kEleEAData2012;
380 + //   } else {
381 + //     cerr << "unknown era for effective areas ... quitting." << endl;
382 + //     exit(1);
383 + //   }
384 + // }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines