ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidateTools.h
Revision: 1.16
Committed: Fri Apr 12 23:34:29 2013 UTC (12 years ago) by sdas
Content type: text/plain
Branch: MAIN
CVS Tags: EDMV42_Step2_V8, EDMV42_Step2_V7, HEAD
Changes since 1.15: +7 -0 lines
Log Message:
Added functionality for retaining H(bb)H(bb) events. Configuration ntuple.py file needs isZbbHbb switch set to True if you intend to keep these events, not discard them like most VH(bb) analyses.

File Contents

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