Advertisement
reeps

task5Kutenev

May 3rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf8 -*-
  3.  
  4. import sys
  5. import ROOT
  6.  
  7. def function(xx, pp):
  8.     x = xx[0]
  9.     A = pp[0]
  10.     M = pp[1]
  11.     G = pp[2]
  12.     return (A * (G / 2)**2) / ((x - M)**2+(G / 2)**2)
  13.  
  14. g = ROOT.TGraphErrors("data.txt")
  15.  
  16. func = ROOT.TF1("f", function, 0.0,1.0, 3)
  17.  
  18. func.SetParameter(0, 1400)
  19. func.SetParameter(1, 0.8)
  20. func.SetParameter(2, 0.01)
  21. func.SetLineColor(ROOT.kBlue)
  22. g.Fit(func)
  23. g.SetMarkerStyle(20)
  24. canvas.cd(2)
  25. g.Draw("AP")
  26. sys.stdin.readline()
  27.  
  28. ROOT.gStyle.SetOptFit(1111)
  29. fit_result = g.Fit("f", "S")
  30.  
  31. # Get value A, M, G
  32. print " "
  33. print "A:"
  34. print "VALUE: ", func.GetParameter(0)
  35. print "ERROR: ", func.GetParError(0)
  36. print " "
  37.  
  38. print "M:"
  39. print "VALUE: ", func.GetParameter(1)
  40. print "ERROR: ", func.GetParError(1)
  41. print " "
  42.  
  43. print "G:"
  44. print "VALUE: ", func.GetParameter(2)
  45. print "ERROR: ", func.GetParError(2)
  46. print " "
  47.  
  48. # Correlation between parameters.
  49. print "Correlation(A,M): ", fit_result.Correlation(0, 1)
  50. print "Correlation(A,G): ", fit_result.Correlation(0, 2)
  51. print "Correlation(M,G): ", fit_result.Correlation(0, 1)
  52. print " "
  53.  
  54. # hi**2
  55. print "Coefficient hi", fit_result.Chi2()/24.
  56. print " "
  57.  
  58. canvas.Update()
  59.  
  60.  
  61.  
  62.  
  63.  
  64. histA = ROOT.TH1F("histA", "A", 50, 1420, 1540)
  65. histM = ROOT.TH1F("histM", "M", 50, 0.783, 0.784)
  66. histG = ROOT.TH1F("histG", "G", 50, 0.0085, 0.0092)
  67.  
  68. sigma_E = 0.1 / 1000
  69. for i in range(0, 100):
  70.     delta_E = ROOT.gRandom.Gaus(0, sigma_E)
  71.     g2 = ROOT.TGraphErrors(t.GetEntries())
  72.     for j in range(0, t.GetEntries()):
  73.         sigma_epsilon = 0.01 * t.GetV1()[j] / 1.02
  74.         delta_epsilon = ROOT.gRandom.Gaus(0, sigma_epsilon)
  75.         E  = t.GetV1()[j] + delta_E
  76.         Si = t.GetV2()[j] * (1 + delta_epsilon)
  77.         g2.SetPoint(j, E, Si)
  78.         g2.SetPointError(j, 0, t.GetV3()[i])
  79.     fit_result2 = g2.Fit("f", "QS")
  80.     histA.Fill(func.GetParameter(0))
  81.     histM.Fill(func.GetParameter(1))
  82.     histG.Fill(func.GetParameter(2))
  83.  
  84. print ""
  85. print "A RMS:", histA.GetRMS()
  86. print "M RMS:", histM.GetRMS()
  87. print "G RMS:", histG.GetRMS()
  88.  
  89. canvas.cd(3)
  90. histA.Draw()
  91. canvas.cd(4)
  92. histM.Draw()
  93. canvas.cd(5)
  94. histG.Draw()
  95. sys.stdin.readline()
  96.  
  97.  
  98.  
  99. # закрыть файл
  100. f.Close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement