Logo ROOT  
Reference Guide
rh2.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This macro generates RH2D and draw it with different options in RCanvas
5///
6/// \macro_image (rcanvas_js)
7/// \macro_code
8///
9/// \date 2020-06-25
10/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
11/// \author Sergey Linev <s.linev@gsi.de>
12
13/*************************************************************************
14 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
15 * All rights reserved. *
16 * *
17 * For the licensing terms see $ROOTSYS/LICENSE. *
18 * For the list of contributors see $ROOTSYS/README/CREDITS. *
19 *************************************************************************/
20
21#include "ROOT/RHist.hxx"
23#include "ROOT/RFrameTitle.hxx"
24#include "ROOT/RCanvas.hxx"
25#include "ROOT/RPad.hxx"
26#include "TRandom.h"
27
28// macro must be here while cling is not capable to load
29// library automatically for outlined function see ROOT-10336
30R__LOAD_LIBRARY(libROOTHistDraw)
31
32using namespace ROOT::Experimental;
33
34void rh2()
35{
36 // Create the histogram.
37 RAxisConfig xaxis("x", 20, 0., 10.);
38 RAxisConfig yaxis("y", 20, 0., 10.);
39 auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
40
41 for (int n=0;n<10000;n++)
42 pHist->Fill({gRandom->Gaus(5.,2.), gRandom->Gaus(5.,2.)});
43
44 // Create a canvas to be displayed.
45 auto canvas = RCanvas::Create("RH2 drawing options");
46
47 // Divide canvas on 2x3 sub-pads to show different draw options
48 auto subpads = canvas->Divide(2,3);
49
50 // default draw option
51 subpads[0][0]->Draw<RFrameTitle>("Color() draw option (default)");
52 subpads[0][0]->Draw(pHist);
53
54 // contour draw options
55 subpads[1][0]->Draw<RFrameTitle>("Contour() draw option");
56 subpads[1][0]->Draw(pHist)->Contour();
57
58 // text draw options
59 subpads[0][1]->Draw<RFrameTitle>("Text() draw option");
60 subpads[0][1]->Draw(pHist)->Text().text.color = RColor::kBlue;
61
62 // arrow draw options
63 subpads[1][1]->Draw<RFrameTitle>("Arrow() draw option");
64 auto draw11 = subpads[1][1]->Draw(pHist);
65 draw11->Arrow();
66 draw11->line.color = RColor::kRed;
67
68 // lego draw options
69 subpads[0][2]->Draw<RFrameTitle>("Lego() draw option");
70 subpads[0][2]->Draw(pHist)->Lego(2);
71
72 // surf draw option
73 subpads[1][2]->Draw<RFrameTitle>("Surf() draw option");
74 subpads[1][2]->Draw(pHist)->Surf(2);
75
76 canvas->SetSize(1000, 700);
77 canvas->Show();
78}
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:472
@ kRed
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
Objects used to configure the different axis types.
Definition: RAxisConfig.hxx:35
const Int_t n
Definition: legend1.C:16