Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
h1draw.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook -js
4 /// 1-D histogram drawing options.
5 /// We attach (or generate) the ROOT file in `$ROOTSYS/tutorials/hsimple.root`
6 /// or `$PWD/hsimple.root`
7 /// We draw one histogram in different formats.
8 ///
9 /// \macro_image
10 /// \macro_code
11 ///
12 /// \author Rene Brun
13 
14 #include "TInterpreter.h"
15 #include "TCanvas.h"
16 #include "TSystem.h"
17 #include "TFile.h"
18 #include "TH2.h"
19 #include "TNtuple.h"
20 #include "TPaveLabel.h"
21 #include "TPaveText.h"
22 #include "TFrame.h"
23 #include "TSystem.h"
24 #include "TInterpreter.h"
25 
26 void h1draw()
27 {
28  TString dir = gROOT->GetTutorialDir();
29  dir.Append("/hsimple.C");
30  dir.ReplaceAll("/./","/");
31  if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data());
32  TFile *example = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
33  if (!example) return;
34 
35  example->ls();
36  TH1 *hpx = (TH1*)example->Get("hpx");
37 
38  TCanvas *c1 = new TCanvas("c1","Histogram Drawing Options",200,10,700,900);
39  TPad *pad1 = new TPad("pad1",
40  "The pad with the function",0.03,0.62,0.50,0.92);
41  TPad *pad2 = new TPad("pad2",
42  "The pad with the histogram",0.51,0.62,0.98,0.92);
43  TPad *pad3 = new TPad("pad3",
44  "The pad with the histogram",0.03,0.02,0.97,0.57);
45  pad1->Draw();
46  pad2->Draw();
47  pad3->Draw();
48 
49  // Draw a global picture title
50  TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98,
51  "Drawing options for one dimensional histograms");
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->Draw();
62 
63  // Draw hpx as a lego. Clicking on the lego area will show
64  // a "transparent cube" to guide you rotating the lego in real time.
65  pad2->cd();
66  hpx->DrawCopy("lego1");
67  TPaveLabel *label2 = new TPaveLabel(-0.72,0.74,-0.22,0.88,"option Lego1");
68  label2->Draw();
69  TPaveLabel *label2a = new TPaveLabel(-0.93,-1.08,0.25,-0.92,
70  "Click on lego to rotate");
71  label2a->Draw();
72 
73  // Draw hpx with its errors and a marker.
74  pad3->cd();
75  pad3->SetGridx();
76  pad3->SetGridy();
77  hpx->SetMarkerStyle(21);
78  hpx->Draw("e1p");
79  TPaveLabel *label3 = new TPaveLabel(2,600,3.5,650,"option e1p");
80  label3->Draw();
81 
82  // The following illustrates how to add comments using a PaveText.
83  // Attributes of text/lines/boxes added to a PaveText can be modified.
84  // The AddText function returns a pointer to the added object.
85  TPaveText *pave = new TPaveText(-3.78,500,-1.2,750);
86  TText *t1=pave->AddText("You can move");
87  t1->SetTextColor(4);
88  t1->SetTextSize(0.05);
89  pave->AddText("Title and Stats pads");
90  pave->AddText("X and Y axis");
91  pave->AddText("You can modify bin contents");
92  pave->Draw();
93  c1->Update();
94 }