ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/jbabb/ScriptsAndMacros/StatsPlotter.C
Revision: 1.1
Committed: Sat Sep 3 21:22:23 2011 UTC (13 years, 8 months ago) by jbabb
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 //
2 // A root macro to plot MC and data on the
3 // same histogram for a variety of different
4 // variables.
5 //
6 // John Babb 11/11/10
7 //
8
9 //ROOT includes
10 #include "TTree.h"
11 #include "TFile.h"
12 #include "TBranch.h"
13 #include "TLeafF.h"
14 #include "TLeafI.h"
15 #include "TH1F.h"
16 #include "TH2F.h"
17 #include "THStack.h"
18
19
20 //System includes
21 #include <TObject.h>
22 #include <TMinuit.h>
23 #include <TLorentzVector.h>
24 #include <TMath.h>
25 #include <TString.h>
26 #include <TStyle.h>
27 #include <TLegend.h>
28 #include <TCanvas.h>
29 #include <TPad.h>
30 #include <TGraphErrors.h>
31 #include <TSystem.h>
32 #include <vector>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <iostream>
36 #include <string>
37
38
39
40
41 void StatsPlotter() {
42
43 //Output file
44 TFile *f = new TFile("hists_for_statistics_2011.root", "recreate");
45
46
47 //scale...
48 double ttbar_lumi = 1286491./(157.5*1.081);
49 double st_s_lumi = 494967./1.49;
50 double st_t_lumi = 484060./20.93;
51 double st_tw_lumi = 494961./10.6;
52 double ww_lumi = 2061760. / (27.79 * 1.);
53 double wz_lumi = 2194752. / (10.4* 1.);
54 double zz_lumi = 2113368. / (4.297 * 1.);
55 double qcd_lumi = 29504866.*(138./153.) / (296600000. * 0.0002855 * 1.081);
56 //double qcd_lumi = 20416038.*(138./153.) /(296600000. * 0.0002855 * 0.949);
57 double wjets_lumi = 14819145. /(31314.*1.197);
58 double zjets_lumi = 2543706. / 3048.;
59 double lumi_2010 = 36.1;
60 double lumi_2011 = 767.;
61 double data_lumi = 767.;
62
63
64
65 //767pb numbers - bdt
66 double scale30 = 1.2181*1.0000;
67 double scale31 = 0.9830*0.1481;
68 double scale32 = 0.7937*0.0158;
69 double scale40 = 1.1755*0.0433;
70 double scale41 = 0.9671*0.0276;
71 double scale42 = 0.8437*0.0084;
72
73
74
75 TString path = "/uscms_data/d2/jbabb/CMSSW_4_1_4/src/TopQuarkAnalysis/Skynet/test/Preselection_35GeV/Skynet_TTbarTree_";
76 TString qcdpath = "/uscms_data/d2/jbabb/CMSSW_4_1_4/src/TopQuarkAnalysis/Skynet/test/Preselection_35GeV/Skynet_InvertedIsolation_TTbarTree_";
77
78
79 //List the variables that we want plots of
80 int nVariables = 1;
81 int nBins = 40;
82
83 double VariableMax = 2000.;
84 double VariableMin = 0.;
85
86 int nFiles = 15;
87
88 TString filenames[] = {"TTbar",
89 "ST-s",
90 "ST-t",
91 "ST-tW",
92 "WW",
93 "WZ",
94 "ZZ",
95 "WJets",
96 "ZJets",
97 //"Zprime500",
98 "Zprime750",
99 "Zprime1000",
100 "Zprime1250",
101 "Zprime1500",
102 "Zprime2000",
103 "2011"
104 };
105
106
107 int qcdFiles = 6;
108
109 TString qcdfilenames[] = {
110 "3jets0bjets_QCD",
111 "3jets1bjets_QCD",
112 "3jets2bjets_QCD",
113 "4jets0bjets_QCD",
114 "4jets1bjets_QCD",
115 "4jets2bjets_QCD",
116 }
117
118 double scales[] = { data_lumi/ttbar_lumi,
119 data_lumi/st_s_lumi,
120 data_lumi/st_t_lumi,
121 data_lumi/st_tw_lumi,
122 data_lumi/ww_lumi,
123 data_lumi/wz_lumi,
124 data_lumi/zz_lumi,
125 data_lumi/wjets_lumi,
126 data_lumi/zjets_lumi,
127 //data_lumi/qcd_lumi,
128 //data_lumi/zprime_lumi,
129 //data_lumi/zprime_lumi,
130 //data_lumi/zprime_lumi,
131 //data_lumi/zprime_lumi,
132 //data_lumi/zprime_lumi,
133 //data_lumi/zprime_lumi,
134 1.,
135 1.,
136 1.,
137 1.,
138 1.,
139 1.
140 };
141
142
143 double qcdscales[] = { data_lumi/qcd_lumi*scale30,
144 data_lumi/qcd_lumi*scale31,
145 data_lumi/qcd_lumi*scale32,
146 data_lumi/qcd_lumi*scale40,
147 data_lumi/qcd_lumi*scale41,
148 data_lumi/qcd_lumi*scale42};
149
150
151
152
153
154
155
156 for (int i = 0; i < nFiles; i++) {
157
158 TFile *file = new TFile(path+filenames[i]+".root", "OPEN");
159
160 TCanvas* c1 = new TCanvas();
161 c1->cd();
162
163 TH1F *h1 = (TH1F*) file->Get("Skynet");
164 h1->SetTitle(filenames[i]);
165 h1->Rebin(4);
166 h1->GetXaxis()->SetTitle("BDT");
167
168
169 TH1F *skynet = new TH1F(filenames[i]+"_BDT", filenames[i]+"_BDT", 25, -1., 1.);
170
171 for (int x = 1; x <= 25; x++) {
172 skynet->SetBinContent(x, h1->GetBinContent(x));
173 }
174
175 skynet->Scale( scales[i], "" );
176 skynet->GetXaxis()->SetTitle("BDT");
177 skynet->Sumw2();
178 skynet->Draw("pe");
179 c1->Update();
180
181 f->cd();
182 skynet->Write();
183
184 delete c1;
185 delete h1;
186 delete skynet;
187
188
189 TTree *tree = (TTree*)file->Get("PATuple");
190
191 float tt;
192
193 int entries = tree->GetEntries();
194 TH1F *Plot = new TH1F(filenames[i]+"_MASS", filenames[i]+"Mass", nBins, VariableMin, VariableMax);
195 TBranch *Branch = tree->GetBranch( "unfittedEvent_ttInvariantMass" );
196
197 Branch->SetAddress(&tt);
198
199
200 TCanvas* c1 = new TCanvas();
201 c1->cd();
202
203 for ( int j = 0; j < entries; j++ ) {
204 Branch->GetEntry(j);
205 Plot->Fill(tt);
206 }
207
208 Plot->Scale( scales[i], "" );
209 Plot->Sumw2();
210 Plot->Draw("pe");
211 c1->Update();
212
213 f->cd();
214
215 Plot->Write();
216
217
218 delete c1;
219 delete Plot;
220
221
222 }//for i
223
224
225
226
227 TH1F *skynet_qcd = new TH1F("QCD_BDT", "QCD_BDT", 25, -1., 1.);
228 TH1F *Plot_qcd = new TH1F("QCD_MASS", "QCD_Mass", nBins, VariableMin, VariableMax);
229
230 for (int i = 0; i < qcdFiles; i++) {
231
232 TFile *file = new TFile(qcdpath+qcdfilenames[i]+".root", "OPEN");
233
234 TCanvas* c1 = new TCanvas();
235 c1->cd();
236
237 TH1F *h1 = (TH1F*) file->Get("Skynet");
238 h1->SetTitle(qcdfilenames[i]);
239 h1->Rebin(4);
240 h1->GetXaxis()->SetTitle("BDT");
241
242
243 TH1F *skynet = new TH1F(filenames[i]+"_BDT", filenames[i]+"_BDT", 25, -1., 1.);
244
245 for (int x = 1; x <= 25; x++) {
246 skynet->SetBinContent(x, h1->GetBinContent(x));
247 }
248
249 skynet->Scale( qcdscales[i], "" );
250 skynet->GetXaxis()->SetTitle("BDT");
251 skynet->Sumw2();
252 skynet->Draw("pe");
253 c1->Update();
254
255 skynet_qcd->Add(skynet);
256
257 f->cd();
258 skynet->Write();
259
260 delete c1;
261 delete h1;
262 delete skynet;
263
264
265 TTree *tree = (TTree*)file->Get("PATuple");
266
267 float tt;
268
269 int entries = tree->GetEntries();
270 TH1F *Plot = new TH1F(qcdfilenames[i]+"_MASS", qcdfilenames[i]+"Mass", nBins, VariableMin, VariableMax);
271 TBranch *Branch = tree->GetBranch( "unfittedEvent_ttInvariantMass" );
272
273 Branch->SetAddress(&tt);
274
275
276 TCanvas* c1 = new TCanvas();
277 c1->cd();
278
279 for ( int j = 0; j < entries; j++ ) {
280 Branch->GetEntry(j);
281 Plot->Fill(tt);
282 }
283
284 Plot->Scale( qcdscales[i], "" );
285 Plot->Sumw2();
286 Plot->Draw("pe");
287 c1->Update();
288
289 Plot_qcd->Add(Plot);
290
291
292 f->cd();
293
294 Plot->Write();
295
296
297 delete c1;
298 delete Plot;
299
300
301 }//for i
302
303
304 f->cd();
305
306 Plot_qcd->Write();
307 skynet_qcd->Write();
308
309 f->Write();
310 f->Close();
311
312
313 }//DataPlotter