{
"cells": [
{
"cell_type": "markdown",
"id": "a1fc013d",
"metadata": {},
"source": [
"# foam_demopers\n",
"This simple macro demonstrates persistency of FOAM object.\n",
"First run macro foam_demo.C to create file foam_demo.root with FOAM object.\n",
"\n",
"Next type `root -l foam_demopers.C` from shell command line\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, March 19, 2024 at 07:09 PM."
]
},
{
"cell_type": "markdown",
"id": "79702353",
"metadata": {},
"source": [
"need to load the foam_demo tutorial for the definition of the function"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "08acca24",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:09:22.399683Z",
"iopub.status.busy": "2024-03-19T19:09:22.399274Z",
"iopub.status.idle": "2024-03-19T19:09:34.145108Z",
"shell.execute_reply": "2024-03-19T19:09:34.143273Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : creating shared library /home/sftnight/build/workspace/root-makedoc-master/rootspi/rdoc/src/master.build/tutorials/foam/foam_demo_C.so\n"
]
}
],
"source": [
"TString macroName = gROOT->GetTutorialDir();\n",
"macroName.Append(\"/foam/foam_demo.C\");\n",
"gROOT->ProcessLine(TString::Format(\".L %s+\",macroName.Data()));"
]
},
{
"cell_type": "markdown",
"id": "0e1f33ae",
"metadata": {},
"source": [
"******************************************"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d8e95c69",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:09:34.162333Z",
"iopub.status.busy": "2024-03-19T19:09:34.161908Z",
"iopub.status.idle": "2024-03-19T19:09:34.453815Z",
"shell.execute_reply": "2024-03-19T19:09:34.450765Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"====================== TestVector ================================\n",
"------------------------------------------------------------------\n",
"TFile**\t\tfoam_demo.root\thistograms\n",
" TFile*\t\tfoam_demo.root\thistograms\n",
" KEY: TFoam\tFoamX;1\tGeneral purpose self-adapting Monte Carlo event generator\n",
" KEY: TProcessID\tProcessID0;1\t5b654550-e623-11ee-abb1-942c8a89beef\n",
" KEY: TH1D\thst_Wt;1\tMain weight of Foam\n",
"------------------------------------------------------------------\n",
"20240319/190325 At:100 N=144 TFile \n",
"20240319/190326 At:244 N=155 TProcessID \n",
"20240319/190326 At:399 N=27808 TFoam CX = 3.29 \n",
"20240319/190328 At:28207 N=332 TH1D CX = 3.13 \n",
"20240319/190328 At:28539 N=301 KeysList \n",
"20240319/190328 At:28840 N=6076 StreamerInfo CX = 3.17 \n",
"20240319/190328 At:34916 N=68 FreeSegments \n",
"20240319/190328 At:34984 N=1 END \n",
"------------------------------------------------------------------\n",
"OBJ: TList\tTList\tDoubly linked list : 0\n",
"\n",
"StreamerInfo for class: TNamed, version=1, checksum=0xdfb74a3c\n",
" TObject BASE offset= 0 type=66 Basic ROOT object \n",
" TString fName offset= 0 type=65 object identifier \n",
" TString fTitle offset= 0 type=65 object title \n",
"\n",
"StreamerInfo for class: TObject, version=1, checksum=0x901bc02d\n",
" unsigned int fUniqueID offset= 0 type=13 object unique identifier\n",
" unsigned int fBits offset= 0 type=15 bit field status word\n",
"\n",
"StreamerInfo for class: THashList, version=0, checksum=0xcc7e49c1\n",
" TList BASE offset= 0 type= 0 Doubly linked list \n",
"\n",
"StreamerInfo for class: TList, version=5, checksum=0x69c5c3bb\n",
" TSeqCollection BASE offset= 0 type= 0 Sequenceable collection ABC\n",
"\n",
"StreamerInfo for class: TSeqCollection, version=0, checksum=0xfc6c3bc6\n",
" TCollection BASE offset= 0 type= 0 Collection abstract base class\n",
"\n",
"StreamerInfo for class: TCollection, version=3, checksum=0x57e3cb9c\n",
" TObject BASE offset= 0 type=66 Basic ROOT object \n",
" TString fName offset= 0 type=65 name of the collection\n",
" int fSize offset= 0 type= 3 number of elements in collection\n",
"\n",
"StreamerInfo for class: TFoam, version=2, checksum=0x231190da\n",
" TObject BASE offset= 0 type=66 Basic ROOT object \n",
" TString fName offset= 0 type=65 Name of a given instance of the FOAM class\n",
" TString fVersion offset= 0 type=65 Actual version of the FOAM like (1.01m)\n",
" TString fDate offset= 0 type=65 Release date of FOAM\n",
" int fDim offset= 0 type= 6 Dimension of the integration/simulation space\n",
" int fNCells offset= 0 type= 6 Maximum number of cells\n",
" int fRNmax offset= 0 type= 6 Maximum No. of the rand. numb. requested at once\n",
" int fOptDrive offset= 0 type= 3 Optimization switch =1,2 for variance or maximum weight optimization\n",
" int fChat offset= 0 type= 3 Chat=0,1,2 chat level in output, Chat=1 normal level\n",
" int fOptRej offset= 0 type= 3 Switch =0 for weighted events; =1 for unweighted events in MC\n",
" int fNBin offset= 0 type= 3 No. of bins in the edge histogram for cell MC exploration\n",
" int fNSampl offset= 0 type= 3 No. of MC events, when dividing (exploring) cell\n",
" int fEvPerBin offset= 0 type= 3 Maximum number of effective (wt=1) events per bin\n",
" int fOptPRD offset= 0 type= 3 Option switch for predefined division, for quick check\n",
" int fNoAct offset= 0 type= 6 Number of active cells\n",
" int fLastCe offset= 0 type= 3 Index of the last cell\n",
" TFoamCell** fCells offset= 0 type=501 [fNCells] Array of ALL cells\n",
" TFoamMaxwt* fMCMonit offset= 0 type=64 Monitor of the MC weight for measuring MC efficiency\n",
" double fMaxWtRej offset= 0 type= 8 Maximum weight in rejection for getting wt=1 events\n",
" vector fCellsAct offset= 0 type=300 ,stl=1, ctype=4, Index of active cells, constructed at the end of foam build-up\n",
" double* fPrimAcu offset= 0 type=48 [fNoAct] Array of cumulative probability of all active cells\n",
" TObjArray* fHistEdg offset= 0 type=64 Histograms of wt, one for each cell edge\n",
" TObjArray* fHistDbg offset= 0 type=64 Histograms of wt, for debug\n",
" TH1D* fHistWt offset= 0 type=64 Histogram of the MC wt\n",
" double* fMCvect offset= 0 type=48 [fDim] Generated MC vector for the outside user\n",
" double fMCwt offset= 0 type= 8 MC weight \n",
" double* fRvec offset= 0 type=48 [fRNmax] random number vector from r.n. generator fDim+1 maximum elements\n",
" TRandom* fPseRan offset= 0 type=64 Pointer to user-defined generator of pseudorandom numbers\n",
" long fNCalls offset= 0 type= 4 Total number of the function calls\n",
" long fNEffev offset= 0 type= 4 Total number of effective events (wt=1) in the foam buildup\n",
" double fSumWt offset= 0 type= 8 Total sum of wt and wt^2\n",
" double fSumWt2 offset= 0 type= 8 Total sum of wt and wt^2\n",
" double fSumOve offset= 0 type= 8 Total Sum of overweighted events\n",
" double fNevGen offset= 0 type= 8 Total number of the generated MC events\n",
" double fWtMax offset= 0 type= 8 Maximum/Minimum MC weight\n",
" double fWtMin offset= 0 type= 8 Maximum/Minimum MC weight\n",
" double fPrime offset= 0 type= 8 Primary integral R' (R=R'``)\n",
" double fMCresult offset= 0 type= 8 True Integral R from MC series\n",
" double fMCerror offset= 0 type= 8 and its error \n",
" double* fAlpha offset= 0 type=48 [fDim] Internal parameters of the hyper-rectangle\n",
"\n",
"StreamerInfo for class: TFoamCell, version=2, checksum=0x743666eb\n",
" TObject BASE offset= 0 type=66 Basic ROOT object \n",
" short fDim offset= 0 type= 2 Dimension of the vector space\n",
" int fSerial offset= 0 type= 3 Serial number \n",
" int fStatus offset= 0 type= 3 Status (active, inactive)\n",
" TRef fParent offset= 0 type=61 Pointer to parent cell\n",
" TRef fDaught0 offset= 0 type=61 Pointer to daughter 1\n",
" TRef fDaught1 offset= 0 type=61 Pointer to daughter 2\n",
" int fParentIdx offset= 0 type= 3 Serial number of parent cell\n",
" int fDaught0Idx offset= 0 type= 3 Serial number of daughter 1\n",
" int fDaught1Idx offset= 0 type= 3 Serial number of daughter 2\n",
" double fXdiv offset= 0 type= 8 Factor for division \n",
" int fBest offset= 0 type= 3 Best Edge for division\n",
" double fVolume offset= 0 type= 8 Cartesian Volume of cell\n",
" double fIntegral offset= 0 type= 8 Integral over cell (estimate from exploration)\n",
" double fDrive offset= 0 type= 8 Driver integral, only for cell build-up\n",
" double fPrimary offset= 0 type= 8 Primary integral, only for MC generation\n",
"\n",
"StreamerInfo for class: TProcessID, version=1, checksum=0x2b7ef579\n",
" TNamed BASE offset= 0 type=67 The basis for a named object (name, title)\n",
"\n",
"StreamerInfo for class: TFoamMaxwt, version=1, checksum=0x75617bf1\n",
" TObject BASE offset= 0 type=66 Basic ROOT object \n",
" double fNent offset= 0 type= 8 No. of MC events \n",
" int fnBin offset= 0 type= 3 No. of bins on the weight distribution\n",
" double fwmax offset= 0 type= 8 Maximum analyzed weight\n",
" TH1D* fWtHst1 offset= 0 type=64 Histogram of the weight wt\n",
" TH1D* fWtHst2 offset= 0 type=64 Histogram of wt filled with wt\n",
"\n",
"StreamerInfo for class: TH1D, version=3, checksum=0xf9b1569f\n",
" TH1 BASE offset= 0 type= 0 1-Dim histogram base class\n",
" TArrayD BASE offset= 0 type= 0 Array of doubles \n",
"\n",
"StreamerInfo for class: TH1, version=8, checksum=0x1c3740c4\n",
" TNamed BASE offset= 0 type=67 The basis for a named object (name, title)\n",
" TAttLine BASE offset= 0 type= 0 Line attributes \n",
" TAttFill BASE offset= 0 type= 0 Fill area attributes\n",
" TAttMarker BASE offset= 0 type= 0 Marker attributes \n",
" int fNcells offset= 0 type= 3 Number of bins(1D), cells (2D) +U/Overflows\n",
" TAxis fXaxis offset= 0 type=61 X axis descriptor \n",
" TAxis fYaxis offset= 0 type=61 Y axis descriptor \n",
" TAxis fZaxis offset= 0 type=61 Z axis descriptor \n",
" short fBarOffset offset= 0 type= 2 (1000*offset) for bar charts or legos\n",
" short fBarWidth offset= 0 type= 2 (1000*width) for bar charts or legos\n",
" double fEntries offset= 0 type= 8 Number of entries \n",
" double fTsumw offset= 0 type= 8 Total Sum of weights\n",
" double fTsumw2 offset= 0 type= 8 Total Sum of squares of weights\n",
" double fTsumwx offset= 0 type= 8 Total Sum of weight*X\n",
" double fTsumwx2 offset= 0 type= 8 Total Sum of weight*X*X\n",
" double fMaximum offset= 0 type= 8 Maximum value for plotting\n",
" double fMinimum offset= 0 type= 8 Minimum value for plotting\n",
" double fNormFactor offset= 0 type= 8 Normalization factor\n",
" TArrayD fContour offset= 0 type=62 Array to display contour levels\n",
" TArrayD fSumw2 offset= 0 type=62 Array of sum of squares of weights\n",
" TString fOption offset= 0 type=65 Histogram options \n",
" TList* fFunctions offset= 0 type=63 ->Pointer to list of functions (fits and user)\n",
" int fBufferSize offset= 0 type= 6 fBuffer size \n",
" double* fBuffer offset= 0 type=48 [fBufferSize] entry buffer\n",
" TH1::EBinErrorOpt fBinStatErrOpt offset= 0 type= 3 Option for bin statistical errors\n",
" TH1::EStatOverflows fStatOverflows offset= 0 type= 3 Per object flag to use under/overflows in statistics\n",
"\n",
"StreamerInfo for class: TAttLine, version=2, checksum=0x94074549\n",
" short fLineColor offset= 0 type= 2 Line color \n",
" short fLineStyle offset= 0 type= 2 Line style \n",
" short fLineWidth offset= 0 type= 2 Line width \n",
"\n",
"StreamerInfo for class: TAttFill, version=2, checksum=0xffd92a92\n",
" short fFillColor offset= 0 type= 2 Fill area color \n",
" short fFillStyle offset= 0 type= 2 Fill area style \n",
"\n",
"StreamerInfo for class: TAttMarker, version=2, checksum=0x291d8bec\n",
" short fMarkerColor offset= 0 type= 2 Marker color \n",
" short fMarkerStyle offset= 0 type= 2 Marker style \n",
" float fMarkerSize offset= 0 type= 5 Marker size \n",
"\n",
"StreamerInfo for class: TAxis, version=10, checksum=0x5a496e70\n",
" TNamed BASE offset= 0 type=67 The basis for a named object (name, title)\n",
" TAttAxis BASE offset= 0 type= 0 Axis attributes \n",
" int fNbins offset= 0 type= 3 Number of bins \n",
" double fXmin offset= 0 type= 8 Low edge of first bin\n",
" double fXmax offset= 0 type= 8 Upper edge of last bin\n",
" TArrayD fXbins offset= 0 type=62 Bin edges array in X\n",
" int fFirst offset= 0 type= 3 First bin to display\n",
" int fLast offset= 0 type= 3 Last bin to display \n",
" unsigned short fBits2 offset= 0 type=12 Second bit status word\n",
" bool fTimeDisplay offset= 0 type=18 On/off displaying time values instead of numerics\n",
" TString fTimeFormat offset= 0 type=65 Date&time format, ex: 09/12/99 12:34:00\n",
" THashList* fLabels offset= 0 type=64 List of labels \n",
" TList* fModLabs offset= 0 type=64 List of modified labels\n",
"\n",
"StreamerInfo for class: TAttAxis, version=4, checksum=0x5c6fff3e\n",
" int fNdivisions offset= 0 type= 3 Number of divisions(10000*n3 + 100*n2 + n1)\n",
" short fAxisColor offset= 0 type= 2 Color of the line axis\n",
" short fLabelColor offset= 0 type= 2 Color of labels \n",
" short fLabelFont offset= 0 type= 2 Font for labels \n",
" float fLabelOffset offset= 0 type= 5 Offset of labels \n",
" float fLabelSize offset= 0 type= 5 Size of labels \n",
" float fTickLength offset= 0 type= 5 Length of tick marks\n",
" float fTitleOffset offset= 0 type= 5 Offset of axis title\n",
" float fTitleSize offset= 0 type= 5 Size of axis title \n",
" short fTitleColor offset= 0 type= 2 Color of axis title \n",
" short fTitleFont offset= 0 type= 2 Font for axis title \n",
"\n",
"StreamerInfo for class: TString, version=2, checksum=0x17419\n",
"\n",
"StreamerInfo for class: TRandom3, version=2, checksum=0x824af0bb\n",
" TRandom BASE offset= 0 type= 0 Simple Random number generator (periodicity = 10**9)\n",
" unsigned int fMt[624] offset= 0 type=33 \n",
" int fCount624 offset= 0 type= 3 \n",
"\n",
"StreamerInfo for class: TRandom, version=3, checksum=0xe0f3fab\n",
" TNamed BASE offset= 0 type=67 The basis for a named object (name, title)\n",
" ROOT::Math::TRandomEngine BASE offset= 0 type= 0 \n",
" unsigned int fSeed offset= 0 type=13 Random number generator seed\n",
"\n",
"StreamerInfo for class: ROOT::Math::TRandomEngine, version=1, checksum=0xdbdd9943\n",
" OBJ: TList\tlistOfRules\tDoubly linked list : 0\n",
" OBJ: TObjString\ttype=read sourceClass=\"TFoam\" targetClass=\"TFoam\" version=\"[1]\" source=\"Int_t fNCells; TFoamCell **fCells; TRefArray *fCellsAct\" target=\"fNCells,fCells,fCellsAct\" include=\"TRefArray.h\" code=\"{fNCells = onfile.fNCells; \\n fCells = onfile.fCells; \\n onfile.fCells = nullptr; \\n fCellsAct.clear(); \\n for (Int_t i=0; i < onfile.fCellsAct->GetEntries(); ++i) { \\n const TObject* cellp = onfile.fCellsAct->At(i); \\n for (Int_t j=0; j < fNCells; ++j) { \\n if (cellp == fCells[j]) { \\n fCellsAct.push_back(j); \\n break; \\n } \\n } \\n }}\" \tCollectable string class : 0 at: 0x7f7eab0bea10\n",
"------------------------------------------------------------------\n",
"Collection name='THashList', class='THashList', size=3\n",
" TKey Name = FoamX, Title = General purpose self-adapting Monte Carlo event generator, Cycle = 1\n",
" TKey Name = ProcessID0, Title = 5b654550-e623-11ee-abb1-942c8a89beef, Cycle = 1\n",
" TKey Name = hst_Wt, Title = Main weight of Foam, Cycle = 1\n",
"------------------------------------------------------------------\n"
]
}
],
"source": [
"cout<<\"====================== TestVector ================================\"<Print();\n",
"cout<<\"------------------------------------------------------------------\"<PrintCells();"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ace15c56",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:09:34.716847Z",
"iopub.status.busy": "2024-03-19T19:09:34.716460Z",
"iopub.status.idle": "2024-03-19T19:09:34.949829Z",
"shell.execute_reply": "2024-03-19T19:09:34.948631Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"///////////////////////////// FOAM_Checks /////////////////////////////////\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : Check has found 0 errors and 0 warnings \n",
"\n"
]
}
],
"source": [
"FoamX->CheckAll(1);"
]
},