Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
cernstaff.C File Reference

Detailed Description

View in nbviewer Open in SWAN Playing with a Tree containing variables of type character

void cernstaff () {
TString dir = gROOT->GetTutorialDir();
dir.Append("/tree/cernstaff.C");
if (gSystem->AccessPathName("cernstaff.root")) {
gROOT->SetMacroPath(dir);
gROOT->ProcessLine(".x cernbuild.C");
}
TFile *f = new TFile("cernstaff.root");
TTree *T = (TTree*)f->Get("T");
TCanvas *c1 = new TCanvas("c1","CERN staff",10,10,1000,750);
c1->Divide(2,2);
// make table of number of people per Nation & Division
c1->cd(1); gPad->SetGrid();
T->Draw("Nation:Division>>hN","","text");
TH2F *hN = (TH2F*)gDirectory->Get("hN");
hN->SetMarkerSize(1.6);
hN->SetStats(0);
//make profile of Average cost per Nation
c1->cd(2); gPad->SetGrid();
gPad->SetLeftMargin(0.12);
T->Draw("Cost:Nation>>hNation","","prof,goff");
TH1F *hNation = (TH1F*)gDirectory->Get("hNation");
hNation->SetTitle("Average Cost per Nation");
hNation->LabelsOption(">"); //sort by decreasing bin contents
hNation->SetMaximum(13000);
hNation->SetMinimum(7000);
hNation->SetStats(0);
hNation->SetMarkerStyle(21);
hNation->Draw();
//make stacked plot of Nations versus Grade
c1->cd(3); gPad->SetGrid();
THStack *hGrades = new THStack("hGrades","Nations versus Grade");
TH1F *hFR = new TH1F("hFR","FR",12,3,15);
hGrades->Add(hFR);
T->Draw("Grade>>hFR","Nation==\"FR\"");
TH1F *hCH = new TH1F("hCH","CH",12,3,15);
hGrades->Add(hCH);
T->Draw("Grade>>hCH","Nation==\"CH\"");
TH1F *hIT = new TH1F("hIT","IT",12,3,15);
hGrades->Add(hIT);
T->Draw("Grade>>hIT","Nation==\"IT\"");
TH1F *hDE = new TH1F("hDE","DE",12,3,15);
hGrades->Add(hDE);
T->Draw("Grade>>hDE","Nation==\"DE\"");
TH1F *hGB = new TH1F("hGB","GB",12,3,15);
hGrades->Add(hGB);
T->Draw("Grade>>hGB","Nation==\"GB\"");
hGrades->Draw();
TLegend *legend = new TLegend(0.7,0.65,0.86,0.88);
legend->AddEntry(hGB,"GB","f");
legend->AddEntry(hDE,"DE","f");
legend->AddEntry(hIT,"IT","f");
legend->AddEntry(hCH,"CH","f");
legend->AddEntry(hFR,"FR","f");
legend->Draw();
//make histogram of age distribution
c1->cd(4); gPad->SetGrid();
T->Draw("Age");
T->Draw("Age>>hRetired","Age>(65-2002+1988)","same");
TH1F *hRetired = (TH1F*)gDirectory->Get("hRetired");
hRetired->SetFillColor(kRed);
hRetired->SetFillStyle(3010);
TArrow *arrow = new TArrow(32,169,55,74,0.03,"|>");
arrow->SetFillColor(1);
arrow->SetFillStyle(1001);
arrow->Draw();
TPaveText *pt = new TPaveText(0.12,0.8,0.55,0.88,"brNDC");
pt->AddText("People at CERN in 1988");
pt->AddText("and retired in 2002");
pt->Draw();
c1->cd();
}
#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
#define gDirectory
Definition TDirectory.h:290
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#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: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:23
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition TH1.cxx:6678
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Sort bins with labels or set option(s) to draw axis with labels.
Definition TH1.cxx:5313
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:398
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:399
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8830
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:251
The Histogram stack class.
Definition THStack.h:38
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition THStack.cxx:467
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:381
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.
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Basic string class.
Definition TString.h:136
TString & Append(const char *cs)
Definition TString.h:564
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
A TTree represents a columnar dataset.
Definition TTree.h:79
TPaveText * pt
return c1
Definition legend1.C:41
Author
Rene Brun

Definition in file cernstaff.C.