def results(histos_central, systematics, title, legend_titles, x_label, y_label, save_path, ratio, **kwargs): if len(histos_central) != len(systematics): print(f"Number of systematics {len(systematics)} differs from number of " \ f"histograms {len(histos_central)}") return if len(histos_central) != len(legend_titles): print(f"Number of legend titles {len(legend_titles)} differs from number of " \ f"histograms {len(histos_central)}") return colors = kwargs.get("colors", [kRed - i for i in range(len(histos_central))]) if len(histos_central) != len(colors): print(f"Number of colors {len(colors)} differs from number of " \ f"histograms {len(histos_central)}") return colors = colors * 2 markerstyles = [1] * len(histos_central) + [20] * len(histos_central) draw_options = ["E2"] * len(histos_central) + [""] * len(histos_central) legend_titles = [None] * len(histos_central) + legend_titles if ratio is False: plot_histograms([*systematics, *histos_central], True, [False, False, [1e-8, 1]], legend_titles, title, x_label, y_label, "", save_path, linesytles=[1], markerstyles=markerstyles, colors=colors, linewidths=[1], draw_options=draw_options, fillstyles=[0]) elif ratio is True: plot_histograms([*systematics, *histos_central], True, [False, True, [0.01, 100]], legend_titles, title, x_label, y_label, "", save_path, linesytles=[1], markerstyles=markerstyles, colors=colors, linewidths=[1], draw_options=draw_options, fillstyles=[0]) else: plot_histograms([*systematics, *histos_central], False, [False, True, [0, 0.6]], legend_titles, title, x_label, y_label, "", save_path, linesytles=[1], markerstyles=markerstyles, colors=colors, linewidths=[1], draw_options=draw_options, fillstyles=[0])
def plot_hfptspectrum_ml_over_std(case_ml, ana_type_ml, period_number, filepath_std, case_std, scale_std=None, map_std_bins=None, mult_bin=None, ml_histo_names=None, std_histo_names=None, suffix=""): with open("../data/database_ml_parameters_%s.yml" % case_ml, 'r') as param_config: data_param = yaml.load(param_config, Loader=yaml.FullLoader) if period_number < 0: filepath_ml = data_param[case_ml]["analysis"][ana_type_ml]["data"][ "resultsallp"] else: filepath_ml = data_param[case_ml]["analysis"][ana_type_ml]["data"][ "results"][period_number] # Get pt spectrum files if mult_bin is None: mult_bin = 0 path_ml = f"{filepath_ml}/finalcross{case_ml}{ana_type_ml}mult{mult_bin}.root" if not os.path.exists(path_ml): FILES_NOT_FOUND.append(path_ml) return name = data_param[case_ml]["analysis"][ana_type_ml]["latexnamemeson"] file_ml = TFile.Open(path_ml, "READ") file_std = TFile.Open(filepath_std, "READ") # Collect histo names to quickly loop later histo_names = [ "hDirectMCpt", "hFeedDownMCpt", "hDirectMCptMax", "hDirectMCptMin", "hFeedDownMCptMax", "hFeedDownMCptMin", "hDirectEffpt", "hFeedDownEffpt", "hRECpt", "histoYieldCorr", "histoYieldCorrMax", "histoYieldCorrMin", "histoSigmaCorr", "histoSigmaCorrMax", "histoSigmaCorrMin" ] if ml_histo_names is None: ml_histo_names = histo_names if std_histo_names is None: std_histo_names = histo_names for hn_ml, hn_std in zip(ml_histo_names, std_histo_names): histo_ml = file_ml.Get(hn_ml) histo_std_tmp = file_std.Get(hn_std) histo_std = None if not histo_ml: print(f"Could not find histogram {hn_ml}, continue...") continue if not histo_std_tmp: print(f"Could not find histogram {hn_std}, continue...") continue if "MC" not in hn_ml and map_std_bins is not None: histo_std = histo_ml.Clone("std_rebin") histo_std.Reset("ICESM") contents = [0] * histo_ml.GetNbinsX() errors = [0] * histo_ml.GetNbinsX() for ml_bin, std_bins in map_std_bins: for b in std_bins: contents[ml_bin-1] += histo_std_tmp.GetBinWidth(b) * \ histo_std_tmp.GetBinContent(b) / histo_ml.GetBinWidth(ml_bin) errors[ml_bin - 1] += histo_std_tmp.GetBinError( b) * histo_std_tmp.GetBinError(b) for b in range(histo_std.GetNbinsX()): histo_std.SetBinContent(b + 1, contents[b]) histo_std.SetBinError(b + 1, sqrt(errors[b])) else: histo_std = histo_std_tmp.Clone("std_cloned") if scale_std is not None: histo_std.Scale(scale_std) folder_plots = data_param[case_ml]["analysis"]["dir_general_plots"] if not os.path.exists(folder_plots): print("creating folder ", folder_plots) os.makedirs(folder_plots) h_ratio = histo_ml.Clone(f"{histo_ml.GetName()}_ratio") h_ratio.Divide(histo_std) save_path = f"{folder_plots}/{hn_ml}_ml_std_{case_ml}_over_{case_std}_{suffix}.eps" plot_histograms([h_ratio], False, False, None, histo_ml.GetTitle(), "#it{p}_{T} (GeV/#it{c}", f"{name} / {case_std}", "", save_path)
def compare_ml_std_ratio(case_ml_1, case_ml_2, ana_type_ml, period_number, filepath_std_1, filepath_std_2, scale_std_1=None, scale_std_2=None, map_std_bins=None, mult_bin=None, ml_histo_names=None, std_histo_names_1=None, std_histo_names_2=None, suffix=""): with open("../data/database_ml_parameters_%s.yml" % case_ml_1, 'r') as param_config: data_param_1 = yaml.load(param_config, Loader=yaml.FullLoader) with open("../data/database_ml_parameters_%s.yml" % case_ml_2, 'r') as param_config: data_param_2 = yaml.load(param_config, Loader=yaml.FullLoader) if period_number < 0: filepath_ml_1 = data_param_1[case_ml_1]["analysis"][ana_type_ml][ "data"]["resultsallp"] filepath_ml_2 = data_param_2[case_ml_2]["analysis"][ana_type_ml][ "data"]["resultsallp"] else: filepath_ml_1 = \ data_param_1[case_ml_1]["analysis"][ana_type_ml]["data"]["results"][period_number] filepath_ml_2 = \ data_param_2[case_ml_2]["analysis"][ana_type_ml]["data"]["results"][period_number] name_1 = data_param_1[case_ml_1]["analysis"][ana_type_ml]["latexnamemeson"] name_2 = data_param_2[case_ml_2]["analysis"][ana_type_ml]["latexnamemeson"] # Get pt spectrum files if mult_bin is None: mult_bin = 0 path_ml_1 = f"{filepath_ml_1}/finalcross{case_ml_1}{ana_type_ml}mult{mult_bin}.root" path_ml_2 = f"{filepath_ml_2}/finalcross{case_ml_2}{ana_type_ml}mult{mult_bin}.root" if not os.path.exists(path_ml_1): FILES_NOT_FOUND.append(path_ml_1) return if not os.path.exists(path_ml_2): FILES_NOT_FOUND.append(path_ml_2) return file_ml_1 = TFile.Open(path_ml_1, "READ") file_ml_2 = TFile.Open(path_ml_2, "READ") file_std_1 = TFile.Open(filepath_std_1, "READ") file_std_2 = TFile.Open(filepath_std_2, "READ") # Collect histo names to quickly loop later histo_names = [ "hDirectMCpt", "hFeedDownMCpt", "hDirectMCptMax", "hDirectMCptMin", "hFeedDownMCptMax", "hFeedDownMCptMin", "hDirectEffpt", "hFeedDownEffpt", "hRECpt", "histoYieldCorr", "histoYieldCorrMax", "histoYieldCorrMin", "histoSigmaCorr", "histoSigmaCorrMax", "histoSigmaCorrMin" ] if ml_histo_names is None: ml_histo_names = histo_names if std_histo_names_1 is None: std_histo_names_1 = histo_names if std_histo_names_2 is None: std_histo_names_2 = histo_names for hn_ml, hn_std_1, hn_std_2 in zip(ml_histo_names, std_histo_names_1, std_histo_names_2): histo_ml_1 = file_ml_1.Get(hn_ml) histo_ml_2 = file_ml_2.Get(hn_ml) histo_std_tmp_1 = file_std_1.Get(hn_std_1) histo_std_tmp_2 = file_std_2.Get(hn_std_2) histo_std_1 = None histo_std_2 = None if not histo_ml_1: print(f"Could not find histogram {hn_ml}, continue...") continue if not histo_ml_2: print(f"Could not find histogram {hn_ml}, continue...") continue if not histo_std_tmp_1: print(f"Could not find histogram {hn_std_1}, continue...") continue if not histo_std_tmp_2: print(f"Could not find histogram {hn_std_2}, continue...") continue if "MC" not in hn_ml and map_std_bins is not None: histo_std_1 = histo_ml_1.Clone("std_rebin_1") histo_std_1.Reset("ICESM") histo_std_2 = histo_ml_2.Clone("std_rebin_2") histo_std_2.Reset("ICESM") contents = [0] * histo_ml_1.GetNbinsX() errors = [0] * histo_ml_1.GetNbinsX() for ml_bin, std_bins in map_std_bins: for b in std_bins: contents[ ml_bin - 1] += histo_std_tmp_1.GetBinContent(b) / len(std_bins) errors[ml_bin-1] += \ histo_std_tmp_1.GetBinError(b) * histo_std_tmp_1.GetBinError(b) for b in range(histo_std_1.GetNbinsX()): histo_std_1.SetBinContent(b + 1, contents[b]) histo_std_1.SetBinError(b + 1, sqrt(errors[b])) contents = [0] * histo_ml_2.GetNbinsX() errors = [0] * histo_ml_2.GetNbinsX() for ml_bin, std_bins in map_std_bins: for b in std_bins: contents[ ml_bin - 1] += histo_std_tmp_2.GetBinContent(b) / len(std_bins) errors[ml_bin-1] += \ histo_std_tmp_2.GetBinError(b) * histo_std_tmp_2.GetBinError(b) for b in range(histo_std_2.GetNbinsX()): histo_std_2.SetBinContent(b + 1, contents[b]) histo_std_2.SetBinError(b + 1, sqrt(errors[b])) else: histo_std_1 = histo_std_tmp_1.Clone("std_cloned_1") histo_std_2 = histo_std_tmp_2.Clone("std_cloned_2") if scale_std_1 is not None: histo_std_1.Scale(scale_std_1) if scale_std_2 is not None: histo_std_2.Scale(scale_std_2) histo_ratio_ml = histo_ml_1.Clone("{histo_ml_1.GetName()}_ratio") histo_ratio_ml.Divide(histo_ml_2) histo_ratio_std = histo_std_1.Clone("{histo_std_1.GetName()}_ratio") histo_ratio_std.Divide(histo_std_2) folder_plots = data_param_1[case_ml_1]["analysis"]["dir_general_plots"] if not os.path.exists(folder_plots): print("creating folder ", folder_plots) os.makedirs(folder_plots) save_path = f"{folder_plots}/ratio_{case_ml_1}_{case_ml_2}_{hn_ml}_ml_std_mult_" \ f"{mult_bin}_period_{period_number}{suffix}.eps" plot_histograms([histo_ratio_std, histo_ratio_ml], True, True, ["STD", "ML"], "Ratio", "#it{p}_{T} (GeV/#it{c}", f"{name_1} / {name_2}", "ML / STD", save_path) folder_plots = data_param_2[case_ml_2]["analysis"]["dir_general_plots"] if not os.path.exists(folder_plots): print("creating folder ", folder_plots) os.makedirs(folder_plots) save_path = f"{folder_plots}/ratio_{case_ml_1}_{case_ml_2}_{hn_ml}_ml_std_mult_" \ f"{mult_bin}_period_{period_number}{suffix}.eps" plot_histograms([histo_ratio_std, histo_ratio_ml], True, True, ["STD", "ML"], "Ratio", "#it{p}_{T} (GeV/#it{c}", f"{name_1} / {name_2}", "ML / STD", save_path)
def draw_fits(self, save_dir, root_dir=None): """ Draw all fits one-by-one Args: save_dir: directory where to save plots root_dir: TDirectory where to save summary plots """ gStyle.SetOptStat(0) gStyle.SetOptStat(0000) gStyle.SetPalette(1) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) bins2 = self.get_bins2() bins1_ranges = self.pars_factory.bins1_edges_low.copy() bins1_ranges.append(self.pars_factory.bins1_edges_up[-1]) n_bins1 = len(bins1_ranges) - 1 # Summarize in mult histograms in pT bins yieldshistos = {ibin2: TH1F("hyields%d" % (ibin2), "", \ n_bins1, array("d", bins1_ranges)) for ibin2 in bins2} means_histos = {ibin2:TH1F("hmeanss%d" % (ibin2), "", \ n_bins1, array("d", bins1_ranges)) for ibin2 in bins2} sigmas_histos = {ibin2: TH1F("hsigmas%d" % (ibin2), "", \ n_bins1, array("d", bins1_ranges)) for ibin2 in bins2} have_summary_pt_bins = [] means_init_mc_histos = TH1F("hmeans_init_mc", "", n_bins1, array("d", bins1_ranges)) sigmas_init_mc_histos = TH1F("hsigmas_init_mc", "", n_bins1, array("d", bins1_ranges)) means_init_data_histos = TH1F("hmeans_init_data", "", n_bins1, array("d", bins1_ranges)) sigmas_init_data_histos = TH1F("hsigmas_init_data", "", n_bins1, array("d", bins1_ranges)) nx = 4 ny = 2 canvy = 533 if n_bins1 > 12: nx = 5 ny = 4 canvy = 1200 elif n_bins1 > 8: nx = 4 ny = 3 canvy = 800 canvas_init_mc = TCanvas("canvas_init_mc", "MC", 1000, canvy) canvas_init_data = TCanvas("canvas_init_data", "Data", 1000, canvy) canvas_data = {ibin2: TCanvas("canvas_data%d" % (ibin2), "Data", 1000, canvy) \ for ibin2 in bins2} canvas_init_mc.Divide(nx, ny) canvas_init_data.Divide(nx, ny) for c in canvas_data.values(): c.Divide(nx, ny) # Need to cache some object for which the canvas is only written after the loop... for (ibin1, ibin2), fit in self.central_fits.items(): bin_id_match = self.pars_factory.bin_matching[ibin1] # Some variables set for drawing title = f"{self.pars_factory.bins1_edges_low[ibin1]:.1f} < #it{{p}}_{{T}} < " \ f"{self.pars_factory.bins1_edges_up[ibin1]:.1f}" \ f"(prob > {self.pars_factory.prob_cut_fin[bin_id_match]:.2f})" x_axis_label = "#it{M}_{inv} (GeV/#it{c}^{2})" n_sigma_signal = self.pars_factory.n_sigma_signal suffix_write = self.pars_factory.make_suffix(ibin1, ibin2) kernel = fit.kernel histo = fit.histo # Central fits y_axis_label = \ f"Entries/({histo.GetBinWidth(1) * 1000:.0f} MeV/#it{{c}}^{{2}})" canvas = TCanvas("fit_canvas", suffix_write, 700, 700) fit.draw(canvas, sigma_signal=n_sigma_signal, x_axis_label=x_axis_label, y_axis_label=y_axis_label, title=title) if self.pars_factory.apply_weights is False: canvas.SaveAs( make_file_path(save_dir, "fittedplot", "eps", None, suffix_write)) else: canvas.SaveAs( make_file_path(save_dir, "fittedplotweights", "eps", None, suffix_write)) canvas.Close() fit.draw(canvas_data[ibin2].cd(ibin1 + 1), sigma_signal=n_sigma_signal, x_axis_label=x_axis_label, y_axis_label=y_axis_label, title=title) if fit.success: # Only fill these summary plots in case of success yieldshistos[ibin2].SetBinContent(ibin1 + 1, kernel.GetRawYield()) yieldshistos[ibin2].SetBinError(ibin1 + 1, kernel.GetRawYieldError()) means_histos[ibin2].SetBinContent(ibin1 + 1, kernel.GetMean()) means_histos[ibin2].SetBinError(ibin1 + 1, kernel.GetMeanUncertainty()) sigmas_histos[ibin2].SetBinContent(ibin1 + 1, kernel.GetSigma()) sigmas_histos[ibin2].SetBinError(ibin1 + 1, kernel.GetSigmaUncertainty()) # Residual plot c_res = TCanvas('cRes', 'The Fit Canvas', 800, 800) c_res.cd() h_pulls = histo.Clone(f"{histo.GetName()}_pull") h_residual_trend = histo.Clone( f"{histo.GetName()}_residual_trend") h_pulls_trend = histo.Clone(f"{histo.GetName()}_pulls_trend") _ = kernel.GetOverBackgroundResidualsAndPulls( \ h_pulls, h_residual_trend, h_pulls_trend, \ self.pars_factory.fit_range_low[ibin1], \ self.pars_factory.fit_range_up[ibin1]) h_residual_trend.Draw() c_res.SaveAs( make_file_path(save_dir, "residual", "eps", None, suffix_write)) c_res.Close() # Summary plots to be done only once per pT bin if ibin1 in have_summary_pt_bins: continue have_summary_pt_bins.append(ibin1) # Pre-fit MC suffix_write = self.pars_factory.make_suffix( ibin1, self.pars_factory.bins2_int_bin) pre_fit_mc = self.pre_fits_mc[ibin1] kernel = pre_fit_mc.kernel histo = pre_fit_mc.histo y_axis_label = \ f"Entries/({histo.GetBinWidth(1) * 1000:.0f} MeV/#it{{c}}^{{2}})" canvas = TCanvas("fit_canvas_mc_init", suffix_write, 700, 700) pre_fit_mc.draw(canvas, x_axis_label=x_axis_label, y_axis_label=y_axis_label, title=title) canvas.SaveAs( make_file_path(save_dir, "fittedplot_integrated_mc", "eps", None, suffix_write)) canvas.Close() pre_fit_mc.draw(canvas_init_mc.cd(ibin1 + 1), x_axis_label=x_axis_label, y_axis_label=y_axis_label, title=title) if pre_fit_mc.success: # Only fill these summary plots in case of success means_init_mc_histos.SetBinContent(ibin1 + 1, kernel.GetParameter(1)) means_init_mc_histos.SetBinError(ibin1 + 1, kernel.GetParError(1)) sigmas_init_mc_histos.SetBinContent(ibin1 + 1, kernel.GetParameter(2)) sigmas_init_mc_histos.SetBinError(ibin1 + 1, kernel.GetParError(2)) pre_fit_data = self.pre_fits_data[ibin1] kernel = pre_fit_data.kernel histo = pre_fit_data.histo # Pre-fit data y_axis_label = \ f"Entries/({histo.GetBinWidth(1) * 1000:.0f} MeV/#it{{c}}^{{2}})" canvas = TCanvas("fit_canvas_data_init", suffix_write, 700, 700) pre_fit_data.draw(canvas, sigma_signal=n_sigma_signal, x_axis_label=x_axis_label, y_axis_label=y_axis_label, title=title) canvas.SaveAs( make_file_path(save_dir, "fittedplot_integrated", "eps", None, suffix_write)) canvas.Close() pre_fit_data.draw(canvas_init_data.cd(ibin1 + 1), sigma_signal=n_sigma_signal, x_axis_label=x_axis_label, y_axis_label=y_axis_label, title=title) if pre_fit_data.success: # Only fill these summary plots in case of success means_init_data_histos.SetBinContent(ibin1 + 1, kernel.GetMean()) means_init_data_histos.SetBinError(ibin1 + 1, kernel.GetMeanUncertainty()) sigmas_init_data_histos.SetBinContent(ibin1 + 1, kernel.GetSigma()) sigmas_init_data_histos.SetBinError( ibin1 + 1, kernel.GetSigmaUncertainty()) canvas_init_mc.SaveAs(make_file_path(save_dir, "canvas_InitMC", "eps")) canvas_init_mc.Close() canvas_init_data.SaveAs( make_file_path(save_dir, "canvas_InitData", "eps")) canvas_init_data.Close() for ibin2 in bins2: suffix2 = f"ibin2_{ibin2}" canvas_data[ibin2].SaveAs( make_file_path(save_dir, "canvas_FinalData", "eps", None, suffix2)) if root_dir: root_dir.cd() yieldshistos[ibin2].Write() means_histos[ibin2].Write() sigmas_histos[ibin2].Write() #canvas_data[ibin2].Close() latex_bin2_var = self.ana_config["latexbin2var"] latex_hadron_name = self.ana_config["latexnamehadron"] # Plot some summary historgrams leg_strings = [f"{self.pars_factory.bins2_edges_low[ibin2]} #leq {latex_bin2_var} < " \ f"{self.pars_factory.bins2_edges_up[ibin2]}" for ibin2 in bins2] save_name = make_file_path(save_dir, "Yields", "eps", None, [self.case, self.ana_type]) # Yields summary plot plot_histograms( [yieldshistos[ibin2] for ibin2 in bins2], True, True, leg_strings, "uncorrected yields", "#it{p}_{T} (GeV/#it{c})", f"Uncorrected yields {latex_hadron_name} {self.ana_type}", "mult. / int.", save_name) save_name = make_file_path(save_dir, "Means", "eps", None, [self.case, self.ana_type]) # Means summary plot plot_histograms([means_histos[ibin2] for ibin2 in bins2], False, True, leg_strings, "Means", "#it{p}_{T} (GeV/#it{c})", "#mu_{fit} " + f"{latex_hadron_name} {self.ana_type}", "mult. / int.", save_name) save_name = make_file_path(save_dir, "Sigmas", "eps", None, [self.case, self.ana_type]) #Sigmas summary plot plot_histograms([sigmas_histos[ibin2] for ibin2 in bins2], False, True, leg_strings, "Sigmas", "#it{p}_{T} (GeV/#it{c})", "#sigma_{fit} " + f"{latex_hadron_name} {self.ana_type}", "mult. / int.", save_name) # Plot the initialized means and sigma for MC and data save_name = make_file_path(save_dir, "Means_mult_int", "eps", None, [self.case, self.ana_type]) plot_histograms([means_init_mc_histos, means_init_data_histos], False, False, ["MC", "data"], "Means of int. mult.", "#it{p}_{T} (GeV/#it{c})", "#mu_{fit} " + f"{latex_hadron_name} {self.ana_type}", "", save_name) save_name = make_file_path(save_dir, "Sigmas_mult_int", "eps", None, [self.case, self.ana_type]) plot_histograms([sigmas_init_mc_histos, sigmas_init_data_histos], False, False, ["MC", "data"], "Sigmas of int. mult.", "#it{p}_{T} (GeV/#it{c})", "#sigma_{fit} " + f"{latex_hadron_name} {self.ana_type}", "", save_name)
def plot_hfspectrum_years_ratios(case_1, case_2, ana_type, mult_bins=None): with open("data/database_ml_parameters_%s.yml" % case_1, 'r') as param_config: data_param_1 = yaml.load(param_config, Loader=yaml.FullLoader) with open("data/database_ml_parameters_%s.yml" % case_2, 'r') as param_config: data_param_2 = yaml.load(param_config, Loader=yaml.FullLoader) folder_plots_1 = data_param_1[case_1]["analysis"]["dir_general_plots"] folder_plots_2 = data_param_2[case_2]["analysis"]["dir_general_plots"] folder_plots_1 = folder_plots_1 + "/comp_years" folder_plots_2 = folder_plots_2 + "/comp_years" if not os.path.exists(folder_plots_1): print("creating folder ", folder_plots_1) os.makedirs(folder_plots_1) if not os.path.exists(folder_plots_2): print("creating folder ", folder_plots_2) os.makedirs(folder_plots_2) use_period = data_param_1[case_1]["analysis"][ana_type]["useperiod"] latexbin2var = data_param_1[case_1]["analysis"][ana_type]["latexbin2var"] result_paths_1 = [data_param_1[case_1]["analysis"][ana_type]["data"]["results"][i] \ for i in range(len(use_period)) if use_period[i]] result_paths_1.insert( 0, data_param_1[case_1]["analysis"][ana_type]["data"]["resultsallp"]) result_paths_2 = [data_param_2[case_2]["analysis"][ana_type]["data"]["results"][i] \ for i in range(len(use_period)) if use_period[i]] result_paths_2.insert( 0, data_param_2[case_2]["analysis"][ana_type]["data"]["resultsallp"]) # Assume same in all particle cases periods = [data_param_1[case_1]["multi"]["data"]["period"][i] \ for i in range(len(use_period)) if use_period[i]] periods.insert(0, "merged") binsmin = data_param_1[case_1]["analysis"][ana_type]["sel_binmin2"] binsmax = data_param_1[case_1]["analysis"][ana_type]["sel_binmax2"] name_1 = data_param_1[case_1]["analysis"][ana_type]["latexnamemeson"] name_2 = data_param_2[case_2]["analysis"][ana_type]["latexnamemeson"] #br_1 = data_param_1[case_1]["ml"]["opt"]["BR"] #br_2 = data_param_2[case_2]["ml"]["opt"]["BR"] #sigmav0_1 = data_param_1[case_1]["analysis"]["sigmav0"] #sigmav0_2 = data_param_2[case_2]["analysis"]["sigmav0"] if mult_bins is None: mult_bins = range(len(binsmin)) files_mult_1 = [] files_mult_2 = [] periods_string = "_".join(periods) for imult in mult_bins: files_years_1 = [] files_years_2 = [] for folder_1, folder_2 in zip(result_paths_1, result_paths_2): path_1 = f"{folder_1}/finalcross{case_1}{ana_type}mult{imult}.root" path_2 = f"{folder_2}/finalcross{case_2}{ana_type}mult{imult}.root" if not os.path.exists(path_1) or not os.path.exists(path_2): FILES_NOT_FOUND.append(f"{path_1} or {path_2}") continue files_years_1.append(path_1) files_years_2.append(path_2) files_mult_1.append(files_years_1) files_mult_2.append(files_years_2) histos = [] legend_titles = [] for period, path_1, path_2 in zip(periods, files_years_1, files_years_2): file_1 = TFile.Open(path_1, "READ") file_2 = TFile.Open(path_2, "READ") hyield_1 = file_1.Get("histoSigmaCorr") hyield_1.SetDirectory(0) hyield_2 = file_2.Get("histoSigmaCorr") hyield_2.SetDirectory(0) #hyield_1.Scale(1./(br_1 * sigmav0_1 * 1e12)) #hyield_2.Scale(1./(br_2 * sigmav0_2 * 1e12)) hyield_ratio = hyield_1.Clone( f"{case_1}_{case_2}_ratio_{period}_{imult}") hyield_ratio.Divide(hyield_2) histos.append(hyield_ratio) l_string = f"{binsmin[imult]:.1f} #leq {latexbin2var} < {binsmax[imult]:.1f} "\ f"({ana_type}), {period}" legend_titles.append(l_string) if not histos: continue sub_folder = os.path.join(folder_plots_1, "ratios", ana_type) if not os.path.exists(sub_folder): os.makedirs(sub_folder) save_path = f"{sub_folder}/{histos[0].GetName()}_combined_{periods_string}_{imult}.eps" y_label = f"{histos[0].GetYaxis().GetTitle()} {name_1} / {name_2}" plot_histograms(histos, True, True, legend_titles, histos[0].GetTitle(), "#it{p}_{T} (GeV/#it{c})", y_label, "year / merged", save_path)
comment = "(empty)" l_string = f"{binsmin[imult]:.1f} #leq {latexbin2var} < {binsmax[imult]:.1f} "\ f"({ana_type}), {period} {comment}" legend_titles.append(l_string) if not histos: continue sub_folder = os.path.join(folder_plots, ana_type) if not os.path.exists(sub_folder): os.makedirs(sub_folder) save_path = f"{sub_folder}/{hn}_combined_{periods_string}_{imult}.eps" label_y = f"{histos[0].GetYaxis().GetTitle()} {name}" plot_histograms(histos, True, True, legend_titles, histos[0].GetTitle(), "#it{p}_{T} (GeV/#it{c})", label_y, "year / merged", save_path) ##################################### gROOT.SetBatch(True) plot_hfspectrum_years("LcpK0spp", "MBvspt_ntrkl") #plot_hfspectrum_years("LcpK0spp", "MBvspt_v0m") plot_hfspectrum_years("LcpK0spp", "MBvspt_perc") #plot_hfspectrum_years("LcpK0spp", "V0mvspt") #plot_hfspectrum_years("LcpK0spp", "V0mvspt_perc_v0m") plot_hfspectrum_years("LcpK0spp", "SPDvspt") plot_hfspectrum_years("D0pp", "MBvspt_ntrkl")
def results(histos_central, systematics, title, legend_titles, x_label, y_label, save_path, ratio, **kwargs): if systematics and (len(histos_central) != len(systematics)): print(f"Number of systematics {len(systematics)} differs from number of " \ f"histograms {len(histos_central)}") return if len(histos_central) != len(legend_titles): print(f"Number of legend titles {len(legend_titles)} differs from number of " \ f"histograms {len(histos_central)}") return colors = kwargs.get("colors", [kRed - i for i in range(len(histos_central))]) if len(histos_central) != len(colors): print(f"Number of colors {len(colors)} differs from number of " \ f"histograms {len(histos_central)}") return y_range = kwargs.get("y_range", [1e-8, 1]) markerstyles = [1] * len(histos_central) + [20] * len(histos_central) \ if systematics else [20] * len(histos_central) draw_options = ["E2"] * len(histos_central) + [""] * len(histos_central) \ if systematics else [""] * len(histos_central) if systematics: colors = colors * 2 legend_titles = [None] * len(histos_central) + legend_titles histos_central = systematics + histos_central if ratio is False: plot_histograms(histos_central, kwargs.get("log_y", True), [False, False, y_range], legend_titles, title, x_label, y_label, "", save_path, linesytles=[1], markerstyles=markerstyles, colors=colors, linewidths=[1], draw_options=draw_options, fillstyles=[0]) elif ratio == 1: plot_histograms(histos_central, kwargs.get("log_y", True), [True, False, y_range], legend_titles, title, x_label, y_label, "", save_path, linesytles=[1], markerstyles=markerstyles, colors=colors, linewidths=[1], draw_options=draw_options, fillstyles=[0]) elif ratio == 2: plot_histograms(histos_central, kwargs.get("log_y", False), [False, True, [0, 3.1]], legend_titles, title, x_label, y_label, "", save_path, linesytles=[1], markerstyles=markerstyles, colors=colors, linewidths=[1], draw_options=draw_options, fillstyles=[0]) elif ratio == 3: plot_histograms(histos_central, kwargs.get("log_y", False), [False, True, [0, 3.1]], legend_titles, title, x_label, y_label, "", save_path, linesytles=[1], markerstyles=markerstyles, colors=colors, linewidths=[1], draw_options=draw_options, fillstyles=[0]) else: plot_histograms(histos_central, kwargs.get("log_y", False), [False, True, [0, 1.0]], legend_titles, title, x_label, y_label, "", save_path, linesytles=[1], markerstyles=markerstyles, colors=colors, linewidths=[1], draw_options=draw_options, fillstyles=[0])