\n",
"ROOT is not only a tool for the one aiming to a prestigious scientific discovery, but also for education. This notebook illustrates how ROOT can be used to explain the [slits experiment](https://en.wikipedia.org/wiki/Double-slit_experiment). See also the treatment of this example in the [ROOT primer](https://root.cern.ch/root/htmldoc/guides/primer/ROOTPrimer.html#root-as-function-plotter)."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
"require(['notebook'],\n",
" function() {\n",
" IPython.CodeCell.config_defaults.highlight_modes['magic_text/x-c++src'] = {'reg':[/^%%cpp/]};\n",
" console.log(\"JupyROOT - %%cpp magic configured\");\n",
" }\n",
");\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Welcome to JupyROOT 6.07/07\n"
]
}
],
"source": [
"import ROOT"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Writing the Function\n",
"Let's write in C++ the functions we will use to represent the interference figure. \n",
"They will be JIT-ted: this will be more performant than a Python interpreted version."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%cpp -d\n",
"auto pi = TMath::Pi();\n",
"double single(double *x, double *par){return pow(sin(pi*par[0]*x[0])/(pi*par[0]*x[0]),2);};\n",
"double nslit0(double *x, double *par){return pow(sin(pi*par[1]*x[0])/sin(pi*x[0]),2);};\n",
"double nslit(double *x, double *par){return single(x,par) * nslit0(x,par);};"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now write a [ROOT function](https://root.cern.ch/doc/master/classTF1.html) in Python wrapping the C++ function we created above. The number of points drawn is increased in order to visualize a smooth curve."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"interfTF1 = ROOT.TF1(\"Slits interference\",ROOT.nslit,-5.001,5.,2)\n",
"interfTF1.SetNpx(1000)\n",
"\n",
"c = ROOT.TCanvas(\"c\",\"c\",1024,768)\n",
"def interFunction(Distances_Ratio, Number_Of_Slits):\n",
" interfTF1.SetParameters(Distances_Ratio,Number_Of_Slits)\n",
" interfTF1.Draw()\n",
" c.Draw()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The parameters with which one can play are two:\n",
"1. The number of slits\n",
"2. The ratio of the distance between slits and the distance between the panels"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"