forked from keras-team/keras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getqgauc.py
112 lines (111 loc) · 3.49 KB
/
getqgauc.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import ROOT as rt
import matplotlib.pyplot as plt
from sklearn.metrics import roc_auc_score, roc_curve
import numpy as np
import argparse
import os
import random
import scipy.stats
parser=argparse.ArgumentParser()
parser.add_argument("--var",type=str,default="eta",help='')
parser.add_argument("--savename",type=str,default="savemae",help='')
parser.add_argument("--eta",type=float,default=0,help='')
parser.add_argument("--etabin",type=float,default=2.4,help='')
parser.add_argument("--ptmin",type=float,default=0,help='')
parser.add_argument("--ptmax",type=float,default=2.,help='')
parser.add_argument("--pt",type=int,default=1000,help='')
parser.add_argument("--get",type=str,default="",help='')
parser.add_argument("--gaus",type=int,default=0,help='')
args=parser.parse_args()
if("pt" in args.get):
if(args.pt==100):
args.ptmin=0.815
args.ptmax=1.159
if(args.pt==200):
args.ptmin=0.819
args.ptmax=1.123
if(args.pt==500):
args.ptmin=0.821
args.ptmax=1.093
if(args.pt==1000):
args.ptmin=0.8235
args.ptmax=1.076
#if("eta" in args.get):
# args.etabin=1
if("acut" in args.get):
if(args.pt==100):
args.ptmin=0.815
args.ptmax=1.159
if(args.pt==200):
args.ptmin=0.819
args.ptmax=1.123
if(args.pt==500):
args.ptmin=0.821
args.ptmax=1.093
if(args.pt==1000):
args.ptmin=0.8235
args.ptmax=1.076
args.etabin=1
if("npz" in args.savename):
args.ptmin=1.
args.ptmax=1.2
pt=args.pt
res=100
#os.system("ls save/"+args.savename+"/get.root")
if(args.gaus):
jgaus=eval(open("jjgaus.txt").readline())
zgaus=eval(open("zjgaus.txt").readline())
lgaus=[jgaus,zgaus]
for num in range(1,2):
#try:
if("bdt" in args.savename):f=rt.TFile("xgb/"+args.savename+"get.root",'read')
else:f=rt.TFile("save/"+args.savename+"/qgget.root",'read')
dq=f.Get("dq")
zq=f.Get("zq")
dg=f.Get("dg")
zg=f.Get("zg")
tree=[dq,zq,dg,zg]
lab=["dijet","Z+jet"]
wr=open("aucs/{}{}".format(args.savename,args.get),'w')
wr.write("{")
mv=0
for k in range(1):
if("npz" in args.savename):
if("npzzq" in args.savename and k==0):continue
if("npzqq" in args.savename and k==1):continue
else:
if("zq" in args.savename and k==0):continue
if("qq" in args.savename and k==1):continue
y=[]
p=[]
for i in range(1):
print(tree[i*2+k].GetEntries())
for j in range(tree[i*2+k].GetEntries()):
tree[i*2+k].GetEntry(j)
if(abs(tree[i*2+k].pt)>args.pt*args.ptmax or abs(tree[i*2+k].pt)<args.pt*args.ptmin):continue
if(abs(tree[i*2+k].eta)>args.eta+args.etabin or abs(tree[i*2+k].eta)<args.eta):continue
if(args.gaus):
if(random.random()>lgaus[k][int(250*tree[i*2+k].pt/args.pt)]):continue
if(tree[i*2+k].pid!=21 and tree[i*2+k].pid!=0):
y.append(1)
p.append(tree[i*2+k].p)
elif(tree[i*2+k].pid==21):
y.append(0)
p.append(tree[i*2+k].p)
sem=scipy.stats.sem(p)
fpr,tpr,thresholds=roc_curve(y,p)
tnr=1-fpr
diff=1.
diffi=0
for i in range(len(tpr)):
if(abs(tpr[i]-0.5)<diff):
diff=abs(tpr[i]-0.5)
diffi=i
print(args.savename,lab[k],round(roc_auc_score(y,p),5),round(fpr[diffi],5),diffi)
wr.write("'{}':{},".format(lab[k],round(roc_auc_score(y,p),5)))
wr.write("'{}05':{},".format(lab[k],round(fpr[diffi],5)))
wr.write("'{}sem':{},".format(lab[k],round(sem,5)))
f.Close()
wr.write("}")
#except:
# pass