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

Comparing UserCode/MitHzz4l/LeptonSelection/src/MuonSelection.cc (file contents):
Revision 1.1 by khahn, Mon Feb 13 09:35:20 2012 UTC vs.
Revision 1.32 by anlevin, Thu Jul 5 19:34:29 2012 UTC

# Line 1 | Line 1
1   #include <math.h>
2   #include <iostream>
3  
4 #include "HiggsAnaDefs.hh"
5
4   #include "MuonSelection.h"
5   #include "ParseArgs.h"
6   #include "SelectionStatus.h"
7  
8 + #include "Track.h"
9 + #include "MuonTools.h"
10 + #include "MuonQuality.h"
11 + #include "MuonIDMVA.h"
12 +
13 + mithep::MuonIDMVA * muIDMVA;
14 + mithep::MuonTools muTools;
15 +
16 + extern vector<bool> PFnoPUflag;
17 + extern Float_t computePFMuonIso(const mithep::Muon *mu,
18 +                        const mithep::Vertex * vtx,
19 +                        const mithep::Array<mithep::PFCandidate> * pfCandidates,
20 +                        const Double_t dRMax);
21  
22 < SelectionStatus muonPreSelection( ControlFlags &ctrl,  const mithep::TMuon * mu ) {
23 <  if(ctrl.debug) cout << "inside muonpresel ... " << endl;
13 <  bool ret = isMuFO(mu);
14 <  if(ctrl.debug) cout << "iS fo? ... " << ret << endl;  
15 <  ret &= ( fabs(mu->ip3dSig) < 4 ? true : false );
16 <  if(ctrl.debug) cout << "and pass IP (" << mu->ip3dSig << ") ? ... " << ret << endl;  
17 <  ret &= ( mu->pt > 5 ? true : false );
18 <  if(ctrl.debug) cout << "and >5 GeV ? ... " << ret << endl;  
19 <  ret &= ( fabs(mu->eta) < 2.4 ? true : false );
20 <  if(ctrl.debug) cout << "and < 2.4 eta ? ... " << ret << endl;  
21 <
22 <  SelectionStatus status;
23 <  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
24 <  if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;  
25 <  return status;
26 < }
27 <
28 < bool isMuFO( const mithep::TMuon * mu ) {
29 <  bool isgood=true;
30 <  float reliso = mu->pfIso03/mu->pt;
31 <
32 <  if( mu->pt < 5  )         isgood=false;                          
33 <  if ( fabs(mu->dz) > 0.2 ) isgood=false;   // needed to remove cosmics in HF sample
34 <
35 <  //
22 > bool muonPOG2012CutBasedIDTight(const mithep::Muon *mu, const mithep::Vertex * vtx, const mithep::Array<mithep::PFCandidate> * pfCandidates, const mithep::Array<mithep::PileupEnergyDensity> * puEnergyDensity)
23 > {
24  
25 <  // HF seems to not want tkquality, SS does
26 <  if( mu->pt>20 ) {
27 <    if ( !((mu->typeBits & kGlobal) && mu->nSeg>0  ) ) isgood=false; //&& mu->nValidHits>0
28 <  } else {
29 <    if ( !((mu->typeBits & kGlobal) && mu->nSeg>0 ) //&& //&& mu->nValidHits>0
30 <         && !( (mu->typeBits & kTracker) &&  (mu->qualityBits & kTMOneStationLoose)
31 <               )
32 <         )   isgood=false;
25 >  Float_t charged_iso = 0;
26 >  
27 >  Float_t sumChargedHadronPt = 0;
28 >  Float_t sumNeutralHadronPt = 0;
29 >  Float_t sumPhotonPt = 0;
30 >  Float_t sumPUPt = 0;
31 >
32 >  for(unsigned k=0; k<pfCandidates->GetEntries(); ++k) {
33 >    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfCandidates)[k]);
34 >    Double_t dr = mithep::MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
35 >    if(dr > 0.4) continue;
36 >    if(pf->TrackerTrk() && mu->TrackerTrk() && pf->TrackerTrk() == mu->TrackerTrk()) continue;
37 >
38 >    if(PFnoPUflag[k]){ //pf no pileup
39 >      if(abs(pf->PFType()) == mithep::PFCandidate::eHadron)
40 >        sumChargedHadronPt += pf->Pt();
41 >      else if (pf->Pt() > 0.5 && abs(pf->PFType()) == mithep::PFCandidate::eNeutralHadron)
42 >        sumNeutralHadronPt += pf->Pt();
43 >      else if (pf->Pt() > 0.5 && abs(pf->PFType()) == mithep::PFCandidate::eGamma)
44 >        sumPhotonPt += pf->Pt();
45 >    }
46 >    else {//pf pile up
47 >      if(pf->Charge() != 0)
48 >        sumPUPt += pf->Pt();
49 >    }
50 >  
51    }
52 +  double iso_sum =  sumChargedHadronPt+ max(0.,sumNeutralHadronPt+sumPhotonPt-0.5*sumPUPt);
53  
54 +  bool pass = kTRUE;
55 +  if(!mu->IsGlobalMuon()) pass = kFALSE;
56  
57 <  //
58 <  // for HF MC to agree w/ data, cannot put any Tk quality bits
50 <  // but to get to 5% closure in the SS test, we need at least Tk oneStationLoose
57 >  //there is not necessarily a global track or a tracker track if is global muon is false
58 >  if(!pass) return pass;
59  
60 <  /*
61 < && ( (mu->qualityBits & kTMOneStationLoose) ||
62 <                                               (mu->qualityBits & kTMLastStationOptimizedBarrelLowPtLoose) ||
63 <                                               (mu->qualityBits & kTMLastStationOptimizedLowPtLoose)
64 <                                               )
65 <  */
60 >  if(!mu->IsPFMuon()) pass = kFALSE;
61 >  if(mu->GlobalTrk()->RChi2() > 10) pass= kFALSE;
62 >  if(mu->NValidHits() == 0 ) pass= kFALSE;
63 >  if(mu->NMatches() <= 1) pass = kFALSE;
64 >  if(fabs(mu->TrackerTrk()->D0Corrected(*vtx)) > 0.2) pass = kFALSE;
65 >  if(fabs(mu->TrackerTrk()->DzCorrected(*vtx)) > 0.5) pass = kFALSE;
66 >  if(mu->BestTrk()->NPixelHits() == 0) pass = kFALSE;
67 >  if(mu->NTrkLayersHit() <= 5) pass = kFALSE;
68 >  if(iso_sum/mu->Pt() > 0.12 ) pass = kFALSE;
69  
70 +  return pass;
71  
60  // comment for more stats for mu fake shape
61  if( mu->pt < 20 ) {
62    if( reliso > 3 ) isgood=false;    
63  } else {
64    if( reliso > 5 ) isgood=false;    
65  }
72  
73 <  return isgood;
74 < };
73 > }
74 >
75  
76 + bool muon2012CutBasedIDTight(const mithep::Muon *mu, const mithep::Vertex * vtx, const mithep::Array<mithep::PFCandidate> * pfCandidates, const mithep::Array<mithep::PileupEnergyDensity> * puEnergyDensity)
77 + {
78  
79 < SelectionStatus passSoftMuonSelection( ControlFlags &ctrl, const mithep::TMuon * mu ) {
79 >  mithep::MuonTools   muT;
80  
81 <  int level=0;
82 <  unsigned failmask=0x0;
81 >  Float_t charged_iso = 0;
82 >  Float_t neutral_iso = 0;
83 >  Float_t gamma_iso = 0;
84    
85 <  if(mu->nTkHits < 11 )  
86 <    failmask |= (1<<level);
87 <  level++;
85 >  for(int k=0; k<pfCandidates->GetEntries(); ++k) {
86 >    
87 >    if( !(PFnoPUflag[k]) ) continue;
88 >    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfCandidates)[k]);
89 >    
90 >    Double_t dr = mithep::MathUtils::DeltaR(mu->Phi(),mu->Eta(), pf->Phi(), pf->Eta());
91 >    if (dr > 0.4) continue;
92 >    
93 >    if (pf->Charge() != 0 && (pf->HasTrackerTrk()||pf->HasGsfTrk()) ) {
94 >      
95 >      if (abs(pf->PFType()) == mithep::PFCandidate::eElectron || abs(pf->PFType()) == mithep::PFCandidate::eMuon) continue;
96 >      
97 >      charged_iso += pf->Pt();
98 >    }
99 >    
100 >    else if (abs(pf->PFType()) == mithep::PFCandidate::eGamma) {
101 >      
102 >      gamma_iso += pf->Pt();
103 >    }
104 >    
105 >    else {
106 >      neutral_iso += pf->Pt();
107 >    }
108 >  }
109 >  
110 >  mithep::MuonTools::EMuonEffectiveAreaTarget EffectiveAreaVersion  = mithep::MuonTools::kMuEAData2012;
111 >  float rho = puEnergyDensity->At(0)->RhoKt6PFJetsCentralNeutral();
112 >  
113 >  double iso_sum = charged_iso + fmax(0.0,(gamma_iso + neutral_iso
114 >                                        -rho*muT.MuonEffectiveArea(muT.kMuGammaAndNeutralHadronIso04,
115 >                                                                   mu->Eta(),EffectiveAreaVersion)));
116 >
117 >  bool pass = kTRUE;
118 >  if(!mu->IsGlobalMuon()) pass = kFALSE;
119 >
120 >  //there is not necessarily a global track or a tracker track if is global muon is false
121 >  if(!pass) return pass;
122 >
123 >  if(!mu->IsPFMuon()) pass = kFALSE;
124 >  if(mu->GlobalTrk()->RChi2() > 10) pass= kFALSE;
125 >  if(mu->NValidHits() == 0 ) pass= kFALSE;
126 >  if(mu->NMatches() <= 1) pass = kFALSE;
127 >  if(fabs(mu->TrackerTrk()->D0Corrected(*vtx)) > 0.2) pass = kFALSE;
128 >  if(fabs(mu->TrackerTrk()->DzCorrected(*vtx)) > 0.5) pass = kFALSE;
129 >  if(mu->BestTrk()->NPixelHits() == 0) pass = kFALSE;
130 >  if(mu->NTrkLayersHit() <= 5) pass = kFALSE;
131 >  if(iso_sum/mu->Pt() > 0.12 ) pass = kFALSE;
132 >
133 >  return pass;
134 >
135 >
136 > }
137 >
138 > bool trackToPFMuonSelection( const mithep::Track *track, const mithep::MuonCol * muoncol )
139 > {
140 >        bool pass = false;
141 >  for(UInt_t i=0; i<muoncol->GetEntries(); ++i) {
142 >    const mithep::Muon *mu = muoncol->At(i);
143 >                if(mu->TrackerTrk() == track && (mu->IsGlobalMuon() || mu->IsTrackerMuon()) && mu->IsPFMuon())
144 >                        pass = true;
145 >        }              
146 >                
147 >        return pass;            
148 >                
149 > }
150  
151 <  if(fabs(mu->d0) > 0.2)
152 <    failmask |= (1<<level);
153 <  level++;
151 > //--------------------------------------------------------------------------------------------------
152 > SelectionStatus muonDummyVeto(ControlFlags &ctrl,
153 >                              const mithep::Muon *muon,
154 >                              const mithep::Vertex * vtx)
155 > //--------------------------------------------------------------------------------------------------
156 > {
157 >  SelectionStatus status;
158 >  status.setStatus(SelectionStatus::PRESELECTION);
159 >  return status;  
160 > }
161  
162 <  if(fabs(mu->dz) > 0.1)
163 <    failmask |= (1<<level);
164 <  level++;
162 > //--------------------------------------------------------------------------------------------------
163 > SelectionStatus muonCutBasedVeto(ControlFlags &ctrl,
164 >                                 const mithep::Muon *muon,
165 >                                 const mithep::Vertex *vtx)
166 > //--------------------------------------------------------------------------------------------------
167 > {
168 >  //
169 >  // Loose cut-based ID for isolation veto
170 >  //
171 >  bool ret = true;
172 >  
173 >  if(!(muon->IsGlobalMuon() || muon->IsTrackerMuon())) ret = false;
174 >  if( muon->NValidHits() < 11 )                        ret = false;
175 >  if( fabs(muon->Ip3dPVSignificance()) >= 4 )          ret = false;
176  
177 <  if(!(mu->typeBits & kTracker))
178 <    failmask |= (1<<level);
179 <  level++;
177 >  SelectionStatus status;
178 >  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
179 >  return status;
180 > }
181  
92  if(!(mu->qualityBits & kTMLastStationAngTight))
93    failmask |= (1<<level);      
94  level++;
182  
183 <  Double_t iso = (mu->trkIso03 + mu->emIso03 + mu->hadIso03)/mu->pt;
184 <  if(mu->pt>20 && iso<0.1)
98 <    failmask |= (1<<level);
183 > //--------------------------------------------------------------------------------------------------
184 > SelectionStatus noPreSelection( ControlFlags &ctrl,  const mithep::Muon * mu )
185  
186 <  bool passtight  = !(failmask);
187 <  bool passloose  = !(failmask);
188 <  return SelectionStatus( passtight | passloose );
189 <  
186 > //--------------------------------------------------------------------------------------------------
187 > {
188 >        SelectionStatus status;
189 >        status.setStatus(SelectionStatus::PRESELECTION);
190 >        if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;
191 >        return status;
192   }
193  
194 <
195 < //unsigned passMuonSelectionZZ( const mithep::TMuon * mu ) {
196 < SelectionStatus passMuonSelectionZZ( ControlFlags &ctrl, const mithep::TMuon * mu ) {
197 <  int level=0;
198 <  unsigned failmask=0x0;
194 > //--------------------------------------------------------------------------------------------------
195 > SelectionStatus muonPreSelection( ControlFlags &ctrl,  
196 >                                  const mithep::Muon * mu,
197 >                                  const mithep::Vertex * vtx,
198 >                                  const mithep::Array<mithep::PFCandidate> * pfCandidates )
199 > //--------------------------------------------------------------------------------------------------
200 > {
201 >  bool ret = true;
202 >
203 >  ret &= ( fabs(mu->Ip3dPVSignificance()) < 100 );
204 >  ret &= ( mu->Pt() >= 5 );
205 >  ret &= ( fabs(mu->Eta()) <= 2.4 );
206 >  ret &= ( mu->IsTrackerMuon() || mu->IsGlobalMuon() );
207 > //   if( mu->IsTrackerMuon() && mu->HasTrackerTrk() && !mu->IsGlobalMuon() )  
208 > //     ret &=  ( mu->Quality().QualityMask().Mask() & mithep::MuonQuality::AllArbitrated);
209 >  ret &= (  mu->IsoR03SumPt()/mu->Pt() < 0.7 );
210  
211 <  if(mu->pt < 5) {
212 <    failmask |= (1<<level);
213 <  }
211 >  SelectionStatus status;
212 >  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
213 >  if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;  
214 >  return status;
215 > }
216  
116  level++;
117  if(fabs(mu->eta) > 2.4) {
118    failmask |= (1<<level);
119  }
217  
121  level++;
122  if(!(mu->typeBits & kGlobal)) {
123    failmask |= (1<<level);
124  }
218  
219 <  level++;
220 <  if(mu->nTkHits          < 10) {
221 <    failmask |= (1<<level);
222 <  }
219 > //--------------------------------------------------------------------------------------------------
220 > SelectionStatus muonReferencePreSelection( ControlFlags &ctrl,  
221 >                                           const mithep::Muon * mu,
222 >                                           const mithep::Vertex * vtx,
223 >                                           const mithep::Array<mithep::PFCandidate> * pfCandidates )
224 > //--------------------------------------------------------------------------------------------------
225 > {
226 >  bool ret = true;
227  
228 +  if(ctrl.debug) cout << "inside muonpresel ... " << endl;
229 +  ret &= ( fabs(mu->Ip3dPVSignificance()) < 100 );
230 +  if(ctrl.debug) cout << "and pass IP (" << mu->Ip3dPVSignificance() << ") ? ... " << ret << endl;  
231 +  ret &= ( mu->Pt() >= 5 );
232 +  if(ctrl.debug) cout << "and >5 GeV (" << mu->Pt() << ") ? ... " << ret << endl;  
233 +  ret &= ( fabs(mu->Eta()) <= 2.4 );
234 +  if(ctrl.debug) cout << "and < 2.4 eta (" << mu->Eta() << ")? ... " << ret << endl;  
235 +  ret &= ( mu->IsTrackerMuon() || mu->IsGlobalMuon() );
236 +  if(ctrl.debug) cout << "is Tracker or Global? ... " << ret << endl;
237 +  ret &= (mu->HasTrackerTrk() &&
238 +          fabs(mu->TrackerTrk()->D0Corrected(*vtx)) < 0.5 &&
239 +          fabs(mu->TrackerTrk()->DzCorrected(*vtx)) < 1.0);
240 +  if(ctrl.debug) cout << "d0 and dz? ... " << ret << endl;  
241 +          
242 +  //  if( mu->IsTrackerMuon() && mu->HasTrackerTrk() && !mu->IsGlobalMuon() )  
243 +  //    ret &=  ( mu->Quality().QualityMask().Mask() & mithep::MuonQuality::AllArbitrated);
244 +  //  if(ctrl.debug) cout << "if isTrackerMuon, arbitrated ? ... " << ret << endl;  
245 +  //  ret &= ( mu->BestTrk()->DzCorrected(vtx) < 0.1);  
246 +  //  if( ctrl.debug ) cout << "elepresel : ret after dZcorr : " << ret <<  endl;
247  
132  level++;  
133  if( (mu->trkIso03/mu->pt) > 0.7 ) {
134    failmask |= (1<<level);
135  }
248  
137  //  if(muon->nPixHits   < 1)     return false;
138  //  if(muon->muNchi2    > 10)    return false;
139  //  if(muon->nMatch     < 2)     return false;
140  //  if(muon->nValidHits         < 1)     return false;
141  //  if(muon->pterr/muon->pt > 0.1)   return false;
142  //  if(fabs(muon->dz)       > 0.1)   return false;  
143  
249    SelectionStatus status;
250 <  if( !failmask ) status.setStatus(SelectionStatus::LOOSEID);
251 <  if( !failmask ) status.setStatus(SelectionStatus::TIGHTID);
250 >  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
251 >  if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;  
252    return status;
253 + }
254 + //--------------------------------------------------------------------------------------------------
255 + SelectionStatus muonDenominatorSelection( ControlFlags &ctrl,  
256 +                                          const mithep::Muon * mu,
257 +                                          const mithep::Vertex * vtx,
258 +                                          const mithep::Array<mithep::PFCandidate> * pfCandidates )
259 + //--------------------------------------------------------------------------------------------------
260 + {
261 +  bool ret = true;
262 +
263 +  ret &= ( fabs(mu->Ip3dPVSignificance()) < 100 );
264 +  ret &= ( mu->Pt() >= 5 );
265 +  ret &= ( fabs(mu->Eta()) <= 2.4 );
266 +  ret &= ( mu->IsTrackerMuon() || mu->IsGlobalMuon() );
267 +  ret &= (mu->HasTrackerTrk() &&
268 +          fabs(mu->TrackerTrk()->D0Corrected(*vtx)) < 0.5 &&
269 +          fabs(mu->TrackerTrk()->DzCorrected(*vtx)) < 1.0);
270  
271 +  SelectionStatus status;
272 +  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
273 +  return status;
274 + }
275  
276 + //--------------------------------------------------------------------------------------------------
277 + SelectionStatus muonPreSelectionNoD0DzIP( ControlFlags &ctrl,  
278 +                                          const mithep::Muon * mu,
279 +                                          const mithep::Vertex * vtx,
280 +                                          const mithep::Array<mithep::PFCandidate> * pfCandidates )
281 + //--------------------------------------------------------------------------------------------------
282 + {
283 +  bool ret = true;
284  
285 < };
285 >  if(ctrl.debug) cout << "inside muonpresel ... " << endl;
286 >  ret &= ( mu->Pt() >= 5 );
287 >  if(ctrl.debug) cout << "and >5 GeV (" << mu->Pt() << ") ? ... " << ret << endl;  
288 >  ret &= ( fabs(mu->Eta()) <= 2.4 );
289 >  if(ctrl.debug) cout << "and < 2.4 eta (" << mu->Eta() << ")? ... " << ret << endl;  
290 >  ret &= ( mu->IsTrackerMuon() || mu->IsGlobalMuon() );
291 >  if(ctrl.debug) cout << "is Tracker or Global? ... " << ret << endl;
292 >          
293 >  //  if( mu->IsTrackerMuon() && mu->HasTrackerTrk() && !mu->IsGlobalMuon() )  
294 >  //    ret &=  ( mu->Quality().QualityMask().Mask() & mithep::MuonQuality::AllArbitrated);
295 >  //  if(ctrl.debug) cout << "if isTrackerMuon, arbitrated ? ... " << ret << endl;  
296 >  //  ret &= ( mu->BestTrk()->DzCorrected(vtx) < 0.1);  
297 >  //  if( ctrl.debug ) cout << "elepresel : ret after dZcorr : " << ret <<  endl;
298  
299  
300 +  SelectionStatus status;
301 +  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
302 +  if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;  
303 +  return status;
304 + }
305  
306  
156 //
157 // Kevin's WW selection
158 //
159 SelectionStatus passMuonSelection( ControlFlags &ctrl, const mithep::TMuon * mu ) {
160  int level=0;
161  unsigned failmask=0x0;
307  
163  // 0x1
164  if(mu->pt < 5) {
165    failmask |= (1<<level);
166  }
308  
309 <  // 0x2
310 <  level++;
311 <  if(fabs(mu->eta) > 2.4) {
312 <    failmask |= (1<<level);
313 <  }
309 > //--------------------------------------------------------------------------------------------------
310 > SelectionStatus muonIDMVASelection(ControlFlags &ctrl,
311 >                                 const mithep::Muon *mu,
312 >                                 const mithep::Vertex * vtx   )
313 > //--------------------------------------------------------------------------------------------------
314 > {
315 >  double global_rchi2 = (mu->IsGlobalMuon()) ? mu->GlobalTrk()->RChi2() : 0.;
316  
317 <  // 0x4
318 <  level++;
319 <  if(mu->ptErr/mu->pt > 0.1)   {
320 <    failmask |= (1<<level);
321 <  }
317 >  //
318 >  // WARNING !!! KH hacked out to sync
319 >  //
320 >  /*
321 >  double mvaval = muIDMVA->MVAValue_ID(mu->Pt(),
322 >                                    mu->Eta(),
323 >                                    mu->IsGlobalMuon(),
324 >                                    mu->IsTrackerMuon(),
325 >                                    mu->TrackerTrk()->RChi2(),
326 >                                    global_rchi2,
327 >                                    (Double_t)(mu->NValidHits()),
328 >                                    (Double_t)(mu->TrackerTrk()->NHits()),
329 >                                    (Double_t)(mu->TrackerTrk()->NPixelHits()),
330 >                                    (Double_t)(mu->NMatches()),
331 >                                    mu->TrkKink(),
332 >                                    muTools.GetSegmentCompatability(mu),
333 >                                    muTools.GetCaloCompatability(mu,true,true),
334 >                                    mu->HadEnergy(),
335 >                                    mu->EmEnergy(),
336 >                                    mu->HadS9Energy(),
337 >                                    mu->EmS9Energy(),
338 >                                    (Bool_t)(ctrl.debug) );
339 >  */
340 >  double mvaval = 0.0;
341  
342 <  // 0x8
343 <  level++;
344 <  if( fabs(mu->dz) > 0.1 )   {
345 <    failmask |= (1<<level);
342 >  SelectionStatus status;
343 >  bool pass = false;
344 >  
345 >  if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
346 >      && fabs(mu->Eta()) <= 1.5 && mu->Pt() <= 10 && mvaval >= MUON_IDMVA_CUT_BIN0)  pass = true;
347 >  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
348 >           && fabs(mu->Eta()) <= 1.5 && mu->Pt() > 10 && mvaval >= MUON_IDMVA_CUT_BIN1)  pass = true;
349 >  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
350 >           && fabs(mu->Eta()) > 1.5 && mu->Pt() <= 10 && mvaval >= MUON_IDMVA_CUT_BIN2)  pass = true;
351 >  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
352 >           && fabs(mu->Eta()) > 1.5 && mu->Pt() > 10 && mvaval >= MUON_IDMVA_CUT_BIN3)  pass = true;
353 >  else if( !(mu->IsGlobalMuon()) && mu->IsTrackerMuon() && mvaval >= MUON_IDMVA_CUT_BIN4 )  pass = true;
354 >  else if( mu->IsGlobalMuon() && !(mu->IsTrackerMuon()) && mvaval >= MUON_IDMVA_CUT_BIN5 )  pass = true;
355 >  
356 >
357 >
358 >  if( pass ) {
359 >    status.orStatus(SelectionStatus::LOOSEID);
360 >    status.orStatus(SelectionStatus::TIGHTID);
361    }
362  
363 +  return status;
364 + }
365  
366 <  Bool_t isGlobal  = (mu->typeBits & kGlobal) && (mu->muNchi2 < 10) && (mu->nMatch > 1) && (mu->nValidHits > 0);
367 <  Bool_t isTracker = (mu->typeBits & kTracker) && (mu->qualityBits & kTMLastStationTight);
368 <
369 <  // 0x10
370 <  level++;
371 <  if(!isGlobal && !isTracker) {
372 <    failmask |= (1<<level);
373 <  }
366 > //--------------------------------------------------------------------------------------------------
367 > void initMuonIDMVA()
368 > //--------------------------------------------------------------------------------------------------
369 > {
370 >  muIDMVA = new mithep::MuonIDMVA();
371 >  vector<string> weightFiles;
372 >  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_barrel_lowpt_V2.weights.xml");
373 >  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_barrel_highpt_V2.weights.xml");
374 >  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_endcap_lowpt_V2.weights.xml");
375 >  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_endcap_highpt_V2.weights.xml");
376 >  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_tracker_V2.weights.xml");
377 >  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_global_V2.weights.xml");
378 >  muIDMVA->Initialize( "MuonIDMVA",
379 >                       mithep::MuonIDMVA::kIDV0,
380 >                       kTRUE, weightFiles);
381 > }
382  
383 <  // 0x20
384 <  level++;
385 <  if( mu->nTkHits < 10 ) {
386 <    failmask |= (1<<level);
383 > //--------------------------------------------------------------------------------------------------
384 > SelectionStatus muonIDPFSelection(ControlFlags &ctrl,
385 >                                  const mithep::Muon *mu,
386 >                                  const mithep::Vertex * vtx,
387 >                                  const mithep::Array<mithep::PFCandidate> * pfCandidates )
388 > //--------------------------------------------------------------------------------------------------
389 > {
390 >  bool pass = false;
391 >  SelectionStatus status; // init'ed to FAIL
392 >
393 >  // check that it matches to a PF muon
394 >  for( int i=0; i<pfCandidates->GetEntries(); i++ ) {
395 >    // tmp
396 >    if( !(PFnoPUflag[i]) ) continue; // my PF no PU hack
397 >
398 >    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfCandidates)[i]);
399 >    if( (pf->TrackerTrk() == mu->TrackerTrk()) && abs(pf->PFType()) == mithep::PFCandidate::eMuon ) {
400 >      pass = true;
401 >      break;
402 >    }
403    }
404 + //      
405 + //      if(mu->IsPFMuon()) pass = true;
406 + //      else pass = false;
407  
408 <  level++;
409 <  if(mu->nPixHits         < 1) {
410 <    failmask |= (1<<level);
408 >  //
409 >  // NB : ipsig here for reference synch ...
410 >  //
411 > #ifdef SYNC
412 >  if( pass && fabs(mu->Ip3dPVSignificance()) < 4 ) {
413 >    status.orStatus(SelectionStatus::LOOSEID);
414 >    status.orStatus(SelectionStatus::TIGHTID);
415 >  }
416 > #else
417 >  if( pass ) {
418 >    status.orStatus(SelectionStatus::LOOSEID);
419 >    status.orStatus(SelectionStatus::TIGHTID);
420    }
421 + #endif
422  
423 +  return status;
424 + }
425 + //----------------------------------------------------------------------------------------
426 + SelectionStatus PassWwMuonSel(const mithep::Muon *mu, const mithep::Vertex *vtx,
427 +                              const mithep::Array<mithep::PFCandidate> *pfArr
428 + )
429 + {
430 +  bool passID=true;
431 +  bool passIso=true;
432 +  
433 +  if (mu->Pt() < 5)
434 +    passID = false;
435 +  if (fabs(mu->Eta()) > 2.4)
436 +    passID = false;
437 +  if (mu->BestTrk()->PtErr()/mu->Pt() > 0.1)
438 +    passID = false;
439 +  if (fabs(mu->BestTrk()->DzCorrected(*vtx)) > 0.1)
440 +    passID = false;
441 +  Bool_t isGlobal  = (mu->IsGlobalMuon()) && (mu->BestTrk()->RChi2() < 10) &&
442 +                      (mu->NMatches() > 1) && (mu->NValidHits() > 0);
443 +  Bool_t isTracker = (mu->IsTrackerMuon()) &&
444 +                      (mu->Quality().Quality(mithep::MuonQuality::TMLastStationTight));
445 +  if (!isGlobal && !isTracker)
446 +    passID = false;
447 +  int ntrkhits = (mu->HasTrackerTrk()) ? mu->TrackerTrk()->NHits() : 0;
448 +  if (ntrkhits < 10)
449 +    passID = false;
450 +  if (mu->BestTrk()->NPixelHits() < 1)
451 +    passID = false;
452 +  if (fabs(mu->BestTrk()->D0Corrected(*vtx)) > 0.02)
453 +    passID = false;
454 +  
455 +  // note: this isn't really ww muon isolation
456 +  float pfiso = computePFMuonIso(mu,vtx,pfArr,0.3);
457  
458 <  level++;
459 <  if(fabs(mu->d0)>0.02)   {
210 <    failmask |= (1<<level);
211 <  }
212 <
213 <  /*
214 <  if(mu->pt>20) {
215 <    if(fabs(mu->d0)>0.02)   {
216 <      failmask |= (1<<level);
217 <    }
218 <  } else {
219 <    if(fabs(mu->d0)>0.01)  {
220 <    failmask |= (1<<level);
221 <    }
222 <  }
223 <  */
458 >  if (pfiso > 0.2*mu->Pt())
459 >    passIso = false;
460  
461    SelectionStatus status;
462 <  if( !failmask ) status.setStatus(SelectionStatus::LOOSEID);
463 <  if( !failmask ) status.setStatus(SelectionStatus::TIGHTID);
462 >  if(passID)  status |= SelectionStatus::TIGHTIDANDPRE;
463 >  if(passIso) status |= SelectionStatus::TIGHTISOANDPRE;
464 >  
465    return status;
466  
467 <
231 < };
232 <
467 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines