ijazz.sas_utils

Attributes

resp_exp

reso_exp

pt_fit_resp

pt_fit_reso

p0_resp

pr_resp

p0_reso

pr_reso

Classes

FuncStr

Vectorized function wrapper built from a string expression.

Functions

ijazz_shape(→ List)

Returns the shape to be used for reshaping the tensor of parameters of the ijazz fit

parameters_from_json(→ Dict)

Extract and re-shape the IJazZ sas results saved in a json file

parameters_to_json(→ None)

Dump the parameters dictionnary to a json file

json_safe_load(json_name[, mc_errors])

Load an IJazZ JSON file and convert arrays to numpy.

to_correction_lib(→ Tuple[str, List[str]])

Create a correction lib files based

compute_syst_from_jsons(→ Tuple[str, List[str]])

Compute the systematic uncertainties from the json files

apply_corrlib_df(df, cset_vars, cset_name, cset_file, ...)

Apply the correction lib to a pandas dataframe

apply_corrlib_df_mmg(df, cset_vars, cset_name, ...[, ...])

Apply the correction lib to a pandas dataframe

do_pt_fit(axval, avar, eavar, func, p0, p_range[, ...])

Fit a smooth pT-dependent function to binned inputs.

pt_smoothing(→ Tuple[Dict, Dict])

Function to fit the pT-dependent sas to make them smooth

create_pt_corrector(sas[, dir_results, dset_name, ...])

Create a correction lib files based

ijazz_sas_smoothing()

entry point for the ijazz_sas_smoothing command

Module Contents

ijazz.sas_utils.ijazz_shape(categories: dict) List[source]

Returns the shape to be used for reshaping the tensor of parameters of the ijazz fit

Parameters:

categories (dict) – categories used in the ijazz sas fit

Returns:

shape

Return type:

list

ijazz.sas_utils.parameters_from_json(json_file: str | pathlib.Path | Dict) Dict[source]

Extract and re-shape the IJazZ sas results saved in a json file

Parameters:

json_file (Union[str, Path, Dict]) – name of the json file where the fit results are stored

Returns:

dictionnary with the categories used in the fit and the results of the fit

Return type:

dict

ijazz.sas_utils.parameters_to_json(params: Dict, outfile: str | pathlib.Path) None[source]

Dump the parameters dictionnary to a json file

Parameters:
  • params (Dict) – input dictionnary

  • outfile (Union[str, Path]) – output file

ijazz.sas_utils.json_safe_load(json_name, mc_errors=False)[source]

Load an IJazZ JSON file and convert arrays to numpy.

Parameters:
  • json_name (str | Path) – path to the JSON file.

  • mc_errors (bool) – if True, also load MC error arrays.

Returns:

parsed JSON with numpy arrays for numeric fields.

Return type:

dict

ijazz.sas_utils.to_correction_lib(sas: Dict | str | pathlib.Path, dir_results: 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]][source]

Create a correction lib files based

Parameters:
  • sas (Dict,) – dictionnary with scales and smearings

  • dir_results (Path, optional) – directory. Defaults to Path(‘./tmp/’).

  • dset_name (str, optional) – dataset nickname. Defaults to ‘DSET’.

  • cset_name (str, optional) – correction saet name. Defaults to ‘CSET’.

  • cset_description (str, optional) – description of the correction set. Defaults to None.

  • cset_version (int, optional) – correction set version. Defaults to 1.

  • cat_latex (Dict, optional) – dictionnary with a description of variables in categories. Defaults to None.

ijazz.sas_utils.compute_syst_from_jsons(nominal: Dict | str | pathlib.Path, syst_jsons: List[Dict | str | pathlib.Path], fit_2g: Dict | str | pathlib.Path = None, scale_flat_syst: float = 0.0, smear_flat_syst: float = 0.0) Tuple[str, List[str]][source]

Compute the systematic uncertainties from the json files

Parameters:
  • nominal (Union[Dict, str, Path]) – nominal json file

  • syst_jsons (List[Union[Dict, str, Path]]) – list of json files with systematic variations

  • fit_2g (Union[Dict, str, Path], optional) – json file with the parameters of the double gaussian fit. Defaults to None.

  • scale_flat_syst (float, optional) – flat scale systematic uncertainty. Defaults to 0.0.

  • smear_flat_syst (float, optional) – flat smear systematic uncertainty. Defaults to 0.0.

Returns:

ijazz.sas_utils.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')[source]

Apply the correction lib to a pandas dataframe

Parameters:
  • df (pd.DataFrame) – dataframe with the variables to correct

  • cset_vars (List[str]) – list of the variables used in the correction

  • cset_name (str) – name of the correction set

  • cset_file (str) – name of the correction file

  • syst_name (str) – type of correction to apply: scale or smear

  • mll_name (str, optional) – dilepton mass variable name. Defaults to ‘mass’.

  • ptl_name (str, optional) – lepton tranverse momentum variable name. Defaults to ‘pt’.

ijazz.sas_utils.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')[source]

Apply the correction lib to a pandas dataframe

Parameters:
  • df (pd.DataFrame) – dataframe with the variables to correct

  • cset_vars (List[str]) – list of the variables used in the correction

  • cset_name (str) – name of the correction set

  • cset_file (str) – name of the correction file

  • syst_name (str) – type of correction to apply: scale or smear

  • vllg_name (str, optional) – Zmmg visible mass variable name. Defaults to ‘v_mmg’.

  • mllg_name (str, optional) – Zmmg mass variable name. Defaults to ‘mass’.

  • mll_name (str, optional) – dilepton mass variable name. Defaults to ‘mass_mm’.

  • ptg_name (str, optional) – lepton tranverse momentum variable name. Defaults to ‘ptg’.

class ijazz.sas_utils.FuncStr(expression: str)[source]

Vectorized function wrapper built from a string expression.

n_par[source]
expression[source]
replace_par(*par)[source]
tformula(*par) str[source]

Return a ROOT type TFormula replacing parameters with inputs pars

Returns:

TFormula expression

Return type:

str

__call__(x, *par)[source]
ijazz.sas_utils.resp_exp = '[0] * np.power(min(x, 160)/45., [1]) + [2]'[source]
ijazz.sas_utils.reso_exp = 'np.sqrt(np.abs(np.power([0], 2) + [1]/min(x, 160)))'[source]
ijazz.sas_utils.pt_fit_resp[source]
ijazz.sas_utils.pt_fit_reso[source]
ijazz.sas_utils.p0_resp[source]
ijazz.sas_utils.pr_resp[source]
ijazz.sas_utils.p0_reso = [0.01, 0.0][source]
ijazz.sas_utils.pr_reso[source]
ijazz.sas_utils.do_pt_fit(axval, avar, eavar, func: FuncStr, p0, p_range, do_plot=False, min_pt=25, max_pt=160, width_pt=0.5)[source]

Fit a smooth pT-dependent function to binned inputs.

Parameters:
  • axval (np.ndarray) – x-bin centers.

  • avar (np.ndarray) – values to fit (shape: nbin x ncat).

  • eavar (np.ndarray) – uncertainties for avar.

  • func (FuncStr) – function form to fit.

  • p0 (list) – initial parameter values.

  • p_range (list) – parameter ranges.

  • do_plot (bool) – if True, plot fit and points.

  • min_pt (float) – minimum pT for fine grid.

  • max_pt (float) – maximum pT for fine grid.

  • width_pt (float) – step size for fine grid.

Returns:

list of fitted TFormula strings per category.

Return type:

list

ijazz.sas_utils.pt_smoothing(json_file: str | pathlib.Path | Dict, dim_to_fit='pt', do_plot=False) Tuple[Dict, Dict][source]

Function to fit the pT-dependent sas to make them smooth

Parameters:
  • json_file (Union[str, Path]) – name of the json file containing the result of the sas fit

  • dim_to_fit (str, optional) – name of the pt dimension. Defaults to ‘pt’.

Returns:

new sas dictionnary

Return type:

Dict

ijazz.sas_utils.create_pt_corrector(sas: Dict | str | pathlib.Path, dir_results: pathlib.Path | str = './tmp/', dset_name='DSET', cset_name='CSET', cset_description: str = None, cset_version=1, cat_latex=None, pt_name='pt')[source]

Create a correction lib files based

Parameters:
  • sas (Dict,) – dictionnary with scales and smearings

  • dir_results (Path, optional) – directory. Defaults to Path(‘./tmp/’).

  • dset_name (str, optional) – dataset nickname. Defaults to ‘DSET’.

  • cset_name (str, optional) – correction saet name. Defaults to ‘CSET’.

  • cset_description (str, optional) – description of the correction set. Defaults to None.

  • cset_version (int, optional) – correction set version. Defaults to 1.

  • cat_latex (Dict, optional) – dictionnary with a description of variables in categories. Defaults to None.

ijazz.sas_utils.ijazz_sas_smoothing()[source]

entry point for the ijazz_sas_smoothing command