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.11 by khahn, Thu May 3 22:06:47 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 Float_t computePFMuonIso(const mithep::Muon *mu,
17 +                        const mithep::Vertex & vtx,
18 +                        const mithep::Array<mithep::PFCandidate> * pfCandidates,
19 +                        const Double_t dRMax);
20 +
21 + //--------------------------------------------------------------------------------------------------
22 + SelectionStatus muonDummyVeto(ControlFlags &ctrl,
23 +                              const mithep::Muon *muon,
24 +                              const mithep::Vertex &vtx)
25 + //--------------------------------------------------------------------------------------------------
26 + {
27 +  SelectionStatus status;
28 +  status.setStatus(SelectionStatus::PRESELECTION);
29 +  return status;  
30 + }
31 +
32 + //--------------------------------------------------------------------------------------------------
33 + SelectionStatus muonCutBasedVeto(ControlFlags &ctrl,
34 +                                 const mithep::Muon *muon,
35 +                                 const mithep::Vertex &vtx)
36 + //--------------------------------------------------------------------------------------------------
37 + {
38 +  //
39 +  // Loose cut-based ID for isolation veto
40 +  //
41 +  bool ret = true;
42 +  
43 +  if(!(muon->IsGlobalMuon() || muon->IsTrackerMuon())) ret = false;
44 +  if( muon->NValidHits() < 11 )                        ret = false;
45 +  if( fabs(muon->Ip3dPVSignificance()) >= 4 )          ret = false;
46 +
47 +  SelectionStatus status;
48 +  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
49 +  return status;
50 + }
51  
52 < SelectionStatus muonPreSelection( ControlFlags &ctrl,  const mithep::TMuon * mu ) {
52 >
53 > //--------------------------------------------------------------------------------------------------
54 > SelectionStatus noPreSelection( ControlFlags &ctrl,  const mithep::Muon * mu )
55 >
56 > //--------------------------------------------------------------------------------------------------
57 > {
58 >        SelectionStatus status;
59 >        status.setStatus(SelectionStatus::PRESELECTION);
60 >        if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;
61 >        return status;
62 > }
63 >
64 > //--------------------------------------------------------------------------------------------------
65 > SelectionStatus muonPreSelection( ControlFlags &ctrl,  
66 >                                  const mithep::Muon * mu,
67 >                                  const mithep::Vertex & vtx,
68 >                                  const mithep::Array<mithep::PFCandidate> * pfCandidates )
69 > //--------------------------------------------------------------------------------------------------
70 > {
71 >  bool ret = true;
72    if(ctrl.debug) cout << "inside muonpresel ... " << endl;
73 <  bool ret = isMuFO(mu);
73 >  //  bool ret = isMuFO(mu,vtx,pfCandidates);
74    if(ctrl.debug) cout << "iS fo? ... " << ret << endl;  
75 <  ret &= ( fabs(mu->ip3dSig) < 4 ? true : false );
76 <  if(ctrl.debug) cout << "and pass IP (" << mu->ip3dSig << ") ? ... " << ret << endl;  
77 <  ret &= ( mu->pt > 5 ? true : false );
78 <  if(ctrl.debug) cout << "and >5 GeV ? ... " << ret << endl;  
79 <  ret &= ( fabs(mu->eta) < 2.4 ? true : false );
80 <  if(ctrl.debug) cout << "and < 2.4 eta ? ... " << ret << endl;  
75 >  ret &= ( fabs(mu->Ip3dPVSignificance()) < 4 );
76 >  if(ctrl.debug) cout << "and pass IP (" << mu->Ip3dPVSignificance() << ") ? ... " << ret << endl;  
77 >  ret &= ( mu->Pt() > 5 );
78 >  if(ctrl.debug) cout << "and >5 GeV (" << mu->Pt() << ") ? ... " << ret << endl;  
79 >  ret &= ( fabs(mu->Eta()) <= 2.4 );
80 >  if(ctrl.debug) cout << "and < 2.4 eta (" << mu->Eta() << ")? ... " << ret << endl;  
81 >  ret &= ( mu->IsTrackerMuon() || mu->IsGlobalMuon() );
82 >  if(ctrl.debug) cout << "is Tracker or Global? ... " << ret << endl;  
83 >  if( mu->IsTrackerMuon() && mu->HasTrackerTrk() && !mu->IsGlobalMuon() )  
84 >    ret &=  ( mu->Quality().QualityMask().Mask() & mithep::MuonQuality::AllArbitrated);
85 >  if(ctrl.debug) cout << "if isTrackerMuon, arbitrated ? ... " << ret << endl;  
86 >  ret &= ( mu->BestTrk()->DzCorrected(vtx) < 0.1);  
87 >  if( ctrl.debug ) cout << "elepresel : ret after dZcorr : " << ret <<  endl;
88 >
89  
90    SelectionStatus status;
91    if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
# Line 25 | Line 93 | SelectionStatus muonPreSelection( Contro
93    return status;
94   }
95  
96 < bool isMuFO( const mithep::TMuon * mu ) {
96 >
97 > //--------------------------------------------------------------------------------------------------
98 > bool isMuFO( const mithep::Muon * mu,
99 >             const mithep::Vertex & vtx,
100 >             const mithep::Array<mithep::PFCandidate> * pfCandidates )
101 > //--------------------------------------------------------------------------------------------------
102 > {
103    bool isgood=true;
104 <  float reliso = mu->pfIso03/mu->pt;
104 >  float reliso = computePFMuonIso(mu,vtx,pfCandidates,0.3)/mu->Pt();
105  
106 <  if( mu->pt < 5  )         isgood=false;                          
107 <  if ( fabs(mu->dz) > 0.2 ) isgood=false;   // needed to remove cosmics in HF sample
106 >  if( mu->Pt() < 5  )         isgood=false;                          
107 >  if ( fabs(mu->BestTrk()->DzCorrected(vtx)) > 0.2 ) isgood=false;   // needed to remove cosmics in HF sample
108  
109    //
110  
111    // HF seems to not want tkquality, SS does
112 <  if( mu->pt>20 ) {
113 <    if ( !((mu->typeBits & kGlobal) && mu->nSeg>0  ) ) isgood=false; //&& mu->nValidHits>0
112 >  if( mu->Pt()>20 ) {
113 >    if ( !((mu->IsGlobalMuon()) && mu->NSegments()>0  ) ) isgood=false; //&& mu->nValidHits>0
114    } else {
115 <    if ( !((mu->typeBits & kGlobal) && mu->nSeg>0 ) //&& //&& mu->nValidHits>0
116 <         && !( (mu->typeBits & kTracker) &&  (mu->qualityBits & kTMOneStationLoose)
115 >    if ( !((mu->IsGlobalMuon()) && mu->NSegments()>0 ) //&& //&& mu->nValidHits>0
116 >         && !( (mu->IsTrackerMuon()) &&  (mu->Quality().QualityMask().Mask() & muTools.kTMOneStationLoose)
117                 )
118           )   isgood=false;
119    }
# Line 58 | Line 132 | bool isMuFO( const mithep::TMuon * mu )
132  
133  
134    // comment for more stats for mu fake shape
135 <  if( mu->pt < 20 ) {
135 >  if( mu->Pt() < 20 ) {
136      if( reliso > 3 ) isgood=false;    
137    } else {
138      if( reliso > 5 ) isgood=false;    
# Line 67 | Line 141 | bool isMuFO( const mithep::TMuon * mu )
141    return isgood;
142   };
143  
144 <
145 < SelectionStatus passSoftMuonSelection( ControlFlags &ctrl, const mithep::TMuon * mu ) {
144 > //--------------------------------------------------------------------------------------------------
145 > SelectionStatus passSoftMuonSelection( ControlFlags &ctrl,
146 >                                       const mithep::Muon * mu ,
147 >                                       const mithep::Vertex & vtx)
148 > //--------------------------------------------------------------------------------------------------
149 > {
150  
151    int level=0;
152    unsigned failmask=0x0;
153    
154 <  if(mu->nTkHits < 11 )  
154 >  // Use tracker track when available
155 >  const mithep::Track *muTrk=0;
156 >  if(mu->HasStandaloneTrk()) { muTrk = mu->StandaloneTrk(); }
157 >  else if(mu->HasTrackerTrk())         { muTrk = mu->TrackerTrk(); }
158 >  else if(mu->HasGlobalTrk())     { muTrk = mu->GlobalTrk(); }
159 >  assert(muTrk);                  
160 >
161 >  if(mu->TrackerTrk()->NHits() < 11 )  
162      failmask |= (1<<level);
163    level++;
164  
165 <  if(fabs(mu->d0) > 0.2)
165 >  if(fabs(muTrk->D0Corrected(vtx)) > 0.2)
166      failmask |= (1<<level);
167    level++;
168  
169 <  if(fabs(mu->dz) > 0.1)
169 >  if(fabs(muTrk->DzCorrected(vtx)) > 0.1)
170      failmask |= (1<<level);
171    level++;
172  
173 <  if(!(mu->typeBits & kTracker))
173 >  if(!(mu->IsTrackerMuon()))
174      failmask |= (1<<level);
175    level++;
176  
177 <  if(!(mu->qualityBits & kTMLastStationAngTight))
177 >  //  if(!(mu->Quality().QualityMask().Mask() & muTools.kTMLastStationAngTight))
178 >  if(!(mu->Quality().QualityMask().Mask() & muTools.kTMLastStationTight))
179      failmask |= (1<<level);      
180    level++;
181  
182 <  Double_t iso = (mu->trkIso03 + mu->emIso03 + mu->hadIso03)/mu->pt;
183 <  if(mu->pt>20 && iso<0.1)
182 >  Double_t iso = (mu->IsoR03SumPt() + mu->IsoR03EmEt() + mu->IsoR03HadEt())/mu->Pt();
183 >  if(mu->Pt()>20 && iso<0.1)
184      failmask |= (1<<level);
185  
186    bool passtight  = !(failmask);
# Line 103 | Line 189 | SelectionStatus passSoftMuonSelection( C
189    
190   }
191  
192 <
192 > //--------------------------------------------------------------------------------------------------
193   //unsigned passMuonSelectionZZ( const mithep::TMuon * mu ) {
194 < SelectionStatus passMuonSelectionZZ( ControlFlags &ctrl, const mithep::TMuon * mu ) {
194 > SelectionStatus passMuonSelectionZZ( ControlFlags &ctrl, const mithep::Muon * mu )
195 > //--------------------------------------------------------------------------------------------------
196 > {
197    int level=0;
198    unsigned failmask=0x0;
199  
200 <  if(mu->pt < 5) {
200 >  if(mu->Pt() < 5) {
201      failmask |= (1<<level);
202    }
203  
204    level++;
205 <  if(fabs(mu->eta) > 2.4) {
205 >  if(fabs(mu->Eta()) > 2.4) {
206      failmask |= (1<<level);
207    }
208  
209    level++;
210 <  if(!(mu->typeBits & kGlobal)) {
210 >  if(!(mu->IsGlobalMuon())) {
211      failmask |= (1<<level);
212    }
213  
214    level++;
215 <  if(mu->nTkHits          < 10) {
215 >  if(mu->TrackerTrk()->NHits()  < 10) {
216      failmask |= (1<<level);
217    }
218  
219  
220    level++;  
221 <  if( (mu->trkIso03/mu->pt) > 0.7 ) {
221 >  if( (mu->IsoR03SumPt()/mu->Pt()) > 0.7 ) {
222      failmask |= (1<<level);
223    }
224  
# Line 142 | Line 230 | SelectionStatus passMuonSelectionZZ( Con
230    //  if(fabs(muon->dz)       > 0.1)   return false;  
231    
232    SelectionStatus status;
233 <  if( !failmask ) status.setStatus(SelectionStatus::LOOSEID);
234 <  if( !failmask ) status.setStatus(SelectionStatus::TIGHTID);
233 >  if( !failmask ) status.orStatus(SelectionStatus::LOOSEID);
234 >  if( !failmask ) status.orStatus(SelectionStatus::TIGHTID);
235    return status;
236  
237  
# Line 156 | Line 244 | SelectionStatus passMuonSelectionZZ( Con
244   //
245   // Kevin's WW selection
246   //
247 < SelectionStatus passMuonSelection( ControlFlags &ctrl, const mithep::TMuon * mu ) {
247 > //--------------------------------------------------------------------------------------------------
248 > SelectionStatus passMuonSelection( ControlFlags &ctrl,
249 >                                   const mithep::Muon * mu,
250 >                                   const mithep::Vertex & vtx   )
251 > //--------------------------------------------------------------------------------------------------
252 > {
253 >  SelectionStatus status;
254    int level=0;
255    unsigned failmask=0x0;
256  
257 +  // Use tracker track when available
258 +  const mithep::Track *muTrk=0;
259 +  if(mu->HasTrackerTrk())         { muTrk = mu->TrackerTrk(); }
260 +  else if(mu->HasGlobalTrk())     { muTrk = mu->GlobalTrk(); }
261 +  else if(mu->HasStandaloneTrk()) { muTrk = mu->StandaloneTrk(); }
262 +  assert(muTrk);                  
263 +  
264 +
265 +
266    // 0x1
267 <  if(mu->pt < 5) {
267 >  if(muTrk->Pt() < 5) {
268      failmask |= (1<<level);
269    }
270  
271    // 0x2
272    level++;
273 <  if(fabs(mu->eta) > 2.4) {
273 >  if(fabs(muTrk->Eta()) > 2.4) {
274      failmask |= (1<<level);
275    }
276  
277    // 0x4
278    level++;
279 <  if(mu->ptErr/mu->pt > 0.1)   {
279 >  if(muTrk->PtErr()/muTrk->Pt() > 0.1)   {
280      failmask |= (1<<level);
281    }
282  
283    // 0x8
284    level++;
285 <  if( fabs(mu->dz) > 0.1 )   {
285 >  if( fabs(muTrk->DzCorrected(vtx)) > 0.1 )   {
286      failmask |= (1<<level);
287    }
288  
289 +  double muNchi2;
290 +  if(mu->HasStandaloneTrk())      { muNchi2 = mu->StandaloneTrk()->RChi2(); }
291 +  else if(mu->HasGlobalTrk())     { muNchi2 = mu->GlobalTrk()->RChi2();     }
292 +  else if(mu->HasTrackerTrk())    { muNchi2 = mu->TrackerTrk()->RChi2();    }
293  
294 <  Bool_t isGlobal  = (mu->typeBits & kGlobal) && (mu->muNchi2 < 10) && (mu->nMatch > 1) && (mu->nValidHits > 0);
295 <  Bool_t isTracker = (mu->typeBits & kTracker) && (mu->qualityBits & kTMLastStationTight);
294 >  unsigned qualityBits = mu->Quality().QualityMask().Mask();
295 >  
296 >  Bool_t isGlobal  = (mu->IsGlobalMuon()) && (muNchi2 < 10) && (mu->NMatches() > 1) && (mu->NValidHits() > 0);
297 >  Bool_t isTracker = (mu->IsTrackerMuon() ) && (qualityBits & muTools.kTMLastStationTight);
298  
299    // 0x10
300    level++;
301 <  if(!isGlobal && !isTracker) {
301 >  if((!isGlobal && !isTracker) || !(mu->HasTrackerTrk())) {
302      failmask |= (1<<level);
303 +    status.setStatus(SelectionStatus::FAIL);
304 +    return status;    
305    }
306  
307    // 0x20
308    level++;
309 <  if( mu->nTkHits < 10 ) {
309 >  assert(mu->HasTrackerTrk());
310 >  assert(mu->TrackerTrk());
311 >  if( mu->TrackerTrk()->NHits() < 10 ) {
312      failmask |= (1<<level);
313    }
314  
315    level++;
316 <  if(mu->nPixHits         < 1) {
316 >  if(muTrk->NPixelHits()          < 1) {
317      failmask |= (1<<level);
318    }
319  
320  
321    level++;
322 <  if(fabs(mu->d0)>0.02)   {
322 >  if(fabs(muTrk->D0Corrected(vtx))>0.02)   {
323      failmask |= (1<<level);
324    }
325  
# Line 222 | Line 335 | SelectionStatus passMuonSelection( Contr
335    }
336    */
337  
338 <  SelectionStatus status;
339 <  if( !failmask ) status.setStatus(SelectionStatus::LOOSEID);
227 <  if( !failmask ) status.setStatus(SelectionStatus::TIGHTID);
338 >  if( !failmask ) status.orStatus(SelectionStatus::LOOSEID);
339 >  if( !failmask ) status.orStatus(SelectionStatus::TIGHTID);
340    return status;
341  
342  
343   };
344  
345 +
346 + //--------------------------------------------------------------------------------------------------
347 + SelectionStatus muonIDMVASelection(ControlFlags &ctrl,
348 +                                 const mithep::Muon *mu,
349 +                                 const mithep::Vertex & vtx   )
350 + //--------------------------------------------------------------------------------------------------
351 + {
352 +  double global_rchi2 = (mu->IsGlobalMuon()) ? mu->GlobalTrk()->RChi2() : 0.;
353 +
354 +  double mvaval = muIDMVA->MVAValue_ID(mu->Pt(),
355 +                                    mu->Eta(),
356 +                                    mu->IsGlobalMuon(),
357 +                                    mu->IsTrackerMuon(),
358 +                                    mu->TrackerTrk()->RChi2(),
359 +                                    global_rchi2,
360 +                                    (Double_t)(mu->NValidHits()),
361 +                                    (Double_t)(mu->TrackerTrk()->NHits()),
362 +                                    (Double_t)(mu->TrackerTrk()->NPixelHits()),
363 +                                    (Double_t)(mu->NMatches()),
364 +                                    mu->TrkKink(),
365 +                                    muTools.GetSegmentCompatability(mu),
366 +                                    muTools.GetCaloCompatability(mu,true,true),
367 +                                    mu->HadEnergy(),
368 +                                    mu->EmEnergy(),
369 +                                    mu->HadS9Energy(),
370 +                                    mu->EmS9Energy(),
371 +                                    (Bool_t)(ctrl.debug) );
372 +
373 +
374 +  SelectionStatus status;
375 +  bool pass = false;
376 +  
377 +  if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
378 +      && fabs(mu->Eta()) <= 1.5 && mu->Pt() <= 10 && mvaval >= MUON_IDMVA_CUT_BIN0)  pass = true;
379 +  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
380 +           && fabs(mu->Eta()) <= 1.5 && mu->Pt() > 10 && mvaval >= MUON_IDMVA_CUT_BIN1)  pass = true;
381 +  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
382 +           && fabs(mu->Eta()) > 1.5 && mu->Pt() <= 10 && mvaval >= MUON_IDMVA_CUT_BIN2)  pass = true;
383 +  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
384 +           && fabs(mu->Eta()) > 1.5 && mu->Pt() > 10 && mvaval >= MUON_IDMVA_CUT_BIN3)  pass = true;
385 +  else if( !(mu->IsGlobalMuon()) && mu->IsTrackerMuon() && mvaval >= MUON_IDMVA_CUT_BIN4 )  pass = true;
386 +  else if( mu->IsGlobalMuon() && !(mu->IsTrackerMuon()) && mvaval >= MUON_IDMVA_CUT_BIN5 )  pass = true;
387 +  
388 +
389 +
390 +  if( pass ) {
391 +    status.orStatus(SelectionStatus::LOOSEID);
392 +    status.orStatus(SelectionStatus::TIGHTID);
393 +  }
394 +
395 +  return status;
396 + }
397 +
398 + //--------------------------------------------------------------------------------------------------
399 + void initMuonIDMVA()
400 + //--------------------------------------------------------------------------------------------------
401 + {
402 +  muIDMVA = new mithep::MuonIDMVA();
403 +  vector<string> weightFiles;
404 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_barrel_lowpt_V2.weights.xml");
405 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_barrel_highpt_V2.weights.xml");
406 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_endcap_lowpt_V2.weights.xml");
407 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_endcap_highpt_V2.weights.xml");
408 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_tracker_V2.weights.xml");
409 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_global_V2.weights.xml");
410 +  muIDMVA->Initialize( "MuonIDMVA",
411 +                       mithep::MuonIDMVA::kIDV0,
412 +                       kTRUE, weightFiles);
413 + }
414 +
415 + //--------------------------------------------------------------------------------------------------
416 + SelectionStatus muonIDPFSelection(ControlFlags &ctrl,
417 +                                  const mithep::Muon *mu,
418 +                                  const mithep::Vertex & vtx,
419 +                                  const mithep::Array<mithep::PFCandidate> * pfCandidates )
420 + //--------------------------------------------------------------------------------------------------
421 + {
422 +  bool pass = false;
423 +  SelectionStatus status; // init'ed to FAIL
424 +
425 +  // check that it matches to a PF muon
426 +  for( int i=0; i<pfCandidates->GetEntries(); i++ ) {
427 +    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfCandidates)[i]);
428 +    if( pf->HasTrackerTrk() ) {
429 +      if( (pf->TrackerTrk() == mu->TrackerTrk()) && abs(pf->PFType()) == mithep::PFCandidate::eMuon ) {
430 +        pass = true;
431 +        break;
432 +      }
433 +    }
434 +  }
435 +
436 +  if( pass ) {
437 +    status.orStatus(SelectionStatus::LOOSEID);
438 +    status.orStatus(SelectionStatus::TIGHTID);
439 +  }
440 +
441 +  return status;
442 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines