Advertisement
reeps

task5Igor

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