ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidateTools.h
Revision: 1.13
Committed: Wed Mar 21 22:07:27 2012 UTC (13 years, 1 month ago) by sethzenz
Content type: text/plain
Branch: MAIN
CVS Tags: tauCandV42, hbbsubstructDev_11, hbbsubstructDev_10, hbbsubstructDev_9, hbbsubstructDev_8, hbbsubstructDev_7, hbbsubstructDev_6, hbbsubstructDev_5, hbbsubstructDev_4, hbbsubstructDev_3, hbbsubstructDev_2, hbbsubstructDev_1, hbbsubstructDev, EDMV42_Step2_V4a, EDMV42_Step2_V4, EDMV42_Step2_V3, EDMV42_Step2_V2, EDMV42_Step2_V1, EdmV42, EdmV41alpha1, EdmV40alpha1, EdmV40alpha, V21emuCand, EdmV33Jun12v2_consistent, Step2ForV33_v2, Step2ForV33_v1, EdmV33Jun12v2, EdmV33Jun12v1, EdmV33Jun12v0, Step2ForV32_v2, Step2ForV32_v1, Step2ForV32_v0, Step2ForV31_v0, EdmV32May24v0, EdmV31May21v1, EdmV31May17v0, May14thStep2, EdmV30Apr10, EdmV21Apr10v2, EdmV22May9, EdmV21Apr06, EdmV21Apr10, EdmV21Apr04, EdmV21Apr03, EdmV21Apr2, EdmV21Mar30
Branch point for: V42TauCandidate, hbbsubstructDevPostHCP, V21emuCandidate
Changes since 1.12: +42 -1 lines
Log Message:
additions for taus

File Contents

# User Rev Content
1 tboccali 1.1 #ifndef VHBBCANDIDATETOOLS_H
2     #define VHBBCANDIDATETOOLS_H
3    
4     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidate.h"
5    
6     #include <iostream>
7    
8 tboccali 1.7 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 tboccali 1.1 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 tboccali 1.9
36    
37 sethzenz 1.13 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 tboccali 1.9
80     VHbbCandidate getHZmumuCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
81 tboccali 1.1 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 tboccali 1.9
87 tboccali 1.7 //
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 tboccali 1.9
94     // beware: assumes already sorted!!!!
95    
96     // CompareJetPtMuons ptComparator;
97     // std::sort(muons_.begin(), muons_.end(), ptComparator);
98 tboccali 1.7 if (muons_[0].p4.Pt()<20 || muons_[1].p4.Pt()<20 ) return in;
99 tboccali 1.9
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 tboccali 1.7 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 tboccali 1.9
126 tboccali 1.7 // the same for electrons
127     std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
128 tboccali 1.9
129     // beware; assumes already sorted
130    
131     // CompareJetPtElectrons ptComparator2;
132     // std::sort(electrons_.begin(), electrons_.end(), ptComparator2);
133 tboccali 1.7 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 tboccali 1.9 //
140 tboccali 1.7 // consider all
141     //
142    
143 tboccali 1.1
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 tboccali 1.9
153     temp.V.firstLepton = pos[0];
154     temp.V.secondLepton = pos[selectMu2];
155     ok = true;
156 tboccali 1.1 return temp;
157     }
158 tboccali 1.9 VHbbCandidate getHZeeCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
159 tboccali 1.1 if (verbose_){
160 tboccali 1.7 std::cout <<" getHZeeCandidate input mu "<<in.V.electrons.size()<<" e "<<in.V.muons.size()<<std::endl;
161 tboccali 1.1 }
162     ok = false;
163     VHbbCandidate temp=in;
164 tboccali 1.9
165 tboccali 1.1 //
166 tboccali 1.7 // change: allow for additional leptons; by definition
167 tboccali 1.1 //
168 tboccali 1.7 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 tboccali 1.9
172     // beware assumes already sorted
173    
174     // CompareJetPtElectrons ptComparator;
175     // std::sort(electrons_.begin(), electrons_.end(), ptComparator);
176 tboccali 1.7 if (electrons_[0].p4.Pt()<20 || electrons_[1].p4.Pt()<20 ) return in;
177 tboccali 1.9 //
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 tboccali 1.7 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 tboccali 1.9
206     // beware assumes already sorted
207    
208     // CompareJetPtMuons ptComparator2;
209     // std::sort(muons_.begin(), muons_.end(), ptComparator2);
210 tboccali 1.7 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 tboccali 1.9
216     temp.V.firstLepton = pos[0];
217     temp.V.secondLepton = pos[selectE2];
218    
219 tboccali 1.7
220     ok = true;
221 tboccali 1.1 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 arizzi 1.10 //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 tboccali 1.1
236 tboccali 1.6 temp.V.p4 = temp.V.mets[0].p4;
237 tboccali 1.1 if (verbose_) {
238     std::cout <<" debug met "<< temp.V.mets[0].metSig << " " << temp.V.mets[0].sumEt<< std::endl;
239     }
240 arizzi 1.12 // if (temp.V.mets[0].metSig<5) return in;
241 tboccali 1.11 if (temp.V.mets[0].p4.Pt()<80) return in;
242 tboccali 1.6 // if (temp.H.p4.Pt()<150)return in;
243 tboccali 1.1 // if (temp.H.firstJet().csv< 0.9) return in;
244     // if (temp.H.secondJet().csv<0.5) return in;
245 tboccali 1.6 // if (deltaPhi(temp.V.p4.Phi(),temp.H.p4.Phi())<2.95) return in;
246 tboccali 1.1 // 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 tboccali 1.9 VHbbCandidate getHWmunCandidate(const VHbbCandidate & in, bool & ok , std::vector<unsigned int>& pos){
255 tboccali 1.1 ok = false;
256     VHbbCandidate temp=in;
257 tboccali 1.2 // require a muon and no electrons
258 tboccali 1.1 if (temp.V.muons.size()!=1) return in ;
259     if (temp.V.electrons.size()!=0) return in ;
260 tboccali 1.3 if (temp.V.mets.size()<1) return in ;
261 tboccali 1.1 //
262 tboccali 1.2 /*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 tboccali 1.6 temp.V.p4 = temp.V.muons[0].p4+temp.V.mets[0].p4;
279 tboccali 1.9 temp.V.firstLepton=pos[0];
280 tboccali 1.2
281     ok=true;
282 tboccali 1.3 return temp;
283 tboccali 1.1 }
284    
285 tboccali 1.9 VHbbCandidate getHWenCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
286 tboccali 1.1 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 tboccali 1.3 if (temp.V.mets.size()<1) return in ;
291 tboccali 1.1 //
292 tboccali 1.2 /*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 tboccali 1.9 temp.V.firstLepton=pos[0];
310 tboccali 1.6 temp.V.p4 = temp.V.electrons[0].p4+temp.V.mets[0].p4;
311 tboccali 1.3 return temp;
312 tboccali 1.1 }
313    
314     public:
315     bool verbose_;
316 tboccali 1.2
317     public:
318 tboccali 1.9 static float getDeltaTheta( const VHbbEvent::SimpleJet & j1, const VHbbEvent::SimpleJet & j2 ) {
319 tboccali 1.5 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 tboccali 1.4 float getHelicity(const VHbbEvent::SimpleJet& j, TVector3 boost) const {
350     double hel = 1e10;
351 tboccali 1.6 TLorentzVector jet = j.p4;
352 tboccali 1.4 jet.Boost( -boost );
353     hel = TMath::Cos( jet.Vect().Angle( boost ) );
354     return hel;
355     }
356    
357 tboccali 1.1
358     };
359    
360    
361    
362     #endif
363    
364    
365    
366    
367    
368