ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ntuple1.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tree
3 ///
4 /// Simple tree analysis.
5 ///
6 /// \macro_image
7 /// \macro_code
8 /// \author Rene Brun
9 #include "TCanvas.h"
10 #include "TFile.h"
11 #include "TNtuple.h"
12 #include "TProfile.h"
13 #include "TBenchmark.h"
14 #include "TStyle.h"
15 #include "TPaveText.h"
16 #include "TFrame.h"
17 #include "TF1.h"
18 #include "TROOT.h"
19 #include "TSystem.h"
20 #include "TInterpreter.h"
21 
22 void ntuple1() {
23 
24  //just in case this script is executed multiple times
25  delete gROOT->GetListOfFiles()->FindObject("hsimple.root");
26  delete gROOT->GetListOfCanvases()->FindObject("c1");
27 
28  gBenchmark->Start("ntuple1");
29  //
30  // Connect ROOT histogram/ntuple demonstration file
31  // generated by example $ROOTSYS/tutorials/hsimple.C.
32  TString dir = gSystem->UnixPathName(__FILE__);
33  dir.ReplaceAll("ntuple1.C","../hsimple.C");
34  dir.ReplaceAll("/./","/");
35  if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data());
36  TFile *f1 = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
37  if (!f1) return;
38  //
39  // Create a canvas, with 4 pads
40  //
41  TCanvas *c1 = new TCanvas("c1","The Ntuple canvas",200,10,700,780);
42  TPad *pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.48,0.98,21);
43  TPad *pad2 = new TPad("pad2","This is pad2",0.52,0.52,0.98,0.98,21);
44  TPad *pad3 = new TPad("pad3","This is pad3",0.02,0.02,0.48,0.48,21);
45  TPad *pad4 = new TPad("pad4","This is pad4",0.52,0.02,0.98,0.48,1);
46  pad1->Draw();
47  pad2->Draw();
48  pad3->Draw();
49  pad4->Draw();
50  //
51  // Change default style for the statistics box
52  gStyle->SetStatW(0.30);
53  gStyle->SetStatH(0.20);
54  //
55  // Display a function of one ntuple column imposing a condition
56  // on another column.
57  pad1->cd();
58  pad1->SetGrid();
59  pad1->SetLogy();
60  TNtuple *ntuple = (TNtuple*)f1->Get("ntuple");
61  ntuple->SetLineColor(1);
62  ntuple->SetFillStyle(1001);
63  ntuple->SetFillColor(45);
64  ntuple->Draw("3*px+2","px**2+py**2>1");
65  ntuple->SetFillColor(38);
66  ntuple->Draw("2*px+2","pz>2","same");
67  ntuple->SetFillColor(5);
68  ntuple->Draw("1.3*px+2","(px^2+py^2>4) && py>0","same");
69  pad1->RedrawAxis();
70  //
71  // Display the profile of two columns
72  // The profile histogram produced is saved in the current directory with
73  // the name hprofs
74  pad2->cd();
75  pad2->SetGrid();
76  ntuple->Draw("pz:px>>hprofs","","goffprofs");
77  TProfile *hprofs = (TProfile*)gDirectory->Get("hprofs");
78  hprofs->SetMarkerColor(5);
79  hprofs->SetMarkerSize(0.7);
80  hprofs->SetMarkerStyle(21);
81  hprofs->Fit("pol2");
82  // Get pointer to fitted function and modify its attributes
83  TF1 *fpol2 = hprofs->GetFunction("pol2");
84  fpol2->SetLineWidth(4);
85  fpol2->SetLineColor(2);
86  //
87  // Display a scatter plot of two columns with a selection.
88  // Superimpose the result of another cut with a different marker color
89  pad3->cd();
90  pad3->GetFrame()->SetBorderSize(8);
91  ntuple->SetMarkerColor(1);
92  ntuple->Draw("py:px","pz>1");
93  ntuple->SetMarkerColor(2);
94  ntuple->Draw("py:px","pz<1","same");
95  //
96  // Display a 3-D scatter plot of 3 columns. Superimpose a different selection.
97  pad4->cd();
98  ntuple->Draw("pz:py:px","(pz<10 && pz>6)+(pz<4 && pz>3)");
99  ntuple->SetMarkerColor(4);
100  ntuple->Draw("pz:py:px","pz<6 && pz>4","same");
101  ntuple->SetMarkerColor(5);
102  ntuple->Draw("pz:py:px","pz<4 && pz>3","same");
103  TPaveText *l4 = new TPaveText(-0.9,0.5,0.9,0.95);
104  l4->SetFillColor(42);
105  l4->SetTextAlign(12);
106  l4->AddText("You can interactively rotate this view in 2 ways:");
107  l4->AddText(" - With the RotateCube in clicking in this pad");
108  l4->AddText(" - Selecting View with x3d in the View menu");
109  l4->Draw();
110  //
111  c1->cd();
112  c1->Update();
113  gStyle->SetStatColor(19);
114  gBenchmark->Show("ntuple1");
115 }
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:211
void SetStatColor(Color_t color=19)
Definition: TStyle.h:384
void SetStatH(Float_t h=0.1)
Definition: TStyle.h:394
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
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
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:155
Basic string class.
Definition: TString.h:137
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
#define gInterpreter
Definition: TInterpreter.h:502
Profile Historam.
Definition: TProfile.h:34
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
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:172
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2729
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:326
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
virtual void RedrawAxis(Option_t *option="")
Redraw the frame axis Redrawing axis may be necessary in case of superimposed histograms when one or ...
Definition: TPad.cxx:4705
virtual void SetBorderSize(Short_t bordersize)
Definition: TWbox.h:63
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1192
virtual void SetTextAlign(Short_t align=11)
Definition: TAttText.h:55
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:30
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
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
void SetStatW(Float_t w=0.19)
Definition: TStyle.h:393
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
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 *opt)
Default Draw method for all objects.
Definition: TTree.h:360
1-Dim function class
Definition: TF1.h:149
#define gDirectory
Definition: TDirectory.h:221
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
Definition: TH1.cxx:3607
virtual TF1 * GetFunction(const char *name) const
Return pointer to function with name.
Definition: TH1.cxx:8382
virtual void SetLogy(Int_t value=1)
Set Lin/Log scale for Y.
Definition: TPad.cxx:5314