1 |
#ifndef VHBBCANDIDATETOOLS_H
|
2 |
#define VHBBCANDIDATETOOLS_H
|
3 |
|
4 |
#include "VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidate.h"
|
5 |
|
6 |
#include <iostream>
|
7 |
|
8 |
struct CompareJetPtMuons {
|
9 |
bool operator()( const VHbbEvent::MuonInfo& j1, const VHbbEvent::MuonInfo& j2 ) const {
|
10 |
return j1.p4.Pt() > j2.p4.Pt();
|
11 |
}
|
12 |
};
|
13 |
struct CompareJetPtElectrons {
|
14 |
bool operator()( const VHbbEvent::ElectronInfo& j1, const VHbbEvent::ElectronInfo& j2 ) const {
|
15 |
return j1.p4.Pt() > j2.p4.Pt();
|
16 |
}
|
17 |
};
|
18 |
|
19 |
|
20 |
|
21 |
class VHbbCandidateTools {
|
22 |
public:
|
23 |
|
24 |
VHbbCandidateTools(bool verbose = false): verbose_(verbose){}
|
25 |
|
26 |
float deltaPhi(float in2, float in1){
|
27 |
float dphi = in2-in1;
|
28 |
if ( dphi > M_PI ) {
|
29 |
dphi -= 2.0*M_PI;
|
30 |
} else if ( dphi <= -M_PI ) {
|
31 |
dphi += 2.0*M_PI;
|
32 |
}
|
33 |
return dphi;
|
34 |
}
|
35 |
|
36 |
|
37 |
VHbbCandidate getHZtaumuCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& muPos, std::vector<unsigned int>& tauPos){
|
38 |
if (verbose_) std::cout <<" getHZtaumuCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<< " tau " << in.V.taus.size() << std::endl;
|
39 |
ok = false;
|
40 |
VHbbCandidate temp=in;
|
41 |
// Require exactly one tau and muon, and no electrons
|
42 |
if (temp.V.taus.size()!=1) return in;
|
43 |
if (temp.V.muons.size()!=1) return in ;
|
44 |
if (temp.V.electrons.size()!=0) return in ;
|
45 |
temp.V.p4 = temp.V.taus[0].p4 + temp.V.muons[0].p4;
|
46 |
temp.V.firstLepton = muPos[0];
|
47 |
temp.V.secondLepton = tauPos[0];
|
48 |
|
49 |
ok = true;
|
50 |
return temp;
|
51 |
|
52 |
}
|
53 |
VHbbCandidate getHWtaunCandidate(const VHbbCandidate & in, bool & ok , std::vector<unsigned int>& pos){
|
54 |
|
55 |
if (verbose_){
|
56 |
std::cout <<" getHWtaunCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<< " tau " << in.V.taus.size() << std::endl;
|
57 |
std::cout << " pos.size()=" << pos.size() << std::endl;
|
58 |
}
|
59 |
|
60 |
ok = false;
|
61 |
VHbbCandidate temp=in;
|
62 |
// require a tau and no electrons or muons
|
63 |
if (temp.V.taus.size()!=1) return in;
|
64 |
if (temp.V.muons.size()!=0) return in ;
|
65 |
if (temp.V.electrons.size()!=0) return in ;
|
66 |
if (temp.V.mets.size()<1) return in ;
|
67 |
temp.V.p4 = temp.V.taus[0].p4+temp.V.mets[0].p4;
|
68 |
temp.V.firstLepton=pos[0];
|
69 |
|
70 |
if (verbose_){
|
71 |
std::cout << "Done with getHWtaunCandidate" << std::endl;
|
72 |
}
|
73 |
|
74 |
ok=true;
|
75 |
return temp;
|
76 |
}
|
77 |
|
78 |
|
79 |
|
80 |
VHbbCandidate getHZmumuCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
|
81 |
if (verbose_){
|
82 |
std::cout <<" getHZmumuCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<<std::endl;
|
83 |
}
|
84 |
ok = false;
|
85 |
VHbbCandidate temp=in;
|
86 |
|
87 |
//
|
88 |
// change: allow for additional leptons; by definition
|
89 |
//
|
90 |
if (temp.V.muons.size()<2) return in ;
|
91 |
// if (temp.V.electrons.size()!=0) return in ;
|
92 |
std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
|
93 |
|
94 |
// beware: assumes already sorted!!!!
|
95 |
|
96 |
// CompareJetPtMuons ptComparator;
|
97 |
// std::sort(muons_.begin(), muons_.end(), ptComparator);
|
98 |
if (muons_[0].p4.Pt()<20 || muons_[1].p4.Pt()<20 ) return in;
|
99 |
|
100 |
//
|
101 |
// now I need to ask also for the charge
|
102 |
//
|
103 |
int selectMu2=1;
|
104 |
|
105 |
if (muons_[0].charge* muons_[selectMu2].charge > 0){
|
106 |
if (muons_.size() ==2) return in;
|
107 |
//
|
108 |
// i need to find a proper pair
|
109 |
//
|
110 |
|
111 |
for (unsigned int it=2; it< muons_.size(); ++it){
|
112 |
if ( muons_[it].charge * muons_[0].charge < 0) {
|
113 |
selectMu2 = it;
|
114 |
break;
|
115 |
}
|
116 |
if (selectMu2 == 1) return in;
|
117 |
}
|
118 |
}
|
119 |
temp.V.p4 = muons_[0].p4+muons_[selectMu2].p4;
|
120 |
std::vector<VHbbEvent::MuonInfo> muons2_;
|
121 |
for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons_.begin(); it!= muons_.end(); ++it){
|
122 |
if (it->p4.Pt()>20) muons2_.push_back(*it);
|
123 |
}
|
124 |
temp.V.muons = muons2_;
|
125 |
|
126 |
// the same for electrons
|
127 |
std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
|
128 |
|
129 |
// beware; assumes already sorted
|
130 |
|
131 |
// CompareJetPtElectrons ptComparator2;
|
132 |
// std::sort(electrons_.begin(), electrons_.end(), ptComparator2);
|
133 |
std::vector<VHbbEvent::ElectronInfo> electrons2_;
|
134 |
for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons_.begin(); it!= electrons_.end(); ++it){
|
135 |
if (it->p4.Pt()>20) electrons2_.push_back(*it);
|
136 |
}
|
137 |
temp.V.electrons = electrons2_;
|
138 |
|
139 |
//
|
140 |
// consider all
|
141 |
//
|
142 |
|
143 |
|
144 |
// if (temp.V.Pt()<150 ) return in;
|
145 |
// if (temp.H.Pt()<150) return in;
|
146 |
// if (temp.H.firstJet().csv< 0.9) return in;
|
147 |
// if (temp.H.secondJet().csv<0.5) return in;
|
148 |
// if (deltaPhi(temp.V.Phi(),temp.H.Phi())<2.7) return in;
|
149 |
// if (temp.V.FourMomentum.Mass()<75 || temp.V.FourMomentum.Mass()>105) return in;
|
150 |
// if (temp.additionalJets.size()>0) return in;
|
151 |
// if (std::Abs(deltaTheta) ????
|
152 |
|
153 |
temp.V.firstLepton = pos[0];
|
154 |
temp.V.secondLepton = pos[selectMu2];
|
155 |
ok = true;
|
156 |
return temp;
|
157 |
}
|
158 |
VHbbCandidate getHZeeCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
|
159 |
if (verbose_){
|
160 |
std::cout <<" getHZeeCandidate input mu "<<in.V.electrons.size()<<" e "<<in.V.muons.size()<<std::endl;
|
161 |
}
|
162 |
ok = false;
|
163 |
VHbbCandidate temp=in;
|
164 |
|
165 |
//
|
166 |
// change: allow for additional leptons; by definition
|
167 |
//
|
168 |
if (temp.V.electrons.size()<2) return in ;
|
169 |
// if (temp.V.electrons.size()!=0) return in ;
|
170 |
std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
|
171 |
|
172 |
// beware assumes already sorted
|
173 |
|
174 |
// CompareJetPtElectrons ptComparator;
|
175 |
// std::sort(electrons_.begin(), electrons_.end(), ptComparator);
|
176 |
if (electrons_[0].p4.Pt()<20 || electrons_[1].p4.Pt()<20 ) return in;
|
177 |
//
|
178 |
// now I need to ask also for the charge
|
179 |
//
|
180 |
int selectE2=1;
|
181 |
|
182 |
if (electrons_[0].charge* electrons_[selectE2].charge > 0){
|
183 |
if (electrons_.size() ==2) return in;
|
184 |
//
|
185 |
// i need to find a proper pair
|
186 |
//
|
187 |
|
188 |
for (unsigned int it=2; it< electrons_.size(); ++it){
|
189 |
if ( electrons_[it].charge * electrons_[0].charge < 0) {
|
190 |
selectE2 = it;
|
191 |
break;
|
192 |
}
|
193 |
if (selectE2 == 1) return in;
|
194 |
}
|
195 |
}
|
196 |
temp.V.p4 = electrons_[0].p4+electrons_[selectE2].p4;
|
197 |
std::vector<VHbbEvent::ElectronInfo> electrons2_;
|
198 |
for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons_.begin(); it!= electrons_.end(); ++it){
|
199 |
if (it->p4.Pt()>20) electrons2_.push_back(*it);
|
200 |
}
|
201 |
temp.V.electrons = electrons2_;
|
202 |
|
203 |
// the same for muonss
|
204 |
std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
|
205 |
|
206 |
// beware assumes already sorted
|
207 |
|
208 |
// CompareJetPtMuons ptComparator2;
|
209 |
// std::sort(muons_.begin(), muons_.end(), ptComparator2);
|
210 |
std::vector<VHbbEvent::MuonInfo> muons2_;
|
211 |
for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons_.begin(); it!= muons_.end(); ++it){
|
212 |
if (it->p4.Pt()>20) muons2_.push_back(*it);
|
213 |
}
|
214 |
temp.V.muons = muons2_;
|
215 |
|
216 |
temp.V.firstLepton = pos[0];
|
217 |
temp.V.secondLepton = pos[selectE2];
|
218 |
|
219 |
|
220 |
ok = true;
|
221 |
return temp;
|
222 |
}
|
223 |
VHbbCandidate getHZnnCandidate(const VHbbCandidate & in, bool & ok){
|
224 |
if (verbose_){
|
225 |
std::cout <<" getHZnnCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<<" met "<<in.V.mets.size()<<std::endl;
|
226 |
}
|
227 |
|
228 |
ok = false;
|
229 |
VHbbCandidate temp=in;
|
230 |
if (temp.V.mets.size()!=1) return in;
|
231 |
//always build a NuNu candidate, exclusion come from if/else series on the caller side
|
232 |
// this allow to still build candidates for mu+e and same sign dilept
|
233 |
// if (temp.V.muons.size()!=0) return in ;
|
234 |
// if (temp.V.electrons.size()!=0) return in ;
|
235 |
|
236 |
temp.V.p4 = temp.V.mets[0].p4;
|
237 |
if (verbose_) {
|
238 |
std::cout <<" debug met "<< temp.V.mets[0].metSig << " " << temp.V.mets[0].sumEt<< std::endl;
|
239 |
}
|
240 |
// if (temp.V.mets[0].metSig<5) return in;
|
241 |
if (temp.V.mets[0].p4.Pt()<80) return in;
|
242 |
// if (temp.H.p4.Pt()<150)return in;
|
243 |
// if (temp.H.firstJet().csv< 0.9) return in;
|
244 |
// if (temp.H.secondJet().csv<0.5) return in;
|
245 |
// if (deltaPhi(temp.V.p4.Phi(),temp.H.p4.Phi())<2.95) return in;
|
246 |
// if (temp.V.electrons.size()>0 || temp.V.muons.size()>0 ) return in;
|
247 |
// if (temp.additionalJets.size()>0) return in;
|
248 |
// if (std::Abs(deltaTheta) ????
|
249 |
|
250 |
ok = true;
|
251 |
return temp;
|
252 |
}
|
253 |
|
254 |
VHbbCandidate getHWmunCandidate(const VHbbCandidate & in, bool & ok , std::vector<unsigned int>& pos){
|
255 |
ok = false;
|
256 |
VHbbCandidate temp=in;
|
257 |
// require a muon and no electrons
|
258 |
if (temp.V.muons.size()!=1) return in ;
|
259 |
if (temp.V.electrons.size()!=0) return in ;
|
260 |
if (temp.V.mets.size()<1) return in ;
|
261 |
//
|
262 |
/*pT(W) > 150 GeV (pt(W) computed using lepton px,y and PF MET x and y components)
|
263 |
pT(H) > 150 GeV
|
264 |
best btag, CSV > 0.90
|
265 |
second-best btag, CSV > 0.50
|
266 |
Dphi(W,H) > 2.95
|
267 |
no additional isolated leptons (pT > 15 GeV)
|
268 |
|
269 |
same lepton definition as in the physics objects section
|
270 |
|
271 |
No additional ak5PFjets (pT > 30 GeV; |eta| < 2.4)
|
272 |
MET>35. for the electron BDT analysis
|
273 |
|cos(theta * )| (TBO)
|
274 |
color flow pull angle (TBO)
|
275 |
We don't cut on the transverse mass (for boosted objects cutting on the transverse mass introduces an inefficiency due to the angle between the MET and the lepton being close to 0.)
|
276 |
*/
|
277 |
|
278 |
temp.V.p4 = temp.V.muons[0].p4+temp.V.mets[0].p4;
|
279 |
temp.V.firstLepton=pos[0];
|
280 |
|
281 |
ok=true;
|
282 |
return temp;
|
283 |
}
|
284 |
|
285 |
VHbbCandidate getHWenCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
|
286 |
ok = false;
|
287 |
VHbbCandidate temp=in;
|
288 |
if (temp.V.electrons.size()!=1) return in ;
|
289 |
if (temp.V.muons.size()!=0) return in ;
|
290 |
if (temp.V.mets.size()<1) return in ;
|
291 |
//
|
292 |
/*pT(W) > 150 GeV (pt(W) computed using lepton px,y and PF MET x and y components)
|
293 |
pT(H) > 150 GeV
|
294 |
best btag, CSV > 0.90
|
295 |
second-best btag, CSV > 0.50
|
296 |
Dphi(W,H) > 2.95
|
297 |
no additional isolated leptons (pT > 15 GeV)
|
298 |
|
299 |
same lepton definition as in the physics objects section
|
300 |
|
301 |
No additional ak5PFjets (pT > 30 GeV; |eta| < 2.4)
|
302 |
MET>35. for the electron BDT analysis
|
303 |
|cos(theta * )| (TBO)
|
304 |
color flow pull angle (TBO)
|
305 |
We don't cut on the transverse mass (for boosted objects cutting on the transverse mass introduces an inefficiency due to the angle between the MET and the lepton being close to 0.)
|
306 |
*/
|
307 |
|
308 |
ok=true;
|
309 |
temp.V.firstLepton=pos[0];
|
310 |
temp.V.p4 = temp.V.electrons[0].p4+temp.V.mets[0].p4;
|
311 |
return temp;
|
312 |
}
|
313 |
|
314 |
public:
|
315 |
bool verbose_;
|
316 |
|
317 |
public:
|
318 |
static float getDeltaTheta( const VHbbEvent::SimpleJet & j1, const VHbbEvent::SimpleJet & j2 ) {
|
319 |
double deltaTheta = 1e10;
|
320 |
TLorentzVector pi(0,0,0,0);
|
321 |
TLorentzVector v_j1 = j1.chargedTracksFourMomentum;
|
322 |
TLorentzVector v_j2 = j2.chargedTracksFourMomentum;
|
323 |
|
324 |
if( v_j2.Mag() == 0
|
325 |
|| v_j1.Mag() == 0 )
|
326 |
return deltaTheta = 1e10;
|
327 |
|
328 |
//use j1 to calculate the pull vector
|
329 |
TVector2 t = j1.tVector;
|
330 |
|
331 |
if( t.Mod() == 0 )
|
332 |
return deltaTheta = 1e10;
|
333 |
|
334 |
Double_t dphi = v_j2.Phi()- v_j1.Phi();
|
335 |
if ( dphi > M_PI ) {
|
336 |
dphi -= 2.0*M_PI;
|
337 |
} else if ( dphi <= -M_PI ) {
|
338 |
dphi += 2.0*M_PI;
|
339 |
}
|
340 |
Double_t deltaeta = v_j2.Rapidity() - v_j1.Rapidity();
|
341 |
TVector2 BBdir( deltaeta, dphi );
|
342 |
|
343 |
deltaTheta = t.DeltaPhi(BBdir);
|
344 |
|
345 |
return deltaTheta;
|
346 |
|
347 |
}
|
348 |
|
349 |
float getHelicity(const VHbbEvent::SimpleJet& j, TVector3 boost) const {
|
350 |
double hel = 1e10;
|
351 |
TLorentzVector jet = j.p4;
|
352 |
jet.Boost( -boost );
|
353 |
hel = TMath::Cos( jet.Vect().Angle( boost ) );
|
354 |
return hel;
|
355 |
}
|
356 |
|
357 |
|
358 |
};
|
359 |
|
360 |
|
361 |
|
362 |
#endif
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|