5 sys.path.append(os.path.join(os.path.dirname(__file__),
'HistCompare'))
7 from RecExOnline.power_of_test
import power_of_test
8 from RecExOnline.utils
import get_array
10 warnings.filterwarnings(
"ignore")
20 from collections
import Counter, defaultdict
24 currenttime=datetime.datetime.now()
25 rel=currenttime.isoweekday()
26 print (
"Time for RTT Alg : %d" %currenttime.hour)
27 if currenttime.hour>15:
31 print (
"rel for RTT Alg : %d" %rel)
34 header = dict([(
"Object",
max(len(h)
for h
in histnames)),(
"Test",
max(len(t.split(
"_")[0])
for t
in tests)),(
"p-value",21)])
35 std_line = [
"Object",
"Test",
"p-value"]
37 if not os.path.isdir(output_directory):
38 os.makedirs(output_directory)
39 files = ROOT.TFile(ref_filename), ROOT.TFile(rtt_filename)
40 trees = [file.Get(treename)
for treename, file
in zip([ref_treename, rtt_treename], files)]
41 hist_pairs = [(histname, tuple(tree.Get(histname)
for tree
in trees))
for histname
in histnames]
43 output_file = ROOT.TFile(os.path.join(output_directory,
"power_of_test.root"),
"RECREATE")
44 output_tree = ROOT.TTree(
"Tree",
"Tree")
45 output_tree.SetEntries(size)
48 print (std_line[0].ljust(header[
"Object"]), std_line[1].ljust(header[
"Test"]), std_line[2].center(header[
"p-value"]))
49 print (
"="*header[
"Object"],
"="*header[
"Test"],
"="*header[
"p-value"])
50 for 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
77 output_file.Write(
"", 2)
78 for f
in files: f.Close()
85 f_html =
open(
'RTTAlg.html',
'w')
86 f_html.write(
"<table> \n")
87 for 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")
91 f_html.write(
"</table> \n")