ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/rootEWKanalyzer/plotDataMCwSignal.C
Revision: 1.2
Committed: Tue Jul 20 15:32:44 2010 UTC (14 years, 9 months ago) by jueugste
Content type: text/plain
Branch: MAIN
Changes since 1.1: +71 -23 lines
Log Message:
many changes...

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