ROOT
Version v6.34
master
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
▼
ROOT
ROOT Reference Documentation
Tutorials
▼
Functional Parts
►
Core ROOT classes
►
std Extension classes
►
Parallelized classes
►
The Geometry Package
►
Graphics
►
Event display with ROOT7
►
GUI
►
Web Widgets
►
Web Display
►
Histogram Library
►
Input/Output Library
►
Math
►
N-D parametric functions
►
VecOps
►
Monte Carlo
►
HTTP server
►
PROOF
►
TMVA
►
RooFit
►
Dataframe
►
ROOT7 classes
►
NTuple-related classes
►
Tree Library
►
TreePlayer Library
▼
Tutorials
▼
Histograms tutorials
candledecay.C
candlehisto.C
candleplot.C
candleplotoption.C
candleplotstack.C
candleplotwhiskers.C
candlescaled.C
ContourList.C
cumulative.C
draw2dopt.C
DynamicSlice.C
exec1.C
exec2.C
Fibonacci.C
fillhistosauto2p.C
fillrandom.C
fillrandom.py
FirstContour.C
greyscale.C
h1ReadAndDraw.C
h2_cut.C
h2proj.C
hbars.C
histpalettecolor.C
hksimple.C
hlabels1.C
hlabels2.C
hlHisto1.C
hlHisto2.C
hlHisto3.C
hlHisto4.C
hstack.C
hstackpads.C
hsum.C
hsumTimer.C
legendautoplaced.C
logscales.C
movepalette.C
multicolor.C
NormalizeHistogram.C
ratioplot1.C
ratioplot1.py
ratioplot2.C
ratioplot2.py
ratioplot3.C
ratioplot3.py
ratioplot4.C
ratioplot4.py
ratioplot5.C
ratioplot5.py
ratioplot6.C
ratioplot6.py
ratioplotOld.C
rebin.C
reverseaxis.C
sparsehist.C
statsEditing.C
testSmooth.C
th2polyBoxes.C
th2polyEurope.C
th2polyHoneycomb.C
th2polyUSA.C
thstack2palettecolor.C
thstackcolorscheme.C
thstackpalettecolor.C
tprofile2polyRealistic.C
tprofile2polyRealisticModuleError.C
transpad.C
twoscales.C
twoscales.py
xyplot.C
ZoomHistogram.C
►
Tree tutorials
►
Dataframe tutorials
►
ROOT 7 tutorials
►
FOAM tutorials
►
Containers tutorials
►
Event display tutorials
►
Event display ROOT7 tutorials
►
Geometry tutorials
►
Fast Fourier Transforms tutorials
►
Fit Tutorials
►
RooFit Tutorials
►
Graphs tutorials
►
Graphics tutorials
►
OpenGL tutorials
►
Tutorials specific to Mac/Cocoa
►
GUI tutorials
►
HistFactory Tutorials
►
HTTP tutorials
►
Image tutorials
►
IO tutorials
►
Math tutorials
►
Matrix tutorials
►
Monte Carlo tutorials
►
Multicore tutorials
►
Net tutorials
►
Physics tutorials
►
PyRoot tutorials
►
Pythia tutorials
►
Quadratic programming package.
►
R tutorials
►
RooStats Tutorials
►
Spectrum tutorials
►
TSPlot tutorials
►
SQL tutorials
►
TMVA tutorials
►
TUnfold tutorials
►
Unuran tutorials
►
VecOps tutorials
►
FITS files interface tutorials
►
XML tutorials
►
Proof tutorials
►
TWebCanvas tutorials
►
Webgui tutorials
►
Legacy tutorials
demos.C
demoshelp.C
hsimple.C
rootlogoff.C
rootlogon.C
►
R Interface for Statistical Computing
►
Namespaces
►
All Classes
►
Files
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
hbars.C File Reference
Tutorials
»
Histograms tutorials
Detailed Description
Example of bar charts with 1-d histograms.
TCanvas
*
hbars
()
{
// Try to open first the file cernstaff.root in tutorials/tree directory
TString
filedir
=
gROOT
->GetTutorialDir();
filedir
+=
TString
(
"/tree/"
);
TString
filename
=
"cernstaff.root"
;
bool
fileNotFound
=
gSystem
->
AccessPathName
(
filename
);
// note opposite return code
// If file is not found try to generate it using the macro tree/cernbuild.C
if
(
fileNotFound
) {
TString
macroName
=
filedir
+
"cernbuild.C"
;
if
(!
gInterpreter
->IsLoaded(
macroName
))
gInterpreter
->LoadMacro(
macroName
);
gROOT
->ProcessLineFast(
"cernbuild()"
);
}
TFile
*
f
=
TFile::Open
(
filename
);
if
(!
f
) {
Error
(
"hbars"
,
"file cernstaff.root not found"
);
return
nullptr
;
}
TTree
*T = (
TTree
*)
f
->Get(
"T"
);
if
(!T) {
Error
(
"hbars"
,
"Tree T is not present in file %s"
,
f
->GetName());
return
nullptr
;
}
T->SetFillColor(45);
TCanvas
*
c1
=
new
TCanvas
(
"c1"
,
"histograms with bars"
,700,800);
c1
->SetFillColor(42);
c1
->Divide(1,2);
// Horizontal bar chart
c1
->cd(1);
gPad
->SetGrid();
gPad
->SetLogx();
gPad
->SetFrameFillColor(33);
T->Draw(
"Nation"
,
""
,
"hbar2"
);
// Vertical bar chart
c1
->cd(2);
gPad
->SetGrid();
gPad
->SetFrameFillColor(33);
T->Draw(
"Division>>hDiv"
,
""
,
"goff"
);
TH1F
*
hDiv
= (
TH1F
*)
gDirectory
->Get(
"hDiv"
);
hDiv
->SetStats(0);
TH1F
*
hDivFR
= (
TH1F
*)
hDiv
->Clone(
"hDivFR"
);
T->Draw(
"Division>>hDivFR"
,
"Nation==\"FR\""
,
"goff"
);
hDiv
->SetBarWidth(0.45);
hDiv
->SetBarOffset(0.1);
hDiv
->SetFillColor(49);
TH1
*
h1
=
hDiv
->DrawCopy(
"bar2"
);
hDivFR
->SetBarWidth(0.4);
hDivFR
->SetBarOffset(0.55);
hDivFR
->SetFillColor(50);
TH1
*
h2
=
hDivFR
->DrawCopy(
"bar2,same"
);
TLegend
*
legend
=
new
TLegend
(0.55,0.65,0.76,0.82);
legend
->AddEntry(
h1
,
"All nations"
,
"f"
);
legend
->AddEntry(h2,
"French only"
,
"f"
);
legend
->Draw();
c1
->cd();
delete
f
;
return
c1
;
}
f
#define f(i)
Definition
RSha256.hxx:104
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
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition
TError.cxx:185
filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Definition
TGWin32VirtualXProxy.cxx:232
gInterpreter
#define gInterpreter
Definition
TInterpreter.h:573
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
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TFile
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition
TFile.h:53
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:4094
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:622
TH1
TH1 is the base class of all histogram classes in ROOT.
Definition
TH1.h:59
TLegend
This class displays a legend box (TPaveText) containing several legend entries.
Definition
TLegend.h:23
TString
Basic string class.
Definition
TString.h:139
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
c1
return c1
Definition
legend1.C:41
h1
TH1F * h1
Definition
legend1.C:5
TMVA_SOFIE_GNN_Parser.h2
h2
Definition
TMVA_SOFIE_GNN_Parser.py:188
Author
Rene Brun
Definition in file
hbars.C
.
tutorials
hist
hbars.C
ROOT tags/6-34-04 - Reference Guide Generated on Wed Mar 26 2025 04:46:35 (GVA Time) using Doxygen 1.10.0