-
Notifications
You must be signed in to change notification settings - Fork 8
Alphabet and param scan dev #89
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d531b06
Stop tracking userConfig.py (local config)
billy000400 c8ce780
update git ignore
billy000400 bdbf1d1
add userConfig back but enable project name and user matching
billy000400 ad5dc8a
rm redundant code
billy000400 398063b
dev: enable sensitivity-dir CLI argument, project name matching
billy000400 fb3c002
comment: --sm-only does not change the sig injected into cards but ad…
billy000400 ad65253
add: helpful scripts
billy000400 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Extract QCD transfer factor values from FitShapes.root. | ||
| Usage: python scripts/extract_qcd_tf.py <FitShapes.root> [--region ggfbbtthmpass] | ||
| """ | ||
| import argparse | ||
| import sys | ||
|
|
||
| import numpy as np | ||
|
|
||
| try: | ||
| import uproot | ||
| except ImportError: | ||
| print("ERROR: uproot required. Install with: pip install uproot") | ||
| sys.exit(1) | ||
|
|
||
| QCD_KEY = "CMS_bbtautau_boosted_qcd_datadriven" | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("fit_shapes", help="Path to FitShapes.root") | ||
| parser.add_argument("--region", default="ggfbbtthmpass", help="Pass region (e.g. ggfbbtthmpass)") | ||
| args = parser.parse_args() | ||
|
|
||
| f = uproot.open(args.fit_shapes) | ||
| pass_region = args.region | ||
| fail_region = pass_region.replace("pass", "fail") | ||
|
|
||
| pass_dir = f"{pass_region}_postfit" | ||
| fail_dir = f"{fail_region}_postfit" | ||
|
|
||
| try: | ||
| pass_qcd = f[f"{pass_dir}/{QCD_KEY}"] | ||
| fail_qcd = f[f"{fail_dir}/{QCD_KEY}"] | ||
| except KeyError as e: | ||
| print(f"ERROR: {e}") | ||
| print("Available keys:", [k for k in f.keys() if "postfit" in k][:20]) | ||
| sys.exit(1) | ||
|
|
||
| pass_vals = np.array(pass_qcd.values()) | ||
| fail_vals = np.array(fail_qcd.values()) | ||
| axis = pass_qcd.axes[0] | ||
| edges = np.array(axis.edges()) if callable(getattr(axis, "edges", None)) else np.array(axis.edges) | ||
| centers = (edges[:-1] + edges[1:]) / 2 | ||
|
|
||
| tf = np.where(fail_vals > 0, pass_vals / fail_vals, np.nan) | ||
|
|
||
| print(f"QCD Transfer Factor: {pass_region} / {fail_region}") | ||
| print("=" * 50) | ||
| print(f"{'Bin center':>12} | {'TF':>12} | Pass QCD | Fail QCD") | ||
| print("-" * 50) | ||
| for i in range(len(centers)): | ||
| print(f"{centers[i]:12.4f} | {tf[i]:12.6e} | {pass_vals[i]:9.4e} | {fail_vals[i]:9.4e}") | ||
| print("-" * 50) | ||
| valid = ~np.isnan(tf) | ||
| if np.any(valid): | ||
| print(f"Min: {np.nanmin(tf):.6e} Max: {np.nanmax(tf):.6e} Mean: {np.nanmean(tf):.6e} Std: {np.nanstd(tf):.6e}") | ||
| cv = np.nanstd(tf) / np.nanmean(tf) * 100 if np.nanmean(tf) != 0 else 0 | ||
| print(f"Coefficient of variation: {cv:.2f}%") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
also here, why do you want to ignore
userConfig.py?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.
I wanted to leave UserConfig.py to every user. Basically, I wanted to improve it because the main user and repository path is hardcoded. I have found a more elegant way that automatically detects the current user and project path. It should be in the latest commit. Thanks for pointing it out!