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

File Contents

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