From a56b7e6c5d5971c9597c5f204f51e8a08b2b1cb0 Mon Sep 17 00:00:00 2001 From: jiangyi15 Date: Fri, 28 Jul 2023 17:17:25 +0800 Subject: [PATCH] fixed: add negtive weights in bg_rec --- tf_pwa/config_loader/data.py | 8 +++++--- tf_pwa/config_loader/plot.py | 10 ++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/tf_pwa/config_loader/data.py b/tf_pwa/config_loader/data.py index 41e8472c..8491cd67 100644 --- a/tf_pwa/config_loader/data.py +++ b/tf_pwa/config_loader/data.py @@ -1,5 +1,6 @@ import functools import os +import re import warnings import numpy as np @@ -107,10 +108,11 @@ def particle_item(): return new_order def get_weight_sign(self, idx): - negtive_idx = self.dic.get("negtive_idx", ["bg"]) + negtive_idx = self.dic.get("negtive_idx", ["bg*"]) weight_sign = 1 - if idx in negtive_idx: - weight_sign = -1 + for i in negtive_idx: + if re.match(i, idx): + weight_sign = -1 return weight_sign def get_data(self, idx) -> dict: diff --git a/tf_pwa/config_loader/plot.py b/tf_pwa/config_loader/plot.py index 35de0052..0513789d 100644 --- a/tf_pwa/config_loader/plot.py +++ b/tf_pwa/config_loader/plot.py @@ -491,10 +491,7 @@ def _cal_partial_wave( if ref_amp is not None: norm_frac_ref = n_data / np.sum(total_weight_ref) else: - if isinstance(w_bkg, float): - n_sig = n_data - w_bkg * data_shape(bg) - else: - n_sig = n_data + np.sum(w_bkg) + n_sig = n_data + np.sum(w_bkg) norm_frac = n_sig / np.sum(total_weight) if ref_amp is not None: norm_frac_ref = n_sig / np.sum(total_weight_ref) @@ -522,10 +519,7 @@ def _cal_partial_wave( cut_function(phsp_rec) * total_weight_ref * norm_frac_ref ) if bg is not None: - if isinstance(w_bkg, float): - bg_weight = [w_bkg] * data_shape(bg) - else: - bg_weight = -w_bkg + bg_weight = -w_bkg bg_dict["sideband_weights"] = ( cut_function(bg) * bg_weight ) # sideband weight