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