20 #include <TVirtualPad.h>
29 using std::stringstream;
34 gStyle->SetOptStat(
"rm");
36 gStyle->SetOptTitle(0);
38 gStyle->SetCanvasColor(kWhite);
39 gStyle->SetFrameFillColor(kWhite);
40 gStyle->SetFrameBorderMode(0);
41 gStyle->SetPadColor(kWhite);
42 gStyle->SetStatColor(kWhite);
43 gStyle->SetTitleFillColor(kWhite);
44 gStyle->SetPalette(55, 0);
52 const string& drawOpt,
59 hist->SetLineColor(color);
60 hist->SetLineWidth(lineWidth);
61 hist->SetLineStyle(lineStyle);
62 hist->SetMarkerColor(color);
63 hist->SetMarkerSize(markerSize);
64 hist->SetMarkerStyle(markerStyle);
65 if (logx ==
kLog) { gPad->SetLogx(); }
66 if (logy ==
kLog) { gPad->SetLogy(); }
67 hist->GetXaxis()->SetLabelSize(textSize);
68 hist->GetXaxis()->SetNdivisions(505, kTRUE);
69 hist->GetYaxis()->SetLabelSize(textSize);
70 hist->GetXaxis()->SetTitleSize(textSize);
71 hist->GetYaxis()->SetTitleSize(textSize);
72 hist->GetXaxis()->SetTitleOffset(1.0);
73 hist->GetYaxis()->SetTitleOffset(1.3);
74 gPad->SetLeftMargin(0.17);
75 gPad->SetBottomMargin(0.15);
76 gPad->SetTopMargin(0.12);
78 hist->Draw(drawOpt.c_str());
79 gPad->SetGrid(
true,
true);
80 hist->SetStats(
false);
88 const string& drawOpt) {
90 if (logx ==
kLog) { gPad->SetLogx(); }
91 if (logy ==
kLog) { gPad->SetLogy(); }
92 if (logz ==
kLog) { gPad->SetLogz(); }
93 hist->GetXaxis()->SetLabelSize(textSize);
94 hist->GetXaxis()->SetNdivisions(505, kTRUE);
95 hist->GetYaxis()->SetLabelSize(textSize);
96 hist->GetYaxis()->SetNdivisions(505, kTRUE);
97 hist->GetZaxis()->SetLabelSize(textSize);
99 hist->GetXaxis()->SetTitleSize(textSize);
100 hist->GetYaxis()->SetTitleSize(textSize);
101 hist->GetZaxis()->SetTitleSize(textSize);
102 hist->GetXaxis()->SetTitleOffset(1.0);
103 hist->GetYaxis()->SetTitleOffset(1.3);
104 hist->GetZaxis()->SetTitleOffset(1.5);
105 gPad->SetLeftMargin(0.17);
106 gPad->SetRightMargin(0.30);
107 gPad->SetBottomMargin(0.15);
108 gPad->SetTicks(1, 1);
109 hist->Draw(drawOpt.c_str());
110 gPad->SetGrid(
true,
true);
111 hist->SetStats(
false);
116 const vector<string>& histLabels,
124 const string& drawOpt) {
125 assert(histos.size() != 0 && histLabels.size() == histos.size());
127 UInt_t nofHistos = histos.size();
128 TLegend* legend =
new TLegend(x1, y1, x2, y2);
129 legend->SetFillColor(kWhite);
130 for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
131 TH1* hist = histos[iHist];
132 string opt = (iHist == 0) ? drawOpt
133 : (iHist == nofHistos - 1) ?
"SAME" + drawOpt
145 legend->AddEntry(hist, histLabels[iHist].c_str(),
"lp");
147 histos[0]->SetMaximum(
max * 1.17);
148 if (drawLegend) { legend->Draw(); }
154 const string& drawOpt,
161 graph->SetLineColor(color);
162 graph->SetLineWidth(lineWidth);
163 graph->SetLineStyle(lineStyle);
164 graph->SetMarkerColor(color);
165 graph->SetMarkerSize(markerSize);
166 graph->SetMarkerStyle(markerStyle);
167 if (drawOpt.find(
"A") != string::npos) {
168 if (logx ==
kLog) { gPad->SetLogx(); }
169 if (logy ==
kLog) { gPad->SetLogy(); }
170 graph->GetXaxis()->SetLabelSize(textSize);
171 graph->GetXaxis()->SetNdivisions(505, kTRUE);
172 graph->GetYaxis()->SetLabelSize(textSize);
173 graph->GetXaxis()->SetTitleSize(textSize);
174 graph->GetYaxis()->SetTitleSize(textSize);
175 graph->GetXaxis()->SetTitleOffset(1.0);
176 graph->GetYaxis()->SetTitleOffset(1.3);
178 gPad->SetLeftMargin(0.17);
179 gPad->SetBottomMargin(0.15);
180 graph->Draw(drawOpt.c_str());
181 gPad->SetGrid(
true,
true);
187 const vector<string>& graphLabels,
195 assert(graphs.size() != 0 && graphs.size() == graphLabels.size());
199 TLegend* legend =
new TLegend(x1, y1, x2, y2);
200 legend->SetFillColor(kWhite);
201 UInt_t nofGraphs = graphs.size();
202 for (UInt_t iGraph = 0; iGraph < nofGraphs; iGraph++) {
203 TGraph* graph = graphs[iGraph];
204 string opt = (iGraph == 0) ?
"ACP" :
"CP";
216 legend->AddEntry(graph, graphLabels[iGraph].c_str(),
"lp");
218 graphs[0]->SetMaximum(
max);
219 graphs[0]->SetMinimum(
min);
220 if (drawLegend) { legend->Draw(); }
228 const string& drawOpt) {
230 if (logx ==
kLog) { gPad->SetLogx(); }
231 if (logy ==
kLog) { gPad->SetLogy(); }
232 if (logz ==
kLog) { gPad->SetLogz(); }
233 graph->GetXaxis()->SetLabelSize(textSize);
234 graph->GetXaxis()->SetNdivisions(505, kTRUE);
235 graph->GetYaxis()->SetLabelSize(textSize);
236 graph->GetYaxis()->SetNdivisions(505, kTRUE);
237 graph->GetZaxis()->SetLabelSize(textSize);
239 graph->GetXaxis()->SetTitleSize(textSize);
240 graph->GetYaxis()->SetTitleSize(textSize);
241 graph->GetZaxis()->SetTitleSize(textSize);
242 graph->GetXaxis()->SetTitleOffset(1.0);
243 graph->GetYaxis()->SetTitleOffset(1.3);
244 graph->GetZaxis()->SetTitleOffset(1.7);
245 gPad->SetLeftMargin(0.17);
246 gPad->SetRightMargin(0.2);
247 gPad->SetBottomMargin(0.15);
248 gPad->SetTicks(1, 1);
249 graph->Draw(drawOpt.c_str());
250 gPad->SetGrid(
true,
true);
258 TLegend* leg =
new TLegend(x1, y1, x2, y2);
259 leg->AddEntry(
new TH2D(), text.c_str(),
"");
260 leg->SetFillColor(kWhite);
261 leg->SetFillStyle(0);
262 leg->SetBorderSize(0);
269 Double_t userRangeMin,
270 Double_t userRangeMax) {
271 if (hist ==
nullptr)
return;
273 hist->GetYaxis()->SetTitle(
"Yield (a.u.)");
275 if (doScale) hist->Scale(1. / hist->Integral());
276 if (!(userRangeMin == 0. && userRangeMax == 0.))
277 hist->GetXaxis()->SetRangeUser(userRangeMin, userRangeMax);
278 hist->Fit(
"gaus",
"Q");
279 TF1* func = hist->GetFunction(
"gaus");
280 if (func ==
nullptr)
return;
281 func->SetLineColor(kBlack);
285 double m = func->GetParameter(1);
286 double s = func->GetParameter(2);
287 string txt1 = Cbm::NumberToString<Double_t>(
m, 2) +
" / "
288 + Cbm::NumberToString<Double_t>(s, 2);
290 text.SetTextAlign(21);
291 text.SetTextSize(0.06);
292 text.DrawTextNDC(0.5, 0.92, txt1.c_str());
299 const string& drawOpt2D,
301 Int_t profileLineWidth) {
302 if (hist ==
nullptr)
return;
314 (TH1D*) hist->ProjectionX((
string(hist->GetName()) +
"_mean").c_str())
316 string yTitle = (doGaussFit) ?
"Mean and sigma. " :
"Mean and RMS. ";
317 hMean->GetYaxis()->SetTitle(
318 (yTitle +
string(hist->GetYaxis()->GetTitle())).c_str());
319 for (Int_t
i = 1;
i <= hist->GetXaxis()->GetNbins();
i++) {
321 ss << string(hist->GetName()) <<
"_py" <<
i;
322 TH1D* pr = hist->ProjectionY(ss.str().c_str(),
i,
i);
323 if (hMean ==
nullptr || pr ==
nullptr)
continue;
325 Double_t
m = 0., s = 0.;
327 pr->Fit(
"gaus",
"QO");
328 TF1* func = pr->GetFunction(
"gaus");
329 if (func !=
nullptr) {
330 m = func->GetParameter(1);
331 s = func->GetParameter(2);
338 hMean->SetBinContent(
i,
m);
340 hMean->SetBinError(
i, s);
342 hMean->SetBinError(
i, 0.);
374 Int_t nBinsX =
h->GetNbinsX();
375 Int_t nBinsY =
h->GetNbinsY();
376 TH2D* h2 = (TH2D*)
h->Project3D(
"yx")->Clone();
378 for (Int_t
x = 1;
x <= nBinsX;
x++) {
379 for (Int_t
y = 1;
y <= nBinsY;
y++) {
381 ss <<
h->GetName() <<
"_z_" <<
x <<
"_" <<
y;
382 TH1D* hz =
h->ProjectionZ(ss.str().c_str(),
x,
x,
y,
y);
385 hz->Fit(
"gaus",
"QO");
386 TF1* func = hz->GetFunction(
"gaus");
387 if (func !=
nullptr) {
388 ms = (drawMean) ? func->GetParameter(1) : func->GetParameter(2);
391 ms = (drawMean) ? hz->GetMean() : hz->GetRMS();
393 h2->SetBinContent(
x,
y, ms);
397 string zAxisTitle = string(
h->GetZaxis()->GetTitle());
398 string sigmaRms = (doGaussFit) ?
"Sigma." :
"RMS.";
399 zAxisTitle = (drawMean) ?
"Mean." + zAxisTitle : sigmaRms + zAxisTitle;
401 h2->GetZaxis()->SetTitle(zAxisTitle.c_str());
402 if (zMin < zMax) h2->GetZaxis()->SetRangeUser(zMin, zMax);