def calculate_pull(hist: TH1, ff: TF1) -> tuple: """ Calculate a pull plot between a histogram and a fitted function. Parameters ---------- hist : TH1 ROOT TH1 histogram ff : TF1 ROOT TF1 function used to fit. Returns ------- x, y : np.array, np.array points for pull plot """ x, y = [], [] for n in range(1, hist.GetNbinsX() + 1): x.append(hist.GetBinCenter(n)) if not hist.GetBinError(n): y.append(0) continue y.append((hist.GetBinContent(n) - ff.Eval(hist.GetBinCenter(n))) / ( hist.GetBinError(n))) return x, y
def _convert_tf1(root_obj: TF1) -> dict: """ Takes values from a fit function and puts them into an array to be plotted. Parameters ---------- root_obj : TF1 ROOT TF1 Returns ------- dict Dictionary with x, y points """ assert(isinstance(root_obj, TF1)) x = np.linspace(root_obj.GetXaxis().GetXmin(), root_obj.GetXaxis().GetXmax(), 1000) y = [] for p in x: y.append(root_obj.Eval(p)) return {'x': x, 'y': np.array(y)}