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