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
11void 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);
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}
#define f(i)
Definition: RSha256.hxx:104
@ kRed
Definition: Rtypes.h:64
@ kGreen
Definition: Rtypes.h:64
@ kWhite
Definition: Rtypes.h:63
@ kCyan
Definition: Rtypes.h:64
@ kBlue
Definition: Rtypes.h:64
@ kYellow
Definition: Rtypes.h:64
#define gDirectory
Definition: TDirectory.h:229
#define gROOT
Definition: TROOT.h:406
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
#define gPad
Definition: TVirtualPad.h:287
Draw all kinds of Arrows.
Definition: TArrow.h:29
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
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:27
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:571
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6345
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Set option(s) to draw axis with labels.
Definition: TH1.cxx:5222
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2998
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8446
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
The Histogram stack class.
Definition: THStack.h:31
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:445
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:359
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:23
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:330
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:423
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
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:182
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:233
Basic string class.
Definition: TString.h:131
TString & Append(const char *cs)
Definition: TString.h:559
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:1291
A TTree represents a columnar dataset.
Definition: TTree.h:78
TPaveText * pt
return c1
Definition: legend1.C:41
double T(double x)
Definition: ChebyshevPol.h:34