{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "//************************************************************************//\n",
    "//                                                                        //\n",
    "//  Copyright 2017 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",
    "#include <iostream>\n",
    "#include <sstream>\n",
    "#include \"TFile.h\"\n",
    "#include \"TH1F.h\"\n",
    "#include \"TCanvas.h\"\n",
    "#include \"TMath.h\"\n",
    "#include \"TLegend.h\"\n",
    "#include <algorithm>    // std::max\n",
    "\n",
    "TCanvas* contribCanvas = new TCanvas();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "void DrawContibutions(std::string rootFileNames, std::string name, bool withLegend = false, \n",
    "                          std::string legendNames = \"\") {\n",
    "  TH1F* histVec[20];\n",
    "  \n",
    "  std::stringstream rootFileNamesStrStr(rootFileNames);\n",
    "  vector<std::string> rootFileNamesVec;\n",
    "  std::string currentStr;\n",
    "  while (rootFileNamesStrStr >> currentStr) rootFileNamesVec.push_back(currentStr);\n",
    "  vector<std::string>::iterator it;\n",
    "  for(it = rootFileNamesVec.begin(); it != rootFileNamesVec.end(); ++it) {\n",
    "    std::cout << (*it) << std::endl;\n",
    "  }\n",
    "\n",
    "  TLegend *legend = new TLegend(0.19, 0.59, 0.39, 0.89);\n",
    "  vector<std::string> legendNamesVec;\n",
    "  if (withLegend) {\n",
    "    std::stringstream legendNamesStrStr(legendNames);\n",
    "    while (legendNamesStrStr >> currentStr) legendNamesVec.push_back(currentStr);\n",
    "    for (it = legendNamesVec.begin(); it != legendNamesVec.end(); ++it){\n",
    "      std::cout << (*it) << std::endl;\n",
    "    }\n",
    "    if (rootFileNamesVec.size() != legendNamesVec.size()) {\n",
    "      std::cout << \"rootFileNamesVec.size()= \" << rootFileNamesVec.size() \n",
    "          << \" != legendNamesVec.size(): \" << legendNamesVec.size() << std::endl;\n",
    "      return;\n",
    "    }\n",
    "  }\n",
    " \n",
    "  for (unsigned int id = 0; id < rootFileNamesVec.size(); ++id){\n",
    "    std::string currentFileName = rootFileNamesVec.at(id);\n",
    "    TFile* currentTFile = new TFile(currentFileName.c_str());\n",
    "    TH1F* currentHist = (TH1F*)currentTFile->Get(name.c_str());\n",
    "    currentHist->SetLineColor(kBlack + id);\n",
    "    currentHist->SetLineWidth(2);\n",
    "    histVec[id] = currentHist;\n",
    "    if (0 ==id) \n",
    "        currentHist->Draw(); \n",
    "    else \n",
    "        currentHist->Draw(\"same\");\n",
    "    currentHist->SetMaximum(1.05*(std::max(currentHist->GetMaximum(), histVec[0]->GetMaximum())));\n",
    "    if (withLegend) \n",
    "        legend->AddEntry(currentHist, legendNamesVec.at(id).c_str(), \"l\");\n",
    "  }\n",
    "\n",
    "  if (withLegend) {\n",
    "    legend->SetFillColor(0);\n",
    "    legend->SetBorderSize(1);\n",
    "    legend->Draw(); \n",
    "  } \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/nfs/data/jollyj/bertram/fits/pbarp/coupled_PiPiEta_PiEtaEta_KKPi/paperFinalHyper/final/Ochs2013---/4f2_0orderBgV5a/qaPiPiEta\n",
      "pawianHists.root\n",
      "pawianHistsf0Matrix.root\n",
      "pawianHistsf2Matrix.root\n",
      "pawianHistsa0Matrix.root\n",
      "pawianHistsa2Matrix.root\n",
      "pawianHistspi1Matrix.root\n",
      "all\n",
      "f0\n",
      "f2\n",
      "a0\n",
      "a2\n",
      "#pi_{1}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 21784 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "gSystem->cd(\"/data/jollyj/bertram/fits/pbarp/coupled_PiPiEta_PiEtaEta_KKPi/paperFinalHyper/final/Ochs2013---/4f2_0orderBgV5a/qaPiPiEta\");\n",
    "std::cout << gSystem->pwd() << std::endl;\n",
    "DrawContibutions(\"pawianHists.root pawianHistsf0Matrix.root pawianHistsf2Matrix.root pawianHistsa0Matrix.root pawianHistsa2Matrix.root pawianHistspi1Matrix.root\",\"Fitpion0Apion0B\", true, \"all f0 f2 a0 a2 #pi_{1}\");\n",
    "\n",
    "contribCanvas->Draw();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 21212 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pawianHists.root\n",
      "pawianHistsf0Matrix.root\n",
      "pawianHistsf2Matrix.root\n",
      "pawianHistsa0Matrix.root\n",
      "pawianHistsa2Matrix.root\n",
      "pawianHistspi1Matrix.root\n",
      "all\n",
      "f0\n",
      "f2\n",
      "a0\n",
      "a2\n",
      "#pi_{1}\n"
     ]
    }
   ],
   "source": [
    "DrawContibutions(\"pawianHists.root pawianHistsf0Matrix.root pawianHistsf2Matrix.root pawianHistsa0Matrix.root pawianHistsa2Matrix.root pawianHistspi1Matrix.root\",\"Fitpion0Aeta\", true, \"all f0 f2 a0 a2 #pi_{1}\");\n",
    "\n",
    "contribCanvas->Draw();"
   ]
  },
  {
   "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
}
