-
Notifications
You must be signed in to change notification settings - Fork 432
Update yr5 #1255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update yr5 #1255
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,31 +3,35 @@ | |
|
|
||
| import xlrd | ||
|
|
||
| stdHeading = ("mH_GeV", "XS_pb", "Sca_Hi", "Sca_Lo", "Pdf_alpha_s", "Pdf", "alpha_s") | ||
| from openpyxl import load_workbook | ||
|
|
||
| stdHeading = ("mH_GeV", "XS_pb", "Sca_Hi", "Sca_Lo", "Pdf_alpha_s", "Total_pos", "Total_neg") | ||
| xsecGroups = { | ||
| "ggH": {"col": "A", "heading": stdHeading}, | ||
| "VBF": {"col": "I", "heading": stdHeading}, | ||
| "WH": {"col": "Q", "heading": stdHeading + ("XS_WplusH_pb", "XS_WminusH_pb")}, | ||
| "ZH": {"col": "AA", "heading": stdHeading + ("XS_ggZH_pb",)}, | ||
| "ttH": {"col": "AJ", "heading": stdHeading}, | ||
| "ggH": {"col": "A", "heading": ("mH_GeV", "XS_pb", "Sca_Hi", "Sca_Lo", "Pdf_minus_TH","Gauss","Pdf_alpha_s", "Total_pos", "Total_neg")}, | ||
| "vbfH": {"col": "L", "heading": stdHeading}, | ||
| "WH": {"col": "T", "heading": stdHeading + ("XS_WplusH_pb", "XS_WminusH_pb")}, | ||
| "ZH": {"col": "AD", "heading": stdHeading + ("XS_ggZH_pb",)}, | ||
| "ttH": {"col": "AM", "heading": stdHeading}, | ||
| "bbH": { | ||
| "col": "AR", | ||
| "heading": ("mH_GeV", "XS_pb", "Sca_Pdf_mb_mub_Hi", "Sca_Pdf_mb_mub_Lo"), | ||
| "col": "AU", | ||
| "heading": ("mH_GeV", "XS_pb", "Sca_Hi", "Sca_Lo", "Pdf_as_mb", "Total_pos", "Total_neg"), | ||
| }, | ||
| "tH_tchan": {"col": "AZ", "heading": stdHeading + ("XS_tH_pb", "XS_tbarH_pb")}, | ||
| "tH_schan": {"col": "BJ", "heading": stdHeading + ("XS_tH_pb", "XS_tbarH_pb")}, | ||
| "tH_tchan": {"col": "BC", "heading": stdHeading + ("XS_tH_pb", "XS_tbarH_pb")}, | ||
| "tH_schan": {"col": "BM", "heading": stdHeading + ("XS_tH_pb", "XS_tbarH_pb")}, | ||
| "tHW" : {"col": "BW", "heading": stdHeading }, | ||
| "ggZH": {"col": "AD", "heading": ("mH_GeV", "SKIP", "SKIP", "SKIP", "SKIP", "SKIP", "SKIP", "XS_pb")}, | ||
| # 'total': {'col':'BT', 'heading':('XS_pb',)}, | ||
| "WminusH_lv": {"col": "BX", "heading": stdHeading + ("XS_gamma_pb",)}, | ||
| "WplusH_lv": {"col": "CG", "heading": stdHeading + ("XS_gamma_pb",)}, | ||
| "ZH_ll": {"col": "CP", "heading": stdHeading + ("XS_ggZH_pb", "XS_gamma_pb")}, | ||
| "ZH_vv": {"col": "CZ", "heading": stdHeading + ("XS_ggZH_pb", "XS_gamma_pb")}, | ||
| "VBF_qqH_schan": {"col": "DJ", "heading": ("mH_GeV", "XS_pb")}, | ||
| #"WminusH_lv": {"col": "BX", "heading": stdHeading + ("XS_gamma_pb",)}, | ||
| #"WplusH_lv": {"col": "CG", "heading": stdHeading + ("XS_gamma_pb",)}, | ||
| #"ZH_ll": {"col": "CP", "heading": stdHeading + ("XS_ggZH_pb", "XS_gamma_pb")}, | ||
| #"ZH_vv": {"col": "CZ", "heading": stdHeading + ("XS_ggZH_pb", "XS_gamma_pb")}, | ||
| #"VBF_qqH_schan": {"col": "DJ", "heading": ("mH_GeV", "XS_pb")}, | ||
| } | ||
|
|
||
| reducedHeading = ("mH_GeV", "XS_pb", "Sca_Hi", "Sca_Lo", "Pdf_alpha_s") | ||
| xsecGroupsBSM = { | ||
| "ggH": {"col": "A", "heading": stdHeading + ("1_plus_dEW",)}, | ||
| "VBF": {"col": "J", "heading": stdHeading}, | ||
| "vbfH": {"col": "J", "heading": stdHeading}, | ||
| "WH": {"col": "S", "heading": reducedHeading}, | ||
| "ZH": {"col": "AD", "heading": reducedHeading}, | ||
| "bbH": { | ||
|
|
@@ -39,39 +43,43 @@ | |
| } | ||
|
|
||
| specs = { | ||
| "YR4 SM 7TeV": { | ||
| "7 TeV": { | ||
| "rows": (6, 43), | ||
| "groups": xsecGroups, | ||
| }, | ||
| "8 TeV": { | ||
| "rows": (6, 43), | ||
| "groups": xsecGroups, | ||
| }, | ||
| "YR4 SM 8TeV": { | ||
| "13 TeV": { | ||
| "rows": (6, 43), | ||
| "groups": xsecGroups, | ||
| }, | ||
| "YR4 SM 13TeV": { | ||
| "13.6 TeV": { | ||
| "rows": (6, 43), | ||
| "groups": xsecGroups, | ||
| }, | ||
| "YR4 SM 14TeV": { | ||
| "14 TeV": { | ||
| "rows": (6, 43), | ||
| "groups": xsecGroups, | ||
| }, | ||
| "YR4 BSM 7TeV": { | ||
| "BSM 7TeV": { | ||
| "rows": (6, 119), | ||
| "groups": xsecGroupsBSM, | ||
| }, | ||
| "YR4 BSM 8TeV": { | ||
| "BSM 8TeV": { | ||
| "rows": (6, 119), | ||
| "groups": xsecGroupsBSM, | ||
| }, | ||
| "YR4 BSM 13TeV": { | ||
| "BSM 13TeV": { | ||
| "rows": (6, 119), | ||
| "groups": xsecGroupsBSM, | ||
| }, | ||
| "YR4 BSM 14TeV": { | ||
| "BSM 14TeV": { | ||
| "rows": (6, 119), | ||
| "groups": xsecGroupsBSM, | ||
| }, | ||
| "YR4 SM BR": { | ||
| "SM BR": { | ||
| "rows": (7, 44), | ||
| "groups": { | ||
| "BR1": { | ||
|
|
@@ -185,11 +193,18 @@ | |
|
|
||
|
|
||
| # import prettytable | ||
| def print_table(table): | ||
| def print_table(table, save_file=None): | ||
| col_width = [max(len(x) for x in col) for col in zip(*table)] | ||
| for line in table: | ||
| print(" ".join("{:{}}".format(x, col_width[i]) for i, x in enumerate(line))) | ||
|
|
||
| # if given option, save_file, then also save to the file given too | ||
| if save_file is not None: | ||
| with open(save_file, "w") as f: | ||
| for line in table: | ||
| f.write(" ".join("{:{}}".format(x, col_width[i]) for i, x in enumerate(line)) + "\n") | ||
| print(f"Saved table to {save_file}") | ||
|
|
||
|
|
||
| # Based on http://stackoverflow.com/a/12640614/665025 | ||
| def col2num(col_str): | ||
|
|
@@ -202,22 +217,68 @@ def col2num(col_str): | |
| return col_num | ||
|
|
||
|
|
||
| # import urllib2 | ||
| # response = urllib2.urlopen('https://twiki.cern.ch/twiki/pub/LHCPhysics/CERNYellowReportPageAt8TeV/Higgs_XSBR_YR3.xlsx') | ||
| # f = xlrd.open_workbook(file_contents=response.read()) | ||
| def find_filename(sheet_name, group_name): | ||
| # given the sheet name and group name, find which of the dictionary keys match | ||
| # and return the filename in the format sm/xs/{sheet_name}/{group_name}.txt | ||
| for key in specs.keys(): | ||
| if key in sheet_name: | ||
| for group_key in specs[key]["groups"].keys(): | ||
| if group_key in group_name: | ||
| if "BR" in group_key: | ||
| filename = f"sm/br/{group_name}.txt" | ||
| else: | ||
| xsfoldername = sheet_name.replace(" ", "") | ||
| filename = f"sm/xs/{xsfoldername}/{xsfoldername}-{group_name}.txt" | ||
| return filename | ||
|
|
||
| ############################# openpyxl wrappers | ||
| class OpenPyXLSheet(object): | ||
| def __init__(self, ws): | ||
| self.name = ws.title | ||
| # values_only=True returns plain Python values; normalize None to '' | ||
| self._rows = [list(row) for row in ws.iter_rows(values_only=True)] | ||
|
|
||
| def row_values(self, idx): | ||
| row = self._rows[idx] | ||
| return ["" if v is None else v for v in row] | ||
|
|
||
|
|
||
| class OpenPyXLBook(object): | ||
| def __init__(self, wb): | ||
| self._sheets = [OpenPyXLSheet(ws) for ws in wb.worksheets] | ||
|
|
||
| def sheets(self): | ||
| return self._sheets | ||
|
|
||
|
|
||
| def open_workbook(path): | ||
| if path.lower().endswith(".xlsx"): | ||
| wb = load_workbook(filename=path, data_only=True, read_only=True) | ||
| return OpenPyXLBook(wb) | ||
|
|
||
| if xlrd is None: | ||
| raise RuntimeError("Legacy .xls input requires xlrd, but xlrd is not installed.") | ||
|
|
||
| return xlrd.open_workbook(path) | ||
| ################################################## | ||
|
|
||
| def formatval(v): | ||
| try: | ||
| # This is to remove pesky unicode symbols like \pm | ||
| v = float(v.encode("ascii", "ignore")) | ||
| except AttributeError: | ||
| pass | ||
| # want to have at most 4 decimal digits. | ||
| v = round(v, 4) | ||
| return "{:+}".format(v) | ||
|
|
||
|
|
||
| def main(o): | ||
| f = xlrd.open_workbook(o.input) | ||
| try: | ||
| f = xlrd.open_workbook(o.input) | ||
| except: | ||
| f = open_workbook(o.input) ## openpyxl | ||
|
Comment on lines
+277
to
+280
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bare The bare 🐛 Proposed fix to catch specific exceptions try:
f = xlrd.open_workbook(o.input)
- except:
+ except (xlrd.XLRDError, FileNotFoundError, PermissionError):
f = open_workbook(o.input) ## openpyxlOr if xlrd may not be installed: try:
f = xlrd.open_workbook(o.input)
- except:
+ except Exception as e:
+ logging.debug("xlrd failed (%s), trying openpyxl", e)
f = open_workbook(o.input) ## openpyxl🧰 Tools🪛 Ruff (0.15.15)[error] 279-279: Do not use bare (E722) 🤖 Prompt for AI Agents |
||
|
|
||
| for s in f.sheets(): | ||
| try: | ||
| spec = specs[s.name] | ||
|
|
@@ -231,21 +292,28 @@ def main(o): | |
| # open output | ||
| # dump heading | ||
| heading = props["heading"] | ||
| table.append(heading) | ||
| real_heading = [h for h in heading if h != "SKIP"] | ||
| table.append(real_heading) | ||
| startRow, endRow = spec["rows"] | ||
| for r in range(startRow - 1, endRow): | ||
| offset = col2num(props["col"]) - 1 | ||
| vals = s.row_values(r)[offset : offset + len(heading)] | ||
| # remove headers that say "SKIP" | ||
| vals_keep = [] | ||
| for i, v in enumerate(vals): | ||
| if heading[i] == "SKIP": | ||
| continue | ||
| vals_keep.append(v) | ||
| if set(vals[1:]) == set(("",)): | ||
| continue | ||
| try: | ||
| table.append(list(map(formatval, vals))) | ||
| table.append(list(map(formatval, vals_keep))) | ||
| except ValueError: | ||
| print("Could not parse the followig tuple: ") | ||
| print(vals) | ||
| print(vals_keep) | ||
| raise | ||
|
|
||
| print_table(table) | ||
| file_name=find_filename(s.name,group) | ||
| print_table(table, save_file=file_name) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
@@ -261,6 +329,12 @@ def main(o): | |
| metavar="LEVEL", | ||
| help="Set the minimum logging level.", | ||
| ) | ||
| parser.add_option( | ||
| "-s", | ||
| "--savefiles", | ||
| action="store_true", | ||
| help="Whether to save the tables to files in the sm directory.", | ||
| ) | ||
|
|
||
| o, args = parser.parse_args() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| mH_GeV XS_pb Sca_Hi Sca_Lo Pdf_alpha_s Total_pos Total_neg XS_WplusH_pb XS_WminusH_pb | ||
| +120.0 +1.6729 +0.459 -0.726 +1.844 +1.9003 -1.9818 +1.0233 +0.6496 | ||
| +122.0 +1.5868 +0.466 -0.729 +1.848 +1.9058 -1.9866 +0.9714 +0.6154 | ||
| +124.0 +1.5062 +0.48 -0.739 +1.855 +1.9161 -1.9968 +0.9227 +0.5834 | ||
| +124.6 +1.483 +0.467 -0.744 +1.862 +1.9197 -2.0051 +0.9088 +0.5742 | ||
| +124.8 +1.4755 +0.468 -0.746 +1.868 +1.9257 -2.0115 +0.9042 +0.5712 | ||
| +125.0 +1.4678 +0.477 -0.739 +1.876 +1.9357 -2.0163 +0.8995 +0.5682 | ||
| +125.09 +1.4643 +0.479 -0.738 +1.868 +1.9284 -2.0085 +0.8975 +0.5668 | ||
| +125.2 +1.4602 +0.486 -0.732 +1.876 +1.9379 -2.0138 +0.895 +0.5652 | ||
| +125.3 +1.4565 +0.478 -0.741 +1.871 +1.9311 -2.0124 +0.8927 +0.5637 | ||
| +125.38 +1.4534 +0.478 -0.736 +1.87 +1.9301 -2.0096 +0.891 +0.5625 | ||
| +125.6 +1.4451 +0.485 -0.738 +1.865 +1.927 -2.0057 +0.8859 +0.5593 | ||
| +126.0 +1.4303 +0.482 -0.741 +1.863 +1.9243 -2.005 +0.8769 +0.5534 | ||
| +128.0 +1.3591 +0.488 -0.749 +1.878 +1.9404 -2.0219 +0.8339 +0.5252 | ||
| +130.0 +1.2922 +0.508 -0.753 +1.88 +1.9474 -2.0252 +0.7934 +0.4988 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| mH_GeV XS_pb Sca_Hi Sca_Lo Pdf_alpha_s Total_pos Total_neg XS_ggZH_pb | ||
| +120.0 +1.066 +2.7 -2.5 +1.63 +3.1539 -2.9844 +0.1376 | ||
| +122.0 +1.017 +2.8 -2.6 +1.64 +3.2449 -3.074 +0.1348 | ||
| +124.0 +0.9707 +2.8 -2.6 +1.63 +3.2399 -3.0687 +0.1319 | ||
| +124.6 +0.9574 +2.8 -2.6 +1.63 +3.2399 -3.0687 +0.1311 | ||
| +124.8 +0.9531 +2.9 -2.6 +1.64 +3.3316 -3.074 +0.1308 | ||
| +125.0 +0.9488 +2.8 -2.6 +1.66 +3.2551 -3.0847 +0.1305 | ||
| +125.09 +0.9468 +2.9 -2.6 +1.62 +3.3218 -3.0634 +0.1304 | ||
| +125.2 +0.9443 +2.9 -2.6 +1.62 +3.3218 -3.0634 +0.1302 | ||
| +125.3 +0.9421 +2.9 -2.6 +1.62 +3.3218 -3.0634 +0.1301 | ||
| +125.38 +0.9405 +2.9 -2.6 +1.62 +3.3218 -3.0634 +0.13 | ||
| +125.6 +0.9357 +2.9 -2.6 +1.62 +3.3218 -3.0634 +0.1297 | ||
| +126.0 +0.9272 +2.9 -2.7 +1.64 +3.3316 -3.1591 +0.1291 | ||
| +128.0 +0.8859 +3.0 -2.7 +1.63 +3.4142 -3.1539 +0.1263 | ||
| +130.0 +0.8469 +3.0 -2.7 +1.63 +3.4142 -3.1539 +0.1235 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| mH_GeV XS_pb Sca_Hi Sca_Lo Pdf_as_mb Total_pos Total_neg | ||
| +120.0 +0.648 +8.8 -8.8 +3.4 +9.4 -9.4 | ||
| +122.0 +0.615 +8.7 -8.7 +3.4 +9.4 -9.4 | ||
| +124.0 +0.584 +8.7 -8.7 +3.4 +9.3 -9.3 | ||
| +124.6 +0.575 +8.6 -8.6 +3.4 +9.3 -9.3 | ||
| +124.8 +0.572 +8.6 -8.6 +3.4 +9.3 -9.3 | ||
| +125.0 +0.569 +8.6 -8.6 +3.4 +9.3 -9.3 | ||
| +125.09 +0.568 +8.6 -8.6 +3.4 +9.3 -9.3 | ||
| +125.2 +0.566 +8.6 -8.6 +3.4 +9.3 -9.3 | ||
| +125.3 +0.565 +8.6 -8.6 +3.4 +9.3 -9.3 | ||
| +125.38 +0.563 +8.6 -8.6 +3.4 +9.3 -9.3 | ||
| +125.6 +0.561 +8.6 -8.6 +3.5 +9.3 -9.3 | ||
| +126.0 +0.555 +8.6 -8.6 +3.5 +9.3 -9.3 | ||
| +128.0 +0.528 +8.5 -8.5 +3.5 +9.2 -9.2 | ||
| +130.0 +0.502 +8.5 -8.5 +3.5 +9.2 -9.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The notes still describe removed
tHWinputs.This migration switches the supported tH channels to
tH_schan/tH_tchan, anddata/lhc-hxswg/sm/makeAllSMSplines.Cno longer buildstHW. Keeping this YR4-specific note here will send readers to the wrong inputs for YR5.🧰 Tools
🪛 LanguageTool
[grammar] ~15-~15: Ensure spelling is correct
Context: ...lue at 125.0 GeV. This is only to allow bulding a spline. These numbers are from YR4 - ...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🪛 markdownlint-cli2 (0.22.1)
[warning] 18-18: Link text should be descriptive
(MD059, descriptive-link-text)
🤖 Prompt for AI Agents