-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_data.py
63 lines (53 loc) · 1.74 KB
/
extract_data.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from ROOT import TF1, TH1F, TCanvas, gStyle, TH1D, TTree
from ROOT import TFile
import ROOT
from array import array
import numpy as np
#import rootnotes
f = ROOT.TFile.Open('build/Edep.root', 'read')
# Setup a canvas for plotting. The arguments are a name, an optional title, and the width and height in pixels.
canvas = ROOT.TCanvas('canvas', '', 500, 500)
hist = f.Get('Edep')
length = hist.GetEntries()
#int k = h->GetXaxis()->FindBin(x);
x=[]
for k in xrange(0,100):
x.append(hist.GetBinContent(k))
#print(x)
f.Close()
exit()
#Bis hier liest es die Daten ein!
#bins = hist.GetArray()
#x=[]
#print(bins)
#for i in xrange(0,len(bins)):
# x.append(bins[i])
x = ROOT.RooRealVar("x","x",-20,30);
mpv = ROOT.RooRealVar("mpv","mpv",1,0.1,4);
width = ROOT.RooRealVar("width","width",1,0.1,10);
landau = ROOT.RooLandau("ld","ld",x,mpv,width);
mean = ROOT.RooRealVar("mean","mean",0.1,0.1,4);
sigma = ROOT.RooRealVar("sigma","sigma",0.5,0.1,10);
gauss = ROOT.RooGaussian("gs","gs",x,mean,sigma);
lxg = ROOT.RooFFTConvPdf("lxg","lxg",x,landau,gauss);
#TestData
data = lxg.generate(ROOT.RooArgSet(x),10000)
print(data)
result = gauss.fitTo(data,ROOT.RooFit.PrintLevel(-1))
resultL = landau.fitTo(data,ROOT.RooFit.PrintLevel(-1))
result_lxg = lxg.fitTo(data,ROOT.RooFit.PrintLevel(-1))
xframe = x.frame()
data.plotOn(xframe,ROOT.RooFit.Binning(25))
gauss.plotOn(xframe)
sigma.setVal(0.2)
landau.plotOn(xframe,ROOT.RooFit.LineColor(2))
lxg.plotOn(xframe,ROOT.RooFit.LineColor(3))
xframe.Draw()
#Getting the data in the Tree
# tree = ROOT.TTree("tree","tree")
# x = np.zeros(1,dtype=float)
# tree.Branch("x",x,'x/D')
# for i in range(10000):
# x[0] = np.random.normal(0,3,1)
# tree.Fill()
#data = ROOT.RooDataSet("data","dataset from tree",tree,ROOT.RooArgSet(x))