Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
hsumanim.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_image
3/// \notebook
4/// This script is a slightly modified version of hsum.C.
5///
6/// Uncomment the two `c1->Print(...);` lines in order to produce
7/// an animated gif file. The option "++" makes an infinite animation.
8/// The animated file `hsumanim.gif` can be visualized within a web browser
9///
10/// \macro_image
11/// \macro_code
12///
13/// \authors Rene Brun, Valeriy Onuchin
14
15void hsumanim()
16{
17 auto c1 = new TCanvas("c1", "The HSUM example", 200, 10, 600, 400);
18 c1->SetGrid();
19
20 gBenchmark->Start("hsum");
21
22 // Create some histograms.
23 auto total = new TH1F("total", "This is the total distribution", 100, -4, 4);
24 auto main = new TH1F("main", "Main contributor", 100, -4, 4);
25 auto s1 = new TH1F("s1", "This is the first signal", 100, -4, 4);
26 auto s2 = new TH1F("s2", "This is the second signal", 100, -4, 4);
27 total->Sumw2(); // this makes sure that the sum of squares of weights will be stored
28 total->SetMarkerStyle(21);
29 total->SetMarkerSize(0.7);
30 main->SetFillColor(16);
31 s1->SetFillColor(42);
32 s2->SetFillColor(46);
33 TSlider *slider = 0;
34 gSystem->Unlink("hsumanim.gif"); // delete old file
35
36 // Fill histograms randomly
38 const Int_t kUPDATE = 500;
40 Int_t gifcnt = 0;
41 for (Int_t i = 0; i < 10000; i++) {
42 xmain = gRandom->Gaus(-1, 1.5);
43 xs1 = gRandom->Gaus(-0.5, 0.5);
44 xs2 = gRandom->Landau(1, 0.15);
45 main->Fill(xmain);
46 s1->Fill(xs1, 0.3);
47 s2->Fill(xs2, 0.2);
48 total->Fill(xmain);
49 total->Fill(xs1, 0.3);
50 total->Fill(xs2, 0.2);
51 if (i && (i % kUPDATE) == 0) {
52 if (i == kUPDATE) {
53 total->Draw("e1p");
54 main->Draw("same");
55 s1->Draw("same");
56 s2->Draw("same");
57 c1->Update();
58 slider = new TSlider("slider", "test", 4.2, 0, 4.6, total->GetMaximum(), 38);
59 slider->SetFillColor(46);
60 }
61 if (slider)
62 slider->SetRange(0, Float_t(i) / 10000.);
63 c1->Modified();
64 c1->Update();
65 if (gROOT->IsBatch()) {
66 // c1->Print("hsumanim.gif+");
67 printf("i = %d\n", i);
68 } else {
70 break;
71 }
72 }
73 }
74 slider->SetRange(0, 1);
75 total->Draw("sameaxis"); // to redraw axis hidden by the fill area
76 c1->Modified();
77 // c1->Print("hsumanim.gif++")
78
79 gBenchmark->Show("hsum");
80}
int main()
Definition Prototype.cxx:12
#define s1(x)
Definition RSha256.hxx:91
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
R__EXTERN TBenchmark * gBenchmark
Definition TBenchmark.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static unsigned int total
#define gROOT
Definition TROOT.h:406
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
virtual void Start(const char *name)
Starts Benchmark with the specified name.
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:650
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:275
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandom.cxx:615
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:381
A specialized TPad including a TSliderBox object.
Definition TSlider.h:17
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:416
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1392
return c1
Definition legend1.C:41