Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import ROOT
  2.  
  3. f = ROOT.TFile.Open("tmp/LT_LT.root")
  4.  
  5. inc = f.Get("hist0")
  6. inc.Scale(1000*4.957e+03/49144274.0)
  7.  
  8. lt_hists = [f.Get("hist%d" % i ) for i in range(1,10)]
  9.  
  10. def myfit(x, p):
  11. ret = 0
  12. for h,scale in zip(lt_hists,p):
  13. ret += h.GetBinContent( h.FindBin(x[0])) * scale
  14. return ret
  15.  
  16.  
  17. fit = ROOT.TF1("myfit", myfit, 50, 500, 10)
  18. fit.SetParameters(*([1]*len(lt_hists)))
  19.  
  20. ROOT.gROOT.SetBatch(True)
  21.  
  22. c = ROOT.TCanvas()
  23.  
  24. inc.Fit("myfit", "N")
  25.  
  26. inc.Draw()
  27. fit.Draw("same")
  28.  
  29. c.SetLogx()
  30. c.SetLogy()
  31. c.SaveAs("plots/LT_fit.png")
  32.  
  33. stack = ROOT.THStack()
  34. for h,scale in zip(lt_hists, fit.GetParameters()):
  35. h.Scale(scale)
  36. stack.Add(h)
  37.  
  38. res = inc.Clone()
  39. res.Add(stack.GetStack().Last(), -1)
  40. res.Divide(inc)
  41. res.SetMaximum(.2)
  42. res.SetMinimum(-.2)
  43. #res.GetXaxis().SetRangeUser(50,150)
  44. res.Draw()
  45.  
  46. c.SetLogx(False)
  47. c.SetLogy(False)
  48. c.SaveAs("plots/LT_fit_res.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement