ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidateTools.h
Revision: 1.15
Committed: Tue Mar 12 13:48:48 2013 UTC (12 years, 1 month ago) by msegala
Content type: text/plain
Branch: MAIN
Changes since 1.14: +2 -2 lines
Log Message:
Tau pt fix

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 msegala 1.15
60 sethzenz 1.13 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 arizzi 1.14 temp.V.firstLepton = 0;
154     temp.V.secondLepton = selectMu2;
155     temp.V.firstLeptonOrig = pos[0];
156     temp.V.secondLeptonOrig = pos[selectMu2];
157    
158 tboccali 1.9 ok = true;
159 tboccali 1.1 return temp;
160     }
161 tboccali 1.9 VHbbCandidate getHZeeCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
162 tboccali 1.1 if (verbose_){
163 tboccali 1.7 std::cout <<" getHZeeCandidate input mu "<<in.V.electrons.size()<<" e "<<in.V.muons.size()<<std::endl;
164 tboccali 1.1 }
165     ok = false;
166     VHbbCandidate temp=in;
167 tboccali 1.9
168 tboccali 1.1 //
169 tboccali 1.7 // change: allow for additional leptons; by definition
170 tboccali 1.1 //
171 tboccali 1.7 if (temp.V.electrons.size()<2) return in ;
172     // if (temp.V.electrons.size()!=0) return in ;
173     std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
174 tboccali 1.9
175     // beware assumes already sorted
176    
177     // CompareJetPtElectrons ptComparator;
178     // std::sort(electrons_.begin(), electrons_.end(), ptComparator);
179 tboccali 1.7 if (electrons_[0].p4.Pt()<20 || electrons_[1].p4.Pt()<20 ) return in;
180 tboccali 1.9 //
181     // now I need to ask also for the charge
182     //
183     int selectE2=1;
184    
185     if (electrons_[0].charge* electrons_[selectE2].charge > 0){
186     if (electrons_.size() ==2) return in;
187     //
188     // i need to find a proper pair
189     //
190    
191     for (unsigned int it=2; it< electrons_.size(); ++it){
192     if ( electrons_[it].charge * electrons_[0].charge < 0) {
193     selectE2 = it;
194     break;
195     }
196     if (selectE2 == 1) return in;
197     }
198     }
199     temp.V.p4 = electrons_[0].p4+electrons_[selectE2].p4;
200 tboccali 1.7 std::vector<VHbbEvent::ElectronInfo> electrons2_;
201     for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons_.begin(); it!= electrons_.end(); ++it){
202     if (it->p4.Pt()>20) electrons2_.push_back(*it);
203     }
204     temp.V.electrons = electrons2_;
205    
206     // the same for muonss
207     std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
208 tboccali 1.9
209     // beware assumes already sorted
210    
211     // CompareJetPtMuons ptComparator2;
212     // std::sort(muons_.begin(), muons_.end(), ptComparator2);
213 tboccali 1.7 std::vector<VHbbEvent::MuonInfo> muons2_;
214     for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons_.begin(); it!= muons_.end(); ++it){
215     if (it->p4.Pt()>20) muons2_.push_back(*it);
216     }
217     temp.V.muons = muons2_;
218 tboccali 1.9
219 arizzi 1.14 temp.V.firstLepton = 0;
220     temp.V.secondLepton = selectE2;
221     temp.V.firstLeptonOrig = pos[0];
222     temp.V.secondLeptonOrig = pos[selectE2];
223 tboccali 1.9
224 tboccali 1.7
225     ok = true;
226 tboccali 1.1 return temp;
227     }
228     VHbbCandidate getHZnnCandidate(const VHbbCandidate & in, bool & ok){
229     if (verbose_){
230     std::cout <<" getHZnnCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<<" met "<<in.V.mets.size()<<std::endl;
231     }
232    
233     ok = false;
234     VHbbCandidate temp=in;
235     if (temp.V.mets.size()!=1) return in;
236 arizzi 1.10 //always build a NuNu candidate, exclusion come from if/else series on the caller side
237     // this allow to still build candidates for mu+e and same sign dilept
238     // if (temp.V.muons.size()!=0) return in ;
239     // if (temp.V.electrons.size()!=0) return in ;
240 tboccali 1.1
241 tboccali 1.6 temp.V.p4 = temp.V.mets[0].p4;
242 tboccali 1.1 if (verbose_) {
243     std::cout <<" debug met "<< temp.V.mets[0].metSig << " " << temp.V.mets[0].sumEt<< std::endl;
244     }
245 arizzi 1.12 // if (temp.V.mets[0].metSig<5) return in;
246 tboccali 1.11 if (temp.V.mets[0].p4.Pt()<80) return in;
247 tboccali 1.6 // if (temp.H.p4.Pt()<150)return in;
248 tboccali 1.1 // if (temp.H.firstJet().csv< 0.9) return in;
249     // if (temp.H.secondJet().csv<0.5) return in;
250 tboccali 1.6 // if (deltaPhi(temp.V.p4.Phi(),temp.H.p4.Phi())<2.95) return in;
251 tboccali 1.1 // if (temp.V.electrons.size()>0 || temp.V.muons.size()>0 ) return in;
252     // if (temp.additionalJets.size()>0) return in;
253     // if (std::Abs(deltaTheta) ????
254    
255     ok = true;
256     return temp;
257     }
258    
259 tboccali 1.9 VHbbCandidate getHWmunCandidate(const VHbbCandidate & in, bool & ok , std::vector<unsigned int>& pos){
260 tboccali 1.1 ok = false;
261     VHbbCandidate temp=in;
262 tboccali 1.2 // require a muon and no electrons
263 tboccali 1.1 if (temp.V.muons.size()!=1) return in ;
264     if (temp.V.electrons.size()!=0) return in ;
265 tboccali 1.3 if (temp.V.mets.size()<1) return in ;
266 tboccali 1.1 //
267 tboccali 1.2 /*pT(W) > 150 GeV (pt(W) computed using lepton px,y and PF MET x and y components)
268     pT(H) > 150 GeV
269     best btag, CSV > 0.90
270     second-best btag, CSV > 0.50
271     Dphi(W,H) > 2.95
272     no additional isolated leptons (pT > 15 GeV)
273    
274     same lepton definition as in the physics objects section
275    
276     No additional ak5PFjets (pT > 30 GeV; |eta| < 2.4)
277     MET>35. for the electron BDT analysis
278     |cos(theta * )| (TBO)
279     color flow pull angle (TBO)
280     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.)
281     */
282    
283 tboccali 1.6 temp.V.p4 = temp.V.muons[0].p4+temp.V.mets[0].p4;
284 arizzi 1.14 temp.V.firstLeptonOrig=pos[0];
285 msegala 1.15
286 tboccali 1.2 ok=true;
287 tboccali 1.3 return temp;
288 tboccali 1.1 }
289    
290 tboccali 1.9 VHbbCandidate getHWenCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
291 tboccali 1.1 ok = false;
292     VHbbCandidate temp=in;
293     if (temp.V.electrons.size()!=1) return in ;
294     if (temp.V.muons.size()!=0) return in ;
295 tboccali 1.3 if (temp.V.mets.size()<1) return in ;
296 tboccali 1.1 //
297 tboccali 1.2 /*pT(W) > 150 GeV (pt(W) computed using lepton px,y and PF MET x and y components)
298     pT(H) > 150 GeV
299     best btag, CSV > 0.90
300     second-best btag, CSV > 0.50
301     Dphi(W,H) > 2.95
302     no additional isolated leptons (pT > 15 GeV)
303    
304     same lepton definition as in the physics objects section
305    
306     No additional ak5PFjets (pT > 30 GeV; |eta| < 2.4)
307     MET>35. for the electron BDT analysis
308     |cos(theta * )| (TBO)
309     color flow pull angle (TBO)
310     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.)
311     */
312    
313     ok=true;
314 arizzi 1.14 temp.V.firstLeptonOrig=pos[0];
315 tboccali 1.6 temp.V.p4 = temp.V.electrons[0].p4+temp.V.mets[0].p4;
316 tboccali 1.3 return temp;
317 tboccali 1.1 }
318    
319     public:
320     bool verbose_;
321 tboccali 1.2
322     public:
323 tboccali 1.9 static float getDeltaTheta( const VHbbEvent::SimpleJet & j1, const VHbbEvent::SimpleJet & j2 ) {
324 tboccali 1.5 double deltaTheta = 1e10;
325     TLorentzVector pi(0,0,0,0);
326     TLorentzVector v_j1 = j1.chargedTracksFourMomentum;
327     TLorentzVector v_j2 = j2.chargedTracksFourMomentum;
328    
329     if( v_j2.Mag() == 0
330     || v_j1.Mag() == 0 )
331     return deltaTheta = 1e10;
332    
333     //use j1 to calculate the pull vector
334     TVector2 t = j1.tVector;
335    
336     if( t.Mod() == 0 )
337     return deltaTheta = 1e10;
338    
339     Double_t dphi = v_j2.Phi()- v_j1.Phi();
340     if ( dphi > M_PI ) {
341     dphi -= 2.0*M_PI;
342     } else if ( dphi <= -M_PI ) {
343     dphi += 2.0*M_PI;
344     }
345     Double_t deltaeta = v_j2.Rapidity() - v_j1.Rapidity();
346     TVector2 BBdir( deltaeta, dphi );
347    
348     deltaTheta = t.DeltaPhi(BBdir);
349    
350     return deltaTheta;
351    
352     }
353    
354 tboccali 1.4 float getHelicity(const VHbbEvent::SimpleJet& j, TVector3 boost) const {
355     double hel = 1e10;
356 tboccali 1.6 TLorentzVector jet = j.p4;
357 tboccali 1.4 jet.Boost( -boost );
358     hel = TMath::Cos( jet.Vect().Angle( boost ) );
359     return hel;
360     }
361    
362 tboccali 1.1
363     };
364    
365    
366    
367     #endif
368    
369    
370    
371    
372    
373