Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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);
h1->SetDirectory(nullptr);
for (int i=0;i<10000;i++)
h1->Fill(gRandom->Gaus(0,1));
//create hint1 filled with the bins integral of h1
auto hint1 = std::make_shared<TH1F>("hint1","h1 bins integral",100,-3,3);
hint1->SetDirectory(nullptr);
hint1->SetStats(kFALSE);
Float_t sum = 0;
for (int i=1;i<=100;i++) {
hint1->SetBinContent(i,sum);
}
hint1->SetLineColor(kRed);
hint1->GetYaxis()->SetAxisColor(kRed);
hint1->GetYaxis()->SetLabelColor(kRed);
// 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
canvas->Show();
// create PNG file
// canvas->SaveAs("th1_twoscales.png");
}
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
@ kRed
Definition Rtypes.h:66
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
Provides v7 drawing facilities for TObject types (TGraph, TH1, TH2, etc).
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:8803
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3338
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5025
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8856
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
Date
2021-07-05
Warning
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Author
Sergey Linev s.lin.nosp@m.ev@g.nosp@m.si.de

Definition in file th1_twoscales.cxx.