Skip to content

Commit

Permalink
fix: add pv hists
Browse files Browse the repository at this point in the history
  • Loading branch information
Ming-Yan committed Feb 14, 2024
1 parent bf16c52 commit 8ee9f5d
Show file tree
Hide file tree
Showing 30 changed files with 336 additions and 183 deletions.
5 changes: 4 additions & 1 deletion condor/execute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ OPTS="--wf ${ARGS[workflow]} --year ${ARGS[year]} --campaign ${ARGS[campaign]} -
if [ "${ARGS[voms]}" != "null" ]; then
OPTS="$OPTS --voms ${ARGS[voms]}"
fi
for key in isSyst isArray noHist overwrite skipbadfiles; do
if [ "${ARGS[isSyst]}" != "null" ]; then
OPTS="$OPTS --isSyst ${ARGS[isSyst]}"
fi
for key in isArray noHist overwrite skipbadfiles; do
if [ "${ARGS[$key]}" == true ]; then
OPTS="$OPTS --$key"
fi
Expand Down
Binary file modified src/BTVNanoCommissioning/data/JME/Summer22Run3/jec_compiled.pkl.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 15 additions & 2 deletions src/BTVNanoCommissioning/utils/AK4_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,31 @@
},
"Summer23": {
"lumiMask": "Cert_Collisions2023_366442_370790_Golden.json",
# "PU": "puweight_Summer22EERun3-80p0mb.histo.root", # 69.2mb
"PU": "puwei_Summer23.histo.root",
# "JME": "jec_compiled.pkl.gz",
"jetveto": {
"Run2023BC jetvetomap": "jetveto2023BC.histo.root"
}, # this is from Mikko https://indico.cern.ch/event/1315421/contributions/5532963/attachments/2697975/4683826/2023_08_16_jetvetomaps_v3.pdf
"JPCalib": {
"Run2023B-22Sep2023-v1": "calibeHistoWrite_Data2023B-22Sep2023.root",
"Run2023C-22Sep2023-v1": "calibeHistoWrite_Data2023C-22Sep2023_v1.root",
"Run2023C-22Sep2023-v2": "calibeHistoWrite_Data2023C-22Sep2023_v2.root",
"Run2023C-22Sep2023-v3": "calibeHistoWrite_Data2023C-22Sep2023_v3.root",
"Run2023C-22Sep2023-v4": "calibeHistoWrite_Data2023C-22Sep2023_v4.root",
"MC": "calibeHistoWrite_MC2023_Summer23.root",
},
},
"Summer23BPix": {
"lumiMask": "Cert_Collisions2023_366442_370790_Golden.json",
# "PU": "puweight_Summer22EERun3-80p0mb.histo.root", # 69.2mb
"PU": "puwei_Summer23BPix.histo.root",
# "JME": "jec_compiled.pkl.gz",
"jetveto": {
"Run2023D jetvetomap_bpix": "jetveto2023D.histo.root"
}, # this is from Mikko https://indico.cern.ch/event/1315421/contributions/5532963/attachments/2697975/4683826/2023_08_16_jetvetomaps_v3.pdf
"JPCalib": {
"Run2023D-22Sep2023-v1": "calibeHistoWrite_Data2023D-22Sep2023_v1.root",
"Run2023D-22Sep2023-v2": "calibeHistoWrite_Data2023D-22Sep2023_v2.root",
"MC": "calibeHistoWrite_MC2023_Summer23BPix.root",
},
},
}
4 changes: 1 addition & 3 deletions src/BTVNanoCommissioning/utils/correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def load_SF(campaign, syst=False):
]
elif str(filename).endswith(".json.gz"):
correct_map["PU"] = correctionlib.CorrectionSet.from_file(
importlib.resources.path(
f"BTVNanoCommissioning.data.PU.{campaign}", filename
)
str(filename)
)
elif str(filename).endswith(".histo.root"):
ext = extractor()
Expand Down
4 changes: 2 additions & 2 deletions src/BTVNanoCommissioning/utils/histogrammer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def histogrammer(events, workflow):
ptratio_axis = Hist.axis.Regular(50, 0, 1, name="ratio", label="ratio")
n_axis = Hist.axis.Integer(0, 10, name="n", label="N obj")
osss_axis = Hist.axis.IntCategory([1, -1], name="osss", label="OS(+)/SS(-)")
_hist_dict["npvs"] = Hist.Hist(npvs_axis, Hist.storage.Weight())
_hist_dict["pu"] = Hist.Hist(npvs_axis, Hist.storage.Weight())
_hist_dict["npvs"] = Hist.Hist(syst_axis, npvs_axis, Hist.storage.Weight())
_hist_dict["pu"] = Hist.Hist(syst_axis, npvs_axis, Hist.storage.Weight())
### Workflow specific
if "example" == workflow:
obj_list = [
Expand Down
21 changes: 15 additions & 6 deletions src/BTVNanoCommissioning/workflows/ctag_DY_valid_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ def process_shift(self, events, shift_name):
**_hist_event_dict,
}

if isRealData:
output["sumw"] = len(events)
else:
output["sumw"] = ak.sum(events.genWeight)
if shift_name is None:
if isRealData:
output["sumw"] = len(events)
else:
output["sumw"] = ak.sum(events.genWeight)

####################
# Selections #
Expand Down Expand Up @@ -381,9 +382,17 @@ def process_shift(self, events, shift_name):
output["z_eta"].fill(syst, flatten(sz.eta), weight=weight)
output["z_phi"].fill(syst, flatten(sz.phi), weight=weight)
output["z_mass"].fill(syst, flatten(sz.mass), weight=weight)
output["npvs"].fill(events[event_level].PV.npvs, weight=weight)
output["npvs"].fill(
syst,
ak.values_astype(events[event_level].PV.npvs, np.uint8),
weight=weight,
)
if not isRealData:
output["pu"].fill(events[event_level].Pileup.nTrueInt, weight=weight)
output["pu"].fill(
syst,
ak.values_astype(events[event_level].Pileup.nTrueInt, np.uint8),
weight=weight,
)
#######################
# Create root files #
#######################
Expand Down
49 changes: 31 additions & 18 deletions src/BTVNanoCommissioning/workflows/ctag_Wc_valid_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ def process_shift(self, events, shift_name):
**_hist_event_dict,
}

