-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_input_array.py
91 lines (83 loc) · 4.7 KB
/
make_input_array.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#import tensorflow as tf
import ROOT as root
import numpy as np
import root_numpy as rootnp
#from tensorflow import keras
import matplotlib.pyplot as plt
#from sklearn.metrics import roc_curve, auc
#from sklearn.ensemble import RandomForestClassifier
#from sklearn.ensemble import AdaBoostClassifier
#from sklearn.tree import DecisionTreeClassifier
#from sklearn.model_selection import train_test_split
#array = np.load('x_vbf062420_zb070520.npy')
#print(array)
fVBF = root.TFile.Open("/afs/cern.ch/work/a/addropul/public/forAditya/l1TNtuple-VBF_072020_norecomatch_newbdtcuts.root","READ")
#fVBF.Print()
fZB = root.TFile.Open('/afs/cern.ch/work/a/addropul/public/forAditya/l1TNtuple-ZeroBias-072020_norecomatch_newbdtcut.root', "READ")
#fZB.Print()
fVBFTree = fVBF.Get("l1NtupleProducer/Stage3Regions/efficiencyTree")
fZBTree = fZB.Get("l1NtupleProducer/Stage3Regions/efficiencyTree")
print(fZBTree.GetEntries())
#print(type(fZBTree))
#VBF tree to array
fVBFDataDeltaEta = rootnp.tree2array(fVBFTree, branches = 'l1DeltaEta')
fVBFDataDeltaPhi = rootnp.tree2array(fVBFTree, branches = 'l1DeltaPhi')
fVBFDataMass = rootnp.tree2array(fVBFTree, branches = 'l1Mass')
fVBFDataPt1 = rootnp.tree2array(fVBFTree, branches = 'l1Pt_1')
fVBFDataPt2 = rootnp.tree2array(fVBFTree, branches = 'l1Pt_2')
#ZB tree to array
fZBDataDeltaEta = rootnp.tree2array(fZBTree, branches = 'l1DeltaEta')
fZBDataDeltaPhi = rootnp.tree2array(fZBTree, branches = 'l1DeltaPhi')
fZBDataMass = rootnp.tree2array(fZBTree, branches = 'l1Mass')
fZBDataPt1 = rootnp.tree2array(fZBTree, branches = 'l1Pt_1')
fZBDataPt2 = rootnp.tree2array(fZBTree, branches = 'l1Pt_2')
#Applying cut
import pandas as pd
dataset_VBF = pd.DataFrame({'l1Pt_1':fVBFDataPt1, 'l1Pt_2': fVBFDataPt2,'l1DeltaEta': fVBFDataDeltaEta, 'l1DeltaPhi':fVBFDataDeltaPhi, 'l1Mass':fVBFDataMass})
dataset_VBF = dataset_VBF.drop(dataset_VBF[dataset_VBF.l1Pt_1 <= 0].index)
dataset_VBF = dataset_VBF.drop(dataset_VBF[dataset_VBF.l1Pt_2 <= 0].index)
dataset_VBF = dataset_VBF.drop(dataset_VBF[dataset_VBF.l1Mass <= 0].index)
print(dataset_VBF.shape)
dataset_ZB = pd.DataFrame({'l1Pt_1':fZBDataPt1, 'l1Pt_2': fZBDataPt2,'l1DeltaEta': fZBDataDeltaEta, 'l1DeltaPhi':fZBDataDeltaPhi, 'l1Mass':fZBDataMass})
dataset_ZB = dataset_ZB.drop(dataset_ZB[dataset_ZB.l1Pt_1 <= 0].index)
dataset_ZB = dataset_ZB.drop(dataset_ZB[dataset_ZB.l1Pt_2 <= 0].index)
dataset_ZB = dataset_ZB.drop(dataset_ZB[dataset_ZB.l1Mass <= 0].index)
print(dataset_ZB.shape)
dataset_VBF['VBF_label'] = np.ones_like(dataset_VBF['l1Pt_1'].shape[0]).tolist()
dataset_ZB['VBF_label'] = np.zeros_like(dataset_ZB['l1Pt_1'].shape[0]).tolist()
dataset_full = pd.concat([dataset_VBF,dataset_ZB])
x = dataset_full.as_matrix(columns= ['l1Pt_1','l1Pt_2','l1DeltaEta','l1DeltaPhi','l1Mass'])
#print(x)
y = dataset_full.as_matrix(columns= ['VBF_label'])
np.save('x_vbf072020_zb072020.npy', x)
#x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=42)
#
#
##--------------
## BDT
##--------------
#
#bdt = AdaBoostClassifier(DecisionTreeClassifier(max_depth=1), algorithm="SAMME.R", n_estimators=200)
#
#
##bdt = RandomForestClassifier(n_estimators=200)
#
#
##bdt = DecisionTreeClassifier(max_depth = 1)
#
#bdt.fit(x_train,y_train)
#
#y_pred_kerasBDT = bdt.predict_proba(x_test)
#
#y_pred_kerasBDT = np.delete(y_pred_kerasBDT, 0, 1)
#fpr_kerasBDT, tpr_kerasBDT, thresholds_kerasBDT = roc_curve(y_test, y_pred_kerasBDT)
#
#auc_kerasBDT = auc(1-fpr_kerasBDT, tpr_kerasBDT)
#
#
#plt.plot(1 - fpr_kerasBDT, tpr_kerasBDT,label='BDT AUC (area = %0.2f)' % auc_kerasBDT)
##plt.scatter(1 - fpr_keras, tpr_keras)
#plt.xlabel('Signal Efficiency')
#plt.ylabel('Background Rejection')
#plt.title('BDT ROC')
#plt.legend(loc="lower right")