Skip to content

Instantly share code, notes, and snippets.

@welschma
Created October 27, 2016 07:49
Show Gist options
  • Save welschma/07cc3d6e0d11ce13ff391237f63e6598 to your computer and use it in GitHub Desktop.
Save welschma/07cc3d6e0d11ce13ff391237f63e6598 to your computer and use it in GitHub Desktop.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Umsetzung Root->Numpy"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\n",
"from tree2array import ReadTTree"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pfade zu Root Trees"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"signal_dir1 = ['/storage/jbod/welsch/ntuples/ttHbb/Even/' + x for x in \n",
" os.listdir('/storage/jbod/welsch/ntuples/ttHbb/Even/')]\n",
"signal_dir2 = [ '/storage/jbod/welsch/ntuples/ttHbb/Odd/' + x for x in \n",
" os.listdir('/storage/jbod/welsch/ntuples/ttHbb/Odd/')]\n",
"signal_dir = signal_dir1 + signal_dir2\n",
"\n",
"background_dir1 = ['/storage/jbod/welsch/ntuples/ttbarSL/Even/' + x for x in \n",
" os.listdir('/storage/jbod/welsch/ntuples/ttbarSL/Even/')]\n",
"background_dir2 = ['/storage/jbod/welsch/ntuples/ttbarSL/Odd/' + x for x in \n",
" os.listdir('/storage/jbod/welsch/ntuples/ttbarSL/Odd/')]\n",
"background_dir = background_dir1 + background_dir2\n",
"\n",
"treename = 'MVATree'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Wandle Dateien um"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"convert= ReadTTree(signal_dir, background_dir,treename, read_new = False)\n",
"array = convert.get_array_include('testbranches2.txt', 'UCIlikedata_2', \n",
" category='all')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0. -0.77377683 -0.93944979 -0.90936399 -1.39126837 0.58802342\n",
" -0.77298152 1.18897867 -0.61258119 0.9871887 1.08780718 0.24216792\n",
" 0.84163421 -0.13825552 -0.79785258 -2.04607296 0.39207008 0.27452457\n",
" 1.06821191 -0.61810285 -0.17287344 0. 0. 0.93986824\n",
" -0.30467564 -2.0600799 -0.91354035 -0.21903954 -0.58481437 -0.70923758\n",
" 1.47277915 -0.77878302 -0.82648003 -0.2749474 -0.24532947 -1.56962574\n",
" -1.04367363 -0.43350819 -2.11030293 -0.42432666 -1.4390775 1.62937534\n",
" -1.10555732 -0.69825202 -0.83134842 -0.53475606 -0.77014762]\n"
]
}
],
"source": [
"print(array[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment