21 for (
int k = 0;
k <= 100;
k++)
32 int Ntot,
int Nsamp1,
int Nsamp2,
int cut,
int Nbef,
int Naft,
int niv1,
int niv2,
int niv3,
int nevl,
int NSlide) {
36 nsigcut = (double)
cut;
37 fNum_samp_bef_max = Nbef;
38 fNum_samp_aft_max = Naft;
39 level1 = ((double)niv1) / 100.;
40 level2 = ((double)niv2) / 100.;
41 level3 = ((double)niv3) / 100.;
45 for (
int k = 0;
k < nevlasers;
k++)
47 for (
int k = 0;
k < nevlasers;
k++)
64 double dsum = 0., dsum2 = 0.;
70 if (Nsamp != fNsamples) {
71 printf(
"found different number of samples fNsamples=%d Nsamp=%d\n", fNsamples, Nsamp);
75 for (
k = 0;
k < presample;
k++) {
79 bl = dsum / ((double)presample);
80 double ss = (dsum2 / ((double)presample) - bl * bl);
84 for (ithr = 0,
k = presample;
k < endsample;
k++) {
85 if (
adc[
k] > (bl + nsigcut * sigbl) && ithr == 0) {
94 for (ithr = 0,
k = firstsample;
k < Nsamp;
k++) {
95 if (
adc[
k] < (bl + nsigcut * sigbl) && ithr == 0) {
103 if (lastsample > firstsample +
NMAXSAMP)
104 lastsample = firstsample +
NMAXSAMP;
108 for (Int_t is = firstsample; is < lastsample; is++) {
109 bong[is - firstsample] =
adc[is] - bl;
110 if (bong[is - firstsample] > val_max) {
111 val_max = bong[is - firstsample];
117 if (samplemax > lastsample)
119 if (samplemax < firstsample)
122 int endslide = samplemax - nslide;
123 int beginslide = nslide;
124 int islidingmean = 0;
127 for (
int i = beginslide;
i < endslide;
i++) {
128 slidingmean +=
adc[
i];
131 if (islidingmean != 0)
132 slidingmean /= double(islidingmean);
141 double thres = val_max * level1;
145 if (bong[
k] > thres) {
156 if (bong[
k] > thres) {
165 double sumpkval = 1.;
168 if (nbsup == nbinf) {
180 for (
k = 0;
k < nbinf;
k++)
191 }
else if (jfind == 1) {
196 bing[
k + 1] = (
int)bong[
k];
209 if (sumpkval > 1000.)
212 pkval += (firstsample - 1);
223 int heresamplemax = samplemax - firstsample;
225 int beginfit = heresamplemax - fNum_samp_bef_max;
226 int endfit = heresamplemax + fNum_samp_aft_max;
228 int nval = endfit - beginfit + 1;
231 for (
int kn = beginfit; kn <= endfit; kn++) {
238 for (
int i = 0;
i < nval;
i++) {
239 val[
i] = bong[beginfit +
i];
241 fv2[
i] = (double)(
i);
242 fv3[
i] = ((double)(
i)) * ((
double)(
i));
245 TVectorD y(nval,
val);
246 TVectorD
f1(nval, fv1);
247 TVectorD
f2(nval, fv2);
248 TVectorD f3(nval, fv3);
266 TMatrixD
a(3, 3, aij);
273 double *par =
c.GetMatrixArray();
275 timeatmax = -par[1] / (2. * par[2]);
276 ampl = par[0] - par[2] * (timeatmax * timeatmax);
280 ampl = bong[heresamplemax];
286 if ((
int)timeatmax < 0)
289 timeatmax += (beginfit + firstsample);
291 int tplus[3], tminus[3];
293 xampl[0] = 0.2 * ampl;
294 xampl[1] = 0.5 * ampl;
295 xampl[2] = 0.8 * ampl;
301 for (
int i = 0;
i < 3;
i++) {
305 tplus[
i] = firstsample + lastsample;
310 int im = heresamplemax;
311 int iplusbound = firstsample + lastsample - im;
313 for (
int j = 0;
j < 3;
j++) {
314 for (
int i = 1;
i < im;
i++) {
315 if (bong[im -
i] < xampl[
j] && bong[im -
i + 1] > xampl[
j]) {
322 for (
int i = 0;
i < iplusbound;
i++) {
323 if (bong[im +
i] > xampl[
j] && bong[im +
i + 1] < xampl[
j]) {
332 double slopeplus = double(bong[tplus[
j] + 1] - bong[tplus[
j]]);
333 double slopeminus = double(bong[tminus[
j] + 1] - bong[tminus[
j]]);
335 double timeminus = double(tminus[
j]) + 0.5;
337 timeminus = tminus[
j] + (xampl[
j] - double(bong[tminus[
j]])) / slopeminus;
339 double timeplus = double(tplus[
j]) + 0.5;
341 timeplus = tplus[
j] + (xampl[
j] - double(bong[tplus[
j]])) / slopeplus;
343 width[
j] = timeplus - timeminus;
374 int kmax = (
int)pkval - firstsample;
377 for (Int_t
k = 0;
k < kmax;
k++)
378 if (0. < bong[
k] && bong[
k] < amplx) {
384 for (Int_t
k = kmax;
k >= 0;
k--)
385 if (bong[
k] > amplx) {
390 if (bin_high < bin_low)
393 if (bin_low == bin_high) {
394 T = (double)bin_high;
396 double slope = (bong[bin_high] - bong[bin_low]) / ((
double)(bin_high - bin_low));
397 T = (double)bin_high - (bong[bin_high] - amplx) /
slope;
404 if (anevt < 2 * nevlasers) {
405 if (anevt < nevlasers) {
407 status[nevmtq0 - 1] = anevt;
408 comp_trise[nevmtq0 - 1] = trise;
409 comp_peak[nevmtq0 - 1] = pkval;
412 status[nevmtq0 + nevmtq1 - 1] = anevt;
413 comp_trise[nevmtq0 + nevmtq1 - 1] = trise;
414 comp_peak[nevmtq0 + nevmtq1 - 1] = pkval;
417 if (anevt < 3 * nevlasers) {
419 status[nevmtq0 - 1] = anevt;
420 comp_trise[nevmtq0 - 1] = trise;
421 comp_peak[nevmtq0 - 1] = pkval;
424 status[nevmtq0 + nevmtq1 - 1] = anevt;
425 comp_trise[nevmtq0 + nevmtq1 - 1] = trise;
426 comp_peak[nevmtq0 + nevmtq1 - 1] = pkval;
436 sprintf(
filename,
"runMatacq%d.pedestal", gRunNumber);
438 if (fmatacq ==
nullptr)
439 printf(
"Error while opening file : %s\n",
filename);
441 double sumtrise = 0.;
442 double sumtrise2 = 0.;
443 int timestop = timestart + 3;
444 double mintrise = 10000.;
445 double maxtrise = 0.;
446 for (
i = 0;
i < nevmtq0;
i++) {
447 if (comp_trise[
i] > maxtrise) {
448 maxtrise = comp_trise[
i];
450 if (comp_trise[
i] < mintrise) {
451 mintrise = comp_trise[
i];
453 sumtrise += comp_trise[
i];
454 sumtrise2 += comp_trise[
i] * comp_trise[
i];
456 meantrise = sumtrise / ((double)nevmtq0);
457 ss = (sumtrise2 / ((double)nevmtq0) - meantrise * meantrise);
462 fmatacq,
"%d %d %d %d %f %f %f %f\n", nevmtq0, color, timestart, timestop, meantrise, sigtrise, mintrise, maxtrise);
468 for (
i = nevmtq0;
i < nevmtq0 + nevmtq1;
i++) {
469 if (comp_trise[
i] > maxtrise) {
470 maxtrise = comp_trise[
i];
472 if (comp_trise[
i] < mintrise) {
473 mintrise = comp_trise[
i];
475 sumtrise += comp_trise[
i];
476 sumtrise2 += comp_trise[
i] * comp_trise[
i];
478 meantrise = sumtrise / ((double)nevmtq1);
479 ss = (sumtrise2 / ((double)nevmtq1) - meantrise * meantrise);
484 fmatacq,
"%d %d %d %d %f %f %f %f\n", nevmtq1, color, timestart, timestop, meantrise, sigtrise, mintrise, maxtrise);
486 int iret = fclose(fmatacq);
487 printf(
" Closing file : %d\n", iret);
493 sprintf(
filename,
"badevtsMatacq%d.dat", gRunNumber);
495 if (fmatacq ==
nullptr)
496 printf(
"Error while opening file : %s\n",
filename);
499 for (Int_t
i = 0;
i < nevmtq0 + nevmtq1;
i++) {
500 if (comp_trise[
i] < meantrise - 3. * sigtrise) {
502 fprintf(fmatacq,
"%d \n",
status[
i]);
505 if (comp_trise[
i] > meantrise + 3. * sigtrise) {
507 fprintf(fmatacq,
"%d \n",
status[
i]);
512 int iret = fclose(fmatacq);
513 printf(
" Closing file : %d\n", iret);
522 sprintf(
filename,
"runiterMatacq%d.pedestal", gRunNumber);
524 if (fmatacq ==
nullptr)
525 printf(
"Error while opening file : %s\n",
filename);
528 double sumtrise = 0.;
529 double sumtrise2 = 0.;
530 int timestop = timestart + 3;
531 double mintrise = 10000.;
532 double maxtrise = 0.;
533 for (
i = 0;
i < nevmtq0;
i++) {
536 if (comp_trise[
i] > maxtrise) {
537 maxtrise = comp_trise[
i];
539 if (comp_trise[
i] < mintrise) {
540 mintrise = comp_trise[
i];
542 sumtrise += comp_trise[
i];
543 sumtrise2 += comp_trise[
i] * comp_trise[
i];
546 meantrise = sumtrise / ((double)nevmtqgood);
547 ss = (sumtrise2 / ((double)nevmtqgood) - meantrise * meantrise);
552 "%d %d %d %d %f %f %f %f\n",
567 for (
i = nevmtq0;
i < nevmtq0 + nevmtq1;
i++) {
570 if (comp_trise[
i] > maxtrise) {
571 maxtrise = comp_trise[
i];
573 if (comp_trise[
i] < mintrise) {
574 mintrise = comp_trise[
i];
576 sumtrise += comp_trise[
i];
577 sumtrise2 += comp_trise[
i] * comp_trise[
i];
580 meantrise = sumtrise / ((double)nevmtqgood);
581 ss = (sumtrise2 / ((double)nevmtqgood) - meantrise * meantrise);
586 "%d %d %d %d %f %f %f %f\n",
596 int iret = fclose(fmatacq);
597 printf(
" Closing file : %d\n", iret);