ijazz.sas_utils =============== .. py:module:: ijazz.sas_utils Attributes ---------- .. autoapisummary:: ijazz.sas_utils.resp_exp ijazz.sas_utils.reso_exp ijazz.sas_utils.pt_fit_resp ijazz.sas_utils.pt_fit_reso ijazz.sas_utils.p0_resp ijazz.sas_utils.pr_resp ijazz.sas_utils.p0_reso ijazz.sas_utils.pr_reso Classes ------- .. autoapisummary:: ijazz.sas_utils.FuncStr Functions --------- .. autoapisummary:: ijazz.sas_utils.ijazz_shape ijazz.sas_utils.parameters_from_json ijazz.sas_utils.parameters_to_json ijazz.sas_utils.json_safe_load ijazz.sas_utils.to_correction_lib ijazz.sas_utils.compute_syst_from_jsons ijazz.sas_utils.apply_corrlib_df ijazz.sas_utils.apply_corrlib_df_mmg ijazz.sas_utils.do_pt_fit ijazz.sas_utils.pt_smoothing ijazz.sas_utils.create_pt_corrector ijazz.sas_utils.ijazz_sas_smoothing Module Contents --------------- .. py:function:: ijazz_shape(categories: dict) -> List Returns the shape to be used for reshaping the tensor of parameters of the ijazz fit :param categories: categories used in the ijazz sas fit :type categories: dict :returns: shape :rtype: list .. py:function:: parameters_from_json(json_file: Union[str, pathlib.Path, Dict]) -> Dict Extract and re-shape the IJazZ sas results saved in a json file :param json_file: name of the json file where the fit results are stored :type json_file: Union[str, Path, Dict] :returns: dictionnary with the categories used in the fit and the results of the fit :rtype: dict .. py:function:: parameters_to_json(params: Dict, outfile: Union[str, pathlib.Path]) -> None Dump the parameters dictionnary to a json file :param params: input dictionnary :type params: Dict :param outfile: output file :type outfile: Union[str, Path] .. py:function:: json_safe_load(json_name, mc_errors=False) Load an IJazZ JSON file and convert arrays to numpy. :param json_name: path to the JSON file. :type json_name: str | Path :param mc_errors: if True, also load MC error arrays. :type mc_errors: bool :returns: parsed JSON with numpy arrays for numeric fields. :rtype: dict .. py:function:: to_correction_lib(sas: Union[Dict, str, pathlib.Path], dir_results: Union[pathlib.Path, str] = './tmp/', dset_name='DSET', cset_name='CSET', cset_description: str = None, cset_version=1, change_abs_var: Dict[str, str] = {}, cat_latex=None, dry_run=False) -> Tuple[str, List[str]] Create a correction lib files based :param sas: dictionnary with scales and smearings :type sas: Dict, :param dir_results: directory. Defaults to Path('./tmp/'). :type dir_results: Path, optional :param dset_name: dataset nickname. Defaults to 'DSET'. :type dset_name: str, optional :param cset_name: correction saet name. Defaults to 'CSET'. :type cset_name: str, optional :param cset_description: description of the correction set. Defaults to None. :type cset_description: str, optional :param cset_version: correction set version. Defaults to 1. :type cset_version: int, optional :param cat_latex: dictionnary with a description of variables in categories. Defaults to None. :type cat_latex: Dict, optional .. py:function:: compute_syst_from_jsons(nominal: Union[Dict, str, pathlib.Path], syst_jsons: List[Union[Dict, str, pathlib.Path]], fit_2g: Union[Dict, str, pathlib.Path] = None, scale_flat_syst: float = 0.0, smear_flat_syst: float = 0.0) -> Tuple[str, List[str]] Compute the systematic uncertainties from the json files :param nominal: nominal json file :type nominal: Union[Dict, str, Path] :param syst_jsons: list of json files with systematic variations :type syst_jsons: List[Union[Dict, str, Path]] :param fit_2g: json file with the parameters of the double gaussian fit. Defaults to None. :type fit_2g: Union[Dict, str, Path], optional :param scale_flat_syst: flat scale systematic uncertainty. Defaults to 0.0. :type scale_flat_syst: float, optional :param smear_flat_syst: flat smear systematic uncertainty. Defaults to 0.0. :type smear_flat_syst: float, optional Returns: .. py:function:: apply_corrlib_df(df: pandas.DataFrame, cset_vars: List[str], cset_name: str, cset_file: str, syst_name: str, mll_name='mass', ptl_name='pt') Apply the correction lib to a pandas dataframe :param df: dataframe with the variables to correct :type df: pd.DataFrame :param cset_vars: list of the variables used in the correction :type cset_vars: List[str] :param cset_name: name of the correction set :type cset_name: str :param cset_file: name of the correction file :type cset_file: str :param syst_name: type of correction to apply: scale or smear :type syst_name: str :param mll_name: dilepton mass variable name. Defaults to 'mass'. :type mll_name: str, optional :param ptl_name: lepton tranverse momentum variable name. Defaults to 'pt'. :type ptl_name: str, optional .. py:function:: apply_corrlib_df_mmg(df: pandas.DataFrame, cset_vars: List[str], cset_name: str, cset_file: str, syst_name: str, vllg_name='v_mmg', mllg_name='mass', mll_name='mass_mm', ptg_name='ptg') Apply the correction lib to a pandas dataframe :param df: dataframe with the variables to correct :type df: pd.DataFrame :param cset_vars: list of the variables used in the correction :type cset_vars: List[str] :param cset_name: name of the correction set :type cset_name: str :param cset_file: name of the correction file :type cset_file: str :param syst_name: type of correction to apply: scale or smear :type syst_name: str :param vllg_name: Zmmg visible mass variable name. Defaults to 'v_mmg'. :type vllg_name: str, optional :param mllg_name: Zmmg mass variable name. Defaults to 'mass'. :type mllg_name: str, optional :param mll_name: dilepton mass variable name. Defaults to 'mass_mm'. :type mll_name: str, optional :param ptg_name: lepton tranverse momentum variable name. Defaults to 'ptg'. :type ptg_name: str, optional .. py:class:: FuncStr(expression: str) Vectorized function wrapper built from a string expression. .. py:attribute:: n_par .. py:attribute:: expression .. py:method:: replace_par(*par) .. py:method:: tformula(*par) -> str Return a ROOT type TFormula replacing parameters with inputs pars :returns: TFormula expression :rtype: str .. py:method:: __call__(x, *par) .. py:data:: resp_exp :value: '[0] * np.power(min(x, 160)/45., [1]) + [2]' .. py:data:: reso_exp :value: 'np.sqrt(np.abs(np.power([0], 2) + [1]/min(x, 160)))' .. py:data:: pt_fit_resp .. py:data:: pt_fit_reso .. py:data:: p0_resp .. py:data:: pr_resp .. py:data:: p0_reso :value: [0.01, 0.0] .. py:data:: pr_reso .. py:function:: do_pt_fit(axval, avar, eavar, func: FuncStr, p0, p_range, do_plot=False, min_pt=25, max_pt=160, width_pt=0.5) Fit a smooth pT-dependent function to binned inputs. :param axval: x-bin centers. :type axval: np.ndarray :param avar: values to fit (shape: nbin x ncat). :type avar: np.ndarray :param eavar: uncertainties for avar. :type eavar: np.ndarray :param func: function form to fit. :type func: FuncStr :param p0: initial parameter values. :type p0: list :param p_range: parameter ranges. :type p_range: list :param do_plot: if True, plot fit and points. :type do_plot: bool :param min_pt: minimum pT for fine grid. :type min_pt: float :param max_pt: maximum pT for fine grid. :type max_pt: float :param width_pt: step size for fine grid. :type width_pt: float :returns: list of fitted TFormula strings per category. :rtype: list .. py:function:: pt_smoothing(json_file: Union[str, pathlib.Path, Dict], dim_to_fit='pt', do_plot=False) -> Tuple[Dict, Dict] Function to fit the pT-dependent sas to make them smooth :param json_file: name of the json file containing the result of the sas fit :type json_file: Union[str, Path] :param dim_to_fit: name of the pt dimension. Defaults to 'pt'. :type dim_to_fit: str, optional :returns: new sas dictionnary :rtype: Dict .. py:function:: create_pt_corrector(sas: Union[Dict, str, pathlib.Path], dir_results: Union[pathlib.Path, str] = './tmp/', dset_name='DSET', cset_name='CSET', cset_description: str = None, cset_version=1, cat_latex=None, pt_name='pt') Create a correction lib files based :param sas: dictionnary with scales and smearings :type sas: Dict, :param dir_results: directory. Defaults to Path('./tmp/'). :type dir_results: Path, optional :param dset_name: dataset nickname. Defaults to 'DSET'. :type dset_name: str, optional :param cset_name: correction saet name. Defaults to 'CSET'. :type cset_name: str, optional :param cset_description: description of the correction set. Defaults to None. :type cset_description: str, optional :param cset_version: correction set version. Defaults to 1. :type cset_version: int, optional :param cat_latex: dictionnary with a description of variables in categories. Defaults to None. :type cat_latex: Dict, optional .. py:function:: ijazz_sas_smoothing() entry point for the ijazz_sas_smoothing command