clustering by a Gaussing fit to the charge distribution 4 different fit are: First find the clusters for each cluster fit to the left and to the right of the peak then fit the whole distribution with one Gaussian Finally fit the whold distribution with 2 Gaussians If the fit does not converge or is "bad" then take the weighted average
make a selection for the best position finding the error on the position is the error on the weight mean
46 double zfcsc1 = -1000.0, zcscl = 0, zcscr = 0;
48 double fErr1 = 10000.0;
50 double dzcut = da / 25.0;
63 for (is = 1; is < L; is++) {
66 if (is == (L - 1)) q2 = 0;
67 if (q1 < thr && q2 >= thr) ithrL = is;
68 if (q1 < thr || q2 >= thr)
continue;
75 double al = qstr[
imax] / 2.0;
79 for (ii = 0; ii < L; ii++)
80 if (ii >= iquest1 && ii <= iquest2 && *(qstr + ii) > 1) NPT++;
81 double lowerBin = da * iquest1 - da * L / 2;
82 double higherBin = da * iquest2 - da * L / 2;
83 TH1F*
hist =
new TH1F(
"csc",
"csc", NPT, lowerBin, higherBin);
84 for (ii = 0; ii < L; ii++) {
85 if (ii >= iquest1 && ii <= iquest2 && *(qstr + ii) > 1) {
86 double y = *(qstr + ii);
87 double x = da * ((ii + 0.5) - L / 2);
95 TF1* func =
new TF1(
"f1gauss",
f1gauss, lowerBin, higherBin, 4);
98 Double_t x0 = da * ((
imax + 0.5) - L / 2);
100 func->SetParameters(qstr[
imax], x0, s0, 0.0);
102 func->GetParameters(&
par[0]);
104 fErr1 = func->GetParError(1);
106 <<
"Avg = " << zl <<
" Mean = " <<
par[1] <<
" Error = " << fErr1 <<
" status = " <<
status <<
endmsg;
119 iquest2 =
std::min(ithrR + 2, L - 1);
120 double ar = qstr[
imax] / 2.0;
124 for (ii = 0; ii < L; ii++)
125 if (ii >= iquest1 && ii <= iquest2 && *(qstr + ii) > 1) NPT++;
126 lowerBin = da * iquest1 - da * L / 2;
127 higherBin = da * iquest2 - da * L / 2;
128 hist =
new TH1F(
"csc",
"csc", NPT, lowerBin, higherBin);
129 for (ii = 0; ii < L; ii++) {
130 if (ii >= iquest1 && ii <= iquest2 && *(qstr + ii) > 1) {
131 double y = *(qstr + ii);
132 double x = da * ((ii + 0.5) - L / 2);
141 func =
new TF1(
"f1gauss",
f1gauss, lowerBin, higherBin, 4);
144 Double_t x0 = da * ((
imax + 0.5) - L / 2);
146 func->SetParameters(qstr[
imax], x0, s0, 0.0);
148 func->GetParameters(&
par[0]);
150 fErr1 = func->GetParError(1);
152 <<
"Avg = " << zr <<
" Mean = " <<
par[1] <<
" Error = " << fErr1 <<
" status = " <<
status <<
endmsg;
166 iquest2 =
std::min(ithrR + 2, L - 1);
167 int jmax =
icmax(qstr, iquest1, iquest2) + 1;
172 for (ii = 0; ii < L; ii++)
173 if (ii >= iquest1 && ii <= iquest2 && *(qstr + ii) > 1) NPT++;
174 lowerBin = da * iquest1 - da * L / 2;
175 higherBin = da * iquest2 - da * L / 2;
176 hist =
new TH1F(
"csc",
"csc", NPT, lowerBin, higherBin);
177 for (ii = 0; ii < L; ii++) {
178 if (ii >= iquest1 && ii <= iquest2 && *(qstr + ii) > 1) {
179 double y = *(qstr + ii);
180 double x = da * ((ii + 0.5) - L / 2);
189 double sigMainFit = 0.0;
191 bool mainFit =
false;
192 func =
new TF1(
"f1gauss",
f1gauss, lowerBin, higherBin, 4);
197 func->SetParameters(qstr[jmax],
z0, s0, 0.0);
200 func->GetParameters(&
par[0]);
205 fErr1 = func->GetParError(1);
211 <<
"Avg = " <<
z0 <<
" Mean = " <<
par[1] <<
" Error = " << fErr1 <<
" baseline = " <<
par[3] <<
" status = " <<
status
220 iquest2 =
std::min(ithrR + 2, L - 1);
225 double max_charge = -1;
226 for (ii = 0; ii < L; ii++)
227 if (ii >= iquest1 && ii <= iquest2 && *(qstr + ii) > 1) NPT++;
228 lowerBin = da * iquest1 - da * L / 2;
229 higherBin = da * iquest2 - da * L / 2;
230 hist =
new TH1F(
"csc",
"csc", NPT, lowerBin, higherBin);
231 for (ii = 0; ii < L; ii++) {
232 if (ii >= iquest1 && ii <= iquest2 && *(qstr + ii) > 1) {
233 double y = *(qstr + ii);
234 double x = da * ((ii + 0.5) - L / 2);
237 if (
y > max_charge) {
245 bool doubleGaussianFit =
false;
246 func =
new TF1(
"f2gauss",
f2gauss, lowerBin, higherBin, 7);
250 if (mainFit)
s0 = sigMainFit / 2.0;
251 func->SetParameters(al, zl, s0, ar, zr, s0, 0.0);
253 func->GetParameters(&
par[0]);
255 doubleGaussianFit =
true;
261 <<
"Avg = " <<
z0 <<
" Mean One Gaussian = " << zfcsc1 <<
" Mean1 = " <<
par[1] <<
" Error1 = " << func->GetParError(1)
262 <<
" Mean2 = " <<
par[4] <<
" Error2 = " << func->GetParError(4) <<
" baseline = " <<
par[6] <<
" status = " <<
status
272 for (
int i = max_strip - 1;
i <= max_strip + 1;
i++) {
273 if (
i >= 0 &&
i < L) {
281 double wErr = da / sqrt(12.0);
282 if (
count > 1 && ysum > 0) wErr =
noise * (da / (ysum)) * sqrt(2.0 * ysum2);
286 double xp0 = 0, xp1 = 0, xp2 = 0;
292 double dx0 = fabs(xp0 -
z0);
293 double dx1 = fabs(xp1 -
z0);
294 double dx2 = fabs(xp2 -
z0);
296 bool checkIt = (dx0 < dzcut) || (dx1 < dzcut) || (dx2 < dzcut);
298 if (mainFit && doubleGaussianFit && checkIt) {
303 if (dx0 < dx1 && dx0 < dx2) {
304 *(zpos + ncl - 1) = xp0;
305 }
else if (dx1 < dx2 && dx1 < dx0) {
306 *(zpos + ncl - 1) = xp1;
307 }
else if (dx2 < dx0 && dx2 < dx1) {
308 *(zpos + ncl - 1) = xp2;
310 *(zpos + ncl - 1) = xp0;
312 *(
sig + ncl - 1) = wErr;
313 }
else if (mainFit && (dx0 < dzcut)) {
318 *(zpos + ncl - 1) = xp0;
319 *(
sig + ncl - 1) = wErr;
326 *(zpos + ncl - 1) =
z0;
327 *(
sig + ncl - 1) = wErr;