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
29using namespace ROOT::Experimental;
30
31void rh1_twoscales()
32{
33 // Create the histogram.
34 RAxisConfig xaxis(25, 0., 10.);
35 auto pHist1 = std::make_shared<RH1D>(xaxis);
36 auto pHist2 = std::make_shared<RH1D>(xaxis);
37
38 for (int n=0;n<1000;n++)
39 pHist1->Fill(gRandom->Gaus(3,0.8));
40
41 for (int n=0;n<3000;n++)
42 pHist2->Fill(gRandom->Gaus(7,1.2));
43
44 // Create a canvas to be displayed.
45 auto canvas = RCanvas::Create("RH1 with two Y scales");
46
47 // histograms colors
48 auto col1 = RColor::kRed, col2 = RColor::kBlue;
49
50 // default draw option
51 canvas->Draw<RFrameTitle>("Two independent Y axes for histograms");
52 auto draw1 = canvas->Draw(pHist1);
53 draw1->line.color = col1;
54 draw1->line.width = 2;
55 auto draw2 = canvas->Draw(pHist2);
56 draw2->secondy = true;
57 draw2->line.color = col2;
58 draw2->line.width = 4;
59
60 canvas->GetFrame()->y.ticks.color = col1;
61 canvas->GetFrame()->y2.ticks.color = col2;
62
63 canvas->SetSize(800, 600);
64 canvas->Show();
65}
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:275
const Int_t n
Definition legend1.C:16