-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread_fit_data.py
More file actions
executable file
·38 lines (32 loc) · 850 Bytes
/
read_fit_data.py
File metadata and controls
executable file
·38 lines (32 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
from ROOT import TGraph, TCanvas, TF1
from array import array
from sys import argv
if len(argv) > 1:
filename = argv[1]
else:
filename = 'mydata.dat'
print('====== Reading', filename)
f = open(filename,'r')
lines = f.readlines()
x = array('f')
y = array('f')
for line in lines:
if line[0][0] != '#':
items = line.split()
if items:
x.append(float(items[0]))
y.append(float(items[1]))
f.close()
print('======', len(x), 'data points read into arrays x and y')
print('====== Plotting data')
c1 = TCanvas('c1','Straight line fit example',10,10,600,400)
gr = TGraph(len(x),x,y)
gr.SetMarkerStyle(20)
gr.SetMarkerSize(1)
gr.Draw("AP")
print('====== Fitting data')
line = TF1('line', '[0]+[1]*x', min(x), max(x))
gr.Fit(line)
c1.Update()
input('====== Press Enter to exit...')