{ "cells": [ { "cell_type": "markdown", "id": "46c984c3", "metadata": {}, "source": [ "# rf902_numgenconfig\n", "Numeric algorithm tuning: configuration and customization of how MC sampling algorithms on specific pdfs are\n", "executed\n", "\n", "\n", "\n", "\n", "**Author:** Wouter Verkerke \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:35 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "d882f41a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:33.405436Z", "iopub.status.busy": "2026-05-19T20:35:33.405293Z", "iopub.status.idle": "2026-05-19T20:35:33.421476Z", "shell.execute_reply": "2026-05-19T20:35:33.420823Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooChebychev.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"RooPlot.h\"\n", "#include \"RooNumGenConfig.h\"\n", "#include \"RooArgSet.h\"\n", "#include \n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "490140fd", "metadata": {}, "source": [ "Adjust global MC sampling strategy\n", "------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "70a04ccb", "metadata": {}, "source": [ "Example pdf for use below" ] }, { "cell_type": "code", "execution_count": 2, "id": "8fc861e8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:33.422952Z", "iopub.status.busy": "2026-05-19T20:35:33.422839Z", "iopub.status.idle": "2026-05-19T20:35:33.826145Z", "shell.execute_reply": "2026-05-19T20:35:33.825765Z" } }, "outputs": [], "source": [ "RooRealVar x(\"x\", \"x\", 0, 10);\n", "RooChebychev model(\"model\", \"model\", x, RooArgList(0, 0.5, -0.1));" ] }, { "cell_type": "markdown", "id": "1af61ba9", "metadata": {}, "source": [ "Change global strategy for 1D sampling problems without conditional observable\n", "(1st false) and without discrete observable (2nd false) from RooFoamGenerator,\n", "( an interface to the TFoam MC generator with adaptive subdivisioning strategy ) to RooAcceptReject,\n", "a plain accept/reject sampling algorithm [ RooFit default before ROOT 5.23/04 ]" ] }, { "cell_type": "code", "execution_count": 3, "id": "506b2c14", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:33.828096Z", "iopub.status.busy": "2026-05-19T20:35:33.827980Z", "iopub.status.idle": "2026-05-19T20:35:34.034834Z", "shell.execute_reply": "2026-05-19T20:35:34.034357Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] ERROR:InputArguments -- Trying to set invalid state label 'RooAcceptReject' for category method1D\n" ] } ], "source": [ "RooAbsPdf::defaultGeneratorConfig()->method1D(false, false).setLabel(\"RooAcceptReject\");" ] }, { "cell_type": "markdown", "id": "28b9c56e", "metadata": {}, "source": [ "Generate 10Kevt using RooAcceptReject" ] }, { "cell_type": "code", "execution_count": 4, "id": "997f8554", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:34.036351Z", "iopub.status.busy": "2026-05-19T20:35:34.036232Z", "iopub.status.idle": "2026-05-19T20:35:34.246459Z", "shell.execute_reply": "2026-05-19T20:35:34.245735Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " --- RooGenContext --- \n", "Using PDF RooChebychev::model[ x=x coefList=(0,0.5,-0.1) ]\n", "Use PDF generator for ()\n", "Use MC sampling generator RooFoamGenerator for (x)\n", "RooDataSet::modelData[x] = 10000 entries\n" ] } ], "source": [ "std::unique_ptr data_ar{model.generate(x, 10000, Verbose(true))};\n", "data_ar->Print();" ] }, { "cell_type": "markdown", "id": "55f6ae3f", "metadata": {}, "source": [ "Adjusting default config for a specific pdf\n", "-------------------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "a66a133b", "metadata": {}, "source": [ "Another possibility: associate custom MC sampling configuration as default for object 'model'\n", "The true argument will install a clone of the default configuration as specialized configuration\n", "for this model if none existed so far" ] }, { "cell_type": "code", "execution_count": 5, "id": "94eb7119", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:34.247835Z", "iopub.status.busy": "2026-05-19T20:35:34.247719Z", "iopub.status.idle": "2026-05-19T20:35:34.453903Z", "shell.execute_reply": "2026-05-19T20:35:34.452936Z" } }, "outputs": [], "source": [ "model.specialGeneratorConfig(true)->method1D(false, false).setLabel(\"RooFoamGenerator\");" ] }, { "cell_type": "markdown", "id": "bb0e40a7", "metadata": {}, "source": [ "Adjusting parameters of a specific technique\n", "---------------------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "c8784f6a", "metadata": {}, "source": [ "Adjust maximum number of steps of RooIntegrator1D in the global default configuration" ] }, { "cell_type": "code", "execution_count": 6, "id": "748ca439", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:34.455298Z", "iopub.status.busy": "2026-05-19T20:35:34.455183Z", "iopub.status.idle": "2026-05-19T20:35:34.664853Z", "shell.execute_reply": "2026-05-19T20:35:34.663768Z" } }, "outputs": [], "source": [ "RooAbsPdf::defaultGeneratorConfig()->getConfigSection(\"RooAcceptReject\").setRealValue(\"nTrial1D\", 2000);" ] }, { "cell_type": "markdown", "id": "77459064", "metadata": {}, "source": [ "Example of how to change the parameters of a numeric integrator\n", "(Each config section is a RooArgSet with RooRealVars holding real-valued parameters\n", "and RooCategories holding parameters with a finite set of options)" ] }, { "cell_type": "code", "execution_count": 7, "id": "7a25f565", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:34.666245Z", "iopub.status.busy": "2026-05-19T20:35:34.666124Z", "iopub.status.idle": "2026-05-19T20:35:34.879653Z", "shell.execute_reply": "2026-05-19T20:35:34.878661Z" } }, "outputs": [], "source": [ "model.specialGeneratorConfig()->getConfigSection(\"RooFoamGenerator\").setRealValue(\"chatLevel\", 1);" ] }, { "cell_type": "markdown", "id": "6ca98956", "metadata": {}, "source": [ "Generate 10Kevt using RooFoamGenerator (FOAM verbosity increased with above chatLevel adjustment for illustration\n", "purposes)" ] }, { "cell_type": "code", "execution_count": 8, "id": "6504962d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:34.881080Z", "iopub.status.busy": "2026-05-19T20:35:34.880958Z", "iopub.status.idle": "2026-05-19T20:35:35.093534Z", "shell.execute_reply": "2026-05-19T20:35:35.092358Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n", "F F\n", "F **************************************** F\n", "F ****** TFoam::Initialize ****** F\n", "F **************************************** F\n", "F TFOAM F\n", "F Version = 1.02M = Release date: 2005.04.10 F\n", "F kDim = 1 = Dimension of the hyper-cubical space F\n", "F nCells = 30 = 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", "11\n", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n", "F F\n", "F *** TFoam::Initialize FINISHED!!! *** F\n", "F nCalls = 5800 = Total number of function calls F\n", "F XPrime = 0.10992972 = Primary total integral F\n", "F XDiver = 0.010000374 = Driver total integral F\n", "F mcResult = 0.099929343 = Estimate of the true MC Integral F\n", "F F\n", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n", " --- RooGenContext --- \n", "Using PDF RooChebychev::model[ x=x coefList=(0,0.5,-0.1) ]\n", "Use PDF generator for ()\n", "Use MC sampling generator RooFoamGenerator for (x)\n", "RooDataSet::modelData[x] = 10000 entries\n" ] } ], "source": [ "std::unique_ptr data_foam{model.generate(x, 10000, Verbose())};\n", "data_foam->Print();" ] } ], "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 }