ROOT Graphics Olivier Couet CERN EPSFT ROOT Users

  • Slides: 21
Download presentation
ROOT Graphics Olivier Couet (CERN EP-SFT) ROOT User’s Workshop 10 -13 September 2018

ROOT Graphics Olivier Couet (CERN EP-SFT) ROOT User’s Workshop 10 -13 September 2018

Abstract ROOT graphics had many developments since the last workshop. This presentation summarises them,

Abstract ROOT graphics had many developments since the last workshop. This presentation summarises them, emphasising the most recent and noticeable ones. Graphics News: ratio plots, automatic placement of legends, automatic coloring, highlight technique ROOT User’s Workshop 10 -13 September 2018

Ratio plots (1) Ratio plots are implemented by the class TRatio. Plot (by Paul

Ratio plots (1) Ratio plots are implemented by the class TRatio. Plot (by Paul Gessinger hello@paulgessinger. com) It displays ratios, differences and fit residuals. TRatio. Plot has two constructors, : • One which accepts two histograms, and is responsible for setting up the calculation of ratios and differences. This calculation is (in part) delegated to TEfficiency. • One which uses a fitted histogram to calculate the fit residual and plot it with the histogram and the fit function. For a complete and detailed description see the ROOT Reference Guide ROOT User’s Workshop 10 -13 September 2018

Ratio plots (2) auto h 1 = new TH 1 D("h 1", 50, 0,

Ratio plots (2) auto h 1 = new TH 1 D("h 1", 50, 0, 10); auto h 2 = new TH 1 D("h 2", 50, 0, 10); auto f 1 = new TF 1("f 1", "exp(- x/[0] )"); f 1 ->Set. Parameter(0, 3); h 1 ->Fill. Random("f 1", 1900); h 2 ->Fill. Random("f 1", 2000); h 1 ->Sumw 2(); h 2 ->Scale(1. 9 / 2. ); auto rp = new TRatio. Plot(h 1, h 2); rp->Draw(); ROOT User’s Workshop 10 -13 September 2018

Ratio plots (3) auto h 1 = new TH 1 D("h 1", 50, -5,

Ratio plots (3) auto h 1 = new TH 1 D("h 1", 50, -5, 5); h 1 ->Fill. Random("gaus", 2000); h 1 ->Fit("gaus"); auto rp 1 = new TRatio. Plot(h 1); rp 1 ->Draw(); rp 1 ->Get. Lower. Ref. Yaxis()->Set. Title("ratio"); rp 1 ->Get. Upper. Ref. Yaxis()->Set. Title("entries"); ROOT User’s Workshop 10 -13 September 2018

Axis Labels Editing (1) • After an axis has been created, TGaxis: : Change.

Axis Labels Editing (1) • After an axis has been created, TGaxis: : Change. Label allows to define new text attributes for a given label. • This allows tuning of the axis’ labels. • All the attributes can be changed as well as the text label itself which can be even removed. Double_t pi = TMath: : Pi(); TF 1* f = new TF 1("f", "TMath: : Cos(x/TMath: : Pi())", -pi, pi); TH 1* h = f->Get. Histogram(); TAxis* a = h->Get. Xaxis(); a->Set. Ndivisions(-502); a->Change. Label(1, -1, -1, -1, "-#pi"); a->Change. Label(-1, -1, -1, "#pi"); f->Draw(); ROOT User’s Workshop 10 -13 September 2018

Axis Labels Editing (2) If an attribute should not be changed just give the

Axis Labels Editing (2) If an attribute should not be changed just give the value "-1". The following macro gives an example: auto c 1 = new TCanvas("c 1", "Examples of Gaxis", 10, 900, 500); c 1 ->Range(-6, -0. 1, 6, 0. 1); TGaxis *axis 1 = new TGaxis(-5. 5, 0. 0, 100, 510, ""); axis 1 ->Set. Name("axis 1"); axis 1 ->Set. Title("Axis Title"); axis 1 ->Set. Title. Size(0. 05); axis 1 ->Set. Title. Color(k. Blue); axis 1 ->Set. Title. Font(42); axis 1 ->Change. Label(1, -1, -1, 2); axis 1 ->Change. Label(3, -1, 0. ); axis 1 ->Change. Label(5, 30. , -1, 0); axis 1 ->Change. Label(6, -1, -1, 3, -1, "6 th label"); axis 1 ->Change. Label(-2, -1, -1, 3, -1, "2 nd to last label"); axis 1 ->Draw(); ROOT User’s Workshop 10 -13 September 2018

Automatic placement of legends • A new TLegend constructor, not specifying the legend position,

Automatic placement of legends • A new TLegend constructor, not specifying the legend position, is available. • Only legend’s width and height are defined. • TPad: : Build. Legend() triggers by default the automatic placement. h 1>Draw("E"); h 2 ->Draw("same"); g->Draw("L"); c->Build. Legend(); In addition to the automatic placement of the legend, the automatic placement of the Y axis title has been also implemented (when the title offset is set to 0). ROOT User’s Workshop 10 -13 September 2018

Automatic coloring (1) When several histograms or graphs are painted in the same canvas

Automatic coloring (1) When several histograms or graphs are painted in the same canvas thanks to the option “SAME”, via a THStack or TMultigraph the options PFC (Palette Fill Color), PLC (Palette Line Color) and PMC (Palette Marker Color allow to slect automatically the histograms and graphs colors in the current palette. Using option SAME … h 1 ->Draw("PLC PMC"); h 2 ->Draw("SAME PLC PMC"); h 3 ->Draw("SAME PLC PMC"); h 4 ->Draw("SAME PLC PMC"); h 5 ->Draw("SAME PLC PMC"); ROOT User’s Workshop 10 -13 September 2018

Automatic coloring (2) With a THStack … auto hs = new THStack(); hs->Add(h 1

Automatic coloring (2) With a THStack … auto hs = new THStack(); hs->Add(h 1 st); hs->Add(h 2 st); hs->Add(h 3 st); g. Style->Set. Palette(k. Ocean); hs->Draw("pfc nostack"); auto hs = new THStack(); hs->Add(h 1); hs->Add(h 2); hs->Add(h 3); hs->Add(h 4); hs->Add(h 5); g. Style->Set. Palette(1); hs->Draw("0 lego 1 PFC"); ROOT User’s Workshop 10 -13 September 2018

Automatic coloring (3) With a TMulti. Graph … auto mg = new TMulti. Graph();

Automatic coloring (3) With a TMulti. Graph … auto mg = new TMulti. Graph(); mg->Add(gr 4, "PL"); mg->Add(gr 3, "PL"); mg->Add(gr 2, "*L"); mg->Add(gr 1, "PL"); mg->Draw("A pmc plc"); ROOT User’s Workshop 10 -13 September 2018

Highlight technique (1) • The highlight mode is implemented for TH 1 (and for

Highlight technique (1) • The highlight mode is implemented for TH 1 (and for TGraph) classses. • When highlight mode is on, the mouse movements over the histograms’ bins or graphs’ points will be highlighted. • Each highlight emits signal TCanvas: : Highlighted() which allows the user to react and call their own function. For a better understanding see also the tutorials $ROOTSYS/tutorials/hist/hl. Histo*. C and $ROOTSYS/tutorials/graphs/hl. Graph*. C. Implemented by Jan Musinsky ROOT User’s Workshop 10 -13 September 2018

Highlight technique (2) Example of histogram highligth ROOT User’s Workshop 10 -13 September 2018

Highlight technique (2) Example of histogram highligth ROOT User’s Workshop 10 -13 September 2018

Highlight technique (3) Example of graph highlight ROOT User’s Workshop 10 -13 September 2018

Highlight technique (3) Example of graph highlight ROOT User’s Workshop 10 -13 September 2018

Candle plots enhancement Candle plots (and «violin plots» ) have been completly rewritten and

Candle plots enhancement Candle plots (and «violin plots» ) have been completly rewritten and extented with many new options by Georg Troska georg. troska@tu-dortmund. de. Several examples illustrating all the possible new options can be found in $ROOTSYS/tutorials/hist ROOT User’s Workshop 10 -13 September 2018

Reverse Axis for graphs When a TGraph is drawn, the X-axis is drawn with

Reverse Axis for graphs When a TGraph is drawn, the X-axis is drawn with increasing values from left to right and the Y-axis from bottom to top. The two options RX and RY allow to change this order. The option RX allows to draw the X-axis with increasing values from right to left and the RY option allows to draw the Y-axis with increasing values from top to bottom. auto *g = new TGraph. Errors(); g->Set. Point(0, -4, -3); g->Set. Point(1, 1, 1); g->Set. Point(2, 2, 1); g->Set. Point(3, 3, 4); g->Set. Point(4, 5, 5); g->Set. Point. Error(0, 1. , 2. ); g->Set. Point. Error(1, 2, 1); g->Set. Point. Error(2, 2, 3); g->Set. Point. Error(3, 3, 2); g->Set. Point. Error(4, 4, 5); g->Draw("A RX RY PL"); ROOT User’s Workshop 10 -13 September 2018

Miscellaneous on color and palette • New color palette “cividis” implemented by Sven Augustin

Miscellaneous on color and palette • New color palette “cividis” implemented by Sven Augustin aiming to solve problems that people with color vision deficiency have with the common colormaps. For more details see: Nuñez J, Anderton C, and Renslow R. Optimizing colormaps with consideration for color vision deficiency to enable accurate interpretation of scientific data. • TColor: : Get. Free. Color. Index() allows to make sure the new color is created with an unused color index. • The method TColor: : Invert. Palette inverts the current palette. The top color becomes bottom and vice versa. This was suggested by Karl Smith. g. Style->Set. Palette(k. Cividis); g. Style->Set. Palette(k. Cherry); TColor: : Invert. Palette(); ROOT User’s Workshop 10 -13 September 2018

Color plot performance improvement The «COL 2» Drawing Option COL 2 is a new

Color plot performance improvement The «COL 2» Drawing Option COL 2 is a new rendering technique providing potential performance improvements compared to the standard COL option. The performance comparison of the COL 2 to the COL option depends on the histogram and the size of the rendering region in the current pad. In general, a small (approx. less than 100 bins per axis), sparsely populated TH 2 will render faster with the COL option. However, for larger histograms (approx. more than 100 bins per axis) that are not sparse, the COL 2 option will provide up to 20 times performance improvements. For example, a 1000 x 1000 bin TH 2 that is not sparse will render an order of magnitude faster with the COL 2 option. The COL 2 option will also scale its performance based on the size of the pixmap the histogram image is being rendered into. It also is much better optimized for sessions where the user is forwarding X 11 windows through an ssh connection. COL 2 option renders the histogram as a bitmap. Therefore it cannot be saved in vector graphics file format like Post. Script or PDF (an empty image will be generated). It can be saved only in bitmap files like PNG format for instance. This has been implemented by Jeromy Tompkins@nscl. msu. edu ROOT User’s Workshop 10 -13 September 2018

3 D histograms rendering The “BOX” options, to draw 3 D histograms, have been

3 D histograms rendering The “BOX” options, to draw 3 D histograms, have been enhanced by Evgueni Tcherniaev The following pictures show the old and new versions. We have now options “BOX 1”, “BOX 2” and “BOX 3” for TH 3 equivalent of “LEGO 1”, “LEGO 2” and “LEGO 3”for TH 2. ROOT User’s Workshop 10 -13 September 2018

And more … • New markers • New graphics style “ATLAS” from M. Sutton.

And more … • New markers • New graphics style “ATLAS” from M. Sutton. • Implement the possibility to generate high definition bitmap pictures in TImage. Dump. This done via g. Style>Set. Image. Scaling(x); x being a multiplication factor. This new feature is now used to generate the reference guide with x=3. Pictures in the reference guide are now much shaper. ROOT User’s Workshop 10 -13 September 2018

Future work Future ROOT Graphics developments will be the new ROOT 7 classes: The

Future work Future ROOT Graphics developments will be the new ROOT 7 classes: The « Rxxx classes » and their rendering using the JSRoot technology. See the « ROOT 5 Graphics » talk. ROOT User’s Workshop 10 -13 September 2018