-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.c
148 lines (127 loc) · 3.82 KB
/
code.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
void code ()
{
float adcCut = 550;
int nrebin = 2;
float sigRange = 1.5;
TF1 *fitFunc;
TF1 *fitFunc2;
char stxt[120];
TCanvas *c1 = new TCanvas("c1", "c1", 1);
//
// Open file
//
std::cout << "File open... ";
FILE* file = fopen("/home/root1/Desktop/diplom/data/processing/ITEP/newnew/uniformity_calice_170303/desy_tile_hv_28_170303_scan3_scan_8.5_8.5.txt", "r");
if (!file) {
std::cout << "[FAIL]\n" << std::endl;
return 0;
} else std::cout << "[OK]" << std::endl;
//
// Create an output file
//
std::cout << "Trying to create output file... ";
FILE* fevtot = fopen("evtot.txt", "a+");
if (!fevtot) {
std::cout << "[FAIL]" << std::endl;
return 0;
} else std::cout << "[OK]" << std::endl;
std::cout << "Trying to create output file... ";
FILE* fevcut = fopen("evcut.txt", "a+");
if (!fevcut) {
std::cout << "[FAIL]" << std::endl;
return 0;
} else std::cout << "[OK]" << std::endl;
std::cout << "Trying to create output file... ";
FILE* fmean = fopen("mean.txt", "a+");
if (!fmean) {
std::cout << "[FAIL]" << std::endl;
return 0;
} else std::cout << "[OK]" << std::endl;
std::cout << "Trying to create output file... ";
FILE* fchi2 = fopen("chi2.txt", "a+");
if (!fchi2) {
std::cout << "[FAIL]" << std::endl;
return 0;
} else std::cout << "[OK]" << std::endl;
TH1F* histTotal = new TH1F("histTotal","Full ADC range",200,0.,1600.);
sprintf(stxt,"Signal above %f ADC", adcCut);
TH1F* histCut = new TH1F("histCut",stxt,100,0.,1600.);
// read data
Int_t a = 0;
Int_t b = 0;
Char_t buf[0xFF];
while( feof(file) == 0 ) {
fscanf ( file,"%d %d", &a, &b );
fgets( buf, 0xFF, file );
// ---------------------------------------------
if ( a == 4 ) {
histTotal->Fill( b );
if ( b > adcCut ) histCut->Fill( b );
}
//----------------------------------------------
a = b = 0;
}
//fill hists
Float_t evtot = 0;
Float_t evcut = 0;
evtot = float(histTotal->GetEntries());
int nevt = histCut->GetEntries();
evcut = float(nevt);
if ( nevt < 50 ) {
std::cout << "No events in signal region." << std::endl;
return;
}
int nbinInit = histCut->GetNbinsX();
int irebin = nbinInit/(nrebin*pow(nevt,1./3));
//if ( nrebin > 1 ) histCut->Rebin(nrebin);
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if ( irebin > 1 ) histCut->Rebin(irebin);
Float_t mean = histCut->GetMean();
Float_t sigma = histCut->GetRMS();
/* std::cout << " Nevt: " << nevt
<< " Mean: " << mean
<< " RMS: " << sigma
<< std::endl;
*/
fitFunc = new TF1("fitFunc", "gaus", mean - sigRange*sigma, mean + sigRange*sigma);
histCut->Fit(fitFunc, "QR0N" );
//std::cout << "FIT 1" << std::endl;
mean = fitFunc->GetParameter(1);
sigma = fitFunc->GetParameter(2);
Double_t chi2 = 0;
chi2 = fitFunc->GetChisquare() / fitFunc->GetNDF();
int minNDF = 4;
int curNDF = 0;
int ncount = 0;
while ( curNDF < 4 && ncount < 10 ) {
ncount++;
fitFunc2 = new TF1("fitFunc2", "gaus",
mean - sigRange*sigma,
mean + sigRange*sigma);
histCut->Fit(fitFunc2, "QR");
//std::cout << "FIT " << ncount+1 << std::endl;
sigRange *= 2;
curNDF = fitFunc2->GetNDF();
}
//std:: cout << "Last range: " << sigRange << std::endl;
Float_t mean2 = fitFunc2->GetParameter(1);
Float_t sigma2 = fitFunc2->GetParameter(2);
Double_t chi22 = 0;
chi22 = fitFunc2->GetChisquare() / fitFunc2->GetNDF();
/* std::cout << " Nevt: " << nevt
<< " Mean: " << mean2
<< " Sigma: " << sigma2
<< " Chi2/ndf: " << chi22
<< std::endl;
*/
histCut->Draw();
/* fprintf(fevtot,"%E\n", evtot);
fprintf(fevcut,"%E\n", evcut);
fprintf(fmean,"%E\n", mean2);
fprintf(fchi2,"%E\n", chi22);
*/
fclose( fevtot );
fclose( fevcut );
fclose( fmean );
fclose( fchi2 );
fclose( file );
}