13 TString filedir = gROOT->GetTutorialDir();
14 filedir += TString(
"/tree/");
15 TString filename =
"cernstaff.root";
16 bool fileNotFound = gSystem->AccessPathName(filename);
20 TString macroName = filedir +
"cernbuild.C";
21 if (!gInterpreter->IsLoaded(macroName)) gInterpreter->LoadMacro(macroName);
22 gROOT->ProcessLineFast(
"cernbuild()");
24 TFile * f = TFile::Open(filename);
26 Error(
"hbars",
"file cernstaff.root not found");
29 TTree *T = (TTree*)f->Get(
"T");
31 Error(
"hbars",
"Tree T is not present in file %s",f->GetName() );
35 TCanvas *c1 =
new TCanvas(
"c1",
"histograms with bars",700,800);
40 c1->cd(1); gPad->SetGrid(); gPad->SetLogx(); gPad->SetFrameFillColor(33);
41 T->Draw(
"Nation",
"",
"hbar2");
44 c1->cd(2); gPad->SetGrid(); gPad->SetFrameFillColor(33);
45 T->Draw(
"Division>>hDiv",
"",
"goff");
46 TH1F *hDiv = (TH1F*)gDirectory->Get(
"hDiv");
48 TH1F *hDivFR = (TH1F*)hDiv->Clone(
"hDivFR");
49 T->Draw(
"Division>>hDivFR",
"Nation==\"FR\"",
"goff");
50 hDiv->SetBarWidth(0.45);
51 hDiv->SetBarOffset(0.1);
52 hDiv->SetFillColor(49);
53 TH1 *h1 = hDiv->DrawCopy(
"bar2");
54 hDivFR->SetBarWidth(0.4);
55 hDivFR->SetBarOffset(0.55);
56 hDivFR->SetFillColor(50);
57 TH1 *h2 = hDivFR->DrawCopy(
"bar2,same");
59 TLegend *legend =
new TLegend(0.55,0.65,0.76,0.82);
60 legend->AddEntry(h1,
"All nations",
"f");
61 legend->AddEntry(h2,
"French only",
"f");