Illustrates the advantages of a TH1K histogram
Author: Victor Perevovchikov
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, April 17, 2024 at 11:12 AM.
Definition of a helper function:
%%cpp -d
void canvasRefresh(TCanvas *c1)
{
for (Int_t j = 0; j < 3; j++)
c1->GetPad(j+1)->Modified();
c1->Modified();
c1->Update();
gSystem->ProcessEvents();
}
Create a new canvas.
TCanvas* c1 = new TCanvas("c1","Dynamic Filling Example",200,10,600,900);
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 Neighbour of order 3",1000,-4,4);
hpx[2] = new TH1K("hk2","Nearest Neighbour of order 16",1000,-4,4,16);
c1->Divide(1,3);
for (Int_t j = 0; j < 3; j++) {
c1->cd(j + 1);
hpx[j]->SetFillColor(48);
hpx[j]->Draw();
}
Fill histograms randomly
gRandom->SetSeed(12345);
Float_t px, py, pz;
const Int_t kUPDATE = 10;
for (Int_t i = 0; i <= 300; i++) {
gRandom->Rannor(px,py);
for (Int_t j = 0; j < 3; j++)
hpx[j]->Fill(px);
if (i && (i % kUPDATE) == 0)
canvasRefresh(c1);
}
for (Int_t j = 0; j < 3; j++)
hpx[j]->Fit("gaus");
canvasRefresh(c1);
**************************************** Minimizer is Minuit2 / Migrad Chi2 = 40.1833 NDf = 218 Edm = 7.43186e-07 NCalls = 139 Constant = 1.23915 +/- 0.0997879 Mean = 0.0188848 +/- 0.628615 Sigma = 3.15709 +/- 1.58217 (limited) **************************************** Minimizer is Minuit2 / Migrad Chi2 = 611.108 NDf = 997 Edm = 7.53389e-08 NCalls = 125 Constant = 0.430426 +/- 0.0266128 Mean = -0.211539 +/- 0.0155663 Sigma = 1.1755 +/- 0.0175562 (limited) **************************************** Minimizer is Minuit2 / Migrad Chi2 = 2585.5 NDf = 997 Edm = 4.06374e-08 NCalls = 100 Constant = 0.542117 +/- 0.0125602 Mean = -0.0437936 +/- 0.00686771 Sigma = 1.32702 +/- 0.00996912 (limited)
Draw all canvases
gROOT->GetListOfCanvases()->Draw()