Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tree501_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
12{
13 TString dir = gROOT->GetTutorialDir();
14 dir.Append("/io/tree/cernstaff.C");
15 if (gSystem->AccessPathName("cernstaff.root")) {
16 gROOT->SetMacroPath(dir);
17 gROOT->ProcessLine(".x tree500_cernbuild.C");
18 }
19 auto f = TFile::Open("cernstaff.root");
20 auto T = f->Get<TTree>("T");
21 auto c1 = new TCanvas("c1", "CERN staff", 10, 10, 1000, 750);
22 c1->Divide(2, 2);
23 // make table of number of people per Nation & Division
24 c1->cd(1);
25 gPad->SetGrid();
26 T->Draw("Nation:Division>>hN", "", "text");
27 TH2F *hN = (TH2F*)gDirectory->Get("hN");
28 hN->SetMarkerSize(1.6);
29 hN->SetStats(0);
30
31 //make profile of Average cost per Nation
32 c1->cd(2);
33 gPad->SetGrid();
34 gPad->SetLeftMargin(0.12);
35 T->Draw("Cost:Nation>>hNation", "", "prof,goff");
36 TH1F *hNation = (TH1F*)gDirectory->Get("hNation");
37 hNation->SetTitle("Average Cost per Nation");
38 hNation->LabelsOption(">"); //sort by decreasing bin contents
39 hNation->SetMaximum(13000);
40 hNation->SetMinimum(7000);
41 hNation->SetStats(0);
42 hNation->SetMarkerStyle(21);
43 hNation->Draw();
44
45 //make stacked plot of Nations versus Grade
46 c1->cd(3);
47 gPad->SetGrid();
48 auto hGrades = new THStack("hGrades", "Nations versus Grade");
49 auto hFR = new TH1F("hFR", "FR", 12, 3, 15);
50 hFR->SetFillColor(kCyan);
51 hGrades->Add(hFR);
52 T->Draw("Grade>>hFR", "Nation==\"FR\"");
53 auto hCH = new TH1F("hCH", "CH", 12, 3, 15);
54 hCH->SetFillColor(kRed);
55 hGrades->Add(hCH);
56 T->Draw("Grade>>hCH","Nation==\"CH\"");
57 auto hIT = new TH1F("hIT", "IT", 12, 3, 15);
58 hIT->SetFillColor(kGreen);
59 hGrades->Add(hIT);
60 T->Draw("Grade>>hIT","Nation==\"IT\"");
61 auto hDE = new TH1F("hDE","DE", 12, 3, 15);
62 hDE->SetFillColor(kYellow);
63 hGrades->Add(hDE);
64 T->Draw("Grade>>hDE","Nation==\"DE\"");
65 auto hGB = new TH1F("hGB","GB", 12, 3, 15);
66 hGB->SetFillColor(kBlue);
67 hGrades->Add(hGB);
68 T->Draw("Grade>>hGB","Nation==\"GB\"");
69 hGrades->Draw();
70 auto legend = new TLegend(0.7, 0.65, 0.86, 0.88);
71 legend->AddEntry(hGB,"GB","f");
72 legend->AddEntry(hDE,"DE","f");
73 legend->AddEntry(hIT,"IT","f");
74 legend->AddEntry(hCH,"CH","f");
75 legend->AddEntry(hFR,"FR","f");
76 legend->Draw();
77
78 //make histogram of age distribution
79 c1->cd(4); gPad->SetGrid();
80 T->Draw("Age");
81 T->Draw("Age>>hRetired", "Age>(65-2002+1988)", "same");
82 TH1F *hRetired = (TH1F*)gDirectory->Get("hRetired");
83 hRetired->SetFillColor(kRed);
84 hRetired->SetFillStyle(3010);
85
86 auto arrow = new TArrow(32, 169, 55, 74, 0.03, "|>");
87 arrow->SetFillColor(1);
88 arrow->SetFillStyle(1001);
89 arrow->Draw();
90
91 auto pt = new TPaveText(0.12, 0.8, 0.55, 0.88, "brNDC");
93 pt->AddText("People at CERN in 1988");
94 pt->AddText("and retired in 2002");
95 pt->Draw();
96
97 c1->cd();
98}
#define f(i)
Definition RSha256.hxx:104
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
@ kWhite
Definition Rtypes.h:65
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kYellow
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gDirectory
Definition TDirectory.h:384
#define gROOT
Definition TROOT.h:414
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define gPad
Draw all kinds of Arrows.
Definition TArrow.h:29
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
The Canvas class.
Definition TCanvas.h:23
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4131
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:877
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
The Histogram stack class.
Definition THStack.h:40
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
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.
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
Basic string class.
Definition TString.h:139
TString & Append(const char *cs)
Definition TString.h:572
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:1308
A TTree represents a columnar dataset.
Definition TTree.h:84
TPaveText * pt
return c1
Definition legend1.C:41