Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
subpads.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This ROOT 7 example demonstrates how to create a ROOT 7 canvas (RCanvas),
5/// divide on sub-sub pads and draw histograms there
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2018-03-13
11/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
12/// \author Sergey Linev <s.linev@gsi.de>
13
14/*************************************************************************
15 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
16 * All rights reserved. *
17 * *
18 * For the licensing terms see $ROOTSYS/LICENSE. *
19 * For the list of contributors see $ROOTSYS/README/CREDITS. *
20 *************************************************************************/
21
23#include "ROOT/RCanvas.hxx"
24#include "ROOT/RPad.hxx"
25#include "ROOT/RStyle.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
32void subpads()
33{
34 using namespace ROOT::Experimental;
35
36 // Create the histogram.
37 RAxisConfig xaxis(25, 0., 10.);
38 auto pHist1 = std::make_shared<RH1D>(xaxis);
39 auto pHist2 = std::make_shared<RH1D>(xaxis);
40 auto pHist3 = std::make_shared<RH1D>(xaxis);
41
42 for (int n = 0; n < 1000; n++) {
43 pHist1->Fill(gRandom->Gaus(3., 0.8));
44 pHist2->Fill(gRandom->Gaus(5., 1.));
45 pHist3->Fill(gRandom->Gaus(7., 1.2));
46 }
47
48 // Create a canvas to be displayed.
49 auto canvas = RCanvas::Create("Sub-sub pads example");
50
51 // Divide canvas on sub-pads
52
53 auto subpads = canvas->Divide(2,2);
54
55 subpads[0][0]->Draw(pHist1)->line.color = RColor::kRed;
56 subpads[1][0]->Draw(pHist2)->line.color = RColor::kBlue;
57 subpads[0][1]->Draw(pHist3)->line.color = RColor::kGreen;
58
59 // Divide sub-pad on sub-sub-pads
60 auto subsubpads = subpads[1][1]->Divide(2,2);
61
62 subsubpads[0][0]->Draw(pHist1)->line.color = RColor::kBlue;
63 subsubpads[1][0]->Draw(pHist2)->line.color = RColor::kGreen;
64 subsubpads[0][1]->Draw(pHist3)->line.color = RColor::kRed;
65
66 auto style = RStyle::Parse(
67 "frame {" // select type frame for RFrame
68 " gridX: true;" // enable grid drawing
69 " gridY: true;"
70 " ticksX: 2;" // enable ticks drawing on both sides
71 " ticksY: 2;"
72 " x_labels_size: 0.05;" // below 1 is scaling factor for pad height
73 " y_labels_size: 20;" // just a font size in pixel
74 " y_labels_color: green;" // and name labels color
75 "}");
76 canvas->UseStyle(style);
77
78 canvas->SetSize(1200, 600);
79 canvas->Show();
80
81 canvas->ClearOnClose(style);
82}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:491
Option_t Option_t style
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
Objects used to configure the different axis types.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition TRandom.cxx:274
const Int_t n
Definition legend1.C:16