{"cells":[{"metadata":{"_uuid":"829adf419f960ee30d878b78803953ec0d928481"},"cell_type":"markdown","source":"Quick plot for particle trajectories from training data."},{"metadata":{"trusted":true,"_uuid":"341e67b0796282fdc67ba99d040a070a475bf6ee","collapsed":true},"cell_type":"code","source":"from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\nimport plotly.offline as py\nimport plotly.graph_objs as go\nimport numpy as np\n\ninit_notebook_mode(connected=True) #do not miss this line","execution_count":2,"outputs":[]},{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","trusted":true,"collapsed":true},"cell_type":"code","source":"#Filename for event\nfn=\"train_1/event000001000\"\n\n#Row in particle file\nn=105\n\nA=np.loadtxt(\"../input/\"+fn+\"-truth.csv\",skiprows=1,delimiter=',')\nB=np.loadtxt(\"../input/\"+fn+\"-particles.csv\",skiprows=1,delimiter=',')\n\n#particle id to nth row in particle file.\npart_id = B[n,0]\n\n#Find hits from particle.\nhits_from_part = np.argwhere(A[:,1]==part_id)[:,0]\n\n#Print particle id and number of hits found.\nprint(\"PARTICLE ID:\")\nprint(int(part_id))\nprint(\"Num hits: \" + str(len(hits_from_part)))\nprint(\"\")\n#Get coordinates from hit-data.\ncoords = np.zeros((len(hits_from_part),3))\nfor i in range(0,len(hits_from_part)):\n\tcoords[i,:] = A[hits_from_part[i],2:5]\n\tprint(\"hit id: \"+str(int(A[hits_from_part[i],0]))+ \". Absolute momentum: \" + str(np.sqrt(np.sum(A[hits_from_part[i],5:8]**2))))\n\t\n#Sort coordinates by z-component.\t\nidx = np.argsort(coords[:,2])\ncoords=coords[idx]\n","execution_count":7,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true,"collapsed":true},"cell_type":"code","source":"trace = go.Scatter3d(\n    x=coords[:, 0], y=coords[:, 1], z=coords[:, 2],\n    marker=dict(\n        size=4,\n    ),\n    line=dict(\n        color='#1f77b4',\n        width=1\n    )\n)\n\ndata = [trace]\n\nlayout = dict(\n    width=500,\n    height=500,\n    autosize=False,\n    title='Trajectory',\n    titlefont = dict(size=8),\n    margin=dict(\n        l=0,\n        r=0,\n        b=0,\n        t=0\n    )\n)\n\nfig = dict(data=data, layout=layout)\npy.iplot(fig, filename='simple-3d')","execution_count":10,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"6bc13242a778155c6ea75103bb998790128b35b8"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.5","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}