{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from numpy import shape, arange\n", "from matplotlib.pyplot import figure, show, hist\n", "from matplotlib import rcParams\n", "from read import ReadGeneration\n", "\n", "label_size = 20\n", "rcParams['xtick.labelsize'] = label_size \n", "rcParams['ytick.labelsize'] = label_size \n", "\n", "from numpy import shape, arange, log10, histogram\n", "from matplotlib.pyplot import figure, show, hist\n", "from read import ReadGeneration, ReadWeight, ReadEnergy\n", "\n", "import matplotlib as mpl\n", "label_size = 20\n", "mpl.rcParams['xtick.labelsize'] = label_size \n", "mpl.rcParams['ytick.labelsize'] = label_size \n", "\n", "def drawWeightHisto(fileId):\n", " '''\n", " Plot particles'weights histogram, generation by generation\n", " Input: directory name\n", " Output: particles'weights histogram\n", " '''\n", " fig = figure(figsize=(12,9))\n", " ax = fig.add_subplot(111)\n", " nbBins =100 \n", "\n", " weight = ReadWeight(fileId)\n", " generation = ReadGeneration(fileId)\n", " print \"file\", fileId, \"->\", shape(generation)[0], \"events\" \n", "\n", " for gen in list(set(generation)):\n", " hist(log10(weight[generation==gen]),nbBins,log=1,range=[0,7],alpha=.5,\n", " label=\"gen=\"+str(int(gen)))\n", "\n", " ax.legend(loc='best',fontsize=label_size)\n", " ax.set_xlabel(\"Weight [log]\",fontsize=label_size)\n", " ax.set_ylabel(\"Number of events\",fontsize=label_size)\n", "\n", " show()\n", "\n", "#######################################################################################\n", "def weightVsEnergy(fileId,gen=-1):\n", " '''\n", " Compute particles'weight versus energy\n", " Input: directory name\n", " Input (optional): generation (default = all)\n", " '''\n", " energy = ReadEnergy(fileId)\n", " weight = ReadWeight(fileId)\n", " nbBins = 100 \n", "\n", " if gen != -1:\n", " generation = ReadGeneration(fileId)\n", " energy=energy[generation==gen]\n", " weight=weight[generation==gen]\n", " nbBins =40 \n", "\n", " weight,ener=histogram(log10(energy),nbBins,weights=log10(weight))\n", " nb,ener=histogram(log10(energy),nbBins)\n", " ener=10**ener\n", " enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2\n", " weight /= nb\n", "\n", " return enercenter, weight\n", "\n", "def drawWeightVsEnergy(fileId):\n", " '''\n", " Plot particles'weight versus energy, generation by generation\n", " Input: directory name\n", " Output: graph of particles'weight versus energy\n", " '''\n", " fig = figure(figsize=(12,9))\n", " ax = fig.add_subplot(111)\n", "\n", " generation = ReadGeneration(fileId)\n", " print \"file\", fileId, \"->\", shape(generation)[0], \"events\" \n", "\n", " for gen in list(set(generation)):\n", " energy,weight = weightVsEnergy(fileId,gen)\n", " ax.plot(energy,weight,\".\",label=\"gen=\"+str(int(gen)))\n", "\n", " energy,weight = weightVsEnergy(fileId)\n", " ax.plot(energy,weight,\"k\",label=\"gen=all\")\n", "\n", " ax.set_xscale('log')\n", " ax.grid(b=True,which='major')\n", " ax.legend(loc=\"best\",fontsize=label_size)\n", " ax.set_title(fileId)\n", " ax.set_xlabel(\"energy [GeV]\",fontsize=label_size)\n", " ax.set_ylabel(\"mean weight [log]\",fontsize=label_size)\n", "\n", " show()\n", "\n", "\n", "\n", "def drawGeneration(files,plot=\"\"):\n", " '''\n", " Plot histogram of particles'generations\n", " Input: list of directories\n", " Output: histogram of generations\n", " '''\n", " fig = figure(figsize=(12,9))\n", " ax = fig.add_subplot(111)\n", " for fileId in files:\n", " if plot==\"generation\":\n", " i=1\n", " for powerlaw_index in [1,1.5,2,2.5]: \n", " generation, ratio = ReadGeneration(fileId,[0,i])\n", " ax.plot(generation,ratio,drawstyle='steps-mid',label=\"p=%.1f\"%powerlaw_index)\n", " i+=1\n", " else:\n", " generation, ratio = ReadGeneration(fileId,[0,3])\n", " ax.plot(generation,ratio,drawstyle='steps-mid',label=fileId)\n", "\n", " xtick=arange(9)\n", " ax.legend(loc='best',fontsize=label_size)\n", " ax.set_yscale('log')\n", " ax.set_xlabel(\"Generation\",fontsize=label_size)\n", " ax.set_ylabel(\"Ratio of events [%]\",fontsize=label_size)\n", "\n", " show()\n" ] } ], "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.11" } }, "nbformat": 4, "nbformat_minor": 0 }