{ "cells": [ { "cell_type": "markdown", "id": "c7cc9baf", "metadata": {}, "source": [ "# foam_demo\n", "Demonstrate the TFoam class.\n", "\n", " To run this macro type from ROOT command line\n", "\n", "```cpp\n", " root [0] gSystem->Load(\"libFoam.so\")\n", " root [1] .x foam_demo.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:06 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "b1543977", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:38.018443Z", "iopub.status.busy": "2026-05-19T20:06:38.018331Z", "iopub.status.idle": "2026-05-19T20:06:38.038873Z", "shell.execute_reply": "2026-05-19T20:06:38.031841Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "\n", "\n", "#include \"Riostream.h\"\n", "#include \"TFile.h\"\n", "#include \"TFoam.h\"\n", "#include \"TH1.h\"\n", "#include \"TMath.h\"\n", "#include \"TFoamIntegrand.h\"\n", "#include \"TRandom3.h\"\n", "\n", "class TFDISTR: public TFoamIntegrand {\n", "public:\n", " TFDISTR(){};\n", " Double_t Density(int nDim, Double_t *Xarg){\n", " // Integrand for mFOAM\n", " Double_t Fun1,Fun2,R1,R2;\n", " Double_t pos1=1e0/3e0;\n", " Double_t pos2=2e0/3e0;\n", " Double_t Gam1= 0.100e0; // as in JPC\n", " Double_t Gam2= 0.100e0; // as in JPC\n", " Double_t sPi = sqrt(TMath::Pi());\n", " Double_t xn1=1e0;\n", " Double_t xn2=1e0;\n", " int i;\n", " R1=0;\n", " R2=0;\n", " for(i = 0 ; iSetSeed(4357);" ] }, { "cell_type": "markdown", "id": "418cac35", "metadata": {}, "source": [ "-----------------------------------------" ] }, { "cell_type": "code", "execution_count": 5, "id": "d4a622a7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:38.942493Z", "iopub.status.busy": "2026-05-19T20:06:38.942325Z", "iopub.status.idle": "2026-05-19T20:06:39.180000Z", "shell.execute_reply": "2026-05-19T20:06:39.172415Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "***** Demonstration Program for Foam version 1.02M *****\n" ] } ], "source": [ "cout<<\"***** Demonstration Program for Foam version \"<GetVersion()<<\" *****\"<SetkDim( kDim); // Mandatory!!!\n", "FoamX->SetnCells( nCells); // optional\n", "FoamX->SetnSampl( nSampl); // optional\n", "FoamX->SetnBin( nBin); // optional\n", "FoamX->SetOptRej( OptRej); // optional\n", "FoamX->SetOptDrive( OptDrive); // optional\n", "FoamX->SetEvPerBin( EvPerBin); // optional\n", "FoamX->SetChat( Chat); // optional" ] }, { "cell_type": "markdown", "id": "ada3397e", "metadata": {}, "source": [ "-----------------------------------------" ] }, { "cell_type": "code", "execution_count": 6, "id": "e52c17a0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:39.193480Z", "iopub.status.busy": "2026-05-19T20:06:39.193341Z", "iopub.status.idle": "2026-05-19T20:06:39.415536Z", "shell.execute_reply": "2026-05-19T20:06:39.414641Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n", "F F\n", "F **************************************** F\n", "F ****** TFoam::Initialize ****** F\n", "F **************************************** F\n", "F FoamX F\n", "F Version = 1.02M = Release date: 2005.04.10 F\n", "F kDim = 2 = Dimension of the hyper-cubical space F\n", "F nCells = 500 = Requested number of Cells (half of them active) F\n", "F nSampl = 200 = No of MC events in exploration of a cell F\n", "F nBin = 8 = No of bins in histograms, MC exploration of cell F\n", "F EvPerBin = 25 = Maximum No effective_events/bin, MC exploration F\n", "F OptDrive = 2 = Type of Driver =1,2 for Sigma,WtMax F\n", "F OptRej = 1 = MC rejection on/off for OptRej=0,1 F\n", "F MaxWtRej = 1.1 = Maximum wt in rejection for wt=1 evts F\n", "F F\n", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n", "2222222222222222222222222222222222222222222222222\n", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n", "F F\n", "F *** TFoam::Initialize FINISHED!!! *** F\n", "F nCalls = 99800 = Total number of function calls F\n", "F XPrime = 1.3929609 = Primary total integral F\n", "F XDiver = 0.39362177 = Driver total integral F\n", "F mcResult = 0.99933914 = Estimate of the true MC Integral F\n", "F F\n", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n" ] } ], "source": [ "FoamX->SetRho(rho);\n", "FoamX->SetPseRan(PseRan);\n", "FoamX->Initialize(); // Initialize simulator\n", "FoamX->Write(\"FoamX\"); // Writing Foam on the disk, TESTING PERSISTENCY!!!" ] }, { "cell_type": "markdown", "id": "f8c6464a", "metadata": {}, "source": [ "-----------------------------------------" ] }, { "cell_type": "code", "execution_count": 7, "id": "6407a2eb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:39.439232Z", "iopub.status.busy": "2026-05-19T20:06:39.439088Z", "iopub.status.idle": "2026-05-19T20:06:39.649128Z", "shell.execute_reply": "2026-05-19T20:06:39.648643Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "====== Initialization done, entering MC loop\n" ] } ], "source": [ "long nCalls=FoamX->GetnCalls();\n", "cout << \"====== Initialization done, entering MC loop\" << endl;" ] }, { "cell_type": "markdown", "id": "c5a5c992", "metadata": {}, "source": [ "-----------------------------------------" ] }, { "cell_type": "code", "execution_count": 8, "id": "0262cfa7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:39.672193Z", "iopub.status.busy": "2026-05-19T20:06:39.672049Z", "iopub.status.idle": "2026-05-19T20:06:39.874422Z", "shell.execute_reply": "2026-05-19T20:06:39.873982Z" } }, "outputs": [], "source": [ "/*cout<<\" About to start MC loop: \"; cin.getline(question,20);*/\n", "Double_t *MCvect =new Double_t[kDim]; // vector generated in the MC run" ] }, { "cell_type": "markdown", "id": "f563801a", "metadata": {}, "source": [ "-----------------------------------------" ] }, { "cell_type": "code", "execution_count": 9, "id": "63f33606", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:39.886217Z", "iopub.status.busy": "2026-05-19T20:06:39.886084Z", "iopub.status.idle": "2026-05-19T20:06:40.095421Z", "shell.execute_reply": "2026-05-19T20:06:40.094694Z" } }, "outputs": [], "source": [ "TH1D *hst_Wt = new TH1D(\"hst_Wt\" , \"Main weight of Foam\",25,0,1.25);\n", "hst_Wt->Sumw2();" ] }, { "cell_type": "markdown", "id": "626a9fe8", "metadata": {}, "source": [ "-----------------------------------------" ] }, { "cell_type": "code", "execution_count": 10, "id": "ab1760b3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:40.104441Z", "iopub.status.busy": "2026-05-19T20:06:40.104306Z", "iopub.status.idle": "2026-05-19T20:06:40.318948Z", "shell.execute_reply": "2026-05-19T20:06:40.318457Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "MCwt= 1, MCvect= 0.68053985 0.69250597 \n", " loop= 0\n", "MCwt= 1, MCvect= 0.39743987 0.22347379 \n", "MCwt= 1, MCvect= 0.41862392 0.37268423 \n", "MCwt= 1, MCvect= 0.33221191 0.37801703 \n", "MCwt= 1, MCvect= 0.32221499 0.25437954 \n", "MCwt= 1, MCvect= 0.61444622 0.60520452 \n", "MCwt= 1, MCvect= 0.30018061 0.38244034 \n", "MCwt= 1, MCvect= 0.76521983 0.777539 \n", "MCwt= 1, MCvect= 0.78407102 0.69301713 \n", "MCwt= 1, MCvect= 0.72028183 0.66087924 \n", "MCwt= 1, MCvect= 0.73255425 0.64108329 \n", "MCwt= 1, MCvect= 0.24614236 0.23288176 \n", "MCwt= 1, MCvect= 0.34828797 0.51862775 \n", "MCwt= 1, MCvect= 0.44052705 0.39626735 \n", "MCwt= 1, MCvect= 0.65947295 0.59166751 \n" ] } ], "source": [ "for(loop=0; loopMakeEvent(); // generate MC event\n", "/*===============================*/\n", " FoamX->GetMCvect( MCvect);\n", " MCwt=FoamX->GetMCwt();\n", " hst_Wt->Fill(MCwt,1.0);\n", " if(loop<15){\n", " cout<<\"MCwt= \"</WtMax = 0.7211993 = MC efficiency, acceptance rate F\n", "F Sigma/ = 0.31991763 = MC efficiency, variance/ave_wt F\n", "F WtMax = 0.995 = WtMax(esp= 0.0005) F\n", "F Sigma = 0.22957075 = variance of MC weight F\n", "F / = 0.00018763091 = Contrib. of events wt>MaxWtRej F\n", "F F\n", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n", "TH1.Print Name = TFoamMaxwt_hst_Wt1, Entries= 76619, Total sum= 76619\n", "TH1.Print Name = TFoamMaxwt_hst_Wt2, Entries= 76619, Total sum= 54981.3\n", "================================================================\n", " MCresult= 0.99957943 +- 0.00115528 RelErr= 0.0011557661\n", " Dispersion/= 0.31991763\n", " /WtMax= 0.7211993, for epsilon = 0.0005\n", " nCalls (initialization only) = 99800\n", "================================================================\n" ] } ], "source": [ "cout << \"====== Events generated, entering Finalize\" << endl;\n", "\n", "hst_Wt->Print(\"all\");\n", "Double_t eps = 0.0005;\n", "Double_t Effic, WtMax, AveWt, Sigma;\n", "Double_t IntNorm, Errel;\n", "FoamX->Finalize( IntNorm, Errel); // final printout\n", "FoamX->GetIntegMC( MCresult, MCerror); // get MC intnegral\n", "FoamX->GetWtParams(eps, AveWt, WtMax, Sigma); // get MC wt parameters\n", "Effic=0; if(WtMax>0) Effic=AveWt/WtMax;\n", "cout << \"================================================================\" << endl;\n", "cout << \" MCresult= \" << MCresult << \" +- \" << MCerror << \" RelErr= \"<< MCerror/MCresult << endl;\n", "cout << \" Dispersion/= \" << Sigma/AveWt << endl;\n", "cout << \" /WtMax= \" << Effic <<\", for epsilon = \"<