Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rh1_twoscales.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This macro generates two RH1D, fills them and draw in RCanvas.
5/// Second histogram uses enables "secondy" attribute to draw separate Y axis on right side
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2021-05-17
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-2021, 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
22#include "ROOT/RHist.hxx"
24#include "ROOT/RFrameTitle.hxx"
25#include "ROOT/RCanvas.hxx"
26#include "ROOT/RPad.hxx"
27#include "TRandom.h"
28
29// macro must be here while cling is not capable to load
30// library automatically for outlined function see ROOT-10336
31R__LOAD_LIBRARY(libROOTHistDraw)
32
33using namespace ROOT::Experimental;
34
35void rh1_twoscales()
36{
37 // Create the histogram.
38 RAxisConfig xaxis(25, 0., 10.);
39 auto pHist1 = std::make_shared<RH1D>(xaxis);
40 auto pHist2 = std::make_shared<RH1D>(xaxis);
41
42 for (int n=0;n<1000;n++)
43 pHist1->Fill(gRandom->Gaus(3,0.8));
44
45 for (int n=0;n<3000;n++)
46 pHist2->Fill(gRandom->Gaus(7,1.2));
47
48 // Create a canvas to be displayed.
49 auto canvas = RCanvas::Create("RH1 with two Y scales");
50
51 // histograms colors
52 auto col1 = RColor::kRed, col2 = RColor::kBlue;
53
54 // default draw option
55 canvas->Draw<RFrameTitle>("Two independent Y axes for histograms");
56 auto draw1 = canvas->Draw(pHist1);
57 draw1->line.color = col1;
58 draw1->line.width = 2;
59 auto draw2 = canvas->Draw(pHist2);
60 draw2->secondy = true;
61 draw2->line.color = col2;
62 draw2->line.width = 4;
63
64 canvas->GetFrame()->y.ticks.color = col1;
65 canvas->GetFrame()->y2.ticks.color = col2;
66
67 canvas->SetSize(800, 600);
68 canvas->Show();
69}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:491
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