Logo ROOT   6.12/07
Reference Guide
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;
17 TSlider *slider;
18 TCanvas *c1;
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 
34  // Create some histograms.
35  auto total = new TH1F("total","This is the total distribution",100,-4,4);
36  auto main = new TH1F("main","Main contributor",100,-4,4);
37  auto s1 = new TH1F("s1","This is the first signal",100,-4,4);
38  auto s2 = new TH1F("s2","This is the second signal",100,-4,4);
39  total->Sumw2(); // store the sum of squares of weights
40  total->SetMarkerStyle(21);
41  total->SetMarkerSize(0.7);
42  main->SetFillColor(16);
43  s1->SetFillColor(42);
44  s2->SetFillColor(46);
45  total->SetMaximum(nfill/20.);
46  total->Draw("e1p");
47  main->Draw("same");
48  s1->Draw("same");
49  s2->Draw("same");
50  c1->Update();slider = new TSlider("slider",
51  "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 = Float_t(i)/Float_t(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 }
77 
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:424
float Float_t
Definition: RtypesCore.h:53
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:256
return c1
Definition: legend1.C:41
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:285
virtual void SetRange(Double_t xmin=0, Double_t xmax=1)
Set Slider range in [0,1].
Definition: TSlider.cxx:204
int Int_t
Definition: RtypesCore.h:41
A specialized TPad including a TSliderBox object.
Definition: TSlider.h:18
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:589
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:327
int main(int argc, char **argv)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
static unsigned int total
The Canvas class.
Definition: TCanvas.h:31
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2248
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:361
void Modified(Bool_t flag=1)
Definition: TPad.h:414