ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidateTools.h
Revision: 1.9
Committed: Fri Sep 9 08:05:27 2011 UTC (13 years, 7 months ago) by tboccali
Content type: text/plain
Branch: MAIN
CVS Tags: Sept13th2011
Changes since 1.8: +84 -25 lines
Log Message:
many small changes

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