ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
hsumTimer.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_hist
3
/// \notebook -js
4
/// Demo of Timers.
5
///
6
/// Simple example illustrating how to use the C++ interpreter
7
/// to fill histograms in a loop and show the graphics results
8
/// This program is a variant of the tutorial "hsum".
9
/// It illustrates the use of Timers.
10
///
11
/// \macro_image
12
/// \macro_code
13
///
14
/// \author Rene Brun
15
16
Float_t
progressRatio = 0.;
17
TSlider
*slider =
nullptr
;
18
TCanvas
*
c1
=
nullptr
;
19
20
void
hsumUpdate()
21
{
22
// called when Timer times out
23
if
(slider) slider->
SetRange
(0., progressRatio);
24
c1
->Modified();
25
c1
->Update();
26
}
27
28
void
hsumTimer(
Int_t
nfill=100000)
29
{
30
c1
=
new
TCanvas
(
"c1"
,
"The HSUM example"
,200,10,600,400);
31
c1
->SetGrid();
32
33
// Create some histograms.
34
auto
total
=
new
TH1F
(
"total"
,
"This is the total distribution"
,100,-4,4);
35
auto
main
=
new
TH1F
(
"main"
,
"Main contributor"
,100,-4,4);
36
auto
s1
=
new
TH1F
(
"s1"
,
"This is the first signal"
,100,-4,4);
37
auto
s2 =
new
TH1F
(
"s2"
,
"This is the second signal"
,100,-4,4);
38
total
->Sumw2();
// store the sum of squares of weights
39
total
->SetMarkerStyle(21);
40
total
->SetMarkerSize(0.7);
41
main
->SetFillColor(16);
42
s1
->SetFillColor(42);
43
s2->SetFillColor(46);
44
total
->SetMaximum(nfill/20.);
45
total
->Draw(
"e1p"
);
46
main
->Draw(
"same"
);
47
s1
->Draw(
"same"
);
48
s2->Draw(
"same"
);
49
c1
->Update();
50
51
slider =
new
TSlider
(
"slider"
,
"test"
,4.2,0,4.6,0.8*
total
->GetMaximum(),38);
52
slider->
SetFillColor
(46);
53
54
// Create a TTimer (hsumUpdate called every 300 msec)
55
TTimer
timer(
"hsumUpdate()"
,300);
56
timer.TurnOn();
57
58
// Fill histograms randomly
59
Float_t
xs1, xs2, xmain;
60
gRandom
->SetSeed();
61
for
(
Int_t
i
=0;
i
<nfill;
i
++) {
62
progressRatio =
i
* 1. / nfill;
63
if
(
gSystem
->ProcessEvents())
break
;
64
xmain =
gRandom
->Gaus(-1,1.5);
65
xs1 =
gRandom
->Gaus(-0.5,0.5);
66
xs2 =
gRandom
->Landau(1,0.15);
67
main
->Fill(xmain);
68
s1
->Fill(xs1,0.3);
69
s2->Fill(xs2,0.2);
70
total
->Fill(xmain);
71
total
->Fill(xs1,0.3);
72
total
->Fill(xs2,0.2);
73
}
74
timer.TurnOff();
75
hsumUpdate();
76
}
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
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
gSystem
R__EXTERN TSystem * gSystem
Definition
TSystem.h:566
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
TTimer
Handles synchronous and a-synchronous timer events.
Definition
TTimer.h:51
c1
return c1
Definition
legend1.C:41
tutorials
hist
hsumTimer.C
ROOT v6-32 - Reference Guide Generated on Sun May 17 2026 02:44:15 (GVA Time) using Doxygen 1.13.2