Advertisement
reeps

55

May 3rd, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.52 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf8 -*-
  3. import sys
  4. import ROOT
  5.  
  6. canvas = ROOT.TCanvas("canvas", "Canvas")
  7. canvas.Divide(2,2)
  8. canvas.cd(1)
  9.  
  10.  
  11. g = ROOT.TGraphErrors("variant2.txt")
  12.  
  13. t = []
  14. f = open("variant2.txt")
  15. t = [tuple(map(float, i.split(' '))) for i in f]
  16.  
  17. func = ROOT.TF1("f", "[0]*([2]/2)^2/((x-[1])^2+([2]/2)^2)", 0, 1)
  18.  
  19. func.SetParameter(0, 400)
  20. func.SetParameter(1, 0.77)
  21. func.SetParameter(2, 0.005)
  22.  
  23. g.SetMarkerStyle(20)
  24.  
  25. #func.Draw()
  26. #raw_input('--->')
  27.  
  28. g.Draw("AP")
  29. raw_input('--->')
  30.  
  31. fit_result = g.Fit(func, "SQ")
  32.  
  33. # Get value A, M, G
  34. print " "
  35. print "A:"
  36. print "VALUE: ", func.GetParameter(0)
  37. print "ERROR: ", func.GetParError(0)
  38. print " "
  39.  
  40. print "M:"
  41. print "VALUE: ", func.GetParameter(1)
  42. print "ERROR: ", func.GetParError(1)
  43. print " "
  44.  
  45. print "G:"
  46. print "VALUE: ", func.GetParameter(2)
  47. print "ERROR: ", func.GetParError(2)
  48. print " "
  49.  
  50. # Correlation between parameters.
  51. print "Correlation(A,M): ", fit_result.Correlation(0, 1)
  52. print "Correlation(A,G): ", fit_result.Correlation(0, 2)
  53. print "Correlation(M,G): ", fit_result.Correlation(0, 1)
  54. print " "
  55.  
  56. # hi**2
  57. print "Coefficient hi", fit_result.Chi2()
  58. print " "
  59. canvas.Update()
  60.  
  61.  
  62. # Define hist.
  63. histA = ROOT.TH1F("histA", "A", 100, 160, 175)
  64. histM = ROOT.TH1F("histM", "M", 100, 0.7818, 0.783)
  65. histG = ROOT.TH1F("histG", "G", 100, -0.00950, -0.00880)
  66.  
  67. raw_input('--->')
  68.  
  69. sigma_E = 0.1 / 1000
  70. for i in range(0, 100):
  71.     delta_E = ROOT.gRandom.Gaus(0, sigma_E)
  72.     g2 = ROOT.TGraphErrors()
  73.     for j in range(0, len(t)):
  74.         E  = t[j][0] + delta_E
  75.         Si = t[j][1]
  76.         g2.SetPoint(j, E, Si)
  77.         g2.SetPointError(j, 0, t[j][3])
  78.     fit_result2 = g2.Fit("f", "SQ")
  79.     histA.Fill(func.GetParameter(0))
  80.     histM.Fill(func.GetParameter(1))
  81.     histG.Fill(func.GetParameter(2))
  82.  
  83. print "\nENERGY CONTRIBUTION"
  84. print "A RMS:", histA.GetRMS()
  85. print "M RMS:", histM.GetRMS()
  86. print "G RMS:", histG.GetRMS()
  87.  
  88. canvas.cd(2)
  89. histA.Draw()
  90. canvas.cd(3)
  91. histM.Draw()
  92. canvas.cd(4)
  93. histG.Draw()
  94. raw_input('--->')
  95.  
  96. for i in range(0, 100):
  97.     g2 = ROOT.TGraphErrors()
  98.     for j in range(0, len(t)):
  99.         sigma_epsilon = 0.01 * t[j][0] / 1.02
  100.         delta_epsilon = ROOT.gRandom.Gaus(0, sigma_epsilon)
  101.         E  = t[j][0]
  102.         Si = t[j][1] * (1 + delta_epsilon)
  103.         g2.SetPoint(j, E, Si)
  104.         g2.SetPointError(j, 0, t[j][3])
  105.     fit_result2 = g2.Fit("f", "SQ")
  106.     histA.Fill(func.GetParameter(0))
  107.     histM.Fill(func.GetParameter(1))
  108.     histG.Fill(func.GetParameter(2))
  109.  
  110. print "\nEFFICIENCY CONTRIBUTION"
  111. print "A RMS:", histA.GetRMS()
  112. print "M RMS:", histM.GetRMS()
  113. print "G RMS:", histG.GetRMS()
  114.  
  115. canvas.cd(2)
  116. histA.Draw()
  117. canvas.cd(3)
  118. histM.Draw()
  119. canvas.cd(4)
  120. histG.Draw()
  121. raw_input('--->')
  122.  
  123. sigma_E = 0.1 / 1000
  124. for i in range(0, 100):
  125.     delta_E = ROOT.gRandom.Gaus(0, sigma_E)
  126.     g2 = ROOT.TGraphErrors()
  127.     for j in range(0, len(t)):
  128.         sigma_epsilon = 0.01 * t[j][0] / 1.02
  129.         delta_epsilon = ROOT.gRandom.Gaus(0, sigma_epsilon)
  130.         E  = t[j][0] + delta_E
  131.         Si = t[j][1] * (1 + delta_epsilon)
  132.         g2.SetPoint(j, E, Si)
  133.         g2.SetPointError(j, 0, t[j][3])
  134.     fit_result2 = g2.Fit("f", "SQ")
  135.     histA.Fill(func.GetParameter(0))
  136.     histM.Fill(func.GetParameter(1))
  137.     histG.Fill(func.GetParameter(2))
  138.  
  139. print "\nTOTAL CONTRIBUTION"
  140. print "A RMS:", histA.GetRMS()
  141. print "M RMS:", histM.GetRMS()
  142. print "G RMS:", histG.GetRMS()
  143.  
  144. canvas.cd(2)
  145. histA.Draw()
  146. canvas.cd(3)
  147. histM.Draw()
  148. canvas.cd(4)
  149. histG.Draw()
  150.  
  151. raw_input('finish --->')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement