// (x, y) 坐标所在的 bin 计数加 1。
Int_t Fill (Double_t x, Double_t y);
%jsroot on
TCanvas *c1 = new TCanvas;
// 创建二维直方图
TH2I *h1 = new TH2I("h1",
"",//title
100,0.0,10.0,// x 轴 bin,min,max
100,0.0,10.0 // y 轴 bin,min,max
);
// 填充数据
for (int i=0; i<500000; i++)
h1->Fill(gRandom->Gaus(4,2), gRandom->Gaus(6,2));
//
h1->GetXaxis()->SetTitle("xxx");
h1->GetYaxis()->SetTitle("yyy");
h1->Draw("colz");
c1->Draw();
// 创建二维直方图
TH2I *h2 = new TH2I("h2", "", 100,0.0,10.0, 100,0.0,10.0 );
// 填充数据
// void SetBinContent(Int_t bin, Int_t, Double_t content) x bin, y bin, counter
for (int i=1; i<=100; i++)
for (int j=1; j<=100; j++)
h2->SetBinContent(i, j, i*i+j*j);
//
h2->GetXaxis()->SetTitle("xxx");
h2->GetYaxis()->SetTitle("yyy");
h2->Draw("colz");
c1->Draw();
// TH1D* ProjectionX(const char* name = "_px", Int_t firstybin = 0, Int_t lastybin = -1, Option_t* option = "")
TH1D *hp1 = (TH1D*)h1->ProjectionX("hp1");// 往 x 轴投影
hp1->Draw();
c1->Draw();
TH1D *hp2 = (TH1D*)h1->ProjectionX("hp2", 25,30);// y轴25-30 bin 往 x 轴投影
hp2->Draw();
c1->Draw();
TH2I *hh = new TH2I("hh","",100,0,10,100,0,10);
hh->Draw("colz");
c1->Draw();
//gSystem->ProcessEvents();
for(int i =0; i < 100000; i++)
{
hh->Fill(gRandom->Gaus(4,2), gRandom->Gaus(6,2));
if(i%1000==0)
{
c1->Modified();
c1->Update();
// c1->Draw();
}
}