ROOT
Version master
master
v6.34
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
v6.04
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
hist000_TH1_first.C
hist000_TH1_first.py
hist001_TH1_fillrandom.C
hist001_TH1_fillrandom.py
hist002_TH1_fillrandom_userfunc.C
hist002_TH1_fillrandom_userfunc.py
hist003_TH1_draw.C
hist003_TH1_draw.py
hist004_TH1_labels.C
hist005_TH1_palettecolor.C
hist006_TH1_bar_charts.C
hist007_TH1_liveupdate.C
hist007_TH1_liveupdate.py
hist008_TH1_zoom.C
hist009_TH1_normalize.C
hist010_TH1_two_scales.C
hist010_TH1_two_scales.py
hist011_TH1_legend_autoplaced.C
hist012_TH1_hksimple.C
hist013_TH1_rebin.C
hist014_TH1_cumulative.C
hist015_TH1_read_and_draw.C
hist015_TH1_read_and_draw.py
hist016_TH1_different_scales_canvas.C
hist017_TH1_smooth.C
hist018_TH2_cutg.C
hist019_TH2_projection.C
hist020_TH2_draw.C
hist021_TH2_reverse_axis.C
hist022_TH2_palette.C
hist023_THStack_simple.C
hist024_THStack_pads.C
hist025_THStack_2d_palette_color.C
hist026_THStack_color_scheme.C
hist027_THStack_palette_color.C
hist028_THStack_multicolor.C
hist029_TRatioPlot_simple.C
hist029_TRatioPlot_simple.py
hist030_TRatioPlot_residual.C
hist030_TRatioPlot_residual.py
hist031_TRatioPlot_residual_fit.C
hist031_TRatioPlot_residual_fit.py
hist032_TRatioPlot_fit_lines.C
hist032_TRatioPlot_fit_lines.py
hist033_TRatioPlot_fit_confidence.C
hist033_TRatioPlot_fit_confidence.py
hist034_TRatioPlot_fit_margin.C
hist034_TRatioPlot_fit_margin.py
hist036_TH2_labels.C
hist037_TH2Poly_boxes.C
hist038_TH2Poly_honeycomb.C
hist039_TH2Poly_usa.C
hist040_TH2Poly_europe.C
hist041_TProfile2Poly_realistic.C
hist042_TProfile2Poly_module_error.C
hist043_Graphics_highlight.C
hist044_Graphics_highlight2D.C
hist045_Graphics_highlight_ntuple.C
hist046_Graphics_highlight1D.C
hist047_Graphics_candle_decay.C
hist048_Graphics_candle_hist.C
hist049_Graphics_candle_plot.C
hist050_Graphics_candle_plot_options.C
hist051_Graphics_candle_plot_stack.C
hist052_Graphics_candle_plot_whiskers.C
hist053_Graphics_candle_scaled.C
hist056_TPolyMarker_contour.C
hist057_TExec_th1.C
hist058_TExec_th2.C
hist060_TH1_stats.C
hist061_TH1_timeonaxis.C
hist062_TH1_timeonaxis2.C
hist063_TH1_seism.C
hist101_TH1_autobinning.C
hist102_TH2_contour_list.C
hist103_THnSparse_hist.C
hist104_TH2Poly_fibonacci.C
hist105_TExec_dynamic_slice.C
hist105_TExec_dynamic_slice.py
►
Data analysis tutorials
►
Visualisation tutorials
►
Experimental API tutorials
►
Event generation tutorials
►
Geometry tutorials
►
RooFit packages tutorials
►
HTTP tutorials
►
IO tutorials
►
Math tutorials
Machine Learning tutorials
►
Geometry tutorials
►
Legacy tutorials
demos.C
demos.py
demoshelp.C
demoshelp.py
hsimple.C
hsimple.py
rootlogoff.C
rootlogon.C
►
Python interface
►
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
hist017_TH1_smooth.C File Reference
Tutorials
»
Histograms tutorials
Detailed Description
Histogram smoothing.
int
ipad
= 1;
TCanvas
*
c1
= 0;
void
smooth_hist
(
const
char
*
fname
,
double
xmin
,
double
xmax
,
int
n1
,
int
n2
)
{
std::cout <<
"smoothing a "
<<
fname
<<
" histogram"
<< std::endl;
TH1D
*
h1
=
new
TH1D
(
"h1"
,
"h1"
, 100,
xmin
,
xmax
);
TH1D
*h2 =
new
TH1D
(
"h2"
,
"h2"
, 100,
xmin
,
xmax
);
h1
->
FillRandom
(
fname
,
n1
);
TH1D
*
h1_s
=
new
TH1D
(*
h1
);
h1_s
->SetName(
"h1_s"
);
h1_s
->Smooth();
h2->
FillRandom
(
fname
,
n2
);
double
p1
=
h1
->
Chi2Test
(h2,
""
);
double
p2
=
h1_s
->Chi2Test(h2,
"UU"
);
if
(
p2
<
p1
)
Error
(
"testSmooth"
,
"TH1::Smooth is not working correctly - a worst chi2 is obtained"
);
std::cout <<
" chi2 test non-smoothed histo "
<<
p1
<< std::endl;
std::cout <<
" chi2 test smoothed histo "
<<
p2
<< std::endl;
double
a1
=
h1
->
AndersonDarlingTest
(h2);
double
a2
=
h1_s
->AndersonDarlingTest(h2);
std::cout <<
" AD test non-smoothed histo "
<<
a1
<< std::endl;
std::cout <<
" AD test smoothed histo "
<<
a2
<< std::endl;
double
k1
=
h1
->
KolmogorovTest
(h2);
double
k2
=
h1_s
->KolmogorovTest(h2);
std::cout <<
" KS test non-smoothed histo "
<<
k1
<< std::endl;
std::cout <<
" KS test smoothed histo "
<<
k2
<< std::endl;
c1
->cd(
ipad
++);
h1
->
Draw
(
"E"
);
h1_s
->SetLineColor(
kRed
);
h1_s
->Draw(
"same"
);
h2->
Scale
(
double
(
n1
) /
n2
);
h2->
SetLineColor
(
kGreen
);
h2->
Draw
(
"same"
);
}
void
hist017_TH1_smooth
(
int
n1
= 1000,
int
n2
= 1000000)
{
TH1::AddDirectory
(
false
);
c1
=
new
TCanvas
();
c1
->Divide(1, 3);
smooth_hist
(
"gaus"
, -5, 5,
n1
,
n2
);
smooth_hist
(
"landau"
, -5, 15,
n1
,
n2
);
smooth_hist
(
"expo"
, -5, 0,
n1
,
n2
);
}
kRed
@ kRed
Definition
Rtypes.h:66
kGreen
@ kGreen
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
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition
TError.cxx:185
xmin
float xmin
Definition
THbookFile.cxx:95
xmax
float xmax
Definition
THbookFile.cxx:95
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TAttLine::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition
TAttLine.h:42
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TH1D
1-D histogram with a double per channel (see TH1 documentation)
Definition
TH1.h:695
TH1::FillRandom
virtual void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom *rng=nullptr)
Definition
TH1.cxx:3499
TH1::AddDirectory
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition
TH1.cxx:1263
TH1::Draw
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition
TH1.cxx:3037
TH1::AndersonDarlingTest
virtual Double_t AndersonDarlingTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using the Anderson-Darling ...
Definition
TH1.cxx:8049
TH1::Chi2Test
virtual Double_t Chi2Test(const TH1 *h2, Option_t *option="UU", Double_t *res=nullptr) const
test for comparing weighted and unweighted histograms.
Definition
TH1.cxx:1979
TH1::Scale
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition
TH1.cxx:6602
TH1::KolmogorovTest
virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using Kolmogorov test.
Definition
TH1.cxx:8165
c1
return c1
Definition
legend1.C:41
h1
TH1F * h1
Definition
legend1.C:5
Date
July 2016
Author
Rene Brun
Definition in file
hist017_TH1_smooth.C
.
tutorials
hist
hist017_TH1_smooth.C
ROOT master - Reference Guide Generated on Thu Mar 13 2025 15:07:09 (GVA Time) using Doxygen 1.10.0