from root_numpy import root2array, tree2array from root_numpy import testdata filename = testdata.get_filepath('test.root') # Convert a TTree in a ROOT file into a NumPy structured array arr = root2array(filename, 'tree') # The TTree name is always optional if there is only one TTree in the file # Or first get the TTree from the ROOT file import ROOT rfile = ROOT.TFile(filename) intree = rfile.Get('tree') # and convert the TTree into an array array = tree2array(intree)
def load(data): if isinstance(data, list): return [get_filepath(x) for x in data] return get_filepath(data)
from root_numpy import root2array, tree2array, testdata, array2root, array2tree import scipy as sp import matplotlib.pyplot as plt import numpy as np from numpy import array from keras.models import Sequential from keras.layers import Dense from keras.utils import plot_model from sklearn.model_selection import train_test_split from sklearn.metrics import roc_curve, auc import ROOT from ROOT import gROOT np.random.seed(7) #extract information from ROOT TTrees file = testdata.get_filepath('out_train_PM.root') Xtrain = root2array(file, 'tree_train', branches=[ 'pointing_angle_var', 'decay_length_var', 'Drecon_dca_var', 'trx_dca_var', 'pk_dca_var1', 'pk_dca_var2', 'dca_angle_var', 'paths_area_var', 'pk_p_frac_var' ]) # Ytrain = root2array(file, 'tree_train', branches='validation_var') Xtrain = Xtrain.view(np.float32).reshape(Xtrain.shape + (-1, )) Ytrain = Ytrain.view(np.int32).reshape(Ytrain.shape + (-1, )) Y_train = [0] Y_train = Y_train * len(Ytrain) for i in range(len(Y_train)): Y_train[i] = int(Ytrain[i][0])