{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"collapsed":true},"cell_type":"markdown","source":"<h1>1.\tLoad Dataset using the  utility library  TrackML</h1>"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true,"collapsed":true,"_kg_hide-output":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nfrom trackml.dataset import load_event,load_dataset\nfrom trackml.randomize import shuffle_hits\nfrom trackml.score import score_event\nimport seaborn as sns\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d76a6282e0ff2e0b82573dd5cbb05badb9cefa09","collapsed":true},"cell_type":"code","source":"path_to_train='../input/train_1'\nevent_prefix= 'event000001000'\n# Load the event event000001000 dateset\nhits, cells, particles, truth = load_event(os.path.join(path_to_train, event_prefix))\n# Load the event detector dataset\ndetector=pd.read_csv('../input/detectors.csv')\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f44ab93ce57185ee52d053c09025d94bbc7651cd"},"cell_type":"markdown","source":"  <h2> 2. Understand Data with Descriptive Stats</h2>"},{"metadata":{"trusted":true,"_uuid":"fafc282f0cc989359aa19a8526c4edc2ae982bb2","collapsed":true},"cell_type":"code","source":"print(particles.head(10))\nprint(particles.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"68f93739b8a08bd74ee56e7788f7d0e87b821b30","collapsed":true},"cell_type":"code","source":"print(detector.head(10))\nprint(detector.dtypes)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b0d69498930a3fd604089f14edc9d9eb897855c1","collapsed":true},"cell_type":"code","source":"print(truth.head(10))\nprint(truth.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"841e12db1bbc75d9d24793106800d6d86a4ee9bc"},"cell_type":"markdown","source":"<h1>3. Visualization of Dataset</h1>"},{"metadata":{"_uuid":"f34a40782a018141b533e7edca71a0001ab0aea0"},"cell_type":"markdown","source":"<h3>A. Weights  of  the particles</h3>\nFrom the below  plot we can determine the particles are also having zero weight."},{"metadata":{"trusted":true,"_uuid":"37fdcf9328a6134e963a92e3ff987b882e4ceb2a","collapsed":true},"cell_type":"code","source":"plt.figure(figsize=(15,5))\nsns.regplot(x=truth.particle_id.values,y=truth.weight.values,fit_reg=False)\nplt.title('Distribution of particle_id w.r.t.its weights in \"event=000001000\"')\nplt.xlabel('particle_id')\nplt.ylabel('weights of the  corresponding particle')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"058f3365e37104eb7d2f2753954a6329b98d86be"},"cell_type":"markdown","source":"<h3>B. Hits by the particles</h3>\nFrom the below density plot we can determine the average hits are at <b>12</b>.  The lowest  hit value is <b>0</b>.  And masximum hits  value is <b>20.</b>"},{"metadata":{"trusted":true,"_uuid":"b59ce1af8e2728ca2c12e0d284234b7c59c7c379","collapsed":true},"cell_type":"code","source":"plt.figure(figsize=(15,5))\nsns.distplot(particles.nhits.values,bins=50,axlabel='Number of Hits by particle',\n            kde_kws={\"color\": \"m\", \"lw\": 3, \"label\": \"KDE\"},\n                 hist_kws={\"histtype\": \"step\", \"linewidth\": 3,\n                           \"alpha\": 1, \"color\": \"g\"})\nplt.title('Distribution of number of hits by particle for \"event=000001000\"')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bbf059341f33f9abe869b0d17d1e0a7505459348","collapsed":true},"cell_type":"code","source":"x=particles.nhits.values\ny=particles.particle_id.values\nplt.plot(y,x)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3bdccd221d1bac0ddd8afc74e32d71114b53a5b5"},"cell_type":"markdown","source":"<h1>Determine the track made by the particle before <b>hit.</b></h1>"},{"metadata":{"trusted":true,"_uuid":"a2a32aa58ecaed0ebede2f5faa4701eb4cc677a8","collapsed":true},"cell_type":"code","source":"class threedim(object):\n    def __init__(self, x, y, z):\n        self.x = x\n        self.y = y\n        self.z = z\n#Now to determine the track from initial position to hit\ndef threedimdistance(i, j):\n    deltaxsquared = (i.x - j.x) ** 2\n    deltaysquared = (i.y - j.y) ** 2\n    deltazsquared = (i.z - j.z) ** 2\nhit_id=19144\n#if ([hits['hit_id']==hit_id]):\nlineone=threedim(hits.x,hits.y,hits.z)\nlinetwo=threedim(particles.vx,particles.vy,particles.vz)\nthreedimdistance(lineone,linetwo)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"546e9778cbbe551d0638727f9e100d0d7379c63f","collapsed":true},"cell_type":"code","source":"table2list=[]#table2list contains the hit_id from hits\ntable1list=[]\ntable3list=[]#table2list contains the hit_id from hits\ntable1list=[]\n\nresult=[]\n#for hit_id in hits:\ntable2list.append(hits.hit_id)\n#for particle_id in particles:\ntable1list.append(particles.particle_id)\n#print(table1list)\nj=18728\ni=0\nfor index,item in enumerate(truth.particle_id.values):\n        table3list.append(truth.particle_id)\n        #i=truth.index(hit_id,i+1)\n    #if(i==table2list.any()):\n        #result.append(i)\n    #print(index,item)\n\nresult=[]\n#for hit_id in hits:\ntable2list.append(hits.hit_id)\n#for particle_id in particles:\ntable1list.append(particles.particle_id)\n#print(table1list)\nj=18728\ni=0\nfor index,item in enumerate(truth.particle_id.values):\n    while i < len(table1list):\n        item==table1list[i]\nindex +=1\n        #i=truth.index(hit_id,i+1)\n    #if(i==table2list.any()):\n        #result.append(i)\nprint(table3list)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3013624081f2478df0b67e9c4cdbf00df2c317c3","collapsed":true},"cell_type":"code","source":"#Now to determine the track from initial position to hit\n#def rotation_matrix(i,j,k):\n    #rot=np.matrix(a,b,c)\n    #return(rot)\na=np.matrix([[detector.rot_xu.data[0],detector.rot_xv,detector.rot_xw],[detector.rot_yu,detector.rot_yv,detector.rot_yw],[detector.rot_zu,detector.rot_zv,detector.rot_zw]])\n\n#rotation_matrix=np.matrix([a],[b],[c])","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}