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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines