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