ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/UNL/macros/MyHbbAnalyzer.C
Revision: 1.2
Committed: Wed Aug 10 18:04:26 2011 UTC (13 years, 9 months ago) by malbouis
Content type: text/plain
Branch: MAIN
Changes since 1.1: +44 -24 lines
Log Message:
updated event selection macro

File Contents

# User Rev Content
1 malbouis 1.1 #define MyHbbAnalyzer_cxx
2     #include "MyHbbAnalyzer.h"
3     #include <TH2.h>
4     #include <TStyle.h>
5     #include <TCanvas.h>
6    
7     void MyHbbAnalyzer::Loop()
8     {
9     // In a ROOT session, you can do:
10     // Root > .L MyHbbAnalyzer.C
11     // Root > MyHbbAnalyzer t
12     // Root > t.GetEntry(12); // Fill t data members with entry number 12
13     // Root > t.Show(); // Show values of entry 12
14     // Root > t.Show(16); // Read and show values of entry 16
15     // Root > t.Loop(); // Loop on all entries
16     //
17    
18     // This is the loop skeleton where:
19     // jentry is the global entry number in the chain
20     // ientry is the entry number in the current Tree
21     // Note that the argument to GetEntry must be:
22     // jentry for TChain::GetEntry
23     // ientry for TTree::GetEntry and TBranch::GetEntry
24     //
25     // To read only selected branches, Insert statements like:
26     // METHOD1:
27     // fChain->SetBranchStatus("*",0); // disable all branches
28     // fChain->SetBranchStatus("branchname",1); // activate branchname
29     // METHOD2: replace line
30     // fChain->GetEntry(jentry); //read all branches
31     //by b_branchname->GetEntry(ientry); //read only this branch
32     if (fChain == 0) return;
33    
34     Long64_t nentries = fChain->GetEntriesFast();
35    
36     Long64_t nbytes = 0, nb = 0;
37    
38     ////////
39     // cut and count variables
40     ////////
41     int allEvts = 0;
42     int preSelection = 0;
43     int pT_jj = 0, pT_Z = 0, CSV1 = 0, CSV2 = 0, DPhi_ZH = 0, N_aj = 0, M_jj = 0;
44     ////////
45     // loop on entries
46     ////////
47     pct = 0;
48     total_entries = fChain->GetEntries();
49    
50     //nentries = 1000;
51     for (Long64_t jentry=0; jentry<nentries;jentry++) {
52     Long64_t ientry = LoadTree(jentry);
53     if (ientry < 0) break;
54     nb = fChain->GetEntry(jentry); nbytes += nb;
55     // if (Cut(ientry) < 0) continue;
56    
57     // jobProgress:
58     jobProgress(jentry);
59    
60     // count events:
61     allEvts++;
62     basicMuonDistributions("allEvts");
63     basicJetDistributions("allEvts");
64    
65     // pre-selection cuts:
66     if (!preSelect()) continue;
67     preSelection++;
68     basicMuonDistributions("preSel");
69     basicJetDistributions("preSel");
70    
71     // pt_jj cut:
72     if (!Select_pTjj()) continue;
73     pT_jj++;
74     basicMuonDistributions("pT_jj");
75     basicJetDistributions("pT_jj");
76    
77     // pT_Z cut:
78     if (!Select_pTZ()) continue;
79     pT_Z++;
80     basicMuonDistributions("pT_Z");
81     basicJetDistributions("pT_Z");
82    
83     // CSV1 cut:
84     if (!Select_CSV1()) continue;
85     CSV1++;
86     basicMuonDistributions("CSV1");
87     basicJetDistributions("CSV1");
88    
89     // CSV2 cut:
90     if (!Select_CSV2()) continue;
91     CSV2++;
92     basicMuonDistributions("CSV2");
93     basicJetDistributions("CSV2");
94    
95     // DPhi cut:
96     if (!Select_DPhi()) continue;
97     DPhi_ZH++;
98     basicMuonDistributions("DPhi");
99     basicJetDistributions("DPhi");
100    
101     // Naj cut:
102     if (!Select_Naj()) continue;
103     N_aj++;
104     basicMuonDistributions("Naj");
105     basicJetDistributions("Naj");
106    
107     // Mjj cut:
108     if (!Select_Mjj()) continue;
109     M_jj++;
110     basicMuonDistributions("Mjj");
111     basicJetDistributions("Mjj");
112    
113     }// loop on entries
114    
115     ////////
116     // write histos to file:
117     ////////
118     TFile *f = new TFile("hbb.root","RECREATE");
119     for (map<std::string,TH1*>::iterator it=histmap.begin(); it!=histmap.end();it++) {
120     (*it).second->Write();
121     }
122     f->Write();
123     f->Close();
124    
125     ////////
126     // print stats
127     ////////
128     cout << "allEvts: " << allEvts << endl;
129     cout << "preSelection: " << preSelection << endl;
130     cout << "pT_jj: " << pT_jj << endl;
131     cout << "pT_Z: " << pT_Z << endl;
132     cout << "CSV1: " << CSV1 << endl;
133     cout << "CSV2: " << CSV2 << endl;
134     cout << "DPhi: " << DPhi_ZH << endl;
135     cout << "Naj: " << N_aj << endl;
136     cout << "Mjj: " << M_jj << endl;
137     cout << "signal eff. PRE-SELECT: " << (double)preSelection/allEvts << endl;
138     cout << "signal eff. pT_jj: " << (double)pT_jj/preSelection << endl;
139     cout << "signal eff. pT_Z: " << (double)pT_Z/pT_jj << endl;
140     cout << "signal eff. CSV1: " << (double)CSV1/pT_Z << endl;
141     cout << "signal eff. CSV2: " << (double)CSV2/CSV1 << endl;
142     cout << "signal eff. DPhi: " << (double)DPhi_ZH/CSV2 << endl;
143     cout << "signal eff. Naj: " << (double)N_aj/DPhi_ZH << endl;
144     cout << "signal eff. Mjj: " << (double)M_jj/N_aj << endl;
145    
146    
147     }// Loop
148     bool MyHbbAnalyzer::preSelect(){
149     bool passedPreSel = true;
150     if (nMuons < 2) passedPreSel = false;
151     if (nJets < 2) passedPreSel = false;
152     return passedPreSel;
153     }// preSelect
154    
155     bool MyHbbAnalyzer::Select_pTjj(){
156     bool passedSel_pTjj = true;
157 malbouis 1.2 // get jet indices that maximize the CSV discriminant
158     int firstJetIdx, secondJetIdx;
159     jetIndices(firstJetIdx, secondJetIdx);
160     // reject event with less than 2 CSV tags
161     if (firstJetIdx == -1 || secondJetIdx == -1) return false;
162     // get the dijet system
163     TLorentzVector firstJet_p4 = TLorentzVector(jetPx[firstJetIdx], jetPy[firstJetIdx], jetPz[firstJetIdx], jetP[firstJetIdx]);
164     TLorentzVector secondJet_p4 = TLorentzVector(jetPx[secondJetIdx], jetPy[secondJetIdx], jetPz[secondJetIdx], jetP[secondJetIdx]);
165     TLorentzVector jj = firstJet_p4 + secondJet_p4;
166     if (jj.Pt() <= 100) passedSel_pTjj = false;
167 malbouis 1.1 return passedSel_pTjj;
168     }// pT_jj cut
169    
170     bool MyHbbAnalyzer::Select_pTZ(){
171     bool passed_pTZ = true;
172     TLorentzVector firstMu_p4 = TLorentzVector(muonPx[0], muonPy[0], muonPz[0], muonP[0]);
173     TLorentzVector secondMu_p4 = TLorentzVector(muonPx[1], muonPy[1], muonPz[1], muonP[1]);
174     TLorentzVector Z = firstMu_p4 + secondMu_p4;
175     if (Z.Pt() <= 100) passed_pTZ = false;
176     return passed_pTZ;
177     }// pT_Z cut
178    
179     bool MyHbbAnalyzer::Select_CSV1(){
180 malbouis 1.2 // max CSV tagged jet should satisfy the tight Operating Point (CSVT > 0.898)
181 malbouis 1.1 bool passedCSV1 = true;
182 malbouis 1.2 int firstJetIdx, secondJetIdx;
183     jetIndices(firstJetIdx, secondJetIdx);
184 malbouis 1.1 double bDiscMax;
185 malbouis 1.2 bDiscMax = bDisc_CSV[firstJetIdx] > bDisc_CSV[secondJetIdx] ? bDisc_CSV[firstJetIdx]:bDisc_CSV[secondJetIdx];
186 malbouis 1.1 if (bDiscMax <= 0.898) passedCSV1 = false;
187     return passedCSV1;
188     }// CSV1
189    
190     bool MyHbbAnalyzer::Select_CSV2(){
191 malbouis 1.2 // min CSV tagged jet should satisfy CSV > 0.5
192 malbouis 1.1 bool passedCSV2 = true;
193 malbouis 1.2 int firstJetIdx, secondJetIdx;
194     jetIndices(firstJetIdx, secondJetIdx);
195 malbouis 1.1 double bDiscMin;
196 malbouis 1.2 bDiscMin = bDisc_CSV[firstJetIdx] < bDisc_CSV[secondJetIdx] ? bDisc_CSV[firstJetIdx]:bDisc_CSV[secondJetIdx];
197 malbouis 1.1 if (bDiscMin <= 0.5) passedCSV2 = false;
198     return passedCSV2;
199     }// CSV2
200    
201     bool MyHbbAnalyzer::Select_DPhi(){
202     bool passedDPhi = true;
203     TLorentzVector firstMu_p4 = TLorentzVector(muonPx[0], muonPy[0], muonPz[0], muonP[0]);
204     TLorentzVector secondMu_p4 = TLorentzVector(muonPx[1], muonPy[1], muonPz[1], muonP[1]);
205     TLorentzVector Z = firstMu_p4 + secondMu_p4;
206 malbouis 1.2 int firstJetIdx, secondJetIdx;
207     jetIndices(firstJetIdx, secondJetIdx);
208     TLorentzVector firstJet_p4 = TLorentzVector(jetPx[firstJetIdx], jetPy[firstJetIdx], jetPz[firstJetIdx], jetP[firstJetIdx]);
209     TLorentzVector secondJet_p4 = TLorentzVector(jetPx[secondJetIdx], jetPy[secondJetIdx], jetPz[secondJetIdx], jetP[secondJetIdx]);
210 malbouis 1.1 TLorentzVector jj = firstJet_p4 + secondJet_p4;
211 malbouis 1.2 if (fabs(Z.DeltaPhi(jj)) <= 2.90) passedDPhi = false;
212 malbouis 1.1 return passedDPhi;
213     }// DPhi
214    
215     bool MyHbbAnalyzer::Select_Naj(){
216     bool passedNaj = true;
217     if (nJets > 3) passedNaj = false;
218     return passedNaj;
219     }// Naj
220    
221     bool MyHbbAnalyzer::Select_Mjj(){
222     bool passedMjj = true;
223 malbouis 1.2 int firstJetIdx, secondJetIdx;
224     jetIndices(firstJetIdx, secondJetIdx);
225     TLorentzVector firstJet_p4 = TLorentzVector(jetPx[firstJetIdx], jetPy[firstJetIdx], jetPz[firstJetIdx], jetP[firstJetIdx]);
226     TLorentzVector secondJet_p4 = TLorentzVector(jetPx[secondJetIdx], jetPy[secondJetIdx], jetPz[secondJetIdx], jetP[secondJetIdx]);
227 malbouis 1.1 TLorentzVector jj = firstJet_p4 + secondJet_p4;
228     if (jj.M() < 95 || jj.M() > 125) passedMjj = false;
229     return passedMjj;
230     }
231 malbouis 1.2 void MyHbbAnalyzer::jetIndices(int &index1, int &index2){
232     int fJetIdx = -1, sJetIdx = -1;
233     double highestBdiscSum = 0;
234     for (int i = 0; i != nJets; ++i){
235     if (bDisc_CSV[i] < 0) continue;
236     for (int j = i+1; j != nJets; ++j){
237     if (bDisc_CSV[j] < 0) continue;
238     if (bDisc_CSV[i] + bDisc_CSV[j] > highestBdiscSum){
239     highestBdiscSum = bDisc_CSV[i] + bDisc_CSV[j];
240     fJetIdx = i;
241     sJetIdx = j;
242     }// if greater sum
243     }// second loop
244     }// 1st loop
245     swap(fJetIdx, index1);
246     swap(sJetIdx, index2);
247     }// jetIndices
248 malbouis 1.1
249     void MyHbbAnalyzer::basicMuonDistributions(string cut){
250     // var definition
251     string ph_process;
252    
253     if (isZH()) ph_process = "ZH";
254     if (isZZ()) ph_process = "ZZ";
255     if (isDY()) ph_process = "DY";
256    
257     for (int i=0; i != nMuons; ++i) {
258     string muonpT = "muonPt_" + ph_process + cut;
259     string muoneta = "muonEta_" + ph_process + cut;
260     string muonphi = "muonPhi_" + ph_process + cut;
261    
262     //cout << muonpT << endl;
263    
264     fillhisto(muonpT, muonPt[i], 1., "#mu pT", 400, 0, 400);
265     fillhisto(muoneta, muonEta[i], 1., "#mu #eta", 100, -5, 5);
266     fillhisto(muonphi, muonPhi[i], 1., "#mu #phi", 80, -4, 4);
267     }
268     }// basicMuonDistributions
269    
270     void MyHbbAnalyzer::basicJetDistributions(string cut){
271     // var definition
272     string ph_process;
273    
274     if (isZH()) ph_process = "ZH";
275     if (isZZ()) ph_process = "ZZ";
276     if (isDY()) ph_process = "DY";
277    
278     for (int i=0; i != nJets; ++i) {
279     string jetpT = "jetPt_" + ph_process + cut;
280     string jeteta = "jetEta_" + ph_process + cut;
281     string jetphi = "jetPhi_" + ph_process + cut;
282    
283     //cout << muonpT << endl;
284    
285     fillhisto(jetpT, jetPt[i], 1., "jet pT", 400, 0, 400);
286     fillhisto(jeteta, jetEta[i], 1., "jet #eta", 100, -5, 5);
287     fillhisto(jetphi, jetPhi[i], 1., "jet #phi", 80, -4, 4);
288     }
289     }// basicJetDistributions