18 for (
int k = 0;
k < NMAXSAMP;
k++)
21 for (
int k = 0;
k <= 100;
k++)
24 for (
int k = 0;
k < NSPARAB;
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;
143 for (
k = 0, jfind = 0;
k < NMAXSAMP;
k++) {
145 if (bong[
k] > thres) {
154 for (
k = NMAXSAMP, jfind = 0;
k > nbinf;
k--) {
156 if (bong[
k] > thres) {
167 if (nbsup == nbinf) {
174 if (nbsup < NMAXSAMP - 4)
179 for (
k = 0;
k < nbinf;
k++)
181 for (
k = nbsup;
k < NMAXSAMP;
k++)
184 for (
k = 0, jfind = 0;
k < NMAXSAMP;
k++) {
190 }
else if (jfind == 1) {
193 for (
k = 0;
k < NMAXSAMP;
k++) {
195 bing[
k + 1] = (
int)bong[
k];
206 pkval += (firstsample - 1);
217 int heresamplemax = samplemax - firstsample;
219 int beginfit = heresamplemax - fNum_samp_bef_max;
220 int endfit = heresamplemax + fNum_samp_aft_max;
222 int nval = endfit - beginfit + 1;
225 for (
int kn = beginfit; kn <= endfit; kn++) {
232 for (
int i = 0;
i < nval;
i++) {
233 val[
i] = bong[beginfit +
i];
235 fv2[
i] = (double)(
i);
236 fv3[
i] = ((double)(
i)) * ((
double)(
i));
239 TVectorD y(nval,
val);
240 TVectorD
f1(nval, fv1);
241 TVectorD
f2(nval, fv2);
242 TVectorD f3(nval, fv3);
260 TMatrixD
a(3, 3, aij);
267 double *par =
c.GetMatrixArray();
269 timeatmax = -par[1] / (2. * par[2]);
270 ampl = par[0] - par[2] * (timeatmax * timeatmax);
274 ampl = bong[heresamplemax];
278 if ((
int)timeatmax > NSPARAB)
280 if ((
int)timeatmax < 0)
283 timeatmax += (beginfit + firstsample);
285 int tplus[3], tminus[3];
287 xampl[0] = 0.2 * ampl;
288 xampl[1] = 0.5 * ampl;
289 xampl[2] = 0.8 * ampl;
295 for (
int i = 0;
i < 3;
i++) {
299 tplus[
i] = firstsample + lastsample;
304 int im = heresamplemax;
305 int iplusbound = firstsample + lastsample - im;
307 for (
int j = 0;
j < 3;
j++) {
308 for (
int i = 1;
i < im;
i++) {
309 if (bong[im -
i] < xampl[
j] && bong[im -
i + 1] > xampl[
j]) {
316 for (
int i = 0;
i < iplusbound;
i++) {
317 if (bong[im +
i] > xampl[
j] && bong[im +
i + 1] < xampl[
j]) {
326 double slopeplus = double(bong[tplus[
j] + 1] - bong[tplus[
j]]);
327 double slopeminus = double(bong[tminus[
j] + 1] - bong[tminus[
j]]);
329 double timeminus = double(tminus[
j]) + 0.5;
331 timeminus = tminus[
j] + (xampl[
j] - double(bong[tminus[
j]])) / slopeminus;
333 double timeplus = double(tplus[
j]) + 0.5;
335 timeplus = tplus[
j] + (xampl[
j] - double(bong[tplus[
j]])) / slopeplus;
337 width[
j] = timeplus - timeminus;
368 int kmax = (
int)pkval - firstsample;
371 for (Int_t
k = 0;
k < kmax;
k++)
372 if (0. < bong[
k] && bong[
k] < amplx) {
378 for (Int_t
k = kmax;
k >= 0;
k--)
379 if (bong[
k] > amplx) {
384 if (bin_high < bin_low)
387 if (bin_low == bin_high) {
388 T = (double)bin_high;
390 double slope = (bong[bin_high] - bong[bin_low]) / ((
double)(bin_high - bin_low));
391 T = (double)bin_high - (bong[bin_high] - amplx) /
slope;
398 if (anevt < 2 * nevlasers) {
399 if (anevt < nevlasers) {
401 status[nevmtq0 - 1] = anevt;
402 comp_trise[nevmtq0 - 1] = trise;
403 comp_peak[nevmtq0 - 1] = pkval;
406 status[nevmtq0 + nevmtq1 - 1] = anevt;
407 comp_trise[nevmtq0 + nevmtq1 - 1] = trise;
408 comp_peak[nevmtq0 + nevmtq1 - 1] = pkval;
411 if (anevt < 3 * nevlasers) {
413 status[nevmtq0 - 1] = anevt;
414 comp_trise[nevmtq0 - 1] = trise;
415 comp_peak[nevmtq0 - 1] = pkval;
418 status[nevmtq0 + nevmtq1 - 1] = anevt;
419 comp_trise[nevmtq0 + nevmtq1 - 1] = trise;
420 comp_peak[nevmtq0 + nevmtq1 - 1] = pkval;
430 sprintf(
filename,
"runMatacq%d.pedestal", gRunNumber);
432 if (fmatacq ==
nullptr)
433 printf(
"Error while opening file : %s\n",
filename);
435 double sumtrise = 0.;
436 double sumtrise2 = 0.;
437 int timestop = timestart + 3;
438 double mintrise = 10000.;
439 double maxtrise = 0.;
440 for (
i = 0;
i < nevmtq0;
i++) {
441 if (comp_trise[
i] > maxtrise) {
442 maxtrise = comp_trise[
i];
444 if (comp_trise[
i] < mintrise) {
445 mintrise = comp_trise[
i];
447 sumtrise += comp_trise[
i];
448 sumtrise2 += comp_trise[
i] * comp_trise[
i];
450 meantrise = sumtrise / ((double)nevmtq0);
451 ss = (sumtrise2 / ((double)nevmtq0) - meantrise * meantrise);
456 fmatacq,
"%d %d %d %d %f %f %f %f\n", nevmtq0, color, timestart, timestop, meantrise, sigtrise, mintrise, maxtrise);
462 for (
i = nevmtq0;
i < nevmtq0 + nevmtq1;
i++) {
463 if (comp_trise[
i] > maxtrise) {
464 maxtrise = comp_trise[
i];
466 if (comp_trise[
i] < mintrise) {
467 mintrise = comp_trise[
i];
469 sumtrise += comp_trise[
i];
470 sumtrise2 += comp_trise[
i] * comp_trise[
i];
472 meantrise = sumtrise / ((double)nevmtq1);
473 ss = (sumtrise2 / ((double)nevmtq1) - meantrise * meantrise);
478 fmatacq,
"%d %d %d %d %f %f %f %f\n", nevmtq1, color, timestart, timestop, meantrise, sigtrise, mintrise, maxtrise);
480 int iret = fclose(fmatacq);
481 printf(
" Closing file : %d\n", iret);
487 sprintf(
filename,
"badevtsMatacq%d.dat", gRunNumber);
489 if (fmatacq ==
nullptr)
490 printf(
"Error while opening file : %s\n",
filename);
493 for (Int_t
i = 0;
i < nevmtq0 + nevmtq1;
i++) {
494 if (comp_trise[
i] < meantrise - 3. * sigtrise) {
496 fprintf(fmatacq,
"%d \n",
status[
i]);
499 if (comp_trise[
i] > meantrise + 3. * sigtrise) {
501 fprintf(fmatacq,
"%d \n",
status[
i]);
506 int iret = fclose(fmatacq);
507 printf(
" Closing file : %d\n", iret);
516 sprintf(
filename,
"runiterMatacq%d.pedestal", gRunNumber);
518 if (fmatacq ==
nullptr)
519 printf(
"Error while opening file : %s\n",
filename);
522 double sumtrise = 0.;
523 double sumtrise2 = 0.;
524 int timestop = timestart + 3;
525 double mintrise = 10000.;
526 double maxtrise = 0.;
527 for (
i = 0;
i < nevmtq0;
i++) {
530 if (comp_trise[
i] > maxtrise) {
531 maxtrise = comp_trise[
i];
533 if (comp_trise[
i] < mintrise) {
534 mintrise = comp_trise[
i];
536 sumtrise += comp_trise[
i];
537 sumtrise2 += comp_trise[
i] * comp_trise[
i];
540 meantrise = sumtrise / ((double)nevmtqgood);
541 ss = (sumtrise2 / ((double)nevmtqgood) - meantrise * meantrise);
546 "%d %d %d %d %f %f %f %f\n",
561 for (
i = nevmtq0;
i < nevmtq0 + nevmtq1;
i++) {
564 if (comp_trise[
i] > maxtrise) {
565 maxtrise = comp_trise[
i];
567 if (comp_trise[
i] < mintrise) {
568 mintrise = comp_trise[
i];
570 sumtrise += comp_trise[
i];
571 sumtrise2 += comp_trise[
i] * comp_trise[
i];
574 meantrise = sumtrise / ((double)nevmtqgood);
575 ss = (sumtrise2 / ((double)nevmtqgood) - meantrise * meantrise);
580 "%d %d %d %d %f %f %f %f\n",
590 int iret = fclose(fmatacq);
591 printf(
" Closing file : %d\n", iret);
void printitermatacqData(Int_t, Int_t, Int_t)
static const double slope[3]
double interpolate(double)
double getPeakValue(int i) const
void printmatacqData(Int_t, Int_t, Int_t)
int rawPulseAnalysis(Int_t, Double_t *)
TMatacq(int, int, int, int, int, int, int, int, int, int, int)
int countBadPulses(Int_t)
uint16_t *__restrict__ uint16_t const *__restrict__ adc