27 """! Calculate and output integration grid quality.
29 Read in integration quality metrics from output files.
30 Allow any check to fail, since this output is not a critical part of generation.
32 @author James Robinson <james.robinson@cern.ch>
34 inclusive_xs, inclusive_xs_error, negative_weights, positive_weights, n_events, n_upper_bound_failures_xs, n_upper_bound_failures_radiation = 0, 0, 0, 0, 0, 0, 0
36 for file_name
in sum([glob.glob(_f)
for _f
in [
"pwgstat.dat",
"pwgstat-0001.dat",
"pwg-stat.dat",
"pwg-st3-0001-stat.dat",
"pwg-0001-st3-stat.dat"]], []):
38 with open(file_name,
"r")
as data_file:
40 matched_lines = [line.replace(
"+-",
"")
for line
in data_file
if re.match(
r"(.*)(btilde(.*)weights)(.*)[0-9](.*)\+\-(.*)[0-9](.*)", line)]
41 matched_lines = [re.sub(
" +",
" ", _l)
for _l
in matched_lines]
42 if len(matched_lines) > 0:
43 positive_weight_xs = sum([list(
map(float, re.findall(regex_match_floats, line)))
for line
in matched_lines
if "pos." in line],[])
44 negative_weight_xs = sum([list(
map(float, re.findall(regex_match_floats, line)))
for line
in matched_lines
if "|neg.|" in line], [])
45 inclusive_xs += positive_weight_xs[0] + negative_weight_xs[0]
46 inclusive_xs_error += math.sqrt(positive_weight_xs[1]**2 + negative_weight_xs[1]**2)
50 with open(file_name,
"r")
as data_file:
52 matched_lines = [line.replace(
"+-",
"")
for line
in data_file
if re.match(
r"(.*)(btilde(.*)weights|Remnant cross section)(.*)[0-9](.*)\+\-(.*)[0-9](.*)", line)]
53 matched_lines = [re.sub(
" +",
" ", _l)
for _l
in matched_lines]
54 if len(matched_lines) > 0:
55 negative_weights += list(
map(float, re.findall(regex_match_floats, [line
for line
in matched_lines
if "btilde |neg.|" in line][0])))[0]
56 positive_weights += list(
map(float, re.findall(regex_match_floats, [line
for line
in matched_lines
if "btilde pos." in line][0])))[0]
57 positive_weights += list(
map(float, re.findall(regex_match_floats, [line
for line
in matched_lines
if "Remnant cross section" in line][0])))[0]
61 file_names = sum([glob.glob(_f)
for _f
in [
"pwgcounters-st4-*.dat",
"pwgcounters0*.dat"]], [])
62 if not file_names: file_names = glob.glob(
"pwgcounters.dat")
63 for file_name
in file_names:
65 with open(file_name,
"r")
as data_file:
67 matched_lines = [line.replace(
"+-",
"")
for line
in data_file
if re.match(
r"(.*)(btilde event|remnant event|upper bound failure)(.*)[0-9](.*)", line)]
68 matched_lines = [re.sub(
" +",
" ", _l)
for _l
in matched_lines]
69 if len(matched_lines) > 0:
70 n_events += sum(list(
map(float, [re.findall(regex_match_floats, line)[0]
for line
in matched_lines
if "event" in line])))
71 n_upper_bound_failures_xs += sum(list(
map(float, [re.findall(regex_match_floats, line)[0]
for line
in matched_lines
if "upper bound failure in inclusive" in line])))
72 n_upper_bound_failures_radiation += sum(list(
map(float, [re.findall(regex_match_floats, line)[0]
for line
in matched_lines
if "upper bound failure in generation" in line])))
78 negative_weight_test =
safe_percentage(negative_weights, (negative_weights + positive_weights))
79 upper_bound_test =
safe_percentage((n_upper_bound_failures_xs + n_upper_bound_failures_radiation), n_events)
80 upper_bound_test_xs =
safe_percentage(n_upper_bound_failures_xs, n_events)
81 upper_bound_test_radiation =
safe_percentage(n_upper_bound_failures_radiation, n_events)
85 getattr(logger, [
"warning",
"info"][0.0 <= inclusive_xs_test < 1.0])(
"Integration test :: {:>30} : {:.2f}%".format(
"cross-section uncertainty", inclusive_xs_test))
86 getattr(logger, [
"warning",
"info"][0.0 <= negative_weight_test < 1.0])(
"Integration test :: {:>30} : {:.2f}%".format(
"negative weight fraction", negative_weight_test))
87 getattr(logger, [
"warning",
"info"][0.0 <= upper_bound_test < 1.0])(
"Integration test :: {:>30} : {:.2f}%".format(
"upper bound violations", upper_bound_test))
88 logger.info(
" -> {:>30} : {:.2f}%".format(
"in inclusive cross-section", upper_bound_test_xs))
89 logger.info(
" -> {:>30} : {:.2f}%".format(
"in generation of radiation", upper_bound_test_radiation))
90 if any((inclusive_xs_test < 0.0, inclusive_xs_test >= 1.0, negative_weight_test < 0.0, negative_weight_test >= 1.0, upper_bound_test < 0.0, upper_bound_test >= 1.0)):
91 logger.warning(
"Not all integration tests passed. Please ensure that physics validation is done before using this sample!")
integration_grid_tester()
Calculate and output integration grid quality.