ATLAS Offline Software
CreatePhysValWebPage.py
Go to the documentation of this file.
1 
4 
5 # Create Physics Validation Web page
6 # Author: Arnaud Duperrin <duperrin@cppm.in2p3.fr> - March 2021
7 
8 # python CreatePhysValWebPage.py -h
9 # python CreatePhysValWebPage.py -i ROC
10 
11 # Import os module to read directory
12 import getopt,os,glob,argparse,sys
13 
14 parser = argparse.ArgumentParser(description='Create the Physics Validation web page:', usage='%(prog)s -i ROC/ ')
15 parser.add_argument("-i", "--input_dir", help="path to the folder holding the plots (default: ./)", default=os.getcwd())
16 parser.add_argument("-n", "--number_of_histo", help="number of histo per raw (default is 4)", default=4)
17 #parser.add_argument("-o", "--output_dir", help="path for the output (default: ./FTAG_PhysValWebPage.html", default=os.getcwd()+"/FTAG_PhysValWebPage.html")
18 parser.add_argument("-f", "--format", help='format for the plots (default: "*.png")', default="*.png")
19 
20 
21 
22 def row_major(alist, sublen):
23  return [alist[i:i+sublen] for i in range(0, len(alist), sublen)]
24 
25 def col_major(alist, sublen):
26  numrows = (len(alist)+sublen-1) // sublen
27  return [alist[i::sublen] for i in range(numrows)]
28 
29 #example:
30 #L = ['one','two','three','four','five','six','seven','eight','nine']
31 #for r in row_major(L, 3): print r
32 #for r in col_major(L, 3): print r
33 #for r in row_major(L, 4): print r
34 
35 def html_table(lol):
36  string = '<html><table>'
37  for sublist in lol:
38  string += '<tr><th> '
39  #print (sublist)
40  list_len = len(sublist)
41 
42  #First the headers
43  for file in sublist:
44  idx = sublist.index(file)
45  print("Histo: " + sublist[idx])
46  list_end = list_len - idx
47  if list_end != 1:
48  next_idx = idx + 1
49  string += '<p style=\"color:#0000FF\";>'+ str(file)+ '<p> </th><th>'
50  else:
51  #print("End Of List!")
52  string += '<p style=\"color:#0000FF\";>'+ str(file)+ '<p> </th></tr> '
53 
54  #Then the plots
55  string += '<tr><td> '
56  for file in sublist:
57  idx = sublist.index(file)
58  list_end = list_len - idx
59  if list_end != 1:
60  next_idx = idx + 1
61  string += '<a href="'+str(file)+'"> <img alt="'+str(file)+'" src="'+str(file)+'" width="400" height="300"></a> </td><th>'
62  else:
63  string += '<a href="'+str(file)+'"> <img alt="'+str(file)+'" src="'+str(file)+'" width="400" height="300"></a> </td><tr>'
64 
65  #print("string= "+string)
66  #print(".........")
67  string += '</table></html>'
68  return string
69 
70 def list_to_html_table(alist, sublength, column_major=False):
71  if column_major:
72  lol = col_major(alist, sublength)
73  else:
74  lol = row_major(alist, sublength)
75  return(html_table(lol))
76 
77 
78 
79 
80 args = parser.parse_args()
81 folder = os.path.abspath(args.input_dir)
82 
83 if not os.path.isdir(folder):
84  print("The folder " + folder + " doesn't exist !")
85  sys.exit()
86 
87 #out = args.output_dir
88 format = args.format
89 nHisto = int(args.number_of_histo)
90 
91 #origDir = os.getcwd()
92 #output_file = os.path.abspath(args.output_dir)
93 
94 
95 os.chdir(folder)
96 
97 files = glob.glob(format)
98 
99 #print ("nHisto = " + str(nHisto))
100 
101 print("=================================================")
102 print("Processing histo in directory "+folder)
103 print("=================================================")
104 #Start by main ROC directory:
105 my_htm_page= list_to_html_table(files, nHisto)
106 #print(my_htm_page)
107 hs = open("FTAG_PhysValWebPage.html", 'w')
108 hs.write(my_htm_page)
109 print("")
110 print("See "+folder+"/FTAG_PhysValWebPage.html")
111 
112 folder_eff= folder+"/eff_vs_Lxy"
113 if (os.path.isdir(folder_eff)):
114  os.chdir(folder_eff)
115  files = glob.glob(format)
116  my_htm_page= list_to_html_table(files, nHisto)
117  hs = open("FTAG_PhysValWebPage.html", 'w')
118  hs.write(my_htm_page)
119  #print("")
120  #print("See "+folder_eff+"/FTAG_PhysValWebPage.html")
121 else:
122  print("There is no Efficiency vs Lxy directory: " + folder_eff)
123 
124 
125 folder_pt= folder+"/eff_vs_pt_ttbar"
126 is_ttbar = 1
127 if (os.path.isdir(folder_pt)):
128  os.chdir(folder_pt)
129  files = glob.glob(format)
130  my_htm_page= list_to_html_table(files, nHisto)
131  hs = open("FTAG_PhysValWebPage.html", 'w')
132  hs.write(my_htm_page)
133  #print("")
134  #print("See "+folder_eff+"/FTAG_PhysValWebPage.html")
135 else:
136  is_ttbar = 0
137  folder_pt= folder+"/eff_vs_pt_Zprime"
138  if (os.path.isdir(folder_pt)):
139  os.chdir(folder_pt)
140  files = glob.glob(format)
141  my_htm_page= list_to_html_table(files, nHisto)
142  hs = open("FTAG_PhysValWebPage.html", 'w')
143  hs.write(my_htm_page)
144  #print("")
145  #print("See "+folder_pt+"/FTAG_PhysValWebPage.html")
146  else:
147  print("There is no Efficiency vs pT directory (ttbar or Z'): " + folder_pt)
148 
149 #Create the master web page
150 os.chdir(folder)
151 mypage = "<html><table>"
152 mypage += '<tr><th><p style=\"color:#0000FF\";> FTAG Physics validation web page <p> </th> </tr>'
153 mypage += '<tr><td> <a href="FTAG_PhysValWebPage.html">' +str(args.input_dir)+'</a> </td></tr> '
154 mypage += '<tr><td> <ul> <li> <a href="eff_vs_Lxy/FTAG_PhysValWebPage.html"> Efficiency versus Lxy </a> </li> '
155 if (is_ttbar):
156  mypage += ' <li> <a href="eff_vs_pt_ttbar/FTAG_PhysValWebPage.html"> Efficiency versus pT </a> </li> </td></tr> '
157 else:
158  mypage += ' <li> <a href="eff_vs_pt_Zprime/FTAG_PhysValWebPage.html"> Efficiency versus pT </a> </li> </td></tr> '
159 mypage += "</table></html>"
160 
161 #print(mypage)
162 hs = open("FTAG_PhysVal.html", 'w')
163 hs.write(mypage)
164 print("See "+folder+"/FTAG_PhysVal.html")
165 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CreatePhysValWebPage.html_table
def html_table(lol)
Definition: CreatePhysValWebPage.py:35
CreatePhysValWebPage.col_major
def col_major(alist, sublen)
Definition: CreatePhysValWebPage.py:25
CreatePhysValWebPage.row_major
def row_major(alist, sublen)
Definition: CreatePhysValWebPage.py:22
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
CreatePhysValWebPage.list_to_html_table
def list_to_html_table(alist, sublength, column_major=False)
Definition: CreatePhysValWebPage.py:70
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70