5sys.path.append(os.path.join(os.path.dirname(__file__),
'HistCompare'))
7from RecExOnline.power_of_test
import power_of_test
8from RecExOnline.utils
import get_array
10warnings.filterwarnings(
"ignore")
19Matrix = [0
for x
in range(w)]
20from collections
import Counter, defaultdict
24currenttime=datetime.datetime.now()
25rel=currenttime.isoweekday()
26print (
"Time for RTT Alg : %d" %currenttime.hour)
27if currenttime.hour>15:
31print (
"rel for RTT Alg : %d" %rel)
34header = dict([(
"Object",
max(len(h)
for h
in histnames)),(
"Test",
max(len(t.split(
"_")[0])
for t
in tests)),(
"p-value",21)])
35std_line = [
"Object",
"Test",
"p-value"]
37if not os.path.isdir(output_directory):
38 os.makedirs(output_directory)
39files = ROOT.TFile(ref_filename), ROOT.TFile(rtt_filename)
40trees = [file.Get(treename)
for treename, file
in zip([ref_treename, rtt_treename], files)]
41hist_pairs = [(histname, tuple(tree.Get(histname)
for tree
in trees))
for histname
in histnames]
43output_file = ROOT.TFile(os.path.join(output_directory,
"power_of_test.root"),
"RECREATE")
44output_tree = ROOT.TTree(
"Tree",
"Tree")
45output_tree.SetEntries(size)
48print (std_line[0].ljust(header[
"Object"]), std_line[1].ljust(header[
"Test"]), std_line[2].center(header[
"p-value"]))
49print (
"="*header[
"Object"],
"="*header[
"Test"],
"="*header[
"p-value"])
50for histname, hist_pair
in hist_pairs:
51 output_tree.Branch(
"/"+histname.replace(
"/",
"."))
52 bins = np.intersect1d(*
map(
lambda hist: [hist.GetBinLowEdge(i)
for i
in range(1, hist.GetNbinsX()+2)], hist_pair))
53 for hist
in hist_pair: hist.SetBins(bins.size-1, bins)
54 data1, data2 =
map(get_array, hist_pair)
55 address = np.zeros(1,
'float32')
56 htmalhisname=
"tot_"+rtt_treename+
"_"+histname.replace(
"/",
"_")+
".png"
57 Matrix[h_th]=(
"<img src=\"https://atlas-rtt.cern.ch/prod/rtt/rel_%d/20.11.X.Y.Z-VAL/build/x86_64-slc6-gcc49-opt/AtlasP1MON/RecExOnline/RecExOnline_User_Offline_test_v1/" +htmalhisname+
"\" alt=\""+htmalhisname+
"\" height=\"250\">") %rel
59 for test, p_arr
in power_of_test(data1+data2, data2, tests = tests, rvs_key = {
'size' : size,
'freeze' : (
False,
True),
'entries' : data2.sum()}.copy(), parallel =
False).items():
60 branchname =
'.'.join([histname.replace(
'/',
'.'), test.split(
'_')[0]])
61 branch = output_tree.Branch(branchname, address,
"F")
62 p_arr = np.array(p_arr).round(5)
63 if test ==
"anderson_ksamp":
64 p_arr[p_arr >= 1.2] = 0.
65 print ((histname
if std_line[0]!=histname
else "").ljust(header[
"Object"]), (test.split(
"_")[0]
if std_line[1]!=test
else "").ljust(header[
"Test"]),
"{:>8} +/- {:<8} (%)".format(round(p_arr.mean()*100,1),round(p_arr.std()*100,2)))
66 Testresult=
"%s %s:%s +- %s" % (histname,test ,p_arr.mean(),p_arr.std())
67 if test ==
"ks_2samp" and (p_arr.mean()+p_arr.std()<0.05):
68 Testresult=
"<font color=\"red\">%s %s:%s +- %s </font>" % (histname,test ,p_arr.mean(),p_arr.std())
69 Matrix[h_th]= Testresult
71 print (
"matrix index check : %d "%(h_th))
73 std_line[:2] = histname, test
77output_file.Write(
"", 2)
78for f
in files: f.Close()
85f_html = open(
'RTTAlg.html',
'w')
86f_html.write(
"<table> \n")
87for nprint
in range(w):
88 f_html.write(
"<tr> \n")
89 f_html.write(
"<td>" + Matrix[nprint] +
"</td> \n")
90 f_html.write(
"</tr> \n")
91f_html.write(
"</table> \n")