import ROOT
Welcome to JupyROOT 6.07/01
Let's write in C++ the functions we will use to represent the interference figure. They will be JIT-ted: this will be more performant than a Python interpreted version.
%%cpp -d
auto pi = TMath::Pi();
double single(double *x, double *par){return pow(sin(pi*par[0]*x[0])/(pi*par[0]*x[0]),2);};
double nslit0(double *x, double *par){return pow(sin(pi*par[1]*x[0])/sin(pi*x[0]),2);};
double nslit(double *x, double *par){return single(x,par) * nslit0(x,par);};
We now write a ROOT function in Python wrapping the C++ function we created above. The number of points drawn is increased in order to visualize a smooth curve.
interfTF1 = ROOT.TF1("Slits interference",ROOT.nslit,-5.001,5.,2)
interfTF1.SetNpx(1000)
c = ROOT.TCanvas("c","c",1600,1200)
TCanvas::Constructor:0: RuntimeWarning: Deleting canvas with same name: c
The parameters with which one can play are two:
In order to easily modify the parameters of the function, a widget is used.
from ipywidgets import interact, FloatSlider
RatioSlider = FloatSlider(min=.05, max=1., step=0.05, value=0.2)
NSSlider = FloatSlider(min=1, max=10, step=1, value=2)
@interact(Ratio = RatioSlider, Number_Of_Slits = NSSlider)
def interFunction(Ratio, Number_Of_Slits):
interfTF1.SetParameters(Ratio,Number_Of_Slits)
interfTF1.Draw()
c.Draw()
return 0
0