{"cells":[{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","trusted":false},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":4,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":false,"collapsed":true},"cell_type":"code","source":"import matplotlib\nimport matplotlib.pyplot as plt\n%matplotlib inline \n\n#from trackml.dataset import load_event, load_dataset","execution_count":3,"outputs":[]},{"metadata":{"_cell_guid":"f0f7ba35-33a2-43b4-9d35-f0c46eaf54d3","_uuid":"49aac99deda97c8ecf62ee9561461995fc3a3de3","trusted":false},"cell_type":"code","source":"hits = pd.read_csv('../input/train_1/event000001000-hits.csv')  \nhits.head()\n","execution_count":5,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"648e6038c340a023aff181692fc21d0a72184dfb"},"cell_type":"markdown","source":"Coordinates are in mm and momentum in MeV/c"},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"601ec71eb9dbba407ad5b606c78ccfa2f8f9c0cc"},"cell_type":"code","source":"def display_detector_r_z_view():\n    x_coord = hits['x'].values\n    y_coord = hits['y'].values\n    z_coord = hits['z'].values\n    radius = np.sqrt(x_coord**2 + y_coord**2)\n    \n    font = {'family': 'serif',\n        'color':  'darkred',\n        'weight': 'normal',\n        'size': 26,\n        }\n    plt.figure(figsize=(15,12))\n    plt.scatter(z_coord, radius)\n    plt.ylabel('r [mm]')\n    plt.xlabel('z [mm]')\n    plt.text(-2500, 900, '16', fontdict=font)\n    plt.text(0,     900, '17', fontdict=font)\n    plt.text(2500,  900, '18', fontdict=font)\n    plt.text(-2500, 500, '12', fontdict=font)\n    plt.text(0,     500, '13', fontdict=font)\n    plt.text(2500,  500, '14', fontdict=font)\n    plt.text(-1100, 100, '7', fontdict=font)\n    plt.text(0,     110, '8', fontdict=font)\n    plt.text(1000,  100, '9', fontdict=font)\n\n    plt.show()","execution_count":6,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"64c5457743e5b9d578c514012a3549788ef351e2"},"cell_type":"code","source":"# show the volume_id\ndisplay_detector_r_z_view()","execution_count":8,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"071827241dd671702cf477e977b61b02490b4d4b"},"cell_type":"code","source":"def plot_volume(vol_id, view='yx'):\n    x_coord = hits[(hits['volume_id']==vol_id)]['x'].values\n    print('length of x_coord: ', len(x_coord)) \n    y_coord = hits[(hits['volume_id']==vol_id)]['y'].values\n    print('length of y_coord: ', len(y_coord)) \n    z_coord = hits[(hits['volume_id']==vol_id)]['z'].values\n    print('length of y_coord: ', len(z_coord)) \n    if view == 'yx':\n        plt.figure(figsize=(15,12))\n        plt.scatter(x_coord, y_coord)\n        plt.ylabel('y [mm]')\n        plt.xlabel('x [mm]')\n        plt.title('Volume_id='+str(vol_id))\n        plt.show()\n    if view == 'yz':\n        plt.figure(figsize=(15,12))\n        plt.scatter(z_coord, y_coord)\n        plt.ylabel('y [mm]')\n        plt.xlabel('z [mm]')\n        plt.title('Volume_id='+str(vol_id))\n        plt.show()\n    ","execution_count":9,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"deee9ad3287b021e9bbb3dd7bd2934f2714ebb5b"},"cell_type":"code","source":"def plot_volume_and_layer(vol_id, layer_id, view='yx'):\n    x_coord = hits[(hits['volume_id']==vol_id) & (hits['layer_id']==layer_id)]['x'].values\n    print('length of x_coord: ', len(x_coord)) \n    y_coord = hits[(hits['volume_id']==vol_id) & (hits['layer_id']==layer_id)]['y'].values\n    print('length of y_coord: ', len(y_coord)) \n    z_coord = hits[(hits['volume_id']==vol_id) & (hits['layer_id']==layer_id)]['z'].values\n    print('length of y_coord: ', len(z_coord)) \n    if view == 'yx':\n        plt.figure(figsize=(15,12))\n        plt.scatter(x_coord, y_coord)\n        plt.ylabel('y [mm]')\n        plt.xlabel('x [mm]')\n        plt.title('Volume_id='+str(vol_id)+'_layer_'+str(layer_id))\n        plt.show()\n    if view == 'yz':\n        plt.figure(figsize=(15,12))\n        plt.scatter(z_coord, y_coord)\n        plt.ylabel('y [mm]')\n        plt.xlabel('z [mm]')\n        plt.title('Volume_id='+str(vol_id)+'_layer_'+str(layer_id))\n        plt.show()","execution_count":10,"outputs":[]},{"metadata":{"_uuid":"88d215b99800422da55298329eead2e4c879b421"},"cell_type":"markdown","source":"The two functions defined above allow for a bit more detailed view of the detector; **plot_volume**  allows you to select the volume id and you can displays two views: \ntransverse: \"yx\" and longitudinal: \"yz\"\nWith **plot_volume_and_layer** you can include the layer_id in your choice. The display is also possible in two views."},{"metadata":{"trusted":true,"_uuid":"7c5a30f1f96463527ba47cb4b11922e4d8e86716"},"cell_type":"code","source":"plot_volume(8, \"yx\")","execution_count":11,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3b66d16cba4aabff52b36e96bb030838f834c0a1"},"cell_type":"code","source":"# The layer ids listed in this dataset are:\nlayers = hits['layer_id'].unique()\nprint('Layer ids: ', layers)","execution_count":12,"outputs":[]},{"metadata":{"_uuid":"2754693ed49fdf45538d346c19e02e65d0bc9597"},"cell_type":"markdown","source":"The layers of all volumes are labelled from the inside out; volume 9 has its first layer (2) at z~600 mm, its last layer (14) at z~1500 mm Similar labelling is used for the 'barrel' detectors."},{"metadata":{"trusted":true,"_uuid":"856bd46da65516e4f2e10c31ed35015edaa74cf8"},"cell_type":"code","source":"plot_volume_and_layer(9, 2, 'yz')","execution_count":13,"outputs":[]},{"metadata":{"_uuid":"6b02419f2fc29b2d91bffc09c861b2380b1e5409"},"cell_type":"markdown","source":"This figure is a bit confusing, it implies that the 'disc' detectors have four elements in each layer. Or this could be an artifact of the hit coordinate algorithm."},{"metadata":{"_uuid":"0d9b992268b049c980526bfa1f3fb7aeb2337842"},"cell_type":"markdown","source":"From this first look at the data, it is clear that even though the hits appear to be listed by volume_id and layer_id, all memory of the tracks has been removed from the data set. As stated by the organizers."},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"c06e01652c8cecf8fcbc391d4442d4a0e2db2aac"},"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}