ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/rootEWKanalyzer/plotDataMCwSignal.C
Revision: 1.4
Committed: Tue Dec 21 15:25:39 2010 UTC (14 years, 4 months ago) by jueugste
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +23 -14 lines
Log Message:
Added generated PU info

File Contents

# Content
1 using namespace std;
2 #include "tdrstyle.C"
3
4 void plotDataMCwSignal(){
5
6 // specify the DATA/MC root file!!!
7 // --------------------------------------------------------------------------
8 TFile *data = TFile::Open("Data/root/Data.root");
9 TFile *mc = TFile::Open("QCD_bckgd.root");
10 TFile *mcOther = TFile::Open("other_bckgd.root");
11 TFile *mcTTbar = TFile::Open("TTbar_bckgd.root");
12 TFile *mcSignal = TFile::Open("mcSignal.root");
13
14 char *legDataTitle = "Data";//"Signal, W #rightarrow e #nu";
15 char *legMCTitle = "QCD, #gamma + jet"; //"Background";
16 char *legMCotherTitle = "EWK"; //"Background";
17 char *legMCttbarTitle = "ttbar"; //"Background";
18 char *legMCsigTitle = "W #rightarrow e #nu"; //"Signal";
19 TString dataset="";
20 TString overallTitle="CMS preliminary 2010";
21 TString CMen="#sqrt{s}=7TeV, #int L = 890 nb^{-1}";
22 TString cuts1="";
23 Tstring cuts2="";
24 double rebin=1.;
25 bool isptplot;
26
27 bool normalizeToArea=false;
28
29 //---------------------------------------------------------------------------
30 setTDRStyle();
31 gROOT->ForceStyle();
32 TIter next (data->GetListOfKeys ());
33
34 // TString name;
35 // TRegexp jpt("JPT");
36 // TRegexp pf("PF");
37 int colour;
38 // TRegexp twodim("map");
39 // //non log plots
40 // TRegexp eta("eta");
41 // TRegexp phi("phi");
42 // TRegexp hits("hits");
43 // //
44 // TRegexp pt("pt");
45 // TRegexp dphi("dphi");
46 // TRegexp mass("mass");
47
48 // TRegexp emf("emf");
49 // TRegexp CHF("CHF");
50 // TRegexp NHF("NHF");
51 // TRegexp NEF("NEF");
52 // TRegexp METover("METover");
53 // TRegexp dijet("DiJet");
54 // TRegexp cons("cons");
55
56 int islog=0;
57
58 int index=0;
59
60 for (TKey* key = 0; (key = (TKey *) next());) {
61 // isptplot=false;
62 // //determine wether it is a Calo/JPT or PF plots to make
63 // name=key->GetName();
64 // if(name.Index(twodim)>-1) continue; //dont want comparisons for 2D histos
65 // colour=5;
66 // cuts1="p_{T}(jet)> 25 GeV";
67 // cuts2="|#eta(jet)| < 3";
68 // if(name.Index(jpt)>-1) {
69 // colour=896;
70 // cuts1="p_{T}(jet)> 25 GeV";
71 // cuts2="|#eta(jet)| < 3";
72 // }
73 // if(name.Index(pf)>-1){
74
75
76 colour=38;
77 // colour=4;
78 cuts1="p_{T}(jet)> 25 GeV";
79 cuts2="|#eta(jet)| < 3";
80
81 // }
82
83
84 cout<<"here"<<endl;
85
86 islog=0;
87 // if(name.Index(eta)>-1||name.Index(phi)>-1||name.Index(hits)>-1 || name.Index(emf)>-1 || name.Index(CHF)>-1 || name.Index(NHF)>-1|| name.Index(NEF)>-1||name.Index(cons)>-1) islog=0;
88 TH1D * h_data= data->Get(key->GetName());
89 TH1D * h_mc=mc->Get(key->GetName());
90 TH1D * h_other=mcOther->Get(key->GetName());
91 TH1D * h_ttbar=mcTTbar->Get(key->GetName());
92 TH1D * h_sig=mcSignal->Get(key->GetName());
93 // only for filled histos
94 if( h_mc->GetEntries()!=0) {
95
96 //
97
98
99 cout<<"here"<<endl;
100 }
101 // h_data->SetTitle(overallTitle);
102 // h_mc->SetTitle(overallTitle);
103 // h_other->SetTitle(overallTitle);
104 // h_ttbar->SetTitle(overallTitle);
105 // h_sig->SetTitle(overallTitle);
106
107
108
109 // if(name.Index(pt)>-1) {
110 // h_data->SetYTitle("Jets/GeV");
111 // h_mc->SetYTitle("Jets/GeV");
112 // isptplot=true;
113 // // cout << h_data->GetXaxis()->GetBinWidth(1)<< endl;
114 // }
115 // if(name.Index(eta)>-1||name.Index(phi)>-1) {
116 // h_data->SetYTitle("Jets");
117 // h_mc->SetYTitle("Jets");
118 // }
119 // if(name.Index(dphi)>-1) {
120 // h_data->SetYTitle("Events");
121 // h_mc->SetYTitle("Events");
122 // }
123 // if(name.Index(mass)>-1){
124 // h_data->SetYTitle("Events/GeV");
125 // h_mc->SetYTitle("Events/GeV");
126 isptplot=true;
127 // }
128
129 TCanvas *c = new TCanvas("c","",600,600);
130 double scalefactor;
131 // if(h_mc->Integral()!=0) {
132 // scalefactor=h_data->Integral()/h_mc->Integral();
133 // }
134 // else {scalefactor=1;}
135 // cout<<"scale factor: "<<scalefactor<<endl;
136
137
138 // if (isptplot) {
139 // // h_mc->Sumw2(); //for some reason it doesnt plot this one if i do sumw2, so i comment it out. anyhow we dont see its errors, but to be checked!
140 // // h_data->Sumw2();
141 // for(int j=0 ; j<=h_mc->GetNbinsX(); ++j){
142 // h_data->SetBinError(j,sqrt(h_data->GetBinContent(j))/h_data->GetBinWidth(j));
143 // //
144 // h_mc->SetBinContent(j,h_mc->GetBinContent(j)/h_mc->GetBinWidth(j));
145 // h_data->SetBinContent(j,h_data->GetBinContent(j)/h_data->GetBinWidth(j));
146 // }
147 // }
148
149
150
151 // h_mc->Scale(scalefactor);
152
153
154 // h_mc->Rebin(rebin);
155 // h_sig->Rebin(rebin);
156 // h_data->Rebin(rebin);
157
158 // h_mc->SetMaximum(1.5*h_data->GetMaximum());
159
160
161 h_data->SetMarkerStyle(20);
162 h_other->SetFillColor(8);
163 h_other->SetLineColor(1);
164 h_ttbar->SetFillColor(15);
165 h_ttbar->SetLineColor(1);
166 h_sig->SetFillColor(46);
167 h_sig->SetLineColor(1);
168 h_mc->SetFillColor(colour);
169 h_mc->SetLineColor(1);
170
171
172 // h_data->SetTitle(overallTitle);
173 // h_mc->SetTitle(overallTitle);
174 // std::cout << "Plotting: " << key->GetName() << std::endl;
175 // h_mc->SetMinimum(0.01);
176 // h_data->SetMinimum(0.01);
177
178
179
180 //draw title
181 MoveStatsAndDraw(h_data , h_mc, h_other, h_ttbar, h_sig, legDataTitle, legMCTitle, legMCsigTitle, legMCotherTitle, legMCttbarTitle, overallTitle, CMen, islog, colour, false, cuts1, cuts2, isptplot, normalizeToArea);
182
183 char histname [256];
184 sprintf (histname, "plottingTest/%s.gif", key->GetName());
185 // cout<<key->GetName()<<endl;
186 char test [256];//="s_El_ElCharge_";
187 // index++;
188 sprintf (test, "%s%i", "s_El_ElCharge_",index);
189 // cout<<test<<endl;
190 if(!strcmp(key->GetName(),test)) {
191 index++;
192 continue;
193 }
194 c->Print(histname);
195 // cout<<"here2"<<endl;
196
197 delete c;
198
199
200 // } //if Entries != 0
201 } // loop over keys
202
203
204 // cout << "------ Calo Jets --------" <<endl;
205 // TH1D * temp =data->Get("dijetptall");
206 // cout << "CaloJets " << temp->GetEntries() <<endl;
207 // TH1D *temp2 =data->Get("dijetptallJIDloose");
208 // cout << "Loose CaloJets " << temp2->GetEntries() <<endl;
209 // TH1D *temp3 =data->Get("dijetptallJIDtight");
210 // cout << "Tight CaloJets " << temp3->GetEntries() <<endl;
211
212 // cout << "------ PF Jets --------" <<endl;
213 // TH1D * temp5 =data->Get("diPFjetptall");
214 // cout << "PFJets " << temp5->GetEntries() <<endl;
215 // TH1D *temp6 =data->Get("diPFjetptallJIDloose");
216 // cout << "Loose PFJets " << temp6->GetEntries() <<endl;
217 // TH1D *temp7 =data->Get("diPFjetptallJIDtight");
218 // cout << "Tight PFJets " << temp7->GetEntries() <<endl;
219
220 // cout << "------ JPT Jets --------" <<endl;
221 // TH1D * temp8 =data->Get("diJPTjetptall");
222 // cout << "JPTJets " << temp8->GetEntries() <<endl;
223 // TH1D *temp9 =data->Get("diJPTjetptallJIDloose");
224 // cout << "Loose JPTJets " << temp9->GetEntries() <<endl;
225 // TH1D *temp10 =data->Get("diJPTjetptallJIDtight");
226 // cout << "Tight JPTJets " << temp10->GetEntries() <<endl;
227 }
228
229
230
231 //-------------------------------------------------------------------------------------
232 void MoveStatsAndDraw (TH1 *data, TH1 *mc, TH1 *other, TH1 *ttbar, TH1 *sig, char *dataTitle, char* mcTitle, char *mcSigTitle, char* otherTitle, char *ttbarTitle, char* firstline, char* secondline, int log, int col, bool stat, TString cut1, TString cut2, bool movepave, bool normalizeToArea){
233
234 c->SetLogy(log);
235
236 if(normalizeToArea) {
237 double S=sig->Integral();
238 double N=mc->Integral();
239 double f=1;
240 if(N!=0) f = S/N;
241 mc->Scale(f);
242 other->Scale(f);
243 ttbar->Scale(f);
244 sig->Scale(f);
245 }
246
247
248
249 // maximumData;
250 // double maximumMc;
251 int maximumData=data->GetBinContent(data->GetMaximumBin());
252 int maximumMc=mc->GetBinContent(mc->GetMaximumBin());
253
254
255
256
257 // if(data->GetBinContent(data->GetMaximum())<mc->GetBinContent(mc->GetMaximum())) {
258 if(maximumData<maximumMc) {
259 // sig->SetMaximum(maximumMc * 2.5);
260 mc->SetMaximum(maximumMc * 2.5);
261 if(log==1) sig->SetMinimum(0.0001);
262 if(log==0) sig->SetMinimum(0.);
263 mc->Draw("");
264 other->Draw("sames");
265 ttbar->Draw("sames");
266 sig->Draw("sames");
267 data->Draw("pe1sames");
268 }
269 else {
270 data->SetMaximum(maximumData * 2.5);
271 if(log==1) data->SetMinimum(0.0001);
272 if(log==0) data->SetMinimum(0.);
273 data->Draw("pe1");
274 mc->Draw("sames");
275 other->Draw("sames");
276 ttbar->Draw("sames");
277 sig->Draw("sames");
278 data->Draw("pe1 sames");
279
280 }
281
282
283 gStyle->SetOptStat(00000000);
284 stat=0;
285 if(stat) gStyle->SetOptStat(1111111);
286
287
288
289 /* TPaveText *TITLE = new TPaveText(0.2,0.65,0.55,0.9,"blNDC");
290 TITLE->SetFillStyle(4000);
291 TITLE->SetFillColor(kWhite);
292 TITLE->SetBorderSize(0.1);
293 TITLE->SetTextFont(42);
294 TITLE->AddText(firstline);
295 TITLE->Draw(); */
296
297 if(!movepave) {
298 TPaveText *title = new TPaveText(0.2,0.7,0.55,0.93,"blNDC");
299 } else {
300 // TPaveText *title = new TPaveText(0.6,0.58,0.95,0.83,"blNDC");
301 TPaveText *title = new TPaveText(0.6,0.7,0.95,0.93,"blNDC");
302 }
303 title->SetFillStyle(4000);
304 title->SetFillColor(kWhite);
305 title->SetBorderSize(0.1);
306 title->SetTextFont(42);
307 title->AddText(firstline);
308 title->AddText(secondline);
309 // title->AddText(cut1);
310 // title->AddText(cut2);
311 title->Draw();
312 if(!movepave) {
313 TLegend *leg = new TLegend(0.65,0.83,1.,0.93);
314 } else {
315 TLegend *leg = new TLegend(0.60,0.53,1.,0.7);
316 }
317 leg->SetFillStyle(4000);
318 leg->SetFillColor(kWhite);
319 leg->SetBorderSize(0.1);
320 leg->SetTextFont(42);
321 leg->AddEntry(data,dataTitle,"p"); //p
322 leg->AddEntry(mc,mcTitle,"f");
323 leg->AddEntry(other,otherTitle,"f");
324 leg->AddEntry(ttbar,ttbarTitle,"f");
325 leg->AddEntry(sig,mcSigTitle, "f");
326 leg->Draw();
327
328 c->Modified();
329 c->Update();
330
331
332 if(stat){
333 TPaveStats * ps = (TPaveStats *) mc->GetListOfFunctions()->FindObject("stats");
334 TPaveStats * ps2 = (TPaveStats *) data->GetListOfFunctions()->FindObject("stats");
335 TPaveStats * ps3 = (TPaveStats *) sig->GetListOfFunctions()->FindObject("stats");
336 Int_t ci;
337 ci = TColor::GetColor(col);
338 // Data
339 ps2->SetY1NDC(0.45);
340 ps2->SetY2NDC(0.59);
341 ps2->SetX1NDC(0.80);
342 ps2->SetX2NDC(0.97);
343 if( ps ){
344 ps->SetTextColor(col);
345 ps->SetFillStyle(0);
346 ps->SetLineColor(col);
347 }
348 else std::cout << "Null pointer to TPaveStats: " << ps << std::endl;
349 // MC Background
350 ps->SetY1NDC(0.30);
351 ps->SetY2NDC(0.44);
352 ps->SetX1NDC(0.80);
353 ps->SetX2NDC(0.97);
354 if( ps2 ) {
355 ps2->SetTextColor(ci);
356 ps2->SetFillStyle(0);
357 }
358 else std::cout << "Null pointer to TPaveStats: " << ps2 << std::endl;
359 // MC Signal
360 ps3->SetY1NDC(0.15);
361 ps3->SetY2NDC(0.29);
362 ps3->SetX1NDC(0.80);
363 ps3->SetX2NDC(0.97);
364 if( ps3 ) {
365 ps3->SetTextColor(46);
366 ps3->SetLineColor(46);
367 ps3->SetFillStyle(0);
368 }
369 else std::cout << "Null pointer to TPaveStats: " << ps3 << std::endl;
370
371 }
372
373
374 }