Logo ROOT  
Reference Guide
 
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/// When run in batch mode, it produces an animated gif file.
6///
7/// \macro_image
8/// \macro_code
9///
10/// \authors Rene Brun, Valeriy Onuchin
11
12void hsumanim() {
13 auto c1 = new TCanvas("c1","The HSUM example",200,10,600,400);
14 c1->SetGrid();
15
16 gBenchmark->Start("hsum");
17
18 // Create some histograms.
19 auto total = new TH1F("total","This is the total distribution",100,-4,4);
20 auto main = new TH1F("main","Main contributor",100,-4,4);
21 auto s1 = new TH1F("s1","This is the first signal",100,-4,4);
22 auto s2 = new TH1F("s2","This is the second signal",100,-4,4);
23 total->Sumw2(); // this makes sure that the sum of squares of weights will be stored
24 total->SetMarkerStyle(21);
25 total->SetMarkerSize(0.7);
26 main->SetFillColor(16);
27 s1->SetFillColor(42);
28 s2->SetFillColor(46);
29 TSlider *slider = 0;
30 gSystem->Unlink("hsumanim.gif"); // delete old file
31
32 // Fill histograms randomly
34 const Int_t kUPDATE = 500;
35 Float_t xs1, xs2, xmain;
36 Int_t gifcnt = 0;
37 for ( Int_t i=0; i<10000; i++) {
38 xmain = gRandom->Gaus(-1,1.5);
39 xs1 = gRandom->Gaus(-0.5,0.5);
40 xs2 = gRandom->Landau(1,0.15);
41 main->Fill(xmain);
42 s1->Fill(xs1,0.3);
43 s2->Fill(xs2,0.2);
44 total->Fill(xmain);
45 total->Fill(xs1,0.3);
46 total->Fill(xs2,0.2);
47 if (i && (i%kUPDATE) == 0) {
48 if (i == kUPDATE) {
49 total->Draw("e1p");
50 main->Draw("same");
51 s1->Draw("same");
52 s2->Draw("same");
53 c1->Update();
54 slider = new TSlider("slider","test",4.2,0,4.6,total->GetMaximum(),38);
55 slider->SetFillColor(46);
56 }
57 if (slider) slider->SetRange(0,Float_t(i)/10000.);
58 c1->Modified();
59 c1->Update();
60 if (gROOT->IsBatch()) {
61 c1->Print("hsumanim.gif+");
62 printf("i = %d\n", i);
63 } else {
65 break;
66 }
67 }
68 }
69 slider->SetRange(0,1);
70 total->Draw("sameaxis"); // to redraw axis hidden by the fill area
71 c1->Modified();
72 // make infinite animation by adding "++" to the file name
73 if (gROOT->IsBatch()) c1->Print("hsumanim.gif++");
74
75 //You can view the animated file hsumanim.gif with Netscape/IE or mozilla
76
77 gBenchmark->Show("hsum");
78}
#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
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:559
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
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:575
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
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandom.cxx:608
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
A specialized TPad including a TSliderBox object.
Definition TSlider.h:17
virtual void SetRange(Double_t xmin=0, Double_t xmax=1)
Set Slider range in [0,1].
Definition TSlider.cxx:207
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:417
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1379
int main()
return c1
Definition legend1.C:41