Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
Loading...
Searching...
No Matches
PlottingUtils.hpp
Go to the documentation of this file.
1#ifndef PLOTTINGUTILS_H
2#define PLOTTINGUTILS_H
3
4#include <TCanvas.h>
5#include <TF1.h>
6#include <TGaxis.h>
7#include <TGraph.h>
8#include <TGraphErrors.h>
9#include <TH1.h>
10#include <TH2.h>
11#include <TLatex.h>
12#include <TLegend.h>
13#include <TMath.h>
14#include <TPad.h>
15#include <TROOT.h>
16#include <TRandom3.h>
17#include <TStyle.h>
18#include <TSystem.h>
19#include <iostream>
20#include <vector>
21
28
30enum class PlotSaveFormat {
33};
34
48public:
64 static void
66
71 static void ConfigureAndDrawGraph(TGraph *graph, Int_t color,
72 const TString title = "");
73
78 static void ConfigureAndDrawHistogram(TH1 *hist, Int_t color,
79 const TString title = "");
80
85 static void ConfigureAndDraw2DHistogram(TH2 *hist, TCanvas *canvas,
86 const TString title = "");
87
98 static void ConfigureGraph(TGraph *graph, Int_t color,
99 const TString title = "");
100
111 static void ConfigureGraph(TGraphErrors *graph, Int_t color,
112 const TString title = "");
113
125 static void ConfigureHistogram(TH1 *hist, Int_t color,
126 const TString title = "");
127
138 static void Configure2DHistogram(TH2 *hist, TCanvas *canvas,
139 const TString title = "");
140
151 static TCanvas *GetConfiguredCanvas(Bool_t logy = kFALSE);
152
178 static void SaveFigure(TCanvas *canvas, TString output_filename,
179 TString output_subdirectory = "",
181
192 static void SetPlotsBaseDir(const TString &dir);
193
196 static TString GetPlotsBaseDir();
197
222 static void
223 PlotFitWithResiduals(TH1 *hist, TGraph *total_graph,
224 const std::vector<TGraph *> &component_graphs,
225 Float_t fit_range_low, Float_t fit_range_high,
226 const TString &output_name,
227 const TString &output_subdirectory = "fits",
228 const TString &label = "", Bool_t logy = kTRUE);
229
244 static TLegend *AddLegend(Double_t x1 = 0.7, Double_t x2 = 0.9,
245 Double_t y1 = 0.7, Double_t y2 = 0.9);
246
260 static TLatex *AddText(const TString label, Double_t x = 0.9,
261 Double_t y = 0.85, Double_t angle = 0);
262
265 static std::vector<Int_t> GetDefaultColors();
266
275 static TString GetRandomName();
276
279 static Width_t GetLineWidth() { return line_width_; };
280
281private:
282 static PlotSaveFormat save_format_;
283 static Bool_t preferences_set_;
284 static Width_t line_width_;
285 static TString plots_base_dir_;
286 static void SetTurboPalette();
287 static void WarnIfNotConfigured(const TString method_name);
288 static void PlotPullHistogram(TGraph *residuals, const TString &output_name,
289 const TString &output_subdirectory);
290};
291
292#endif
PlotSaveOptions
Which axis scalings SaveFigure() should write out.
@ kBOTH
Both, as two separate files.
@ kLOG
Logarithmic y only, written with a log_ filename prefix.
@ kLINEAR
Linear y only.
PlotSaveFormat
Output file format for saved figures.
@ kPNG
PNG raster output; line width 2.
@ kPDF
PDF vector output; line width 1.
All-static helpers for publication-quality ROOT graphics.
static TLatex * AddText(const TString label, Double_t x=0.9, Double_t y=0.85, Double_t angle=0)
Create and draw a text annotation on the current pad.
static void ConfigureAndDrawGraph(TGraph *graph, Int_t color, const TString title="")
ConfigureGraph() followed by Draw().
static TLegend * AddLegend(Double_t x1=0.7, Double_t x2=0.9, Double_t y1=0.7, Double_t y2=0.9)
Create, style and draw a legend on the current pad.
static void SaveFigure(TCanvas *canvas, TString output_filename, TString output_subdirectory="", PlotSaveOptions save_options=PlotSaveOptions::kBOTH)
Write a canvas to disk under the configured plots base directory.
static void SetPlotsBaseDir(const TString &dir)
Set the base directory that saved figures are written under.
static TString GetRandomName()
Generate a name unlikely to collide with existing ROOT objects.
static void ConfigureGraph(TGraph *graph, Int_t color, const TString title="")
Apply the house style to a graph without drawing it.
static void SetStylePreferences(PlotSaveFormat save_format=PlotSaveFormat::kPNG)
Install the global ROOT style and choose the output format.
static void Configure2DHistogram(TH2 *hist, TCanvas *canvas, const TString title="")
Apply the house style to a 2-D histogram and its canvas.
static void ConfigureAndDrawHistogram(TH1 *hist, Int_t color, const TString title="")
ConfigureHistogram() followed by Draw("HIST").
static void ConfigureHistogram(TH1 *hist, Int_t color, const TString title="")
Apply the house style to a 1-D histogram without drawing it.
static TCanvas * GetConfiguredCanvas(Bool_t logy=kFALSE)
Create a 1200x800 canvas with grid and ticks already set up.
static Width_t GetLineWidth()
Line width the Configure* methods apply.
static void PlotFitWithResiduals(TH1 *hist, TGraph *total_graph, const std::vector< TGraph * > &component_graphs, Float_t fit_range_low, Float_t fit_range_high, const TString &output_name, const TString &output_subdirectory="fits", const TString &label="", Bool_t logy=kTRUE)
Draw a fit over its data with a residual panel and save it.
static std::vector< Int_t > GetDefaultColors()
A palette of visually distinct ROOT colour indices.
static void ConfigureAndDraw2DHistogram(TH2 *hist, TCanvas *canvas, const TString title="")
Configure2DHistogram() followed by Draw("COLZ").
static TString GetPlotsBaseDir()
Current base directory for saved figures, without trailing slash.