6 import matplotlib.pyplot
as plt
9 filename_pattern =
"pwg-*-st2-stat.dat"
12 N_values = [50, 100,200,400,800,1000,1100,1200,1250,1260,1270,1275,1278,1279,1280]
20 file_list = glob.glob(filename_pattern)
23 empty_files = [f
for f
in file_list
if os.path.getsize(f) == 0]
24 file_list = [f
for f
in file_list
if f
not in empty_files]
27 num_empty_files = len(empty_files)
30 print(f
"Number of empty files: {num_empty_files}")
33 N_values = [N-num_empty_files
for N
in N_values]
35 print(
"N_values after subtracting empty files:")
39 results = {N: []
for N
in N_values}
43 for _
in range(num_repeats):
45 selected_files = random.sample(file_list,
min(N, len(file_list)))
51 for file_path
in selected_files:
52 with open(file_path,
'r')
as file:
55 match = re.search(
r"^ grand total total \(pos\.-\|neg\.\|\):\s+(\d+\.\d+|\d+)\s+\+-\s+(\d+\.\d+E[-+]\d+|\d+\.\d+)", line)
59 value_list.append(value)
63 quadrature_sum = np.sqrt(np.sum(np.array(value_list) ** 2))/len(value_list)
64 results[N].
append(quadrature_sum)
73 for file_path
in file_list:
74 with open(file_path,
'r')
as file:
77 match = re.search(
r"^ grand total total \(pos\.-\|neg\.\|\):\s+(\d+\.\d+|\d+)\s+\+-\s+(\d+\.\d+E[-+]\d+|\d+\.\d+)", line)
80 value =
float(match.group(2))
81 value_list.append(value)
85 upper_bound_value_list = value_list[-N:]
86 lower_bound_value_list = value_list[:N]
87 upper_bounds.append(np.sqrt(np.sum(np.array(upper_bound_value_list) ** 2))/len(upper_bound_value_list))
88 lower_bounds.append(np.sqrt(np.sum(np.array(lower_bound_value_list) ** 2))/len(lower_bound_value_list))
99 mean_values.append(np.mean(results[N]))
100 std_dev_values.append(np.std(results[N]))
103 plt.figure(figsize=(10, 6))
104 plt.plot(N_values,upper_bounds,label=
"upper bound")
105 plt.plot(N_values,lower_bounds,label=
"lower bound")
106 plt.errorbar(N_values, mean_values, yerr=std_dev_values, fmt=
'o-', capsize=5, label=
"x-sec uncertainty")
107 plt.fill_between(N_values,
108 np.array(mean_values) - np.array(std_dev_values),
109 np.array(mean_values) + np.array(std_dev_values),
110 alpha=0.2, color=
"blue", label=
"Error band (std dev)")
112 plt.xlabel(
"Number of files (N)")
113 plt.ylabel(
"x-sec uncertainty")
114 plt.title(
"x-sec with error band vs. N")
117 plt.savefig(
"sum_of_squares_vs_N"+plot_file_postfix+
".png", format=
"png", dpi=300, bbox_inches=
"tight")
120 plt.errorbar([N]*len(results[N]),results[N],fmt=
"o",color=
'darkgreen',markersize=2)
121 plt.savefig(
"sum_of_squares_vs_N_with_val"+plot_file_postfix+
".png", format=
"png", dpi=300, bbox_inches=
"tight")