Logo ROOT  
Reference Guide
th1_twoscales.cxx File Reference

Detailed Description

Macro illustrating how to superimpose two histograms with different scales on the RCanvas.

It shows exactly same data as in hist/twoscales.C macro, but with fully interactive graphics

* Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
#include "ROOT/RCanvas.hxx"
#include "TH1.h"
#include "TRandom.h"
using namespace ROOT::Experimental;
void th1_twoscales()
//create/fill draw h1
auto h1 = std::make_shared<TH1F>("h1","Example histogram",100,-3,3);
for (int i=0;i<10000;i++)
//create hint1 filled with the bins integral of h1
auto hint1 = std::make_shared<TH1F>("hint1","h1 bins integral",100,-3,3);
Float_t sum = 0;
for (int i=1;i<=100;i++) {
// Create a canvas to be displayed.
auto canvas = RCanvas::Create("Two TH1 with two independent Y scales");
// just draw histogram on RCanvas
canvas->Draw<TObjectDrawable>(h1, "");
// add second histogram and specify Y+ draw option
canvas->Draw<TObjectDrawable>(hint1, "same,Y+");
// new window in web browser should popup
// create PNG file
// canvas->SaveAs("th1_twoscales.png");
const Bool_t kFALSE
Definition: RtypesCore.h:101
float Float_t
Definition: RtypesCore.h:57
@ kRed
Definition: Rtypes.h:66
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8780
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3351
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4994
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8833
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
TH1F * h1
Definition: legend1.C:5
static uint64_t sum(uint64_t i)
Definition: Factory.cxx:2345
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Sergey Linev s.lin.nosp@m.ev@g.nosp@m.si.de

Definition in file th1_twoscales.cxx.