-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfit_caldac.c
67 lines (64 loc) · 2.14 KB
/
fit_caldac.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
int fit_caldac()
{
gROOT->Reset();
ifstream fin("./cald_test.log");
int slot_mask;
int adccounts[4096];
int adcs[4][4096];
int numpoints;
int i,j;
int adccount,s,adc[4];
int slot;
fin >> slot_mask >> numpoints;
numpoints--;
TGraph *g[16][4];
TF1 *f[16][4];
TMultiGraph *mg[16];
TCanvas *c[16];
double chi2[16][4],par0[16][4],par1[16][4];
int endpoint[4];
char fname[10];
char cname[10];
for (slot = 0;slot<16;slot++){
if ((0x1<<slot) & slot_mask){
for (i=0;i<4;i++){
endpoint[i] = 4096;
}
printsend("slot = %d\n",slot);
for (i=-1;i<numpoints;i++){
fin >> adccount >> s >> adc[0] >> adc[1] >> adc[2] >> adc[3];
if (i>=0){
adccounts[i] = adccount;
for (j=0;j<4;j++){
adcs[j][i] = adc[j];
if (adc[j] == 0 && adccount < endpoint[j])
endpoint[j] = adccount;
}
}
}
mg[slot] = new TMultiGraph();
sprintf(cname,"slot_%d",slot);
c[slot] = new TCanvas(cname,cname,200,10,700,500);
for (j=0;j<4;j++){
g[slot][j] = new TGraph(numpoints,adccounts,adcs[j]);
g[slot][j]->SetMarkerStyle(6);
g[slot][j]->SetMarkerColor(j+2);
sprintf(fname,"f_%d_%d",slot,j);
f[slot][j] = new TF1(fname,"pol1",adccounts[10],endpoint[j]);
g[slot][j]->Fit(fname,"SR");
chi2[slot][j] = f[slot][j]->GetChisquare();
par0[slot][j] = f[slot][j]->GetParameter(0);
par1[slot][j] = f[slot][j]->GetParameter(1);
mg[slot]->Add(g[slot][j]);
}
mg[slot]->Draw("AP");
}
}
for (slot=0;slot<16;slot++){
if ((0x1<<slot) & slot_mask){
for (i=0;i<4;i++){
printsend("For slot %d adc %d, fit %6.2f + %6.2f x with chi2 of %6.2f\n",slot,i,par0[slot][i],par1[slot][i],chi2[slot][i]);
}
}
}
}