ROOT
master
Reference Guide
Loading...
Searching...
No Matches
tree501_cernstaff.C File Reference
Tutorials
»
IO tutorials
»
Tree tutorials
Detailed Description
Playing with a Tree containing variables of type character
void
tree501_cernstaff
()
{
TString
dir =
gROOT
->GetTutorialDir();
dir.
Append
(
"/io/tree/cernstaff.C"
);
if
(
gSystem
->
AccessPathName
(
"cernstaff.root"
)) {
gROOT
->SetMacroPath(dir);
gROOT
->ProcessLine(
".x tree500_cernbuild.C"
);
}
auto
f
=
TFile::Open
(
"cernstaff.root"
);
auto
T =
f
->Get<
TTree
>(
"T"
);
auto
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();
auto
hGrades
=
new
THStack
(
"hGrades"
,
"Nations versus Grade"
);
auto
hFR
=
new
TH1F
(
"hFR"
,
"FR"
, 12, 3, 15);
hFR
->SetFillColor(
kCyan
);
hGrades
->Add(
hFR
);
T->Draw(
"Grade>>hFR"
,
"Nation==\"FR\""
);
auto
hCH
=
new
TH1F
(
"hCH"
,
"CH"
, 12, 3, 15);
hCH
->SetFillColor(
kRed
);
hGrades
->Add(
hCH
);
T->Draw(
"Grade>>hCH"
,
"Nation==\"CH\""
);
auto
hIT
=
new
TH1F
(
"hIT"
,
"IT"
, 12, 3, 15);
hIT
->SetFillColor(
kGreen
);
hGrades
->Add(
hIT
);
T->Draw(
"Grade>>hIT"
,
"Nation==\"IT\""
);
auto
hDE
=
new
TH1F
(
"hDE"
,
"DE"
, 12, 3, 15);
hDE
->SetFillColor(
kYellow
);
hGrades
->Add(
hDE
);
T->Draw(
"Grade>>hDE"
,
"Nation==\"DE\""
);
auto
hGB
=
new
TH1F
(
"hGB"
,
"GB"
, 12, 3, 15);
hGB
->SetFillColor(
kBlue
);
hGrades
->Add(
hGB
);
T->Draw(
"Grade>>hGB"
,
"Nation==\"GB\""
);
hGrades
->Draw();
auto
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);
auto
arrow
=
new
TArrow
(32, 169, 55, 74, 0.03,
"|>"
);
arrow
->SetFillColor(1);
arrow
->SetFillStyle(1001);
arrow
->Draw();
auto
pt
=
new
TPaveText
(0.12, 0.8, 0.55, 0.88,
"brNDC"
);
pt
->
SetFillColor
(
kWhite
);
pt
->
AddText
(
"People at CERN in 1988"
);
pt
->
AddText
(
"and retired in 2002"
);
pt
->
Draw
();
c1
->cd();
}
f
#define f(i)
Definition
RSha256.hxx:104
kRed
@ kRed
Definition
Rtypes.h:66
kGreen
@ kGreen
Definition
Rtypes.h:66
kWhite
@ kWhite
Definition
Rtypes.h:65
kCyan
@ kCyan
Definition
Rtypes.h:66
kBlue
@ kBlue
Definition
Rtypes.h:66
kYellow
@ kYellow
Definition
Rtypes.h:66
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
gDirectory
#define gDirectory
Definition
TDirectory.h:384
gROOT
#define gROOT
Definition
TROOT.h:406
gSystem
R__EXTERN TSystem * gSystem
Definition
TSystem.h:572
gPad
#define gPad
Definition
TVirtualPad.h:308
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TArrow
Draw all kinds of Arrows.
Definition
TArrow.h:29
TAttFill::SetFillColor
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition
TAttFill.h:38
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TFile::Open
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:4130
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:647
TH2F
2-D histogram with a float per channel (see TH1 documentation)
Definition
TH2.h:307
THStack
The Histogram stack class.
Definition
THStack.h:40
TLegend
This class displays a legend box (TPaveText) containing several legend entries.
Definition
TLegend.h:23
TPaveText
A Pave (see TPave) with text, lines or/and boxes inside.
Definition
TPaveText.h:21
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:190
TPaveText::Draw
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
Definition
TPaveText.cxx:241
TString
Basic string class.
Definition
TString.h:139
TString::Append
TString & Append(const char *cs)
Definition
TString.h:572
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:1296
TTree
A TTree represents a columnar dataset.
Definition
TTree.h:79
pt
TPaveText * pt
Definition
entrylist_figure1.C:7
c1
return c1
Definition
legend1.C:41
arrow
Definition
RArrowDS.hxx:17
Author
Rene Brun
Definition in file
tree501_cernstaff.C
.
tutorials
io
tree
tree501_cernstaff.C
ROOT master - Reference Guide Generated on Thu Mar 13 2025 15:07:09 (GVA Time) using Doxygen 1.10.0