ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/LeptonSelection/src/MuonSelection.cc
Revision: 1.20
Committed: Sun May 20 19:08:58 2012 UTC (13 years ago) by khahn
Content type: text/plain
Branch: MAIN
Changes since 1.19: +6 -14 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <math.h>
2 #include <iostream>
3
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 //--------------------------------------------------------------------------------------------------
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);
50 return status;
51 }
52
53
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 //--------------------------------------------------------------------------------------------------
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
82 SelectionStatus status;
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 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 // if( mu->IsTrackerMuon() && mu->HasTrackerTrk() && !mu->IsGlobalMuon() )
109 // ret &= ( mu->Quality().QualityMask().Mask() & mithep::MuonQuality::AllArbitrated);
110 // if(ctrl.debug) cout << "if isTrackerMuon, arbitrated ? ... " << ret << endl;
111 // ret &= ( mu->BestTrk()->DzCorrected(vtx) < 0.1);
112 // if( ctrl.debug ) cout << "elepresel : ret after dZcorr : " << ret << endl;
113
114
115 SelectionStatus status;
116 if( ret ) status.setStatus(SelectionStatus::PRESELECTION);
117 if(ctrl.debug) cout << "muon presel returning status : " << status.getStatus() << endl;
118 return status;
119 }
120
121
122
123
124 //--------------------------------------------------------------------------------------------------
125 SelectionStatus muonIDMVASelection(ControlFlags &ctrl,
126 const mithep::Muon *mu,
127 const mithep::Vertex & vtx )
128 //--------------------------------------------------------------------------------------------------
129 {
130 double global_rchi2 = (mu->IsGlobalMuon()) ? mu->GlobalTrk()->RChi2() : 0.;
131
132 //
133 // WARNING !!! KH hacked out to sync
134 //
135 /*
136 double mvaval = muIDMVA->MVAValue_ID(mu->Pt(),
137 mu->Eta(),
138 mu->IsGlobalMuon(),
139 mu->IsTrackerMuon(),
140 mu->TrackerTrk()->RChi2(),
141 global_rchi2,
142 (Double_t)(mu->NValidHits()),
143 (Double_t)(mu->TrackerTrk()->NHits()),
144 (Double_t)(mu->TrackerTrk()->NPixelHits()),
145 (Double_t)(mu->NMatches()),
146 mu->TrkKink(),
147 muTools.GetSegmentCompatability(mu),
148 muTools.GetCaloCompatability(mu,true,true),
149 mu->HadEnergy(),
150 mu->EmEnergy(),
151 mu->HadS9Energy(),
152 mu->EmS9Energy(),
153 (Bool_t)(ctrl.debug) );
154 */
155 double mvaval = 0.0;
156
157 SelectionStatus status;
158 bool pass = false;
159
160 if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
161 && fabs(mu->Eta()) <= 1.5 && mu->Pt() <= 10 && mvaval >= MUON_IDMVA_CUT_BIN0) pass = true;
162 else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
163 && fabs(mu->Eta()) <= 1.5 && mu->Pt() > 10 && mvaval >= MUON_IDMVA_CUT_BIN1) pass = true;
164 else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
165 && fabs(mu->Eta()) > 1.5 && mu->Pt() <= 10 && mvaval >= MUON_IDMVA_CUT_BIN2) pass = true;
166 else if( mu->IsGlobalMuon() && mu->IsTrackerMuon()
167 && fabs(mu->Eta()) > 1.5 && mu->Pt() > 10 && mvaval >= MUON_IDMVA_CUT_BIN3) pass = true;
168 else if( !(mu->IsGlobalMuon()) && mu->IsTrackerMuon() && mvaval >= MUON_IDMVA_CUT_BIN4 ) pass = true;
169 else if( mu->IsGlobalMuon() && !(mu->IsTrackerMuon()) && mvaval >= MUON_IDMVA_CUT_BIN5 ) pass = true;
170
171
172
173 if( pass ) {
174 status.orStatus(SelectionStatus::LOOSEID);
175 status.orStatus(SelectionStatus::TIGHTID);
176 }
177
178 return status;
179 }
180
181 //--------------------------------------------------------------------------------------------------
182 void initMuonIDMVA()
183 //--------------------------------------------------------------------------------------------------
184 {
185 muIDMVA = new mithep::MuonIDMVA();
186 vector<string> weightFiles;
187 weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_barrel_lowpt_V2.weights.xml");
188 weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_barrel_highpt_V2.weights.xml");
189 weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_endcap_lowpt_V2.weights.xml");
190 weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_endcap_highpt_V2.weights.xml");
191 weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_tracker_V2.weights.xml");
192 weightFiles.push_back("./data/MuonIDMVAWeights/MuonIDMVA_BDTG_global_V2.weights.xml");
193 muIDMVA->Initialize( "MuonIDMVA",
194 mithep::MuonIDMVA::kIDV0,
195 kTRUE, weightFiles);
196 }
197
198 //--------------------------------------------------------------------------------------------------
199 SelectionStatus muonIDPFSelection(ControlFlags &ctrl,
200 const mithep::Muon *mu,
201 const mithep::Vertex & vtx,
202 const mithep::Array<mithep::PFCandidate> * pfCandidates )
203 //--------------------------------------------------------------------------------------------------
204 {
205 bool pass = false;
206 SelectionStatus status; // init'ed to FAIL
207
208 // check that it matches to a PF muon
209 for( int i=0; i<pfCandidates->GetEntries(); i++ ) {
210 // tmp
211 if( !(PFnoPUflag[i]) ) continue; // my PF no PU hack
212
213 const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfCandidates)[i]);
214 if( (pf->TrackerTrk() == mu->TrackerTrk()) && abs(pf->PFType()) == mithep::PFCandidate::eMuon ) {
215 pass = true;
216 break;
217 }
218 }
219
220 //
221 // NB : ipsig here for reference synch ...
222 //
223 #ifdef SYNC
224 if( pass && fabs(mu->Ip3dPVSignificance()) < 4 ) {
225 status.orStatus(SelectionStatus::LOOSEID);
226 status.orStatus(SelectionStatus::TIGHTID);
227 }
228 #else
229 if( pass ) {
230 status.orStatus(SelectionStatus::LOOSEID);
231 status.orStatus(SelectionStatus::TIGHTID);
232 }
233 #endif
234
235 return status;
236 }