Analysis-Utilities 26.10.19
C++/ROOT utilities for nuclear measurement data analysis
Loading...
Searching...
No Matches
PlottingUtils Class Reference

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 preferred style to a graph without drawing it.
static void ConfigureGraph (TGraphErrors *graph, Int_t color, const TString title="")
 Apply the preferred style to a graph with error bars.
static void ConfigureHistogram (TH1 *hist, Int_t color, const TString title="")
 Apply the preferred style to a 1-D histogram without drawing it.
static void Configure2DHistogram (TH2 *hist, TCanvas *canvas, const TString title="")
 Apply the preferred 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 TCanvas * GetConfiguredCanvasWithSideLegend (TPad *&plot, TPad *&legend_pad, Int_t legend_width_px=600, Int_t plot_height_px=800, Bool_t logy=kFALSE)
 A canvas with the standard plot area and a legend pad to its right.
static void SplitPadForPanel (TVirtualPad *pad, Int_t panel_height_px, TPad *&upper, TPad *&lower)
 Split a pad into a main pad above and a panel below, leaving the main pad's frame exactly as it would be on its own.
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 Double_t TextWidthPx (const TString &text, Double_t size_px=30.0, Int_t font=43)
 Rendered width of a text in a pixel-sized font.
static Double_t LegendWidthPx (const std::vector< TString > &labels, const TString &header="", Double_t size_px=30.0, Double_t margin=0.25, Double_t padding_px=15.0)
 Width a legend box needs for its labels at AddLegend()'s font.
static Double_t FigureScale (TVirtualPad *pad, Int_t reference_width_px=1200)
 How much larger a pad is than the standard plot area, by width.
static void ScaleFigure (TVirtualPad *pad, Int_t reference_width_px=1200, Int_t reference_height_px=800)
 Scale everything on a pad, and its sub-pads, to print like the standard figure.
static void ScalePad (TVirtualPad *pad, Double_t scale, Int_t reference_width_px=1200, Int_t reference_height_px=800)
 Scale one pad and everything drawn on it, recursively.
static void ScaleAxisFontsToPad (TH1 *frame, TVirtualPad *pad, Double_t scale=1.0, Int_t reference_width_px=1200, Int_t reference_height_px=800)
 Size a frame's axis text as on the standard canvas, times a scale.
static void ScaleLegend (TLegend *legend, Double_t scale)
 Set a legend's text to AddLegend()'s 30 px times a scale.
static void ScaleText (TText *text, TVirtualPad *pad, Double_t scale, Int_t reference_height_px=800)
 Scale a text object with its pad.
static TLatex * DrawTitle (TVirtualPad *pad, const TString &title, Double_t scale=1.0)
 Draw a figure title centred in a pad's top margin, at the size ROOT's own pad title has on the standard canvas.
static void ScaleLine (TAttLine *line, Double_t scale)
 Multiply a line width by a scale, rounded to a whole pixel.
static void ScaleMarker (TAttMarker *marker, Double_t scale)
 Multiply a marker size by a scale.
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.

Detailed Description

All-static helpers for publication-quality ROOT graphics.

No instantiation is required or possible. SetStylePreferences() must be called before anything else; the other methods print a warning to stdout if it has not been, but still run.

Note
Several methods return heap-allocated ROOT objects. ROOT's own ownership rules apply and are called out per method; in general the objects returned here are owned by the caller or by the current pad, never by this class.

Definition at line 47 of file PlottingUtils.hpp.

Member Function Documentation

◆ AddLegend()

TLegend * PlottingUtils::AddLegend ( Double_t x1 = 0.7,
Double_t x2 = 0.9,
Double_t y1 = 0.7,
Double_t y2 = 0.9 )
static

Create, style and draw a legend on the current pad.

Parameters
x1Left edge, in NDC (0-1).
x2Right edge, in NDC (0-1).
y1Bottom edge, in NDC (0-1).
y2Top edge, in NDC (0-1).
Returns
The drawn TLegend, so entries can be added to it. Owned by the current pad once drawn.
Warning
The argument order is (x1, x2, y1, y2) — both x bounds, then both y bounds — not ROOT's own TLegend(x1, y1, x2, y2).

Definition at line 321 of file PlottingUtils.cpp.

◆ AddText()

TLatex * PlottingUtils::AddText ( const TString label,
Double_t x = 0.9,
Double_t y = 0.85,
Double_t angle = 0 )
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.

Parameters
labelText to draw. ROOT TLatex markup is honoured.
xHorizontal position, in NDC (0-1).
yVertical position, in NDC (0-1).
angleRotation in degrees, counter-clockwise. 0 by default.
Returns
The drawn TLatex. Owned by the current pad once drawn.

Definition at line 502 of file PlottingUtils.cpp.

Referenced by PlotFitWithResiduals().

◆ Configure2DHistogram()

void PlottingUtils::Configure2DHistogram ( TH2 * hist,
TCanvas * canvas,
const TString title = "" )
static

Apply the preferred 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.

Parameters
histHistogram to configure. Null is tolerated and ignored.
canvasCanvas to adjust. Null is tolerated and ignored.
titleHistogram title, in the usual ROOT "title;x;y;z" form.

Definition at line 114 of file PlottingUtils.cpp.

Referenced by ConfigureAndDraw2DHistogram().

◆ ConfigureAndDraw2DHistogram()

void PlottingUtils::ConfigureAndDraw2DHistogram ( TH2 * hist,
TCanvas * canvas,
const TString title = "" )
static

Configure2DHistogram() followed by Draw("COLZ").

No-op if null.

Parameters
hist2-D histogram to configure and draw.
canvasCanvas whose log-z and right margin are adjusted.
titleHistogram title, in the usual ROOT "title;x;y;z" form.

Definition at line 156 of file PlottingUtils.cpp.

◆ ConfigureAndDrawGraph()

void PlottingUtils::ConfigureAndDrawGraph ( TGraph * graph,
Int_t color,
const TString title = "" )
static

ConfigureGraph() followed by Draw().

No-op if graph is null.

Parameters
graphGraph to configure and draw onto the current pad.
colorROOT colour index for the line.
titleGraph title, in the usual ROOT "title;x;y" form.

Definition at line 138 of file PlottingUtils.cpp.

◆ ConfigureAndDrawHistogram()

void PlottingUtils::ConfigureAndDrawHistogram ( TH1 * hist,
Int_t color,
const TString title = "" )
static

ConfigureHistogram() followed by Draw("HIST").

No-op if null.

Parameters
histHistogram to configure and draw onto the current pad.
colorROOT colour index for the line.
titleHistogram title, in the usual ROOT "title;x;y" form.

Definition at line 147 of file PlottingUtils.cpp.

◆ ConfigureGraph() [1/2]

void PlottingUtils::ConfigureGraph ( TGraph * graph,
Int_t color,
const TString title = "" )
static

Apply the preferred 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.

Parameters
graphGraph to configure. Must not be null.
colorROOT colour index for the line.
titleGraph title, in the usual ROOT "title;x;y" form.

Definition at line 58 of file PlottingUtils.cpp.

Referenced by ConfigureAndDrawGraph(), and WaveformProcessingUtils::SaveSampleWaveform().

◆ ConfigureGraph() [2/2]

void PlottingUtils::ConfigureGraph ( TGraphErrors * graph,
Int_t color,
const TString title = "" )
static

Apply the preferred 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.

Parameters
graphGraph to configure. Must not be null.
colorROOT colour index for both line and markers.
titleGraph title, in the usual ROOT "title;x;y" form.

Definition at line 73 of file PlottingUtils.cpp.

◆ ConfigureHistogram()

void PlottingUtils::ConfigureHistogram ( TH1 * hist,
Int_t color,
const TString title = "" )
static

Apply the preferred 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.

Parameters
histHistogram to configure. Null is tolerated and ignored.
colorROOT colour index for the line.
titleHistogram title, in the usual ROOT "title;x;y" form.

Definition at line 91 of file PlottingUtils.cpp.

Referenced by ConfigureAndDrawHistogram().

◆ DrawTitle()

TLatex * PlottingUtils::DrawTitle ( TVirtualPad * pad,
const TString & title,
Double_t scale = 1.0 )
static

Draw a figure title centred in a pad's top margin, at the size ROOT's own pad title has on the standard canvas.

ROOT sizes a histogram's pad title from the pad height, so on a pad that takes part of a figure, such as the upper pad of SplitPadForPanel(), it comes out small. This draws the title as text in a pixel-sized font of 36 px times scale instead, which matches the standard title; give the frame no title of its own. Call it after ScaleFigure(), with the scale that used.

Parameters
padPad to draw on. Null is tolerated and ignored.
titleTitle text. ROOT TLatex markup is honoured.
scaleOverall scale, normally from FigureScale().
Returns
The drawn TLatex, owned by the pad. Null when nothing was drawn.

Definition at line 472 of file PlottingUtils.cpp.

◆ FigureScale()

Double_t PlottingUtils::FigureScale ( TVirtualPad * pad,
Int_t reference_width_px = 1200 )
static

How much larger a pad is than the standard plot area, by width.

A figure placed at a fixed column width is shrunk by its pixel width, so everything on a wider plot has to be drawn proportionally larger to print at the same size as on the standard 1200x800 canvas. This is that proportion, the pad's pixel width over reference_width_px. For a canvas it is the canvas width; for the plot pad of GetConfiguredCanvasWithSideLegend() it is 1.

Parameters
padPad, or canvas, to measure. Null gives 1.
reference_width_pxWidth of the standard plot area, in pixels. 1200 by default, the width of GetConfiguredCanvas().
Returns
The pad width divided by the reference width.

Definition at line 361 of file PlottingUtils.cpp.

Referenced by ScaleFigure().

◆ GetConfiguredCanvas()

TCanvas * PlottingUtils::GetConfiguredCanvas ( Bool_t logy = kFALSE)
static

Create a 1200x800 canvas with grid and ticks already set up.

Parameters
logykTRUE to start with a logarithmic y axis.
Returns
A newly allocated TCanvas with a randomised name (see GetRandomName()). The caller owns this pointer.
Note
The canvas is made current, so subsequent Draw() calls land on it.

Definition at line 167 of file PlottingUtils.cpp.

Referenced by PlotFitWithResiduals(), and WaveformProcessingUtils::SaveSampleWaveform().

◆ GetConfiguredCanvasWithSideLegend()

TCanvas * PlottingUtils::GetConfiguredCanvasWithSideLegend ( TPad *& plot,
TPad *& legend_pad,
Int_t legend_width_px = 600,
Int_t plot_height_px = 800,
Bool_t logy = kFALSE )
static

A canvas with the standard plot area and a legend pad to its right.

The plot pad is exactly the standard 1200 px wide and plot_height_px tall, with the preferred margins, grid and ticks, so everything drawn on it comes out as on GetConfiguredCanvas(); the canvas is wider by legend_width_px. The legend pad is transparent and margin-less and runs from the plot frame's right edge, over the plot pad's blank right margin, to the canvas edge, so a legend placed in it can sit as close to the frame as wanted. LegendWidthPx() gives the width a legend needs, from which the caller picks legend_width_px and the box position. A plot taller than the standard 800 px is for a panel below the plot: see SplitPadForPanel().

Parameters
[out]plotThe plot pad, drawn and made current.
[out]legend_padThe legend pad, drawn over the plot pad's right margin.
legend_width_pxWidth added to the canvas for the legend, in pixels; the legend pad is this plus the plot pad's right margin.
plot_height_pxHeight of the plot pad and the canvas, in pixels. 800 by default.
logykTRUE for a logarithmic y axis on the plot pad.
Returns
The canvas, with a randomised name. The caller owns this pointer; the pads belong to the canvas.

Definition at line 181 of file PlottingUtils.cpp.

◆ GetDefaultColors()

std::vector< Int_t > PlottingUtils::GetDefaultColors ( )
static

A palette of visually distinct ROOT colour indices.

Returns
24 colour indices, intended to be indexed by series number.

Definition at line 313 of file PlottingUtils.cpp.

◆ GetLineWidth()

Width_t PlottingUtils::GetLineWidth ( )
inlinestatic

Line width the Configure* methods apply.

Returns
2 after SetStylePreferences(PlotSaveFormat::kPNG), 1 for kPDF.

Definition at line 537 of file PlottingUtils.hpp.

Referenced by FittingUtils::PlotFitDoublePeak(), RooFitUtils::PlotFitDoublePeak(), FittingUtils::PlotFitSinglePeak(), RooFitUtils::PlotFitSinglePeak(), FittingUtils::PlotFitTriplePeak(), and RooFitUtils::PlotFitTriplePeak().

◆ GetPlotsBaseDir()

TString PlottingUtils::GetPlotsBaseDir ( )
static

Current base directory for saved figures, without trailing slash.

Returns
The directory last set by SetPlotsBaseDir(), or "plots".

Definition at line 20 of file PlottingUtils.cpp.

Referenced by SaveFigure(), and InitUtils::SetROOTPreferences().

◆ GetRandomName()

TString PlottingUtils::GetRandomName ( )
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.

Returns
A name of the form nameX.XXXXXXX from a clock-seeded generator.

Definition at line 515 of file PlottingUtils.cpp.

Referenced by RooFitUtils::BuildDisplayHistogramFrom(), GetConfiguredCanvas(), GetConfiguredCanvasWithSideLegend(), SplitPadForPanel(), and TextWidthPx().

◆ LegendWidthPx()

Double_t PlottingUtils::LegendWidthPx ( const std::vector< TString > & labels,
const TString & header = "",
Double_t size_px = 30.0,
Double_t margin = 0.25,
Double_t padding_px = 15.0 )
static

Width a legend box needs for its labels at AddLegend()'s font.

A TLegend gives the leading margin of its width to the symbol column and draws the labels after it, while a header starts at the box's left edge, so the box must be the widest label over (1 - margin) or the header's width, whichever is larger, plus padding_px each side.

Parameters
labelsThe entry labels. ROOT TLatex markup is honoured.
headerThe header, or empty for none.
size_pxFont size in pixels. 30 by default.
marginThe legend's symbol-column fraction. 0.25 by default, TLegend's own default.
padding_pxClear space inside each side of the box, in pixels. 15 by default.
Returns
The box width in pixels.

Definition at line 351 of file PlottingUtils.cpp.

◆ PlotFitWithResiduals()

void PlottingUtils::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 )
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.

Parameters
histData histogram. Must not be null.
total_graphCurve for the summed model.
component_graphsOne curve per model component; may be empty.
fit_range_lowLower fit bound, in the histogram's x units.
fit_range_highUpper fit bound, in the histogram's x units.
output_nameBase filename, without extension.
output_subdirectorySubdirectory under the plots base. "fits" by default.
labelOptional annotation drawn on the plot; empty draws nothing.
logykTRUE (default) for a logarithmic y axis on the upper pad.
Note
Saves through SaveFigure(), so the same base-directory and format rules apply. A companion pull histogram is written alongside.

Definition at line 522 of file PlottingUtils.cpp.

Referenced by FittingUtils::PlotFitDoublePeak(), RooFitUtils::PlotFitDoublePeak(), FittingUtils::PlotFitSinglePeak(), RooFitUtils::PlotFitSinglePeak(), FittingUtils::PlotFitTriplePeak(), and RooFitUtils::PlotFitTriplePeak().

◆ SaveFigure()

void PlottingUtils::SaveFigure ( TCanvas * canvas,
TString output_filename,
TString output_subdirectory = "",
PlotSaveOptions save_options = PlotSaveOptions::kBOTH )
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.

Parameters
canvasCanvas to save. Must not be null.
output_filenameBase filename, without extension.
output_subdirectorySubdirectory under the plots base; empty means the base itself.
save_optionsWhich axis scalings to write. PlotSaveOptions::kBOTH by default.
Warning
Requesting a logarithmic variant for a canvas containing a TH2 is treated as a usage error and terminates the process via std::exit(1) after printing an explanation. The log option refers to the y axis and is meaningless for a 2-D colour plot, whose z axis is already logarithmic if it went through Configure2DHistogram(). Use PlotSaveOptions::kLINEAR for those.
Note
The canvas is left with log-y disabled on return, whatever it was set to beforehand.
PDFs are printed with ROOT's Portrait option, so the page has the canvas's own shape and is not rotated. Without it ROOT puts any canvas at least as wide as it is tall onto a portrait page turned by 90 degrees, which LaTeX places sideways or shrunk.

Definition at line 249 of file PlottingUtils.cpp.

Referenced by PlotFitWithResiduals(), and WaveformProcessingUtils::SaveSampleWaveform().

◆ ScaleAxisFontsToPad()

void PlottingUtils::ScaleAxisFontsToPad ( TH1 * frame,
TVirtualPad * pad,
Double_t scale = 1.0,
Int_t reference_width_px = 1200,
Int_t reference_height_px = 800 )
static

Size a frame's axis text as on the standard canvas, times a scale.

The preferred 0.06 title and label sizes are fractions of the pad's smaller pixel dimension, so a pad taking part of a figure renders them smaller than a standard one. This sets every non-zero title and label size of both axes so the text comes out at 0.06 of reference_height_px pixels times scale, whatever the pad's size. A size already at zero, hiding that axis's text, stays zero. ROOT places a title at its offset times the title size measured along the other axis of the pad, so the 1.2 preferred offsets are rescaled by the pad's aspect ratio to put each title the same number of pixels from its axis as on the standard canvas.

Parameters
frameHistogram or frame whose axes are styled. Null is tolerated and ignored.
padThe pad the frame is drawn on. Null is tolerated and ignored.
scaleOverall scale, normally from FigureScale().
reference_width_pxWidth of the standard plot area, in pixels.
reference_height_pxHeight of the standard plot area, in pixels.

Definition at line 420 of file PlottingUtils.cpp.

Referenced by ScalePad().

◆ ScaleFigure()

void PlottingUtils::ScaleFigure ( TVirtualPad * pad,
Int_t reference_width_px = 1200,
Int_t reference_height_px = 800 )
static

Scale everything on a pad, and its sub-pads, to print like the standard figure.

The one call for a figure of non-standard size or layout, made once, after everything is drawn. Works out the scale of pad with FigureScale() and applies ScalePad() to it and, through it, to every pad inside it: pad margins, axis text, legends, text, line widths and marker sizes all come out as on the standard canvas multiplied by that scale, whatever share of the figure each pad takes. Pass the canvas for a plain figure, or the plot pad of GetConfiguredCanvasWithSideLegend(). Line widths and marker sizes are multiplied in place, so calling this twice doubles the effect.

Parameters
padPad, or canvas, to scale. Null is tolerated and ignored.
reference_width_pxWidth of the standard plot area, in pixels. 1200 by default.
reference_height_pxHeight of the standard plot area, in pixels. 800 by default.

Definition at line 369 of file PlottingUtils.cpp.

◆ ScaleLegend()

void PlottingUtils::ScaleLegend ( TLegend * legend,
Double_t scale )
static

Set a legend's text to AddLegend()'s 30 px times a scale.

Parameters
legendLegend to resize. Null is tolerated and ignored.
scaleOverall scale, normally from FigureScale().

Definition at line 449 of file PlottingUtils.cpp.

Referenced by ScalePad().

◆ ScaleLine()

void PlottingUtils::ScaleLine ( TAttLine * line,
Double_t scale )
static

Multiply a line width by a scale, rounded to a whole pixel.

A width of zero, meaning no line, stays zero.

Parameters
lineObject with line attributes. Null is tolerated and ignored.
scaleOverall scale, normally from FigureScale().

Definition at line 489 of file PlottingUtils.cpp.

Referenced by ScalePad().

◆ ScaleMarker()

void PlottingUtils::ScaleMarker ( TAttMarker * marker,
Double_t scale )
static

Multiply a marker size by a scale.

Parameters
markerObject with marker attributes. Null is tolerated and ignored.
scaleOverall scale, normally from FigureScale().

Definition at line 496 of file PlottingUtils.cpp.

Referenced by ScalePad().

◆ ScalePad()

void PlottingUtils::ScalePad ( TVirtualPad * pad,
Double_t scale,
Int_t reference_width_px = 1200,
Int_t reference_height_px = 800 )
static

Scale one pad and everything drawn on it, recursively.

Margins are taken as fractions of the standard plot area and multiplied by its size over the pad's own pixel size on each axis, times scale, so they hold the same number of text lines as on the standard canvas. Then each primitive is scaled: a histogram or frame by ScaleAxisFontsToPad(), a legend by ScaleLegend(), text by ScaleText(), anything with line attributes by ScaleLine(), anything with marker attributes by ScaleMarker(), and a nested pad by this function again.

Parameters
padPad to scale. Null is tolerated and ignored.
scaleOverall scale, normally from FigureScale().
reference_width_pxWidth of the standard plot area, in pixels.
reference_height_pxHeight of the standard plot area, in pixels.

Definition at line 378 of file PlottingUtils.cpp.

Referenced by ScaleFigure(), and ScalePad().

◆ ScaleText()

void PlottingUtils::ScaleText ( TText * text,
TVirtualPad * pad,
Double_t scale,
Int_t reference_height_px = 800 )
static

Scale a text object with its pad.

A pixel-sized font (precision 3, such as AddText()'s 43) is multiplied by scale. A relative font is a fraction of the pad's smaller pixel dimension, so it is reset to give the pixels it would have on the standard canvas, times scale.

Parameters
textText to resize. Null is tolerated and ignored.
padThe pad the text is drawn on. Null is tolerated and ignored.
scaleOverall scale, normally from FigureScale().
reference_height_pxHeight of the standard plot area, in pixels.

Definition at line 455 of file PlottingUtils.cpp.

Referenced by ScalePad().

◆ SetPlotsBaseDir()

void PlottingUtils::SetPlotsBaseDir ( const TString & dir)
static

Set the base directory that saved figures are written under.

Parameters
dirBase directory. Pass an absolute path so output is anchored to a project root regardless of the current working directory. Trailing slashes are stripped.
Note
The default is the CWD-relative "plots". InitUtils::SetROOTPreferences() calls this for you.

Definition at line 13 of file PlottingUtils.cpp.

Referenced by InitUtils::SetROOTPreferences().

◆ SetStylePreferences()

void PlottingUtils::SetStylePreferences ( PlotSaveFormat save_format = PlotSaveFormat::kPNG)
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.

Parameters
save_formatOutput format for SaveFigure(). Defaults to PlotSaveFormat::kPNG.
Note
Mutates ROOT global state (gStyle) for the whole process. InitUtils::SetROOTPreferences() calls this and is the recommended entry point.

Definition at line 28 of file PlottingUtils.cpp.

Referenced by WaveformProcessingUtils::SaveSampleWaveform(), and InitUtils::SetROOTPreferences().

◆ SplitPadForPanel()

void PlottingUtils::SplitPadForPanel ( TVirtualPad * pad,
Int_t panel_height_px,
TPad *& upper,
TPad *& lower )
static

Split a pad into a main pad above and a panel below, leaving the main pad's frame exactly as it would be on its own.

For a residual or deviation panel under a plot. The upper pad is the pad less panel_height_px at the bottom, with all four of the pad's margins, grid, ticks and log-y setting, so a frame drawn on it is pixel-for-pixel the frame of a standard figure when the pad is the standard height plus the panel. The lower pad is transparent and reaches up over the upper pad's blank bottom margin to the foot of its frame, so the two frames share the x axis with only a small gap; it keeps the pad's left, right and bottom margins with a small top margin. Margins are the standard fractions; ScaleFigure() on the parent sizes the panel's margins and axis text to match. The caller hides the upper frame's x-axis labels and title.

Parameters
padPad to split. Its own margins stay as they were.
panel_height_pxHeight added below the main pad for the panel, in pixels: the pad's height less the main pad's.
[out]upperThe main pad, drawn first.
[out]lowerThe panel, drawn over the main pad's bottom margin.

Definition at line 208 of file PlottingUtils.cpp.

◆ TextWidthPx()

Double_t PlottingUtils::TextWidthPx ( const TString & text,
Double_t size_px = 30.0,
Int_t font = 43 )
static

Rendered width of a text in a pixel-sized font.

Measured by ROOT on a scratch canvas, so it is what the text will take on any pad, whatever the pad's size.

Parameters
textText to measure. ROOT TLatex markup is honoured.
size_pxFont size in pixels. 30 by default, the size AddLegend() uses.
fontROOT font code, of precision 3 so the size is in pixels. 43 by default, the font AddLegend() uses.
Returns
The width in pixels.

Definition at line 333 of file PlottingUtils.cpp.

Referenced by LegendWidthPx().


The documentation for this class was generated from the following files: