{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "//************************************************************************//\n",
    "//                                                                        //\n",
    "//  Copyright 2018 Bertram Kopf (bertram@ep1.rub.de)                      //\n",
    "//                 - Ruhr-Universität Bochum                              //\n",
    "//                                                                        //\n",
    "//  This file is part of Pawian.                                          //\n",
    "//                                                                        //\n",
    "//  Pawian is free software: you can redistribute it and/or modify        //\n",
    "//  it under the terms of the GNU General Public License as published by  //\n",
    "//  the Free Software Foundation, either version 3 of the License, or     //\n",
    "//  (at your option) any later version.                                   //\n",
    "//                                                                        //\n",
    "//  Pawian is distributed in the hope that it will be useful,             //\n",
    "//  but WITHOUT ANY WARRANTY; without even the implied warranty of        //\n",
    "//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //\n",
    "//  GNU General Public License for more details.                          //\n",
    "//                                                                        //\n",
    "//  You should have received a copy of the GNU General Public License     //\n",
    "//  along with Pawian.  If not, see <http://www.gnu.org/licenses/>.       //\n",
    "//                                                                        //\n",
    "//************************************************************************//\n",
    "\n",
    "#pragma once\n",
    "\n",
    "#include <iostream>\n",
    "\n",
    "class StatisticalTools\n",
    "{\n",
    " public:\n",
    "    static double sigmaFromLikelihoodRatio(double diffNLL, unsigned int diffParams) {\n",
    "        return ROOT::Math::chisquared_quantile_c(TMath::Prob(2.*diffNLL, diffParams), 1);\n",
    "    }\n",
    "\n",
    "    static double sigmaFromLikelihoodRatio(double NLL1, int ndf1, double NLL2, int ndf2) {\n",
    "        double diffNLL = fabs(NLL1-NLL2);\n",
    "        int diffParams = ndf1 - ndf2;\n",
    "        if(diffParams<0) {\n",
    "            std::cout << \"ndf2 > ndf1 !!!!\\n\" << \"this is not supported!!!\" << endl;\n",
    "            return -10000000000000.;\n",
    "        }\n",
    "        return sigmaFromLikelihoodRatio(diffNLL, diffParams);    \n",
    "    }\n",
    "\n",
    "    static double AIC(double NLL, int ndf) {\n",
    "        return (2. * NLL) + (2. * ndf);\n",
    "    }\n",
    "\n",
    "    static double BIC(double NLL, int ndf, int nEvts) {\n",
    "        return (2. * NLL) + (ndf * log(nEvts));\n",
    "    } \n",
    "};"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sigma = 2\n"
     ]
    }
   ],
   "source": [
    "std::cout << \"sigma = \" << StatisticalTools::sigmaFromLikelihoodRatio(1., 1.) << std::endl;\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ROOT C++ (Python 3)",
   "language": "c++",
   "name": "python36-jupyroot"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".C",
   "mimetype": " text/x-c++src",
   "name": "c++"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
