/
final_fit.C
133 lines (104 loc) · 3.76 KB
/
final_fit.C
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// gSystem->AddLinkedLibs("-lgsl -lgslcblas -lm");
// .include -I/usr/include
// Test to see how emacs works
// Most of these are not needed as the CINT loads them
#include <iostream>
#include "TString.h"
#include "Riostream.h"
#include "TH2.h"
#include "TNtuple.h"
#include "TF1.h"
#include "TMath.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TGaxis.h"
#include <gsl/gsl_sf_lambert.h>
Double_t fitf(Double_t *x, Double_t *par)
{
// A simple function to create c*(x^n)
return par[0]*TMath::Power(x[0],par[1]);
}
Double_t fitLambertW(Double_t * x, Double_t *par) {
double prefactor = (par[0]*TMath::Power(x[0],par[1]));
return prefactor * gsl_sf_lambert_W0( (1e-3)/(par[2]*prefactor) );
}
void final_fit() {
TGraph *g1 = new TGraph("2013-02-01-beam-off-clean.dat","%lg %*lg %*lg %*lg %lg"," ");
TGraph *g2 = new TGraph("2013-02-15-beam-off-clean.dat","%lg %*lg %*lg %*lg %lg"," ");
TGraph *g3 = new TGraph("2013-02-28-beam-off_clean.dat","%lg %*lg %*lg %*lg %lg"," ");
TMultiGraph *mg = new TMultiGraph();
mg->Add(g1,"g1");
mg->Add(g2,"g2");
mg->Add(g3,"g3");
TGraph *cernGraph = new TGraph("CERN_guessed_data.dat");
TMultiGraph *mgaxes = new TMultiGraph();
mgaxes->Add(g1,"g12");
mgaxes->Add(g2,"g22");
mgaxes->Add(g3,"g32");
mgaxes->Add(cernGraph,"cernGraph");
// Creates a Root function based on function fitf above
// TF1 *func = new TF1("fitf",fitf,1E9,1E12,2);
// TF1 *func2 = new TF1("fitf",fitf,4E12,5E14,2);
TF1 *lambertfunc = new TF1("fitLambertW",fitLambertW,2e13,5E15,3);
TF1 *lambertCERNfunc = new TF1("fitLambertW",fitLambertW,5e12,1E16,3);
// TF1 *func2 = new TF1("fitLambertW",fitf,1E13,1.1E16,3);
// Sets initial values (guesses)
// func->SetParameters(0.5,0);
// func2->SetParameters(0.5,0);
// lambertfunc->SetParameters(4.27e-11,0.83,4.9e-6); // Based on the other straight line
// lambertfunc->SetParameters(1.9e-17,1.279,1.1e-5);
lambertCERNfunc->SetParameters(4.27e-18,1.289,4.9e-6); // Based on initial fits
lambertfunc->SetParameters(4.27e-18,1.289,4.9e-6); // Based on CERN paper
// Fit histogram in range defined by function
// h2->Fit(func2,"r+");
// lambertCERNfunc->SetLineColor(4);
// lambertCERNfunc->SetLineWidth(2);
// lambertCERNfunc->SetLineStyle(2);
mg->Fit(lambertfunc,"m+");
TCanvas *c1 = new TCanvas("c1","c1",800,800);
mgaxes->SetTitle("Final Fit (with CERN data in black)");
mgaxes->Draw("a");
// mgaxes->SetTicks(2,2);
g1->Draw("*");
g1->SetMarkerStyle(3);
g1->SetMarkerColor(kRed);
g2->Draw("*");
g2->SetMarkerStyle(25);
g2->SetMarkerColor(kBlue);
g3->Draw("*");
g3->SetMarkerStyle(27);
g3->SetMarkerColor(kGreen+3);
lambertfunc->Draw("same");
cernGraph->Draw("*");
lambertCERNfunc->Draw("same");
lambertCERNfunc->SetLineColor(kBlack);
// TH2F *hpx = new TH2F("hpx"," Forward Voltage V_{F} vs. Fluence n_{eq} (with CERN data)",10,1E10,6.4E16,100,0.2,210.0);
// // axis range
// hpx->SetStats(kFALSE);// no statistics
// hpx->Draw();
// g1->SetTitle("Fluence vs. Forward Voltage");
// g1->SetFillColor(1);
// g1->SetMarkerStyle(3);
// g1->Fit(func,"r");
// g1->Fit(lambertfunc,"r+");
// c1->Divide(1,2);
// c1->cd(1);
// h2->SetMarkerStyle(2);
// h2->SetMarkerSize(0.6);
// h2->Draw(); // minor change
// c1->cd(2);
// cernGraph->Draw("*");
// cernGraph->SetMarkerStyle(4);
// cernGraph->GetXaxis()->SetRangeUser(5E10,6.4E20);// axis1->Draw("same");
// g1->Draw("*");
// g1->GetXaxis()->SetRangeUser(5E10,6.4E20);// axis1->Draw("same");
// lambertCERNfunc->Draw("same");
// g1->Draw();
// c1->cd(2);
// lambertfunc->Draw();
c1->SetLogx(1); // Set Log scale in x
c1->SetLogy(1); // Set Log scale in y
c1->SetTicks(2,2); // This is for the ticks on both sides
c1->SetGrid(1);
}