def fit_hist(hist, fit_options="LR"):
  # I: fit using integral of func (not value @ centre, better for rapid function)
  # L: Loglikelihood (better @ low stats)
  # V: verbose mode
  # E: better errors
  # M: More, improve fit results (looks for alt local minima)
  # R: fit to function range
  def get_fit_goodness(func):
    return  (func.GetChisquare()/func.GetNDF())
  initial_settings = get_initial_settings(hist)
  fit_func = get_func_with_named_initialised_param("f_"+hist.GetTitle(), hist, 
                                                   func_fmt, initial_settings,
                                                   l_bound, u_bound)
  fit_func.SetNpx(10000) # number of points for drawing the function 
  hist.Fit(fit_func, fit_options)
  # best_t = t = initial_settings[2][1](hist)
  # d=0.05
  # min_goodness = goodness = get_fit_goodness(fit_func)
  # while (goodness)>3.0:
  #   t+=d
  #   fit_func.SetParameter(2,t)
  #   hist.Fit(fit_func, fit_options)
  #   goodness = get_fit_goodness(fit_func)
  #   if goodness < min_goodness: 
  #     min_goodness=goodness
  #     best_t = t
  #   if t > (initial_settings[2][1](hist)+ d*100):
  #     print "breaking fit loop, best fit {} for t={}".format(min_goodness, best_t)
  #     break 
      
  hist.fit_func = fit_func
  hist.fit_param = get_fit_parameters(fit_func)
Ejemplo n.º 2
0
def fit_hist(hist, fit_options="LIMER"):
  def get_fit_goodness(func):
    return  (func.GetChisquare()/func.GetNDF())
  initial_settings = get_initial_settings(hist)
  fit_func = get_func_with_named_initialised_param("f_"+hist.GetTitle(), hist, 
                                                   func_fmt, initial_settings,
                                                   l_bound, u_bound)
  fit_func.SetNpx(100000)
  hist.Fit(fit_func, fit_options)
  hist.fit_func = fit_func
  hist.fit_param = get_fit_parameters(fit_func)
def fit_histogram(hist, func_fmt, initial_settings, func_name, fit_options="MER",img_name=""):
  func = get_func_with_named_initialised_param(func_name, hist, func_fmt, initial_settings)
  
  if img_name:
    canvas = make_canvas(img_name, resize=True)
    hist.Draw()
    hist.Fit(func, fit_options)
    canvas.Update()
    canvas.SaveAs(img_name+".eps")
    canvas.SaveAs(img_name+".svg")
  else:
    hist.Fit(func, fit_options+"N")

  hist.func = func
  hist.fit_param = get_fit_parameters(func)