ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/LeptonSelection/src/FSR.cc
Revision: 1.7
Committed: Wed Oct 17 01:31:22 2012 UTC (12 years, 7 months ago) by anlevin
Content type: text/plain
Branch: MAIN
Changes since 1.6: +16 -11 lines
Log Message:
updates for hcp sync

File Contents

# Content
1 #include <vector>
2 #include "MathUtils.h"
3 #include "FSR.h"
4 #include "IsolationSelection.h"
5 #include "CommonDefs.h"
6 #include "TLorentzVector.h"
7
8 using namespace std;
9
10 extern vector<bool> PFnoPUflag;
11
12 //--------------------------------------------------------------------------------------------------
13 // typeI = PF IDed photons. NB : repurpose PFnoPUflag, flip for recovered photons
14 // so that they are skipped in the isolation calculation
15 //--------------------------------------------------------------------------------------------------
16 bool recover_typeI_Photon( ControlFlags & ctrl,
17 mithep::Electron * el,
18 const int electronIndex,
19 vector<SimpleLepton> &lepvec,
20 const mithep::Array<mithep::PFCandidate> * pfArr,
21 const mithep::Array<mithep::Electron> *eleArr,
22 TLorentzVector * Zvec,
23 vector<const mithep::PFCandidate*> &photonsToVeto )
24 //--------------------------------------------------------------------------------------------------
25 {
26 if( lepvec[electronIndex].fsrRecoveryAttempted ) return false;
27
28 vector<int> photonIndices;
29 for( int i=0; i<pfArr->GetEntries(); i++ ) {
30
31 if( !(PFnoPUflag[i])) continue; // my PF no PU hack
32 const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfArr)[i]);
33 if( abs(pf->PFType()) == mithep::PFCandidate::eGamma &&
34 pf->Pt() > 2.0 && fabs(pf->Eta()) < 2.4 ) {
35
36 if( ctrl.debug ) std::cerr << "FSR :: pass preselection ... pt: "<< pf->Pt() << std::endl;
37 // float dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(), el->Phi(), el->Eta());
38 float dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(),
39 lepvec[electronIndex].vec.Phi(), lepvec[electronIndex].vec.Eta());
40 if( ctrl.debug ) std::cerr << "FSR :: dR = " << dR << std::endl;
41
42 //
43 // veto if close to an electron SC
44 //
45 bool flagEleSC = false;
46 for( int j=0; j<lepvec.size(); j++ ) {
47 if( !(abs(lepvec[j].type) == 11 ) ) continue;
48 if( !(lepvec[j].status.looseIDAndPre()) ) continue;
49 double eeta=lepvec[j].vec.Eta(); double ephi=lepvec[j].vec.Phi();
50 float dPhi = fabs(mithep::MathUtils::DeltaPhi(pf->Phi(),ephi));
51 float dEta = fabs(pf->Eta()-eeta);
52 float dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(), ephi, eeta);
53 if(ctrl.debug) cout << "FSR :: comparing to ele, dPhi: " << dPhi
54 << "\tdEta: " << dEta
55 << "\tetaPH: " << pf->Eta()
56 << "\tetaELH: " << eeta
57 << "\tdR:" << dR << endl;
58 if( (dPhi<2.&& dEta<0.05) || dR<0.15 ) {
59 flagEleSC = true;
60 break;
61 }
62 if( flagEleSC ) break;
63 }
64 if( flagEleSC ) continue;
65 if( ctrl.debug ) std::cerr << "FSR :: not matched to an ele SC ... " << std::endl;
66
67 //
68 // check that input electron is the closest lepton to this photon
69 //
70 bool found_closer_lepton=false;
71 for( int j=0; j<lepvec.size(); j++ ) {
72 if( j == electronIndex ) continue;
73 if( !(lepvec[j].status.looseIDAndPre()) ) continue;
74 float tmp_dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(),
75 lepvec[j].vec.Phi(), lepvec[j].vec.Eta());
76 if( tmp_dR < dR ) {
77 if(ctrl.debug) cout << "FSR :: found closer lepton (j="<<j<<" : "
78 <<tmp_dR<<" vs "<<dR<<") skipping..." << endl;
79 found_closer_lepton=true;
80 break;
81 }
82 }
83 if( found_closer_lepton ) continue;
84
85
86 //
87 // Z mass OK?
88 //
89 TLorentzVector pvec;
90 pvec.SetPtEtaPhiM( pf->Pt(), pf->Eta(), pf->Phi(), 0.);
91 float newMass = (pvec + *Zvec).M();
92 if( !( newMass > 4. &&
93 newMass < 100. &&
94 (fabs(newMass-Z_MASS) < fabs(Zvec->M()-Z_MASS))
95 ) ) continue;
96 if( ctrl.debug ) std::cerr << "FSR :: improved Zmass ... " <<
97 Zvec->M() << " -> " << newMass << std::endl;
98
99
100 //
101 // "keep all photons close to one of the 4L electrons ..."
102 //
103 if( dR < 0.07 ) {
104 if( ctrl.debug ) std::cerr << "FSR :: dR < 0.07, pushing ... " << std::endl;
105 photonIndices.push_back(i);
106 }
107
108 //
109 // "need tighter cuts for other photons ..."
110 //
111 //if( dR < 0.5 && pf->Pt() > 4. && dbetaCorrectedIsoDr03(ctrl, pf, el, pfArr) < 1.0) {
112 if( dR < 0.5 && pf->Pt() > 4. && nonCorrectedIsoDr03(ctrl, pf, el, pfArr) < 1.0) {
113 if( ctrl.debug ) std::cerr << "FSR :: tighter cuts, pushing ... " << std::endl;
114 photonIndices.push_back(i);
115 }
116 }
117 }
118
119 float highest_pt = -1; int highest_pt_index=-1;
120 float smallest_dR = 999.; int smallest_dR_index=-1;
121 for( int i=0; i<photonIndices.size(); i++ ) {
122 const mithep::PFCandidate *pf = (mithep::PFCandidate*)(pfArr->At(photonIndices[i]));
123 float dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(), el->Phi(), el->Eta());
124 if( pf->Pt() > highest_pt ) {
125 highest_pt_index = photonIndices[i];
126 highest_pt = pf->Pt();
127 }
128 if( dR < smallest_dR ) {
129 smallest_dR_index = photonIndices[i];
130 smallest_dR = dR;
131 }
132 }
133
134 const mithep::PFCandidate * thepf;
135 if( highest_pt > 4. ) {
136 thepf = (const mithep::PFCandidate*)(pfArr->At(highest_pt_index));
137 // "... remove it from lepton isolation ..."
138 // PFnoPUflag[highest_pt_index] = 0;
139 // TMP, commented flip above for FSR study
140 // gammaMatches[highest_pt_index].push_back(lepvec[electronIndex].index);
141 photonsToVeto.push_back(thepf);
142 } else if( smallest_dR != 999. ) {
143 thepf = (const mithep::PFCandidate*)(pfArr->At(smallest_dR_index));
144 // "... remove it from lepton isolation ..."
145 // PFnoPUflag[smallest_dR_index] = 0;
146 // TMP, commented flip above for FSR study
147 // gammaMatches[smallest_dR_index].push_back(lepvec[electronIndex].index);
148 photonsToVeto.push_back(thepf);
149 } else {
150 return false;
151 }
152
153 if( thepf != NULL ) {
154 // add to the electron
155 TLorentzVector elvec,phvec,newelvec;
156 elvec.SetPtEtaPhiM( el->Pt(), el->Eta(), el->Phi(), ELECTRON_MASS);
157 phvec.SetPtEtaPhiM( thepf->Pt(), thepf->Eta(), thepf->Phi(), 0.);
158 newelvec = elvec+phvec;
159 // don't update the electron object, just simplelepton
160 // el->SetPtEtaPhi (newelvec.Pt(),
161 // newelvec.Eta(),
162 // newelvec.Phi());
163 lepvec[electronIndex].vec += phvec;
164 lepvec[electronIndex].fsrRecoveryAttempted = true;
165 return true;
166 }
167 return false;
168 }
169
170
171
172 //--------------------------------------------------------------------------------------------------
173 // typeI = PF IDed photons. NB : repurpose PFnoPUflag, flip for recovered photons
174 // so that they are skipped in the isolation calculation
175 //--------------------------------------------------------------------------------------------------
176 bool recover_typeI_Photon( ControlFlags & ctrl,
177 mithep::Muon * mu,
178 const int muonIndex,
179 vector<SimpleLepton> &lepvec,
180 const mithep::Array<mithep::PFCandidate> * pfArr,
181 const mithep::Array<mithep::Electron> *eleArr,
182 TLorentzVector * Zvec,
183 vector<const mithep::PFCandidate*> &photonsToVeto )
184 //--------------------------------------------------------------------------------------------------
185 {
186
187 if( lepvec[muonIndex].fsrRecoveryAttempted ) return false;
188
189 vector<int> photonIndices;
190 for( int i=0; i<pfArr->GetEntries(); i++ ) {
191
192 if( !(PFnoPUflag[i])) continue; // my PF no PU hack
193
194 const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfArr)[i]);
195 if( abs(pf->PFType()) == mithep::PFCandidate::eGamma &&
196 pf->Pt() > 2.0 && fabs(pf->Eta()) < 2.4 ) {
197
198 if( ctrl.debug ) std::cerr << "FSR :: pass preselection ... pt: "<< pf->Pt() << std::endl;
199 // float dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(), mu->Phi(), mu->Eta());
200 float dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(),
201 lepvec[muonIndex].vec.Phi(), lepvec[muonIndex].vec.Eta());
202 if( ctrl.debug ) std::cerr << "FSR :: dR = " << dR << std::endl;
203 //
204 // veto if close to an electron SC
205 //
206 bool flagEleSC = false;
207 for( int j=0; j<lepvec.size(); j++ ) {
208 if( !(abs(lepvec[j].type) == 11 ) ) continue;
209 if( !(lepvec[j].status.looseIDAndPre()) ) continue;
210 double eeta=lepvec[j].vec.Eta(); double ephi=lepvec[j].vec.Phi();
211 float dPhi = fabs(mithep::MathUtils::DeltaPhi(pf->Phi(),ephi));
212 float dEta = fabs(pf->Eta()-eeta);
213 float dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(), ephi, eeta);
214 if(ctrl.debug) cout << "FSR :: comparing to ele, dPhi: " << dPhi
215 << "\tdEta: " << dEta
216 << "\tetaPH: " << pf->Eta()
217 << "\tetaELH: " << eeta
218 << "\tdR:" << dR << endl;
219 if( (dPhi<2.&& dEta<0.05) || dR<0.15 ) {
220 flagEleSC = true;
221 break;
222 }
223 if( flagEleSC ) break;
224 }
225 if( flagEleSC ) continue;
226 if( ctrl.debug ) std::cerr << "FSR :: not matched to an ele SC ... " << std::endl;
227
228
229 //
230 // check that input muon is the closest lepton to this photon
231 //
232 bool found_closer_lepton=false;
233 for( int j=0; j<lepvec.size(); j++ ) {
234 if( j == muonIndex ) continue;
235 if( !(lepvec[j].status.looseIDAndPre()) ) continue;
236 float tmp_dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(),
237 lepvec[j].vec.Phi(), lepvec[j].vec.Eta());
238 if( tmp_dR < dR ) {
239 if(ctrl.debug) cout << "FSR :: found closer lepton (j="<<j<<" : "
240 <<tmp_dR<<" vs "<<dR<<") skipping..." << endl;
241 found_closer_lepton=true;
242 break;
243 }
244 }
245 if( found_closer_lepton ) continue;
246
247
248
249 //
250 // Z mass OK?
251 //
252 TLorentzVector pvec;
253 pvec.SetPtEtaPhiM( pf->Pt(), pf->Eta(), pf->Phi(), 0.);
254 float newMass = (pvec + *Zvec).M();
255 if( !( newMass > 4. &&
256 newMass < 100. &&
257 (fabs(newMass-Z_MASS) < fabs(Zvec->M()-Z_MASS))
258 ) ) continue;
259 if( ctrl.debug ) std::cerr << "FSR :: improved Zmass ... " <<
260 Zvec->M() << " -> " << newMass << std::endl;
261
262 //
263 // "keep all photons close to one of the 4L muons ..."
264 //
265 if( dR < 0.07 ) {
266 if( ctrl.debug ) std::cerr << "FSR :: dR < 0.07, pushing ... " << std::endl;
267 photonIndices.push_back(i);
268 }
269
270 //
271 // "need tighter cuts for other photons ..."
272 //
273 if( ctrl.debug ) std::cerr << "FSR :: pass tighter?, pT: " << pf->Pt() << std::endl;
274 // if( dR < 0.5 && pf->Pt() > 4. && dbetaCorrectedIsoDr03(ctrl, pf, mu, pfArr) < 1.0) {
275
276
277 if( dR < 0.5 && pf->Pt() > 4. && nonCorrectedIsoDr03(ctrl, pf, mu, pfArr) < 1.0) {
278 if( ctrl.debug ) std::cerr << "FSR :: tighter cuts, pushing index= " << i << std::endl;
279 photonIndices.push_back(i);
280 }
281 }
282 }
283
284 float highest_pt = -1; int highest_pt_index=-1;
285 float smallest_dR = 999.; int smallest_dR_index=-1;
286 for( int i=0; i<photonIndices.size(); i++ ) {
287 const mithep::PFCandidate *pf = (mithep::PFCandidate*)(pfArr->At(photonIndices[i]));
288 float dR = mithep::MathUtils::DeltaR(pf->Phi(),pf->Eta(), mu->Phi(), mu->Eta());
289 if( pf->Pt() > highest_pt ) {
290 highest_pt_index = photonIndices[i];
291 highest_pt = pf->Pt();
292 }
293 if( dR < smallest_dR ) {
294 smallest_dR_index = photonIndices[i];
295 smallest_dR = dR;
296 }
297 }
298
299 const mithep::PFCandidate * thepf;
300 if( highest_pt > 4. ) {
301 if(ctrl.debug) std::cerr << "FSR :: taking highest pt gamma, index = " << highest_pt_index << endl;
302 thepf = (const mithep::PFCandidate*)(pfArr->At(highest_pt_index));
303 // "... remove it from lepton isolation ..."
304 // PFnoPUflag[highest_pt_index] = 0;
305 // TMP, commented flip above for FSR study
306 // gammaMatches[highest_pt_index].push_back(lepvec[muonIndex].index);
307 photonsToVeto.push_back(thepf);
308 } else if( smallest_dR != 999. ) {
309 if(ctrl.debug) std::cerr << "FSR :: taking smallest dR gamma, index = " << highest_pt_index << endl;
310 thepf = (const mithep::PFCandidate*)(pfArr->At(smallest_dR_index));
311 // "... remove it from lepton isolation ..."
312 // PFnoPUflag[smallest_dR_index] = 0;
313 // TMP, commented flip above for FSR study
314 //gammaMatches[smallest_dR_index].push_back(lepvec[muonIndex].index);
315 photonsToVeto.push_back(thepf);
316 } else {
317 return false;
318 }
319
320 TLorentzVector pvec;
321 if( thepf != NULL ) {
322 // add to the muon
323 if( ctrl.debug ) cerr << "FSR :: before return, oldpT=" << mu->Pt() << endl;
324 TLorentzVector muvec,phvec,newmuvec;
325 muvec.SetPtEtaPhiM( mu->Pt(), mu->Eta(), mu->Phi(), MUON_MASS);
326 phvec.SetPtEtaPhiM( thepf->Pt(), thepf->Eta(), thepf->Phi(), 0.);
327 pvec = phvec;
328 newmuvec = muvec+phvec;
329 // don't update the muon object, just simplelepton
330 // mu->SetPtEtaPhi (newmuvec.Pt(),
331 // newmuvec.Eta(),
332 // newmuvec.Phi());
333 lepvec[muonIndex].vec += phvec;
334 lepvec[muonIndex].fsrRecoveryAttempted = true;
335 return true;
336 }
337 return false;
338 }
339
340
341
342 //--------------------------------------------------------------------------------------------------
343 // typeII = "PFClusters linked to muons"
344 //--------------------------------------------------------------------------------------------------
345 bool recover_typeII_Photon( ControlFlags & ctrl,
346 mithep::Muon * mu,
347 const int muonIndex,
348 vector<SimpleLepton> &lepvec,
349 const mithep::Array<mithep::PFCandidate> * pfArr )
350 //--------------------------------------------------------------------------------------------------
351 {
352 if( lepvec[muonIndex].fsrRecoveryAttempted ) return false;
353
354 bool foundPF=false;
355 const mithep::PFCandidate * thepf;
356 for( int i=0; i<pfArr->GetEntries(); i++ ) {
357
358 if( !(PFnoPUflag[i]) ) continue; // my PF no PU hack
359 const mithep::PFCandidate *pf = (mithep::PFCandidate*)((*pfArr)[i]);
360 if( abs(pf->PFType()) == mithep::PFCandidate::eMuon
361 && (mu->TrackerTrk()==pf->TrackerTrk()))
362 {
363 if(ctrl.debug) cout << "FSR :: t2, found pf muon, pt " << mu->Pt() << endl;
364 foundPF = true;
365 thepf = pf;
366 break;
367 }
368 }
369
370 if( foundPF ) {
371 double sintet = thepf->Pt()/thepf->E();
372 double phpt = thepf->EECal() * sintet;
373 if ( thepf->EECal() >= 2.0 && phpt >= 2.0 ) {
374 // don't update the muon object, just simplelepton
375 // mu->SetPtEtaPhi (mu->Pt()+phpt,
376 // mu->Eta(),
377 // mu->Phi());
378 TLorentzVector pvec;
379 pvec.SetPtEtaPhiM( phpt,mu->Eta(),mu->Phi(),0.);
380 lepvec[muonIndex].vec += pvec;
381 if(ctrl.debug) cout << "FSR :: t2, new pt " << lepvec[muonIndex].vec.Pt() << endl;
382 lepvec[muonIndex].fsrRecoveryAttempted = true;
383 return true;
384 }
385 }
386
387 return false;
388 }