hsumTimer.C

Go to the documentation of this file.
00001 // demo of Timers
00002 Int_t i;
00003 Float_t ratio;
00004 TSlider *slider;
00005 TCanvas *c1;
00006 
00007 void hsumTimer(Int_t nfill=100000)
00008 {
00009 //
00010 // Simple example illustrating how to use the C++ interpreter   
00011 // to fill histograms in a loop and show the graphics results
00012 // This program is a variant of the tutorial "hsum".
00013 // It illustrates the use of Timers.
00014 //Author: Rene Brun
00015    
00016   c1 = new TCanvas("c1","The HSUM example",200,10,600,400);
00017   c1->SetGrid();
00018 
00019 
00020 // Create some histograms.
00021   total  = new TH1F("total","This is the total distribution",100,-4,4);
00022   main   = new TH1F("main","Main contributor",100,-4,4);
00023   s1     = new TH1F("s1","This is the first signal",100,-4,4);
00024   s2     = new TH1F("s2","This is the second signal",100,-4,4);
00025   total->Sumw2();   // store the sum of squares of weights
00026   total->SetMarkerStyle(21);
00027   total->SetMarkerSize(0.7);
00028   main->SetFillColor(16);
00029   s1->SetFillColor(42);
00030   s2->SetFillColor(46);
00031   total->SetMaximum(nfill/20.);
00032   total->Draw("e1p");
00033   main->Draw("same");
00034   s1->Draw("same");
00035   s2->Draw("same");
00036   c1->Update();slider = new TSlider("slider",
00037      "test",4.2,0,4.6,0.8*total->GetMaximum(),38);
00038   slider->SetFillColor(46);
00039 
00040 // Create a TTimer (hsumUpdate called every 300 msec)
00041   TTimer timer("hsumUpdate()",300); 
00042   timer.TurnOn();
00043 
00044  // Fill histograms randomly
00045   Float_t xs1, xs2, xmain;
00046   gRandom->SetSeed();
00047   for (Int_t i=0; i<nfill; i++) {
00048      ratio = Float_t(i)/Float_t(nfill);
00049      if (gSystem->ProcessEvents()) break;
00050      xmain = gRandom->Gaus(-1,1.5);
00051      xs1   = gRandom->Gaus(-0.5,0.5);
00052      xs2   = gRandom->Landau(1,0.15);
00053      main->Fill(xmain);
00054      s1->Fill(xs1,0.3);
00055      s2->Fill(xs2,0.2);
00056      total->Fill(xmain);
00057      total->Fill(xs1,0.3);
00058      total->Fill(xs2,0.2);
00059   }
00060   timer.TurnOff();
00061   hsumUpdate();
00062 }
00063 
00064 void hsumUpdate()
00065 {
00066 // called when Timer times out
00067    if (slider) slider->SetRange(0,ratio);
00068    c1->Modified();
00069    c1->Update();
00070 }

Generated on Tue Jul 5 15:44:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1