Logo ROOT  
Reference Guide
cernstaff.C
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
10 
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);
28 
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();
41 
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();
73 
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);
81 
82  TArrow *arrow = new TArrow(32,169,55,74,0.03,"|>");
83  arrow->SetFillColor(1);
84  arrow->SetFillStyle(1001);
85  arrow->Draw();
86 
87  TPaveText *pt = new TPaveText(0.12,0.8,0.55,0.88,"brNDC");
89  pt->AddText("People at CERN in 1988");
90  pt->AddText("and retired in 2002");
91  pt->Draw();
92 
93  c1->cd();
94 }
TAttMarker::SetMarkerSize
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
TH1::LabelsOption
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Set option(s) to draw axis with labels.
Definition: TH1.cxx:5285
f
#define f(i)
Definition: RSha256.hxx:104
TAttFill::SetFillStyle
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
TH1::SetMinimum
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:397
kGreen
@ kGreen
Definition: Rtypes.h:66
TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
THStack
The Histogram stack class.
Definition: THStack.h:38
THStack::Add
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:361
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
TString
Basic string class.
Definition: TString.h:136
TSystem::AccessPathName
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:1294
TH1::SetTitle
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6564
TPaveText::Draw
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:234
kCyan
@ kCyan
Definition: Rtypes.h:66
kWhite
@ kWhite
Definition: Rtypes.h:65
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TH1::SetMaximum
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:396
TLegend::AddEntry
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:330
gDirectory
#define gDirectory
Definition: TDirectory.h:236
kRed
@ kRed
Definition: Rtypes.h:66
TH1::SetStats
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8665
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TPaveText::AddText
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
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:573
arrow
Definition: RArrowDS.hxx:9
TAttFill::SetFillColor
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
TArrow
Draw all kinds of Arrows.
Definition: TArrow.h:29
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
kBlue
@ kBlue
Definition: Rtypes.h:66
gPad
#define gPad
Definition: TVirtualPad.h:287
TLegend::Draw
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:423
TPaveText
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
TLegend
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:23
TAttMarker::SetMarkerStyle
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
pt
TPaveText * pt
Definition: entrylist_figure1.C:7
THStack::Draw
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:447
kYellow
@ kYellow
Definition: Rtypes.h:66
gROOT
#define gROOT
Definition: TROOT.h:406
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3050
c1
return c1
Definition: legend1.C:41