ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidateTools.h
Revision: 1.13.6.2
Committed: Thu May 2 17:04:24 2013 UTC (12 years ago) by wilken
Content type: text/plain
Branch: V42TauCandidate
Changes since 1.13.6.1: +106 -0 lines
Log Message:
same sign background

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 wilken 1.13.6.1 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     std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
43     std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
44     std::vector<VHbbEvent::TauInfo> taus_ = temp.V.taus;
45    
46     int Nelectrons = 0;
47     for(unsigned int j = 0; j<temp.V.electrons.size();j++){
48     if (electrons_[j].p4.Pt()>20) Nelectrons++;
49     }
50    
51     if (temp.V.muons.size() < 1) return in;
52     if (temp.V.taus.size() < 1) return in;
53    
54     // only count muons with pT > 15.
55     std::vector<VHbbEvent::MuonInfo> muons2_;
56     for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons_.begin(); it!= muons_.end(); ++it){
57     if (it->p4.Pt()>15) muons2_.push_back(*it);
58     }
59    
60     // only consider taus that have opposite charge to the leading muon
61     std::vector<VHbbEvent::TauInfo> taus2_;
62     for (std::vector<VHbbEvent::TauInfo>::const_iterator it = taus_.begin(); it!= taus_.end(); ++it){
63     if ( (*it).charge * muons_[0].charge < 0) taus2_.push_back(*it);
64     }
65    
66     temp.V.muons = muons2_;
67     temp.V.taus = taus2_;
68     ////////
69     ////////
70    
71    
72     // Require exactly one tau and muon, and no electrons
73     ////if (temp.V.taus.size()<1) return in;
74     if (temp.V.taus.size()!=1) return in;
75     if (temp.V.muons.size()!=1) return in ;
76     if (Nelectrons!=0) return in ;
77    
78     temp.V.p4 = temp.V.taus[0].p4 + temp.V.muons[0].p4;
79     temp.V.firstLepton = muPos[0];
80     temp.V.secondLepton = tauPos[0];
81    
82     ok = true;
83     return temp;
84    
85     }
86     VHbbCandidate getHZtaueCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& elePos, std::vector<unsigned int>& tauPos){
87     if (verbose_) std::cout <<" getHZtaueCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<< " tau " << in.V.taus.size() << std::endl;
88     ok = false;
89     VHbbCandidate temp=in;
90     // Require exactly one tau and muon, and no electrons
91     std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
92     std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
93     std::vector<VHbbEvent::TauInfo> taus_ = temp.V.taus;
94    
95     int Nmuons = 0;
96     for(unsigned int j = 0; j<temp.V.muons.size();j++){
97     if (muons_[j].p4.Pt()>20) Nmuons++;
98     }
99    
100     if (temp.V.electrons.size() < 1) return in;
101     if (temp.V.taus.size() < 1) return in;
102    
103     // only count muons with pT > 15.
104     std::vector<VHbbEvent::ElectronInfo> electrons2_;
105     for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons_.begin(); it!= electrons_.end(); ++it){
106     if (it->p4.Pt()>15) electrons2_.push_back(*it);
107     }
108    
109     // only consider taus that have opposite charge to the leading electron
110     std::vector<VHbbEvent::TauInfo> taus2_;
111     for (std::vector<VHbbEvent::TauInfo>::const_iterator it = taus_.begin(); it!= taus_.end(); ++it){
112     if ( (*it).charge * electrons_[0].charge < 0) taus2_.push_back(*it);
113     }
114    
115     temp.V.electrons = electrons2_;
116     temp.V.taus = taus2_;
117     ////////
118     ////////
119    
120    
121     // Require exactly one tau and muon, and no electrons
122     if (temp.V.taus.size()<1) return in;
123     //if (temp.V.taus.size()!=1) return in;
124     if (temp.V.electrons.size()!=1) return in ;
125     if (Nmuons!=0) return in ;
126    
127     temp.V.p4 = temp.V.taus[0].p4 + temp.V.electrons[0].p4;
128     temp.V.firstLepton = elePos[0];
129     temp.V.secondLepton = tauPos[0];
130    
131     ok = true;
132     return temp;
133    
134     }
135     VHbbCandidate getHZtautauCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
136     if (verbose_) std::cout <<" getHZtautauCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<< " tau " << in.V.taus.size() << std::endl;
137     ok = false;
138     VHbbCandidate temp=in;
139     // Require exactly one tau and muon, and no electrons
140     std::vector<VHbbEvent::MuonInfo> Nmuons_ = temp.V.muons;
141     std::vector<VHbbEvent::ElectronInfo> Nelectrons_ = temp.V.electrons;
142     int Nmuons = 0;
143     int Nelectrons = 0;
144     for(unsigned int i = 0; i<temp.V.muons.size();i++){
145     if (Nmuons_[i].p4.Pt()>20) Nmuons++;
146     }
147     for(unsigned int j = 0; j<temp.V.electrons.size();j++){
148     if (Nelectrons_[j].p4.Pt()>20) Nelectrons++;
149     }
150    
151     if (temp.V.taus.size()<2) return in;
152     if (Nmuons!=0) return in ;
153     if (Nelectrons!=0) return in ;
154    
155    
156     std::vector<VHbbEvent::TauInfo> taus_ = temp.V.taus;
157     if (taus_[0].p4.Pt() < 20 || taus_[1].p4.Pt()<20) return in;
158     if (taus_.size()==2){
159     temp.V.p4 = temp.V.taus[0].p4 + temp.V.taus[1].p4;
160     temp.V.firstLepton = pos[0];
161     temp.V.secondLepton = pos[1];
162    
163     ok = true;
164     return temp;
165     }
166     int selectTau2=1;
167     for (unsigned int it=2; it< taus_.size(); ++it){
168     if (taus_[0].charge*taus_[it].charge < 0){
169     selectTau2 = it;
170     break;
171     }
172     }
173     std::vector<VHbbEvent::TauInfo> taus2_;
174     for (std::vector<VHbbEvent::TauInfo>::const_iterator it = taus_.begin(); it!= taus_.end(); ++it){
175     if (it->p4.Pt()>20) taus2_.push_back(*it);
176     }
177     temp.V.taus = taus2_;
178    
179     temp.V.p4 = temp.V.taus[0].p4 + temp.V.taus[selectTau2].p4;
180     temp.V.firstLepton = pos[0];
181     temp.V.secondLepton = pos[selectTau2];
182    
183     ok = true;
184     return temp;
185    
186     }
187     VHbbCandidate getHWtaunCandidate(const VHbbCandidate & in, bool & ok , std::vector<unsigned int>& pos){
188 sethzenz 1.13
189     if (verbose_){
190     std::cout <<" getHWtaunCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<< " tau " << in.V.taus.size() << std::endl;
191     std::cout << " pos.size()=" << pos.size() << std::endl;
192     }
193    
194     ok = false;
195     VHbbCandidate temp=in;
196     // require a tau and no electrons or muons
197 wilken 1.13.6.1 std::vector<VHbbEvent::MuonInfo> Nmuons_ = temp.V.muons;
198     std::vector<VHbbEvent::ElectronInfo> Nelectrons_ = temp.V.electrons;
199     int Nmuons = 0;
200     int Nelectrons = 0;
201     for(unsigned int i = 0; i<temp.V.muons.size();i++){
202     if (Nmuons_[i].p4.Pt()>20) Nmuons++;
203     }
204     for(unsigned int j = 0; j<temp.V.electrons.size();j++){
205     if (Nelectrons_[j].p4.Pt()>20) Nelectrons++;
206     }
207    
208 sethzenz 1.13 if (temp.V.taus.size()!=1) return in;
209 wilken 1.13.6.1 if (Nmuons!=0) return in ;
210     if (Nelectrons!=0) return in ;
211 sethzenz 1.13 if (temp.V.mets.size()<1) return in ;
212     temp.V.p4 = temp.V.taus[0].p4+temp.V.mets[0].p4;
213     temp.V.firstLepton=pos[0];
214    
215     if (verbose_){
216     std::cout << "Done with getHWtaunCandidate" << std::endl;
217     }
218    
219     ok=true;
220     return temp;
221     }
222    
223 wilken 1.13.6.1 VHbbCandidate getHZemuCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& elePos, std::vector<unsigned int>& muPos){
224     if (verbose_){
225     std::cout <<" getHZemuCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<<std::endl;
226     }
227     ok = false;
228     VHbbCandidate temp=in;
229    
230     //
231     // change: allow for additional leptons; by definition
232     //
233     if (temp.V.muons.size()<1) return in ;
234     if (temp.V.electrons.size()<1) return in ;
235     if (temp.V.mets.size()<1) return in;
236    
237     // if (temp.V.electrons.size()!=0) return in ;
238     std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
239     std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
240    
241     //orthogonality with Zmumu and Zee
242     if (temp.V.muons.size()>1){
243     if (muons_[0].p4.Pt()>20 && muons_[1].p4.Pt()>20 && (muons_[0].charge*muons_[1].charge)< 0)return in;
244     }
245     if (temp.V.electrons.size()>1){
246     if (electrons_[0].p4.Pt()>20 && electrons_[1].p4.Pt()>20&&(electrons_[0].charge*electrons_[1].charge)< 0)return in;
247     }
248    
249    
250     // beware: assumes already sorted!!!!
251    
252     // CompareJetPtMuons ptComparator;
253     // std::sort(muons_.begin(), muons_.end(), ptComparator);
254     if (muons_[0].p4.Pt()<10 || electrons_[0].p4.Pt()<10 ) return in;
255    
256     //
257     // now I need to ask also for the charge
258     //
259     int tauEle=-99, tauMu =-99;
260     float Tau_pT = -99.99;
261     int tmpEle =0, tmpMu =0;
262     int N_pairs = 0;
263     //
264     // i need to find a proper pair
265     //
266    
267     for (unsigned int ele_it=0; ele_it< electrons_.size(); ++ele_it){
268     for (unsigned int mu_it=0; mu_it< muons_.size(); ++mu_it){
269     if (muons_[mu_it].p4.Pt()>10 && electrons_[ele_it].p4.Pt()>10 ){
270     if ( electrons_[ele_it].charge * muons_[mu_it].charge < 0) {
271     tmpEle = ele_it;
272     tmpMu = mu_it;
273     if (N_pairs ==0){
274     tauEle = ele_it;
275     tauMu = mu_it;
276     }
277     N_pairs++;
278     temp.V.p4 = muons_[mu_it].p4+electrons_[ele_it].p4;
279     if (temp.V.p4.Pt() > Tau_pT) {
280     tauEle = ele_it;
281     tauMu = mu_it;
282     Tau_pT = temp.V.p4.Pt();
283     }
284     } // if opposite charge
285     }//leption pt requirement
286     } // muon for loop
287     } //electron for loop
288     if (tauEle==-99) return in;
289     if (N_pairs>1) std::cout <<" Number emu pairs: "<<N_pairs<<std::endl;
290    
291    
292     temp.V.p4 = muons_[tauMu].p4+electrons_[tauEle].p4;
293     std::vector<VHbbEvent::MuonInfo> muons2_;
294     for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons_.begin(); it!= muons_.end(); ++it){
295     if (it->p4.Pt()>10) muons2_.push_back(*it);
296     }
297     temp.V.muons = muons2_;
298    
299     // beware; assumes already sorted
300    
301     // CompareJetPtElectrons ptComparator2;
302     // std::sort(electrons_.begin(), electrons_.end(), ptComparator2);
303     std::vector<VHbbEvent::ElectronInfo> electrons2_;
304     for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons_.begin(); it!= electrons_.end(); ++it){
305     if (it->p4.Pt()>10) electrons2_.push_back(*it);
306     }
307     temp.V.electrons = electrons2_;
308    
309     //
310     // consider all
311     //
312    
313    
314     // if (temp.V.Pt()<150 ) return in;
315     // if (temp.H.Pt()<150) return in;
316     // if (temp.H.firstJet().csv< 0.9) return in;
317     // if (temp.H.secondJet().csv<0.5) return in;
318     // if (deltaPhi(temp.V.Phi(),temp.H.Phi())<2.7) return in;
319     // if (temp.V.FourMomentum.Mass()<75 || temp.V.FourMomentum.Mass()>105) return in;
320     // if (temp.additionalJets.size()>0) return in;
321     // if (std::Abs(deltaTheta) ????
322    
323     temp.V.firstLepton = elePos[tauEle];
324     temp.V.secondLepton = muPos[tauMu];
325     ok = true;
326    
327     return temp;
328     }
329    
330 wilken 1.13.6.2 VHbbCandidate getSameSignCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& elePos, std::vector<unsigned int>& muPos){
331     if (verbose_){
332     std::cout <<" getSameSignCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<<std::endl;
333     }
334     ok = false;
335     VHbbCandidate temp=in;
336    
337     //
338     // change: allow for additional leptons; by definition
339     //
340     if (temp.V.muons.size()<1) return in ;
341     if (temp.V.electrons.size()<1) return in ;
342     if (temp.V.mets.size()<1) return in;
343    
344     // if (temp.V.electrons.size()!=0) return in ;
345     std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
346     std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
347    
348     //orthogonality with Zmumu and Zee
349     if (temp.V.muons.size()>1){
350     if (muons_[0].p4.Pt()>20 && muons_[1].p4.Pt()>20 && (muons_[0].charge*muons_[1].charge)< 0)return in;
351     }
352     if (temp.V.electrons.size()>1){
353     if (electrons_[0].p4.Pt()>20 && electrons_[1].p4.Pt()>20&&(electrons_[0].charge*electrons_[1].charge)< 0)return in;
354     }
355    
356    
357     // beware: assumes already sorted!!!!
358    
359     // CompareJetPtMuons ptComparator;
360     // std::sort(muons_.begin(), muons_.end(), ptComparator);
361     if (muons_[0].p4.Pt()<10 || electrons_[0].p4.Pt()<10 ) return in;
362    
363     //
364     // now I need to ask also for the charge
365     //
366     int tauEle=-99, tauMu =-99;
367     float Tau_pT = -99.99;
368     int tmpEle =0, tmpMu =0;
369     int N_pairs = 0;
370     //
371     // i need to find a proper pair
372     //
373    
374     for (unsigned int ele_it=0; ele_it< electrons_.size(); ++ele_it){
375     for (unsigned int mu_it=0; mu_it< muons_.size(); ++mu_it){
376     if (muons_[mu_it].p4.Pt()>10 && electrons_[ele_it].p4.Pt()>10 ){
377     if ( electrons_[ele_it].charge * muons_[mu_it].charge > 0) {
378     tmpEle = ele_it;
379     tmpMu = mu_it;
380     if (N_pairs ==0){
381     tauEle = ele_it;
382     tauMu = mu_it;
383     }
384     N_pairs++;
385     temp.V.p4 = muons_[mu_it].p4+electrons_[ele_it].p4;
386     if (temp.V.p4.Pt() > Tau_pT) {
387     tauEle = ele_it;
388     tauMu = mu_it;
389     Tau_pT = temp.V.p4.Pt();
390     }
391     } // if opposite charge
392     }//leption pt requirement
393     } // muon for loop
394     } //electron for loop
395     if (tauEle==-99) return in;
396     if (N_pairs>1) std::cout <<" Number SameSign pairs: "<<N_pairs<<std::endl;
397    
398    
399     temp.V.p4 = muons_[tauMu].p4+electrons_[tauEle].p4;
400     std::vector<VHbbEvent::MuonInfo> muons2_;
401     for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons_.begin(); it!= muons_.end(); ++it){
402     if (it->p4.Pt()>10) muons2_.push_back(*it);
403     }
404     temp.V.muons = muons2_;
405    
406     // beware; assumes already sorted
407    
408     // CompareJetPtElectrons ptComparator2;
409     // std::sort(electrons_.begin(), electrons_.end(), ptComparator2);
410     std::vector<VHbbEvent::ElectronInfo> electrons2_;
411     for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons_.begin(); it!= electrons_.end(); ++it){
412     if (it->p4.Pt()>10) electrons2_.push_back(*it);
413     }
414     temp.V.electrons = electrons2_;
415    
416     //
417     // consider all
418     //
419    
420    
421     // if (temp.V.Pt()<150 ) return in;
422     // if (temp.H.Pt()<150) return in;
423     // if (temp.H.firstJet().csv< 0.9) return in;
424     // if (temp.H.secondJet().csv<0.5) return in;
425     // if (deltaPhi(temp.V.Phi(),temp.H.Phi())<2.7) return in;
426     // if (temp.V.FourMomentum.Mass()<75 || temp.V.FourMomentum.Mass()>105) return in;
427     // if (temp.additionalJets.size()>0) return in;
428     // if (std::Abs(deltaTheta) ????
429    
430     temp.V.firstLepton = elePos[tauEle];
431     temp.V.secondLepton = muPos[tauMu];
432     ok = true;
433    
434     return temp;
435     }
436 sethzenz 1.13
437 tboccali 1.9
438     VHbbCandidate getHZmumuCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
439 tboccali 1.1 if (verbose_){
440     std::cout <<" getHZmumuCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<<std::endl;
441     }
442     ok = false;
443     VHbbCandidate temp=in;
444 tboccali 1.9
445 tboccali 1.7 //
446     // change: allow for additional leptons; by definition
447     //
448 wilken 1.13.6.1 std::vector<VHbbEvent::MuonInfo> Nmuons_ = temp.V.muons;
449     std::vector<VHbbEvent::ElectronInfo> Nelectrons_ = temp.V.electrons;
450     int Nmuons = 0;
451     int Nelectrons = 0;
452     for(unsigned int i = 0; i<temp.V.muons.size();i++){
453     if (Nmuons_[i].p4.Pt()>20) Nmuons++;
454     }
455     for(unsigned int j = 0; j<temp.V.electrons.size();j++){
456     if (Nelectrons_[j].p4.Pt()>20) Nelectrons++;
457     }
458    
459     if (Nmuons<2) return in ;
460 tboccali 1.7 // if (temp.V.electrons.size()!=0) return in ;
461     std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
462 tboccali 1.9
463     // beware: assumes already sorted!!!!
464    
465     // CompareJetPtMuons ptComparator;
466     // std::sort(muons_.begin(), muons_.end(), ptComparator);
467 tboccali 1.7 if (muons_[0].p4.Pt()<20 || muons_[1].p4.Pt()<20 ) return in;
468 tboccali 1.9
469     //
470     // now I need to ask also for the charge
471     //
472     int selectMu2=1;
473    
474     if (muons_[0].charge* muons_[selectMu2].charge > 0){
475     if (muons_.size() ==2) return in;
476     //
477     // i need to find a proper pair
478     //
479    
480     for (unsigned int it=2; it< muons_.size(); ++it){
481     if ( muons_[it].charge * muons_[0].charge < 0) {
482 wilken 1.13.6.1 if (muons_[it].p4.Pt()>20) selectMu2 = it;
483 tboccali 1.9 break;
484     }
485     if (selectMu2 == 1) return in;
486     }
487     }
488     temp.V.p4 = muons_[0].p4+muons_[selectMu2].p4;
489 tboccali 1.7 std::vector<VHbbEvent::MuonInfo> muons2_;
490     for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons_.begin(); it!= muons_.end(); ++it){
491     if (it->p4.Pt()>20) muons2_.push_back(*it);
492     }
493     temp.V.muons = muons2_;
494 tboccali 1.9
495 tboccali 1.7 // the same for electrons
496     std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
497 tboccali 1.9
498     // beware; assumes already sorted
499    
500     // CompareJetPtElectrons ptComparator2;
501     // std::sort(electrons_.begin(), electrons_.end(), ptComparator2);
502 tboccali 1.7 std::vector<VHbbEvent::ElectronInfo> electrons2_;
503     for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons_.begin(); it!= electrons_.end(); ++it){
504     if (it->p4.Pt()>20) electrons2_.push_back(*it);
505     }
506     temp.V.electrons = electrons2_;
507    
508 tboccali 1.9 //
509 tboccali 1.7 // consider all
510     //
511    
512 tboccali 1.1
513     // if (temp.V.Pt()<150 ) return in;
514     // if (temp.H.Pt()<150) return in;
515     // if (temp.H.firstJet().csv< 0.9) return in;
516     // if (temp.H.secondJet().csv<0.5) return in;
517     // if (deltaPhi(temp.V.Phi(),temp.H.Phi())<2.7) return in;
518     // if (temp.V.FourMomentum.Mass()<75 || temp.V.FourMomentum.Mass()>105) return in;
519     // if (temp.additionalJets.size()>0) return in;
520     // if (std::Abs(deltaTheta) ????
521 tboccali 1.9
522     temp.V.firstLepton = pos[0];
523     temp.V.secondLepton = pos[selectMu2];
524     ok = true;
525 tboccali 1.1 return temp;
526     }
527 tboccali 1.9 VHbbCandidate getHZeeCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
528 tboccali 1.1 if (verbose_){
529 wilken 1.13.6.1 std::cout <<" getHZeeCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<<std::endl;
530 tboccali 1.1 }
531     ok = false;
532     VHbbCandidate temp=in;
533 tboccali 1.9
534 tboccali 1.1 //
535 tboccali 1.7 // change: allow for additional leptons; by definition
536 tboccali 1.1 //
537 wilken 1.13.6.1 std::vector<VHbbEvent::MuonInfo> Nmuons_ = temp.V.muons;
538     std::vector<VHbbEvent::ElectronInfo> Nelectrons_ = temp.V.electrons;
539     int Nmuons = 0;
540     int Nelectrons = 0;
541     for(unsigned int i = 0; i<temp.V.muons.size();i++){
542     if (Nmuons_[i].p4.Pt()>20) Nmuons++;
543     }
544     for(unsigned int j = 0; j<temp.V.electrons.size();j++){
545     if (Nelectrons_[j].p4.Pt()>20) Nelectrons++;
546     }
547    
548     if (Nelectrons<2) return in ;
549 tboccali 1.7 // if (temp.V.electrons.size()!=0) return in ;
550     std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
551 tboccali 1.9
552     // beware assumes already sorted
553    
554     // CompareJetPtElectrons ptComparator;
555     // std::sort(electrons_.begin(), electrons_.end(), ptComparator);
556 tboccali 1.7 if (electrons_[0].p4.Pt()<20 || electrons_[1].p4.Pt()<20 ) return in;
557 tboccali 1.9 //
558     // now I need to ask also for the charge
559     //
560     int selectE2=1;
561    
562     if (electrons_[0].charge* electrons_[selectE2].charge > 0){
563     if (electrons_.size() ==2) return in;
564     //
565     // i need to find a proper pair
566     //
567    
568     for (unsigned int it=2; it< electrons_.size(); ++it){
569     if ( electrons_[it].charge * electrons_[0].charge < 0) {
570 wilken 1.13.6.1 if (electrons_[it].p4.Pt()>20) selectE2 = it;
571 tboccali 1.9 break;
572     }
573     if (selectE2 == 1) return in;
574     }
575     }
576     temp.V.p4 = electrons_[0].p4+electrons_[selectE2].p4;
577 tboccali 1.7 std::vector<VHbbEvent::ElectronInfo> electrons2_;
578     for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons_.begin(); it!= electrons_.end(); ++it){
579     if (it->p4.Pt()>20) electrons2_.push_back(*it);
580     }
581     temp.V.electrons = electrons2_;
582    
583     // the same for muonss
584     std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
585 tboccali 1.9
586     // beware assumes already sorted
587    
588     // CompareJetPtMuons ptComparator2;
589     // std::sort(muons_.begin(), muons_.end(), ptComparator2);
590 tboccali 1.7 std::vector<VHbbEvent::MuonInfo> muons2_;
591     for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons_.begin(); it!= muons_.end(); ++it){
592     if (it->p4.Pt()>20) muons2_.push_back(*it);
593     }
594     temp.V.muons = muons2_;
595 tboccali 1.9
596     temp.V.firstLepton = pos[0];
597     temp.V.secondLepton = pos[selectE2];
598    
599 tboccali 1.7
600     ok = true;
601 tboccali 1.1 return temp;
602     }
603     VHbbCandidate getHZnnCandidate(const VHbbCandidate & in, bool & ok){
604     if (verbose_){
605     std::cout <<" getHZnnCandidate input mu "<<in.V.muons.size()<<" e "<<in.V.electrons.size()<<" met "<<in.V.mets.size()<<std::endl;
606     }
607    
608     ok = false;
609     VHbbCandidate temp=in;
610     if (temp.V.mets.size()!=1) return in;
611 arizzi 1.10 //always build a NuNu candidate, exclusion come from if/else series on the caller side
612     // this allow to still build candidates for mu+e and same sign dilept
613     // if (temp.V.muons.size()!=0) return in ;
614     // if (temp.V.electrons.size()!=0) return in ;
615 tboccali 1.1
616 tboccali 1.6 temp.V.p4 = temp.V.mets[0].p4;
617 tboccali 1.1 if (verbose_) {
618     std::cout <<" debug met "<< temp.V.mets[0].metSig << " " << temp.V.mets[0].sumEt<< std::endl;
619     }
620 arizzi 1.12 // if (temp.V.mets[0].metSig<5) return in;
621 tboccali 1.11 if (temp.V.mets[0].p4.Pt()<80) return in;
622 tboccali 1.6 // if (temp.H.p4.Pt()<150)return in;
623 tboccali 1.1 // if (temp.H.firstJet().csv< 0.9) return in;
624     // if (temp.H.secondJet().csv<0.5) return in;
625 tboccali 1.6 // if (deltaPhi(temp.V.p4.Phi(),temp.H.p4.Phi())<2.95) return in;
626 tboccali 1.1 // if (temp.V.electrons.size()>0 || temp.V.muons.size()>0 ) return in;
627     // if (temp.additionalJets.size()>0) return in;
628     // if (std::Abs(deltaTheta) ????
629    
630     ok = true;
631     return temp;
632     }
633    
634 tboccali 1.9 VHbbCandidate getHWmunCandidate(const VHbbCandidate & in, bool & ok , std::vector<unsigned int>& pos){
635 tboccali 1.1 ok = false;
636     VHbbCandidate temp=in;
637 tboccali 1.2 // require a muon and no electrons
638 wilken 1.13.6.1 std::vector<VHbbEvent::MuonInfo> Nmuons_ = temp.V.muons;
639     std::vector<VHbbEvent::ElectronInfo> Nelectrons_ = temp.V.electrons;
640     int Nmuons = 0;
641     int Nelectrons = 0;
642     int position = 0;
643     for(unsigned int i = 0; i<temp.V.muons.size();i++){
644     if (Nmuons_[i].p4.Pt()>20) {
645     Nmuons++;
646     position = i;
647     } }
648     for(unsigned int j = 0; j<temp.V.electrons.size();j++){
649     if (Nelectrons_[j].p4.Pt()>20) Nelectrons++;
650     }
651    
652     if (Nmuons!=1) return in ;
653     if (Nelectrons!=0) return in ;
654 tboccali 1.3 if (temp.V.mets.size()<1) return in ;
655 wilken 1.13.6.1 std::vector<VHbbEvent::MuonInfo> muons_ = temp.V.muons;
656     if (muons_[position].p4.Pt()<20) return in;
657 tboccali 1.1 //
658 tboccali 1.2 /*pT(W) > 150 GeV (pt(W) computed using lepton px,y and PF MET x and y components)
659     pT(H) > 150 GeV
660     best btag, CSV > 0.90
661     second-best btag, CSV > 0.50
662     Dphi(W,H) > 2.95
663     no additional isolated leptons (pT > 15 GeV)
664    
665     same lepton definition as in the physics objects section
666    
667     No additional ak5PFjets (pT > 30 GeV; |eta| < 2.4)
668     MET>35. for the electron BDT analysis
669     |cos(theta * )| (TBO)
670     color flow pull angle (TBO)
671     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.)
672     */
673    
674 wilken 1.13.6.1 temp.V.p4 = temp.V.muons[position].p4+temp.V.mets[0].p4;
675 tboccali 1.9 temp.V.firstLepton=pos[0];
676 tboccali 1.2
677     ok=true;
678 tboccali 1.3 return temp;
679 tboccali 1.1 }
680    
681 tboccali 1.9 VHbbCandidate getHWenCandidate(const VHbbCandidate & in, bool & ok, std::vector<unsigned int>& pos){
682 tboccali 1.1 ok = false;
683     VHbbCandidate temp=in;
684 wilken 1.13.6.1 std::vector<VHbbEvent::MuonInfo> Nmuons_ = temp.V.muons;
685     std::vector<VHbbEvent::ElectronInfo> Nelectrons_ = temp.V.electrons;
686     int Nmuons = 0;
687     int Nelectrons = 0;
688     int position = 0;
689     for(unsigned int i = 0; i<temp.V.muons.size();i++){
690     if (Nmuons_[i].p4.Pt()>20) Nmuons++;
691     }
692     for(unsigned int j = 0; j<temp.V.electrons.size();j++){
693     if (Nelectrons_[j].p4.Pt()>20) {
694     Nelectrons++;
695     position = j;
696     } }
697    
698     if (Nelectrons!=1) return in ;
699     if (Nmuons!=0) return in ;
700 tboccali 1.3 if (temp.V.mets.size()<1) return in ;
701 wilken 1.13.6.1 std::vector<VHbbEvent::ElectronInfo> electrons_ = temp.V.electrons;
702     if (electrons_[position].p4.Pt()<20) return in;
703 tboccali 1.1 //
704 tboccali 1.2 /*pT(W) > 150 GeV (pt(W) computed using lepton px,y and PF MET x and y components)
705     pT(H) > 150 GeV
706     best btag, CSV > 0.90
707     second-best btag, CSV > 0.50
708     Dphi(W,H) > 2.95
709     no additional isolated leptons (pT > 15 GeV)
710    
711     same lepton definition as in the physics objects section
712    
713     No additional ak5PFjets (pT > 30 GeV; |eta| < 2.4)
714     MET>35. for the electron BDT analysis
715     |cos(theta * )| (TBO)
716     color flow pull angle (TBO)
717     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.)
718     */
719    
720     ok=true;
721 tboccali 1.9 temp.V.firstLepton=pos[0];
722 tboccali 1.6 temp.V.p4 = temp.V.electrons[0].p4+temp.V.mets[0].p4;
723 tboccali 1.3 return temp;
724 tboccali 1.1 }
725    
726     public:
727     bool verbose_;
728 tboccali 1.2
729     public:
730 tboccali 1.9 static float getDeltaTheta( const VHbbEvent::SimpleJet & j1, const VHbbEvent::SimpleJet & j2 ) {
731 tboccali 1.5 double deltaTheta = 1e10;
732     TLorentzVector pi(0,0,0,0);
733     TLorentzVector v_j1 = j1.chargedTracksFourMomentum;
734     TLorentzVector v_j2 = j2.chargedTracksFourMomentum;
735    
736     if( v_j2.Mag() == 0
737     || v_j1.Mag() == 0 )
738     return deltaTheta = 1e10;
739    
740     //use j1 to calculate the pull vector
741     TVector2 t = j1.tVector;
742    
743     if( t.Mod() == 0 )
744     return deltaTheta = 1e10;
745    
746     Double_t dphi = v_j2.Phi()- v_j1.Phi();
747     if ( dphi > M_PI ) {
748     dphi -= 2.0*M_PI;
749     } else if ( dphi <= -M_PI ) {
750     dphi += 2.0*M_PI;
751     }
752     Double_t deltaeta = v_j2.Rapidity() - v_j1.Rapidity();
753     TVector2 BBdir( deltaeta, dphi );
754    
755     deltaTheta = t.DeltaPhi(BBdir);
756    
757     return deltaTheta;
758    
759     }
760    
761 tboccali 1.4 float getHelicity(const VHbbEvent::SimpleJet& j, TVector3 boost) const {
762     double hel = 1e10;
763 tboccali 1.6 TLorentzVector jet = j.p4;
764 tboccali 1.4 jet.Boost( -boost );
765     hel = TMath::Cos( jet.Vect().Angle( boost ) );
766     return hel;
767     }
768    
769 tboccali 1.1
770     };
771    
772    
773    
774     #endif
775    
776    
777    
778    
779    
780