Back to home page

EIC code displayed by LXR

 
 

    


Warning, /estarlight/production/accel_x_secs/x_section_calculations.ipynb is written in an unsupported language. File is not indexed.

0001 {
0002  "cells": [
0003   {
0004    "cell_type": "markdown",
0005    "metadata": {},
0006    "source": [
0007     "## Particle cross-section studies\n",
0008     "This notebook \"automates\" the procedure used to obtain particle cross-sections for electro- and photo-production at the different colliders. This works for both _ep_ and _eA_, where _A_ is the corresponding heavy-ion target at the different colliders. \n",
0009     "The colliders are defined as follows:\n",
0010     "- eRHIC: 18 GeV electrons on 275 GeV protons or 100 GeV/n Gold\n",
0011     "- JLEIC: 10 GeV electrons on 100 GeV protons or 40 GeV/n Lead\n",
0012     "- LHeC: 60 GeV electrons  on 7 TeV protons or 2.8 TeV/n Lead\n",
0013     "- CEBAF: Fixed target exepriment, 12 GeV electrons on protons or Lead\n",
0014     "- HERA: 27.5 GeV electrons on protons\n",
0015     "\n",
0016     "First we load the relevant modules"
0017    ]
0018   },
0019   {
0020    "cell_type": "code",
0021    "execution_count": 1,
0022    "metadata": {
0023     "collapsed": true
0024    },
0025    "outputs": [],
0026    "source": [
0027     "import itertools\n",
0028     "import sys, string, os\n",
0029     "from math import log10, floor"
0030    ]
0031   },
0032   {
0033    "cell_type": "markdown",
0034    "metadata": {},
0035    "source": [
0036     "### Global variables\n",
0037     "Define some global variables for the production, e.g. working directory, particle id's and associated names, units used for decoding the log files, etc.\n",
0038     "\n",
0039     "*Note*: It is assumed that home_dir contains eSTARlight and the compiled executable e_starlight"
0040    ]
0041   },
0042   {
0043    "cell_type": "code",
0044    "execution_count": 2,
0045    "metadata": {
0046     "collapsed": true
0047    },
0048    "outputs": [],
0049    "source": [
0050     "home_dir = '/Users/michaellomnitz/Documents/install_test/'\n",
0051     "particle_id = [ 113, 333, 443011, 444011, 553011]\n",
0052     "#particle_id = [ 444011, 553011]\n",
0053     "particle_name = ['rho', 'phi', 'J_psi', 'Psi_2s', 'Upsilon_1s']\n",
0054     "#particle_name = [ 'Psi_2s', 'Upsilon_1s']\n",
0055     "unit_decode = { 'mb.':-3, 'microb.':-6, 'nanob.':-9, 'picob.':-12, 'femtob.':-15}\n",
0056     "unit_latex = { 'mb.':'mb', 'microb.':'$\\mu$b', 'nanob.':'nb', 'picob.':'pb', 'femtob.':'fb'}\n",
0057     "event_unit = { 3:'K', 6:'M', 9:'G'}\n",
0058     "n_events_from_units = {'mb.':'T', 'microb.':'G', 'nanob.':'M', 'picob.':'K', 'femtob.':''} #considering 1 fb^-1"
0059    ]
0060   },
0061   {
0062    "cell_type": "markdown",
0063    "metadata": {},
0064    "source": [
0065     "### Function definitions\n",
0066     "Some simple funcitons used for utilies and run workflow:\n",
0067     "- round_sig: Round a number to a given number of significant figures\n",
0068     "- make_input_file: Takes template input file for _eSTARlight_ and sets the desired $Q^2$ range and target nucleii.\n",
0069     "- run_accel_study: Iterates over particle species for both photo-($Q^2$ < 1 \\rm{GeV}$) and electro-(1< $Q^2$ < 100 \\rm{GeV}$ and calls _eSTARlight_. The log file is then saved to desired location\n",
0070     "- decode_string: Takes relevant line from _eSTARlight_ and extract the cross-section and units (i.e. reads \"gamma+X --> VM+X 204.161 microb.\" and returns $204.161\\times10^{-6}$)\n",
0071     "- find_x_section: Iterates over produced log files and extracts cross-sections\n",
0072     "- make_table_line: Prints the table as would be formatted for a paper table table"
0073    ]
0074   },
0075   {
0076    "cell_type": "code",
0077    "execution_count": 3,
0078    "metadata": {
0079     "collapsed": false
0080    },
0081    "outputs": [],
0082    "source": [
0083     "\n",
0084     "def round_sig(x, sig=2):\n",
0085     "    if x < 1e-6:\n",
0086     "        return 0\n",
0087     "    return round(x, sig-int(floor(log10(abs(x))))-1)\n",
0088     "\n",
0089     "def make_input_file(prod_no,prod_mech, template_loc):\n",
0090     "    #load template\n",
0091     "    with open(template_loc,'r') as f:\n",
0092     "        data = f.readlines()\n",
0093     "    # --  Set prodiction id\n",
0094     "    data[29] = 'PROD_PID = '+str(particle_id[prod_no])+'   #Channel of interest; this is '+str(particle_name[prod_no])+'\\n'\n",
0095     "    if prod_mech is 'PP':\n",
0096     "        data[33] = 'MIN_GAMMA_Q2 = 0. \\n'\n",
0097     "        data[34] = 'MAX_GAMMA_Q2 = 1.0 \\n'\n",
0098     "    if prod_mech is 'EP':\n",
0099     "        data[33] = 'MIN_GAMMA_Q2 = 1.0 \\n'\n",
0100     "        data[34] = 'MAX_GAMMA_Q2 = 100.0 \\n'\n",
0101     "    with open(home_dir+'slight.in','w') as f:\n",
0102     "        f.writelines(data)\n",
0103     "\n",
0104     "def run_accel_study(accel_name, pwd_to_template):\n",
0105     "    print(len(particle_id),' particles in study')\n",
0106     "    output_dir = home_dir+'eSTARlight/production/accel_x_secs/'+accel_name\n",
0107     "    if os.path.isdir(output_dir) is False:\n",
0108     "        os.makedirs(output_dir)\n",
0109     "        os.makedirs(output_dir+'/PP')\n",
0110     "        os.makedirs(output_dir+'/EP')\n",
0111     "    for idx,part in enumerate(particle_id):\n",
0112     "        make_input_file(idx,'PP',pwd_to_template)\n",
0113     "        os.chdir( home_dir )\n",
0114     "        os.system( home_dir+'e_starlight > log' )\n",
0115     "        os.rename(home_dir+'log',output_dir+'/PP/x_section_'+particle_name[idx]+'.txt')\n",
0116     "        #\n",
0117     "        #print('Finished with ',particle_name[idx],' photo-production')\n",
0118     "        make_input_file(idx,'EP',pwd_to_template)\n",
0119     "        os.chdir( home_dir )\n",
0120     "        os.system( home_dir+'e_starlight > log' )\n",
0121     "        os.rename(home_dir+'log',output_dir+'/EP/x_section_'+particle_name[idx]+'.txt')\n",
0122     "    \n",
0123     "def decode_string( line ):\n",
0124     "    space_pos = [pos for pos,char in enumerate(line) if char == ' ']\n",
0125     "    n_space = len(space_pos)\n",
0126     "    #print(line[space_pos[n_space-2]:space_pos[n_space-1]])\n",
0127     "    num = float(line[space_pos[n_space-2]:space_pos[n_space-1]])\n",
0128     "    num = round_sig(num,2)\n",
0129     "    units = line[space_pos[n_space-1]+1:-1]\n",
0130     "    return num,units\n",
0131     "    \n",
0132     "def find_x_section(accel_name, prod_mech, part_id):\n",
0133     "    file_loc = home_dir+'eSTARlight/production/accel_x_secs/'\n",
0134     "    file_loc = file_loc+accel_name+'/'+prod_mech+'/x_section_'+particle_name[part_id]+'.txt'\n",
0135     "    with open(file_loc,'r') as f:\n",
0136     "        data = f.readlines()\n",
0137     "    nline = 0\n",
0138     "    for i in range(len(data)):\n",
0139     "        if \"Total cross section\" in data[i]:\n",
0140     "            nline = i\n",
0141     "    x_sec, units = decode_string(data[nline])\n",
0142     "    return x_sec, units\n",
0143     "\n",
0144     "def make_table_line(collision_system, prod_mech, target_A):\n",
0145     "    particle_row = ''\n",
0146     "    x_sec_row = ' & '\n",
0147     "    rate_row = ''\n",
0148     "    for idx, a in enumerate(particle_name):\n",
0149     "        x_sec, units = find_x_section(collision_system, prod_mech, idx)\n",
0150     "        n_events = round(10*x_sec/target_A,2)\n",
0151     "        particle_row+=a+' & '\n",
0152     "        x_sec_row+='$'+str(x_sec)+'$ '+unit_latex[units]+' & '\n",
0153     "        rate_row+= str(n_events)+n_events_from_units[units]\n",
0154     "        if idx != len(particle_name)-1:\n",
0155     "            rate_row+=' & '\n",
0156     "        else:\n",
0157     "            rate_row+='\\\\\\\\'\n",
0158     "    return x_sec_row+rate_row"
0159    ]
0160   },
0161   {
0162    "cell_type": "markdown",
0163    "metadata": {},
0164    "source": [
0165     "### Run the study"
0166    ]
0167   },
0168   {
0169    "cell_type": "code",
0170    "execution_count": 4,
0171    "metadata": {
0172     "collapsed": false
0173    },
0174    "outputs": [
0175     {
0176      "name": "stdout",
0177      "output_type": "stream",
0178      "text": [
0179       " ----  JLEIC  ----  /Users/michaellomnitz/Documents/install_test/eSTARlight/production/templates/slight_template_JLEIC.in\n",
0180       "5  particles in study\n",
0181       " ----  eRHIC  ----  /Users/michaellomnitz/Documents/install_test/eSTARlight/production/templates/slight_template_eRHIC.in\n",
0182       "5  particles in study\n",
0183       " ----  LHeC  ----  /Users/michaellomnitz/Documents/install_test/eSTARlight/production/templates/slight_template_LHeC.in\n",
0184       "5  particles in study\n",
0185       " ----  JLEIC_eA  ----  /Users/michaellomnitz/Documents/install_test/eSTARlight/production/templates/slight_template_JLEIC_eA.in\n",
0186       "5  particles in study\n",
0187       " ----  eRHIC_eA  ----  /Users/michaellomnitz/Documents/install_test/eSTARlight/production/templates/slight_template_eRHIC_eA.in\n",
0188       "5  particles in study\n",
0189       " ----  LHeC_eA  ----  /Users/michaellomnitz/Documents/install_test/eSTARlight/production/templates/slight_template_LHeC_eA.in\n",
0190       "5  particles in study\n"
0191      ]
0192     }
0193    ],
0194    "source": [
0195     "detectors = ['JLEIC', 'eRHIC', 'LHeC','JLEIC_eA', 'eRHIC_eA', 'LHeC_eA']\n",
0196     "for det in detectors:\n",
0197     "    temlate_loc = home_dir+'eSTARlight/production/templates/slight_template_'+det+'.in'\n",
0198     "    print(' ---- ',det,' ---- ', temlate_loc)\n",
0199     "    run_accel_study(det,temlate_loc)\n"
0200    ]
0201   },
0202   {
0203    "cell_type": "markdown",
0204    "metadata": {},
0205    "source": [
0206     "## Make paper tables\n",
0207     "Using the previously defined tables we can now pepare the tables for the paper. Define the individual rows with their associated rows and the correct scaling for the heavy-ion targets.  The function _make_full_table_ builds the table out of the previous functions. "
0208    ]
0209   },
0210   {
0211    "cell_type": "code",
0212    "execution_count": 5,
0213    "metadata": {
0214     "collapsed": false
0215    },
0216    "outputs": [
0217     {
0218      "name": "stdout",
0219      "output_type": "stream",
0220      "text": [
0221       "eRHIC - $ep$ & $5.0$ $\\mu$b & $230.0$ nb & $8.5$ nb & $1.4$ nb & $14.0$ pb & 50.0G & 2300.0M & 85.0M & 14.0M & 140.0K\\\\\n",
0222       "eRHIC - $eA$ & $870.0$ $\\mu$b & $55.0$ $\\mu$b & $1.9$ $\\mu$b & $320.0$ nb & $1.2$ nb & 44.16G & 2.79G & 0.1G & 16.24M & 0.06M\\\\\n",
0223       "\\hline\n",
0224       "JLEIC - $ep$ & $3.7$ $\\mu$b & $160.0$ nb & $3.9$ nb & $600.0$ pb & $4.3$ pb & 37.0G & 1600.0M & 39.0M & 6000.0K & 43.0K\\\\\n",
0225       "JLEIC - $eA$ & $580.0$ $\\mu$b & $33.0$ $\\mu$b & $590.0$ nb & $82.0$ nb & $0$ fb & 27.88G & 1.59G & 28.37M & 3.94M & 0.0\\\\\n",
0226       "\\hline\n",
0227       "LHeC - $ep$ & $10.0$ $\\mu$b & $560.0$ nb & $47.0$ nb & $7.8$ nb & $120.0$ pb & 100.0G & 5600.0M & 470.0M & 78.0M & 1200.0K\\\\\n",
0228       "LHeC - $eA$ & $2.3$ mb & $170.0$ $\\mu$b & $15.0$ $\\mu$b & $2.9$ $\\mu$b & $41.0$ nb & 0.11T & 8.17G & 0.72G & 0.14G & 1.97M\\\\\n",
0229       "\\hline\n"
0230      ]
0231     }
0232    ],
0233    "source": [
0234     "_prod_rows = { 'eRHIC':['eRHIC - $ep$',1], 'eRHIC_eA':['eRHIC - $eA$',197],\n",
0235     "               'JLEIC':['JLEIC - $ep$',1], 'JLEIC_eA':['JLEIC - $eA$',208],\n",
0236     "               'LHeC' :['LHeC - $ep$',1],  'LHEC_eA' :['LHeC - $eA$',208],\n",
0237     "             }\n",
0238     "def make_full_table( prod_mech ):\n",
0239     "    for idx,key in enumerate(_prod_rows):\n",
0240     "        #print(idx,_prod_rows[key][0])\n",
0241     "        to_print = _prod_rows[key][0] + make_table_line(key,prod_mech,_prod_rows[key][1])\n",
0242     "        print( to_print )\n",
0243     "        if (idx+1)%2 == 0:\n",
0244     "            print('\\hline')\n",
0245     "make_full_table('PP') # > 1 GeV"
0246    ]
0247   },
0248   {
0249    "cell_type": "code",
0250    "execution_count": 6,
0251    "metadata": {
0252     "collapsed": false
0253    },
0254    "outputs": [
0255     {
0256      "name": "stdout",
0257      "output_type": "stream",
0258      "text": [
0259       "eRHIC - $ep$ & $14.0$ nb & $1.7$ nb & $580.0$ pb & $120.0$ pb & $2.4$ pb & 140.0M & 17.0M & 5800.0K & 1200.0K & 24.0K\\\\\n",
0260       "eRHIC - $eA$ & $730.0$ nb & $110.0$ nb & $79.0$ nb & $19.0$ nb & $200.0$ pb & 37.06M & 5.58M & 4.01M & 0.96M & 10.15K\\\\\n",
0261       "\\hline\n",
0262       "JLEIC - $ep$ & $10.0$ nb & $1.2$ nb & $270.0$ pb & $55.0$ pb & $790.0$ fb & 100.0M & 12.0M & 2700.0K & 550.0K & 7900.0\\\\\n",
0263       "JLEIC - $eA$ & $450.0$ nb & $67.0$ nb & $25.0$ nb & $5.1$ nb & $0$ fb & 21.63M & 3.22M & 1.2M & 0.25M & 0.0\\\\\n",
0264       "\\hline\n",
0265       "LHeC - $ep$ & $26.0$ nb & $3.7$ nb & $3.0$ nb & $630.0$ pb & $18.0$ pb & 260.0M & 37.0M & 30.0M & 6300.0K & 180.0K\\\\\n",
0266       "LHeC - $eA$ & $2.0$ $\\mu$b & $340.0$ nb & $570.0$ nb & $150.0$ nb & $5.3$ nb & 0.1G & 16.35M & 27.4M & 7.21M & 0.25M\\\\\n",
0267       "\\hline\n"
0268      ]
0269     }
0270    ],
0271    "source": [
0272     "make_full_table('EP') # < 1 GeV"
0273    ]
0274   },
0275   {
0276    "cell_type": "code",
0277    "execution_count": null,
0278    "metadata": {
0279     "collapsed": false
0280    },
0281    "outputs": [],
0282    "source": []
0283   },
0284   {
0285    "cell_type": "code",
0286    "execution_count": null,
0287    "metadata": {
0288     "collapsed": true
0289    },
0290    "outputs": [],
0291    "source": []
0292   },
0293   {
0294    "cell_type": "code",
0295    "execution_count": null,
0296    "metadata": {
0297     "collapsed": false
0298    },
0299    "outputs": [],
0300    "source": []
0301   },
0302   {
0303    "cell_type": "code",
0304    "execution_count": null,
0305    "metadata": {
0306     "collapsed": false
0307    },
0308    "outputs": [],
0309    "source": []
0310   },
0311   {
0312    "cell_type": "code",
0313    "execution_count": null,
0314    "metadata": {
0315     "collapsed": true
0316    },
0317    "outputs": [],
0318    "source": []
0319   }
0320  ],
0321  "metadata": {
0322   "kernelspec": {
0323    "display_name": "Python 3",
0324    "language": "python",
0325    "name": "python3"
0326   },
0327   "language_info": {
0328    "codemirror_mode": {
0329     "name": "ipython",
0330     "version": 3
0331    },
0332    "file_extension": ".py",
0333    "mimetype": "text/x-python",
0334    "name": "python",
0335    "nbconvert_exporter": "python",
0336    "pygments_lexer": "ipython3",
0337    "version": "3.6.0"
0338   }
0339  },
0340  "nbformat": 4,
0341  "nbformat_minor": 2
0342 }