def InputROOT_OutputTXT(infileROOT, ModelName): inputFile = read_file_name_root(infileROOT) ROOT_input = inputFile[2] Text_output = inputFile[0] + ".txt" # data = TFile.Open('/Users/leejunho/Desktop/git/PKUHEP/DNN/SSWW_split_input/result/for_DNN/TTTL_LL_230M_comparable.root') data = TFile.Open(ROOT_input) tree = data.Get('tree') ####################################### Input DATA Sets !!!!! lep1pt_ = tree2array(tree, branches='lep1pt') lep1eta_ = tree2array(tree, branches='lep1eta') lep1phi_ = tree2array(tree, branches='lep1phi') lep2pt_ = tree2array(tree, branches='lep2pt') lep2eta_ = tree2array(tree, branches='lep2eta') lep2phi_ = tree2array(tree, branches='lep2phi') jet1pt_ = tree2array(tree, branches='jet1pt') jet1eta_ = tree2array(tree, branches='jet1eta') jet1phi_ = tree2array(tree, branches='jet1phi') jet1M_ = tree2array(tree, branches='jet1M') jet2pt_ = tree2array(tree, branches='jet2pt') jet2eta_ = tree2array(tree, branches='jet2eta') jet2phi_ = tree2array(tree, branches='jet2phi') jet2M_ = tree2array(tree, branches='jet2M') MET_ = tree2array(tree, branches='MET') #lep1PID_ = tree2array(tree, branches='lep1PID') #lep2PID_ = tree2array(tree, branches='lep2PID') #Mjj_ = tree2array(tree, branches='Mjj') #dr_ll_jj_ = tree2array(tree, branches='dr_ll_jj') #dphijj_ = tree2array(tree, branches='dphijj') #zeppen_lep1_ = tree2array(tree, branches='zeppen_lep1') #zeppen_lep2_ = tree2array(tree, branches='zeppen_lep2') METphi_ = tree2array(tree, branches='METphi') #detajj_ = tree2array(tree, branches='detajj') #Mll_ = tree2array(tree, branches='Mll') #RpT_ = tree2array(tree, branches='RpT') ############################################################################################################### ##################################### Target DATA !!!!! LL_Helicity_ = tree2array(tree, branches='LL_Helicity') TTTL_Helicity_ = tree2array(tree, branches='TTTL_Helicity') #TL_Helicity_ = tree2array(tree, branches='TL_Helicity') #TT_Helicity_ = tree2array(tree, branches='TT_Helicity') ############################################################################################################### ENTRY = LL_Helicity_.size print "ENTRY :", ENTRY lep1pt = np.zeros(ENTRY) lep1eta = np.zeros(ENTRY) lep1phi = np.zeros(ENTRY) lep2pt = np.zeros(ENTRY) lep2eta = np.zeros(ENTRY) lep2phi = np.zeros(ENTRY) jet1pt = np.zeros(ENTRY) jet1eta = np.zeros(ENTRY) jet1phi = np.zeros(ENTRY) jet1M = np.zeros(ENTRY) jet2pt = np.zeros(ENTRY) jet2eta = np.zeros(ENTRY) jet2phi = np.zeros(ENTRY) jet2M = np.zeros(ENTRY) MET = np.zeros(ENTRY) #lep1PID = np.zeros(ENTRY) #lep2PID = np.zeros(ENTRY) #Mjj = np.zeros(ENTRY) #dr_ll_jj = np.zeros(ENTRY) #dphijj = np.zeros(ENTRY) #zeppen_lep1 = np.zeros(ENTRY) #zeppen_lep2 = np.zeros(ENTRY) METphi = np.zeros(ENTRY) #detajj = np.zeros(ENTRY) #Mll = np.zeros(ENTRY) #RpT = np.zeros(ENTRY) LL_Helicity = np.zeros(ENTRY) TTTL_Helicity = np.zeros(ENTRY) #TL_Helicity = np.zeros(ENTRY) #TT_Helicity = np.zeros(ENTRY) ############################################################################################################### for j1 in range(ENTRY): lep1pt[j1] = lep1pt_[j1] lep1eta[j1] = lep1eta_[j1] lep1phi[j1] = lep1phi_[j1] lep2pt[j1] = lep2pt_[j1] lep2eta[j1] = lep2eta_[j1] lep2phi[j1] = lep2phi_[j1] jet1pt[j1] = jet1pt_[j1] jet1eta[j1] = jet1eta_[j1] jet1phi[j1] = jet1phi_[j1] jet1M[j1] = jet1M_[j1] jet2pt[j1] = jet2pt_[j1] jet2eta[j1] = jet2eta_[j1] jet2phi[j1] = jet2phi_[j1] jet2M[j1] = jet2M_[j1] MET[j1] = MET_[j1] #lep1PID[j1] = lep1PID_[j1] #lep2PID[j1] = lep2PID_[j1] #Mjj[j1] = Mjj_[j1] #dr_ll_jj[j1] = dr_ll_jj_[j1] #dphijj[j1] = dphijj_[j1] #zeppen_lep1[j1] = zeppen_lep1_[j1] #zeppen_lep2[j1] = zeppen_lep2_[j1] METphi[j1] = METphi_[j1] #detajj[j1] = detajj_[j1] #Mll[j1] = Mll_[j1] #RpT[j1] = RpT_[j1] LL_Helicity[j1] = LL_Helicity_[j1] TTTL_Helicity[j1] = TTTL_Helicity_[j1] #TL_Helicity[j1] = TL_Helicity_[j1] #TT_Helicity[j1] = TT_Helicity_[j1] #ARRAY = np.stack((lep1pt, lep1eta, lep1phi, lep2pt, lep2eta, lep2phi, jet1pt, jet1eta, jet1phi, jet1M, jet2pt, jet2eta, jet2phi, jet2M, MET, lep1PID, lep2PID, Mjj, dr_ll_jj, dphijj, zeppen_lep1, zeppen_lep2, METphi, detajj, Mll, RpT)) #ARRAY = np.stack((lep1pt, lep1eta, lep2pt, lep2eta, jet1pt, jet1eta, jet2pt, jet2eta, MET, dr_ll_jj, dphijj, detajj, Mll)) ARRAY = np.stack( (lep1pt, lep1eta, lep1phi, lep2pt, lep2eta, lep2phi, jet1pt, jet1eta, jet1phi, jet1M, jet2pt, jet2eta, jet2phi, jet2M, MET, METphi)) TARGET = np.stack((LL_Helicity, TTTL_Helicity)) #TARGET = np.stack((LL_Helicity, TL_Helicity, TT_Helicity)) ARRAY = ARRAY.T TARGET = TARGET.T ##''' X_part = ARRAY[:] Y_part = TARGET[:] #N_validation = ARRAY.shape[0]-(N_train) print(X_part.shape, "x_train") print(Y_part.shape) #model = DNN(n_in=26, n_hiddens=[150], n_out=2) ##FIXME TODO model = DNN(n_in=16, n_hiddens=[150, 150, 150, 150, 150, 150, 150, 150, 150, 150], n_out=2) ##FIXME TODO print("Error test1") model.fit_classify_model_read(ModelName=ModelName) print("Error test2") accuracy = model.evaluate(X_part, Y_part) print('accuracy:', accuracy) np.set_printoptions(threshold='nan') LL_TTTL_prob_tuple = model.Indicate_classified_LL_TTTL(X_part, Y_part) OF = open(Text_output, "w+") print(len(LL_TTTL_prob_tuple[2])) for i in range(len(LL_TTTL_prob_tuple[2])): if i == 0: OF.write("%s\n" % "LL TTTL") LL_n_TTTL = str(LL_TTTL_prob_tuple[2][i]).replace("[", "") LL_n_TTTL = LL_n_TTTL.replace("]", "") OF.write("%s" % LL_n_TTTL) #LL_p, TTTL_p = LL_n_TTTL.split(); LL_p = float(LL_p); TTTL_p = float(TTTL_p) #print(LL_n_TTTL, LL_p, TTTL_p) OF.write("\n") OF.close() ##''' ''' X_train = ARRAY[:] Y_train = TARGET[:] N_validation = ARRAY.shape[0]-(N_train) X_train, X_test, Y_train, Y_test = train_test_split(X_train, Y_train, train_size=N_train) X_train, X_validation, Y_train, Y_validation = train_test_split(X_train, Y_train, test_size=N_validation) print(X_train.shape,"x_train");print(X_validation.shape,"x_validation");print(Y_train.shape);print(Y_validation.shape) model = DNN(n_in=26, n_hiddens=[150,150,150], n_out=2) model.fit_classify_model_read(ModelName=ModelName) accuracy = model.evaluate(X_test, Y_test) print('accuracy:', accuracy) np.set_printoptions(threshold='nan') LL_TTTL_prob_tuple = model.Indicate_classified_LL_TTTL(X_test,Y_test) ''' '''
# Use input file from SSWW_split_input/result/for_DNN/***_comparable.root TODO import numpy as np import os from DNN_tensorflow_class_py2 import EarlyStopping, DNN from ROOT import TFile, TTree, TCut, TH1F from root_numpy import fill_hist from root_numpy import root2array, tree2array, array2root, array2tree from root_numpy import testdata from sklearn.model_selection import train_test_split from Epoch_loss_plots import Plotting #os.environ["CUDA_VISIBLE_DEVICES"]="0,1,2,3" model = DNN(n_in=16, n_hiddens=[150, 150, 150, 150, 150, 150, 150, 150, 150, 150], n_out=2) #TODO FIXME #epochs = 1000 epochs = 300 earlyStop = 20 #20 #TODO FIXME batch_size = 10 #TODO FIXME Date = 20181122 #TODO FIXME Layer_NUM = 10 #TODO FIXME Node_on_Each_layer = 150 #TODO FIXME N_train = 2600000 #TODO FIXME Model_name = "Raw_" + str(Date) + "_" + "TrainENum" + str( N_train) + "/" + "LayerNum_" + str(Layer_NUM) + "+" + "Node_" + str( Node_on_Each_layer) + "+" + "BatchSize_" + str(batch_size) Make_dir = "mkdir -p " + "tens_model_class/" + Model_name os.system(Make_dir) model_name = Model_name + "/" + "SSWW_tensor_TTTL-LL_comp"
def InputROOT_OutputTXT(infileROOT,ModelName): inputFile = read_file_name_root(infileROOT) ROOT_input = inputFile[2] ROOT_Estimated_LL = inputFile[3] + "Estimated_LL.root" ROOT_Estimated_TTTL = inputFile[3] + "Estimated_TTTL.root" # ROOT_Estimated_TTTL = inputFile[3] + inputFile[0] + "_Esti_TTTL.root" print(ROOT_Estimated_LL, ROOT_Estimated_TTTL) data = TFile.Open(ROOT_input) tree = data.Get('tree') ####################################### Input DATA Sets !!!!! lep1pt_ = tree2array(tree, branches='lep1pt') lep1eta_ = tree2array(tree, branches='lep1eta') #lep1phi_ = tree2array(tree, branches='lep1phi') lep2pt_ = tree2array(tree, branches='lep2pt') lep2eta_ = tree2array(tree, branches='lep2eta') #lep2phi_ = tree2array(tree, branches='lep2phi') jet1pt_ = tree2array(tree, branches='jet1pt') jet1eta_ = tree2array(tree, branches='jet1eta') #jet1phi_ = tree2array(tree, branches='jet1phi') #jet1M_ = tree2array(tree, branches='jet1M') jet2pt_ = tree2array(tree, branches='jet2pt') jet2eta_ = tree2array(tree, branches='jet2eta') #jet2phi_ = tree2array(tree, branches='jet2phi') #jet2M_ = tree2array(tree, branches='jet2M') MET_ = tree2array(tree, branches='MET') #lep1PID_ = tree2array(tree, branches='lep1PID') #lep2PID_ = tree2array(tree, branches='lep2PID') #Mjj_ = tree2array(tree, branches='Mjj') dr_ll_jj_ = tree2array(tree, branches='dr_ll_jj') dphijj_ = tree2array(tree, branches='dphijj') #zeppen_lep1_ = tree2array(tree, branches='zeppen_lep1') #zeppen_lep2_ = tree2array(tree, branches='zeppen_lep2') #METphi_ = tree2array(tree, branches='METphi') detajj_ = tree2array(tree, branches='detajj') Mll_ = tree2array(tree, branches='Mll') #RpT_ = tree2array(tree, branches='RpT') ############################################################################################################### ##################################### Target DATA !!!!! LL_Helicity_ = tree2array(tree, branches='LL_Helicity') TTTL_Helicity_ = tree2array(tree, branches='TTTL_Helicity') #TL_Helicity_ = tree2array(tree, branches='TL_Helicity') #TT_Helicity_ = tree2array(tree, branches='TT_Helicity') ############################################################################################################### ENTRY = LL_Helicity_.size print "ENTRY :", ENTRY lep1pt = np.zeros(ENTRY) lep1eta = np.zeros(ENTRY) #lep1phi = np.zeros(ENTRY) lep2pt = np.zeros(ENTRY) lep2eta = np.zeros(ENTRY) #lep2phi = np.zeros(ENTRY) jet1pt = np.zeros(ENTRY) jet1eta = np.zeros(ENTRY) #jet1phi = np.zeros(ENTRY) #jet1M = np.zeros(ENTRY) jet2pt = np.zeros(ENTRY) jet2eta = np.zeros(ENTRY) #jet2phi = np.zeros(ENTRY) #jet2M = np.zeros(ENTRY) MET = np.zeros(ENTRY) #lep1PID = np.zeros(ENTRY) #lep2PID = np.zeros(ENTRY) #Mjj = np.zeros(ENTRY) dr_ll_jj = np.zeros(ENTRY) dphijj = np.zeros(ENTRY) #zeppen_lep1 = np.zeros(ENTRY) #zeppen_lep2 = np.zeros(ENTRY) #METphi = np.zeros(ENTRY) detajj = np.zeros(ENTRY) Mll = np.zeros(ENTRY) #RpT = np.zeros(ENTRY) LL_Helicity = np.zeros(ENTRY) TTTL_Helicity = np.zeros(ENTRY) #TL_Helicity = np.zeros(ENTRY) #TT_Helicity = np.zeros(ENTRY) ############################################################################################################### for j1 in range(ENTRY): lep1pt[j1] = lep1pt_[j1] lep1eta[j1] = lep1eta_[j1] #lep1phi[j1] = lep1phi_[j1] lep2pt[j1] = lep2pt_[j1] lep2eta[j1] = lep2eta_[j1] #lep2phi[j1] = lep2phi_[j1] jet1pt[j1] = jet1pt_[j1] jet1eta[j1] = jet1eta_[j1] #jet1phi[j1] = jet1phi_[j1] #jet1M[j1] = jet1M_[j1] jet2pt[j1] = jet2pt_[j1] jet2eta[j1] = jet2eta_[j1] #jet2phi[j1] = jet2phi_[j1] #jet2M[j1] = jet2M_[j1] MET[j1] = MET_[j1] #lep1PID[j1] = lep1PID_[j1] #lep2PID[j1] = lep2PID_[j1] #Mjj[j1] = Mjj_[j1] dr_ll_jj[j1] = dr_ll_jj_[j1] dphijj[j1] = dphijj_[j1] #zeppen_lep1[j1] = zeppen_lep1_[j1] #zeppen_lep2[j1] = zeppen_lep2_[j1] #METphi[j1] = METphi_[j1] detajj[j1] = detajj_[j1] Mll[j1] = Mll_[j1] #RpT[j1] = RpT_[j1] LL_Helicity[j1] = LL_Helicity_[j1] TTTL_Helicity[j1] = TTTL_Helicity_[j1] #TL_Helicity[j1] = TL_Helicity_[j1] #TT_Helicity[j1] = TT_Helicity_[j1] #ARRAY = np.stack((lep1pt, lep1eta, lep1phi, lep2pt, lep2eta, lep2phi, jet1pt, jet1eta, jet1phi, jet1M, jet2pt, jet2eta, jet2phi, jet2M, MET, lep1PID, lep2PID, Mjj, dr_ll_jj, dphijj, zeppen_lep1, zeppen_lep2, METphi, detajj, Mll, RpT)) ARRAY = np.stack((lep1pt, lep1eta, lep2pt, lep2eta, jet1pt, jet1eta, jet2pt, jet2eta, MET, dr_ll_jj, dphijj, detajj, Mll)) TARGET = np.stack((LL_Helicity, TTTL_Helicity)) #TARGET = np.stack((LL_Helicity, TL_Helicity, TT_Helicity)) ARRAY = ARRAY.T TARGET = TARGET.T ##''' X_part = ARRAY[:] Y_part = TARGET[:] #N_validation = ARRAY.shape[0]-(N_train) print(X_part.shape,"x_train"); print(Y_part.shape) #model = DNN(n_in=26, n_hiddens=[150], n_out=2) ##FIXME TODO model = DNN(n_in=13, n_hiddens=[150,150,150,150,150,150,150], n_out=2) ##FIXME TODO model.fit_classify_model_read(ModelName=ModelName) accuracy = model.evaluate(X_part, Y_part) print('accuracy:', accuracy) np.set_printoptions(threshold='nan') LL_TTTL_prob_tuple = model.Indicate_classified_LL_TTTL(X_part, Y_part) print(len(LL_TTTL_prob_tuple[2])) #List = []; List_LL = []; List_TTTL = [] for i in range(len(LL_TTTL_prob_tuple[2])): LL_n_TTTL = str(LL_TTTL_prob_tuple[2][i]).replace("[","") LL_n_TTTL = LL_n_TTTL.replace("]","") XY_part = np.append(X_part[i],Y_part[i]) XY_part = tuple(XY_part) #List.append(XY_part) LL_p, TTTL_p = LL_n_TTTL.split(); LL_p = float(LL_p); TTTL_p = float(TTTL_p) #print(LL_n_TTTL, LL_p, TTTL_p) if(LL_p>0.5): List_LL.append(XY_part) elif(TTTL_p>0.5): List_TTTL.append(XY_part) else: print("ERROR on LL, TTTL proportion!") break nplist_LL = np.array(List_LL, dtype=[('lep1pt',np.float32),('lep1eta',np.float32),('lep2pt',np.float32),('lep2eta',np.float32), ('jet1pt',np.float32),('jet1eta',np.float32),('jet2pt',np.float32),('jet2eta',np.float32), ('MET',np.float32),('dr_ll_jj',np.float32),('dphijj',np.float32), ('detajj',np.float32),('Mll',np.float32), ('LL_Helicity',np.float32), ('TTTL_Helicity',np.float32)] ) nplist_TTTL = np.array(List_TTTL, dtype=[('lep1pt',np.float32),('lep1eta',np.float32),('lep2pt',np.float32),('lep2eta',np.float32), ('jet1pt',np.float32),('jet1eta',np.float32),('jet2pt',np.float32),('jet2eta',np.float32), ('MET',np.float32),('dr_ll_jj',np.float32),('dphijj',np.float32), ('detajj',np.float32),('Mll',np.float32), ('LL_Helicity',np.float32), ('TTTL_Helicity',np.float32)] ) LL_ROOT = TFile(ROOT_Estimated_LL,"RECREATE") tree_LL = array2tree(nplist_LL) tree_LL.Write() LL_ROOT.Close() TTTL_ROOT = TFile(ROOT_Estimated_TTTL,"RECREATE") tree_TTTL = array2tree(nplist_TTTL) tree_TTTL.Write() TTTL_ROOT.Close() return [ROOT_Estimated_LL,ROOT_Estimated_TTTL]
#TARGET = np.stack((LL_Helicity, TL_Helicity, TT_Helicity)) ARRAY = ARRAY.T TARGET = TARGET.T X_part = ARRAY[:] Y_part = TARGET[:] N_validation = ARRAY.shape[0] - (N_train) #X_train, X_test, Y_train, Y_test = train_test_split(X_train, Y_train, train_size=N_train) #X_train, X_validation, Y_train, Y_validation = train_test_split(X_train, Y_train, test_size=N_validation) #print(X_train.shape,"x_train");print(X_validation.shape,"x_validation");print(Y_train.shape);print(Y_validation.shape) print(X_part.shape, "x_train") print(Y_part.shape) model = DNN(n_in=26, n_hiddens=[150, 150, 150], n_out=2) model.fit_classify_model_read(ModelName=ModelName) #accuracy = model.evaluate(X_test, Y_test) accuracy = model.evaluate(X_part, Y_part) print('accuracy:', accuracy) np.set_printoptions(threshold='nan') LL_TTTL_prob_tuple = model.Indicate_classified_LL_TTTL(X_part, Y_part) #print(LL_TTTL_prob.shape) #print(X_part.shape) #print(X_part[0]) #LL_nplist = np.zeros(LL_TTTL_prob_tuple[0]) #TTTL_nplist = np.zeros(LL_TTTL_prob_tuple[1]) #print(LL_nplist.shape) #print(TTTL_nplist.shape)
def InputROOT_OutputTXT(infileROOT, ModelName): inputFile = read_file_name_root(infileROOT) ROOT_input = inputFile[2] Text_output = inputFile[0] + "reg.txt" data = TFile.Open(ROOT_input) tree = data.Get('tree') ####################################### Input DATA Sets !!!!! reco_bj1_Energy_ = tree2array(tree, branches='reco_bj1_Energy') reco_bj1_Theta_ = tree2array(tree, branches='reco_bj1_Theta') reco_bj1_Phi_ = tree2array(tree, branches='reco_bj1_Phi') reco_bj2_Energy_ = tree2array(tree, branches='reco_bj2_Energy') reco_bj2_Theta_ = tree2array(tree, branches='reco_bj2_Theta') reco_bj2_Phi_ = tree2array(tree, branches='reco_bj2_Phi') reco_MW1_Energy_ = tree2array(tree, branches='reco_MW1_Energy') reco_MW1_Theta_ = tree2array(tree, branches='reco_MW1_Theta') reco_MW1_Phi_ = tree2array(tree, branches='reco_MW1_Phi') reco_MW2_Energy_ = tree2array(tree, branches='reco_MW2_Energy') reco_MW2_Theta_ = tree2array(tree, branches='reco_MW2_Theta') reco_MW2_Phi_ = tree2array(tree, branches='reco_MW2_Phi') reco_l1_Energy_ = tree2array(tree, branches='reco_l1_Energy') reco_l1_Theta_ = tree2array(tree, branches='reco_l1_Theta') reco_l1_Phi_ = tree2array(tree, branches='reco_l1_Phi') reco_l2_Energy_ = tree2array(tree, branches='reco_l2_Energy') reco_l2_Theta_ = tree2array(tree, branches='reco_l2_Theta') reco_l2_Phi_ = tree2array(tree, branches='reco_l2_Phi') reco_l3_Energy_ = tree2array(tree, branches='reco_l3_Energy') reco_l3_Theta_ = tree2array(tree, branches='reco_l3_Theta') reco_l3_Phi_ = tree2array(tree, branches='reco_l3_Phi') reco_mET_Pt_ = tree2array(tree, branches='reco_mET_Pt') reco_mET_Phi_ = tree2array(tree, branches='reco_mET_Phi') mHT_ = tree2array(tree, branches='mHT') Gen_BjetTopHad_E_ = tree2array(tree, branches='Gen_BjetTopHad_E') Gen_WTopHad_mW_ = tree2array(tree, branches='Gen_WTopHad_mW') Gen_BjetTopLep_E_ = tree2array(tree, branches='Gen_BjetTopLep_E') Gen_NeutTopLep_Phi_ = tree2array(tree, branches='Gen_NeutTopLep_Phi') Gen_WTopLep_mW_ = tree2array(tree, branches='Gen_WTopLep_mW') #Kin_BjetTopHad_E_ = tree2array(tree, branches='Kin_BjetTopHad_E') #Kin_WTopHad_mW_ = tree2array(tree, branches='Kin_WTopHad_mW') #Kin_BjetTopLep_E_ = tree2array(tree, branches='Kin_BjetTopLep_E') #Kin_NeutTopLep_Phi_ = tree2array(tree, branches='Kin_NeutTopLep_Phi') #Kin_WTopLep_mW_ = tree2array(tree, branches='Kin_WTopLep_mW') ############################################################################################################### ##################################### Target DATA !!!!! mc_mem_ttz_weight_evalgenmax_log = tree2array( tree, branches='mc_mem_ttz_weight_evalgenmax_log') #mc_kin_ttz_weight_logmax = tree2array(tree, branches='mc_kin_ttz_weight_logmax') ############################################################################################################### ENTRY = mc_mem_ttz_weight_evalgenmax_log.size num_Valid = np.zeros(ENTRY) print "ENTRY :", ENTRY for i2 in range(ENTRY): num_Valid[i2] = i2 I2 = ENTRY reco_bj1_Energy = np.zeros(I2) reco_bj1_Theta = np.zeros(I2) reco_bj1_Phi = np.zeros(I2) reco_bj2_Energy = np.zeros(I2) reco_bj2_Theta = np.zeros(I2) reco_bj2_Phi = np.zeros(I2) reco_MW1_Energy = np.zeros(I2) reco_MW1_Theta = np.zeros(I2) reco_MW1_Phi = np.zeros(I2) reco_MW2_Energy = np.zeros(I2) reco_MW2_Theta = np.zeros(I2) reco_MW2_Phi = np.zeros(I2) reco_l1_Energy = np.zeros(I2) reco_l1_Theta = np.zeros(I2) reco_l1_Phi = np.zeros(I2) reco_l2_Energy = np.zeros(I2) reco_l2_Theta = np.zeros(I2) reco_l2_Phi = np.zeros(I2) reco_l3_Energy = np.zeros(I2) reco_l3_Theta = np.zeros(I2) reco_l3_Phi = np.zeros(I2) reco_mET_Pt = np.zeros(I2) reco_mET_Phi = np.zeros(I2) mHT = np.zeros(I2) Gen_BjetTopHad_E = np.zeros(I2) Gen_WTopHad_mW = np.zeros(I2) Gen_BjetTopLep_E = np.zeros(I2) Gen_NeutTopLep_Phi = np.zeros(I2) Gen_WTopLep_mW = np.zeros(I2) #Kin_BjetTopHad_E = np.zeros(I2) #Kin_WTopHad_mW = np.zeros(I2) #Kin_BjetTopLep_E = np.zeros(I2) #Kin_NeutTopLep_Phi = np.zeros(I2) #Kin_WTopLep_mW = np.zeros(I2) TARGET = np.zeros(I2) for j1 in range(reco_bj1_Energy.size): jj1 = int(num_Valid[j1]) reco_bj1_Energy[j1] = reco_bj1_Energy_[jj1] reco_bj1_Theta[j1] = reco_bj1_Theta_[jj1] reco_bj1_Phi[j1] = reco_bj1_Phi_[jj1] reco_bj2_Energy[j1] = reco_bj2_Energy_[jj1] reco_bj2_Theta[j1] = reco_bj2_Theta_[jj1] reco_bj2_Phi[j1] = reco_bj2_Phi_[jj1] reco_MW1_Energy[j1] = reco_MW1_Energy_[jj1] reco_MW1_Theta[j1] = reco_MW1_Theta_[jj1] reco_MW1_Phi[j1] = reco_MW1_Phi_[jj1] reco_MW2_Energy[j1] = reco_MW2_Energy_[jj1] reco_MW2_Theta[j1] = reco_MW2_Theta_[jj1] reco_MW2_Phi[j1] = reco_MW2_Phi_[jj1] reco_l1_Energy[j1] = reco_l1_Energy_[jj1] reco_l1_Theta[j1] = reco_l1_Theta_[jj1] reco_l1_Phi[j1] = reco_l1_Phi_[jj1] reco_l2_Energy[j1] = reco_l2_Energy_[jj1] reco_l2_Theta[j1] = reco_l2_Theta_[jj1] reco_l2_Phi[j1] = reco_l2_Phi_[jj1] reco_l3_Energy[j1] = reco_l3_Energy_[jj1] reco_l3_Theta[j1] = reco_l3_Theta_[jj1] reco_l3_Phi[j1] = reco_l3_Phi_[jj1] reco_mET_Pt[j1] = reco_mET_Pt_[jj1] reco_mET_Phi[j1] = reco_mET_Phi_[jj1] mHT[j1] = mHT_[jj1] Gen_BjetTopHad_E[j1] = Gen_BjetTopHad_E_[jj1] Gen_WTopHad_mW[j1] = Gen_WTopHad_mW_[jj1] Gen_BjetTopLep_E[j1] = Gen_BjetTopLep_E_[jj1] Gen_NeutTopLep_Phi[j1] = Gen_NeutTopLep_Phi_[jj1] Gen_WTopLep_mW[j1] = Gen_WTopLep_mW_[jj1] #Kin_BjetTopHad_E[j1] = Kin_BjetTopHad_E_[jj1] #Kin_WTopHad_mW[j1] = Kin_WTopHad_mW_[jj1] #Kin_BjetTopLep_E[j1] = Kin_BjetTopLep_E_[jj1] #Kin_NeutTopLep_Phi[j1] = Kin_NeutTopLep_Phi_[jj1] #Kin_WTopLep_mW[j1] = Kin_WTopLep_mW_[jj1] TARGET[j1] = mc_mem_ttz_weight_evalgenmax_log[jj1] ARRAY = np.stack( (reco_bj1_Energy, reco_bj1_Theta, reco_bj1_Phi, reco_bj2_Energy, reco_bj2_Theta, reco_bj2_Phi, reco_MW1_Energy, reco_MW1_Theta, reco_MW1_Phi, reco_MW2_Energy, reco_MW2_Theta, reco_MW2_Phi, reco_l1_Energy, reco_l1_Theta, reco_l1_Phi, reco_l2_Energy, reco_l2_Theta, reco_l2_Phi, reco_l3_Energy, reco_l3_Theta, reco_l3_Phi, reco_mET_Pt, reco_mET_Phi, mHT, Gen_BjetTopHad_E, Gen_WTopHad_mW, Gen_BjetTopLep_E, Gen_NeutTopLep_Phi, Gen_WTopLep_mW)) TARGET = np.stack([TARGET]) ARRAY = ARRAY.T TARGET = TARGET.T X_part = ARRAY[:] Y_part = TARGET[:] print(X_part.shape, "x_train") print(Y_part.shape) model = DNN(n_in=29, n_hiddens=[150, 150, 150, 150, 150, 150, 150, 150, 150, 150], n_out=1) ##FIXME TODO model.regression_model_read(ModelName=ModelName) accuracy = model.regression_evaluate(X_part, Y_part) print('Error value :', accuracy) #np.set_printoptions(threshold='nan') print("REAL Y :", Y_part) Regressed_values = model.Indicated_regressed_ttZ(X_part, Y_part) OF = open(Text_output, "w+") print("Length of DATA :", len(Regressed_values)) for i in range(len(Regressed_values)): if i == 0: OF.write("%s\n" % "Real Regressed") OF.write("%s " % (str(Y_part[i][0]))) OF.write("%s\n" % (str(Regressed_values[i][0])))
import numpy as np from DNN_tensorflow_class_py2 import EarlyStopping, DNN from ROOT import TFile, TTree, TCut, TH1F from root_numpy import fill_hist from root_numpy import root2array, tree2array, array2root from root_numpy import testdata from sklearn.model_selection import train_test_split model = DNN(n_in=26, n_hiddens=[150, 150, 150, 150], n_out=3) epochs = 1000 earlyStop = 100 batch_size = 200 model_name = "SSWW_tensor2" N_train = 1800000 data = TFile.Open('SSWW_input/SS_190M.root') tree = data.Get('tree') ####################################### Input DATA Sets !!!!! lep1pt_ = tree2array(tree, branches='lep1pt') lep1eta_ = tree2array(tree, branches='lep1eta') lep1phi_ = tree2array(tree, branches='lep1phi') lep2pt_ = tree2array(tree, branches='lep2pt') lep2eta_ = tree2array(tree, branches='lep2eta') lep2phi_ = tree2array(tree, branches='lep2phi') jet1pt_ = tree2array(tree, branches='jet1pt') jet1eta_ = tree2array(tree, branches='jet1eta') jet1phi_ = tree2array(tree, branches='jet1phi') jet1M_ = tree2array(tree, branches='jet1M') jet2pt_ = tree2array(tree, branches='jet2pt') jet2eta_ = tree2array(tree, branches='jet2eta')