Skip to content

Commit

Permalink
bug fix: correction (#109)
Browse files Browse the repository at this point in the history
PR looks good, merging
  • Loading branch information
Ming-Yan authored Jan 15, 2025
1 parent 2740c92 commit 506057c
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 53 deletions.
166 changes: 120 additions & 46 deletions src/BTVNanoCommissioning/utils/correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,14 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
if "correctionlib" in str(type(correct_map["EGM"])):
## Reco SF -splitted pT
if "Reco" in sf:
if "Summer22" not in correct_map["campaign"]:
ele_pt = np.where(ele.pt < 20.0, 20.0, ele.pt)
ele_pt_low = np.where(ele.pt >= 20.0, 19.9, ele.pt)
## phi is used in Summer23
ele_pt = np.clip(ele.pt, 20.1, 74.9)
ele_pt_low = np.where(ele.pt >= 20.0, 19.9, ele.pt)
ele_pt_high = np.clip(ele.pt, 75.0, 500.0)
if "Summer23" in correct_map["campaign"]:
sfs_low = np.where(
(~mask) & (~masknone),
correct_map["EGM"][correct_map["EGM_cfg"][sf]].evaluate(
(ele.pt <= 20.0) & (~masknone),
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sf",
"RecoBelow20",
Expand All @@ -1007,18 +1009,36 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
),
1.0,
)
sfs = np.where(
mask & (~masknone),
sfs_high = np.where(
(ele.pt > 75.0) & (~masknone),
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1], "sf", "RecoAbove20", ele_eta, ele_pt
sf.split(" ")[1],
"sf",
"RecoAbove75",
ele_eta,
ele_pt_high,
ele.phi,
),
sfs_low,
)
sfs = np.where(
(ele.pt > 20.0) & (ele.pt <= 75.0) & (~masknone),
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sf",
"Reco20to75",
ele_eta,
ele_pt,
ele.phi,
),
sfs_high,
)

sfs = np.where(masknone, 1.0, sfs)

if syst:
sfs_up_low = np.where(
~mask & ~masknone,
(ele.pt <= 20.0) & ~masknone,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfup",
Expand All @@ -1030,7 +1050,7 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
0.0,
)
sfs_down_low = np.where(
~mask & ~masknone,
(ele.pt <= 20.0) & ~masknone,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfdown",
Expand All @@ -1041,37 +1061,59 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
),
0.0,
)
sfs_up_high = np.where(
(ele.pt > 20.0) & (ele.pt <= 75.0) & ~masknone,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfup",
"RecoAbove75",
ele_eta,
ele_pt_high,
ele.phi,
),
sfs_up_low,
)
sfs_down_high = np.where(
(ele.pt > 20.0) & (ele.pt <= 75.0) & ~masknone,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfdown",
"RecoAbove75",
ele_eta,
ele_pt_high,
ele.phi,
),
sfs_down_low,
)
sfs_up = np.where(
mask & ~masknone,
(ele.pt > 20.0) & (ele.pt <= 75.0) & ~masknone,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfup",
"RecoAbove20",
"Reco20to75",
ele_eta,
ele_pt,
ele.phi,
),
sfs_up_low,
sfs_up_high,
)
sfs_down = np.where(
mask & ~masknone,
(ele.pt > 20.0) & (ele.pt <= 75.0) & ~masknone,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfdown",
"RecoAbove20",
"Reco20to75",
ele_eta,
ele_pt,
ele.phi,
),
sfs_down_low,
sfs_down_high,
)
sfs_up, sfs_down = np.where(
masknone, 1.0, sfs_up
), np.where(masknone, 1.0, sfs_down)

else:
ele_pt = np.clip(ele.pt, 20.1, 74.9)
ele_pt_low = np.where(ele.pt >= 20.0, 19.9, ele.pt)
ele_pt_high = np.clip(ele.pt, 75.0, 500.0)

sfs_low = np.where(
(ele.pt <= 20.0) & (~masknone),
Expand All @@ -1081,7 +1123,6 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
"RecoBelow20",
ele_eta,
ele_pt_low,
ele.phi,
),
1.0,
)
Expand All @@ -1093,7 +1134,6 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
"RecoAbove75",
ele_eta,
ele_pt_high,
ele.phi,
),
sfs_low,
)
Expand All @@ -1116,7 +1156,6 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
"RecoBelow20",
ele_eta,
ele_pt_low,
ele.phi,
),
0.0,
)
Expand All @@ -1128,7 +1167,6 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
"RecoBelow20",
ele_eta,
ele_pt_low,
ele.phi,
),
0.0,
)
Expand All @@ -1151,7 +1189,6 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
"RecoAbove75",
ele_eta,
ele_pt_high,
ele.phi,
),
sfs_down_low,
)
Expand All @@ -1163,7 +1200,6 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
"Reco20to75",
ele_eta,
ele_pt,
ele.phi,
),
sfs_up_high,
)
Expand All @@ -1175,7 +1211,6 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
"Reco20to75",
ele_eta,
ele_pt,
ele.phi,
),
sfs_down_high,
)
Expand All @@ -1185,43 +1220,82 @@ def eleSFs(ele, correct_map, weights, syst=True, isHLT=False):
), np.where(masknone, 1.0, sfs_down)
## Other files
else:
sfs = np.where(
masknone,
1.0,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sf",
correct_map["EGM_cfg"][sf],
ele_eta,
ele_pt,
ele.phi,
),
)

if syst:
sfs_up = np.where(
if "Summer23" in correct_map["campaign"]:
sfs = np.where(
masknone,
1.0,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfup",
"sf",
correct_map["EGM_cfg"][sf],
ele_eta,
ele_pt,
ele.phi,
),
)
sfs_down = np.where(

if syst:
sfs_up = np.where(
masknone,
1.0,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfup",
correct_map["EGM_cfg"][sf],
ele_eta,
ele_pt,
ele.phi,
),
)
sfs_down = np.where(
masknone,
1.0,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfdown",
correct_map["EGM_cfg"][sf],
ele_eta,
ele_pt,
ele.phi,
),
)
else:
sfs = np.where(
masknone,
1.0,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfdown",
"sf",
correct_map["EGM_cfg"][sf],
ele_eta,
ele_pt,
),
)

if syst:
sfs_up = np.where(
masknone,
1.0,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfup",
correct_map["EGM_cfg"][sf],
ele_eta,
ele_pt,
),
)
sfs_down = np.where(
masknone,
1.0,
correct_map["EGM"][sf.split(" ")[2]].evaluate(
sf.split(" ")[1],
"sfdown",
correct_map["EGM_cfg"][sf],
ele_eta,
ele_pt,
),
)

else:
if "ele_Trig" in sf:
sfs = np.where(
Expand Down Expand Up @@ -1681,9 +1755,9 @@ def weight_manager(pruned_ev, SF_map, isSyst):
syst_wei,
)
if "MUO" in SF_map.keys() and "SelMuon" in pruned_ev.fields:
muSFs(pruned_ev.Muon, SF_map, weights, syst_wei, False)
muSFs(pruned_ev.SelMuon, SF_map, weights, syst_wei, False)
if "EGM" in SF_map.keys() and "SelElectron" in pruned_ev.fields:
eleSFs(pruned_ev.Electron, SF_map, weights, syst_wei, False)
eleSFs(pruned_ev.SelElectron, SF_map, weights, syst_wei, False)
if "BTV" in SF_map.keys() and "SelJet" in pruned_ev.fields:
btagSFs(pruned_ev.SelJet, SF_map, weights, "DeepJetC", syst_wei)
btagSFs(pruned_ev.SelJet, SF_map, weights, "DeepJetB", syst_wei)
Expand Down
Loading

0 comments on commit 506057c

Please sign in to comment.