def _calculate_confidence_band(root_obj: TF1, ci: float, steps: int = 1000) -> dict: """ Calculate confidence bands from a fit of a TF1 to a histogram. Parameters ---------- root_obj : TH1 ROOT TF1 pdf used for the fit ci : float Confidence interval steps : int Number of points in band Returns ------- dict Dictionary with x, y, xerr, yerr points """ assert(isinstance(root_obj, TF1)) band = TGraphErrors(steps) lowb, highb = root_obj.GetXaxis().GetXmin(), root_obj.GetXaxis().GetXmax() for i in range(steps): x = (lowb + ( (highb - lowb) / steps) * i) y = 0 band.SetPoint(i, x, y) (TVirtualFitter.GetFitter()).GetConfidenceIntervals(band, ci) return _convert_tgrapherrors(band)
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)}