Back to home page

EIC code displayed by LXR

 
 

    


Warning, /HEPMC_Merger/python/HEPMC_EVENT_MERGER.ipynb is written in an unsupported language. File is not indexed.

0001 {
0002  "cells": [
0003   {
0004    "cell_type": "code",
0005    "execution_count": 179,
0006    "metadata": {},
0007    "outputs": [],
0008    "source": [
0009     "import numpy as np\n",
0010     "import pandas as pd\n",
0011     "#from google.colab import files\n",
0012     "import matplotlib.pyplot as plt\n",
0013     "import random\n",
0014     "#need to install the pyhepmc module in order to import. python bindings to HEPMC\n",
0015     "#!pip install pyhepmc\n",
0016     "import pyhepmc as hep\n",
0017     "import random as rd\n",
0018     "#c_light  = 299.792458 mm/ns to get mm\n",
0019     "c_light  = 299.792458\n",
0020     "\n",
0021     "#Whether or not we move the signal event\n",
0022     "shift=True\n",
0023     "\n",
0024     "#Depending on the background type.\n",
0025     "#SR Synchrotron radiation will be set too false since there will be many individual photons\n",
0026     "#\n",
0027     "one_background_particle=True\n",
0028     "\n"
0029    ]
0030   },
0031   {
0032    "cell_type": "code",
0033    "execution_count": 180,
0034    "metadata": {},
0035    "outputs": [
0036     {
0037      "data": {
0038       "text/plain": [
0039        "\"name='Test_DIS_event.hepmc'\\nwith hep.WriterAsciiHepMC2(name) as f:\\n  for i in range(10):\\n    f.write_event(dis_event_cont[i])\\n\\nname='Test_Back_event.hepmc'\\nwith hep.WriterAsciiHepMC2(name) as f:\\n  for i in range(90,100):\\n    f.write_event(dis_event_cont[i])\""
0040       ]
0041      },
0042      "execution_count": 180,
0043      "metadata": {},
0044      "output_type": "execute_result"
0045     }
0046    ],
0047    "source": [
0048     "#container for signal events\n",
0049     "sig_cont=[]\n",
0050     "#container for background events\n",
0051     "back_cont=[]\n",
0052     "#container for combo events\n",
0053     "combo_cont=[]\n",
0054     "\n",
0055     "#opens up the signal file and extracts all individual events stores these events in sig_cont\n",
0056     "#with hep.open(\"pythia8NCDIS_10x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1_000.hepmc\") as f:\n",
0057     "with hep.open(\"Test_DIS_event.hepmc\") as f:\n",
0058     "    for event in f:\n",
0059     "        #print(event)\n",
0060     "        sig_cont.append(event)\n",
0061     "        pass\n",
0062     "\n",
0063     "#opens up the signal file and extracts all individual events. stores these events in back_cont\n",
0064     "#with hep.open(\"photon_event16_03_2023_02_05_02.hepmc\") as f:\n",
0065     "with hep.open(\"Test_Back_event.hepmc\") as f:\n",
0066     "    for event in f:\n",
0067     "        #print(event)\n",
0068     "        back_cont.append(event)\n",
0069     "        pass\n",
0070     "\n",
0071     "\n",
0072     "\n",
0073     "\n",
0074     "\n",
0075     "'''name='Test_DIS_event.hepmc'\n",
0076     "with hep.WriterAsciiHepMC2(name) as f:\n",
0077     "  for i in range(10):\n",
0078     "    f.write_event(dis_event_cont[i])\n",
0079     "\n",
0080     "name='Test_Back_event.hepmc'\n",
0081     "with hep.WriterAsciiHepMC2(name) as f:\n",
0082     "  for i in range(90,100):\n",
0083     "    f.write_event(dis_event_cont[i])'''"
0084    ]
0085   },
0086   {
0087    "cell_type": "code",
0088    "execution_count": 181,
0089    "metadata": {},
0090    "outputs": [
0091     {
0092      "name": "stdout",
0093      "output_type": "stream",
0094      "text": [
0095       "8\n",
0096       "8\n",
0097       "________________________________________________________________________\n",
0098       "GenEvent: #0\n",
0099       " Momentum units: GEV Position units: MM\n",
0100       " Entries in this event: 8 vertices, 14 particles, 0 weights.\n",
0101       " Position offset: 0, 0, 0, 0\n",
0102       "                                    GenParticle Legend\n",
0103       "         ID    PDG ID   ( px,       py,       pz,     E )   Stat ProdVtx\n",
0104       "________________________________________________________________________\n",
0105       "Vtx:     -1 stat:   0 (X,cT): -0.23 0.001 39 -32\n",
0106       " I:       1     2212 -2.50e+00,+3.87e-02,+1.00e+02,+1.00e+02   4     0\n",
0107       " O:       2       -2 -3.05e-01,+4.41e-01,+9.80e+00,+9.82e+00  61    -1\n",
0108       "          3     2212 -2.38e+00,-3.88e-01,+6.84e+01,+6.85e+01   1    -1\n",
0109       "          4        2 -5.84e-01,-3.06e-01,+2.28e+01,+2.28e+01  63    -1\n",
0110       "Vtx:     -2 stat:   0 (X,cT): -0.23 0.001 39 -32\n",
0111       " I:       5       11 +3.65e-03,+1.96e-04,-1.00e+01,+1.00e+01   4     0\n",
0112       " O:       6       11 +3.65e-03,+1.96e-04,-1.00e+01,+1.00e+01  21    -2\n",
0113       "Vtx:     -3 stat:   0 (X,cT): -0.23 0.001 39 -32\n",
0114       " I:       2       -2 -3.05e-01,+4.41e-01,+9.80e+00,+9.82e+00  61    -1\n",
0115       " O:       7       -2 -4.69e-01,+7.26e-03,+1.87e+01,+1.88e+01  21    -3\n",
0116       "Vtx:     -4 stat:   0 (X,cT): -0.23 0.001 39 -32\n",
0117       " I:       4        2 -5.84e-01,-3.06e-01,+2.28e+01,+2.28e+01  63    -1\n",
0118       " O:       8        2 -5.84e-01,-3.06e-01,+2.28e+01,+2.28e+01  71    -4\n",
0119       "Vtx:     -5 stat:   0 (X,cT): -0.23 0.001 39 -32\n",
0120       " I:       6       11 +3.65e-03,+1.96e-04,-1.00e+01,+1.00e+01  21    -2\n",
0121       "          7       -2 -4.69e-01,+7.26e-03,+1.87e+01,+1.88e+01  21    -3\n",
0122       " O:       9       -2 -1.43e+00,-3.92e-01,+1.87e+01,+1.88e+01  23    -5\n",
0123       "         10       11 +9.67e-01,+3.99e-01,-9.95e+00,+1.00e+01   1    -5\n",
0124       "Vtx:     -6 stat:   0 (X,cT): -0.23 0.001 39 -32\n",
0125       " I:      11       -2 -5.02e-01,+3.34e-01,+8.64e+00,+8.66e+00  62    -8\n",
0126       " O:      12       -2 -5.02e-01,+3.34e-01,+8.64e+00,+8.66e+00  71    -6\n",
0127       "Vtx:     -7 stat:   0 (X,cT): -0.23 0.001 39 -32\n",
0128       " I:       8        2 -5.84e-01,-3.06e-01,+2.28e+01,+2.28e+01  71    -4\n",
0129       "         12       -2 -5.02e-01,+3.34e-01,+8.64e+00,+8.66e+00  71    -6\n",
0130       " O:      13      211 -5.55e-01,-4.33e-01,+9.32e+00,+9.34e+00   1    -7\n",
0131       "         14     -211 -5.31e-01,+4.61e-01,+2.21e+01,+2.22e+01   1    -7\n",
0132       "Vtx:     -8 stat:   0 (X,cT): -0.23 0.001 39 -32\n",
0133       " I:       9       -2 -1.43e+00,-3.92e-01,+1.87e+01,+1.88e+01  23    -5\n",
0134       " O:      11       -2 -5.02e-01,+3.34e-01,+8.64e+00,+8.66e+00  62    -8\n",
0135       "________________________________________________________________________\n",
0136       "\n",
0137       "________________________________________________________________________\n",
0138       "GenEvent: #90\n",
0139       " Momentum units: GEV Position units: MM\n",
0140       " Entries in this event: 15 vertices, 32 particles, 0 weights.\n",
0141       " Position offset: 0, 0, 0, 0\n",
0142       "                                    GenParticle Legend\n",
0143       "         ID    PDG ID   ( px,       py,       pz,     E )   Stat ProdVtx\n",
0144       "________________________________________________________________________\n",
0145       "Vtx:     -1 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0146       " I:       1     2212 -2.53e+00,+2.08e-02,+1.00e+02,+1.00e+02   4     0\n",
0147       " O:       2       -1 +2.88e-01,+5.64e-01,+3.55e+00,+3.60e+00  61    -1\n",
0148       "          3        2 -2.16e+00,-2.87e-01,+6.71e+01,+6.71e+01  63    -1\n",
0149       "          4     2114 -1.29e+00,+2.06e-01,+2.97e+01,+2.97e+01   2    -1\n",
0150       "Vtx:     -2 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0151       " I:       5       11 +3.96e-04,-1.19e-03,-1.00e+01,+1.00e+01   4     0\n",
0152       " O:       6       11 +3.96e-04,-1.19e-03,-1.00e+01,+1.00e+01  21    -2\n",
0153       "Vtx:     -3 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0154       " I:       2       -1 +2.88e-01,+5.64e-01,+3.55e+00,+3.60e+00  61    -1\n",
0155       " O:       7       -1 -1.43e-01,+1.17e-03,+5.64e+00,+5.64e+00  21    -3\n",
0156       "Vtx:     -4 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0157       " I:       3        2 -2.16e+00,-2.87e-01,+6.71e+01,+6.71e+01  63    -1\n",
0158       " O:       8        2 -2.16e+00,-2.87e-01,+6.71e+01,+6.71e+01  71    -4\n",
0159       "Vtx:     -5 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0160       " I:       4     2114 -1.29e+00,+2.06e-01,+2.97e+01,+2.97e+01   2    -1\n",
0161       " O:       9     2112 -1.07e+00,+2.64e-01,+2.74e+01,+2.75e+01   1    -5\n",
0162       "         10      111 -2.30e-01,-5.76e-02,+2.25e+00,+2.26e+00   2    -5\n",
0163       "Vtx:     -6 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0164       " I:       6       11 +3.96e-04,-1.19e-03,-1.00e+01,+1.00e+01  21    -2\n",
0165       "          7       -1 -1.43e-01,+1.17e-03,+5.64e+00,+5.64e+00  21    -3\n",
0166       " O:      11       -1 -1.21e+00,+7.34e-01,+5.50e+00,+5.69e+00  23    -6\n",
0167       "         12       11 +1.07e+00,-7.34e-01,-9.86e+00,+9.95e+00   1    -6\n",
0168       "Vtx:     -7 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0169       " I:      13       -1 -1.48e-01,+8.34e-01,+3.15e+00,+3.28e+00  62   -10\n",
0170       " O:      14       -1 -1.48e-01,+8.34e-01,+3.15e+00,+3.28e+00  71    -7\n",
0171       "Vtx:     -8 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0172       " I:       8        2 -2.16e+00,-2.87e-01,+6.71e+01,+6.71e+01  71    -4\n",
0173       "         14       -1 -1.48e-01,+8.34e-01,+3.15e+00,+3.28e+00  71    -7\n",
0174       " O:      15      223 -1.56e+00,-2.15e-01,+3.68e+01,+3.68e+01   2    -8\n",
0175       "         16      211 +1.68e-01,+2.01e-01,+7.17e-01,+7.76e-01   1    -8\n",
0176       "         17      113 -7.48e-01,+6.36e-01,+2.20e+01,+2.20e+01   2    -8\n",
0177       "         18      223 -1.68e-01,-7.41e-02,+1.07e+01,+1.08e+01   2    -8\n",
0178       "Vtx:     -9 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0179       " I:      10      111 -2.30e-01,-5.76e-02,+2.25e+00,+2.26e+00   2    -5\n",
0180       " O:      19       22 -1.77e-01,+1.98e-02,+1.39e+00,+1.40e+00   1    -9\n",
0181       "         20       22 -5.26e-02,-7.74e-02,+8.56e-01,+8.61e-01   1    -9\n",
0182       "Vtx:    -10 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0183       " I:      11       -1 -1.21e+00,+7.34e-01,+5.50e+00,+5.69e+00  23    -6\n",
0184       " O:      13       -1 -1.48e-01,+8.34e-01,+3.15e+00,+3.28e+00  62   -10\n",
0185       "Vtx:    -11 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0186       " I:      15      223 -1.56e+00,-2.15e-01,+3.68e+01,+3.68e+01   2    -8\n",
0187       " O:      21      211 -3.13e-01,-6.05e-02,+5.29e+00,+5.30e+00   1   -11\n",
0188       "         22     -211 -4.83e-02,-8.45e-02,+5.05e+00,+5.06e+00   1   -11\n",
0189       "         23      111 -1.20e+00,-7.01e-02,+2.64e+01,+2.64e+01   2   -11\n",
0190       "Vtx:    -12 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0191       " I:      17      113 -7.48e-01,+6.36e-01,+2.20e+01,+2.20e+01   2    -8\n",
0192       " O:      24      211 -1.75e-01,+2.23e-01,+1.34e+01,+1.34e+01   1   -12\n",
0193       "         25     -211 -5.73e-01,+4.13e-01,+8.59e+00,+8.62e+00   1   -12\n",
0194       "Vtx:    -13 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0195       " I:      18      223 -1.68e-01,-7.41e-02,+1.07e+01,+1.08e+01   2    -8\n",
0196       " O:      26      211 -2.37e-01,-2.41e-01,+4.33e+00,+4.35e+00   1   -13\n",
0197       "         27     -211 -7.32e-02,+4.64e-02,+4.10e+00,+4.11e+00   1   -13\n",
0198       "         28      111 +1.42e-01,+1.20e-01,+2.29e+00,+2.31e+00   2   -13\n",
0199       "Vtx:    -14 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0200       " I:      23      111 -1.20e+00,-7.01e-02,+2.64e+01,+2.64e+01   2   -11\n",
0201       " O:      29       22 -7.41e-01,+2.22e-02,+1.61e+01,+1.61e+01   1   -14\n",
0202       "         30       22 -4.56e-01,-9.23e-02,+1.03e+01,+1.03e+01   1   -14\n",
0203       "Vtx:    -15 stat:   0 (X,cT): 0.1 0.0024 81 -87\n",
0204       " I:      28      111 +1.42e-01,+1.20e-01,+2.29e+00,+2.31e+00   2   -13\n",
0205       " O:      31       22 +1.61e-01,+1.10e-01,+1.71e+00,+1.72e+00   1   -15\n",
0206       "         32       22 -1.91e-02,+1.02e-02,+5.81e-01,+5.81e-01   1   -15\n",
0207       "________________________________________________________________________\n",
0208       "\n",
0209       "________________________________________________________________________\n",
0210       "GenEvent: #0\n",
0211       " Momentum units: GEV Position units: MM\n",
0212       " Entries in this event: 23 vertices, 46 particles, 0 weights.\n",
0213       " Position offset: 0, 0, 0, 0\n",
0214       "                                    GenParticle Legend\n",
0215       "         ID    PDG ID   ( px,       py,       pz,     E )   Stat ProdVtx\n",
0216       "________________________________________________________________________\n",
0217       "Vtx:     -1 stat:   0 (X,cT): -0.23 0.001 39 3.7e+05\n",
0218       " I:      13     2212 -2.50e+00,+3.87e-02,+1.00e+02,+1.00e+02   4     0\n",
0219       " O:       1       -2 -3.05e-01,+4.41e-01,+9.80e+00,+9.82e+00  61    -1\n",
0220       "          2     2212 -2.38e+00,-3.88e-01,+6.84e+01,+6.85e+01   1    -1\n",
0221       "          3        2 -5.84e-01,-3.06e-01,+2.28e+01,+2.28e+01  63    -1\n",
0222       "Vtx:     -2 stat:   0 (X,cT): -0.23 0.001 39 3.7e+05\n",
0223       " I:      14       11 +3.65e-03,+1.96e-04,-1.00e+01,+1.00e+01   4     0\n",
0224       " O:       4       11 +3.65e-03,+1.96e-04,-1.00e+01,+1.00e+01  21    -2\n",
0225       "Vtx:     -3 stat:   0 (X,cT): -0.23 0.001 39 3.7e+05\n",
0226       " I:       1       -2 -3.05e-01,+4.41e-01,+9.80e+00,+9.82e+00  61    -1\n",
0227       " O:       5       -2 -4.69e-01,+7.26e-03,+1.87e+01,+1.88e+01  21    -3\n",
0228       "Vtx:     -4 stat:   0 (X,cT): -0.23 0.001 39 3.7e+05\n",
0229       " I:       3        2 -5.84e-01,-3.06e-01,+2.28e+01,+2.28e+01  63    -1\n",
0230       " O:       6        2 -5.84e-01,-3.06e-01,+2.28e+01,+2.28e+01  71    -4\n",
0231       "Vtx:     -5 stat:   0 (X,cT): -0.23 0.001 39 3.7e+05\n",
0232       " I:       4       11 +3.65e-03,+1.96e-04,-1.00e+01,+1.00e+01  21    -2\n",
0233       "          5       -2 -4.69e-01,+7.26e-03,+1.87e+01,+1.88e+01  21    -3\n",
0234       " O:       7       -2 -1.43e+00,-3.92e-01,+1.87e+01,+1.88e+01  23    -5\n",
0235       "          8       11 +9.67e-01,+3.99e-01,-9.95e+00,+1.00e+01   1    -5\n",
0236       "Vtx:     -6 stat:   0 (X,cT): -0.23 0.001 39 3.7e+05\n",
0237       " I:       9       -2 -5.02e-01,+3.34e-01,+8.64e+00,+8.66e+00  62    -8\n",
0238       " O:      10       -2 -5.02e-01,+3.34e-01,+8.64e+00,+8.66e+00  71    -6\n",
0239       "Vtx:     -7 stat:   0 (X,cT): -0.23 0.001 39 3.7e+05\n",
0240       " I:       6        2 -5.84e-01,-3.06e-01,+2.28e+01,+2.28e+01  71    -4\n",
0241       "         10       -2 -5.02e-01,+3.34e-01,+8.64e+00,+8.66e+00  71    -6\n",
0242       " O:      11      211 -5.55e-01,-4.33e-01,+9.32e+00,+9.34e+00   1    -7\n",
0243       "         12     -211 -5.31e-01,+4.61e-01,+2.21e+01,+2.22e+01   1    -7\n",
0244       "Vtx:     -8 stat:   0 (X,cT): -0.23 0.001 39 3.7e+05\n",
0245       " I:       7       -2 -1.43e+00,-3.92e-01,+1.87e+01,+1.88e+01  23    -5\n",
0246       " O:       9       -2 -5.02e-01,+3.34e-01,+8.64e+00,+8.66e+00  62    -8\n",
0247       "Vtx:     -9 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0248       " I:      45     2212 -2.53e+00,+2.08e-02,+1.00e+02,+1.00e+02   4     0\n",
0249       " O:      15       -1 +2.88e-01,+5.64e-01,+3.55e+00,+3.60e+00  61    -9\n",
0250       "         16        2 -2.16e+00,-2.87e-01,+6.71e+01,+6.71e+01  63    -9\n",
0251       "         17     2114 -1.29e+00,+2.06e-01,+2.97e+01,+2.97e+01   2    -9\n",
0252       "Vtx:    -10 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0253       " I:      46       11 +3.96e-04,-1.19e-03,-1.00e+01,+1.00e+01   4     0\n",
0254       " O:      18       11 +3.96e-04,-1.19e-03,-1.00e+01,+1.00e+01  21   -10\n",
0255       "Vtx:    -11 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0256       " I:      15       -1 +2.88e-01,+5.64e-01,+3.55e+00,+3.60e+00  61    -9\n",
0257       " O:      19       -1 -1.43e-01,+1.17e-03,+5.64e+00,+5.64e+00  21   -11\n",
0258       "Vtx:    -12 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0259       " I:      16        2 -2.16e+00,-2.87e-01,+6.71e+01,+6.71e+01  63    -9\n",
0260       " O:      20        2 -2.16e+00,-2.87e-01,+6.71e+01,+6.71e+01  71   -12\n",
0261       "Vtx:    -13 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0262       " I:      17     2114 -1.29e+00,+2.06e-01,+2.97e+01,+2.97e+01   2    -9\n",
0263       " O:      21     2112 -1.07e+00,+2.64e-01,+2.74e+01,+2.75e+01   1   -13\n",
0264       "         22      111 -2.30e-01,-5.76e-02,+2.25e+00,+2.26e+00   2   -13\n",
0265       "Vtx:    -14 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0266       " I:      18       11 +3.96e-04,-1.19e-03,-1.00e+01,+1.00e+01  21   -10\n",
0267       "         19       -1 -1.43e-01,+1.17e-03,+5.64e+00,+5.64e+00  21   -11\n",
0268       " O:      23       -1 -1.21e+00,+7.34e-01,+5.50e+00,+5.69e+00  23   -14\n",
0269       "         24       11 +1.07e+00,-7.34e-01,-9.86e+00,+9.95e+00   1   -14\n",
0270       "Vtx:    -15 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0271       " I:      25       -1 -1.48e-01,+8.34e-01,+3.15e+00,+3.28e+00  62   -18\n",
0272       " O:      26       -1 -1.48e-01,+8.34e-01,+3.15e+00,+3.28e+00  71   -15\n",
0273       "Vtx:    -16 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0274       " I:      20        2 -2.16e+00,-2.87e-01,+6.71e+01,+6.71e+01  71   -12\n",
0275       "         26       -1 -1.48e-01,+8.34e-01,+3.15e+00,+3.28e+00  71   -15\n",
0276       " O:      27      223 -1.56e+00,-2.15e-01,+3.68e+01,+3.68e+01   2   -16\n",
0277       "         28      211 +1.68e-01,+2.01e-01,+7.17e-01,+7.76e-01   1   -16\n",
0278       "         29      113 -7.48e-01,+6.36e-01,+2.20e+01,+2.20e+01   2   -16\n",
0279       "         30      223 -1.68e-01,-7.41e-02,+1.07e+01,+1.08e+01   2   -16\n",
0280       "Vtx:    -17 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0281       " I:      22      111 -2.30e-01,-5.76e-02,+2.25e+00,+2.26e+00   2   -13\n",
0282       " O:      31       22 -1.77e-01,+1.98e-02,+1.39e+00,+1.40e+00   1   -17\n",
0283       "         32       22 -5.26e-02,-7.74e-02,+8.56e-01,+8.61e-01   1   -17\n",
0284       "Vtx:    -18 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0285       " I:      23       -1 -1.21e+00,+7.34e-01,+5.50e+00,+5.69e+00  23   -14\n",
0286       " O:      25       -1 -1.48e-01,+8.34e-01,+3.15e+00,+3.28e+00  62   -18\n",
0287       "Vtx:    -19 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0288       " I:      27      223 -1.56e+00,-2.15e-01,+3.68e+01,+3.68e+01   2   -16\n",
0289       " O:      33      211 -3.13e-01,-6.05e-02,+5.29e+00,+5.30e+00   1   -19\n",
0290       "         34     -211 -4.83e-02,-8.45e-02,+5.05e+00,+5.06e+00   1   -19\n",
0291       "         35      111 -1.20e+00,-7.01e-02,+2.64e+01,+2.64e+01   2   -19\n",
0292       "Vtx:    -20 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0293       " I:      29      113 -7.48e-01,+6.36e-01,+2.20e+01,+2.20e+01   2   -16\n",
0294       " O:      36      211 -1.75e-01,+2.23e-01,+1.34e+01,+1.34e+01   1   -20\n",
0295       "         37     -211 -5.73e-01,+4.13e-01,+8.59e+00,+8.62e+00   1   -20\n",
0296       "Vtx:    -21 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0297       " I:      30      223 -1.68e-01,-7.41e-02,+1.07e+01,+1.08e+01   2   -16\n",
0298       " O:      38      211 -2.37e-01,-2.41e-01,+4.33e+00,+4.35e+00   1   -21\n",
0299       "         39     -211 -7.32e-02,+4.64e-02,+4.10e+00,+4.11e+00   1   -21\n",
0300       "         40      111 +1.42e-01,+1.20e-01,+2.29e+00,+2.31e+00   2   -21\n",
0301       "Vtx:    -22 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0302       " I:      35      111 -1.20e+00,-7.01e-02,+2.64e+01,+2.64e+01   2   -19\n",
0303       " O:      41       22 -7.41e-01,+2.22e-02,+1.61e+01,+1.61e+01   1   -22\n",
0304       "         42       22 -4.56e-01,-9.23e-02,+1.03e+01,+1.03e+01   1   -22\n",
0305       "Vtx:    -23 stat:   0 (X,cT): 0.1 0.0024 81 8.9e+04\n",
0306       " I:      40      111 +1.42e-01,+1.20e-01,+2.29e+00,+2.31e+00   2   -21\n",
0307       " O:      43       22 +1.61e-01,+1.10e-01,+1.71e+00,+1.72e+00   1   -23\n",
0308       "         44       22 -1.91e-02,+1.02e-02,+5.81e-01,+5.81e-01   1   -23\n",
0309       "________________________________________________________________________\n",
0310       "\n"
0311      ]
0312     }
0313    ],
0314    "source": [
0315     "\n",
0316     "\n",
0317     "\n",
0318     "for i in range(2):#len(sig_cont)):\n",
0319     "    combo_cont.append(hep.GenEvent(hep.Units.GEV, hep.Units.MM))\n",
0320     "    sig_particles=[]\n",
0321     "    sig_vertices=[]\n",
0322     "    sig_time_shift=c_light*(2000*rd.random())\n",
0323     "    #sig_vertices.append(hep.GenVertex(sig_cont[i].event_pos()))\n",
0324     "    \n",
0325     "    #Stores the vertices of the event inside a vertex container. These vertices are in increasing order so we can index them with [abs(vertex_id)-1]\n",
0326     "    for vertex in sig_cont[i].vertices:\n",
0327     "        position=vertex.position\n",
0328     "        #if we are shifting the event in time uses the random time generator and adds this time to the position four vector for the vertex\n",
0329     "        if shift:\n",
0330     "            position=position+hep.FourVector(x=0,y=0,z=0,t=sig_time_shift)\n",
0331     "        v1=hep.GenVertex(position)\n",
0332     "        sig_vertices.append(v1)\n",
0333     "    print(len(sig_vertices))\n",
0334     "    \n",
0335     "    #copies the particles and attaches them to their corresponding vertices\n",
0336     "    for particle in sig_cont[i].particles:\n",
0337     "        momentum=particle.momentum\n",
0338     "        status=particle.status\n",
0339     "        pid=particle.pid\n",
0340     "        \n",
0341     "        # hep.GenParticle(momentum(px,py,pz,e), pdgid, status)\n",
0342     "        p1 = hep.GenParticle(momentum,      pid,  status)\n",
0343     "        p1.generated_mass = particle.generated_mass\n",
0344     "        sig_particles.append(p1)\n",
0345     "        #since the beam particles do not have a production vertex they cannot be attached to a production vertex\n",
0346     "        if particle.production_vertex.id<0:\n",
0347     "            production_vertex=particle.production_vertex.id\n",
0348     "            sig_vertices[abs(production_vertex)-1].add_particle_out(p1)\n",
0349     "            combo_cont[i].add_particle(p1)\n",
0350     "        #Adds particles with an end vertex to their end vertices\n",
0351     "        if (particle.end_vertex):     \n",
0352     "            end_vertex=particle.end_vertex.id\n",
0353     "            #print(end_vertex)\n",
0354     "            sig_vertices[abs(end_vertex)-1].add_particle_in(p1)\n",
0355     "    #Adds the vertices with the attached particles to the event        \n",
0356     "    for vertex in sig_vertices:\n",
0357     "        combo_cont[i].add_vertex(vertex)\n",
0358     "\n",
0359     "    \n",
0360     "    \n",
0361     "    #Now we add in the background\n",
0362     "    back_particles=[]\n",
0363     "    back_vertices=[]\n",
0364     "    \n",
0365     "    #Standard use except for SR backgrounds. Will only shift the background event when this conditional is triggered.\n",
0366     "    if one_background_particle:\n",
0367     "        back_time_shift=c_light*(2000*rd.random())\n",
0368     "\n",
0369     "\n",
0370     "    for vertex in back_cont[i].vertices:\n",
0371     "        \n",
0372     "        position=vertex.position\n",
0373     "        #When the background event has many particles separated in time, like SR backgrounds, trigger this coniditional by changing the one_background_particle to False\n",
0374     "        if one_background_particle==False:\n",
0375     "            back_time_shift=c_light*(2000*rd.random())\n",
0376     "        position=position+hep.FourVector(x=0,y=0,z=0,t=back_time_shift)\n",
0377     "        v1=hep.GenVertex(position)\n",
0378     "        back_vertices.append(v1)\n",
0379     "    #print(len(back_vertices))\n",
0380     "    \n",
0381     "    #copies the particles and attaches them to their corresponding vertices\n",
0382     "    for particle in back_cont[i].particles:\n",
0383     "        momentum=particle.momentum\n",
0384     "        status=particle.status\n",
0385     "        pid=particle.pid\n",
0386     "        \n",
0387     "        # hep.GenParticle(momentum(px,py,pz,e), pdgid, status)\n",
0388     "        p1 = hep.GenParticle(momentum,      pid,  status)\n",
0389     "        p1.generated_mass = particle.generated_mass\n",
0390     "        back_particles.append(p1)\n",
0391     "        #since the beam particles do not have a production vertex they cannot be attached to a production vertex\n",
0392     "        if particle.production_vertex.id<0:\n",
0393     "            production_vertex=particle.production_vertex.id\n",
0394     "            back_vertices[abs(production_vertex)-1].add_particle_out(p1)\n",
0395     "            combo_cont[i].add_particle(p1)\n",
0396     "        #Adds particles with an end vertex to their end vertices\n",
0397     "        if (particle.end_vertex):     \n",
0398     "            end_vertex=particle.end_vertex.id\n",
0399     "            #print(end_vertex)\n",
0400     "            back_vertices[abs(end_vertex)-1].add_particle_in(p1)\n",
0401     "    #Adds the vertices with the attached particles to the event        \n",
0402     "    for vertex in back_vertices:\n",
0403     "        combo_cont[i].add_vertex(vertex)\n",
0404     "'''print(sig_cont[0])\n",
0405     "print(back_cont[0])\n",
0406     "print(combo_cont[0])'''\n",
0407     "\n",
0408     "\n",
0409     "\n",
0410     "\n",
0411     "\n"
0412    ]
0413   },
0414   {
0415    "cell_type": "code",
0416    "execution_count": 182,
0417    "metadata": {},
0418    "outputs": [
0419     {
0420      "name": "stdout",
0421      "output_type": "stream",
0422      "text": [
0423       "now = 2023-03-27 01:32:57.157333\n",
0424       "date and time = 27_03_2023_01_32_57\n"
0425      ]
0426     },
0427     {
0428      "name": "stderr",
0429      "output_type": "stream",
0430      "text": [
0431       "C:\\Users\\cello\\AppData\\Local\\Temp\\ipykernel_21648\\3086032701.py:16: VisibleDeprecationWarning: importing WriterAsciiHepMC2 from pyhepmc is deprecated, please import from pyhepmc.io\n",
0432       "  with hep.WriterAsciiHepMC2(name) as f:\n"
0433      ]
0434     }
0435    ],
0436    "source": [
0437     "from datetime import datetime\n",
0438     "\n",
0439     "# datetime object containing current date and time\n",
0440     "now = datetime.now()\n",
0441     " \n",
0442     "print(\"now =\", now)\n",
0443     "\n",
0444     "# dd/mm/YY H:M:S\n",
0445     "dt_string = now.strftime(\"%d_%m_%Y_%H_%M_%S\")\n",
0446     "print(\"date and time =\", dt_string)\t\n",
0447     "#name='combo_event{}.hepmc'.format(dt_string)\n",
0448     "\n",
0449     "name='Dis_1000_event{}.hepmc'.format(dt_string)\n",
0450     "\n",
0451     "\n",
0452     "with hep.WriterAsciiHepMC2(name) as f:\n",
0453     "  for i in combo_cont:\n",
0454     "    f.write_event(i)"
0455    ]
0456   },
0457   {
0458    "cell_type": "code",
0459    "execution_count": null,
0460    "metadata": {},
0461    "outputs": [],
0462    "source": []
0463   },
0464   {
0465    "cell_type": "code",
0466    "execution_count": null,
0467    "metadata": {},
0468    "outputs": [],
0469    "source": []
0470   },
0471   {
0472    "cell_type": "code",
0473    "execution_count": null,
0474    "metadata": {},
0475    "outputs": [],
0476    "source": []
0477   },
0478   {
0479    "cell_type": "code",
0480    "execution_count": null,
0481    "metadata": {},
0482    "outputs": [],
0483    "source": []
0484   }
0485  ],
0486  "metadata": {
0487   "kernelspec": {
0488    "display_name": "Python 3",
0489    "language": "python",
0490    "name": "python3"
0491   },
0492   "language_info": {
0493    "codemirror_mode": {
0494     "name": "ipython",
0495     "version": 3
0496    },
0497    "file_extension": ".py",
0498    "mimetype": "text/x-python",
0499    "name": "python",
0500    "nbconvert_exporter": "python",
0501    "pygments_lexer": "ipython3",
0502    "version": "3.8.5"
0503   },
0504   "orig_nbformat": 4,
0505   "vscode": {
0506    "interpreter": {
0507     "hash": "bbf70c6099e597fc29bbcfe8c2efbc253464c23ecea4e8348654f8eecfb85963"
0508    }
0509   }
0510  },
0511  "nbformat": 4,
0512  "nbformat_minor": 2
0513 }