diff --git a/PWGHF/D2H/Macros/compute_fraction_cutvar.py b/PWGHF/D2H/Macros/compute_fraction_cutvar.py index 74432688725..d3b3b87111d 100644 --- a/PWGHF/D2H/Macros/compute_fraction_cutvar.py +++ b/PWGHF/D2H/Macros/compute_fraction_cutvar.py @@ -16,12 +16,13 @@ import numpy as np # pylint: disable=import-error import ROOT # pylint: disable=import-error -sys.path.insert(0, '..') +sys.path.insert(0, "..") from cut_variation import CutVarMinimiser, MinimisationStatus from style_formatter import set_object_style # pylint: disable=no-member,too-many-locals,too-many-statements + class PlotType(IntEnum): Rawy = 0 Eff = auto() @@ -31,6 +32,7 @@ class PlotType(IntEnum): RelUnc = auto() N = auto() + class ObjectToSave(IntEnum): Canvas = 0 RawYield = auto() @@ -44,6 +46,7 @@ class ObjectToSave(IntEnum): MinimisationStatus = auto() N = auto() + def main(config): """ Main function @@ -65,7 +68,7 @@ def main(config): hist_rawy_name = cfg["rawyields"]["histoname"] hist_rawy.append(infile_rawy.Get(hist_rawy_name)) if not isinstance(hist_rawy[-1], ROOT.TH1): - sys.exit(f"\33[31mFatal error: Histogram with raw yield \"{hist_rawy_name}\" is absent. Exit.\33[0m") + sys.exit(f'\33[31mFatal error: Histogram with raw yield "{hist_rawy_name}" is absent. Exit.\33[0m') hist_rawy[-1].SetDirectory(0) infile_rawy.Close() @@ -75,14 +78,22 @@ def main(config): hist_effp.append(infile_eff.Get(hist_effp_name)) hist_effnp.append(infile_eff.Get(hist_effnp_name)) if not isinstance(hist_effp[-1], ROOT.TH1): - sys.exit(f"\33[31mFatal error: Histogram with efficiency for prompt \"{hist_effp_name}\" is absent. Exit.\33[0m") + sys.exit( + f'\33[31mFatal error: Histogram with efficiency for prompt "{hist_effp_name}" is absent. Exit.\33[0m' + ) if not isinstance(hist_effnp[-1], ROOT.TH1): - sys.exit(f"\33[31mFatal error: Histogram with efficiency for nonprompt \"{hist_effnp}\" is absent. Exit.\33[0m") + sys.exit( + f'\33[31mFatal error: Histogram with efficiency for nonprompt "{hist_effnp}" is absent. Exit.\33[0m' + ) hist_effp[-1].SetDirectory(0) hist_effnp[-1].SetDirectory(0) for i_bin in range(1, hist_effp[-1].GetNbinsX() + 1): - hist_effp[-1].SetBinContent(i_bin, hist_effp[-1].GetBinContent(i_bin) + effp_shift_nsigma*hist_effp[-1].GetBinError(i_bin)) - hist_effnp[-1].SetBinContent(i_bin, hist_effnp[-1].GetBinContent(i_bin) + effnp_shift_nsigma*hist_effnp[-1].GetBinError(i_bin)) + hist_effp[-1].SetBinContent( + i_bin, hist_effp[-1].GetBinContent(i_bin) + effp_shift_nsigma * hist_effp[-1].GetBinError(i_bin) + ) + hist_effnp[-1].SetBinContent( + i_bin, hist_effnp[-1].GetBinContent(i_bin) + effnp_shift_nsigma * hist_effnp[-1].GetBinError(i_bin) + ) if zero_eff_unc: hist_effp[-1].SetBinError(i_bin, 0.0) hist_effnp[-1].SetBinError(i_bin, 0.0) @@ -92,7 +103,9 @@ def main(config): if not isinstance(pt_bin_to_process, int): sys.exit("\33[31mFatal error: pt_bin_to_process must be an integer value. Exit.") if (pt_bin_to_process != -1 and pt_bin_to_process < 1) or pt_bin_to_process > hist_rawy[0].GetNbinsX(): - sys.exit("\33[31mFatal error: pt_bin_to_process must be a positive value up to number of bins in raw yield histogram. Exit.") + sys.exit( + "\33[31mFatal error: pt_bin_to_process must be a positive value up to number of bins in raw yield histogram. Exit." + ) is_draw_title = [False] * PlotType.N is_draw_title[PlotType.Rawy] = cfg.get("is_draw_title", {}).get("rawy", True) @@ -117,10 +130,16 @@ def main(config): is_save_to_root_file[ObjectToSave.Efficiency] = cfg.get("is_save_to_root_file", {}).get("efficiency", True) is_save_to_root_file[ObjectToSave.Fraction] = cfg.get("is_save_to_root_file", {}).get("fraction", True) is_save_to_root_file[ObjectToSave.CorrectedYield] = cfg.get("is_save_to_root_file", {}).get("corrected_yield", True) - is_save_to_root_file[ObjectToSave.CorrelationMatrix] = cfg.get("is_save_to_root_file", {}).get("correlation_matrix", True) + is_save_to_root_file[ObjectToSave.CorrelationMatrix] = cfg.get("is_save_to_root_file", {}).get( + "correlation_matrix", True + ) is_save_to_root_file[ObjectToSave.Covariance] = cfg.get("is_save_to_root_file", {}).get("covariance", True) - is_save_to_root_file[ObjectToSave.CorrectedFraction] = cfg.get("is_save_to_root_file", {}).get("corrected_fraction", True) - is_save_to_root_file[ObjectToSave.MinimisationStatus] = cfg.get("is_save_to_root_file", {}).get("minimisation_status", True) + is_save_to_root_file[ObjectToSave.CorrectedFraction] = cfg.get("is_save_to_root_file", {}).get( + "corrected_fraction", True + ) + is_save_to_root_file[ObjectToSave.MinimisationStatus] = cfg.get("is_save_to_root_file", {}).get( + "minimisation_status", True + ) if cfg["central_efficiency"]["computerawfrac"]: infile_name = os.path.join(cfg["central_efficiency"]["inputdir"], cfg["central_efficiency"]["inputfile"]) @@ -128,11 +147,15 @@ def main(config): hist_central_effp_name = cfg["central_efficiency"]["histonames"]["prompt"] hist_central_effp = infile_central_eff.Get(hist_central_effp_name) if not isinstance(hist_central_effp[-1], ROOT.TH1): - sys.exit(f"\33[31mFatal error: Histogram with central efficiency for prompt \"{hist_central_effp_name}\" is absent. Exit.\33[0m") + sys.exit( + f'\33[31mFatal error: Histogram with central efficiency for prompt "{hist_central_effp_name}" is absent. Exit.\33[0m' + ) hist_central_effnp_name = cfg["central_efficiency"]["histonames"]["nonprompt"] hist_central_effnp = infile_central_eff.Get(hist_central_effnp_name) if not isinstance(hist_central_effnp[-1], ROOT.TH1): - sys.exit(f"\33[31mFatal error: Histogram with central efficiency for nonprompt \"{hist_central_effnp_name}\" is absent. Exit.\33[0m") + sys.exit( + f'\33[31mFatal error: Histogram with central efficiency for nonprompt "{hist_central_effnp_name}" is absent. Exit.\33[0m' + ) hist_central_effp.SetDirectory(0) hist_central_effnp.SetDirectory(0) infile_central_eff.Close() @@ -150,8 +173,18 @@ def main(config): hist_corrfrac_prompt = hist_rawy[0].Clone("hCorrFracPrompt") hist_corrfrac_nonprompt = hist_rawy[0].Clone("hCorrFracNonPrompt") hist_minimisation_status = hist_rawy[0].Clone("hMinimizationStatus") - hist_red_chi2 = hist_rawy[0].Clone("hChi2OverNdf") - for histo in hist_corry_prompt, hist_corry_nonprompt, hist_covariance_pnp, hist_covariance_pp, hist_covariance_npnp, hist_corrfrac_prompt, hist_corrfrac_nonprompt, hist_minimisation_status, hist_red_chi2: + hist_red_chi2 = hist_rawy[0].Clone("hChi2OverNdf") + for histo in ( + hist_corry_prompt, + hist_corry_nonprompt, + hist_covariance_pnp, + hist_covariance_pp, + hist_covariance_npnp, + hist_corrfrac_prompt, + hist_corrfrac_nonprompt, + hist_minimisation_status, + hist_red_chi2, + ): histo.Reset() hist_corry_prompt.GetYaxis().SetTitle("corrected yields prompt") hist_corry_nonprompt.GetYaxis().SetTitle("corrected yields non-prompt") @@ -164,7 +197,7 @@ def main(config): hist_red_chi2.GetYaxis().SetTitle("#chi^{2}/ndf") hist_minimisation_status_title = "" for min_status in MinimisationStatus: - hist_minimisation_status_title += (str(min_status.value) + " = " + min_status.name + ", ") + hist_minimisation_status_title += str(min_status.value) + " = " + min_status.name + ", " hist_minimisation_status_title = hist_minimisation_status_title[:-2] hist_minimisation_status.SetTitle(hist_minimisation_status_title) set_object_style( @@ -221,17 +254,17 @@ def main(config): if pt_bin_to_process != -1: pt_bin_to_process_name_suffix = "_bin_" + str(pt_bin_to_process) - output_name_template = cfg['output']['file'].replace(".root", "") + pt_bin_to_process_name_suffix + ".root" + output_name_template = cfg["output"]["file"].replace(".root", "") + pt_bin_to_process_name_suffix + ".root" output = ROOT.TFile(os.path.join(cfg["output"]["directory"], output_name_template), "recreate") n_sets = len(hist_rawy) pt_axis_title = hist_rawy[0].GetXaxis().GetTitle() for ipt in range(hist_rawy[0].GetNbinsX()): - if pt_bin_to_process !=-1 and ipt+1 != pt_bin_to_process: + if pt_bin_to_process != -1 and ipt + 1 != pt_bin_to_process: continue all_vectors_monotonous = MinimisationStatus.Success pt_min = hist_rawy[0].GetXaxis().GetBinLowEdge(ipt + 1) pt_max = hist_rawy[0].GetXaxis().GetBinUpEdge(ipt + 1) - print(f"\n\nINFO: processing pt range {ipt+1} from {pt_min} to {pt_max} {pt_axis_title}") + print(f"\n\nINFO: processing pt range {ipt + 1} from {pt_min} to {pt_max} {pt_axis_title}") rawy, effp, effnp, unc_rawy, unc_effp, unc_effnp = (np.zeros(n_sets) for _ in range(6)) for iset, (hrawy, heffp, heffnp) in enumerate(zip(hist_rawy, hist_effp, hist_effnp)): @@ -245,16 +278,24 @@ def main(config): if cfg["minimisation"]["correlated"]: if not (np.all(rawy[1:] > rawy[:-1]) or np.all(rawy[1:] < rawy[:-1])): all_vectors_monotonous = MinimisationStatus.MonotonyViolation - print("\0\33[33mWARNING! main(): the raw yield vector is not monotonous. Check the input for stability.\0\33[0m") + print( + "\0\33[33m\nWARNING! main(): the raw yield vector is not monotonous. Check the input for stability.\n\0\33[0m" + ) print(f"raw yield vector elements = {rawy}\n") if not (np.all(unc_rawy[1:] > unc_rawy[:-1]) or np.all(unc_rawy[1:] < unc_rawy[:-1])): all_vectors_monotonous = MinimisationStatus.MonotonyViolation - print("\0\33[33mWARNING! main(): the raw yield uncertainties vector is not monotonous. Check the input for stability.\0\33[0m") + print( + "\0\33[33m\nWARNING! main(): the raw yield uncertainties vector is not monotonous. Check the input for stability.\n\0\33[0m" + ) print(f"raw yield uncertainties vector elements = {unc_rawy}\n") if not (np.all(effp[1:] > effp[:-1]) or np.all(effp[1:] < effp[:-1])): - sys.exit("\33[31mFatal error: the prompt efficiency vector is not monotonous. Check the input. Exit.\33[0m") + all_vectors_monotonous = MinimisationStatus.MonotonyViolation + print("\0\33[33m\nWARNING! the prompt efficiency vector is not monotonous. Check the input.\0\33[0m") + print(f"prompt efficiency vector elements = {effp}\n") if not (np.all(effnp[1:] > effnp[:-1]) or np.all(effnp[1:] < effnp[:-1])): - sys.exit("\33[31mFatal error: the nonprompt efficiency vector is not monotonous. Check the input. Exit.\33[0m") + all_vectors_monotonous = MinimisationStatus.MonotonyViolation + print("\0\33[33m\nWARNING! the nonprompt efficiency vector is not monotonous. Check the input.\0\33[0m") + print(f"nonprompt efficiency vector elements = {effnp}\n") minimiser = CutVarMinimiser(rawy, effp, effnp, unc_rawy, unc_effp, unc_effnp) status = minimiser.minimise_system(cfg["minimisation"]["correlated"]) @@ -290,7 +331,7 @@ def main(config): hist_frac_raw_nonprompt.SetBinContent(ipt + 1, raw_frac_nonprompt[0]) hist_frac_raw_nonprompt.SetBinError(ipt + 1, raw_frac_nonprompt[1]) - hist_bin_title = f"bin # {ipt+1}; {pt_axis_title}#in ({pt_min}; {pt_max})" + hist_bin_title = f"bin # {ipt + 1}; {pt_axis_title}#in ({pt_min}; {pt_max})" hist_bin_title_rawy = hist_bin_title if is_draw_title[PlotType.Rawy] else "" canv_rawy, histos_rawy, _leg_r = minimiser.plot_result(f"_pt_{pt_min}_to_{pt_max}", hist_bin_title_rawy) @@ -298,32 +339,36 @@ def main(config): if is_save_to_root_file[ObjectToSave.Canvas]: canv_rawy.Write() if is_save_to_root_file[ObjectToSave.RawYield]: - for _, hist in histos_rawy.values(): + for hist in histos_rawy.values(): hist.Write() if is_save_canvas_as_macro[PlotType.Rawy]: - canv_rawy.SaveAs(f"canv_rawy_{ipt+1}.C") + canv_rawy.SaveAs(f"canv_rawy_{ipt + 1}.C") hist_bin_title_unc = hist_bin_title if is_draw_title[PlotType.Unc] else "" - canv_unc, histos_unc, _leg_unc = minimiser.plot_uncertainties(f"_pt_{pt_min}_to_{pt_max}", hist_bin_title_unc) + canv_unc, histos_unc, _leg_unc = minimiser.plot_uncertainties( + f"_pt_{pt_min}_to_{pt_max}", hist_bin_title_unc + ) output.cd() if is_save_to_root_file[ObjectToSave.Canvas]: canv_unc.Write() if is_save_to_root_file[ObjectToSave.Uncertainty]: - for _, hist in histos_unc.values(): + for hist in histos_unc.values(): hist.Write() if is_save_canvas_as_macro[PlotType.Unc]: - canv_unc.SaveAs(f"canv_unc_{ipt+1}.C") + canv_unc.SaveAs(f"canv_unc_{ipt + 1}.C") hist_bin_title_rel_unc = hist_bin_title if is_draw_title[PlotType.RelUnc] else "" - canv_rel_unc, histos_rel_unc, _leg_rel_unc = minimiser.plot_relative_uncertainties(f"_pt_{pt_min}_to_{pt_max}", hist_bin_title_rel_unc) + canv_rel_unc, histos_rel_unc, _leg_rel_unc = minimiser.plot_relative_uncertainties( + f"_pt_{pt_min}_to_{pt_max}", hist_bin_title_rel_unc + ) output.cd() if is_save_to_root_file[ObjectToSave.Canvas]: canv_rel_unc.Write() if is_save_to_root_file[ObjectToSave.Uncertainty]: - for _, hist in histos_rel_unc.values(): + for hist in histos_rel_unc.values(): hist.Write() if is_save_canvas_as_macro[PlotType.RelUnc]: - canv_rel_unc.SaveAs(f"canv_rel_unc_{ipt+1}.C") + canv_rel_unc.SaveAs(f"canv_rel_unc_{ipt + 1}.C") hist_bin_title_eff = hist_bin_title if is_draw_title[PlotType.Eff] else "" canv_eff, histos_eff, _leg_e = minimiser.plot_efficiencies(f"_pt_{pt_min}_to_{pt_max}", hist_bin_title_eff) @@ -331,10 +376,10 @@ def main(config): if is_save_to_root_file[ObjectToSave.Canvas]: canv_eff.Write() if is_save_to_root_file[ObjectToSave.Efficiency]: - for _, hist in histos_eff.values(): + for hist in histos_eff.values(): hist.Write() if is_save_canvas_as_macro[PlotType.Eff]: - canv_eff.SaveAs(f"canv_eff_{ipt+1}.C") + canv_eff.SaveAs(f"canv_eff_{ipt + 1}.C") hist_bin_title_frac = hist_bin_title if is_draw_title[PlotType.Frac] else "" canv_frac, histos_frac, _leg_f = minimiser.plot_fractions(f"_pt_{pt_min}_to_{pt_max}", hist_bin_title_frac) @@ -342,10 +387,10 @@ def main(config): if is_save_to_root_file[ObjectToSave.Canvas]: canv_frac.Write() if is_save_to_root_file[ObjectToSave.Fraction]: - for _, hist in histos_frac.values(): + for hist in histos_frac.values(): hist.Write() if is_save_canvas_as_macro[PlotType.Frac]: - canv_frac.SaveAs(f"canv_frac_{ipt+1}.C") + canv_frac.SaveAs(f"canv_frac_{ipt + 1}.C") hist_bin_title_cov = hist_bin_title if is_draw_title[PlotType.Cov] else "" canv_cov, histo_cov = minimiser.plot_cov_matrix(True, f"_pt_{pt_min}_to_{pt_max}", hist_bin_title_cov) @@ -355,7 +400,7 @@ def main(config): if is_save_to_root_file[ObjectToSave.CorrelationMatrix]: histo_cov.Write() if is_save_canvas_as_macro[PlotType.Cov]: - canv_cov.SaveAs(f"canv_cov_{ipt+1}.C") + canv_cov.SaveAs(f"canv_cov_{ipt + 1}.C") else: print(f"Minimization for pT {pt_min}, {pt_max} not successful") hist_minimisation_status.SetBinContent(ipt + 1, MinimisationStatus.Fail) @@ -377,7 +422,7 @@ def main(config): canv_combined.cd(4) canv_cov.DrawClonePad() - output_name_template = output_name_template.replace('.root', '.pdf') + output_name_template = output_name_template.replace(".root", ".pdf") output_name_rawy_pdf = f"Distr_{output_name_template}" output_name_eff_pdf = f"Eff_{output_name_template}" diff --git a/PWGHF/D2H/Macros/cut_variation.py b/PWGHF/D2H/Macros/cut_variation.py index 8a6c31a96b4..a361da090d6 100644 --- a/PWGHF/D2H/Macros/cut_variation.py +++ b/PWGHF/D2H/Macros/cut_variation.py @@ -13,7 +13,7 @@ import numpy as np # pylint: disable=import-error import ROOT # pylint: disable=import-error -sys.path.insert(0, '..') +sys.path.insert(0, "..") from style_formatter import set_global_style, set_object_style @@ -23,6 +23,7 @@ class MinimisationStatus(IntEnum): MonotonyViolation = auto() Fail = auto() + # pylint: disable=too-many-instance-attributes class CutVarMinimiser: """ @@ -176,10 +177,9 @@ def minimise_system(self, correlated=True, precision=1.0e-8, max_iterations=100) ) if correlated and unc_row > 0 and unc_col > 0: - self.m_cov_sets[i_row, i_col] = min(unc_row **2, unc_col ** 2) + self.m_cov_sets[i_row, i_col] = min(unc_row**2, unc_col**2) else: - self.m_cov_sets[i_row, i_col] = unc_row ** 2 if i_row == i_col else 0.0 - + self.m_cov_sets[i_row, i_col] = unc_row**2 if i_row == i_col else 0.0 self.m_cov_sets = np.matrix(self.m_cov_sets) try: @@ -209,13 +209,17 @@ def minimise_system(self, correlated=True, precision=1.0e-8, max_iterations=100) m_corr_yields_old = np.copy(self.m_corr_yields) - print(f"INFO: number of processed iterations = {iteration+1}\n") + print(f"INFO: number of processed iterations = {iteration + 1}\n") minimisation_status = MinimisationStatus.Success if correlated: m_cov_sets_diag = np.diag(self.m_cov_sets) - if not (np.all(m_cov_sets_diag[1:] > m_cov_sets_diag[:-1]) or np.all(m_cov_sets_diag[1:] < m_cov_sets_diag[:-1])): + if not ( + np.all(m_cov_sets_diag[1:] > m_cov_sets_diag[:-1]) or np.all(m_cov_sets_diag[1:] < m_cov_sets_diag[:-1]) + ): minimisation_status = MinimisationStatus.MonotonyViolation - print("\033[33mWARNING! minimise_system(): the residual vector uncertainties elements are not monotonous. Check the input for stability.\033[0m") + print( + "\033[33mWARNING! minimise_system(): the residual vector uncertainties elements are not monotonous. Check the input for stability.\033[0m" + ) print(f"residual vector uncertainties elements = {np.sqrt(m_cov_sets_diag)}\n") # chi2 @@ -351,8 +355,7 @@ def get_raw_prompt_fraction(self, effacc_p, effacc_np): return f_p, f_p_unc - def get_raw_prompt_fraction_ext(self, corry_p, corry_np, unc_corry_p, - unc_corry_np, cov_p_np, effacc_p, effacc_np): + def get_raw_prompt_fraction_ext(self, corry_p, corry_np, unc_corry_p, unc_corry_np, cov_p_np, effacc_p, effacc_np): """ Helper function to get the raw prompt fraction given the efficiencies @@ -386,11 +389,7 @@ def get_raw_prompt_fraction_ext(self, corry_p, corry_np, unc_corry_p, # derivatives of prompt fraction wrt corr yields d_p = (effacc_p * (rawy_p + rawy_np) - effacc_p**2 * corry_p) / (rawy_p + rawy_np) ** 2 d_np = -effacc_np * rawy_p / (rawy_p + rawy_np) ** 2 - f_p_unc = np.sqrt( - d_p**2 * unc_corry_p**2 - + d_np**2 * unc_corry_np**2 - + 2 * d_p * d_np * cov_p_np - ) + f_p_unc = np.sqrt(d_p**2 * unc_corry_p**2 + d_np**2 * unc_corry_np**2 + 2 * d_p * d_np * cov_p_np) return f_p, f_p_unc @@ -417,8 +416,9 @@ def get_raw_nonprompt_fraction(self, effacc_p, effacc_np): return f_np, f_np_unc - def get_raw_nonprompt_fraction_ext(self, corry_p, corry_np, unc_corry_p, - unc_corry_np, cov_p_np, effacc_p, effacc_np): + def get_raw_nonprompt_fraction_ext( + self, corry_p, corry_np, unc_corry_p, unc_corry_np, cov_p_np, effacc_p, effacc_np + ): """ Helper function to get the raw non-prompt fraction given the efficiencies @@ -446,8 +446,9 @@ def get_raw_nonprompt_fraction_ext(self, corry_p, corry_np, unc_corry_p, """ - f_p, f_np_unc = self.get_raw_prompt_fraction_ext(corry_p, corry_np, unc_corry_p, - unc_corry_np, cov_p_np, effacc_p, effacc_np) + f_p, f_np_unc = self.get_raw_prompt_fraction_ext( + corry_p, corry_np, unc_corry_p, unc_corry_np, cov_p_np, effacc_p, effacc_np + ) f_np = 1 - f_p return f_np, f_np_unc @@ -628,7 +629,7 @@ def plot_cov_matrix(self, correlated=True, suffix="", title=""): padleftmargin=0.14, padbottommargin=0.12, padrightmargin=0.12, - padtopmargin = 0.075, + padtopmargin=0.075, palette=ROOT.kRainBow, ) @@ -683,7 +684,7 @@ def plot_efficiencies(self, suffix="", title=""): """ suffix = suffix.replace(".", "_") - set_global_style(padleftmargin=0.14, padbottommargin=0.12, titleoffset=1.2, padtopmargin = 0.075) + set_global_style(padleftmargin=0.14, padbottommargin=0.12, titleoffset=1.2, padtopmargin=0.075) hist_eff_prompt = ROOT.TH1F( f"hEffPromptVsCut{suffix}", @@ -776,7 +777,7 @@ def plot_fractions(self, suffix="", title=""): """ suffix = suffix.replace(".", "_") - set_global_style(padleftmargin=0.14, padbottommargin=0.12, titleoffset=1.2, padtopmargin = 0.075) + set_global_style(padleftmargin=0.14, padbottommargin=0.12, titleoffset=1.2, padtopmargin=0.075) hist_f_prompt = ROOT.TH1F( f"hFracPromptVsCut{suffix}", @@ -887,7 +888,7 @@ def plot_uncertainties(self, suffix="", title=""): for i_bin, (unc_rawy, unc_res) in enumerate(zip(self.unc_raw_yields, m_cov_sets_diag)): hist_raw_yield_unc.SetBinContent(i_bin + 1, unc_rawy) - hist_residual_unc.SetBinContent(i_bin+1, unc_res) + hist_residual_unc.SetBinContent(i_bin + 1, unc_res) set_object_style(hist_raw_yield_unc, color=ROOT.kRed + 1, fillstyle=0) set_object_style(hist_residual_unc, color=ROOT.kAzure + 4, fillstyle=0) @@ -923,7 +924,6 @@ def plot_uncertainties(self, suffix="", title=""): return canvas, histos, leg - # pylint: disable=no-member def plot_relative_uncertainties(self, suffix="", title=""): """ @@ -974,10 +974,19 @@ def plot_relative_uncertainties(self, suffix="", title=""): self.n_sets - 0.5, ) - for i_bin, (unc_rawy, rawy, unc_eff_prompt, eff_prompt, unc_eff_nonprompt, eff_nonprompt) in enumerate(zip(self.unc_raw_yields, self.raw_yields, self.unc_eff_prompt, self.eff_prompt, self.unc_eff_nonprompt, self.eff_nonprompt)): + for i_bin, (unc_rawy, rawy, unc_eff_prompt, eff_prompt, unc_eff_nonprompt, eff_nonprompt) in enumerate( + zip( + self.unc_raw_yields, + self.raw_yields, + self.unc_eff_prompt, + self.eff_prompt, + self.unc_eff_nonprompt, + self.eff_nonprompt, + ) + ): hist_raw_yield_rel_unc.SetBinContent(i_bin + 1, unc_rawy / rawy) - hist_eff_prompt_rel_unc.SetBinContent(i_bin+1, unc_eff_prompt / eff_prompt) - hist_eff_nonprompt_rel_unc.SetBinContent(i_bin+1, unc_eff_nonprompt / eff_nonprompt) + hist_eff_prompt_rel_unc.SetBinContent(i_bin + 1, unc_eff_prompt / eff_prompt) + hist_eff_nonprompt_rel_unc.SetBinContent(i_bin + 1, unc_eff_nonprompt / eff_nonprompt) set_object_style(hist_raw_yield_rel_unc, color=ROOT.kBlack, fillstyle=0) set_object_style(hist_eff_prompt_rel_unc, color=ROOT.kRed + 1, fillstyle=0) @@ -988,7 +997,12 @@ def plot_relative_uncertainties(self, suffix="", title=""): -0.5, 0.0, self.n_sets - 0.5, - max(hist_raw_yield_rel_unc.GetMaximum(), hist_eff_prompt_rel_unc.GetMaximum(), hist_eff_nonprompt_rel_unc.GetMaximum()) * 1.2, + max( + hist_raw_yield_rel_unc.GetMaximum(), + hist_eff_prompt_rel_unc.GetMaximum(), + hist_eff_nonprompt_rel_unc.GetMaximum(), + ) + * 1.2, ";cut set;relative unc.", ) leg = ROOT.TLegend(0.2, 0.75, 0.4, 0.85) @@ -1012,7 +1026,7 @@ def plot_relative_uncertainties(self, suffix="", title=""): histos = { "rawy": hist_raw_yield_rel_unc, "prompt": hist_eff_prompt_rel_unc, - "nonprompt": hist_eff_nonprompt_rel_unc + "nonprompt": hist_eff_nonprompt_rel_unc, } return canvas, histos, leg