6 <contact>software-tracking@belle2.org</contact>
7 <output>fullTrackingValidationTable.root</output>
8 <input>matching_validation.root</input>
9 <description>This module generates events for the validation using the full tracking with a tabular output.</description>
13 from ROOT
import TFile, TNamed, Belle2
15 VALIDATION_OUTPUT_FILE =
"fullTrackingTableValidation.root"
19 from root_pandas
import read_root
22 basf2.B2FATAL(
"You need to have pandas installed for this validation script to run.")
24 FORMAT_STRING =
" {:.2%} <br/> -{:.2%} <br/> <b>-{:.2%}</b> <br/> Matching: {:.2%} <br/> CDC: {:.2%} <br/> VXD: {:.2%}"
25 SHORT_FORMAT_STRING =
"MC: {:.2%} <br/>Missing: -{:.2%} <br/>Missing and !fit: <b>-{:.2%}</b>"
28 def reducelist(list_of_cuts, df, current_name=None, current_cut=None, x=0, y=0):
29 if current_name
is not None:
31 return_string = FORMAT_STRING.format(current_cut.mean(),
32 (current_cut & (df.is_matched == 0)).mean(),
33 (current_cut & (df.fitted_is_matched == 0)).mean(),
34 (current_cut & (df.both_related == 1)).mean(),
35 (current_cut & (df.cdc_has_related == 1)).mean(),
36 (current_cut & (df.vxd_has_related == 1)).mean())
38 return_string = SHORT_FORMAT_STRING.format(current_cut.mean(),
39 (current_cut & (df.is_matched == 0)).mean(),
40 (current_cut & (df.fitted_is_matched == 0)).mean())
41 yield (y, x, current_name), return_string
46 name, cut = list_of_cuts[0]
51 return x.is_missing == x.is_missing
53 if current_name
is None:
54 yield from reducelist(list_of_cuts[1:], df, name, cut(df),
55 x + 2 ** (len(list_of_cuts) - 1), y + 1)
57 yield from reducelist(list_of_cuts[1:], df, current_name +
"_no_" + name, current_cut & (~cut(df)),
59 yield from reducelist(list_of_cuts[1:], df, current_name +
"_" + name, current_cut & (cut(df)),
60 x + 2 ** (len(list_of_cuts) - 1), y + 1)
63 def make_chunks(l, n):
64 return [l[i:i + n]
for i
in range(0, len(l), n)]
67 def write_value_cell(key, value):
69 colspan = 2 ** int(5 - y)
72 3: [
"white",
"gray",
"orange",
"green"],
73 4: [
"gray",
"white",
"gray",
"gray",
74 "orange",
"orange",
"green",
"green"],
75 5: [
"gray",
"gray",
"red",
"green",
76 "gray",
"gray",
"gray",
"gray",
77 "red",
"gray",
"red",
"orange",
78 "green",
"gray",
"orange",
"green"]
82 color_index = int((x - 2 ** 4) / (2 ** (5 - y)))
83 color = colors[y][color_index]
88 <td style="border: 1px solid black" colspan={colspan}
89 align="center" valign=middle bgcolor="{color}">{value}</td>
90 """.format(colspan=colspan, color=color, value=value)
94 keys = [key
for key, _
in x.iteritems()]
95 titles = [key[2]
for key, _
in x.iteritems()]
96 values = [value
for _, value
in x.iteritems()]
98 chunked_titles = make_chunks(titles, 2)
99 common_prefixes = list(map(os.path.commonprefix, chunked_titles))
101 shorter_titles = [title.replace(prefix,
"").replace(
"_",
" ")
102 for list_titles, prefix
in zip(chunked_titles, common_prefixes)
103 for title
in list_titles]
105 row_content =
"".join([write_value_cell(key, value)
for key, value
in zip(keys, shorter_titles)])
106 html =
"<tr>" + row_content +
"</tr>"
108 row_content =
"".join([write_value_cell(key, value)
for key, value
in x.sort_index().iteritems()])
109 html +=
"<tr>" + row_content +
"</tr>"
114 def get_html(df, test):
115 results = pd.DataFrame(dict(reducelist(test, df)), index=[0]).unstack()
117 last_row_titles = [
"",
"",
"CDCTF may help",
"Criteria?",
"",
"",
"",
"",
"VXDTF may help",
"",
118 "hard cases",
"CKF may help",
"Criteria?",
"",
"CKF may help",
"Merging"]
121 html +=
"".join(results.groupby(level=0).apply(make_html_row))
122 html +=
"<tr>" + (
"".join([
"<td>" + value +
"</td>" for value
in last_row_titles])) +
"</tr>"
128 if __name__ ==
'__main__':
132 (
"has_vxd",
lambda x: (x.n_svd_hits >= 2)),
133 (
"vxd_was_found",
lambda x: x[
"vxd_was_found"] == 1),
134 (
"has_cdc",
lambda x: x.n_cdc_hits >= 3),
135 (
"cdc_was_found",
lambda x: x[
"cdc_was_found"] == 1),
138 df = read_root(
"../matching_validation.root")
139 html = get_html(df, test)
141 tfile = TFile(VALIDATION_OUTPUT_FILE,
"RECREATE")
142 html_content = TNamed(
"Tracking Table Validation", html)