Back to home page

EIC code displayed by LXR

 
 

    


Warning, /estarlight/production/event_generation/Event-Generation.ipynb is written in an unsupported language. File is not indexed.

0001 {
0002  "cells": [
0003   {
0004    "cell_type": "markdown",
0005    "metadata": {},
0006    "source": [
0007     "## Event generation\n",
0008     "This notebook illustrates how to automate large sample event generation for a series of accelerator configurations, particle species, etc. The notebook will run three steps:\n",
0009     " - Event generation in _eSTARlight_\n",
0010     " - ASCII file is then converted to ROOT tree\n",
0011     " - Analysis is then run on the output ROOT file and simple histograms are produced"
0012    ]
0013   },
0014   {
0015    "cell_type": "code",
0016    "execution_count": 1,
0017    "metadata": {
0018     "collapsed": true
0019    },
0020    "outputs": [],
0021    "source": [
0022     "import itertools\n",
0023     "import sys, string, os\n",
0024     "from math import log10, floor\n",
0025     "import matplotlib.pyplot as plt  \n",
0026     "import seaborn as sns\n",
0027     "home_dir = '/Users/michaellomnitz/Documents/install_test/'\n",
0028     "unit_decode = { 'mb.':-3, 'microb.':-6, 'nanob.':-9, 'picob.':-12, 'femtob.':-15}"
0029    ]
0030   },
0031   {
0032    "cell_type": "markdown",
0033    "metadata": {},
0034    "source": [
0035     "Some simple funcitons used for utilies and run workflow:\n",
0036     "- round_sig: Round a number to a given number of significant figures\n",
0037     "- make_input_file: Takes template input file for _eSTARlight_ and sets the desired $Q^2$ range and final state.\n",
0038     "- run_prepared_sim: Runs the full pipeline for a prepared input configuration file _slight.in_. This first generates the M.C. sample in _eSTARlight_, then processes the ASCII file to produce ROOT tree. Finally it runs an analysis on the ROOT file.\n",
0039     "\n",
0040     "*Note*: It is assumed that home_dir contains eSTARlight and the compiled executable e_starlight"
0041    ]
0042   },
0043   {
0044    "cell_type": "code",
0045    "execution_count": 2,
0046    "metadata": {
0047     "collapsed": true
0048    },
0049    "outputs": [],
0050    "source": [
0051     "def round_sig(x, sig=2):\n",
0052     "    return round(x, sig-int(floor(log10(abs(x))))-1)\n",
0053     "\n",
0054     "def make_input_file(template_loc, prod_pid, prod_mode):\n",
0055     "    print(prod_mode)\n",
0056     "    with open(template_loc,'r') as f:\n",
0057     "        data=f.readlines()    \n",
0058     "    if prod_mode is 'PP':\n",
0059     "        print('here')\n",
0060     "        data[33] = 'MIN_GAMMA_Q2 = 0. \\n'\n",
0061     "        data[34] = 'MAX_GAMMA_Q2 = 1. \\n'\n",
0062     "    elif prod_mode is 'EP':\n",
0063     "        data[33] = 'MIN_GAMMA_Q2 = 1.0 \\n'\n",
0064     "        data[34] = 'MAX_GAMMA_Q2 = 100.0 \\n'\n",
0065     "    else:\n",
0066     "        print('prod_mode not defined')\n",
0067     "        return\n",
0068     "\n",
0069     "    data[29] = 'PROD_PID = '+str(prod_pid)+'\\n'\n",
0070     "    data[28] = 'N_EVENTS = 100000\\n'\n",
0071     "    with open(home_dir+'slight.in','w') as f:\n",
0072     "        f.writelines(data)\n",
0073     "        \n",
0074     "def run_prepared_sim(pwd_to_out):\n",
0075     "    ascii_to_root = 'root -b -q -l '+home_dir+'eSTARlight/trunk/utils/ConvertStarlightAsciiToTree.C'\n",
0076     "    # Run eSTARlight\n",
0077     "    os.chdir( home_dir )\n",
0078     "    os.system( home_dir+'e_starlight > log' )\n",
0079     "    os.system(ascii_to_root)\n",
0080     "    # Move files\n",
0081     "    os.rename(home_dir+'log',\n",
0082     "              pwd_to_out+'.txt')\n",
0083     "    os.rename(home_dir+'slight.out',\n",
0084     "              pwd_to_out+'.out')\n",
0085     "    os.rename(home_dir+'starlight.root', \n",
0086     "             pwd_to_out+'.root')\n",
0087     "    # \n",
0088     "    os.chdir(home_dir+'eSTARlight/analysis/')\n",
0089     "    os.system('sh e_run.sh '+pwd_to_out+'.root')\n",
0090     "    os.rename('photon_energy_bands.eps', \n",
0091     "             pwd_to_out+'_photon_energy_bands.eps')\n",
0092     "    os.rename('detector_acceptance.eps', \n",
0093     "             pwd_to_out+'_detector_acceptance.eps.eps')\n",
0094     "    # Make root file\n",
0095     "    os.chdir( home_dir )"
0096    ]
0097   },
0098   {
0099    "cell_type": "markdown",
0100    "metadata": {},
0101    "source": [
0102     "## Generate simluation samples\n",
0103     "Set up the specific simulation to produce. We set:\n",
0104     " - particle_prod: Final states to simulate\n",
0105     " - accelerator_facility: Accelerator facilities to simulate\n",
0106     " - prod_m: Production mechanism to study, either photoproduction ('PP') or electroproduction ('EP')\n",
0107     "Then run the fll simulation"
0108    ]
0109   },
0110   {
0111    "cell_type": "code",
0112    "execution_count": 3,
0113    "metadata": {
0114     "collapsed": true
0115    },
0116    "outputs": [],
0117    "source": [
0118     "particle_prod = {'rho':113, 'J_psi':443011}\n",
0119     "accelerator_facility = ['eRHIC','JLEIC','LHeC',\n",
0120     "                        'eRHIC_eA','JLEIC_eA','LHeC_eA']\n",
0121     "prod_m = 'PP'"
0122    ]
0123   },
0124   {
0125    "cell_type": "code",
0126    "execution_count": 5,
0127    "metadata": {
0128     "collapsed": false
0129    },
0130    "outputs": [
0131     {
0132      "name": "stdout",
0133      "output_type": "stream",
0134      "text": [
0135       "Starting with  J_psi\n",
0136       " \t --  JLEIC\n",
0137       "PP\n",
0138       "here\n"
0139      ]
0140     }
0141    ],
0142    "source": [
0143     "temp_S = home_dir+'eSTARlight/production/templates/slight_template_'\n",
0144     "output_loc = home_dir+'eSTARlight/production/event_generation/'\n",
0145     "for key in particle_prod:\n",
0146     "    print('Starting with ', key)\n",
0147     "    for accel in accelerator_facility:\n",
0148     "        out_dir = output_loc+accel\n",
0149     "        print(' \\t -- ',accel)\n",
0150     "        if os.path.isdir(out_dir) is False:\n",
0151     "            os.system('mkdir '+out_dir)\n",
0152     "        make_input_file(temp_S+accel+'.in',particle_prod[key],prod_m)\n",
0153     "        run_prepared_sim(out_dir+'/'+key+'_'+prod_m)"
0154    ]
0155   },
0156   {
0157    "cell_type": "code",
0158    "execution_count": null,
0159    "metadata": {
0160     "collapsed": true
0161    },
0162    "outputs": [],
0163    "source": []
0164   },
0165   {
0166    "cell_type": "code",
0167    "execution_count": null,
0168    "metadata": {
0169     "collapsed": false
0170    },
0171    "outputs": [],
0172    "source": []
0173   },
0174   {
0175    "cell_type": "code",
0176    "execution_count": null,
0177    "metadata": {
0178     "collapsed": false
0179    },
0180    "outputs": [],
0181    "source": []
0182   },
0183   {
0184    "cell_type": "code",
0185    "execution_count": null,
0186    "metadata": {
0187     "collapsed": false
0188    },
0189    "outputs": [],
0190    "source": []
0191   },
0192   {
0193    "cell_type": "code",
0194    "execution_count": null,
0195    "metadata": {
0196     "collapsed": true
0197    },
0198    "outputs": [],
0199    "source": []
0200   }
0201  ],
0202  "metadata": {
0203   "kernelspec": {
0204    "display_name": "Python 3",
0205    "language": "python",
0206    "name": "python3"
0207   },
0208   "language_info": {
0209    "codemirror_mode": {
0210     "name": "ipython",
0211     "version": 3
0212    },
0213    "file_extension": ".py",
0214    "mimetype": "text/x-python",
0215    "name": "python",
0216    "nbconvert_exporter": "python",
0217    "pygments_lexer": "ipython3",
0218    "version": "3.6.0"
0219   }
0220  },
0221  "nbformat": 4,
0222  "nbformat_minor": 2
0223 }