{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# H 1Draw\n",
    "A Simple histogram drawing example\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "**Author:** Wim Lavrijsen  \n",
    "<i><small>This notebook tutorial was automatically generated with <a href= \"https://github.com/root-project/root/blob/master/documentation/doxygen/converttonotebook.py\">ROOTBOOK-izer</a> from the macro found in the ROOT repository  on Wednesday, March 03, 2021 at 09:40 AM.</small></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from ROOT import TCanvas, TPad, TFile, TPaveLabel, TPaveText\n",
    "from ROOT import gROOT\n",
    "\n",
    "c1 = TCanvas( 'c1', 'Histogram Drawing Options', 200, 10, 700, 900 )\n",
    "\n",
    "pad1 = TPad( 'pad1', 'The pad with the function',  0.03, 0.62, 0.50, 0.92, 21 )\n",
    "pad2 = TPad( 'pad2', 'The pad with the histogram', 0.51, 0.62, 0.98, 0.92, 21 )\n",
    "pad3 = TPad( 'pad3', 'The pad with the histogram', 0.03, 0.02, 0.97, 0.57, 21 )\n",
    "pad1.Draw()\n",
    "pad2.Draw()\n",
    "pad3.Draw()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We connect the ROOT file generated in a previous tutorial"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "example = TFile( 'py-hsimple.root' )\n",
    "example.ls()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Draw a global picture title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "title = TPaveLabel( 0.1, 0.94, 0.9, 0.98,\n",
    "                    'Drawing options for one dimensional histograms' )\n",
    "title.SetFillColor( 16 )\n",
    "title.SetTextFont( 52 )\n",
    "title.Draw()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Draw histogram hpx in first pad with the default option."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "pad1.cd()\n",
    "pad1.GetFrame().SetFillColor( 18 )\n",
    "hpx = gROOT.FindObject( 'hpx' )\n",
    "hpx.SetFillColor( 45 )\n",
    "hpx.DrawCopy()\n",
    "label1 = TPaveLabel( -3.5, 700, -1, 800, 'Default option' )\n",
    "label1.SetFillColor( 42 )\n",
    "label1.Draw()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Draw hpx as a lego. Clicking on the lego area will show\n",
    "a \"transparent cube\" to guide you rotating the lego in real time."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "pad2.cd()\n",
    "hpx.DrawCopy( 'lego1' )\n",
    "label2 = TPaveLabel( -0.72, 0.74, -0.22, 0.88, 'option Lego1' )\n",
    "label2.SetFillColor( 42 )\n",
    "label2.Draw()\n",
    "label2a = TPaveLabel( -0.93, -1.08, 0.25, -0.92, 'Click on lego to rotate' )\n",
    "label2a.SetFillColor( 42 )\n",
    "label2a.Draw()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Draw hpx with its errors and a marker."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "pad3.cd()\n",
    "pad3.SetGridx()\n",
    "pad3.SetGridy()\n",
    "pad3.GetFrame().SetFillColor( 18 )\n",
    "hpx.SetMarkerStyle( 21 )\n",
    "hpx.Draw( 'e1p' )\n",
    "label3 = TPaveLabel( 2, 600, 3.5, 650, 'option e1p' )\n",
    "label3.SetFillColor( 42 )\n",
    "label3.Draw()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following illustrates how to add comments using a PaveText.\n",
    "Attributes of text/lines/boxes added to a PaveText can be modified.\n",
    "The AddText function returns a pointer to the added object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "pave = TPaveText( -3.78, 500, -1.2, 750 )\n",
    "pave.SetFillColor( 42 )\n",
    "t1 = pave.AddText( 'You can move' )\n",
    "t1.SetTextColor( 4 )\n",
    "t1.SetTextSize( 0.05 )\n",
    "pave.AddText( 'Title and Stats pads' )\n",
    "pave.AddText( 'X and Y axis' )\n",
    "pave.AddText( 'You can modify bin contents' )\n",
    "pave.Draw()\n",
    "c1.Update()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Draw all canvases "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%jsroot on\n",
    "from ROOT import gROOT \n",
    "gROOT.GetListOfCanvases().Draw()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
