ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/rootEWKanalyzer/plotDataMCwSignal.C
Revision: 1.1
Committed: Mon Jun 7 14:57:40 2010 UTC (14 years, 11 months ago) by jueugste
Content type: text/plain
Branch: MAIN
Log Message:
first commit

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