1 |
#include "CPlot.hh"
|
2 |
#include <TLatex.h>
|
3 |
|
4 |
CPlot::CPlot()
|
5 |
{
|
6 |
TString name = "plot";
|
7 |
name += sCount;
|
8 |
CPlot(name,"","","");
|
9 |
}
|
10 |
|
11 |
CPlot::CPlot(TString name, TString title, TString xtitle, TString ytitle):
|
12 |
fStack(0),
|
13 |
fName(name),
|
14 |
fTitle(title),
|
15 |
fXTitle(xtitle),
|
16 |
fYTitle(ytitle),
|
17 |
fXmin(0),
|
18 |
fXmax(0),
|
19 |
fYmin(0),
|
20 |
fYmax(0),
|
21 |
fLogx(0),
|
22 |
fLogy(0),
|
23 |
fGridx(0),
|
24 |
fGridy(0),
|
25 |
fRebin(1),
|
26 |
fLeg(0),
|
27 |
fShowStats(0),
|
28 |
fStatsX(0.68),
|
29 |
fStatsY(0.90),
|
30 |
fRooPlot(0)
|
31 |
{
|
32 |
sCount++;
|
33 |
}
|
34 |
|
35 |
CPlot::CPlot(TString name, RooPlot* frame, TString title, TString xtitle, TString ytitle):
|
36 |
fStack(0),
|
37 |
fName(name),
|
38 |
fTitle(title),
|
39 |
fXTitle(xtitle),
|
40 |
fYTitle(ytitle),
|
41 |
fXmin(0),
|
42 |
fXmax(0),
|
43 |
fYmin(0),
|
44 |
fYmax(0),
|
45 |
fLogx(0),
|
46 |
fLogy(0),
|
47 |
fGridx(0),
|
48 |
fGridy(0),
|
49 |
fRebin(1),
|
50 |
fLeg(0),
|
51 |
fShowStats(0),
|
52 |
fStatsX(0.68),
|
53 |
fStatsY(0.90),
|
54 |
fRooPlot(frame)
|
55 |
{
|
56 |
fRooPlot->SetTitle(title);
|
57 |
fRooPlot->GetXaxis()->SetTitle(xtitle);
|
58 |
fRooPlot->GetYaxis()->SetTitle(ytitle);
|
59 |
sCount++;
|
60 |
}
|
61 |
|
62 |
|
63 |
//--------------------------------------------------------------------------------------------------
|
64 |
void CPlot::AddHist1D(TH1F *h, TString drawopt, int color, int linesty, int fillsty)
|
65 |
{
|
66 |
if(!h)
|
67 |
return;
|
68 |
|
69 |
h->SetLineColor(color);
|
70 |
h->SetLineStyle(linesty);
|
71 |
h->SetFillColor(color);
|
72 |
h->SetFillStyle(fillsty);
|
73 |
|
74 |
if(drawopt.CompareTo("E",TString::kIgnoreCase)==0)
|
75 |
h->SetMarkerSize(0.9);
|
76 |
|
77 |
CPlotItem item;
|
78 |
item.hist1D = h;
|
79 |
item.drawopt = drawopt;
|
80 |
fItems.push_back(item);
|
81 |
}
|
82 |
|
83 |
void CPlot::AddHist1D(TH1F *h, TString label, TString drawopt, int color, int linesty, int fillsty)
|
84 |
{
|
85 |
if(!h)
|
86 |
return;
|
87 |
|
88 |
if(!fLeg)
|
89 |
fLeg = new TLegend(0.6,0.84,0.93,0.9);
|
90 |
else
|
91 |
fLeg->SetY1(fLeg->GetY1()-0.06);
|
92 |
|
93 |
if(drawopt.CompareTo("E",TString::kIgnoreCase)==0) {
|
94 |
//fLeg->AddEntry(h,label,"P");
|
95 |
fLeg->AddEntry(h,label,"PL");
|
96 |
h->SetMarkerSize(0.9);
|
97 |
} else {
|
98 |
if(fillsty>0) fLeg->AddEntry(h,label,"F");
|
99 |
else fLeg->AddEntry(h,label,"L");
|
100 |
}
|
101 |
|
102 |
AddHist1D(h,drawopt,color,linesty,fillsty);
|
103 |
}
|
104 |
|
105 |
void CPlot::AddHist1D(TFile *f, TString histName, TString drawopt, int color, int linesty, int fillsty)
|
106 |
{
|
107 |
if(!f)
|
108 |
return;
|
109 |
|
110 |
TH1F *h = (TH1F*)f->FindObjectAny(histName);
|
111 |
AddHist1D(h,drawopt,color,linesty,fillsty);
|
112 |
}
|
113 |
|
114 |
void CPlot::AddHist1D(TFile *f, TString histName, TString label, TString drawopt, int color, int linesty, int fillsty)
|
115 |
{
|
116 |
if(!f)
|
117 |
return;
|
118 |
|
119 |
TH1F *h = (TH1F*)f->FindObjectAny(histName);
|
120 |
AddHist1D(h,label,drawopt,color,linesty,fillsty);
|
121 |
}
|
122 |
|
123 |
//--------------------------------------------------------------------------------------------------
|
124 |
void CPlot::AddToStack(TH1F *h, int color)
|
125 |
{
|
126 |
if(!h)
|
127 |
return;
|
128 |
|
129 |
if(!fStack)
|
130 |
fStack = new THStack(fName+TString("_stack"),"");
|
131 |
|
132 |
fStack->Add(h);
|
133 |
AddHist1D(h,"",color,1,1001);
|
134 |
}
|
135 |
|
136 |
void CPlot::AddToStack(TH1F *h, TString label, int color)
|
137 |
{
|
138 |
if(!h)
|
139 |
return;
|
140 |
|
141 |
if(!fStack)
|
142 |
fStack = new THStack(fName+TString("_stack"),"");
|
143 |
|
144 |
if(!fLeg)
|
145 |
fLeg = new TLegend(0.6,0.84,0.93,0.9);
|
146 |
else
|
147 |
fLeg->SetY1(fLeg->GetY1()-0.06);
|
148 |
|
149 |
// make legend entries appear in reverse of the order the histograms are added
|
150 |
fStackEntries.push_back(fLeg->AddEntry(h,label,"F"));
|
151 |
for(Int_t ientry=(fStackEntries.size()-2); ientry>=0; ientry--) {
|
152 |
TObject* hh = fStackEntries[ientry]->GetObject();
|
153 |
TString ll = fStackEntries[ientry]->GetLabel();
|
154 |
fStackEntries[ientry+1]->SetObject(hh);
|
155 |
fStackEntries[ientry+1]->SetLabel(ll);
|
156 |
}
|
157 |
fStackEntries[0]->SetObject(h);
|
158 |
fStackEntries[0]->SetLabel(label);
|
159 |
|
160 |
fStack->Add(h);
|
161 |
AddHist1D(h,"",color,1,1001);
|
162 |
}
|
163 |
|
164 |
void CPlot::AddToStack(TFile *f, TString histName, int color)
|
165 |
{
|
166 |
if(!f)
|
167 |
return;
|
168 |
|
169 |
TH1F *h = (TH1F*)f->FindObjectAny(histName);
|
170 |
AddToStack(h,color);
|
171 |
}
|
172 |
|
173 |
void CPlot::AddToStack(TFile *f, TString histName, TString label, int color)
|
174 |
{
|
175 |
if(!f)
|
176 |
return;
|
177 |
|
178 |
TH1F *h = (TH1F*)f->FindObjectAny(histName);
|
179 |
AddToStack(h,label,color);
|
180 |
}
|
181 |
|
182 |
//--------------------------------------------------------------------------------------------------
|
183 |
void CPlot::AddHist2D(TH2F *h, TString drawopt, int fillcolor, int linecolor)
|
184 |
{
|
185 |
if(!h)
|
186 |
return;
|
187 |
|
188 |
h->SetLineColor(linecolor);
|
189 |
h->SetFillColor(fillcolor);
|
190 |
h->SetMarkerStyle(kFullDotMedium);
|
191 |
|
192 |
CPlotItem item;
|
193 |
item.hist2D = h;
|
194 |
item.drawopt = drawopt;
|
195 |
fItems.push_back(item);
|
196 |
}
|
197 |
|
198 |
void CPlot::AddHist2D(TFile *f, TString histName, TString drawopt, int fillcolor, int linecolor)
|
199 |
{
|
200 |
if(!f)
|
201 |
return;
|
202 |
|
203 |
TH2F *h = (TH2F*)f->FindObjectAny(histName);
|
204 |
AddHist2D(h,drawopt,linecolor,fillcolor);
|
205 |
}
|
206 |
|
207 |
//--------------------------------------------------------------------------------------------------
|
208 |
void CPlot::AddGraph(TGraph *gr, TString drawopt, int color, int marksty, int linesty)
|
209 |
{
|
210 |
if(!gr)
|
211 |
return;
|
212 |
|
213 |
gr->SetMarkerColor(color);
|
214 |
gr->SetLineColor(color);
|
215 |
gr->SetLineStyle(linesty);
|
216 |
gr->SetLineWidth(2);
|
217 |
gr->SetMarkerStyle(marksty);
|
218 |
gr->SetMarkerSize(1.2);
|
219 |
|
220 |
CPlotItem item;
|
221 |
item.graph = gr;
|
222 |
item.drawopt = drawopt;
|
223 |
fItems.push_back(item);
|
224 |
}
|
225 |
|
226 |
void CPlot::AddGraph(TGraph *gr, TString label, TString drawopt, int color, int marksty, int linesty)
|
227 |
{
|
228 |
if(!gr)
|
229 |
return;
|
230 |
|
231 |
if(!fLeg)
|
232 |
fLeg = new TLegend(0.6,0.84,0.93,0.9);
|
233 |
else
|
234 |
fLeg->SetY1(fLeg->GetY1()-0.06);
|
235 |
if( (drawopt.Contains("L",TString::kIgnoreCase)==0) ||
|
236 |
(drawopt.Contains("C",TString::kIgnoreCase)==0) ) {
|
237 |
fLeg->AddEntry(gr,label,"LP");
|
238 |
} else {
|
239 |
fLeg->AddEntry(gr,label,"P");
|
240 |
}
|
241 |
|
242 |
AddGraph(gr,drawopt,color,marksty,linesty);
|
243 |
}
|
244 |
|
245 |
void CPlot::AddGraph(TFile *f, TString grName, TString drawopt, int color, int marksty, int linesty)
|
246 |
{
|
247 |
if(!f)
|
248 |
return;
|
249 |
|
250 |
TGraph *gr = (TGraph*)f->FindObjectAny(grName);
|
251 |
AddGraph(gr,drawopt,color,marksty,linesty);
|
252 |
}
|
253 |
|
254 |
void CPlot::AddGraph(TFile *f, TString grName, TString label, TString drawopt, int color, int marksty, int linesty)
|
255 |
{
|
256 |
if(!f)
|
257 |
return;
|
258 |
|
259 |
TGraph *gr = (TGraph*)f->FindObjectAny(grName);
|
260 |
AddGraph(gr,label,drawopt,color,marksty,linesty);
|
261 |
}
|
262 |
|
263 |
//--------------------------------------------------------------------------------------------------
|
264 |
void CPlot::AddProfile(TProfile *pr, TString drawopt, int color, int marksty, int linesty)
|
265 |
{
|
266 |
if(!pr)
|
267 |
return;
|
268 |
|
269 |
pr->SetMarkerColor(color);
|
270 |
pr->SetLineColor(color);
|
271 |
pr->SetLineStyle(linesty);
|
272 |
pr->SetLineWidth(2);
|
273 |
pr->SetMarkerStyle(marksty);
|
274 |
pr->SetMarkerSize(1.2);
|
275 |
|
276 |
CPlotItem item;
|
277 |
item.prof = pr;
|
278 |
item.drawopt = drawopt;
|
279 |
fItems.push_back(item);
|
280 |
}
|
281 |
|
282 |
void CPlot::AddProfile(TProfile *pr, TString label, TString drawopt, int color, int marksty, int linesty)
|
283 |
{
|
284 |
if(!pr)
|
285 |
return;
|
286 |
|
287 |
if(!fLeg)
|
288 |
fLeg = new TLegend(0.6,0.84,0.93,0.9);
|
289 |
else
|
290 |
fLeg->SetY1(fLeg->GetY1()-0.06);
|
291 |
|
292 |
fLeg->AddEntry(pr,label,"LP");
|
293 |
|
294 |
AddProfile(pr,drawopt,color,marksty,linesty);
|
295 |
}
|
296 |
|
297 |
void CPlot::AddProfile(TFile *f, TString prName, TString drawopt, int color, int marksty, int linesty)
|
298 |
{
|
299 |
if(!f)
|
300 |
return;
|
301 |
|
302 |
TProfile *pr = (TProfile*)f->FindObjectAny(prName);
|
303 |
AddProfile(pr,drawopt,color,marksty,linesty);
|
304 |
}
|
305 |
|
306 |
void CPlot::AddProfile(TFile *f, TString prName, TString label, TString drawopt, int color, int marksty, int linesty)
|
307 |
{
|
308 |
if(!f)
|
309 |
return;
|
310 |
|
311 |
TProfile *pr = (TProfile*)f->FindObjectAny(prName);
|
312 |
AddProfile(pr,label,drawopt,color,marksty,linesty);
|
313 |
}
|
314 |
|
315 |
|
316 |
//--------------------------------------------------------------------------------------------------
|
317 |
void CPlot::AddTextBox(TString text, double x1, double y1, double x2, double y2,
|
318 |
int bordersize, int textcolor, int fillcolor)
|
319 |
{
|
320 |
TPaveText *tb = new TPaveText(x1,y1,x2,y2,"NDC");
|
321 |
tb->SetTextColor(textcolor);
|
322 |
if(fillcolor==-1)
|
323 |
tb->SetFillStyle(0);
|
324 |
else
|
325 |
tb->SetFillColor(fillcolor);
|
326 |
tb->SetBorderSize(bordersize);
|
327 |
tb->AddText(text);
|
328 |
fTextBoxes.push_back(tb);
|
329 |
}
|
330 |
|
331 |
void CPlot::AddTextBox(double x1, double y1, double x2, double y2,
|
332 |
int bordersize, int textcolor, int fillcolor, int nlines,...)
|
333 |
{
|
334 |
TPaveText *tb = new TPaveText(x1,y1,x2,y2,"NDC");
|
335 |
tb->SetTextColor(textcolor);
|
336 |
if(fillcolor==-1)
|
337 |
tb->SetFillStyle(0);
|
338 |
else
|
339 |
tb->SetFillColor(fillcolor);
|
340 |
tb->SetBorderSize(bordersize);
|
341 |
tb->SetTextAlign(12);
|
342 |
|
343 |
va_list ap;
|
344 |
va_start(ap,nlines);
|
345 |
for(int i=0; i<nlines; i++) {
|
346 |
TString textline(va_arg(ap,char*));
|
347 |
tb->AddText(textline);
|
348 |
}
|
349 |
va_end(ap);
|
350 |
|
351 |
fTextBoxes.push_back(tb);
|
352 |
}
|
353 |
|
354 |
//--------------------------------------------------------------------------------------------------
|
355 |
void CPlot::AddLine(double x1, double y1, double x2, double y2, int color, int style)
|
356 |
{
|
357 |
TLine *line = new TLine(x1,y1,x2,y2);
|
358 |
line->SetLineColor(color);
|
359 |
line->SetLineStyle(style);
|
360 |
line->SetLineWidth(2);
|
361 |
fLines.push_back(line);
|
362 |
}
|
363 |
|
364 |
void CPlot::AddLine(double x1, double y1, double x2, double y2,
|
365 |
int color, int style, TString label)
|
366 |
{
|
367 |
TLine *line = new TLine(x1,y1,x2,y2);
|
368 |
line->SetLineColor(color);
|
369 |
line->SetLineStyle(style);
|
370 |
line->SetLineWidth(2);
|
371 |
fLines.push_back(line);
|
372 |
|
373 |
if(!fLeg)
|
374 |
fLeg = new TLegend(0.6,0.84,0.93,0.9);
|
375 |
else
|
376 |
fLeg->SetY1(fLeg->GetY1()-0.06);
|
377 |
fLeg->AddEntry(line,label,"L");
|
378 |
}
|
379 |
|
380 |
//--------------------------------------------------------------------------------------------------
|
381 |
void CPlot::AddBox(double x1, double y1, double x2, double y2,
|
382 |
int linecolor, int linesty, int fillcolor)
|
383 |
{
|
384 |
TBox *box = new TBox(x1,y1,x2,y2);
|
385 |
box->SetLineColor(linecolor);
|
386 |
box->SetLineStyle(linesty);
|
387 |
if(fillcolor==-1)
|
388 |
box->SetFillStyle(0);
|
389 |
else
|
390 |
box->SetFillColor(fillcolor);
|
391 |
box->SetLineWidth(2);
|
392 |
fBoxes.push_back(box);
|
393 |
}
|
394 |
|
395 |
void CPlot::AddBox(double x1, double y1, double x2, double y2,
|
396 |
int linecolor, int linesty, int fillcolor, TString label)
|
397 |
{
|
398 |
TBox *box = new TBox(x1,y1,x2,y2);
|
399 |
box->SetLineColor(linecolor);
|
400 |
box->SetLineStyle(linesty);
|
401 |
if(fillcolor==-1)
|
402 |
box->SetFillStyle(0);
|
403 |
else
|
404 |
box->SetFillColor(fillcolor);
|
405 |
box->SetLineWidth(2);
|
406 |
fBoxes.push_back(box);
|
407 |
|
408 |
if(!fLeg)
|
409 |
fLeg = new TLegend(0.6,0.84,0.93,0.9);
|
410 |
else
|
411 |
fLeg->SetY1(fLeg->GetY1()-0.06);
|
412 |
|
413 |
if(fillcolor<0) fLeg->AddEntry(box,label,"L");
|
414 |
else fLeg->AddEntry(box,label,"F");
|
415 |
}
|
416 |
|
417 |
//--------------------------------------------------------------------------------------------------
|
418 |
void CPlot::AddFcn(TF1* fcn, int color, int linesty)
|
419 |
{
|
420 |
if(!fcn)
|
421 |
return;
|
422 |
|
423 |
fcn->SetLineColor(color);
|
424 |
fcn->SetLineStyle(linesty);
|
425 |
fFcns.push_back(fcn);
|
426 |
}
|
427 |
|
428 |
void CPlot::AddFcn(TF1* fcn, TString label, int color, int linesty)
|
429 |
{
|
430 |
if(!fcn)
|
431 |
return;
|
432 |
|
433 |
if(!fLeg)
|
434 |
fLeg = new TLegend(0.6,0.84,0.93,0.9);
|
435 |
else
|
436 |
fLeg->SetY1(fLeg->GetY1()-0.06);
|
437 |
fLeg->AddEntry(fcn,label,"L");
|
438 |
|
439 |
AddFcn(fcn,color,linesty);
|
440 |
}
|
441 |
|
442 |
//--------------------------------------------------------------------------------------------------
|
443 |
void CPlot::Draw(TCanvas *c, bool doSave, TString format)
|
444 |
{
|
445 |
c->cd();
|
446 |
|
447 |
c->SetLogy(0);
|
448 |
c->SetLogx(0);
|
449 |
|
450 |
if(!fItems.size() && !fRooPlot)
|
451 |
return;
|
452 |
|
453 |
if(fRooPlot) {
|
454 |
fRooPlot->Draw();
|
455 |
}
|
456 |
|
457 |
int nHist1D=0, nHist2D=0, nGraph=0, nProf=0;
|
458 |
for(uint i=0; i<fItems.size(); i++) {
|
459 |
if(fItems[i].hist1D != 0) nHist1D++;
|
460 |
if(fItems[i].hist2D != 0) nHist2D++;
|
461 |
if(fItems[i].graph != 0) nGraph++;
|
462 |
if(fItems[i].prof != 0) nProf++;
|
463 |
}
|
464 |
|
465 |
//
|
466 |
// Draw 2D histogram, save if necessary, then exit
|
467 |
// Suggested options for:
|
468 |
// contour plot -> "CONT4Z"
|
469 |
// lego plot -> "LEGO1 0"
|
470 |
// color plot -> "COLZ"
|
471 |
// Default is scatter plot
|
472 |
//
|
473 |
if(nHist2D>0) {
|
474 |
for(uint i=0; i<fItems.size(); i++) {
|
475 |
if(fItems[i].hist2D==0) continue;
|
476 |
|
477 |
fItems[i].hist2D->Draw(fItems[i].drawopt);
|
478 |
fItems[i].hist2D->SetTitle(fTitle);
|
479 |
fItems[i].hist2D->GetXaxis()->SetTitle(fXTitle);
|
480 |
fItems[i].hist2D->GetYaxis()->SetTitle(fYTitle);
|
481 |
|
482 |
//
|
483 |
// Set log scale if necessary
|
484 |
//
|
485 |
c->SetLogx(fLogx);
|
486 |
c->SetLogy(fLogy);
|
487 |
|
488 |
for(uint k=0; k<fLines.size(); k++)
|
489 |
fLines[k]->Draw();
|
490 |
|
491 |
for(uint k=0; k<fBoxes.size(); k++)
|
492 |
fBoxes[k]->Draw();
|
493 |
|
494 |
for(uint j=0; j<fTextBoxes.size(); j++)
|
495 |
fTextBoxes[j]->Draw();
|
496 |
|
497 |
if(doSave) {
|
498 |
gSystem->mkdir(sOutDir,true);
|
499 |
TString outname = sOutDir+TString("/")+fName+TString(".");
|
500 |
if(format.CompareTo("all",TString::kIgnoreCase)==0) {
|
501 |
c->SaveAs(outname+TString("png"));
|
502 |
c->SaveAs(outname+TString("eps"));
|
503 |
c->SaveAs(outname+TString("C"));
|
504 |
} else {
|
505 |
c->SaveAs(outname+format);
|
506 |
}
|
507 |
}
|
508 |
|
509 |
return;
|
510 |
}
|
511 |
}
|
512 |
|
513 |
//
|
514 |
// Draw 1D histograms
|
515 |
// Histograms are cloned so that content and properties
|
516 |
// of the original histograms are not changed
|
517 |
//
|
518 |
std::vector<TH1F*> vHists;
|
519 |
std::vector<TString> vHistOpts;
|
520 |
if(nHist1D>0) {
|
521 |
|
522 |
double ymax=0;
|
523 |
uint ifirst=0;
|
524 |
|
525 |
for(uint i=0; i<fItems.size(); i++) {
|
526 |
if(fItems[i].hist1D==0) continue;
|
527 |
if(fStack && fStack->GetHists()->Contains(fItems[i].hist1D)) continue;
|
528 |
|
529 |
TString hname = fName;
|
530 |
hname += "_h_";
|
531 |
hname += i;
|
532 |
|
533 |
TH1F *h;
|
534 |
if(fRebin>1)
|
535 |
h = (TH1F*)fItems[i].hist1D->Rebin(fRebin,hname);
|
536 |
else
|
537 |
h = (TH1F*)fItems[i].hist1D->Clone(hname);
|
538 |
|
539 |
if(fXmin < fXmax)
|
540 |
h->GetXaxis()->SetRangeUser(fXmin,fXmax);
|
541 |
|
542 |
if(fYmin < fYmax) {
|
543 |
h->GetYaxis()->SetRangeUser(fYmin,fYmax);
|
544 |
} else {
|
545 |
if(ymax < h->GetMaximum()) {
|
546 |
ymax = h->GetMaximum();
|
547 |
ifirst = vHists.size();
|
548 |
}
|
549 |
}
|
550 |
|
551 |
vHists.push_back(h);
|
552 |
vHistOpts.push_back(fItems[i].drawopt);
|
553 |
}
|
554 |
|
555 |
if(vHists.size()>0) {
|
556 |
vHists[ifirst]->SetTitle(fTitle);
|
557 |
vHists[ifirst]->GetXaxis()->SetTitle(fXTitle);
|
558 |
vHists[ifirst]->GetYaxis()->SetTitle(fYTitle);
|
559 |
vHists[ifirst]->SetLineWidth(2);
|
560 |
vHists[ifirst]->Draw(vHistOpts[ifirst].Data());
|
561 |
}
|
562 |
|
563 |
//
|
564 |
// Draw histogram stack
|
565 |
//
|
566 |
if(fStack) {
|
567 |
if(vHists.size()>0) {
|
568 |
if(fYmin < fYmax) {
|
569 |
fStack->Draw("hist same");
|
570 |
} else {
|
571 |
if(fStack->GetMaximum() > vHists[ifirst]->GetMaximum()) {
|
572 |
fStack->SetTitle(fTitle);
|
573 |
fStack->Draw();
|
574 |
fStack->GetXaxis()->SetTitle(fXTitle);
|
575 |
fStack->GetYaxis()->SetTitle(fYTitle);
|
576 |
fStack->Draw("hist");
|
577 |
} else {
|
578 |
fStack->Draw("hist same");
|
579 |
}
|
580 |
}
|
581 |
|
582 |
} else {
|
583 |
// NOTE: Must draw first before accessing axes
|
584 |
fStack->Draw("hist");
|
585 |
|
586 |
if(fXmin < fXmax)
|
587 |
fStack->GetXaxis()->SetRangeUser(fXmin,fXmax);
|
588 |
|
589 |
if(fYmin < fYmax) {
|
590 |
fStack->SetMaximum(fYmax);
|
591 |
fStack->SetMinimum(fYmin);
|
592 |
}
|
593 |
|
594 |
fStack->SetTitle(fTitle);
|
595 |
fStack->GetXaxis()->SetTitle(fXTitle);
|
596 |
fStack->GetYaxis()->SetTitle(fYTitle);
|
597 |
fStack->Draw("hist");
|
598 |
}
|
599 |
}
|
600 |
|
601 |
for(uint i=0; i<vHists.size(); i++) {
|
602 |
TH1F *h = vHists[i];
|
603 |
h->SetLineWidth(2);
|
604 |
char opt[100];
|
605 |
sprintf(opt,"same%s",vHistOpts[i].Data());
|
606 |
h->Draw(opt);
|
607 |
}
|
608 |
}
|
609 |
|
610 |
//
|
611 |
// Draw graphs
|
612 |
//
|
613 |
std::vector<TGraph*> vGraphs;
|
614 |
std::vector<TString> vGraphOpts;
|
615 |
if(nGraph>0) {
|
616 |
for(uint i=0; i<fItems.size(); i++) {
|
617 |
if(fItems[i].graph==0) continue;
|
618 |
|
619 |
TString grName = fName;
|
620 |
grName += "_gr_";
|
621 |
grName += i;
|
622 |
|
623 |
TGraph *gr = (TGraph*)fItems[i].graph->Clone(grName);
|
624 |
|
625 |
if(fXmin < fXmax)
|
626 |
gr->GetXaxis()->SetLimits(fXmin,fXmax);
|
627 |
// gr->GetXaxis()->SetRangeUser(fXmin,fXmax);
|
628 |
|
629 |
if(fYmin < fYmax)
|
630 |
gr->GetYaxis()->SetRangeUser(fYmin,fYmax);
|
631 |
|
632 |
vGraphs.push_back(gr);
|
633 |
vGraphOpts.push_back(fItems[i].drawopt);
|
634 |
}
|
635 |
|
636 |
if(vHists.size()==0) {
|
637 |
vGraphs[0]->SetTitle(fTitle);
|
638 |
vGraphs[0]->GetXaxis()->SetTitle(fXTitle);
|
639 |
vGraphs[0]->GetYaxis()->SetTitle(fYTitle);
|
640 |
}
|
641 |
|
642 |
for(uint i=0; i<vGraphs.size(); i++) {
|
643 |
TGraph *gr = vGraphs[i];
|
644 |
char opt[100];
|
645 |
(i==0 && nHist1D==0) ? sprintf(opt,"AP%s",vGraphOpts[i].Data()) : sprintf(opt,"P%s",vGraphOpts[i].Data());
|
646 |
gr->Draw(opt);
|
647 |
}
|
648 |
}
|
649 |
|
650 |
//
|
651 |
// Draw profile histograms
|
652 |
//
|
653 |
std::vector<TProfile*> vProfiles;
|
654 |
std::vector<TString> vProfileOpts;
|
655 |
if(nProf>0) {
|
656 |
for(uint i=0; i<fItems.size(); i++) {
|
657 |
if(fItems[i].prof==0) continue;
|
658 |
|
659 |
TString prName = fName;
|
660 |
prName += "_pr_";
|
661 |
prName += i;
|
662 |
|
663 |
TProfile *pr = (TProfile*)fItems[i].prof->Clone(prName);
|
664 |
|
665 |
if(fXmin < fXmax)
|
666 |
pr->GetXaxis()->SetLimits(fXmin,fXmax);
|
667 |
// pr->GetXaxis()->SetRangeUser(fXmin,fXmax);
|
668 |
|
669 |
if(fYmin < fYmax)
|
670 |
pr->GetYaxis()->SetRangeUser(fYmin,fYmax);
|
671 |
|
672 |
vProfiles.push_back(pr);
|
673 |
vProfileOpts.push_back(fItems[i].drawopt);
|
674 |
}
|
675 |
|
676 |
if(vHists.size()==0) {
|
677 |
vProfiles[0]->SetTitle(fTitle);
|
678 |
vProfiles[0]->GetXaxis()->SetTitle(fXTitle);
|
679 |
vProfiles[0]->GetYaxis()->SetTitle(fYTitle);
|
680 |
}
|
681 |
|
682 |
for(uint i=0; i<vProfiles.size(); i++) {
|
683 |
TProfile *pr = vProfiles[i];
|
684 |
char opt[100];
|
685 |
if(i>0 || nHist1D>0 || nGraph>0)
|
686 |
sprintf(opt,"same%s",vProfileOpts[i].Data());
|
687 |
else
|
688 |
sprintf(opt,"%s",vProfileOpts[i].Data());
|
689 |
pr->Draw(opt);
|
690 |
}
|
691 |
}
|
692 |
|
693 |
//
|
694 |
// Draw legend
|
695 |
//
|
696 |
if(fLeg) {
|
697 |
fLeg->SetFillStyle(0);
|
698 |
fLeg->SetBorderSize(0);
|
699 |
fLeg->Draw();
|
700 |
}
|
701 |
|
702 |
//
|
703 |
// Draw statistics box
|
704 |
//
|
705 |
TLatex *stat=0, *sval=0;
|
706 |
if(fShowStats) {
|
707 |
char buffer[20];
|
708 |
stat = new TLatex[3*vHists.size()];
|
709 |
sval = new TLatex[3*vHists.size()];
|
710 |
for(uint i=0; i<vHists.size(); i++) {
|
711 |
int x = fShowStats;
|
712 |
|
713 |
// number of entries
|
714 |
if(x / 100) {
|
715 |
stat[3*i].SetNDC(); stat[3*i].SetTextAlign(13); stat[3*i].SetTextSize(0.03);
|
716 |
stat[3*i].SetText(fStatsX,fStatsY-0.04*(3*i)-0.005*i,"Entries");
|
717 |
stat[3*i].SetTextColor(vHists[i]->GetLineColor());
|
718 |
stat[3*i].Draw();
|
719 |
sprintf(buffer,"%i",int(vHists[i]->Integral()));
|
720 |
sval[3*i].SetNDC(); sval[3*i].SetTextAlign(33); sval[3*i].SetTextSize(0.03);
|
721 |
sval[3*i].SetText(fStatsX+0.25,fStatsY-0.04*(3*i)-0.005*i,buffer);
|
722 |
sval[3*i].SetTextColor(vHists[i]->GetLineColor());
|
723 |
sval[3*i].Draw();
|
724 |
}
|
725 |
|
726 |
// mean
|
727 |
x = x % 100;
|
728 |
if(x / 10) {
|
729 |
stat[3*i+1].SetNDC(); stat[3*i+1].SetTextAlign(13); stat[3*i+1].SetTextSize(0.03);
|
730 |
stat[3*i+1].SetText(fStatsX,fStatsY-0.04*(3*i+1)-0.005*i,"Mean");
|
731 |
stat[3*i+1].SetTextColor(vHists[i]->GetLineColor());
|
732 |
stat[3*i+1].Draw();
|
733 |
sprintf(buffer,"%g",vHists[i]->GetMean());
|
734 |
sval[3*i+1].SetNDC(); sval[3*i+1].SetTextAlign(33); sval[3*i+1].SetTextSize(0.03);
|
735 |
sval[3*i+1].SetText(fStatsX+0.25,fStatsY-0.04*(3*i+1)-0.005*i,buffer);
|
736 |
sval[3*i+1].SetTextColor(vHists[i]->GetLineColor());
|
737 |
sval[3*i+1].Draw();
|
738 |
}
|
739 |
|
740 |
// RMS
|
741 |
x = x % 10;
|
742 |
if(x) {
|
743 |
stat[3*i+2].SetNDC(); stat[3*i+2].SetTextAlign(13); stat[3*i+2].SetTextSize(0.03);
|
744 |
stat[3*i+2].SetText(fStatsX,fStatsY-0.04*(3*i+2)-0.005*i,"RMS");
|
745 |
stat[3*i+2].SetTextColor(vHists[i]->GetLineColor());
|
746 |
stat[3*i+2].Draw();
|
747 |
sprintf(buffer,"%g",vHists[i]->GetRMS());
|
748 |
sval[3*i+2].SetNDC(); sval[3*i+2].SetTextAlign(33); sval[3*i+2].SetTextSize(0.03);
|
749 |
sval[3*i+2].SetText(fStatsX+0.25,fStatsY-0.04*(3*i+2)-0.005*i,buffer);
|
750 |
sval[3*i+2].SetTextColor(vHists[i]->GetLineColor());
|
751 |
sval[3*i+2].Draw();
|
752 |
}
|
753 |
}
|
754 |
}
|
755 |
|
756 |
//
|
757 |
// Draw functions
|
758 |
//
|
759 |
for(uint i=0; i<fFcns.size(); i++)
|
760 |
(i==0 && vHists.size()==0 && vGraphs.size()==0) ? fFcns[i]->Draw() : fFcns[i]->Draw("sameC");
|
761 |
|
762 |
//
|
763 |
// Draw lines
|
764 |
//
|
765 |
for(uint i=0; i<fLines.size(); i++)
|
766 |
fLines[i]->Draw();
|
767 |
|
768 |
//
|
769 |
// Draw Boxes
|
770 |
//
|
771 |
for(uint i=0; i<fBoxes.size(); i++)
|
772 |
fBoxes[i]->Draw();
|
773 |
|
774 |
//
|
775 |
// Draw textboxes
|
776 |
//
|
777 |
for(uint i=0; i<fTextBoxes.size(); i++)
|
778 |
fTextBoxes[i]->Draw();
|
779 |
|
780 |
//
|
781 |
// Set log scale if necessary
|
782 |
//
|
783 |
c->SetLogx(fLogx);
|
784 |
c->SetLogy(fLogy);
|
785 |
|
786 |
//
|
787 |
// Set grid lines if necessary
|
788 |
//
|
789 |
c->SetGridx(fGridx);
|
790 |
c->SetGridy(fGridy);
|
791 |
|
792 |
//
|
793 |
// Save plot if necessary
|
794 |
//
|
795 |
if(doSave) {
|
796 |
gSystem->mkdir(sOutDir,true);
|
797 |
TString outname = sOutDir+TString("/")+fName+TString(".");
|
798 |
if(format.CompareTo("all",TString::kIgnoreCase)==0) {
|
799 |
c->SaveAs(outname+TString("png"));
|
800 |
c->SaveAs(outname+TString("eps"));
|
801 |
c->SaveAs(outname+TString("C"));
|
802 |
} else {
|
803 |
c->SaveAs(outname+format);
|
804 |
}
|
805 |
|
806 |
delete [] stat;
|
807 |
delete [] sval;
|
808 |
// for(uint i=0; i<vHists.size(); i++)
|
809 |
// delete vHists[i];
|
810 |
}
|
811 |
}
|