ROOT logo
// Illustrates the advantages of a TH1K histogram
//Author: Victor Perevovchikov
void padRefresh(TPad *pad,int flag=0);
void hksimple()
{
// Create a new canvas.
  c1 = new TCanvas("c1","Dynamic Filling Example",200,10,600,900);
  c1->SetFillColor(42);

// Create a normal histogram and two TH1K histograms
  TH1 *hpx[3];
  hpx[0]    = new TH1F("hp0","Normal histogram",1000,-4,4);
  hpx[1]    = new TH1K("hk1","Nearest Neighbor of order 3",1000,-4,4);
  hpx[2]    = new TH1K("hk2","Nearest Neighbor of order 16",1000,-4,4,16);
  c1->Divide(1,3);
  Int_t j;
  for (j=0;j<3;j++) {
     c1->cd(j+1); 
     gPad->SetFrameFillColor(33);
     hpx[j]->SetFillColor(48);
     hpx[j]->Draw();
  }

// Fill histograms randomly
  gRandom->SetSeed();
  Float_t px, py, pz;
  const Int_t kUPDATE = 10;
  for (Int_t i = 0; i <= 300; i++) {
     gRandom->Rannor(px,py);
     for (j=0;j<3;j++) {hpx[j]->Fill(px);}
     if (i && (i%kUPDATE) == 0) {
           padRefresh(c1);
     }
  }

  for (j=0;j<3;j++) hpx[j]->Fit("gaus");
  padRefresh(c1);
}
void padRefresh(TPad *pad,int flag)
{
  if (!pad) return;
  pad->Modified();
  pad->Update();
  TList *tl = pad->GetListOfPrimitives();
  if (!tl) return;
  TListIter next(tl);
  TObject *to;
  while ((to=next())) {
    if (to->InheritsFrom(TPad::Class())) padRefresh((TPad*)to,1);}
  if (flag) return;
  gSystem->ProcessEvents();
}
 hksimple.C:1
 hksimple.C:2
 hksimple.C:3
 hksimple.C:4
 hksimple.C:5
 hksimple.C:6
 hksimple.C:7
 hksimple.C:8
 hksimple.C:9
 hksimple.C:10
 hksimple.C:11
 hksimple.C:12
 hksimple.C:13
 hksimple.C:14
 hksimple.C:15
 hksimple.C:16
 hksimple.C:17
 hksimple.C:18
 hksimple.C:19
 hksimple.C:20
 hksimple.C:21
 hksimple.C:22
 hksimple.C:23
 hksimple.C:24
 hksimple.C:25
 hksimple.C:26
 hksimple.C:27
 hksimple.C:28
 hksimple.C:29
 hksimple.C:30
 hksimple.C:31
 hksimple.C:32
 hksimple.C:33
 hksimple.C:34
 hksimple.C:35
 hksimple.C:36
 hksimple.C:37
 hksimple.C:38
 hksimple.C:39
 hksimple.C:40
 hksimple.C:41
 hksimple.C:42
 hksimple.C:43
 hksimple.C:44
 hksimple.C:45
 hksimple.C:46
 hksimple.C:47
 hksimple.C:48
 hksimple.C:49
 hksimple.C:50
 hksimple.C:51
 hksimple.C:52
 hksimple.C:53
thumb