Skip to content

Commit

Permalink
Replace all is_run bools with method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bryates committed Nov 20, 2024
1 parent 2e22a1b commit 3ef58a5
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions topeft/modules/corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,10 +920,6 @@ def AttachMuonSF(muons, year):
- use loose from correction-lib
- reco not available yet, but MUO don't bother about that
'''
is_run3 = False
if is_run3(year):
is_run3 = True
is_run2 = not is_run3

eta = np.abs(muons.eta)
pt = muons.pt
Expand Down Expand Up @@ -964,7 +960,7 @@ def AttachMuonSF(muons, year):
pt_flat_reco = ak.where(~pt_mask_reco, 40., pt_flat)
pt_flat_loose = ak.where(~pt_mask, 15., pt_flat)

if is_run2:
if is_run2(year):
## The only one to be actually got from clib for Run2<
loose_sf_flat = ak.where(
~pt_mask,
Expand Down Expand Up @@ -1005,7 +1001,7 @@ def AttachMuonSF(muons, year):
new_up = new_sf + new_err
new_do = new_sf - new_err

elif is_run3:
elif is_run3(year):
loose_sf_flat = ak.where(
~pt_mask,
1,
Expand Down Expand Up @@ -1068,10 +1064,7 @@ def AttachElectronSF(electrons, year, looseWP=None):
if looseWP is None:
raise ValueError('when calling AttachElectronSF, a looseWP value must be provided according to the ele ID isPres selection')

is_run3 = False
is_run3 = is_run3(year)
is_run2 = is_run2(year)
dt_era = "Run3" if is_run3 else "Run2"
dt_era = "Run3" if is_run3(year) else "Run2"

eta = electrons.eta
pt = electrons.pt
Expand Down Expand Up @@ -1115,7 +1108,7 @@ def AttachElectronSF(electrons, year, looseWP=None):

egm_year = egm_tag_map[clib_year]
egm_tag = "Electron-ID-SF"
if is_run2:
if is_run2(year):
egm_tag = "UL-" + "Electron-ID-SF"

for bintag, bin_edges in pt_bins.items():
Expand Down Expand Up @@ -1168,7 +1161,7 @@ def AttachElectronSF(electrons, year, looseWP=None):
reco_up = ak.unflatten(reco_up_flat, ak.num(pt))
reco_do = ak.unflatten(reco_do_flat, ak.num(pt))

if is_run3:
if is_run3(year):
loose_sf_flat = None
loose_up_flat = None
loose_do_flat = None
Expand Down Expand Up @@ -1651,17 +1644,14 @@ def LoadTriggerSF(year, ch='2l', flav='em'):
return [GetTrig, GetTrigDo, GetTrigUp]

def GetTriggerSF(year, events, lep0, lep1):
is_run3 = is_run3(year)
is_run2 = is_run2(year)

ls = []
for syst in [0,1]:
#2l
if is_run2:
if is_run2(year):
SF_ee = np.where((events.is2l & events.is_ee), LoadTriggerSF(year,ch='2l',flav='ee')[syst](lep0.pt,lep1.pt), 1.0)
SF_em = np.where((events.is2l & events.is_em), LoadTriggerSF(year,ch='2l',flav='em')[syst](lep0.pt,lep1.pt), 1.0)
SF_mm = np.where((events.is2l & events.is_mm), LoadTriggerSF(year,ch='2l',flav='mm')[syst](lep0.pt,lep1.pt), 1.0)
elif is_run3:
elif is_run3(year):
SF_ee = ak.ones_like(events.is2l)
SF_em = ak.ones_like(events.is2l)
SF_mm = ak.ones_like(events.is2l)
Expand Down

0 comments on commit 3ef58a5

Please sign in to comment.