{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import math\n", "import matplotlib.pyplot as plt\n", "from scipy.stats import norm" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Cruijff function\n", "# http://rarfit.sourceforge.net/html/RooCruijff_8cc-source.html\n", "# \n", "# It is a bifurcated Gaussian (different and high/low sigmas)\n", "# with sigma^2 replaced by sigma_R/L^2 + alpha_R/L*(x-mu)^2\n", "# \n", "# Note that the integral over the full range is unbounded, \n", "# so cannot be normalized. We normalize it here arbitrarily\n", "# so that the peak is the same as the peak of a Gaussian\n", "# of sigma=(sigmaL+sigmaR)/2.\n", "#\n", "def cruijff(x, mu, sigmaL, sigmaR, alphaL, alphaR):\n", " sigmaAv = (sigmaL+sigmaR)/2.\n", " N = 1./(math.sqrt(2*math.pi)*sigmaAv)\n", " dx = x - mu\n", " if hasattr(x, \"__len__\"): # x is a vector, assumed numpy\n", " fL = 2*sigmaL*sigmaL + alphaL*dx*dx\n", " fR = 2*sigmaR*sigmaR + alphaR*dx*dx\n", " LorR = x < mu\n", " f = LorR * fL + (1-LorR) * fR\n", " return N*np.exp(-dx*dx/f)\n", " \n", " else: # x is a number\n", " if x" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "x = np.linspace(max(0,mean-4*sigmaL), mean+4*sigmaR, 1000) # plot range\n", "ax = plt.subplot(111)\n", "ax.plot(x, cruijff(x, mean, sigmaL, sigmaR, alphaL, alphaR), label=\"Cruijff\")\n", "ax.plot(x, norm.pdf(x, scale=0.5*(sigmaL+sigmaR), loc=mean), label=\"Gaussian\")\n", "ax.grid()\n", "ax.legend()\n", "_ = ax.set_ylim(bottom=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }