ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
hsumanim.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_image
3 /// This script is a slightly modified version of hsum.C.
4 /// When run in batch mode, it produces an animated gif file.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \authors Rene Brun, Valeriy Onuchin
10 
11 void hsumanim() {
12  c1 = new TCanvas("c1","The HSUM example",200,10,600,400);
13  c1->SetGrid();
14 
15  gBenchmark->Start("hsum");
16 
17 // Create some histograms.
18  total = new TH1F("total","This is the total distribution",100,-4,4);
19  main = new TH1F("main","Main contributor",100,-4,4);
20  s1 = new TH1F("s1","This is the first signal",100,-4,4);
21  s2 = new TH1F("s2","This is the second signal",100,-4,4);
22  total->Sumw2(); // this makes sure that the sum of squares of weights will be stored
23  total->SetMarkerStyle(21);
24  total->SetMarkerSize(0.7);
25  main->SetFillColor(16);
26  s1->SetFillColor(42);
27  s2->SetFillColor(46);
28  TSlider *slider = 0;
29  gSystem->Unlink("hsumanim.gif"); // delete old file
30 
31 // Fill histograms randomly
32  gRandom->SetSeed();
33  const Int_t kUPDATE = 500;
34  Float_t xs1, xs2, xmain;
35  Int_t gifcnt = 0;
36  for ( Int_t i=0; i<10000; i++) {
37  xmain = gRandom->Gaus(-1,1.5);
38  xs1 = gRandom->Gaus(-0.5,0.5);
39  xs2 = gRandom->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) slider->SetRange(0,Float_t(i)/10000.);
57  c1->Modified();
58  c1->Update();
59  if (gROOT->IsBatch()) {
60  c1->Print("hsumanim.gif+");
61  printf("i = %d\n", i);
62  }
63  }
64  }
65  slider->SetRange(0,1);
66  total->Draw("sameaxis"); // to redraw axis hidden by the fill area
67  c1->Modified();
68  // make infinite animation by adding "++" to the file name
69  if (gROOT->IsBatch()) c1->Print("hsumanim.gif++");
70 
71  //You can view the animated file hsumanim.gif with Netscape/IE or mozilla
72 
73  gBenchmark->Show("hsum");
74 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
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:235
TCanvas * c1
Definition: legend1.C:2
virtual void SetRange(Double_t xmin=0, Double_t xmax=1)
Set Slider range in [0,1].
Definition: TSlider.cxx:204
#define gROOT
Definition: TROOT.h:344
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:155
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
int Int_t
Definition: RtypesCore.h:41
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
virtual void Print(const char *filename="") const
Save Pad contents in a file in one of various formats.
Definition: TPad.cxx:4134
virtual void SetSeed(UInt_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
tuple xs2
Definition: hsum.py:47
A specialized TPad including a TSliderBox object.
Definition: TSlider.h:31
TSocket * s1
Definition: hserv2.C:36
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Definition: TSystem.cxx:1294
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:172
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:326
tuple xmain
Definition: hsum.py:45
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
tuple main
Definition: hsum.py:20
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:63
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
TH1F * total
Definition: threadsh2.C:15
The Canvas class.
Definition: TCanvas.h:48
TH1F * s2
Definition: threadsh2.C:15
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8350
tuple xs1
Definition: hsum.py:46
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:7921
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:340
void Modified(Bool_t flag=1)
Definition: TPad.h:407