ROOT
master
Reference Guide
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
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TH1D
1-D histogram with a double per channel (see TH1 documentation)
Definition
TH1.h:693
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:8064
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::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:8180
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 Feb 13 2025 15:59:31 (GVA Time) using Doxygen 1.10.0