ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/src/HbbCandidateFinderAlgo.cc
Revision: 1.7
Committed: Tue Aug 23 09:03:41 2011 UTC (13 years, 8 months ago) by bortigno
Content type: text/plain
Branch: MAIN
Changes since 1.6: +4 -2 lines
Log Message:
bit mask bug fixed

File Contents

# User Rev Content
1 tboccali 1.1 #include "VHbbAnalysis/VHbbDataFormats/interface/HbbCandidateFinderAlgo.h"
2     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidateTools.h"
3    
4     #include <iostream>
5     #include<cstdlib>
6    
7     struct CompareJetPt {
8     bool operator()( const VHbbEvent::SimpleJet& j1, const VHbbEvent::SimpleJet& j2 ) const {
9 tboccali 1.4 return j1.p4.Pt() > j2.p4.Pt();
10 tboccali 1.1 }
11     };
12    
13     struct CompareBTag {
14     bool operator()(const VHbbEvent::SimpleJet& j1, const VHbbEvent::SimpleJet& j2 ) const {
15     return j1.csv > j2.csv;
16     }
17     };
18    
19 arizzi 1.5 VHbbCandidate HbbCandidateFinderAlgo::changeHiggs(bool useHighestPtHiggs , const VHbbCandidate & old)
20     {
21     VHbbCandidateTools selector(verbose_);
22    
23     VHbbCandidate temp(old);
24     VHbbEvent::SimpleJet j1,j2;
25     std::vector<VHbbEvent::SimpleJet> addJets;
26     std::vector<VHbbEvent::SimpleJet> jets;
27    
28     for(size_t i=0; i < old.H.jets.size();i++) jets.push_back(old.H.jets[i]);
29     for(size_t i=0; i < old.additionalJets.size();i++) jets.push_back(old.additionalJets[i]);
30    
31     bool foundJets;
32    
33     if (useHighestPtHiggs == false){
34     foundJets = findDiJets(jets,j1,j2,addJets) ;
35     }else{
36     foundJets= findDiJetsHighestPt(jets,j1,j2,addJets) ;
37     }
38    
39     temp.H.jets.clear();
40     temp.H.jets.push_back(j1);
41     temp.H.jets.push_back(j2);
42     temp.H.p4 = (j1).p4+(j2).p4;
43     TVector3 higgsBoost;
44     higgsBoost = (temp.H.p4).BoostVector();
45     temp.H.helicities.clear();
46     temp.H.helicities.push_back(selector.getHelicity(j1,higgsBoost));
47     temp.H.helicities.push_back(selector.getHelicity(j2,higgsBoost));
48     temp.H.deltaTheta = selector.getDeltaTheta(j1,j2);
49     temp.additionalJets = addJets;
50     return temp;
51    
52     }
53 tboccali 1.1
54    
55    
56     void HbbCandidateFinderAlgo::run (const VHbbEvent* event, std::vector<VHbbCandidate> & candidates){
57     //
58     // first find the jets
59     //
60    
61     VHbbCandidateTools selector(verbose_);
62    
63     VHbbEvent::SimpleJet j1,j2;
64     std::vector<VHbbEvent::SimpleJet> addJets;
65 tboccali 1.2 bool foundJets;
66     if (useHighestPtHiggs_ == false){
67     foundJets = findDiJets(event->simpleJets2,j1,j2,addJets) ;
68     }else{
69     foundJets= findDiJetsHighestPt(event->simpleJets2,j1,j2,addJets) ;
70     }
71 tboccali 1.1
72     if (verbose_){
73     std::cout <<" Found Dijets: "<<foundJets<< " Additional: "<<addJets.size()<< std::endl;
74     }
75    
76     if (foundJets == false) return;
77     //
78     // search for leptons
79     //
80     std::vector<VHbbEvent::MuonInfo> mu;
81     findMuons(event->muInfo,mu);
82     std::vector<VHbbEvent::ElectronInfo> ele;
83     findElectrons(event->eleInfo,ele);
84    
85     std::vector<VHbbEvent::METInfo> met;
86     findMET(event->pfmet, met);
87    
88     if (verbose_){
89     std::cout <<" Electrons: "<< ele.size()<<std::endl;
90     std::cout <<" Muons : "<< mu.size()<<std::endl;
91     std::cout <<" MET : "<< met.size()<<std::endl;
92     }
93     if (ele.size()<1 && mu.size() < 1 && met.size()<1) return;
94    
95     //
96     // fill!
97     //
98     VHbbCandidate temp;
99     temp.H.jets.push_back(j1);
100     temp.H.jets.push_back(j2);
101 tboccali 1.4 temp.H.p4 = (j1).p4+(j2).p4;
102 tboccali 1.1 TVector3 higgsBoost;
103 tboccali 1.4 higgsBoost = (temp.H.p4).BoostVector();
104 tboccali 1.1 temp.H.helicities.push_back(selector.getHelicity(j1,higgsBoost));
105     temp.H.helicities.push_back(selector.getHelicity(j2,higgsBoost));
106     temp.H.deltaTheta = selector.getDeltaTheta(j1,j2);
107     temp.additionalJets = addJets;
108     temp.V.mets = met;
109     temp.V.muons = mu;
110     temp.V.electrons = ele;
111    
112     //
113     // now see which kind of andidate this can be
114     //
115    
116     VHbbCandidate result;
117     bool ok = false;
118     //
119     // first: hZmumu
120     //
121    
122     if (verbose_){
123     std::cout <<" START SELECTION "<<std::endl;
124     }
125    
126     result = selector.getHZmumuCandidate(temp,ok);
127     if ( ok == true ){
128     result.setCandidateType(VHbbCandidate::Zmumu);
129     candidates.push_back(result);
130     }else{
131     // HZee
132     result = selector. getHZeeCandidate(temp,ok);
133     if ( ok == true ){
134     result.setCandidateType(VHbbCandidate::Zee);
135     candidates.push_back(result);
136     return;
137     }else{
138     //HWmunu
139     result = selector. getHWmunCandidate(temp,ok);
140     if ( ok == true ){
141     result.setCandidateType(VHbbCandidate::Wmun);
142     candidates.push_back(result);
143     return;
144     }else{
145     // HWenu
146     result = selector. getHWenCandidate(temp,ok);
147     if ( ok == true ){
148     result.setCandidateType(VHbbCandidate::Wen);
149     candidates.push_back(result);
150     return;
151     }else{
152     // HZnn
153     result = selector. getHZnnCandidate(temp,ok);
154     if ( ok == true ){
155     result.setCandidateType(VHbbCandidate::Znn);
156     candidates.push_back(result);
157     return;
158     }
159     }
160     }
161     }
162     }
163     return;
164     }
165    
166     void HbbCandidateFinderAlgo::findMET(const VHbbEvent::METInfo & met, std::vector<VHbbEvent::METInfo>& out){
167     //
168    
169     // just preselection: met significance > 2
170 tboccali 1.3 // removed on request by A. Rizzi - no filter at all
171     // if (met.metSig >2 ) out.push_back(met);
172     out.push_back(met);
173 tboccali 1.1 if (verbose_){
174     std::cout <<" CandidateFinder: Input MET = "<<met.metSig<<" Output MET = "<<out.size()<<std::endl;
175     }
176    
177     }
178    
179    
180     bool HbbCandidateFinderAlgo::findDiJets (const std::vector<VHbbEvent::SimpleJet>& jets, VHbbEvent::SimpleJet& j1, VHbbEvent::SimpleJet& j2,std::vector<VHbbEvent::SimpleJet>& addJets){
181    
182     std::vector<VHbbEvent::SimpleJet> tempJets;
183    
184     if (verbose_){
185     std::cout <<" CandidateFinder: Input Jets = "<<jets.size()<<std::endl;
186     }
187    
188     for (unsigned int i=0 ; i< jets.size(); ++i){
189 tboccali 1.4 if (jets[i].p4.Pt()> jetPtThreshold)
190 tboccali 1.1 tempJets.push_back(jets[i]);
191     }
192    
193     CompareBTag bTagComparator;
194     CompareJetPt ptComparator;
195    
196     if (verbose_){
197     std::cout <<" CandidateFinder: Intermediate Jets = "<<tempJets.size()<<std::endl;
198     }
199    
200    
201     if (tempJets.size()<2) return false;
202    
203     std::sort(tempJets.begin(), tempJets.end(), bTagComparator);
204    
205 tboccali 1.4 if (tempJets[0].p4.Pt()>(tempJets[1].p4.Pt())){
206 tboccali 1.1 j1 = tempJets[0];
207     j2 = tempJets[1];
208     }else{
209     j2 = tempJets[0];
210     j1 = tempJets[1];
211     }
212    
213     //
214     // additional jets
215     //
216     if (tempJets.size()>2){
217     for (unsigned int i=2 ; i< tempJets.size(); ++i){
218     addJets.push_back(tempJets[i]);
219     }
220     }
221    
222     if (verbose_){
223     std::cout <<" CandidateFinder: Output Jets = "<<2<<" Additional = "<<addJets.size()<<std::endl;
224     }
225    
226    
227     std::sort(addJets.begin(), addJets.end(), ptComparator);
228     return true;
229    
230    
231     }
232    
233 tboccali 1.2
234     bool HbbCandidateFinderAlgo::findDiJetsHighestPt (const std::vector<VHbbEvent::SimpleJet>& jets, VHbbEvent::SimpleJet& j1, VHbbEvent::SimpleJet& j2,std::vector<VHbbEvent::SimpleJet>& addJets){
235    
236     std::vector<VHbbEvent::SimpleJet> tempJets;
237    
238     if (verbose_){
239     std::cout <<" CandidateFinder: Input Jets = "<<jets.size()<<std::endl;
240     }
241    
242     for (unsigned int i=0 ; i< jets.size(); ++i){
243 tboccali 1.4 if (jets[i].p4.Pt()> jetPtThreshold)
244 tboccali 1.2 tempJets.push_back(jets[i]);
245     }
246    
247     if (tempJets.size()<2) return false;
248    
249     //loop over the dijets and save the one with highest Pt
250    
251     CompareJetPt ptComparator;
252     std::sort(tempJets.begin(), tempJets.end(), ptComparator);
253     //
254     // so if i<j, pt(i)>pt(j)
255     //
256    
257     float highestPt = -1000;
258     unsigned int highesti,highestj;
259     for (unsigned int i =0; i< tempJets.size()-1; ++i){
260     for (unsigned int j =i+1; j< tempJets.size(); ++j){
261 tboccali 1.4 float pt = (tempJets[i].p4+tempJets[j].p4).Pt();
262 tboccali 1.2 if (pt> highestPt){
263     highestPt = pt;
264     highesti=i;
265     highestj=j;
266     }
267     }
268     }
269     j1 = tempJets[highesti];
270     j2 = tempJets[highestj];
271    
272     for (unsigned int i=0; i<tempJets.size(); ++i){
273     if (i!= highesti && i!= highestj)
274     addJets.push_back(tempJets[i]);
275     }
276    
277     if (verbose_){
278     std::cout <<" CandidateFinder: Output Jets = "<<2<<" Additional = "<<addJets.size()<<std::endl;
279     }
280    
281     return true;
282    
283    
284     }
285    
286    
287    
288 tboccali 1.1 void HbbCandidateFinderAlgo::findMuons(const std::vector<VHbbEvent::MuonInfo>& muons, std::vector<VHbbEvent::MuonInfo>& out){
289     /* Use:
290     For both W -> mu nu and Z -> mu mu, we adopt the standard VBTF muon selection described in VbtfWmunuBaselineSelection. The explicit cuts are reproduced here:
291    
292 bortigno 1.6 We use RECO (pf?) Muons that are both Global and Tracker
293 tboccali 1.1 chi2/ndof < 10 for the global muon fit
294     The track associated to the muon must have
295     >= 1 pixel hits
296     >= 10 pixel + strip hits
297     >= 1 valid hit in the muon chambers
298     >= 2 muon stations
299     |dxy| < 0.2
300     |eta| < 2.4
301 bortigno 1.6 PF Relative combined isolation (R) is required to be < 0.15
302     R = [pfChaIso + pfNeuIso + pfPhoIso] / pT(mu) computed in a cone of radius 0.3 in eta-phi
303 tboccali 1.1 pT(mu) > 20 GeV
304     */
305     for (std::vector<VHbbEvent::MuonInfo>::const_iterator it = muons.begin(); it!= muons.end(); ++it){
306     if (
307     (*it). globChi2<10 &&
308     (*it).nPixelHits>= 1 &&
309     (*it).globNHits >= 1 &&
310     (*it).nHits >= 10 &&
311 bortigno 1.7 //tracker
312     ((*it).cat & 0x1) &&
313     //global
314     ((*it).cat & 0x2) &&
315 tboccali 1.1 (*it).validMuStations >=2 &&
316     (*it).ipDb<.2 &&
317 bortigno 1.6 // ((*it).hIso+(*it).eIso+(*it).tIso)/(*it).p4.Pt()<.15 &&
318     ((*it).pfChaIso+(*it).pfPhoIso+(*it).pfNeuIso)/(*it).p4.Pt()<.15 &&
319     fabs((*it).p4.Eta())<2.4 &&
320     (*it).p4.Pt()>20) {
321 tboccali 1.1 out.push_back(*it);
322     }
323     }
324    
325     if (verbose_){
326     std::cout <<" CandidateFinder: Input Muons = "<<muons.size()<<" Output Muons = "<<out.size()<<std::endl;
327     }
328    
329    
330    
331     }
332    
333    
334     void HbbCandidateFinderAlgo::findElectrons(const std::vector<VHbbEvent::ElectronInfo>& electrons, std::vector<VHbbEvent::ElectronInfo>& out){
335     /*
336     We adopt the standard cut-based selection from VBTF described in detail here.
337    
338     Z -> ee
339 bortigno 1.6 gsf (pf?) electrons
340 tboccali 1.1 VBTF WP95
341     |eta|<2.5, excluding the gap 1.44 < |eta| < 1.57
342     pT(e) > 20
343    
344     W -> e nu
345 bortigno 1.6 gsf (pf?) electrons
346 tboccali 1.1 VBTF WP80
347     |eta|<2.5, excluding the gap 1.44 < |eta| < 1.57
348     pT(e) > 30
349     */
350    
351     for (std::vector<VHbbEvent::ElectronInfo>::const_iterator it = electrons.begin(); it!= electrons.end(); ++it){
352     if (
353     // fake
354 bortigno 1.6 ((*it).id95r - 7) < 0.1 &&
355 tboccali 1.4 fabs((*it).p4.Eta()) < 2.5 &&
356 bortigno 1.6 !( fabs((*it).p4.Eta()) < 1.57 && fabs((*it).p4.Eta()) > 1.44) &&
357     (*it).p4.Pt()>20 // I use the minimum ok for both Z and W
358 tboccali 1.1 ){
359     out.push_back(*it);
360     }
361     }
362     if (verbose_){
363     std::cout <<" CandidateFinder: Input Electrons = "<<electrons.size()<<" Output Electrons = "<<out.size()<<std::endl;
364     }
365    
366    
367     }
368