Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
draw_subpads.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 //
4 /// This ROOT 7 example demonstrates how to create a ROOT 7 canvas (RCanvas),
5 /// divide on subpads and draw histograms there
6 ///
7 /// \macro_code
8 ///
9 /// \date 2018-03-13
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
12 
13 /*************************************************************************
14  * Copyright (C) 1995-2019, 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/RHistDrawable.hxx"
22 #include "ROOT/RCanvas.hxx"
23 #include "ROOT/RPad.hxx"
24 #include "TRandom.h"
25 
26 // macro must be here while cling is not capable to load
27 // library automatically for outlined function see ROOT-10336
28 R__LOAD_LIBRARY(libROOTHistDraw)
29 
30 void draw_subpads()
31 {
32  using namespace ROOT::Experimental;
33 
34  // Create the histogram.
35  RAxisConfig xaxis(25, 0., 10.);
36  auto pHist1 = std::make_shared<RH1D>(xaxis);
37  auto pHist2 = std::make_shared<RH1D>(xaxis);
38  auto pHist3 = std::make_shared<RH1D>(xaxis);
39 
40 
41  for (int n=0;n<1000;n++) {
42  pHist1->Fill(gRandom->Gaus(3., 0.8));
43  pHist2->Fill(gRandom->Gaus(5., 1.));
44  pHist3->Fill(gRandom->Gaus(7., 1.2));
45  }
46 
47  // Create a canvas to be displayed.
48  auto canvas = RCanvas::Create("Canvas Title");
49 
50  // Divide canvas on sub-pads
51 
52  auto subpads = canvas->Divide(2,2);
53 
54  subpads[0][0]->Draw(pHist1)->AttrLine().SetColor(RColor::kRed);
55  subpads[1][0]->Draw(pHist2)->AttrLine().SetColor(RColor::kBlue);
56  subpads[0][1]->Draw(pHist3)->AttrLine().SetColor(RColor::kGreen);
57 
58  // Divide pad on sub-sub-pads
59  auto subsubpads = subpads[1][1]->Divide(2,2);
60 
61  subsubpads[0][0]->Draw(pHist1)->AttrLine().SetColor(RColor::kBlue);
62  subsubpads[1][0]->Draw(pHist2)->AttrLine().SetColor(RColor::kGreen);
63  subsubpads[0][1]->Draw(pHist3)->AttrLine().SetColor(RColor::kRed);
64 
65  canvas->Show();
66 }