Skip to content

Commit

Permalink
fix:axis
Browse files Browse the repository at this point in the history
  • Loading branch information
Ming-Yan committed Feb 15, 2024
1 parent 1f7f492 commit 19aace1
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 182 deletions.
116 changes: 77 additions & 39 deletions src/BTVNanoCommissioning/workflows/ctag_Wc_valid_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,12 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
flatten(ak.values_astype(genflavor, np.uint8)),
flatten(ak.broadcast_arrays(osss, sjets["pt"])[0]),
flatten(genflavor),
flatten(
ak.broadcast_arrays(
ak.values_astype(osss, np.uint8), sjets["pt"]
)[0]
),
flatten(sjets[histname]),
weight=flatten(
ak.broadcast_arrays(
Expand All @@ -392,12 +396,12 @@ 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"]
ak.values_astype(osss, np.uint8), spfcands["pt"]
)[0]
),
flatten(ak.broadcast_arrays(osss, spfcands["pt"])[0]),
flatten(spfcands[histname.replace("PFCands_", "")]),
weight=flatten(
ak.broadcast_arrays(
Expand All @@ -409,15 +413,19 @@ def process_shift(self, events, shift_name):
elif "jet_" in histname and "mu" not in histname:
h.fill(
syst,
flatten(ak.values_astype(genflavor, np.uint8)),
flatten(ak.broadcast_arrays(osss, sjets["pt"])[0]),
flatten(genflavor),
flatten(
ak.broadcast_arrays(
ak.values_astype(osss, np.uint8), sjets["pt"]
)[0]
),
flatten(sjets[histname.replace("jet_", "")]),
weight=flatten(ak.broadcast_arrays(weight, sjets["pt"])[0]),
)
elif "hl_" in histname and histname.replace("hl_", "") in shmu.fields:
h.fill(
syst,
osss,
ak.values_astype(osss, np.uint8),
flatten(shmu[histname.replace("hl_", "")]),
weight=weight,
)
Expand All @@ -427,16 +435,16 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
ak.values_astype(smflav, np.uint8),
osss,
smflav,
ak.values_astype(osss, np.uint8),
flatten(ssmu[histname.replace("soft_l_", "")]),
weight=weight,
)
elif "mujet_" in histname:
h.fill(
syst,
ak.values_astype(smflav, np.uint8),
osss,
smflav,
ak.values_astype(osss, np.uint8),
flatten(smuon_jet[histname.replace("mujet_", "")]),
weight=weight,
)
Expand All @@ -449,16 +457,16 @@ def process_shift(self, events, shift_name):
continue
h.fill(
syst="noSF",
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
flav=smflav,
osss=ak.values_astype(osss, 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=ak.values_astype(smflav, np.uint8),
osss=osss,
flav=smflav,
osss=ak.values_astype(osss, np.uint8),
discr=smuon_jet[histname.replace(f"_{i}", "")],
weight=weight,
)
Expand All @@ -467,56 +475,86 @@ def process_shift(self, events, shift_name):
histname = histname.replace("Trans", "").replace(f"_{i}", "")
h.fill(
syst="noSF",
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
flav=smflav,
osss=ak.values_astype(osss, np.uint8),
discr=1.0 / np.tanh(smuon_jet[histname]),
weight=weights.partial_weight(exclude=exclude_btv),
)

output["njet"].fill(syst, osss, njet, weight=weight)
output["nmujet"].fill(syst, osss, nmujet, weight=weight)
output["nsoftmu"].fill(syst, osss, nsoftmu, weight=weight)
output["njet"].fill(
syst, ak.values_astype(osss, np.uint8), njet, weight=weight
)
output["nmujet"].fill(
syst, ak.values_astype(osss, np.uint8), nmujet, weight=weight
)
output["nsoftmu"].fill(
syst, ak.values_astype(osss, np.uint8), nsoftmu, weight=weight
)
output["hl_ptratio"].fill(
syst,
flav=ak.values_astype(genflavor[:, 0], np.uint8),
osss=osss,
genflavor[:, 0],
np.uint8,
osss=ak.values_astype(osss, np.uint8),
ratio=shmu.pt / sjets[:, 0].pt,
weight=weight,
)
output["soft_l_ptratio"].fill(
syst,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
flav=smflav,
osss=ak.values_astype(osss, np.uint8),
ratio=ssmu.pt / smuon_jet.pt,
weight=weight,
)
output["dr_lmujetsmu"].fill(
syst,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
flav=smflav,
osss=ak.values_astype(osss, np.uint8),
dr=smuon_jet.delta_r(ssmu),
weight=weight,
)
output["dr_lmujethmu"].fill(
syst,
flav=ak.values_astype(smflav, np.uint8),
osss=osss,
flav=smflav,
osss=ak.values_astype(osss, np.uint8),
dr=smuon_jet.delta_r(shmu),
weight=weight,
)
output["dr_lmusmu"].fill(
syst, osss=osss, dr=shmu.delta_r(ssmu), weight=weight
syst,
osss=ak.values_astype(osss, np.uint8),
dr=shmu.delta_r(ssmu),
weight=weight,
)
output["z_pt"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(sz.pt), weight=weight
)
output["z_eta"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(sz.eta), weight=weight
)
output["z_phi"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(sz.phi), weight=weight
)
output["z_mass"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(sz.mass), weight=weight
)
output["w_pt"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(sw.pt), weight=weight
)
output["w_eta"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(sw.eta), weight=weight
)
output["w_phi"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(sw.phi), weight=weight
)
output["w_mass"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(sw.mass), weight=weight
)
output["MET_pt"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(smet.pt), weight=weight
)
output["MET_phi"].fill(
syst, ak.values_astype(osss, np.uint8), flatten(smet.phi), weight=weight
)
output["z_pt"].fill(syst, osss, flatten(sz.pt), weight=weight)
output["z_eta"].fill(syst, osss, flatten(sz.eta), weight=weight)
output["z_phi"].fill(syst, osss, flatten(sz.phi), weight=weight)
output["z_mass"].fill(syst, osss, flatten(sz.mass), weight=weight)
output["w_pt"].fill(syst, osss, flatten(sw.pt), weight=weight)
output["w_eta"].fill(syst, osss, flatten(sw.eta), weight=weight)
output["w_phi"].fill(syst, osss, flatten(sw.phi), weight=weight)
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(
syst,
events[event_level].PV.npvs,
Expand Down
34 changes: 16 additions & 18 deletions src/BTVNanoCommissioning/workflows/ctag_dileptt_valid_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ def process_shift(self, events, shift_name):
if not isRealData:
weights.add("genweight", events[event_level].genWeight)
par_flav = (sjets.partonFlavour == 0) & (sjets.hadronFlavour == 0)
genflavor = sjets.hadronFlavour + 1 * par_flav
genflavor = ak.values_astype(sjets.hadronFlavour + 1 * par_flav, int)
smpu = (smuon_jet.partonFlavour == 0) & (smuon_jet.hadronFlavour == 0)
smflav = 1 * smpu + smuon_jet.hadronFlavour
smflav = ak.values_astype(1 * smpu + smuon_jet.hadronFlavour, int)
if len(self.SF_map.keys()) > 0:
syst_wei = True if self.isSyst != False else False
if "PU" in self.SF_map.keys():
Expand Down Expand Up @@ -338,7 +338,7 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
flatten(ak.values_astype(genflavor, np.uint8)),
flatten(genflavor),
flatten(sjets[histname]),
weight=flatten(
ak.broadcast_arrays(
Expand All @@ -353,11 +353,7 @@ def process_shift(self, events, shift_name):
):
h.fill(
syst,
flatten(
ak.broadcast_arrays(
ak.values_astype(smflav, np.uint8), spfcands["pt"]
)[0]
),
flatten(ak.broadcast_arrays(smflav, spfcands["pt"])[0]),
flatten(spfcands[histname.replace("PFCands_", "")]),
weight=flatten(
ak.broadcast_arrays(
Expand All @@ -369,7 +365,7 @@ def process_shift(self, events, shift_name):
elif "jet_" in histname and "mu" not in histname:
h.fill(
syst,
flatten(ak.values_astype(genflavor, np.uint8)),
flatten(genflavor),
flatten(sjets[histname.replace("jet_", "")]),
weight=flatten(ak.broadcast_arrays(weight, sjets["pt"])[0]),
)
Expand All @@ -388,14 +384,14 @@ def process_shift(self, events, shift_name):
elif "soft_l" in histname and not "ptratio" in histname:
h.fill(
syst,
ak.values_astype(smflav, np.uint8),
smflav,
flatten(softmu0[histname.replace("soft_l_", "")]),
weight=weight,
)
elif "lmujet_" in histname:
h.fill(
syst,
ak.values_astype(smflav, np.uint8),
smflav,
flatten(smuon_jet[histname.replace("lmujet_", "")]),
weight=weight,
)
Expand All @@ -408,14 +404,14 @@ def process_shift(self, events, shift_name):
continue
h.fill(
syst="noSF",
flav=ak.values_astype(smflav, np.uint8),
flav=smflav,
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=ak.values_astype(smflav, np.uint8),
flav=smflav,
discr=smuon_jet[histname.replace(f"_{i}", "")],
weight=weight,
)
Expand All @@ -425,31 +421,33 @@ def process_shift(self, events, shift_name):
output["nsoftmu"].fill(syst, nsoftmu, weight=weight)
output["hl_ptratio"].fill(
syst,
flav=ak.values_astype(genflavor[:, 0], np.uint8),
genflavor[:, 0],
np.uint8,
ratio=isomu0.pt / sjets[:, 0].pt,
weight=weight,
)
output["sl_ptratio"].fill(
syst,
flav=ak.values_astype(genflavor[:, 0], np.uint8),
genflavor[:, 0],
np.uint8,
ratio=isomu1.pt / sjets[:, 0].pt,
weight=weight,
)
output["soft_l_ptratio"].fill(
syst,
flav=ak.values_astype(smflav, np.uint8),
flav=smflav,
ratio=softmu0.pt / smuon_jet.pt,
weight=weight,
)
output["dr_lmujetsmu"].fill(
syst,
flav=ak.values_astype(smflav, np.uint8),
flav=smflav,
dr=smuon_jet.delta_r(softmu0),
weight=weight,
)
output["dr_lmujethmu"].fill(
syst,
flav=ak.values_astype(smflav, np.uint8),
flav=smflav,
dr=smuon_jet.delta_r(isomu0),
weight=weight,
)
Expand Down
Loading

0 comments on commit 19aace1

Please sign in to comment.