ATLAS Offline Software
RTTAlgmain.py
Go to the documentation of this file.
1 import os, sys
2 import numpy as np
3 import ROOT
4 
5 sys.path.append(os.path.join(os.path.dirname(__file__),'HistCompare'))
6 print (sys.path)
7 from RecExOnline.power_of_test import power_of_test
8 from RecExOnline.utils import get_array
9 import warnings
10 warnings.filterwarnings("ignore")
11 
12 from RecExOnline.setupRTTAlg import *
13 #YJ add for athena
14 theApp.EvtMax = 1
15 #YJ add for html generator (5test & 1 plot)* total his
16 w = 6*len(histnames)
17 h = 7
18 h_th =0
19 Matrix = [0 for x in range(w)]
20 from collections import Counter, defaultdict
21 #YJ for check time for rel
22 
23 import datetime
24 currenttime=datetime.datetime.now()
25 rel=currenttime.isoweekday()
26 print ("Time for RTT Alg : %d" %currenttime.hour)
27 if currenttime.hour>15:
28  rel=rel+1
29 if rel==7:
30  rel=0
31 print ("rel for RTT Alg : %d" %rel)
32 
33 #output format
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"]
36 #check system
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]
42 
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)
46 
47 #main program
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
58  h_th+=1
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
70  h_th+=1
71  print ("matrix index check : %d "%(h_th))
72  sys.stdout.flush()
73  std_line[:2] = histname, test
74  for p in p_arr:
75  address[0] = p
76  branch.Fill()
77 output_file.Write("", 2)
78 for f in files: f.Close()
79 output_file.Close()
80 print (Matrix)
81 
82 
83 
84 
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")
python.power_of_test.power_of_test
def power_of_test(data1, data2, rvs_func='rvs_pairs', tests=['chi2_2samp'], rvs_key={}, test_key={}, parallel=None, sync=True)
Definition: power_of_test.py:80
max
#define max(a, b)
Definition: cfImp.cxx:41
vtune_athena.format
format
Definition: vtune_athena.py:14
setupRTTAlg
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
Trk::open
@ open
Definition: BinningType.h:40
calibdata.copy
bool copy
Definition: calibdata.py:27