25using std::stringstream;
29 gStyle->SetOptStat(
"erm");
31 gStyle->SetOptTitle(0);
33 gStyle->SetCanvasColor(kWhite);
34 gStyle->SetFrameFillColor(kWhite);
35 gStyle->SetFrameBorderMode(0);
36 gStyle->SetPadColor(kWhite);
37 gStyle->SetStatColor(kWhite);
38 gStyle->SetTitleFillColor(kWhite);
39 gStyle->SetPalette(77);
47 const string& drawOpt,
55 hist->SetLineColor(lineColor);
56 hist->SetLineWidth(lineWidth);
57 hist->SetLineStyle(lineStyle);
58 hist->SetMarkerColor(lineColor);
59 hist->SetMarkerSize(markerSize);
60 hist->SetMarkerStyle(markerStyle);
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);
77 if (fillColor > 0) hist->SetFillColor(fillColor);
78 hist->Draw(drawOpt.c_str());
79 gPad->SetGrid(
true,
true);
89 const string& drawOpt) {
100 hist->GetXaxis()->SetLabelSize(textSize);
101 hist->GetXaxis()->SetNdivisions(505, kTRUE);
102 hist->GetYaxis()->SetLabelSize(textSize);
103 hist->GetYaxis()->SetNdivisions(505, kTRUE);
104 hist->GetZaxis()->SetLabelSize(textSize);
106 hist->GetXaxis()->SetTitleSize(textSize);
107 hist->GetYaxis()->SetTitleSize(textSize);
108 hist->GetZaxis()->SetTitleSize(textSize);
109 hist->GetXaxis()->SetTitleOffset(1.0);
110 hist->GetYaxis()->SetTitleOffset(1.3);
111 hist->GetZaxis()->SetTitleOffset(1.5);
112 gPad->SetLeftMargin(0.17);
113 gPad->SetRightMargin(0.30);
114 gPad->SetBottomMargin(0.15);
115 gPad->SetTicks(1, 1);
116 hist->Draw(drawOpt.c_str());
117 gPad->SetGrid(
true,
true);
118 hist->SetStats(
true);
123 const vector<TH1*>& histos,
124 const vector<string>& histLabels,
132 const string& drawOpt,
133 Bool_t outputMeanValue01) {
134 assert(histos.size() != 0 && histLabels.size() == histos.size());
135 Double_t
max = std::numeric_limits<Double_t>::min();
136 Int_t nofHistos = histos.size();
137 TLegend* legend =
new TLegend(x1, y1, x2, y2);
138 legend->SetFillColor(kWhite);
139 for (Int_t iHist = 0; iHist < nofHistos; iHist++) {
140 TH1* hist = histos[iHist];
141 string opt = (iHist == 0) ? drawOpt : (iHist == nofHistos - 1) ?
"SAME" + drawOpt :
"SAME" + drawOpt;
145 max = std::max(
max, hist->GetMaximum());
146 Int_t nonZeroBins = 0;
147 for (Int_t
i = 0;
i < hist->GetNbinsX(); ++
i) {
148 if (hist->GetBinContent(
i) != 0.0) nonZeroBins++;
151 Double_t xMax = hist->GetBinCenter(hist->GetNbinsX());
153 Int_t nGev = Int_t(hist->GetNbinsX() * xGev / xMax);
154 Double_t effAll = hist->Integral() / nonZeroBins;
155 Double_t eff01 = hist->Integral(0.0, nGev) / nGev;
157 if (outputMeanValue01) legText = TString::Format(
"%s | mean = %3.1f | mean01 = %3.1f", histLabels[iHist].c_str(), effAll, eff01).Data();
158 else legText = TString::Format(
"%s | mean = %3.1f", histLabels[iHist].c_str(), effAll).Data();
159 legend->AddEntry(hist, legText,
"lp");
161 FILE*
f = fopen(
"test.dat",
"a+");
162 if (((TString) hist->GetName()).Contains(
"vs_P")) fprintf(
f,
"%s %s %f %f\n", hist->GetName(), histLabels[iHist].c_str(), effAll, eff01);
165 histos[0]->SetMaximum(
max * 1.10);
230 Float_t minX = hist->GetXaxis()->GetXmin();
231 Float_t maxX = hist->GetXaxis()->GetXmax();
232 Int_t nonZeroBins = 0;
233 for (Int_t
i = 0;
i < hist->GetNbinsX(); ++
i) {
234 if (hist->GetBinContent(
i) != 0.0) nonZeroBins++;
236 TLine* line =
new TLine(minX, hist->Integral() / nonZeroBins, maxX, hist->Integral() / nonZeroBins);
237 line->SetLineWidth(2);
238 line->SetLineColor(hist->GetLineColor());
246 const string& drawOpt,
253 graph->SetLineColor(color);
254 graph->SetLineWidth(lineWidth);
255 graph->SetLineStyle(lineStyle);
256 graph->SetMarkerColor(color);
257 graph->SetMarkerSize(markerSize);
258 graph->SetMarkerStyle(markerStyle);
259 if (drawOpt.find(
"A") != string::npos) {
266 graph->GetXaxis()->SetLabelSize(textSize);
267 graph->GetXaxis()->SetNdivisions(505, kTRUE);
268 graph->GetYaxis()->SetLabelSize(textSize);
269 graph->GetXaxis()->SetTitleSize(textSize);
270 graph->GetYaxis()->SetTitleSize(textSize);
271 graph->GetXaxis()->SetTitleOffset(1.0);
272 graph->GetYaxis()->SetTitleOffset(1.3);
274 gPad->SetLeftMargin(0.17);
275 gPad->SetBottomMargin(0.15);
276 graph->Draw(drawOpt.c_str());
277 gPad->SetGrid(
true,
true);
282 const vector<TGraph*>& graphs,
283 const vector<string>& graphLabels,
291 assert(graphs.size() != 0 && graphs.size() == graphLabels.size());
293 Double_t
max = std::numeric_limits<Double_t>::min();
294 Double_t
min = std::numeric_limits<Double_t>::max();
295 TLegend* legend =
new TLegend(x1, y1, x2, y2);
296 legend->SetFillColor(kWhite);
297 Int_t nofGraphs = graphs.size();
298 for (Int_t iGraph = 0; iGraph < nofGraphs; iGraph++) {
299 TGraph* graph = graphs[iGraph];
300 string opt = (iGraph == 0) ?
"ACP" :
"CP";
303 max = std::max(graph->GetYaxis()->GetXmax(),
max);
304 min = std::min(graph->GetYaxis()->GetXmin(),
min);
305 legend->AddEntry(graph, graphLabels[iGraph].c_str(),
"lp");
307 graphs[0]->SetMaximum(
max);
308 graphs[0]->SetMinimum(
min);
320 const string& drawOpt) {
331 graph->GetXaxis()->SetLabelSize(textSize);
332 graph->GetXaxis()->SetNdivisions(505, kTRUE);
333 graph->GetYaxis()->SetLabelSize(textSize);
334 graph->GetYaxis()->SetNdivisions(505, kTRUE);
335 graph->GetZaxis()->SetLabelSize(textSize);
337 graph->GetXaxis()->SetTitleSize(textSize);
338 graph->GetYaxis()->SetTitleSize(textSize);
339 graph->GetZaxis()->SetTitleSize(textSize);
340 graph->GetXaxis()->SetTitleOffset(1.0);
341 graph->GetYaxis()->SetTitleOffset(1.3);
342 graph->GetZaxis()->SetTitleOffset(1.5);
343 gPad->SetLeftMargin(0.17);
344 gPad->SetRightMargin(0.30);
345 gPad->SetBottomMargin(0.15);
346 gPad->SetTicks(1, 1);
347 graph->Draw(drawOpt.c_str());
348 gPad->SetGrid(
true,
true);
void DrawH1(TH1 *hist, HistScale logx, HistScale logy, const string &drawOpt, Int_t lineColor, Int_t lineWidth, Int_t lineStyle, Float_t markerSize, Int_t markerStyle, Int_t fillColor)
void SetDefaultDrawStyle()
void DrawH2(TH2 *hist, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
void DrawMeanLine(TH1 *hist)
void DrawGraph2D(TGraph2D *graph, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
void DrawGraph(TGraph *graph, HistScale logx, HistScale logy, const string &drawOpt, Int_t color, Int_t lineWidth, Int_t lineStyle, Int_t markerSize, Int_t markerStyle)
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Helper functions for drawing 1D and 2D histograms and graphs.
static Int_t LineStyle(Int_t lineStyleIndex)
static Double_t TextSize()
static Int_t Color(Int_t colorIndex)
static Int_t MarkerStyle(Int_t markerIndex)
static Float_t MarkerSize()
HistScale
Define linear or logarithmic scale for drawing.