ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
h1draw.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// 1-D histogram drawing options.
4 /// We attach (or generate) the ROOT file in `$ROOTSYS/tutorials/hsimple.root`
5 /// or `$PWD/hsimple.root`
6 /// We draw one histogram in different formats.
7 ///
8 /// \macro_image
9 /// \macro_code
10 ///
11 /// \author Rene Brun
12 
13 #include "TInterpreter.h"
14 #include "TCanvas.h"
15 #include "TSystem.h"
16 #include "TFile.h"
17 #include "TH2.h"
18 #include "TNtuple.h"
19 #include "TPaveLabel.h"
20 #include "TPaveText.h"
21 #include "TFrame.h"
22 #include "TSystem.h"
23 #include "TInterpreter.h"
24 
25 void h1draw()
26 {
27  TString dir = gSystem->UnixPathName(__FILE__);
28  dir.ReplaceAll("h1draw.C","../hsimple.C");
29  dir.ReplaceAll("/./","/");
30  if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data());
31  TFile *example = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
32  if (!example) return;
33 
34  example->ls();
35  TH1 *hpx = (TH1*)example->Get("hpx");
36 
37  TCanvas *c1 = new TCanvas("c1","Histogram Drawing Options",200,10,700,900);
38  TPad *pad1 = new TPad("pad1",
39  "The pad with the function",0.03,0.62,0.50,0.92,21);
40  TPad *pad2 = new TPad("pad2",
41  "The pad with the histogram",0.51,0.62,0.98,0.92,21);
42  TPad *pad3 = new TPad("pad3",
43  "The pad with the histogram",0.03,0.02,0.97,0.57,21);
44  pad1->Draw();
45  pad2->Draw();
46  pad3->Draw();
47 
48  // Draw a global picture title
49  TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98,
50  "Drawing options for one dimensional histograms");
51  title->SetFillColor(16);
52  title->SetTextFont(52);
53  title->Draw();
54 
55  // Draw histogram hpx in first pad with the default option.
56  pad1->cd();
57  pad1->GetFrame()->SetFillColor(18);
58  hpx->SetFillColor(45);
59  hpx->DrawCopy();
60  TPaveLabel *label1 = new TPaveLabel(-3.5,700,-1,800,"Default option");
61  label1->SetFillColor(42);
62  label1->Draw();
63 
64  // Draw hpx as a lego. Clicking on the lego area will show
65  // a "transparent cube" to guide you rotating the lego in real time.
66  pad2->cd();
67  hpx->DrawCopy("lego1");
68  TPaveLabel *label2 = new TPaveLabel(-0.72,0.74,-0.22,0.88,"option Lego1");
69  label2->SetFillColor(42);
70  label2->Draw();
71  TPaveLabel *label2a = new TPaveLabel(-0.93,-1.08,0.25,-0.92,
72  "Click on lego to rotate");
73  label2a->SetFillColor(42);
74  label2a->Draw();
75 
76  // Draw hpx with its errors and a marker.
77  pad3->cd();
78  pad3->SetGridx();
79  pad3->SetGridy();
80  pad3->GetFrame()->SetFillColor(18);
81  hpx->SetMarkerStyle(21);
82  hpx->Draw("e1p");
83  TPaveLabel *label3 = new TPaveLabel(2,600,3.5,650,"option e1p");
84  label3->SetFillColor(42);
85  label3->Draw();
86 
87  // The following illustrates how to add comments using a PaveText.
88  // Attributes of text/lines/boxes added to a PaveText can be modified.
89  // The AddText function returns a pointer to the added object.
90  TPaveText *pave = new TPaveText(-3.78,500,-1.2,750);
91  pave->SetFillColor(42);
92  TText *t1=pave->AddText("You can move");
93  t1->SetTextColor(4);
94  t1->SetTextSize(0.05);
95  pave->AddText("Title and Stats pads");
96  pave->AddText("X and Y axis");
97  pave->AddText("You can modify bin contents");
98  pave->Draw();
99  c1->Update();
100 }
virtual void SetGridx(Int_t value=1)
Definition: TPad.h:327
virtual void ls(Option_t *option="") const
List file contents.
Definition: TFile.cxx:1361
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:211
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
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:160
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
#define gInterpreter
Definition: TInterpreter.h:502
Int_t GetBench(const char *name) const
Returns index of Benchmark name.
Definition: TBenchmark.cxx:106
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1020
const char * Data() const
Definition: TString.h:349
virtual void SetTextFont(Font_t tfont=62)
Definition: TAttText.h:59
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2729
Base class for several text objects.
Definition: TText.h:42
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition: TH1.cxx:2925
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1192
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:32
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:63
The most important graphics class in the ROOT system.
Definition: TPad.h:46
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
The Canvas class.
Definition: TCanvas.h:48
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:35
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:77
virtual void SetGridy(Int_t value=1)
Definition: TPad.h:328
The TH1 histogram class.
Definition: TH1.h:80
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
virtual void SetTextSize(Float_t tsize=1)
Definition: TAttText.h:60
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179