Logo ROOT   6.10/09
Reference Guide
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tree
3 /// \notebook
4 /// Playing with a Tree containing variables of type character
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Rene Brun
11 void cernstaff () {
12  TString dir = gROOT->GetTutorialDir();
13  dir.Append("/tree/cernstaff.C");
14  if (gSystem->AccessPathName("cernstaff.root")) {
15  gROOT->SetMacroPath(dir);
16  gROOT->ProcessLine(".x cernbuild.C");
17  }
18  TFile *f = new TFile("cernstaff.root");
19  TTree *T = (TTree*)f->Get("T");
20  TCanvas *c1 = new TCanvas("c1","CERN staff",10,10,1000,750);
21  c1->Divide(2,2);
22  // make table of number of people per Nation & Division
23  c1->cd(1); gPad->SetGrid();
24  T->Draw("Nation:Division>>hN","","text");
25  TH2F *hN = (TH2F*)gDirectory->Get("hN");
26  hN->SetMarkerSize(1.6);
27  hN->SetStats(0);
29  //make profile of Average cost per Nation
30  c1->cd(2); gPad->SetGrid();
31  gPad->SetLeftMargin(0.12);
32  T->Draw("Cost:Nation>>hNation","","prof,goff");
33  TH1F *hNation = (TH1F*)gDirectory->Get("hNation");
34  hNation->SetTitle("Average Cost per Nation");
35  hNation->LabelsOption(">"); //sort by decreasing bin contents
36  hNation->SetMaximum(13000);
37  hNation->SetMinimum(7000);
38  hNation->SetStats(0);
39  hNation->SetMarkerStyle(21);
40  hNation->Draw();
42  //make stacked plot of Nations versus Grade
43  c1->cd(3); gPad->SetGrid();
44  THStack *hGrades = new THStack("hGrades","Nations versus Grade");
45  TH1F *hFR = new TH1F("hFR","FR",12,3,15);
46  hFR->SetFillColor(kCyan);
47  hGrades->Add(hFR);
48  T->Draw("Grade>>hFR","Nation==\"FR\"");
49  TH1F *hCH = new TH1F("hCH","CH",12,3,15);
50  hCH->SetFillColor(kRed);
51  hGrades->Add(hCH);
52  T->Draw("Grade>>hCH","Nation==\"CH\"");
53  TH1F *hIT = new TH1F("hIT","IT",12,3,15);
54  hIT->SetFillColor(kGreen);
55  hGrades->Add(hIT);
56  T->Draw("Grade>>hIT","Nation==\"IT\"");
57  TH1F *hDE = new TH1F("hDE","DE",12,3,15);
58  hDE->SetFillColor(kYellow);
59  hGrades->Add(hDE);
60  T->Draw("Grade>>hDE","Nation==\"DE\"");
61  TH1F *hGB = new TH1F("hGB","GB",12,3,15);
62  hGB->SetFillColor(kBlue);
63  hGrades->Add(hGB);
64  T->Draw("Grade>>hGB","Nation==\"GB\"");
65  hGrades->Draw();
66  TLegend *legend = new TLegend(0.7,0.65,0.86,0.88);
67  legend->AddEntry(hGB,"GB","f");
68  legend->AddEntry(hDE,"DE","f");
69  legend->AddEntry(hIT,"IT","f");
70  legend->AddEntry(hCH,"CH","f");
71  legend->AddEntry(hFR,"FR","f");
72  legend->Draw();
74  //make histogram of age distribution
75  c1->cd(4); gPad->SetGrid();
76  T->Draw("Age");
77  T->Draw("Age>>hRetired","Age>(65-2002+1988)","same");
78  TH1F *hRetired = (TH1F*)gDirectory->Get("hRetired");
79  hRetired->SetFillColor(kRed);
80  hRetired->SetFillStyle(3010);
82  TArrow *arrow = new TArrow(32,169,55,74,0.03,"|>");
83  arrow->SetFillColor(1);
84  arrow->SetFillStyle(1001);
85  arrow->Draw();
87  TPaveText *pt = new TPaveText(0.12,0.8,0.55,0.88,"brNDC");
88  pt->SetFillColor(kWhite);
89  pt->AddText("People at CERN in 1988");
90  pt->AddText("and retired in 2002");
91  pt->Draw();
93  c1->cd();
94 }
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1272
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:234
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:375
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:23
The Histogram stack class.
Definition: THStack.h:31
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Set option(s) to draw axis with labels.
Definition: TH1.cxx:4935
return c1
Definition: legend1.C:41
Definition: Rtypes.h:56
double T(double x)
Definition: ChebyshevPol.h:34
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:452
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:311
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
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
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:376
#define gROOT
Definition: TROOT.h:375
Basic string class.
Definition: TString.h:129
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:551
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
Definition: Rtypes.h:56
Definition: Rtypes.h:56
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:448
TLegend * legend
Definition: pirndm.C:35
TArrow * arrow
virtual void Draw(Option_t *option="")
Draw this arrow with its current attributes.
Definition: TArrow.cxx:122
TString & Append(const char *cs)
Definition: TString.h:497
Definition: Rtypes.h:55
TPaveText * pt
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
tomato 2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:249
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
The Canvas class.
Definition: TCanvas.h:31
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
double f(double x)
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:359
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:355
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
Definition: THStack.cxx:362
Definition: Rtypes.h:56
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1135
#define gPad
Definition: TVirtualPad.h:284
A TTree object has a header with a name and a title.
Definition: TTree.h:78
#define gDirectory
Definition: TDirectory.h:211
Definition: Rtypes.h:56
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6028
Draw all kinds of Arrows.
Definition: TArrow.h:29
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8103