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.3 by khahn, Fri Feb 17 14:48:01 2012 UTC vs.
Revision 1.4 by dkralph, Tue Jun 12 22:04:06 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 "UtilFuncs.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 >      tmplep.tightCutsApplied   = false;
148 >      lepvec.push_back(tmplep);
149 >      if( ctrl.debug ) cout << endl;
150 >    }
151  
152 <        SimpleLepton tmplep;
153 <        float pt = mu->pt;
154 <        tmplep.vecorig->SetPtEtaPhiM(pt,
155 <                                    mu->eta,
156 <                                    mu->phi,
157 <                                    MUON_MASS);
152 >    if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
153 >    // --------------------------------------------------------------------------------
154 >    for(int i=0; i<electronArr->GetEntries(); i++)
155 >      {
156 >        const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);
157 >
158 >        SelectionStatus elesel;
159          
160 <        if( ctrl.do_escale_up ) {
161 <          pt=scale_smear_muon_Up(pt, 1,  r);
162 <        }
163 <        if( ctrl.do_escale_down ) {
164 <          pt=scale_smear_muon_Down(pt, 1,  r);
160 >        elesel |= (*ElectronPreSelector)(ctrl,ele,vtx);
161 >        if( !(elesel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
162 >        
163 >        elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
164 >        
165 >        if( !(ctrl.doFSR) ) {
166 >          elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
167          }
168          
169 <        tmplep.vec->SetPtEtaPhiM(pt,
170 <                                mu->eta,
171 <                                mu->phi,
172 <                                MUON_MASS);
169 >        SimpleLepton tmplep;
170 >        float pt = ele->Pt();
171 >        tmplep.vec.SetPtEtaPhiM( pt,
172 >                                 ele->Eta(),
173 >                                 ele->Phi(),
174 >                                 ELECTRON_MASS );
175          
176 <        tmplep.type    = 13;
176 >        tmplep.type    = 11;
177          tmplep.index   = i;
178 <        tmplep.charge  = mu->q;
179 <        tmplep.isoTrk  = mu->trkIso03;
180 <        tmplep.isoEcal = mu->emIso03;
181 <        tmplep.isoHcal = mu->hadIso03;
182 <        tmplep.isoPF03 = mu->pfIso03;
183 <        tmplep.isoPF04 = mu->pfIso04;
184 <        tmplep.ip3dSig = mu->ip3dSig;
178 >        tmplep.charge  = ele->Charge();
179 >        tmplep.isoTrk  = ele->TrackIsolationDr03();
180 >        tmplep.isoEcal = ele->EcalRecHitIsoDr03();
181 >        tmplep.isoHcal = ele->HcalTowerSumEtDr03();
182 >        tmplep.isoPF04 = elesel.isoPF04;
183 >        tmplep.chisoPF04 = elesel.chisoPF04;
184 >        tmplep.gaisoPF04 = elesel.gaisoPF04;
185 >        tmplep.neisoPF04 = elesel.neisoPF04;
186 >        // tmplep.isoPF03 = computePFEleIso(ele,vtx,pfCandidates,0.3);
187 >        // tmplep.isoPF04 = computePFEleIso(ele,vtx,pfCandidates,0.4);
188 >        tmplep.ip3dSig = ele->Ip3dPVSignificance();
189          tmplep.is4l    = false;
190 <        tmplep.isEB    = (fabs(mu->eta) < 1.479 ? 1 : 0 );
191 <        tmplep.isTight = musel.tight();
192 <        tmplep.isLoose = musel.loose();
190 >        tmplep.isEB    = ele->IsEB();
191 >        tmplep.scID    = ele->SCluster()->GetUniqueID();
192 >        tmplep.isTight = elesel.tight();
193 >        tmplep.isLoose = elesel.loose();
194 >        tmplep.status  = elesel;
195 >        tmplep.idMVA   = elesel.idMVA;
196 >        tmplep.isoMVA  = elesel.isoMVA;
197 >        tmplep.fsrRecoveryAttempted = false;
198 >        SelectionStatus tmpstat = electronTagSelection(ele,vtx,pfCandidates);
199 >        tmplep.tightCutsApplied   = tmpstat.tight();
200          lepvec.push_back(tmplep);
201 <        if( ctrl.debug ) { cout << "muon passes ... " << endl;}
201 >        if( ctrl.debug ) cout << endl;
202        }
142      //  }
143    }    
144  
145  
146    
147    //
148    if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
149    // --------------------------------------------------------------------------------
150    for(Int_t i=0; i<electronArr->GetEntries(); i++)
151      {
152        const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]);
153        
154        Bool_t isMuonOverlap = kFALSE;
155        for (int k=0; k<lepvec.size(); ++k) {
156          TVector3 tmplep;
157          tmplep.SetPtEtaPhi(ele->pt, ele->eta, ele->phi);
158          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        }
203  
204 <        // kick out non fiducial, low pT eles
205 <        if ( ele->pt < 7 || fabs(ele->eta) > 2.5 )
206 <          continue;
204 >    sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
205 >
206 >    //********************************************************
207 >    // Step 2: Lepton Cleaning
208 >    //********************************************************
209 >    vector<vector<SimpleLepton>::iterator> electrons_to_erase;
210 >    for (vector<SimpleLepton>::iterator it1=lepvec.begin(); it1 != lepvec.end(); it1++ ) {
211 >      if ( abs(it1->type) != 11 ) continue;
212 >      TVector3 evec = it1->vec.Vect();
213 >      
214 >      bool erase_this_electron=false;
215 >      for (vector<SimpleLepton>::iterator it2=lepvec.begin(); it2 != lepvec.end(); it2++ ) {
216 >        if ( it2 == it1 )                       continue;
217 >        if ( abs(it2->type) != 13 )             continue;
218 >        if( !(it2->status.looseIDAndPre()) )    continue;
219 >        TVector3 mvec = it2->vec.Vect();
220          
221 <        SelectionStatus elesel;
222 <        elesel |= (*ElectronPreSelector)(ctrl,ele);
223 <        elesel |= (*ElectronIDSelector)(ctrl,ele);
172 <        elesel |= (*ElectronIsoSelector)(ctrl,ele);
173 <
174 < //      if( elesel.getStatus() & SelectionStatus::PRESELECTION )
175 < //        elesel.setStatus(SelectionStatus::LOOSESELECTION);
176 <
177 <        if( ctrl.debug ){
178 <          cout << "\tscEt: " << ele->scEt
179 <               << "\tscEta: " << ele->scEta
180 <               << "\tncluster: " << ele->ncluster
181 <               << "\tisorel: " <<  ele->pfIso04/ele->pt
182 <               << "\tstatus: " << hex << elesel.getStatus() << dec
183 <               << endl;
221 >        if ( evec.DrEtaPhi(mvec) < 0.05 ) {
222 >          erase_this_electron=true;
223 >          break;
224          }
185
186        //      if ( elesel.pass() && !isMuonOverlap )
187        if ( !isMuonOverlap )
188          {
189            SimpleLepton tmplep;
190            
191            float pt = ele->pt;
192            tmplep.vecorig->SetPtEtaPhiM( pt,
193                                          ele->eta,
194                                          ele->phi,
195                                          ELECTRON_MASS );
196            
197            if( ctrl.do_escale ) {
198              pt=scale_smear_electron(pt, ele->isEB, r);
199            }
200            if( ctrl.do_escale_up ) {
201              pt=scale_smear_electron_Up(pt, ele->isEB,  r);
202            }
203            if( ctrl.do_escale_down ) {
204              pt=scale_smear_electron_Down(pt, ele->isEB,  r);
205            }
206
207            
208            tmplep.vec->SetPtEtaPhiM( pt,
209                                      ele->eta,
210                                      ele->phi,
211                                      ELECTRON_MASS );
212            
213            tmplep.type    = 11;
214            tmplep.index   = i;
215            tmplep.charge  = ele->q;
216            tmplep.isoTrk  = ele->trkIso03;
217            tmplep.isoEcal = ele->emIso03;
218            tmplep.isoHcal = ele->hadIso03;
219            tmplep.isoPF03 = ele->pfIso03;
220            tmplep.isoPF04 = ele->pfIso04;
221            tmplep.ip3dSig = ele->ip3dSig;
222            tmplep.is4l    = false;
223            tmplep.isEB    = ele->isEB;
224            tmplep.scID    = ele->scID;
225            tmplep.isTight = elesel.tight();
226            tmplep.isLoose = elesel.loose();
227            //      tmplep.isLoose = elesel.pass();
228            lepvec.push_back(tmplep);
229            if( ctrl.debug ) { cout << "\telectron passes ... " << endl; }
230          }
225        }
226 <    
227 <    
226 >      if( erase_this_electron )
227 >        electrons_to_erase.push_back(it1);
228 >    }
229 >    for( int i=0; i<electrons_to_erase.size(); i++ ) {
230 >      lepvec.erase(electrons_to_erase[i]);
231 >    }
232 >
233      //********************************************************
234 <    // Dump Stuff
234 >    // Step 3: Good Leptons
235      //********************************************************
236 <    sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
237 <    int nmu=0, nele=0;
238 <    for( int i=0; i<lepvec.size(); i++ ) {
239 <      if(ctrl.debug) cout << "lepvec :: index: " << i
240 <                          << "\tpt: " << lepvec[i].vec->Pt()
241 <                          << "\ttype: " << lepvec[i].type
242 <                          << endl;
243 <      if( abs(lepvec[i].type) == 11 ) nele++;
244 <      else nmu++;
236 >    vector<double> pt_of_leptons_to_erase;
237 >    for (int i=0; i<lepvec.size(); i++ ) {
238 >      bool already_pushed=false;
239 >      if( !(lepvec[i].status.loose()) ) {
240 >        pt_of_leptons_to_erase.push_back(lepvec[i].vec.Pt());
241 >        already_pushed = true;
242 >        failingLeptons.push_back(lepvec[i]); // these should pass preselection
243 >      } else {
244 >        passingLeptons.push_back(lepvec[i]);
245 >      }
246 > #ifndef SYNC
247 >      if( !already_pushed && fabs(lepvec[i].ip3dSig)>4 )  
248 >        pt_of_leptons_to_erase.push_back(lepvec[i].vec.Pt());
249 > #endif      
250      }
251 <    if( ctrl.debug ) {
252 <      cout << "postsel nlep: " << lepvec.size()
253 <           << "\tnmuon: " << nmu
254 <           << "\tnelectron: " << nele
255 <           << endl;
251 >    for( int i=0; i<pt_of_leptons_to_erase.size(); i++ ) {
252 >      for( vector<SimpleLepton>::iterator it=lepvec.begin(); it != lepvec.end(); it++ ) {
253 >        SimpleLepton flep = *it;
254 >        if( flep.vec.Pt() != pt_of_leptons_to_erase[i] ) continue;
255 >        lepvec.erase(it);
256 >        break;
257 >      }
258      }
259 <    
254 <    
259 >
260      //******************************************************************************
261 <    // Selection
261 >    // W + (OF SS lepton) Selection
262      //******************************************************************************
263 <    float bestMass=-1; int best_mu_index=-1, best_ele_index=-1;
264 <    for(int i = 0; i<lepvec.size(); i++) {      // get a tight muon
265 <      if( abs(lepvec[i].type) != 13 ) continue;
266 <      if( !(lepvec[i].isTight) ) continue;
267 <      //      if( lepvec[i].vec->Pt() < 35 ) continue;
268 <      if( ctrl.debug ) cout << "got a muon, index: " << i << endl;
269 <
270 <      for(int j = 0; j<lepvec.size(); j++) {     // get a loose electron
271 <        if( j == i ) continue;
267 <        if( abs(lepvec[j].type) != 11 ) continue;
268 <        //      if( !(lepvec[j].isLoose) ) continue;
269 <        //      if (lepvec[i].charge == lepvec[j].charge) continue;          
270 <        if (lepvec[i].charge != lepvec[j].charge) continue;          
271 <        if( ctrl.debug ) cout << "got a electron, index: " << j << endl;
272 <
273 <        float tmpMass = ( *(lepvec[i].vec) + *(lepvec[j].vec) ).M();
274 <        if( ctrl.debug ) cout << "tmp vs best :: " << tmpMass << "," << bestMass << endl;
275 <        if( tmpMass > bestMass ) {
276 <          bestMass = tmpMass;
277 <          best_mu_index=i;
278 <          best_ele_index=j;
279 <        }
280 <
263 >    if(ctrl.fakeScheme.Contains("emu-")) {
264 >      if(has_ssof_lepton(ctrl)) {
265 >        ret.status.setStatus(SelectionStatus::EVTPASS);
266 >        ret.Z1leptons.push_back(passingLeptons[0]);
267 >        ret.Z1leptons.push_back(passingLeptons[0]);
268 >        ret.Z2leptons.push_back(passingLeptons[0]);
269 >        ret.Z2leptons.push_back(passingLeptons[0]);
270 >      } else {
271 >        ret.status.setStatus(SelectionStatus::FAIL);
272        }
282    }
283
284    if( bestMass > 0 ) {
285      if( ctrl.debug ) cout << "EMU candidate, mass : " << bestMass << endl;
286
287 //       if( lepvec[best_ele_index].isTight )
288 //      ret.status.setStatus(SelectionStatus::TIGHTSELECTION);
289 //       else
290 //      ret.status.setStatus(SelectionStatus::LOOSESELECTION);
291
292      if( lepvec[best_ele_index].isTight )
293        ret.status.setStatus(SelectionStatus::TIGHTSELECTION);
294      if( lepvec[best_ele_index].isLoose )
295        ret.status.setStatus(SelectionStatus::LOOSESELECTION);
296      if( !(lepvec[best_ele_index].isTight) && !(lepvec[best_ele_index].isLoose)  )
297        ret.status.setStatus(SelectionStatus::UNDEFINED); // using preselection here to mean that muon
298                                                          // is good & ele pass neither loose or tight
299
300      ret.Z1leptons.push_back(lepvec[best_mu_index]);
301      ret.Z1leptons.push_back(lepvec[best_ele_index]);
302      ret.Z2leptons.push_back(lepvec[best_mu_index]);
303      ret.Z2leptons.push_back(lepvec[best_ele_index]);
273        return ret;
274      }
306
307    ret.status.setStatus(SelectionStatus::FAIL);
308    return ret;
309
275   }
276  
277 + // //----------------------------------------------------------------------------
278 + // //
279 + // // Get primary vertices
280 + // // Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
281 + // // NOTE: if no PV is found from fitting tracks, the beamspot is used
282 + // //
283 + // //----------------------------------------------------------------------------
284 + // bool setPV(ControlFlags ctrl,
285 + //         const mithep::Array<mithep::Vertex> * vtxArr,
286 + //         const mithep::Vertex* &vtx)
287 + // //----------------------------------------------------------------------------
288 + // {
289 +
290 + //   const mithep::Vertex *bestPV = 0;    
291 + //   float best_sumpt=-1;
292 +
293 + //   // good PV requirements
294 + //   const UInt_t   fMinNTracksFit = 0;
295 + //   const Double_t fMinNdof       = 4;
296 + //   const Double_t fMaxAbsZ       = 24;
297 + //   const Double_t fMaxRho        = 2;
298 +  
299 + //   for(int i=0; i<vtxArr->GetEntries(); ++i) {
300 + //     const mithep::Vertex *pv = (mithep::Vertex*)(vtxArr->At(i));
301 + //     if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
302 +    
303 + //     // Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
304 + //     if(!pv->IsValid())                                continue;
305 + //     if(pv->NTracksFit()       < fMinNTracksFit)       continue;
306 + //     if(pv->Ndof()              < fMinNdof)         continue;
307 + //     if(fabs(pv->Z()) > fMaxAbsZ)                   continue;
308 + //     if(pv->Position().Rho()   > fMaxRho)           continue;    
309 +    
310 + //     // take the first ...
311 + //     bestPV = pv;
312 + //     break;
313 +
314 + //     // this never reached ...    
315 + //     float tmp_sumpt=0;
316 + //     for( int t=0; t<pv->NTracks(); t++ )
317 + //       tmp_sumpt += pv->Trk(t)->Pt();
318 +    
319 + //     if( tmp_sumpt > best_sumpt  ) {
320 + //       bestPV = pv;
321 + //       best_sumpt = tmp_sumpt;
322 + //       if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
323 + //     }
324 + //   }
325 +        
326 + //   // sync
327 + //   if(!bestPV)
328 + //     return false;
329 + //   else {    
330 + //     vtx = bestPV;
331 + //     return true;
332 + //   }  
333 + // };
334 + //----------------------------------------------------------------------------------------
335 + bool has_ssof_lepton(ControlFlags &ctrl)
336 + {
337 +  bool has_ssof=false;
338 +  for(unsigned iw=0; iw<passingLeptons.size(); iw++) {
339 +    SimpleLepton w_lep = passingLeptons[iw];
340 +    //????????????????????????????????????????????????????????????????????????????????????????
341 +    // this is applied in skim (skim also applies ww muon id)
342 +    // if(abs(w_lep.type) == 11) {
343 +    //   if( !(w_lep.tightCutsApplied) )
344 +    //  continue;
345 +    // }
346 +    //????????????????????????????????????????????????????????????????????????????????????????
347 +    for(unsigned ifake=0; ifake<failingLeptons.size(); ifake++) {
348 +      SimpleLepton fake_lep = failingLeptons[ifake];
349 +      if(abs(fake_lep.type) == abs(w_lep.type)) continue;
350 +      if(fake_lep.charge != w_lep.charge) continue;
351 +      has_ssof = true;
352 +    }
353 +    for(unsigned ipass=0; ipass<passingLeptons.size(); ipass++) {
354 +      if(ipass == iw) continue;
355 +      SimpleLepton pass_lep = passingLeptons[ipass];
356 +      if(abs(pass_lep.type) == abs(w_lep.type)) continue;
357 +      if(pass_lep.charge != w_lep.charge) continue;
358 +      has_ssof = true;
359 +    }
360 +  }
361  
362 +  return has_ssof;
363 + }
364 + // //----------------------------------------------------------------------------------------
365 + // void getEATargets(ControlFlags &ctrl, mithep::MuonTools::EMuonEffectiveAreaTarget &eraMu, mithep::ElectronTools::EElectronEffectiveAreaTarget &eraEle)
366 + // {
367 + //   if( !ctrl.mc && ctrl.era == 2011 ) {
368 + //     eraMu  = mithep::MuonTools::kMuEAData2011;
369 + //     eraEle = mithep::ElectronTools::kEleEAData2011;
370 + //   } else if( !ctrl.mc && ctrl.era == 2012 ) {
371 + //     eraMu  = mithep::MuonTools::kMuEAData2012;
372 + //     eraEle = mithep::ElectronTools::kEleEAData2012;
373 + //   } else if( ctrl.mc && ctrl.era == 2011 ) {
374 + //     eraMu  = mithep::MuonTools::kMuEAFall11MC;
375 + //     eraEle = mithep::ElectronTools::kEleEAFall11MC;
376 + //   } else if( ctrl.mc && ctrl.era == 2012 ) {
377 + //     eraMu  = mithep::MuonTools::kMuEAData2012;
378 + //     eraEle = mithep::ElectronTools::kEleEAData2012;
379 + //   } else {
380 + //     cerr << "unknown era for effective areas ... quitting." << endl;
381 + //     exit(1);
382 + //   }
383 + // }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines