{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Reading Online Data\n\nThe following example shows how to access hits in a ROOT file which is coming\nfrom the detector and written by the `JDataWriter` application.\n\nSuch a file is usually called \"KM3NET_00000001_00000002.root\", where the first\nnumber is the detector ID and the second the run number.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import km3io as ki\nfrom km3net_testdata import data_path" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Accessing the event tree\nJust pass a filename to the reader class and get access to the event tree\nwith:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "f = ki.OnlineReader(data_path(\"online/km3net_online.root\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that only some meta information is read into memory.\n\nPrinting it will simply tell you how many events it has found. Again, nothing\nelse is read yet:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(f.events)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's look at the hits data:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(f.events[0].snapshot_hits.tot)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "the resulting arrays are numpy arrays.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reading SummarySlices\nThe following example shows how to access summary slices, in particular the DOM\nIDs of the slice with the index 0:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "dom_ids = f.summaryslices.slices[0].dom_id\n\nprint(dom_ids)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The .dtype attribute (or in general, completion) is useful to find out\nmore about the field structure:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(f.summaryslices.headers.dtype)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To read the frame index:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(f.summaryslices.headers.frame_index)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The resulting array is a ChunkedArray which is an extended version of a\nnumpy array and behaves like one.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reading TimeSlices\nTo be continued.\n\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" } }, "nbformat": 4, "nbformat_minor": 0 }