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.5 by dkralph, Tue Jun 12 22:39:31 2012 UTC vs.
Revision 1.16 by dkralph, Tue Oct 23 11:24:27 2012 UTC

# Line 30 | Line 30
30  
31   extern vector<SimpleLepton> failingLeptons;
32   extern vector<SimpleLepton> passingLeptons;
33 + extern vector<int> muTrigObjs,eleTrigObjs,muTriggers,eleTriggers;
34 + extern bitset<TRIGGER_BIG_NUMBER> triggerBits;
35  
36   //--------------------------------------------------------------------------------------------------
37   EventData apply_HZZ4L_EMU_selection(ControlFlags &ctrl,           // input control
38 <                                        const mithep::EventHeader *info,     // input event info
39 <                                        const mithep::Array<mithep::Vertex>       * vtxArr ,
40 <                                        const mithep::Array<mithep::PFCandidate>  *pfCandidates,
41 <                                        const mithep::Array<mithep::PileupEnergyDensity>  *puEnergyDensity,
42 <                                        const mithep::Array<mithep::Electron> *electronArr,    // input electrons
43 <                                        SelectionStatus (*ElectronPreSelector)( ControlFlags &,
44 <                                                                                const mithep::Electron*,
45 <                                                                                const mithep::Vertex *),
46 <                                        SelectionStatus (*ElectronIDSelector)( ControlFlags &,
47 <                                                                               const mithep::Electron*,
48 <                                                                               const mithep::Vertex *),
49 <                                        SelectionStatus (*ElectronIsoSelector)( ControlFlags &,
50 <                                                                                const mithep::Electron*,
51 <                                                                                const mithep::Vertex *,
52 <                                                                                const mithep::Array<mithep::PFCandidate> *,
53 <                                                                                const mithep::Array<mithep::PileupEnergyDensity> *,
54 <                                                                                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*,
38 >                                    const mithep::EventHeader *info,     // input event info
39 >                                    mithep::TriggerTable *hltTable,
40 >                                    mithep::Array<mithep::TriggerObject> *hltObjArr,
41 >                                    mithep::TriggerObjectsTable *fTrigObjs,
42 >                                    const mithep::Array<mithep::Vertex>       * vtxArr ,
43 >                                    const mithep::Array<mithep::PFCandidate>  *pfCandidates,
44 >                                    const mithep::Array<mithep::PileupEnergyDensity>  *puEnergyDensity,
45 >                                    const mithep::DecayParticleCol *fConversions,
46 >                                    const mithep::Array<mithep::Electron> *electronArr,    // input electrons
47 >                                    SelectionStatus (*ElectronPreSelector)( ControlFlags &,
48 >                                                                            const mithep::Electron*,
49 >                                                                            const mithep::Vertex *),
50 >                                    SelectionStatus (*ElectronIDSelector)( ControlFlags &,
51 >                                                                           const mithep::Electron*,
52 >                                                                           const mithep::Vertex *),
53 >                                    SelectionStatus (*ElectronIsoSelector)( ControlFlags &,
54 >                                                                            const mithep::Electron*,
55                                                                              const mithep::Vertex *,
56 <                                                                            const mithep::Array<mithep::PFCandidate> *,
56 >                                                                            const mithep::Array<mithep::PFCandidate> *,
57                                                                              const mithep::Array<mithep::PileupEnergyDensity> *,
58 <                                                                            mithep::MuonTools::EMuonEffectiveAreaTarget,
59 <                                                                            vector<const mithep::PFCandidate*>)
60 <                                        )
58 >                                                                            mithep::ElectronTools::EElectronEffectiveAreaTarget,
59 >                                                                            vector<const mithep::PFCandidate*>),
60 >                                    const mithep::Array<mithep::Muon> *muonArr,    // input muons
61 >                                    SelectionStatus (*MuonPreSelector)( ControlFlags &,
62 >                                                                        const mithep::Muon*,
63 >                                                                        const mithep::Vertex *,
64 >                                                                        const mithep::Array<mithep::PFCandidate> *),
65 >                                    SelectionStatus (*MuonIDSelector)( ControlFlags &,
66 >                                                                       const mithep::Muon*,
67 >                                                                       // const mithep::Vertex &),
68 >                                                                       const mithep::Vertex *,
69 >                                                                       const mithep::Array<mithep::PFCandidate> *),
70 >                                    SelectionStatus (*MuonIsoSelector)( ControlFlags &,
71 >                                                                        const mithep::Muon*,
72 >                                                                        const mithep::Vertex *,
73 >                                                                        const mithep::Array<mithep::PFCandidate> *,
74 >                                                                        const mithep::Array<mithep::PileupEnergyDensity> *,
75 >                                                                        mithep::MuonTools::EMuonEffectiveAreaTarget,
76 >                                                                        vector<const mithep::PFCandidate*>)
77 >                                    )
78   //--------------------------------------------------------------------------------------------------
79   {      
80  
# Line 106 | Line 112 | EventData apply_HZZ4L_EMU_selection(Cont
112      {
113        const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[i]);      
114        
109      SelectionStatus musel;
115  
116 <      musel |= (*MuonPreSelector)(ctrl,mu,vtx,pfCandidates);
117 <      if( !(musel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
116 >      SelectionStatus denomSel;
117 >      denomSel |= muonPreSelectionNoD0IP(ctrl,mu,vtx,pfCandidates);
118 >      if( !denomSel.passPre() ) continue;
119  
120 +      SelectionStatus musel;
121 +      musel |= (*MuonPreSelector)(ctrl,mu,vtx,pfCandidates);
122        musel |= (*MuonIDSelector)(ctrl,mu,vtx,pfCandidates );
123 <
116 <      if( !(ctrl.doFSR) ) {
117 <        musel |=  (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);
118 <      }
123 >      musel |= (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);
124  
125        SimpleLepton tmplep;
126        float pt = mu->Pt();
# Line 127 | Line 132 | EventData apply_HZZ4L_EMU_selection(Cont
132        tmplep.type    = 13;
133        tmplep.index   = i;
134        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);
135        tmplep.ip3dSig = mu->Ip3dPVSignificance();
136        tmplep.is4l    = false;
137        tmplep.isEB    = (fabs(mu->Eta()) < 1.479 ? 1 : 0 );
142      tmplep.isoMVA  = musel.isoMVA;
143      tmplep.isTight = musel.tight();
138        tmplep.isLoose = musel.loose();
139 +
140 +      bitset<TRIGGER_BIG_NUMBER> hltMatchBits = fillHLTMatchBits( mu->Eta(), mu->Phi(), hltTable, hltObjArr, fTrigObjs);
141 +      tmplep.isTight = testBits(ctrl,triggerBits,muTriggers,hltMatchBits,muTrigObjs);
142 +
143 +      tmplep.scID = 0;
144 +      if(triggerBits.test(kHLT_IsoMu24_eta2p1))        tmplep.scID |= 1;
145 +      if(hltMatchBits.test(kHLT_IsoMu24_eta2p1_MuObj)) tmplep.scID |= 2;
146 +      if(triggerBits.test(kHLT_IsoMu24))               tmplep.scID |= 4;
147 +      if(hltMatchBits.test(kHLT_IsoMu24_MuObj))        tmplep.scID |= 8;
148 +
149        tmplep.status  = musel;    
150        tmplep.fsrRecoveryAttempted = false;
151 <      tmplep.tightCutsApplied   = false;
151 >      tmplep.tightCutsApplied = muon2012CutBasedIDTightVersionWithOldIsoThatWorksOn2011(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu);
152 >      tmplep.d0      = mu->HasTrackerTrk() ? mu->TrackerTrk()->D0Corrected(*vtx) : 0;
153 >      tmplep.dz      = mu->HasTrackerTrk() ? mu->TrackerTrk()->DzCorrected(*vtx) : 0;
154 >
155        lepvec.push_back(tmplep);
156        if( ctrl.debug ) cout << endl;
157      }
# Line 155 | Line 162 | EventData apply_HZZ4L_EMU_selection(Cont
162        {
163          const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);
164  
165 <        SelectionStatus elesel;
165 >        SelectionStatus denomSel;
166 >        denomSel |= electronPreSelectionNoD0IP(ctrl,ele,vtx);
167 >        if( !denomSel.passPre() ) continue;
168          
169 +        SelectionStatus elesel;
170          elesel |= (*ElectronPreSelector)(ctrl,ele,vtx);
161        if( !(elesel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
162        
171          elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
172 <        
165 <        if( !(ctrl.doFSR) ) {
166 <          elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
167 <        }
172 >        elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
173          
174          SimpleLepton tmplep;
175          float pt = ele->Pt();
# Line 176 | Line 181 | EventData apply_HZZ4L_EMU_selection(Cont
181          tmplep.type    = 11;
182          tmplep.index   = i;
183          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);
184          tmplep.ip3dSig = ele->Ip3dPVSignificance();
185          tmplep.is4l    = false;
186          tmplep.isEB    = ele->IsEB();
187 <        tmplep.scID    = ele->SCluster()->GetUniqueID();
188 <        tmplep.isTight = elesel.tight();
187 >        // tmplep.scID    = ele->SCluster()->GetUniqueID();
188 >
189 >        bitset<TRIGGER_BIG_NUMBER> hltMatchBits = fillHLTMatchBits( ele->Eta(), ele->Phi(), hltTable, hltObjArr, fTrigObjs);
190 >        tmplep.isTight = testBits(ctrl,triggerBits,eleTriggers,hltMatchBits,eleTrigObjs);
191 >
192          tmplep.isLoose = elesel.loose();
193          tmplep.status  = elesel;
195        tmplep.idMVA   = elesel.idMVA;
196        tmplep.isoMVA  = elesel.isoMVA;
194          tmplep.fsrRecoveryAttempted = false;
195 <        SelectionStatus tmpstat = electronTagSelection(ele,vtx,pfCandidates);
196 <        tmplep.tightCutsApplied   = tmpstat.tight();
195 >        tmplep.tightCutsApplied = electron2012CutBasedIDMediumVersionThatWorksOn2011(ctrl,ele,vtx,pfCandidates,fConversions,puEnergyDensity,eraEle);
196 >        tmplep.d0      = ele->BestTrk()->D0Corrected(*vtx);
197 >        tmplep.dz      = ele->BestTrk()->DzCorrected(*vtx);
198 >
199          lepvec.push_back(tmplep);
200          if( ctrl.debug ) cout << endl;
201        }
# Line 215 | Line 214 | EventData apply_HZZ4L_EMU_selection(Cont
214        for (vector<SimpleLepton>::iterator it2=lepvec.begin(); it2 != lepvec.end(); it2++ ) {
215          if ( it2 == it1 )                       continue;
216          if ( abs(it2->type) != 13 )             continue;
217 <        if( !(it2->status.looseIDAndPre()) )    continue;
217 >        // if( !(it2->status.looseIDAndPre()) )    continue;
218          TVector3 mvec = it2->vec.Vect();
219          
220          if ( evec.DrEtaPhi(mvec) < 0.05 ) {
# Line 233 | Line 232 | EventData apply_HZZ4L_EMU_selection(Cont
232      //********************************************************
233      // Step 3: Good Leptons
234      //********************************************************
236    vector<double> pt_of_leptons_to_erase;
235      for (int i=0; i<lepvec.size(); i++ ) {
238      bool already_pushed=false;
236        if( !(lepvec[i].status.loose()) ) {
237 <        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
237 >        failingLeptons.push_back(lepvec[i]);
238        } else {
239          passingLeptons.push_back(lepvec[i]);
240        }
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    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      }
241      }
242  
243      //******************************************************************************
244      // W + (OF SS lepton) Selection
245      //******************************************************************************
246 <    if(ctrl.fakeScheme.Contains("emu-")) {
247 <      if(has_ssof_lepton(ctrl)) {
248 <        ret.status.setStatus(SelectionStatus::EVTPASS);
249 <        ret.Z1leptons.push_back(passingLeptons[0]);
250 <        ret.Z1leptons.push_back(passingLeptons[0]);
251 <        ret.Z2leptons.push_back(passingLeptons[0]);
252 <        ret.Z2leptons.push_back(passingLeptons[0]);
253 <      } else {
271 <        ret.status.setStatus(SelectionStatus::FAIL);
272 <      }
273 <      return ret;
246 >    if(has_ssof_lepton(ctrl)) {
247 >      ret.status.setStatus(SelectionStatus::EVTPASS);
248 >      ret.Z1leptons.push_back(passingLeptons[0]);
249 >      ret.Z1leptons.push_back(passingLeptons[0]);
250 >      ret.Z2leptons.push_back(passingLeptons[0]);
251 >      ret.Z2leptons.push_back(passingLeptons[0]);
252 >    } else {
253 >      ret.status.setStatus(SelectionStatus::FAIL);
254      }
255 +    return ret;
256   }
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 // };
257   //----------------------------------------------------------------------------------------
258   bool has_ssof_lepton(ControlFlags &ctrl)
259   {
# Line 361 | Line 284 | bool has_ssof_lepton(ControlFlags &ctrl)
284  
285    return has_ssof;
286   }
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