
{
"cell_type": "markdown",
"id": "4a5ad75a",
"metadata": {},
"source": [
"N.B. the integrand functions need to be reset\n",
"because cannot be made persistent"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "028a777a",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:09:34.976782Z",
"iopub.status.busy": "2024-03-19T19:09:34.975851Z",
"iopub.status.idle": "2024-03-19T19:09:35.291683Z",
"shell.execute_reply": "2024-03-19T19:09:35.290751Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(x,y) = ( 0.68054, 0.692506 )\n",
"(x,y) = ( 0.39744, 0.223474 )\n",
"(x,y) = ( 0.418624, 0.372684 )\n",
"(x,y) = ( 0.332212, 0.378017 )\n",
"(x,y) = ( 0.322215, 0.25438 )\n",
"(x,y) = ( 0.614446, 0.605205 )\n",
"(x,y) = ( 0.300181, 0.38244 )\n",
"(x,y) = ( 0.76522, 0.777539 )\n",
"(x,y) = ( 0.784071, 0.693017 )\n",
"(x,y) = ( 0.720282, 0.660879 )\n"
]
}
],
"source": [
"TFoamIntegrand * rho = (TFoamIntegrand*) gROOT->ProcessLine(\"return new TFDISTR();\");\n",
"FoamX->SetRho(rho);\n",
"\n",
"Double_t MCvect[2]; // 2-dim vector generated in the MC run\n",
"\n",
"for(long loop=0; loop<50000; 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 <<\" )\"</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",
" MCresult= 0.99957943 +- 0.00115528\n",
"===================== TestPers FINISHED =======================\n"
]
}
],
"source": [
"Double_t IntNorm, Errel;\n",
"FoamX->Finalize( IntNorm, Errel); // final printout\n",
"Double_t MCresult, MCerror;\n",
"FoamX->GetIntegMC( MCresult, MCerror); // get MC integral, should be one\n",
"cout << \" MCresult= \" << MCresult << \" +- \" << MCerror <