-
Notifications
You must be signed in to change notification settings - Fork 8
Fit zgamma #36
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
Draft
gabihamilton
wants to merge
9
commits into
DAZSLE:main
Choose a base branch
from
gabihamilton:fit-gabi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Fit zgamma #36
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c174c59
update ignore
gabihamilton e557843
adapting to zgamma
gabihamilton 895b7ce
fix ruff linting errors
gabihamilton 383b18b
fixing background to gjets
gabihamilton 403302f
checking if histos correspond to my previous plots
gabihamilton ba8d5f0
check plot
gabihamilton d46f7e6
aligning categories
gabihamilton 6af9b7c
script for checking plot
gabihamilton edc0bc2
final zgamma fitting pipeline
gabihamilton 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,4 +22,5 @@ nobackup/ | |
| fitting/results/ | ||
| fitting/templates/ | ||
| plots/ | ||
| *.txt | ||
| *.ipynb_checkpoints/ | ||
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 |
|---|---|---|
|
|
@@ -2,27 +2,35 @@ | |
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import hist | ||
| import json | ||
| import os | ||
| import uproot | ||
|
|
||
| from hbb import utils | ||
|
|
||
|
|
||
| def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true): | ||
|
|
||
| h = hist.Hist(hist.axis.Regular(obs_cfg["nbins"], obs_cfg["min"], obs_cfg["max"], name=obs_cfg["name"], label=obs_cfg["name"])) | ||
| h = hist.Hist( | ||
| hist.axis.Regular( | ||
| obs_cfg["nbins"], | ||
| obs_cfg["min"], | ||
| obs_cfg["max"], | ||
| name=obs_cfg["name"], | ||
| label=obs_cfg["name"], | ||
| ) | ||
| ) | ||
|
|
||
| bins_list = reg_cfg["bins"] | ||
| bin_pname = reg_cfg["bin_pname"] | ||
| str_bin_br = reg_cfg["branch_name"] | ||
|
|
||
| for _process_name, data in events.items(): | ||
|
|
||
| #TODO add in systematics functionality | ||
| # TODO add in systematics functionality | ||
| weight_val = data["finalWeight"].astype(float) | ||
| s = "nominal" | ||
|
|
||
|
|
@@ -37,17 +45,17 @@ def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true): | |
| pre_selection = (obs_br > obs_cfg["min"]) & (obs_br < obs_cfg["max"]) | ||
|
|
||
| selection_dict = { | ||
| "pass_bb": pre_selection & (Txbbxcc > 0.95) & (Txbb > Txcc), | ||
| "pass_cc": pre_selection & (Txbbxcc > 0.95) & (Txcc > Txbb), | ||
| "pass_bb": pre_selection & (Txbbxcc > 0.95) & (Txbb > Txcc), | ||
| "pass_cc": pre_selection & (Txbbxcc > 0.95) & (Txcc > Txbb), | ||
| "fail": pre_selection & (Txbbxcc <= 0.95), | ||
| "pass": pre_selection & (Txbbxcc > 0.95) | ||
| "pass": pre_selection & (Txbbxcc > 0.95), | ||
| } | ||
|
|
||
| cut_bb = (genf == 3) | ||
| cut_bb = genf == 3 | ||
| cut_qq = (genf > 0) & (genf < 3) | ||
|
|
||
| for i in range(len(bins_list) - 1): | ||
| bin_cut = (bin_br > bins_list[i]) & (bin_br < bins_list[i+1]) & pre_selection | ||
| bin_cut = (bin_br > bins_list[i]) & (bin_br < bins_list[i + 1]) & pre_selection | ||
|
|
||
| for category, selection in selection_dict.items(): | ||
| if qq_true: | ||
|
|
@@ -57,7 +65,7 @@ def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true): | |
| obs_br[selection & bin_cut & cut_qq], | ||
| weight=weight_val[selection & bin_cut & cut_qq], | ||
| ) | ||
| if not name in outdict: | ||
| if name not in outdict: | ||
| outdict[name] = h.copy() | ||
| else: | ||
| outdict[name] += h.copy() | ||
|
|
@@ -68,7 +76,7 @@ def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true): | |
| obs_br[selection & bin_cut & cut_bb], | ||
| weight=weight_val[selection & bin_cut & cut_bb], | ||
| ) | ||
| if not name in outdict: | ||
| if name not in outdict: | ||
| outdict[name] = h.copy() | ||
| else: | ||
| outdict[name] += h.copy() | ||
|
|
@@ -80,20 +88,22 @@ def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true): | |
| obs_br[selection & bin_cut], | ||
| weight=weight_val[selection & bin_cut], | ||
| ) | ||
| if not name in outdict: | ||
| if name not in outdict: | ||
| outdict[name] = h.copy() | ||
| else: | ||
| outdict[name] += h.copy() | ||
| return outdict | ||
|
|
||
|
|
||
| def main(args): | ||
| year = args.year | ||
| tag = args.tag | ||
|
|
||
| path_to_dir = f"/eos/uscms/store/group/lpchbbrun3/skims/{tag}" | ||
|
|
||
| samples_qq = ['Wjets','Zjets','EWKW','EWKZ','EWKV'] | ||
|
|
||
| # path_to_dir = f"/eos/uscms/store/group/lpchbbrun3/skims/{tag}" | ||
| path_to_dir = f"/eos/uscms/store/group/lpchbbrun3/gmachado/{tag}" | ||
|
|
||
| samples_qq = ["Wjets", "Zjets", "EWKW", "EWKZ", "EWKV"] | ||
|
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. I think that you need to change |
||
|
|
||
| columns = [ | ||
| "weight", | ||
| "FatJet0_pt", | ||
|
|
@@ -110,31 +120,31 @@ def main(args): | |
| out_path = f"results/{tag}/{year}" | ||
| output_file = f"{out_path}/signalregion.root" | ||
|
|
||
| if not os.path.exists(out_path): | ||
| os.makedirs(out_path) | ||
| if not Path(out_path).exists(): | ||
| Path(out_path).mkdir(parents=True) | ||
|
|
||
| if os.path.isfile(output_file): | ||
| os.remove(output_file) | ||
| if Path(output_file).is_file(): | ||
| Path(output_file).unlink() | ||
| fout = uproot.create(output_file) | ||
|
|
||
| # So I can remember the settings I used for each set of results produced | ||
| os.popen(f'cp setup.json {out_path}') | ||
| with open('setup.json') as f: | ||
| os.popen(f"cp setup.json {out_path}") | ||
| with Path("setup.json").open() as f: | ||
| setup = json.load(f) | ||
| cats = setup["categories"] | ||
| obs_cfg = setup["observable"] | ||
|
|
||
| with open('pmap_run3.json') as f: | ||
| with Path("pmap_run3.json").open() as f: | ||
| pmap = json.load(f) | ||
|
|
||
| filters = [ | ||
| ("FatJet0_pt", ">", 450), | ||
| ("FatJet0_pt", "<", 1200), | ||
| ("VBFPair_mjj", ">", -2), | ||
| ("VBFPair_mjj", "<", 13000), | ||
| ("FatJet0_pt", ">", 450), | ||
| ("FatJet0_pt", "<", 1200), | ||
| ("VBFPair_mjj", ">", -2), | ||
| ("VBFPair_mjj", "<", 13000), | ||
| ] | ||
|
|
||
| if not obs_cfg["branch_name"] in columns: | ||
| if obs_cfg["branch_name"] not in columns: | ||
| columns.append(obs_cfg["branch_name"]) | ||
|
|
||
| out_hists = {} | ||
|
|
@@ -148,7 +158,7 @@ def main(args): | |
| {process: [dataset]}, | ||
| columns=columns, | ||
| region=cfg["name"], | ||
| filters=filters | ||
| filters=filters, | ||
| ) | ||
|
|
||
| if not events: | ||
|
|
@@ -161,6 +171,7 @@ def main(args): | |
|
|
||
| print(f"Histograms saved to {output_file}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description="Make histograms for a given year.") | ||
| parser.add_argument( | ||
|
|
@@ -170,12 +181,7 @@ def main(args): | |
| required=True, | ||
| choices=["2022", "2022EE", "2023", "2023BPix"], | ||
| ) | ||
| parser.add_argument( | ||
| "--tag", | ||
| help="tag", | ||
| type=str, | ||
| required=True | ||
| ) | ||
| parser.add_argument("--tag", help="tag", type=str, required=True) | ||
| args = parser.parse_args() | ||
|
|
||
| main(args) | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.