hksimple.C

Go to the documentation of this file.
00001 // Illustrates the advantages of a TH1K histogram
00002 //Author: Victor Perevovchikov
00003 void padRefresh(TPad *pad,int flag=0);
00004 void hksimple()
00005 {
00006 // Create a new canvas.
00007   c1 = new TCanvas("c1","Dynamic Filling Example",200,10,600,900);
00008   c1->SetFillColor(42);
00009 
00010 // Create a normal histogram and two TH1K histograms
00011   TH1 *hpx[3];
00012   hpx[0]    = new TH1F("hp0","Normal histogram",1000,-4,4);
00013   hpx[1]    = new TH1K("hk1","Nearest Neighbor of order 3",1000,-4,4);
00014   hpx[2]    = new TH1K("hk2","Nearest Neighbor of order 16",1000,-4,4,16);
00015   c1->Divide(1,3);
00016   Int_t j;
00017   for (j=0;j<3;j++) {
00018      c1->cd(j+1); 
00019      gPad->SetFrameFillColor(33);
00020      hpx[j]->SetFillColor(48);
00021      hpx[j]->Draw();
00022   }
00023 
00024 // Fill histograms randomly
00025   gRandom->SetSeed();
00026   Float_t px, py, pz;
00027   const Int_t kUPDATE = 10;
00028   for (Int_t i = 0; i <= 300; i++) {
00029      gRandom->Rannor(px,py);
00030      for (j=0;j<3;j++) {hpx[j]->Fill(px);}
00031      if (i && (i%kUPDATE) == 0) {
00032            padRefresh(c1);
00033      }
00034   }
00035 
00036   for (j=0;j<3;j++) hpx[j]->Fit("gaus");
00037   padRefresh(c1);
00038 }
00039 void padRefresh(TPad *pad,int flag)
00040 {
00041   if (!pad) return;
00042   pad->Modified();
00043   pad->Update();
00044   TList *tl = pad->GetListOfPrimitives();
00045   if (!tl) return;
00046   TListIter next(tl);
00047   TObject *to;
00048   while ((to=next())) {
00049     if (to->InheritsFrom(TPad::Class())) padRefresh((TPad*)to,1);}
00050   if (flag) return;
00051   gSystem->ProcessEvents();
00052 }

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