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