ROOT
remotes/pull/22321/merge
Reference Guide
Loading...
Searching...
No Matches
hist007_TH1_liveupdate.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_hist
3
/// \notebook -js
4
/// \preview 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
/// \date November 2024
12
/// \author Rene Brun
13
14
void
hist007_TH1_liveupdate()
15
{
16
TCanvas
*
c1
=
new
TCanvas
(
"c1"
,
"Live update of histograms"
, 200, 10, 600, 400);
17
c1
->SetGrid();
18
19
// Create some histograms.
20
auto
*
total
=
new
TH1D
(
"total"
,
"This is the total distribution"
, 100, -4, 4);
21
auto
*
main
=
new
TH1D
(
"main"
,
"Main contributor"
, 100, -4, 4);
22
auto
*
s1
=
new
TH1D
(
"s1"
,
"This is the first signal"
, 100, -4, 4);
23
auto
*s2 =
new
TH1D
(
"s2"
,
"This is the second signal"
, 100, -4, 4);
24
total
->Sumw2();
// store the sum of squares of weights
25
// set some style properties
26
total
->SetMarkerStyle(21);
// shape of the markers (\see EMarkerStyle)
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
TRandom3
rng;
35
const
int
kUPDATE
= 500;
36
for
(
int
i = 0; i < 10000; i++) {
37
float
xmain = rng.
Gaus
(-1, 1.5);
38
float
xs1 = rng.
Gaus
(-0.5, 0.5);
39
float
xs2 = rng.
Landau
(1, 0.15);
40
main
->Fill(xmain);
41
s1
->Fill(xs1, 0.3);
42
s2->Fill(xs2, 0.2);
43
total
->Fill(xmain);
44
total
->Fill(xs1, 0.3);
45
total
->Fill(xs2, 0.2);
46
if
(i && (i %
kUPDATE
) == 0) {
47
if
(i ==
kUPDATE
) {
48
total
->Draw(
"e1p"
);
49
main
->Draw(
"same"
);
50
s1
->Draw(
"same"
);
51
s2->Draw(
"same"
);
52
c1
->Update();
53
slider =
new
TSlider
(
"slider"
,
"test"
, 4.2, 0, 4.6,
total
->GetMaximum(), 38);
54
slider->
SetFillColor
(46);
55
}
56
if
(slider)
57
slider->
SetRange
(0., 1. * i / 10000.);
58
c1
->Modified();
59
c1
->Update();
60
}
61
}
62
slider->
SetRange
(0., 1.);
63
c1
->Modified();
64
}
s1
#define s1(x)
Definition
RSha256.hxx:91
kUPDATE
@ kUPDATE
Definition
TFitParametersDialog.cxx:46
total
static unsigned int total
Definition
TGWin32ProxyDefs.h:40
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
TH1D
1-D histogram with a double per channel (see TH1 documentation)
Definition
TH1.h:926
TRandom3
Random number generator class based on M.
Definition
TRandom3.h:27
TRandom::Gaus
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition
TRandom.cxx:274
TRandom::Landau
virtual Double_t Landau(Double_t mean=0, Double_t sigma=1)
Generate a random number following a Landau distribution with location parameter mu and scale paramet...
Definition
TRandom.cxx:380
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
c1
return c1
Definition
legend1.C:41
hist007_TH1_liveupdate
Definition
hist007_TH1_liveupdate.py:1
tutorials
hist
hist007_TH1_liveupdate.C
ROOTremotes/pull/22321/merge - Reference Guide Generated on Thu Jun 25 2026 10:46:09 (GVA Time) using Doxygen 1.13.2