ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/rootEWKanalyzer/plotDataMCwSignal.C
Revision: 1.3
Committed: Mon Sep 20 14:23:15 2010 UTC (14 years, 7 months ago) by jueugste
Content type: text/plain
Branch: MAIN
Changes since 1.2: +29 -11 lines
Log Message:
Update (plus EWK and HWW analysis added)

File Contents

# User Rev Content
1 jueugste 1.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 jueugste 1.2 TFile *mc = TFile::Open("QCD_bckgd.root");
10     TFile *mcOther = TFile::Open("other_bckgd.root");
11     TFile *mcTTbar = TFile::Open("TTbar_bckgd.root");
12 jueugste 1.1 TFile *mcSignal = TFile::Open("mcSignal.root");
13    
14     char *legDataTitle = "Data";//"Signal, W #rightarrow e #nu";
15 jueugste 1.2 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 jueugste 1.1 TString dataset="";
20     TString overallTitle="CMS preliminary 2010";
21 jueugste 1.3 TString CMen="#sqrt{s}=7TeV, #int L = 890 nb^{-1}";
22 jueugste 1.1 TString cuts1="";
23 jueugste 1.3 Tstring cuts2="";
24     double rebin=1.;
25 jueugste 1.1 bool isptplot;
26 jueugste 1.3
27     bool normalizeToArea=false;
28    
29 jueugste 1.1 //---------------------------------------------------------------------------
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 jueugste 1.2 int islog=0;
57    
58     int index=0;
59 jueugste 1.1
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 jueugste 1.3 islog=0;
84 jueugste 1.1 // 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;
85     TH1D * h_data= data->Get(key->GetName());
86     TH1D * h_mc=mc->Get(key->GetName());
87 jueugste 1.2 TH1D * h_other=mcOther->Get(key->GetName());
88     TH1D * h_ttbar=mcTTbar->Get(key->GetName());
89 jueugste 1.1 TH1D * h_sig=mcSignal->Get(key->GetName());
90     // only for filled histos
91     // if( h_mc->GetEntries()!=0) {
92     //
93 jueugste 1.2
94    
95     // cout<<"here"<<endl;
96    
97 jueugste 1.1 h_data->SetTitle(overallTitle);
98     h_mc->SetTitle(overallTitle);
99 jueugste 1.2 h_other->SetTitle(overallTitle);
100     h_ttbar->SetTitle(overallTitle);
101 jueugste 1.1 h_sig->SetTitle(overallTitle);
102     // if(name.Index(pt)>-1) {
103     // h_data->SetYTitle("Jets/GeV");
104     // h_mc->SetYTitle("Jets/GeV");
105     // isptplot=true;
106     // // cout << h_data->GetXaxis()->GetBinWidth(1)<< endl;
107     // }
108     // if(name.Index(eta)>-1||name.Index(phi)>-1) {
109     // h_data->SetYTitle("Jets");
110     // h_mc->SetYTitle("Jets");
111     // }
112     // if(name.Index(dphi)>-1) {
113     // h_data->SetYTitle("Events");
114     // h_mc->SetYTitle("Events");
115     // }
116     // if(name.Index(mass)>-1){
117     // h_data->SetYTitle("Events/GeV");
118     // h_mc->SetYTitle("Events/GeV");
119     isptplot=true;
120     // }
121    
122     TCanvas *c = new TCanvas("c","",600,600);
123     double scalefactor;
124     // if(h_mc->Integral()!=0) {
125     // scalefactor=h_data->Integral()/h_mc->Integral();
126     // }
127     // else {scalefactor=1;}
128     // cout<<"scale factor: "<<scalefactor<<endl;
129    
130    
131     // if (isptplot) {
132     // // 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!
133     // // h_data->Sumw2();
134     // for(int j=0 ; j<=h_mc->GetNbinsX(); ++j){
135     // h_data->SetBinError(j,sqrt(h_data->GetBinContent(j))/h_data->GetBinWidth(j));
136     // //
137     // h_mc->SetBinContent(j,h_mc->GetBinContent(j)/h_mc->GetBinWidth(j));
138     // h_data->SetBinContent(j,h_data->GetBinContent(j)/h_data->GetBinWidth(j));
139     // }
140     // }
141    
142    
143    
144     // h_mc->Scale(scalefactor);
145 jueugste 1.3 h_mc->Rebin(rebin);
146     h_sig->Rebin(rebin);
147     h_data->Rebin(rebin);
148    
149 jueugste 1.1 // h_mc->SetMaximum(1.5*h_data->GetMaximum());
150    
151    
152     h_mc->SetFillColor(colour);
153 jueugste 1.2 h_mc->SetLineColor(1);
154     h_other->SetFillColor(8);
155     h_other->SetLineColor(1);
156     h_ttbar->SetFillColor(15);
157     h_ttbar->SetLineColor(1);
158 jueugste 1.1 h_sig->SetFillColor(46);
159 jueugste 1.2 h_sig->SetLineColor(1);
160 jueugste 1.1 h_data->SetMarkerStyle(20);
161 jueugste 1.2
162 jueugste 1.1
163     // h_data->SetTitle(overallTitle);
164     // h_mc->SetTitle(overallTitle);
165     // std::cout << "Plotting: " << key->GetName() << std::endl;
166     // h_mc->SetMinimum(0.01);
167     // h_data->SetMinimum(0.01);
168    
169 jueugste 1.2
170    
171 jueugste 1.1 //draw title
172 jueugste 1.3 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);
173 jueugste 1.2
174 jueugste 1.1 char histname [256];
175 jueugste 1.2 sprintf (histname, "plotting/%s.gif", key->GetName());
176     // cout<<key->GetName()<<endl;
177     char test [256];//="s_El_ElCharge_";
178     // index++;
179     sprintf (test, "%s%i", "s_El_ElCharge_",index);
180     // cout<<test<<endl;
181     if(!strcmp(key->GetName(),test)) {
182     index++;
183     continue;
184     }
185     c->Print(histname);
186     // cout<<"here2"<<endl;
187    
188 jueugste 1.1 delete c;
189 jueugste 1.2
190    
191 jueugste 1.1 // } //if Entries != 0
192     } // loop over keys
193    
194    
195     // cout << "------ Calo Jets --------" <<endl;
196     // TH1D * temp =data->Get("dijetptall");
197     // cout << "CaloJets " << temp->GetEntries() <<endl;
198     // TH1D *temp2 =data->Get("dijetptallJIDloose");
199     // cout << "Loose CaloJets " << temp2->GetEntries() <<endl;
200     // TH1D *temp3 =data->Get("dijetptallJIDtight");
201     // cout << "Tight CaloJets " << temp3->GetEntries() <<endl;
202    
203     // cout << "------ PF Jets --------" <<endl;
204     // TH1D * temp5 =data->Get("diPFjetptall");
205     // cout << "PFJets " << temp5->GetEntries() <<endl;
206     // TH1D *temp6 =data->Get("diPFjetptallJIDloose");
207     // cout << "Loose PFJets " << temp6->GetEntries() <<endl;
208     // TH1D *temp7 =data->Get("diPFjetptallJIDtight");
209     // cout << "Tight PFJets " << temp7->GetEntries() <<endl;
210    
211     // cout << "------ JPT Jets --------" <<endl;
212     // TH1D * temp8 =data->Get("diJPTjetptall");
213     // cout << "JPTJets " << temp8->GetEntries() <<endl;
214     // TH1D *temp9 =data->Get("diJPTjetptallJIDloose");
215     // cout << "Loose JPTJets " << temp9->GetEntries() <<endl;
216     // TH1D *temp10 =data->Get("diJPTjetptallJIDtight");
217     // cout << "Tight JPTJets " << temp10->GetEntries() <<endl;
218     }
219    
220    
221    
222     //-------------------------------------------------------------------------------------
223 jueugste 1.3 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){
224 jueugste 1.1
225     c->SetLogy(log);
226    
227 jueugste 1.3 if(normalizeToArea) {
228     double S=sig->Integral();
229     double N=mc->Integral();
230     double f=1;
231     if(N!=0) f = S/N;
232     mc->Scale(f);
233     other->Scale(f);
234     ttbar->Scale(f);
235     sig->Scale(f);
236     }
237    
238    
239    
240 jueugste 1.1 // maximumData;
241     // double maximumMc;
242     int maximumData=data->GetBinContent(data->GetMaximumBin());
243 jueugste 1.2 int maximumMc=mc->GetBinContent(mc->GetMaximumBin());
244    
245    
246    
247 jueugste 1.1
248     // if(data->GetBinContent(data->GetMaximum())<mc->GetBinContent(mc->GetMaximum())) {
249     if(maximumData<maximumMc) {
250 jueugste 1.3 // sig->SetMaximum(maximumMc * 2.5);
251     mc->SetMaximum(maximumMc * 2.5);
252 jueugste 1.2 if(log==1) sig->SetMinimum(0.0001);
253     if(log==0) sig->SetMinimum(0.);
254     mc->Draw("");
255     other->Draw("sames");
256     ttbar->Draw("sames");
257     sig->Draw("sames");
258 jueugste 1.1 data->Draw("pe1sames");
259     }
260     else {
261 jueugste 1.3 data->SetMaximum(maximumData * 2.5);
262 jueugste 1.2 if(log==1) data->SetMinimum(0.0001);
263     if(log==0) data->SetMinimum(0.);
264 jueugste 1.1 data->Draw("pe1");
265 jueugste 1.2 mc->Draw("sames");
266     other->Draw("sames");
267     ttbar->Draw("sames");
268 jueugste 1.1 sig->Draw("sames");
269 jueugste 1.2 data->Draw("pe1 sames");
270 jueugste 1.1
271     }
272    
273    
274     gStyle->SetOptStat(00000000);
275 jueugste 1.2 stat=0;
276 jueugste 1.1 if(stat) gStyle->SetOptStat(1111111);
277    
278    
279    
280     /* TPaveText *TITLE = new TPaveText(0.2,0.65,0.55,0.9,"blNDC");
281     TITLE->SetFillStyle(4000);
282     TITLE->SetFillColor(kWhite);
283     TITLE->SetBorderSize(0.1);
284     TITLE->SetTextFont(42);
285     TITLE->AddText(firstline);
286     TITLE->Draw(); */
287    
288     if(!movepave) {
289     TPaveText *title = new TPaveText(0.2,0.7,0.55,0.93,"blNDC");
290     } else {
291     // TPaveText *title = new TPaveText(0.6,0.58,0.95,0.83,"blNDC");
292     TPaveText *title = new TPaveText(0.6,0.7,0.95,0.93,"blNDC");
293     }
294     title->SetFillStyle(4000);
295     title->SetFillColor(kWhite);
296     title->SetBorderSize(0.1);
297     title->SetTextFont(42);
298     title->AddText(firstline);
299     title->AddText(secondline);
300     // title->AddText(cut1);
301     // title->AddText(cut2);
302     title->Draw();
303     if(!movepave) {
304     TLegend *leg = new TLegend(0.65,0.83,1.,0.93);
305     } else {
306 jueugste 1.2 TLegend *leg = new TLegend(0.60,0.53,1.,0.7);
307 jueugste 1.1 }
308     leg->SetFillStyle(4000);
309     leg->SetFillColor(kWhite);
310     leg->SetBorderSize(0.1);
311     leg->SetTextFont(42);
312     leg->AddEntry(data,dataTitle,"p"); //p
313     leg->AddEntry(mc,mcTitle,"f");
314 jueugste 1.2 leg->AddEntry(other,otherTitle,"f");
315     leg->AddEntry(ttbar,ttbarTitle,"f");
316 jueugste 1.1 leg->AddEntry(sig,mcSigTitle, "f");
317     leg->Draw();
318    
319     c->Modified();
320     c->Update();
321    
322    
323     if(stat){
324     TPaveStats * ps = (TPaveStats *) mc->GetListOfFunctions()->FindObject("stats");
325     TPaveStats * ps2 = (TPaveStats *) data->GetListOfFunctions()->FindObject("stats");
326     TPaveStats * ps3 = (TPaveStats *) sig->GetListOfFunctions()->FindObject("stats");
327     Int_t ci;
328     ci = TColor::GetColor(col);
329     // Data
330     ps2->SetY1NDC(0.45);
331     ps2->SetY2NDC(0.59);
332     ps2->SetX1NDC(0.80);
333     ps2->SetX2NDC(0.97);
334     if( ps ){
335     ps->SetTextColor(col);
336     ps->SetFillStyle(0);
337     ps->SetLineColor(col);
338     }
339     else std::cout << "Null pointer to TPaveStats: " << ps << std::endl;
340     // MC Background
341     ps->SetY1NDC(0.30);
342     ps->SetY2NDC(0.44);
343     ps->SetX1NDC(0.80);
344     ps->SetX2NDC(0.97);
345     if( ps2 ) {
346     ps2->SetTextColor(ci);
347     ps2->SetFillStyle(0);
348     }
349     else std::cout << "Null pointer to TPaveStats: " << ps2 << std::endl;
350     // MC Signal
351     ps3->SetY1NDC(0.15);
352     ps3->SetY2NDC(0.29);
353     ps3->SetX1NDC(0.80);
354     ps3->SetX2NDC(0.97);
355     if( ps3 ) {
356     ps3->SetTextColor(46);
357     ps3->SetLineColor(46);
358     ps3->SetFillStyle(0);
359     }
360     else std::cout << "Null pointer to TPaveStats: " << ps3 << std::endl;
361    
362     }
363 jueugste 1.2
364    
365 jueugste 1.1 }