{ "cells": [ { "cell_type": "markdown", "id": "0a95a503", "metadata": {}, "source": [ "# foam_kanwa\n", "This program can be execute from the command line as folows:\n", "\n", "```cpp\n", " root -l foam_kanwa.C\n", "```\n", "\n", "\n", "\n", "\n", "**Author:** Stascek Jadach \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:25 PM." ] }, { "cell_type": "code", "execution_count": null, "id": "ab1c4799", "metadata": { "collapsed": false }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"Riostream.h\"\n", "#include \"TFoam.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TH2.h\"\n", "#include \"TMath.h\"\n", "#include \"TFoamIntegrand.h\"\n", "#include \"TRandom3.h\"" ] }, { "cell_type": "markdown", "id": "687d496e", "metadata": {}, "source": [ " _____________________________________________________________________________\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "9e9f5d41", "metadata": { "collapsed": false }, "outputs": [], "source": [ "%%cpp -d\n", "Double_t sqr(Double_t x){\n", " return x*x;\n", "}" ] }, { "cell_type": "markdown", "id": "40a39133", "metadata": {}, "source": [ " _____________________________________________________________________________\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "0edf3855", "metadata": { "collapsed": false }, "outputs": [], "source": [ "%%cpp -d\n", "Double_t Camel2(Int_t nDim, Double_t *Xarg){\n", " // 2-dimensional distribution for Foam, normalized to one (within 1e-5)\n", " Double_t x=Xarg[0];\n", " Double_t y=Xarg[1];\n", " Double_t GamSq= sqr(0.100e0);\n", " Double_t Dist= 0;\n", " Dist +=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi();\n", " Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi();\n", " return 0.5*Dist;\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "9392155b", "metadata": { "collapsed": false }, "outputs": [], "source": [ "cout<<\"--- kanwa started ---\"<SetSeed(4357);\n", "TFoam *FoamX = new TFoam(\"FoamX\"); // Create Simulator\n", "FoamX->SetkDim(2); // No. of dimensions, obligatory!\n", "FoamX->SetnCells(500); // Optionally No. of cells, default=2000\n", "FoamX->SetRhoInt(Camel2); // Set 2-dim distribution, included below\n", "FoamX->SetPseRan(PseRan); // Set random number generator\n", "FoamX->Initialize(); // Initialize simulator, may take time..." ] }, { "cell_type": "markdown", "id": "42795fdc", "metadata": {}, "source": [ "visualising generated distribution" ] }, { "cell_type": "code", "execution_count": null, "id": "6acdf28e", "metadata": { "collapsed": false }, "outputs": [], "source": [ "TCanvas *cKanwa = new TCanvas(\"cKanwa\",\"Canvas for plotting\",600,600);\n", "cKanwa->cd();" ] }, { "cell_type": "markdown", "id": "8b4cfb7e", "metadata": {}, "source": [ "From now on FoamX is ready to generate events" ] }, { "cell_type": "code", "execution_count": null, "id": "f3a78ec6", "metadata": { "collapsed": false }, "outputs": [], "source": [ "int nshow=5000;\n", "for(long loop=0; loop<100000; loop++){\n", " FoamX->MakeEvent(); // generate MC event\n", " FoamX->GetMCvect( MCvect); // get generated vector (x,y)\n", " Double_t x=MCvect[0];\n", " Double_t y=MCvect[1];\n", " if(loop<10) cout<<\"(x,y) = ( \"<< x <<\", \"<< y <<\" )\"<Fill(x,y);\n", " // live plot\n", " if(loop == nshow){\n", " nshow += 5000;\n", " hst_xy->Draw(\"lego2\");\n", " cKanwa->Update();\n", " }\n", "}// loop" ] }, { "cell_type": "code", "execution_count": null, "id": "7ebcea38", "metadata": { "collapsed": false }, "outputs": [], "source": [ "hst_xy->Draw(\"lego2\"); // final plot\n", "cKanwa->Update();" ] }, { "cell_type": "code", "execution_count": null, "id": "05a38b47", "metadata": { "collapsed": false }, "outputs": [], "source": [ "Double_t MCresult, MCerror;\n", "FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one\n", "cout << \" MCresult= \" << MCresult << \" +- \" << MCerror <GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }