Machine Learning Kurs im Rahmen der Studierendentage im SS 2023
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.3 KiB

2 years ago
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "Test Histogramm Fitting in pyROOT"
  8. ]
  9. },
  10. {
  11. "cell_type": "code",
  12. "execution_count": null,
  13. "metadata": {},
  14. "outputs": [],
  15. "source": [
  16. "import numpy as np\n",
  17. "import math\n",
  18. "#import ROOT\n",
  19. "from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1D, TH2D, TF1 \n",
  20. "from ROOT import gROOT, gBenchmark, gRandom, gSystem"
  21. ]
  22. },
  23. {
  24. "cell_type": "markdown",
  25. "metadata": {},
  26. "source": [
  27. "\n",
  28. "Read data previously used from text file and put it in a numpy array"
  29. ]
  30. },
  31. {
  32. "cell_type": "code",
  33. "execution_count": null,
  34. "metadata": {},
  35. "outputs": [],
  36. "source": [
  37. "data = np.genfromtxt('D0Mass.txt', dtype='d')\n",
  38. "print(data)"
  39. ]
  40. },
  41. {
  42. "cell_type": "markdown",
  43. "metadata": {},
  44. "source": [
  45. "Create histogramm and draw"
  46. ]
  47. },
  48. {
  49. "cell_type": "code",
  50. "execution_count": null,
  51. "metadata": {},
  52. "outputs": [],
  53. "source": [
  54. "d0 = TH1D( 'd0', 'D0 Mass ', 200, 1700. , 2000. )\n",
  55. "for x in data :\n",
  56. " d0.Fill(x)\n",
  57. "c = TCanvas( 'myC', 'Dynamic Filling Example',700, 500 )\n",
  58. "d0.Draw()"
  59. ]
  60. },
  61. {
  62. "cell_type": "markdown",
  63. "metadata": {},
  64. "source": [
  65. "To display the notebook draw the canvas."
  66. ]
  67. },
  68. {
  69. "cell_type": "code",
  70. "execution_count": null,
  71. "metadata": {},
  72. "outputs": [],
  73. "source": [
  74. "# %jsroot on\n",
  75. "c.Draw()"
  76. ]
  77. },
  78. {
  79. "cell_type": "markdown",
  80. "metadata": {},
  81. "source": [
  82. "perform Fit"
  83. ]
  84. },
  85. {
  86. "cell_type": "code",
  87. "execution_count": null,
  88. "metadata": {},
  89. "outputs": [],
  90. "source": [
  91. "func = TF1(\"func\", 'gaus', 1840. , 1880.)\n",
  92. "myfit = d0.Fit(func,\"S\")"
  93. ]
  94. },
  95. {
  96. "cell_type": "code",
  97. "execution_count": null,
  98. "metadata": {},
  99. "outputs": [],
  100. "source": [
  101. "c.Draw()"
  102. ]
  103. }
  104. ],
  105. "metadata": {
  106. "kernelspec": {
  107. "display_name": "Python 3 (ipykernel)",
  108. "language": "python",
  109. "name": "python3"
  110. },
  111. "language_info": {
  112. "codemirror_mode": {
  113. "name": "ipython",
  114. "version": 3
  115. },
  116. "file_extension": ".py",
  117. "mimetype": "text/x-python",
  118. "name": "python",
  119. "nbconvert_exporter": "python",
  120. "pygments_lexer": "ipython3",
  121. "version": "3.10.4"
  122. }
  123. },
  124. "nbformat": 4,
  125. "nbformat_minor": 4
  126. }