-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFitMakro.c
More file actions
66 lines (42 loc) · 1.09 KB
/
FitMakro.c
File metadata and controls
66 lines (42 loc) · 1.09 KB
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
64
65
66
void FitMakro()
{
cout<<"Podaj nazwe pliku wejsciowego (bez .txt)"<<endl;
string wejsciowy;
cin>>wejsciowy;
string file = wejsciowy + ".txt";
ifstream ifile;
ifile.open(file.c_str());
TF1 *fitfunc = new TF1("fitfunc","gaus",0,254);
double x[255];// x
double ex[255]={0};//niepewnosci x
double y[255];//y
double ey[255]={0};//niepewnosci y
int Ox;
for(int i=0; i<255; i++)
{
ifile>>Ox;
x[i] = Ox;
}
int Oy;
for(int i=0; i<255; i++)
{
ifile>>Oy;
y[i] = Oy;
}
ifile.close();
TGraphErrors *h = new TGraphErrors(255,x,y,ex,ey);
h->Fit("fitfunc","rob");
double max = fitfunc->GetMaximum();
double x_maximum = fitfunc->GetMaximumX();
double fwhm_left = fitfunc->GetX(max/2,0, x_maximum);
double fwhm_right = fitfunc->GetX(max/2, x_maximum, 255);
cout<<"FWHM = " << fwhm_right - fwhm_left<<endl;
h->SetTitle(wejsciowy.c_str());
h->GetXaxis()->SetTitle("numer kanalu");
h->GetYaxis()->SetTitle("liczba zliczen");
TCanvas *canva = new TCanvas();
gStyle->SetOptFit(0111);
h->Draw();
string wyjsciowy = wejsciowy + ".png";
canva->Print(wyjsciowy.c_str());
}