ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
hsum.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_hist
3
/// \notebook -js
4
/// Histograms filled and drawn in a loop.
5
/// Simple example illustrating how to use the C++ interpreter
6
/// to fill histograms in a loop and show the graphics results
7
///
8
/// \macro_image
9
/// \macro_code
10
///
11
/// \author Rene Brun
12
13
void
hsum
()
14
{
15
TCanvas
*
c1
=
new
TCanvas
(
"c1"
,
"The HSUM example"
,200,10,600,400);
16
c1
->SetGrid();
17
18
gBenchmark
->Start(
"hsum"
);
19
20
// Create some histograms.
21
auto
total
=
new
TH1F
(
"total"
,
"This is the total distribution"
,100,-4,4);
22
auto
main
=
new
TH1F
(
"main"
,
"Main contributor"
,100,-4,4);
23
auto
s1
=
new
TH1F
(
"s1"
,
"This is the first signal"
,100,-4,4);
24
auto
s2 =
new
TH1F
(
"s2"
,
"This is the second signal"
,100,-4,4);
25
total
->Sumw2();
// store the sum of squares of weights
26
total
->SetMarkerStyle(21);
27
total
->SetMarkerSize(0.7);
28
main
->SetFillColor(16);
29
s1
->SetFillColor(42);
30
s2->SetFillColor(46);
31
TSlider
*slider =
nullptr
;
32
33
// Fill histograms randomly
34
gRandom
->SetSeed();
35
const
Int_t
kUPDATE
= 500;
36
Float_t
xs1, xs2, xmain;
37
for
(
Int_t
i
=0;
i
<10000;
i
++) {
38
xmain =
gRandom
->Gaus(-1,1.5);
39
xs1 =
gRandom
->Gaus(-0.5,0.5);
40
xs2 =
gRandom
->Landau(1,0.15);
41
main
->Fill(xmain);
42
s1
->Fill(xs1,0.3);
43
s2->Fill(xs2,0.2);
44
total
->Fill(xmain);
45
total
->Fill(xs1,0.3);
46
total
->Fill(xs2,0.2);
47
if
(
i
&& (
i
%
kUPDATE
) == 0) {
48
if
(
i
==
kUPDATE
) {
49
total
->Draw(
"e1p"
);
50
main
->Draw(
"same"
);
51
s1
->Draw(
"same"
);
52
s2->Draw(
"same"
);
53
c1
->Update();
54
slider =
new
TSlider
(
"slider"
,
55
"test"
,4.2,0,4.6,
total
->GetMaximum(),38);
56
slider->
SetFillColor
(46);
57
}
58
if
(slider) slider->
SetRange
(0., 1.*
i
/10000.);
59
c1
->Modified();
60
c1
->Update();
61
}
62
}
63
slider->
SetRange
(0., 1.);
64
c1
->Modified();
65
gBenchmark
->Show(
"hsum"
);
66
}
s1
#define s1(x)
Definition
RSha256.hxx:91
Int_t
int Int_t
Definition
RtypesCore.h:45
Float_t
float Float_t
Definition
RtypesCore.h:57
gBenchmark
R__EXTERN TBenchmark * gBenchmark
Definition
TBenchmark.h:59
kUPDATE
@ kUPDATE
Definition
TFitParametersDialog.cxx:46
total
static unsigned int total
Definition
TGWin32ProxyDefs.h:40
i
Int_t i
Definition
TGraphAsymmErrors.cxx:1306
gRandom
R__EXTERN TRandom * gRandom
Definition
TRandom.h:62
main
int main(int argc, char *argv[])
Definition
cef_main.cxx:54
TAttFill::SetFillColor
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition
TAttFill.h:37
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:621
TSlider
A specialized TPad including a TSliderBox object.
Definition
TSlider.h:17
TSlider::SetRange
virtual void SetRange(Double_t xmin=0, Double_t xmax=1)
Set Slider range in [0,1].
Definition
TSlider.cxx:183
c1
return c1
Definition
legend1.C:41
hsum
Definition
hsum.py:1
tutorials
hist
hsum.C
ROOT v6-32 - Reference Guide Generated on Sun May 17 2026 02:44:15 (GVA Time) using Doxygen 1.13.2