From 3ef58a52c69c48879e97bc302d3cd78444a1e137 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Wed, 20 Nov 2024 10:35:10 -0500 Subject: [PATCH] Replace all `is_run` bools with method calls --- topeft/modules/corrections.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/topeft/modules/corrections.py b/topeft/modules/corrections.py index dd7285cb..4557523e 100644 --- a/topeft/modules/corrections.py +++ b/topeft/modules/corrections.py @@ -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 @@ -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, @@ -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, @@ -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 @@ -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(): @@ -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 @@ -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)