Belle II Software development
plot.py
1#!/usr/bin/env python3
2
3
10
11import numpy as np
12import matplotlib.pyplot as plt
13
14
15def fFileExist(filename):
16 """Test if file exists"""
17
18 try:
19 oFile = open(filename)
20 except OSError:
21 return 0
22 else:
23 oFile.close()
24 return 1
25
26
27def read(optlevel, b, name):
28 """read time from out/*.out and save plots to plots/. The cut deletes obviously wrong times."""
29
30 z = 0
31 for i in range(0, len(optlevel)):
32 if fFileExist("out/" + optlevel[i - z] + ".out") == 0:
33 del optlevel[i - z]
34 z = z + 1
35 cut = True
36 value = [0] * len(optlevel)
37 sigma = [0] * len(optlevel)
38 valuenormed = [0] * len(optlevel)
39 sigmanormed = [0] * len(optlevel)
40 n = [0] * len(optlevel)
41 t = list(range(0, len(optlevel)))
42 for i in t:
43 fobj = open("out/" + optlevel[i] + ".out")
44 readvalue = []
45 # read file
46 for line in fobj:
47 words = line.split()
48 readvalue.append(1 / float(words[b]))
49 fobj.close()
50 # Calculation
51 value[i] = np.mean(readvalue)
52 sigma[i] = np.std(readvalue)
53 u = list(range(0, len(readvalue)))
54 z = 0
55 if cut:
56 for j in u:
57 if readvalue[j - z] > 1.5 * value[i] or readvalue[j - z] < 0.5 * value[i]:
58 del readvalue[j - z]
59 z = z + 1
60 sigma[i] = np.std(readvalue)
61 value[i] = np.mean(readvalue)
62 n[i] = len(readvalue)
63 x = 1 / value[0]
64 for i in range(0, len(value)):
65 valuenormed[i] = value[i] * x
66 sigmanormed[i] = sigma[i] * x
67 plt.errorbar(
68 t,
69 valuenormed,
70 xerr=0,
71 yerr=sigmanormed,
72 color="black",
73 fmt="_",
74 ecolor="black",
75 label="normed time",
76 )
77 (locs, labels) = plt.xticks(t, optlevel)
78 plt.setp(labels, rotation=90)
79 plt.xlim([-0.5, len(optlevel) - 0.5])
80 plt.ylabel("performance")
81 fig = plt.gcf()
82 fig.subplots_adjust(bottom=0.65)
83 plt.savefig("plots/" + name + ".png")
84 plt.close()
85 fobj = open("plots/" + name + ".out", "w")
86 for i in t:
87 fobj.write(
88 optlevel[i]
89 + "&"
90 + str(n[i])
91 + "&"
92 + str(f"{value[i]:.3f}")
93 + " & "
94 + str(f"{sigma[i]:.3f}")
95 + "&"
96 + str(f"{valuenormed[i]:.4f}")
97 + "&"
98 + str(f"{sigmanormed[i]:.4f}")
99 + "\\\\\n"
100 )
101 fobj.write(r"\hline\n")
102
103
104name = "CDCLegendreTracking"
105optlevel = ["gcc-O0", "gcc-O3", "gcc-O3-native"]
106read(optlevel, 0, name)