|
Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
|
All-static helpers for publication-quality ROOT graphics. More...
#include <PlottingUtils.hpp>
Static Public Member Functions | |
| static void | SetStylePreferences (PlotSaveFormat save_format=PlotSaveFormat::kPNG) |
| Install the global ROOT style and choose the output format. | |
| static void | ConfigureAndDrawGraph (TGraph *graph, Int_t color, const TString title="") |
| ConfigureGraph() followed by Draw(). | |
| static void | ConfigureAndDrawHistogram (TH1 *hist, Int_t color, const TString title="") |
| ConfigureHistogram() followed by Draw("HIST"). | |
| static void | ConfigureAndDraw2DHistogram (TH2 *hist, TCanvas *canvas, const TString title="") |
| Configure2DHistogram() followed by Draw("COLZ"). | |
| static void | ConfigureGraph (TGraph *graph, Int_t color, const TString title="") |
| Apply the house style to a graph without drawing it. | |
| static void | ConfigureGraph (TGraphErrors *graph, Int_t color, const TString title="") |
| Apply the house style to a graph with error bars. | |
| static void | ConfigureHistogram (TH1 *hist, Int_t color, const TString title="") |
| Apply the house style to a 1-D histogram without drawing it. | |
| static void | Configure2DHistogram (TH2 *hist, TCanvas *canvas, const TString title="") |
| Apply the house style to a 2-D histogram and its canvas. | |
| static TCanvas * | GetConfiguredCanvas (Bool_t logy=kFALSE) |
| Create a 1200x800 canvas with grid and ticks already set up. | |
| 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 | GetPlotsBaseDir () |
| Current base directory for saved figures, without trailing slash. | |
| 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 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 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 std::vector< Int_t > | GetDefaultColors () |
| A palette of visually distinct ROOT colour indices. | |
| static TString | GetRandomName () |
| Generate a name unlikely to collide with existing ROOT objects. | |
| static Width_t | GetLineWidth () |
| Line width the Configure* methods apply. | |
All-static helpers for publication-quality ROOT graphics.
No instantiation is required or possible in practice — every member is static. SetStylePreferences() must be called before anything else; the other methods print a warning to stdout if it has not been, but still run.
Definition at line 47 of file PlottingUtils.hpp.
|
static |
Create, style and draw a legend on the current pad.
| x1 | Left edge, in NDC (0-1). |
| x2 | Right edge, in NDC (0-1). |
| y1 | Bottom edge, in NDC (0-1). |
| y2 | Top edge, in NDC (0-1). |
Definition at line 242 of file PlottingUtils.cpp.
|
static |
Create and draw a text annotation on the current pad.
Useful for subplot labels such as "(a)" and "(b)", or any free annotation. The text is right-top aligned at the given point.
| label | Text to draw. ROOT TLatex markup is honoured. |
| x | Horizontal position, in NDC (0-1). |
| y | Vertical position, in NDC (0-1). |
| angle | Rotation in degrees, counter-clockwise. 0 by default. |
Definition at line 254 of file PlottingUtils.cpp.
Referenced by PlotFitWithResiduals().
|
static |
Apply the house style to a 2-D histogram and its canvas.
Styles the axes as for the 1-D case, then enables log-z on canvas and widens its right margin to 0.15 to make room for the colour axis.
| hist | Histogram to configure. Null is tolerated and ignored. |
| canvas | Canvas to adjust. Null is tolerated and ignored. |
| title | Histogram title, in the usual ROOT "title;x;y;z" form. |
Definition at line 109 of file PlottingUtils.cpp.
Referenced by ConfigureAndDraw2DHistogram().
|
static |
Configure2DHistogram() followed by Draw("COLZ").
No-op if null.
| hist | 2-D histogram to configure and draw. |
| canvas | Canvas whose log-z and right margin are adjusted. |
| title | Histogram title, in the usual ROOT "title;x;y;z" form. |
Definition at line 151 of file PlottingUtils.cpp.
|
static |
ConfigureGraph() followed by Draw().
No-op if graph is null.
| graph | Graph to configure and draw onto the current pad. |
| color | ROOT colour index for the line. |
| title | Graph title, in the usual ROOT "title;x;y" form. |
Definition at line 133 of file PlottingUtils.cpp.
|
static |
ConfigureHistogram() followed by Draw("HIST").
No-op if null.
| hist | Histogram to configure and draw onto the current pad. |
| color | ROOT colour index for the line. |
| title | Histogram title, in the usual ROOT "title;x;y" form. |
Definition at line 142 of file PlottingUtils.cpp.
|
static |
Apply the house style to a graph without drawing it.
Sets line colour and width, 0.06 axis title and label sizes, 1.2 title offsets, and 506 x-axis divisions.
| graph | Graph to configure. Must not be null. |
| color | ROOT colour index for the line. |
| title | Graph title, in the usual ROOT "title;x;y" form. |
Definition at line 53 of file PlottingUtils.cpp.
Referenced by ConfigureAndDrawGraph(), and WaveformProcessingUtils::SaveSampleWaveform().
|
static |
Apply the house style to a graph with error bars.
As the TGraph overload, plus marker style 20 at size 1.2 in the same colour as the line — the usual look for a data series with uncertainties.
| graph | Graph to configure. Must not be null. |
| color | ROOT colour index for both line and markers. |
| title | Graph title, in the usual ROOT "title;x;y" form. |
Definition at line 68 of file PlottingUtils.cpp.
|
static |
Apply the house style to a 1-D histogram without drawing it.
Sets line colour and width, hollow fill, 0.06 axis title and label sizes, 1.2 title offsets, and axis divisions tuned for spectra. The x axis is forced out of exponent notation.
| hist | Histogram to configure. Null is tolerated and ignored. |
| color | ROOT colour index for the line. |
| title | Histogram title, in the usual ROOT "title;x;y" form. |
Definition at line 86 of file PlottingUtils.cpp.
Referenced by ConfigureAndDrawHistogram().
|
static |
Create a 1200x800 canvas with grid and ticks already set up.
| logy | kTRUE to start with a logarithmic y axis. |
Definition at line 162 of file PlottingUtils.cpp.
Referenced by PlotFitWithResiduals(), and WaveformProcessingUtils::SaveSampleWaveform().
|
static |
A palette of visually distinct ROOT colour indices.
Definition at line 234 of file PlottingUtils.cpp.
|
inlinestatic |
Line width the Configure* methods apply.
Definition at line 279 of file PlottingUtils.hpp.
Referenced by FittingUtils::PlotFitDoublePeak(), RooFitUtils::PlotFitDoublePeak(), FittingUtils::PlotFitSinglePeak(), RooFitUtils::PlotFitSinglePeak(), FittingUtils::PlotFitTriplePeak(), and RooFitUtils::PlotFitTriplePeak().
|
static |
Current base directory for saved figures, without trailing slash.
Definition at line 15 of file PlottingUtils.cpp.
Referenced by SaveFigure(), and InitUtils::SetROOTPreferences().
|
static |
Generate a name unlikely to collide with existing ROOT objects.
ROOT keeps named objects in global lists and warns (or misbehaves) on duplicate names; this sidesteps that for throwaway canvases.
Definition at line 267 of file PlottingUtils.cpp.
Referenced by RooFitUtils::BuildDisplayHistogramFrom(), and GetConfiguredCanvas().
|
static |
Draw a fit over its data with a residual panel and save it.
Produces a two-pad figure: the histogram with the total fit and each component overlaid on top (70% of the height), and a pull panel beneath (30%) marked with dashed guide lines at ±3σ. The displayed x range is padded 10% either side of the fit range.
| hist | Data histogram. Must not be null. |
| total_graph | Curve for the summed model. |
| component_graphs | One curve per model component; may be empty. |
| fit_range_low | Lower fit bound, in the histogram's x units. |
| fit_range_high | Upper fit bound, in the histogram's x units. |
| output_name | Base filename, without extension. |
| output_subdirectory | Subdirectory under the plots base. "fits" by default. |
| label | Optional annotation drawn on the plot; empty draws nothing. |
| logy | kTRUE (default) for a logarithmic y axis on the upper pad. |
Definition at line 274 of file PlottingUtils.cpp.
Referenced by FittingUtils::PlotFitDoublePeak(), RooFitUtils::PlotFitDoublePeak(), FittingUtils::PlotFitSinglePeak(), RooFitUtils::PlotFitSinglePeak(), FittingUtils::PlotFitTriplePeak(), and RooFitUtils::PlotFitTriplePeak().
|
static |
Write a canvas to disk under the configured plots base directory.
The file lands in <plots_base>/ or <plots_base>/<subdirectory>/, with the extension chosen by SetStylePreferences(). Missing directories are created. For PlotSaveOptions::kLOG and PlotSaveOptions::kBOTH the log-y variant is written with a log_ filename prefix.
| canvas | Canvas to save. Must not be null. |
| output_filename | Base filename, without extension. |
| output_subdirectory | Subdirectory under the plots base; empty means the base itself. |
| save_options | Which axis scalings to write. PlotSaveOptions::kBOTH by default. |
Definition at line 176 of file PlottingUtils.cpp.
Referenced by PlotFitWithResiduals(), and WaveformProcessingUtils::SaveSampleWaveform().
|
static |
Set the base directory that saved figures are written under.
| dir | Base directory. Pass an absolute path so output is anchored to a project root regardless of the current working directory. Trailing slashes are stripped. |
Definition at line 8 of file PlottingUtils.cpp.
Referenced by InitUtils::SetROOTPreferences().
|
static |
Install the global ROOT style and choose the output format.
Sets gStyle globally: no stat or fit box, 0.06 axis title and label sizes, 1.2 title offsets, grids on in a light grey dashed style, ticks on both axes, and a 255-colour turbo palette for 2-D colour scales. Also fixes the line width used by the Configure* methods — 2 for PNG, 1 for PDF.
| save_format | Output format for SaveFigure(). Defaults to PlotSaveFormat::kPNG. |
Definition at line 23 of file PlottingUtils.cpp.
Referenced by WaveformProcessingUtils::SaveSampleWaveform(), and InitUtils::SetROOTPreferences().