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