#include // histograms filled and drawn in a loop void krogint() { TCanvas *c1 = new TCanvas("c1","Primer MC integracije",200,10,600,600); c1->SetGrid(); // Create some histograms. main = new TF1("krog","sqrt(1.-x*x)",0.,1.); main->SetFillColor(41); //random TRandom *rand = new TRandom2(); // Fill histograms randomly rand->SetSeed(4434333); const Int_t niter=1000000; gr = new TGraph(niter); gr2 = new TGraph(niter); Double_t xsum=0.; Double_t xtot=0.; Double_t x=0.; Double_t y=0.; for ( Int_t i=0; iRndm(); Double_t r2 = rand->Rndm(); x=r1; y=r2; //std::cout << x << ' ' << y << std::endl; if ( x*x+y*y <= 1.0000) { gr->SetPoint(i,x,y); xsum++; } else{ gr2->SetPoint(i,x,y); } xtot++; //main->Fill(xmain); } main->Draw(); //point overlay //gr = new TGraph(niter,xa,ya); gr->SetLineColor(1); gr->SetLineWidth(1); gr->SetMarkerColor(4); gr->SetMarkerStyle(21); gr->Draw("P"); gr2->SetLineColor(1); gr2->SetLineWidth(1); gr2->SetMarkerColor(2); gr2->SetMarkerStyle(21); gr2->Draw("P"); Double_t xres=xsum/xtot*4.; Double_t pi=TMath::Pi(); std::cout << "rezultat=" << xres << " rel=" << 1-xres/pi << " pi=" << pi << std::endl; c1->Update(); c1->Modified(); }