Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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");
88  pt->SetFillColor(kWhite);
89  pt->AddText("People at CERN in 1988");
90  pt->AddText("and retired in 2002");
91  pt->Draw();
92 
93  c1->cd();
94 }