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.2 by khahn, Tue Feb 14 01:29:01 2012 UTC vs.
Revision 1.22 by anlevin, Mon May 28 12:37:10 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 + //--------------------------------------------------------------------------------------------------
23 + SelectionStatus muonDummyVeto(ControlFlags &ctrl,
24 +                              const mithep::Muon *muon,
25 +                              const mithep::Vertex * vtx)
26 + //--------------------------------------------------------------------------------------------------
27 + {
28 +  SelectionStatus status;
29 +  status.setStatus(SelectionStatus::PRESELECTION);
30 +  return status;  
31 + }
32  
33 < SelectionStatus muonPreSelection( ControlFlags &ctrl,  const mithep::TMuon * mu ) {
34 <  if(ctrl.debug) cout << "inside muonpresel ... " << endl;
35 <  bool ret = isMuFO(mu);
36 <  if(ctrl.debug) cout << "iS fo? ... " << ret << endl;  
37 <  ret &= ( fabs(mu->ip3dSig) < 4 );
38 <  if(ctrl.debug) cout << "and pass IP (" << mu->ip3dSig << ") ? ... " << ret << endl;  
39 <  ret &= ( mu->pt > 5 );
40 <  if(ctrl.debug) cout << "and >5 GeV ? ... " << ret << endl;  
41 <  ret &= ( fabs(mu->eta) < 2.4 );
42 <  if(ctrl.debug) cout << "and < 2.4 eta ? ... " << ret << endl;  
33 > //--------------------------------------------------------------------------------------------------
34 > SelectionStatus muonCutBasedVeto(ControlFlags &ctrl,
35 >                                 const mithep::Muon *muon,
36 >                                 const mithep::Vertex *vtx)
37 > //--------------------------------------------------------------------------------------------------
38 > {
39 >  //
40 >  // Loose cut-based ID for isolation veto
41 >  //
42 >  bool ret = true;
43 >  
44 >  if(!(muon->IsGlobalMuon() || muon->IsTrackerMuon())) ret = false;
45 >  if( muon->NValidHits() < 11 )                        ret = false;
46 >  if( fabs(muon->Ip3dPVSignificance()) >= 4 )          ret = false;
47  
48    SelectionStatus status;
49    if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
24  if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;  
50    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  //
36
37  // HF seems to not want tkquality, SS does
38  if( mu->pt>20 ) {
39    if ( !((mu->typeBits & kGlobal) && mu->nSeg>0  ) ) isgood=false; //&& mu->nValidHits>0
40  } else {
41    if ( !((mu->typeBits & kGlobal) && mu->nSeg>0 ) //&& //&& mu->nValidHits>0
42         && !( (mu->typeBits & kTracker) &&  (mu->qualityBits & kTMOneStationLoose)
43               )
44         )   isgood=false;
45  }
46
47
48  //
49  // 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
51
52  /*
53 && ( (mu->qualityBits & kTMOneStationLoose) ||
54                                               (mu->qualityBits & kTMLastStationOptimizedBarrelLowPtLoose) ||
55                                               (mu->qualityBits & kTMLastStationOptimizedLowPtLoose)
56                                               )
57  */
58
59
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  }
66
67  return isgood;
68 };
69
70
71 SelectionStatus passSoftMuonSelection( ControlFlags &ctrl, const mithep::TMuon * mu ) {
72
73  int level=0;
74  unsigned failmask=0x0;
75  
76  if(mu->nTkHits < 11 )  
77    failmask |= (1<<level);
78  level++;
79
80  if(fabs(mu->d0) > 0.2)
81    failmask |= (1<<level);
82  level++;
83
84  if(fabs(mu->dz) > 0.1)
85    failmask |= (1<<level);
86  level++;
87
88  if(!(mu->typeBits & kTracker))
89    failmask |= (1<<level);
90  level++;
91
92  if(!(mu->qualityBits & kTMLastStationAngTight))
93    failmask |= (1<<level);      
94  level++;
95
96  Double_t iso = (mu->trkIso03 + mu->emIso03 + mu->hadIso03)/mu->pt;
97  if(mu->pt>20 && iso<0.1)
98    failmask |= (1<<level);
99
100  bool passtight  = !(failmask);
101  bool passloose  = !(failmask);
102  return SelectionStatus( passtight | passloose );
103  
51   }
52  
106
107 //unsigned passMuonSelectionZZ( const mithep::TMuon * mu ) {
108 SelectionStatus passMuonSelectionZZ( ControlFlags &ctrl, const mithep::TMuon * mu ) {
109  int level=0;
110  unsigned failmask=0x0;
53  
54 <  if(mu->pt < 5) {
55 <    failmask |= (1<<level);
114 <  }
115 <
116 <  level++;
117 <  if(fabs(mu->eta) > 2.4) {
118 <    failmask |= (1<<level);
119 <  }
120 <
121 <  level++;
122 <  if(!(mu->typeBits & kGlobal)) {
123 <    failmask |= (1<<level);
124 <  }
54 > //--------------------------------------------------------------------------------------------------
55 > SelectionStatus noPreSelection( ControlFlags &ctrl,  const mithep::Muon * mu )
56  
57 <  level++;
58 <  if(mu->nTkHits          < 10) {
59 <    failmask |= (1<<level);
60 <  }
57 > //--------------------------------------------------------------------------------------------------
58 > {
59 >        SelectionStatus status;
60 >        status.setStatus(SelectionStatus::PRESELECTION);
61 >        if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;
62 >        return status;
63 > }
64  
65 + //--------------------------------------------------------------------------------------------------
66 + SelectionStatus muonPreSelection( ControlFlags &ctrl,  
67 +                                  const mithep::Muon * mu,
68 +                                  const mithep::Vertex * vtx,
69 +                                  const mithep::Array<mithep::PFCandidate> * pfCandidates )
70 + //--------------------------------------------------------------------------------------------------
71 + {
72 +  bool ret = true;
73 +
74 +  ret &= ( fabs(mu->Ip3dPVSignificance()) < 100 );
75 +  ret &= ( mu->Pt() >= 5 );
76 +  ret &= ( fabs(mu->Eta()) <= 2.4 );
77 +  ret &= ( mu->IsTrackerMuon() || mu->IsGlobalMuon() );
78 + //   if( mu->IsTrackerMuon() && mu->HasTrackerTrk() && !mu->IsGlobalMuon() )  
79 + //     ret &=  ( mu->Quality().QualityMask().Mask() & mithep::MuonQuality::AllArbitrated);
80 +  ret &= (  mu->IsoR03SumPt()/mu->Pt() < 0.7 );
81  
132  level++;  
133  if( (mu->trkIso03/mu->pt) > 0.7 ) {
134    failmask |= (1<<level);
135  }
136
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  
82    SelectionStatus status;
83 <  if( !failmask ) status.setStatus(SelectionStatus::LOOSEID);
84 <  if( !failmask ) status.setStatus(SelectionStatus::TIGHTID);
83 >  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
84 >  if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;  
85    return status;
86 + }
87  
88  
89  
90 < };
91 <
92 <
93 <
90 > //--------------------------------------------------------------------------------------------------
91 > SelectionStatus muonReferencePreSelection( ControlFlags &ctrl,  
92 >                                           const mithep::Muon * mu,
93 >                                           const mithep::Vertex * vtx,
94 >                                           const mithep::Array<mithep::PFCandidate> * pfCandidates )
95 > //--------------------------------------------------------------------------------------------------
96 > {
97 >  bool ret = true;
98  
99 < //
100 < // Kevin's WW selection
101 < //
102 < SelectionStatus passMuonSelection( ControlFlags &ctrl, const mithep::TMuon * mu ) {
103 <  int level=0;
104 <  unsigned failmask=0x0;
99 >  if(ctrl.debug) cout << "inside muonpresel ... " << endl;
100 >  ret &= ( fabs(mu->Ip3dPVSignificance()) < 100 );
101 >  if(ctrl.debug) cout << "and pass IP (" << mu->Ip3dPVSignificance() << ") ? ... " << ret << endl;  
102 >  ret &= ( mu->Pt() >= 5 );
103 >  if(ctrl.debug) cout << "and >5 GeV (" << mu->Pt() << ") ? ... " << ret << endl;  
104 >  ret &= ( fabs(mu->Eta()) <= 2.4 );
105 >  if(ctrl.debug) cout << "and < 2.4 eta (" << mu->Eta() << ")? ... " << ret << endl;  
106 >  ret &= ( mu->IsTrackerMuon() || mu->IsGlobalMuon() );
107 >  if(ctrl.debug) cout << "is Tracker or Global? ... " << ret << endl;
108 >        ret &= (mu->HasTrackerTrk() && mu->TrackerTrk()->D0Corrected(*vtx) < 0.5 && mu->TrackerTrk()->DzCorrected(*vtx) < 1.0);
109 >  if(ctrl.debug) cout << "d0 and dz? ... " << ret << endl;  
110 >          
111 >  //  if( mu->IsTrackerMuon() && mu->HasTrackerTrk() && !mu->IsGlobalMuon() )  
112 >  //    ret &=  ( mu->Quality().QualityMask().Mask() & mithep::MuonQuality::AllArbitrated);
113 >  //  if(ctrl.debug) cout << "if isTrackerMuon, arbitrated ? ... " << ret << endl;  
114 >  //  ret &= ( mu->BestTrk()->DzCorrected(vtx) < 0.1);  
115 >  //  if( ctrl.debug ) cout << "elepresel : ret after dZcorr : " << ret <<  endl;
116  
163  // 0x1
164  if(mu->pt < 5) {
165    failmask |= (1<<level);
166  }
117  
118 <  // 0x2
119 <  level++;
120 <  if(fabs(mu->eta) > 2.4) {
121 <    failmask |= (1<<level);
122 <  }
118 >  SelectionStatus status;
119 >  if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
120 >  if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;  
121 >  return status;
122 > }
123  
174  // 0x4
175  level++;
176  if(mu->ptErr/mu->pt > 0.1)   {
177    failmask |= (1<<level);
178  }
124  
180  // 0x8
181  level++;
182  if( fabs(mu->dz) > 0.1 )   {
183    failmask |= (1<<level);
184  }
125  
126  
127 <  Bool_t isGlobal  = (mu->typeBits & kGlobal) && (mu->muNchi2 < 10) && (mu->nMatch > 1) && (mu->nValidHits > 0);
128 <  Bool_t isTracker = (mu->typeBits & kTracker) && (mu->qualityBits & kTMLastStationTight);
127 > //--------------------------------------------------------------------------------------------------
128 > SelectionStatus muonIDMVASelection(ControlFlags &ctrl,
129 >                                 const mithep::Muon *mu,
130 >                                 const mithep::Vertex * vtx   )
131 > //--------------------------------------------------------------------------------------------------
132 > {
133 >  double global_rchi2 = (mu->IsGlobalMuon()) ? mu->GlobalTrk()->RChi2() : 0.;
134  
135 <  // 0x10
136 <  level++;
137 <  if(!isGlobal && !isTracker) {
138 <    failmask |= (1<<level);
139 <  }
135 >  //
136 >  // WARNING !!! KH hacked out to sync
137 >  //
138 >  /*
139 >  double mvaval = muIDMVA->MVAValue_ID(mu->Pt(),
140 >                                    mu->Eta(),
141 >                                    mu->IsGlobalMuon(),
142 >                                    mu->IsTrackerMuon(),
143 >                                    mu->TrackerTrk()->RChi2(),
144 >                                    global_rchi2,
145 >                                    (Double_t)(mu->NValidHits()),
146 >                                    (Double_t)(mu->TrackerTrk()->NHits()),
147 >                                    (Double_t)(mu->TrackerTrk()->NPixelHits()),
148 >                                    (Double_t)(mu->NMatches()),
149 >                                    mu->TrkKink(),
150 >                                    muTools.GetSegmentCompatability(mu),
151 >                                    muTools.GetCaloCompatability(mu,true,true),
152 >                                    mu->HadEnergy(),
153 >                                    mu->EmEnergy(),
154 >                                    mu->HadS9Energy(),
155 >                                    mu->EmS9Energy(),
156 >                                    (Bool_t)(ctrl.debug) );
157 >  */
158 >  double mvaval = 0.0;
159  
160 <  // 0x20
161 <  level++;
162 <  if( mu->nTkHits < 10 ) {
163 <    failmask |= (1<<level);
160 >  SelectionStatus status;
161 >  bool pass = false;
162 >  
163 >  if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
164 >      && fabs(mu->Eta()) <= 1.5 && mu->Pt() <= 10 && mvaval >= MUON_IDMVA_CUT_BIN0)  pass = true;
165 >  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
166 >           && fabs(mu->Eta()) <= 1.5 && mu->Pt() > 10 && mvaval >= MUON_IDMVA_CUT_BIN1)  pass = true;
167 >  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
168 >           && fabs(mu->Eta()) > 1.5 && mu->Pt() <= 10 && mvaval >= MUON_IDMVA_CUT_BIN2)  pass = true;
169 >  else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
170 >           && fabs(mu->Eta()) > 1.5 && mu->Pt() > 10 && mvaval >= MUON_IDMVA_CUT_BIN3)  pass = true;
171 >  else if( !(mu->IsGlobalMuon()) && mu->IsTrackerMuon() && mvaval >= MUON_IDMVA_CUT_BIN4 )  pass = true;
172 >  else if( mu->IsGlobalMuon() && !(mu->IsTrackerMuon()) && mvaval >= MUON_IDMVA_CUT_BIN5 )  pass = true;
173 >  
174 >
175 >
176 >  if( pass ) {
177 >    status.orStatus(SelectionStatus::LOOSEID);
178 >    status.orStatus(SelectionStatus::TIGHTID);
179    }
180  
181 <  level++;
182 <  if(mu->nPixHits         < 1) {
204 <    failmask |= (1<<level);
205 <  }
181 >  return status;
182 > }
183  
184 + //--------------------------------------------------------------------------------------------------
185 + void initMuonIDMVA()
186 + //--------------------------------------------------------------------------------------------------
187 + {
188 +  muIDMVA = new mithep::MuonIDMVA();
189 +  vector<string> weightFiles;
190 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_barrel_lowpt_V2.weights.xml");
191 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_barrel_highpt_V2.weights.xml");
192 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_endcap_lowpt_V2.weights.xml");
193 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_endcap_highpt_V2.weights.xml");
194 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_tracker_V2.weights.xml");
195 +  weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_global_V2.weights.xml");
196 +  muIDMVA->Initialize( "MuonIDMVA",
197 +                       mithep::MuonIDMVA::kIDV0,
198 +                       kTRUE, weightFiles);
199 + }
200  
201 <  level++;
202 <  if(fabs(mu->d0)>0.02)   {
203 <    failmask |= (1<<level);
201 > //--------------------------------------------------------------------------------------------------
202 > SelectionStatus muonIDPFSelection(ControlFlags &ctrl,
203 >                                  const mithep::Muon *mu,
204 >                                  const mithep::Vertex * vtx,
205 >                                  const mithep::Array<mithep::PFCandidate> * pfCandidates )
206 > //--------------------------------------------------------------------------------------------------
207 > {
208 >  bool pass = false;
209 >  SelectionStatus status; // init'ed to FAIL
210 >
211 >  // check that it matches to a PF muon
212 >  for( int i=0; i<pfCandidates->GetEntries(); i++ ) {
213 >    // tmp
214 >    if( !(PFnoPUflag[i]) ) continue; // my PF no PU hack
215 >
216 >    const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfCandidates)[i]);
217 >    if( (pf->TrackerTrk() == mu->TrackerTrk()) && abs(pf->PFType()) == mithep::PFCandidate::eMuon ) {
218 >      pass = true;
219 >      break;
220 >    }
221    }
222 + //      
223 + //      if(mu->IsPFMuon()) pass = true;
224 + //      else pass = false;
225  
226 <  /*
227 <  if(mu->pt>20) {
228 <    if(fabs(mu->d0)>0.02)   {
229 <      failmask |= (1<<level);
230 <    }
231 <  } else {
232 <    if(fabs(mu->d0)>0.01)  {
233 <    failmask |= (1<<level);
234 <    }
226 >  //
227 >  // NB : ipsig here for reference synch ...
228 >  //
229 > #ifdef SYNC
230 >  if( pass && fabs(mu->Ip3dPVSignificance()) < 4 ) {
231 >    status.orStatus(SelectionStatus::LOOSEID);
232 >    status.orStatus(SelectionStatus::TIGHTID);
233 >  }
234 > #else
235 >  if( pass ) {
236 >    status.orStatus(SelectionStatus::LOOSEID);
237 >    status.orStatus(SelectionStatus::TIGHTID);
238    }
239 <  */
239 > #endif
240  
225  SelectionStatus status;
226  if( !failmask ) status.setStatus(SelectionStatus::LOOSEID);
227  if( !failmask ) status.setStatus(SelectionStatus::TIGHTID);
241    return status;
242 <
230 <
231 < };
232 <
242 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines