diff --git a/Lectures_my/EMPP/2016/Lecture4/Exercises/Error_propagation/result.png b/Lectures_my/EMPP/2016/Lecture4/Exercises/Error_propagation/result.png index 86e4ebe..60424fa 100644 --- a/Lectures_my/EMPP/2016/Lecture4/Exercises/Error_propagation/result.png +++ b/Lectures_my/EMPP/2016/Lecture4/Exercises/Error_propagation/result.png Binary files differ diff --git a/Lectures_my/EMPP/2016/Lecture4/Exercises/Integration_FOAM/foam_kanwa.C b/Lectures_my/EMPP/2016/Lecture4/Exercises/Integration_FOAM/foam_kanwa.C index 138b29d..d6f9611 100755 --- a/Lectures_my/EMPP/2016/Lecture4/Exercises/Integration_FOAM/foam_kanwa.C +++ b/Lectures_my/EMPP/2016/Lecture4/Exercises/Integration_FOAM/foam_kanwa.C @@ -1,167 +1,73 @@ -Double_t sqr(Double_t x){return x*x;} +// This program can be execute from the command line as folows: +// +// root -l foam_kanwa.C +//_____________________________________________________________________________ + +#include "Riostream.h" +#include "TFoam.h" +#include "TCanvas.h" +#include "TH2.h" +#include "TMath.h" +#include "TFoamIntegrand.h" +#include "TRandom3.h" + +//_____________________________________________________________________________ +Double_t sqr(Double_t x){return x*x;}; +//_____________________________________________________________________________ Double_t Camel2(Int_t nDim, Double_t *Xarg){ - // 2-dimensional distribution for FOAM, normalized to one (within 1e-5) +// 2-dimensional distribution for Foam, normalized to one (within 1e-5) Double_t x=Xarg[0]; Double_t y=Xarg[1]; Double_t GamSq= sqr(0.100e0); - Double_t Dist=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi(); - Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi(); + Double_t Dist= 0; + Dist +=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi(); + Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi(); return 0.5*Dist; }// Camel2 -Int_t kanwa(){ - // TH2D *hst_xy = new TH2D("hst_xy" , "x-y plot", 50,0,1.0, 50,0,1.0); +//_____________________________________________________________________________ + +Int_t foam_kanwa(){ + cout<<"--- kanwa started ---"<SetSeed(4357); // Set seed + // + TRandom *PseRan = new TRandom3(); // Create random number generator + PseRan->SetSeed(4357); TFoam *FoamX = new TFoam("FoamX"); // Create Simulator - FoamX->SetkDim(2); // No. of dimensions, obligatory! - FoamX->SetnCells(500); // No. of cells, can be omitted, default=2000 - FoamX->SetRhoInt(Camel2); // Set 2-dim distribution, included below - FoamX->SetPseRan(PseRan); // Set random number generator - FoamX->Initialize(); // Initialize simulator, takes a few seconds... - // From now on FoamX is ready to generate events according to Camel2(x,y) - for(Long_t loop=0; loop<100000; loop++){ - FoamX->MakeEvent(); // generate MC event - FoamX->GetMCvect( MCvect); // get generated vector (x,y) + FoamX->SetkDim(2); // No. of dimensions, obligatory! + FoamX->SetnCells(500); // Optionally No. of cells, default=2000 + FoamX->SetRhoInt(Camel2); // Set 2-dim distribution, included below + FoamX->SetPseRan(PseRan); // Set random number generator + FoamX->Initialize(); // Initialize simulator, may take time... + // + // visualising generated distribution + TCanvas *cKanwa = new TCanvas("cKanwa","Canvas for plotting",600,600); + cKanwa->cd(); + // From now on FoamX is ready to generate events + int nshow=5000; + for(long loop=0; loop<100000; loop++){ + FoamX->MakeEvent(); // generate MC event + FoamX->GetMCvect( MCvect); // get generated vector (x,y) Double_t x=MCvect[0]; Double_t y=MCvect[1]; if(loop<10) cout<<"(x,y) = ( "<< x <<", "<< y <<" )"<Fill(x,y); // fill scattergram + hst_xy->Fill(x,y); + // live plot + if(loop == nshow){ + nshow += 5000; + hst_xy->Draw("lego2"); + cKanwa->Update(); + } }// loop - Double_t mcResult, mcError; - FoamX->GetIntegMC( mcResult, mcError); // get MC integral, should be one - cout << " mcResult= " << mcResult << " +- " << mcError <cd(); - // hst_xy->Draw("lego2"); - return 1; + // + hst_xy->Draw("lego2"); // final plot + cKanwa->Update(); + // + Double_t MCresult, MCerror; + FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one + cout << " MCresult= " << MCresult << " +- " << MCerror <SetkDim(1); // No. of dimensions, obligatory! - FoamX->SetRhoInt(phi); // Set 1-dim distribution, included below - FoamX->SetPseRan(PseRan); // Set random number generator - FoamX->Initialize(); // Initialize simulator, takes a few seconds... - - for(Long_t loop=0; loop<100000; loop++){ - FoamX->MakeEvent(); // generate MC event - //FoamX->GetMCvect( MCvect); // get generated vector (x,y) - //Double_t x=MCvect[0]; - //Double_t y=MCvect[1]; - //if(loop<10) cout<<"(x,y) = ( "<< x <<", "<< y <<" )"<Fill(x,y); // fill scattergram - } - Double_t mcResult, mcError; - FoamX->GetIntegMC(mcResult,mcError); // get MC integral, should be one - cout<<"wartosc= "<Rndm(); - wartf[i]=(f(x)+f(1.-x))/2.; - } - for(int i=0;iRndm(); - wartf[i]=fsubg(x); - } - for(int i=0;iRndm()); - double P;//P=(exp(-0.5)-1)*q*q/(2*sqrt(2*TMath::Pi()))+q/(2*sqrt(2*TMath::Pi())); - double a=2.*(exp(-0.5)/sqrt(2*TMath::Pi())-1.); - double b=2.-exp(-0.5)/sqrt(2*TMath::Pi()); - while(1) - { - - q=gRandom->Rndm(); - // P=(exp(-0.5)-1)*q*q/(2*sqrt(2*TMath::Pi()))+q/(2*sqrt(2*TMath::Pi())); - P=a*q*q/2.+b*q; - // if((gRandom->Rndm()*(1+exp(-0.5))/(2*sqrt(2*TMath::Pi())))Rndm()