{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example 7: Positronium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Injected positrons ultimately cool to nonrelativistic energies, at which point they annihilate with ambient free electrons by first forming positronium and then annihilating. DarkHistory provides the positronium module [*electrons.positronium*](https://darkhistory.readthedocs.io/en/latest/_autosummary/darkhistory/electrons/darkhistory.electrons.positronium.html) to obtain the resulting spectra from a positron at rest annihilating through the formation of positronium."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Initialization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "import sys\n",
    "sys.path.append(\"..\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%autoreload\n",
    "\n",
    "import matplotlib\n",
    "matplotlib.rc_file('matplotlibrc')\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import numpy as np\n",
    "from darkhistory import physics as phys\n",
    "from darkhistory.electrons import positronium as pos"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Positronium Spectrum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Positronium has two ground states: ortho-positronium or the triplet state, which decays to three photons, and para-positronium or the singlet state, which decays to two photons. The para-positronium decay spectrum is simply a line spectrum, while the ortho-positronium spectrum has been worked out to leading order in perturbation theory [[1]](#cite_Ore_Powell). These spectra are computed by [*positronium.ortho_photon_spec()*](https://darkhistory.readthedocs.io/en/latest/_autosummary/darkhistory/electrons/positronium/darkhistory.electrons.positronium.ortho_photon_spec.html) and [*positronium.para_photon_spec()*](https://darkhistory.readthedocs.io/en/latest/_autosummary/darkhistory/electrons/positronium/darkhistory.electrons.positronium.para_photon_spec.html) respectively. \n",
    "\n",
    "If we assume that positrons form positronium and populate these two states according to their statistical weights, then we can also compute a weighted photon spectrum, which is done by [*positronium.weighted_photon_spec()*](https://darkhistory.readthedocs.io/en/latest/_autosummary/darkhistory/electrons/positronium/darkhistory.electrons.positronium.weighted_photon_spec.html). \n",
    "\n",
    "Let's get the spectrum for such decays, with some given energy abscissa provided."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eng = 10**np.arange(3, 6.1, 0.001)\n",
    "\n",
    "ortho_spec    = pos.ortho_photon_spec(eng)\n",
    "para_spec     = pos.para_photon_spec(eng)\n",
    "weighted_spec = pos.weighted_photon_spec(eng)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And a plot of these spectra:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure()\n",
    "\n",
    "weighted_plot, = plt.plot(eng/1e6, eng*weighted_spec.dNdE, label='Weighted')\n",
    "ortho_plot, = plt.plot(\n",
    "    eng/1e6, eng*ortho_spec.dNdE*0.75, \n",
    "    'o', marker='o', markersize='5', \n",
    "    markevery=7, markerfacecolor='w',\n",
    "    label=r'$^3 S_1 \\to 3\\gamma$, $\\times 0.75$' \n",
    ")\n",
    "para_plot,  = plt.plot(\n",
    "    eng/1e6, eng*para_spec.dNdE*0.25,\n",
    "    'go', marker='o', markersize='5', \n",
    "    markevery=1, markerfacecolor='w',\n",
    "    label=r'$^1 S_0 \\to 2\\gamma$, $\\times 0.25$'\n",
    ")\n",
    "\n",
    "plt.legend(handles=[ortho_plot, para_plot, weighted_plot])\n",
    "\n",
    "ax = plt.gca()\n",
    "\n",
    "ax.set_yscale('log')\n",
    "\n",
    "plt.axis([0.3, 0.55, 1e-1, 1e3])\n",
    "\n",
    "plt.title('Positronium Photon Spectrum')\n",
    "plt.xlabel('Photon Energy [MeV]')\n",
    "plt.ylabel(r'$E \\, dN/dE$ [MeV]')\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's check that the energy contained in each spectrum, as well as the number of photons produced makes sense. These spectra are normalized to one positronium annihilation each. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('Number of photons in ortho_spec (3 gammas): ', ortho_spec.totN())\n",
    "print('Number of photons in para_spec (2 gammas): ' , para_spec.totN())\n",
    "print('Number of photons in weighted_spec (3*(3/4) + 2*(1/4) = 2.75 gammas): ', weighted_spec.totN())\n",
    "\n",
    "print('Total energy in ortho_spec: ', ortho_spec.toteng())\n",
    "print('Total energy in para_spec: ' , para_spec.toteng())\n",
    "print('Total energy in weighted_spec: ', weighted_spec.toteng())\n",
    "print('Positronium mass: ', 2*phys.me)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bibliography"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[1]<a id='cite_Ore_Powell'></a> A. Ore and J. L. Powell, “Three photon annihilation of an electron - positron pair,” Phys. Rev. 75, 1696–1699 (1949)."
   ]
  }
 ],
 "metadata": {
  "cite2c": {
   "citations": {
    "6232408/AVJQNP3G": {
     "DOI": "10.1103/PhysRev.75.1696",
     "URL": "https://link.aps.org/doi/10.1103/PhysRev.75.1696",
     "abstract": "Annihilation of an electron-positron pair accompanied by the emission of three photons is discussed for the case of small relative velocity of the two particles. The energy spectrum of the photons is derived and the cross section for the process is calculated. The ratio of this cross section to that of ordinary two-photon annihilation is found to be 1:370. When the result is applied to the 3S ground state of the positronium atom, for which two-photon annihilation is forbidden, one finds a lifetime 1.4×10−7 sec.",
     "accessed": {
      "day": 26,
      "month": 3,
      "year": 2019
     },
     "author": [
      {
       "family": "Ore",
       "given": "A."
      },
      {
       "family": "Powell",
       "given": "J. L."
      }
     ],
     "container-title": "Physical Review",
     "container-title-short": "Phys. Rev.",
     "id": "6232408/AVJQNP3G",
     "issue": "11",
     "issued": {
      "day": 1,
      "month": 6,
      "year": 1949
     },
     "journalAbbreviation": "Phys. Rev.",
     "page": "1696-1699",
     "page-first": "1696",
     "title": "Three-Photon Annihilation of an Electron-Positron Pair",
     "type": "article-journal",
     "volume": "75"
    }
   }
  },
  "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.6.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
