-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDRTileMPV.cpp
107 lines (93 loc) · 2.74 KB
/
DRTileMPV.cpp
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
void DRTileMPV(int a, float cc) {
switch (a) {
case 2:
{
TFile *file = new TFile("flat_scint3_box15_gap01_xz2mm_e200.root");
break;
}
case 4:
{
TFile *file = new TFile("flat_scint3_box15_gap01_xz4mm_e200.root");
break;
}
case 6:
{
TFile *file = new TFile("flat_scint3_box15_gap01_xz6mm_e200.root");
break;
}
case 8:
{
TFile *file = new TFile("flat_scint3_box15_gap01_xz8mm_e200.root");
break;
}
case 10:
{
TFile *file = new TFile("flat_scint3_box15_gap01_xz10mm_e200.root");
break;
}
case 12:
{
TFile *file = new TFile("flat_scint3_box15_gap01_xz12mm_e200.root");
break;
}
case 14:
{
TFile *file = new TFile("flat_scint3_box15_gap01_xz14mm_e200.root");
break;
}
default:
{
std::cout << "Error in \"a\" " << std::endl;
break;
}
}
TH1F *hist;
TF1 *fitFunc1;
TF1 *fitFunc2;
TCanvas *c1 = new TCanvas("c1", "c1", 1);
printf("File open... ");
if (!file) {
printf("[FAIL]\n");
return 0;
} else printf("[OK]\n");
printf("Loading histogram... ");
hist = (TH1F *)file->Get("fCounterSipm");
if (!hist) {
printf("[FAIL]\n");
return 0;
} else printf("[OK]\n");
fitFunc1 = new TF1("fitFunc1", "gaus");
hist->GetYaxis()->SetTitle("Number of events");
hist->GetXaxis()->SetTitle("Number of photons");
hist->Fit(fitFunc1, "0");
float mean1 = fitFunc1->GetParameter(1);
float sigma1 = fitFunc1->GetParameter(2);
std::cout << "Mean1 : " << mean1 << std::endl;
std::cout << "Sigma1 : " << sigma1 << std::endl;
fitFunc2 = new TF1("fitFunc2", "gaus", mean1 - cc*sigma1, mean1 + cc*sigma1);
hist->Fit(fitFunc2, "R");
float mean2 = fitFunc2->GetParameter(1);
float sigma2 = fitFunc2->GetParameter(2);
std::cout << "Mean2 : " << mean2 << std::endl;
std::cout << "Sigma2 : " << sigma2 << std::endl;
int flag = 0;
double chi2 = 0;
chi2 = fitFunc2->GetChisquare() / fitFunc2->GetNDF();
if (chi2 > 5) flag = 1;
c1->SaveAs("pic.jpg");
// hist->Draw();
FILE *out = fopen("out.txt", "a+");
printf("File open... ");
if (!out) {
printf("[FAIL]\n");
return 0;
} else printf("[OK]\n");
fprintf(out,"%i %E %E %E %i\n", a, mean2, sigma2, chi2, flag);
// out << mean2 << " " << sigma2 << " " << chi2 << " " << flag << std::endl;
// fclose(out);
if (flag)
{
hist->Rebin();
c1->SaveAs("pic-re.jpg");
}
}