ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cernstaff.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tree
3 ///
4 /// Playing with a Tree containing variables of type character
5 /// \macro_image
6 /// \macro_code
7 /// \author Rene Brun
8 void cernstaff () {
9  TString dir = gSystem->DirName(__FILE__);
10  if (gSystem->AccessPathName("cernstaff.root")) {
11  gROOT->SetMacroPath(dir);
12  gROOT->ProcessLine(".x cernbuild.C");
13  }
14  TFile *f = new TFile("cernstaff.root");
15  TTree *T = (TTree*)f->Get("T");
16  TCanvas *c1 = new TCanvas("c1","CERN staff",10,10,1000,750);
17  c1->Divide(2,2);
18  // make table of number of people per Nation & Division
19  c1->cd(1); gPad->SetGrid();
20  T->Draw("Nation:Division>>hN","","text");
21  TH2F *hN = (TH2F*)gDirectory->Get("hN");
22  hN->SetMarkerSize(1.6);
23  hN->SetStats(0);
24 
25  //make profile of Average cost per Nation
26  c1->cd(2); gPad->SetGrid();
27  gPad->SetLeftMargin(0.12);
28  T->Draw("Cost:Nation>>hNation","","prof,goff");
29  TH1F *hNation = (TH1F*)gDirectory->Get("hNation");
30  hNation->SetTitle("Average Cost per Nation");
31  hNation->LabelsOption(">"); //sort by decreasing bin contents
32  hNation->SetMaximum(13000);
33  hNation->SetMinimum(7000);
34  hNation->SetStats(0);
35  hNation->SetMarkerStyle(21);
36  hNation->Draw();
37 
38  //make stacked plot of Nations versus Grade
39  c1->cd(3); gPad->SetGrid();
40  THStack *hGrades = new THStack("hGrades","Nations versus Grade");
41  TH1F *hFR = new TH1F("hFR","FR",12,3,15);
42  hFR->SetFillColor(kCyan);
43  hGrades->Add(hFR);
44  T->Draw("Grade>>hFR","Nation==\"FR\"");
45  TH1F *hCH = new TH1F("hCH","CH",12,3,15);
46  hCH->SetFillColor(kRed);
47  hGrades->Add(hCH);
48  T->Draw("Grade>>hCH","Nation==\"CH\"");
49  TH1F *hIT = new TH1F("hIT","IT",12,3,15);
50  hIT->SetFillColor(kGreen);
51  hGrades->Add(hIT);
52  T->Draw("Grade>>hIT","Nation==\"IT\"");
53  TH1F *hDE = new TH1F("hDE","DE",12,3,15);
54  hDE->SetFillColor(kYellow);
55  hGrades->Add(hDE);
56  T->Draw("Grade>>hDE","Nation==\"DE\"");
57  TH1F *hGB = new TH1F("hGB","GB",12,3,15);
58  hGB->SetFillColor(kBlue);
59  hGrades->Add(hGB);
60  T->Draw("Grade>>hGB","Nation==\"GB\"");
61  hGrades->Draw();
62  TLegend *legend = new TLegend(0.7,0.65,0.86,0.88);
63  legend->AddEntry(hGB,"GB","f");
64  legend->AddEntry(hDE,"DE","f");
65  legend->AddEntry(hIT,"IT","f");
66  legend->AddEntry(hCH,"CH","f");
67  legend->AddEntry(hFR,"FR","f");
68  legend->Draw();
69 
70  //make histogram of age distribution
71  c1->cd(4); gPad->SetGrid();
72  T->Draw("Age");
73  T->Draw("Age>>hRetired","Age>(65-2002+1988)","same");
74  TH1F *hRetired = (TH1F*)gDirectory->Get("hRetired");
75  hRetired->SetFillColor(kRed);
76  hRetired->SetFillStyle(3010);
77 
78  TArrow *arrow = new TArrow(32,169,55,74,0.03,"|>");
79  arrow->SetFillColor(1);
80  arrow->SetFillStyle(1001);
81  arrow->Draw();
82 
83  TPaveText *pt = new TPaveText(0.12,0.8,0.55,0.88,"brNDC");
84  pt->SetFillColor(kWhite);
85  pt->AddText("People at CERN in 1988");
86  pt->AddText("and retired in 2002");
87  pt->Draw();
88 
89  c1->cd();
90 }
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:1213
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:211
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
The Histogram stack class.
Definition: THStack.h:35
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Set option(s) to draw axis with labels.
Definition: TH1.cxx:4901
Definition: Rtypes.h:61
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
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.
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:980
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
Definition: Rtypes.h:61
Definition: Rtypes.h:61
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:422
virtual void Draw(Option_t *option="")
Draw this arrow with its current attributes.
Definition: TArrow.cxx:121
Definition: Rtypes.h:60
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
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
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
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:360
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:336
Definition: Rtypes.h:61
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:1073
#define gPad
Definition: TVirtualPad.h:288
A TTree object has a header with a name and a title.
Definition: TTree.h:98
#define gDirectory
Definition: TDirectory.h:221
Definition: Rtypes.h:61
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6268
Draw all kinds of Arrows.
Definition: TArrow.h:35
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8320