Logo ROOT  
Reference Guide
h1draw.C File Reference

Detailed Description

View in nbviewer Open in SWAN 1-D histogram drawing options. We attach (or generate) the ROOT file in $ROOTSYS/tutorials/hsimple.root or $PWD/hsimple.root We draw one histogram in different formats.

#include "TInterpreter.h"
#include "TCanvas.h"
#include "TSystem.h"
#include "TFile.h"
#include "TH2.h"
#include "TNtuple.h"
#include "TPaveLabel.h"
#include "TPaveText.h"
#include "TFrame.h"
#include "TSystem.h"
#include "TInterpreter.h"
void h1draw()
{
TString dir = gROOT->GetTutorialDir();
dir.Append("/hsimple.C");
dir.ReplaceAll("/./","/");
if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data());
TFile *example = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
if (!example) return;
example->ls();
TH1 *hpx = (TH1*)example->Get("hpx");
TCanvas *c1 = new TCanvas("c1","Histogram Drawing Options",200,10,700,900);
TPad *pad1 = new TPad("pad1",
"The pad with the function",0.03,0.62,0.50,0.92);
TPad *pad2 = new TPad("pad2",
"The pad with the histogram",0.51,0.62,0.98,0.92);
TPad *pad3 = new TPad("pad3",
"The pad with the histogram",0.03,0.02,0.97,0.57);
pad1->Draw();
pad2->Draw();
pad3->Draw();
// Draw a global picture title
TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98,
"Drawing options for one dimensional histograms");
title->SetTextFont(52);
title->Draw();
// Draw histogram hpx in first pad with the default option.
pad1->cd();
pad1->GetFrame()->SetFillColor(18);
hpx->SetFillColor(45);
hpx->DrawCopy();
TPaveLabel *label1 = new TPaveLabel(-3.5,700,-1,800,"Default option");
label1->Draw();
// Draw hpx as a lego. Clicking on the lego area will show
// a "transparent cube" to guide you rotating the lego in real time.
pad2->cd();
hpx->DrawCopy("lego1");
TPaveLabel *label2 = new TPaveLabel(-0.72,0.74,-0.22,0.88,"option Lego1");
label2->Draw();
TPaveLabel *label2a = new TPaveLabel(-0.93,-1.08,0.25,-0.92,
"Click on lego to rotate");
label2a->Draw();
// Draw hpx with its errors and a marker.
pad3->cd();
pad3->SetGridx();
pad3->SetGridy();
hpx->SetMarkerStyle(21);
hpx->Draw("e1p");
TPaveLabel *label3 = new TPaveLabel(2,600,3.5,650,"option e1p");
label3->Draw();
// The following illustrates how to add comments using a PaveText.
// Attributes of text/lines/boxes added to a PaveText can be modified.
// The AddText function returns a pointer to the added object.
TPaveText *pave = new TPaveText(-3.78,500,-1.2,750);
TText *t1=pave->AddText("You can move");
t1->SetTextColor(4);
t1->SetTextSize(0.05);
pave->AddText("Title and Stats pads");
pave->AddText("X and Y axis");
pave->AddText("You can modify bin contents");
pave->Draw();
c1->Update();
}
Author
Rene Brun

Definition in file h1draw.C.

h1draw
Definition: h1draw.py:1
TPad
Definition: TPad.h:26
TString::Data
const char * Data() const
Definition: TString.h:369
TH1::DrawCopy
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition: TH1.cxx:3044
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:558
TPad::SetGridy
virtual void SetGridy(Int_t value=1)
Definition: TPad.h:329
TCanvas.h
TString
Definition: TString.h:136
TFile.h
TPaveLabel::Draw
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:77
TPaveLabel.h
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TPaveText.h
example
Definition: example.py:1
TNtuple.h
TPaveText::Draw
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:234
TBenchmark::GetBench
Int_t GetBench(const char *name) const
Returns index of Benchmark name.
Definition: TBenchmark.cxx:106
TPad::SetGridx
virtual void SetGridx(Int_t value=1)
Definition: TPad.h:328
TSystem.h
gBenchmark
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:59
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TH2.h
TFile
Definition: TFile.h:54
TPaveText::AddText
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:183
TPaveLabel
Definition: TPaveLabel.h:20
TText
Definition: TText.h:22
TCanvas
Definition: TCanvas.h:23
t1
auto * t1
Definition: textangle.C:20
TInterpreter.h
TPad::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
TFrame.h
TH1
Definition: TH1.h:57
TPad::GetFrame
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2847
TPaveText
Definition: TPaveText.h:21
gROOT
#define gROOT
Definition: TROOT.h:406
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
c1
return c1
Definition: legend1.C:41
TPad::Draw
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1285