if isRealData:
output["sumw"] = len(events)
else:
output["sumw"] = ak.sum(events.genWeight)
if shift_name is None:
if isRealData:
output["sumw"] = len(events)
else:
output["sumw"] = ak.sum(events.genWeight)
####################
# Selections #
####################
Expand Down Expand Up @@ -375,7 +376,7 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
flatten(genflavor),
flatten(ak.values_astype(genflavor, np.uint8)),
flatten(ak.broadcast_arrays(osss, sjets["pt"])[0]),
flatten(sjets[histname]),
weight=flatten(
Expand All @@ -391,7 +392,11 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
flatten(ak.broadcast_arrays(smflav, spfcands["pt"])[0]),
flatten(
ak.broadcast_arrays(
ak.values_astype(smflav, np.uint8), spfcands["pt"]
)[0]
),
flatten(ak.broadcast_arrays(osss, spfcands["pt"])[0]),
flatten(spfcands[histname.replace("PFCands_", "")]),
weight=flatten(
Expand All @@ -404,7 +409,7 @@ def process_shift(self, events, shift_name):
elif "jet_" in histname and "mu" not in histname:
h.fill(
syst,
flatten(genflavor),
flatten(ak.values_astype(genflavor, np.uint8)),
flatten(ak.broadcast_arrays(osss, sjets["pt"])[0]),
flatten(sjets[histname.replace("jet_", "")]),
weight=flatten(ak.broadcast_arrays(weight, sjets["pt"])[0]),
Expand All @@ -422,15 +427,15 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
smflav,
ak.values_astype(smflav, np.uint8),
osss,
flatten(ssmu[histname.replace("soft_l_", "")]),
weight=weight,
)
elif "mujet_" in histname:
h.fill(
syst,
smflav,
ak.values_astype(smflav, np.uint8),
osss,
flatten(smuon_jet[histname.replace("mujet_", "")]),
weight=weight,
Expand All @@ -444,15 +449,15 @@ def process_shift(self, events, shift_name):
continue
h.fill(
syst="noSF",
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
discr=smuon_jet[histname.replace(f"_{i}", "")],
weight=weights.partial_weight(exclude=exclude_btv),
)
if not isRealData and "btag" in self.SF_map.keys():
h.fill(
syst=syst,
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
discr=smuon_jet[histname.replace(f"_{i}", "")],
weight=weight,
Expand All @@ -462,7 +467,7 @@ def process_shift(self, events, shift_name):
histname = histname.replace("Trans", "").replace(f"_{i}", "")
h.fill(
syst="noSF",
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
discr=1.0 / np.tanh(smuon_jet[histname]),
weight=weights.partial_weight(exclude=exclude_btv),
Expand All @@ -473,28 +478,28 @@ def process_shift(self, events, shift_name):
output["nsoftmu"].fill(syst, osss, nsoftmu, weight=weight)
output["hl_ptratio"].fill(
syst,
flav=genflavor[:, 0],
flav=ak.values_astype(genflavor[:, 0], np.uint8),
osss=osss,
ratio=shmu.pt / sjets[:, 0].pt,
weight=weight,
)
output["soft_l_ptratio"].fill(
syst,
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
ratio=ssmu.pt / smuon_jet.pt,
weight=weight,
)
output["dr_lmujetsmu"].fill(
syst,
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
dr=smuon_jet.delta_r(ssmu),
weight=weight,
)
output["dr_lmujethmu"].fill(
syst,
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
dr=smuon_jet.delta_r(shmu),
weight=weight,
Expand All @@ -512,9 +517,17 @@ def process_shift(self, events, shift_name):
output["w_mass"].fill(syst, osss, flatten(sw.mass), weight=weight)
output["MET_pt"].fill(syst, osss, flatten(smet.pt), weight=weight)
output["MET_phi"].fill(syst, osss, flatten(smet.phi), weight=weight)
output["npvs"].fill(events[event_level].PV.npvs, weight=weight)
output["npvs"].fill(
syst,
ak.values_astype(events[event_level].PV.npvs, np.uint8),
weight=weight,
)
if not isRealData:
output["pu"].fill(events[event_level].Pileup.nTrueInt, weight=weight)
output["pu"].fill(
syst,
ak.values_astype(events[event_level].Pileup.nTrueInt, np.uint8),
weight=weight,
)
#######################
# Create root files #
#######################
Expand Down
49 changes: 31 additions & 18 deletions src/BTVNanoCommissioning/workflows/ctag_dileptt_valid_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ def process_shift(self, events, shift_name):
**_hist_event_dict,
}

if isRealData:
output["sumw"] = len(events)
else:
output["sumw"] = ak.sum(events.genWeight)
if shift_name is None:
if isRealData:
output["sumw"] = len(events)
else:
output["sumw"] = ak.sum(events.genWeight)

####################
# Selections #
Expand Down Expand Up @@ -337,7 +338,7 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
flatten(genflavor),
flatten(ak.values_astype(genflavor, np.uint8)),
flatten(sjets[histname]),
weight=flatten(
ak.broadcast_arrays(
Expand All @@ -352,7 +353,11 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
flatten(ak.broadcast_arrays(smflav, spfcands["pt"])[0]),
flatten(
ak.broadcast_arrays(
ak.values_astype(smflav, np.uint8), spfcands["pt"]
)[0]
),
flatten(spfcands[histname.replace("PFCands_", "")]),
weight=flatten(
ak.broadcast_arrays(
Expand All @@ -364,7 +369,7 @@ def process_shift(self, events, shift_name):
elif "jet_" in histname and "mu" not in histname:
h.fill(
syst,
flatten(genflavor),
flatten(ak.values_astype(genflavor, np.uint8)),
flatten(sjets[histname.replace("jet_", "")]),
weight=flatten(ak.broadcast_arrays(weight, sjets["pt"])[0]),
)
Expand All @@ -383,14 +388,14 @@ def process_shift(self, events, shift_name):
elif "soft_l" in histname and not "ptratio" in histname:
h.fill(
syst,
smflav,
ak.values_astype(smflav, np.uint8),
flatten(softmu0[histname.replace("soft_l_", "")]),
weight=weight,
)
elif "lmujet_" in histname:
h.fill(
syst,
smflav,
ak.values_astype(smflav, np.uint8),
flatten(smuon_jet[histname.replace("lmujet_", "")]),
weight=weight,
)
Expand All @@ -403,14 +408,14 @@ def process_shift(self, events, shift_name):
continue
h.fill(
syst="noSF",
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
discr=smuon_jet[histname.replace(f"_{i}", "")],
weight=weights.partial_weight(exclude=exclude_btv),
)
if not isRealData and "btag" in self.SF_map.keys():
h.fill(
syst=syst,
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
discr=smuon_jet[histname.replace(f"_{i}", "")],
weight=weight,
)
Expand All @@ -420,31 +425,31 @@ def process_shift(self, events, shift_name):
output["nsoftmu"].fill(syst, nsoftmu, weight=weight)
output["hl_ptratio"].fill(
syst,
flav=genflavor[:, 0],
flav=ak.values_astype(genflavor[:, 0], np.uint8),
ratio=isomu0.pt / sjets[:, 0].pt,
weight=weight,
)
output["sl_ptratio"].fill(
syst,
flav=genflavor[:, 0],
flav=ak.values_astype(genflavor[:, 0], np.uint8),
ratio=isomu1.pt / sjets[:, 0].pt,
weight=weight,
)
output["soft_l_ptratio"].fill(
syst,
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
ratio=softmu0.pt / smuon_jet.pt,
weight=weight,
)
output["dr_lmujetsmu"].fill(
syst,
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
dr=smuon_jet.delta_r(softmu0),
weight=weight,
)
output["dr_lmujethmu"].fill(
syst,
flav=smflav,
flav=ak.values_astype(smflav, np.uint8),
dr=smuon_jet.delta_r(isomu0),
weight=weight,
)
Expand All @@ -455,9 +460,17 @@ def process_shift(self, events, shift_name):
output["z_mass"].fill(syst, flatten(sz.mass), weight=weight)
output["MET_pt"].fill(syst, flatten(smet.pt), weight=weight)
output["MET_phi"].fill(syst, flatten(smet.phi), weight=weight)
output["npvs"].fill(events[event_level].PV.npvs, weight=weight)
output["npvs"].fill(
syst,
ak.values_astype(events[event_level].PV.npvs, np.uint8),
weight=weight,
)
if not isRealData:
output["pu"].fill(events[event_level].Pileup.nTrueInt, weight=weight)
output["pu"].fill(
syst,
ak.values_astype(events[event_level].Pileup.nTrueInt, np.uint8),
weight=weight,
)
#######################
# Create root files #
#######################
Expand Down
Loading

0 comments on commit 8ee9f5d

Please sign in to comment.