22 for(
int k=0;
k<=100;
k++)
32 TMatacq::TMatacq(
int Ntot,
int Nsamp1,
int Nsamp2,
int cut,
int Nbef,
int Naft,
int niv1,
int niv2,
int niv3,
int nevl,
int NSlide)
37 nsigcut= (double) cut;
38 fNum_samp_bef_max= Nbef;
39 fNum_samp_aft_max= Naft;
40 level1= ((double) niv1)/100.;
41 level2= ((double) niv2)/100.;
42 level3= ((double) niv3)/100.;
46 for(
int k=0;
k<nevlasers;
k++)
48 for(
int k=0;
k<nevlasers;
k++)
66 double dsum=0.,dsum2=0.;
72 if(Nsamp != fNsamples) {
73 printf(
"found different number of samples fNsamples=%d Nsamp=%d\n",fNsamples,Nsamp);
77 for(k=0;k<presample;k++) {
79 dsum2+= adc[
k]*adc[
k];
81 bl=dsum/((double) presample);
82 double ss= (dsum2/((double) presample)-bl*bl);
85 for(ithr=0,k=presample;k<endsample;k++) {
86 if(adc[k] > (bl+nsigcut*sigbl) && ithr == 0) {
87 ithr=1; firstsample=
k;
91 if(ithr == 0)
return 101;
93 for(ithr=0,k=firstsample;k<Nsamp;k++) {
94 if(adc[k] < (bl+nsigcut*sigbl) && ithr == 0) {
98 if(ithr == 0) lastsample= Nsamp;
102 val_max=0.; samplemax=0;
103 for (Int_t is=firstsample;is<lastsample;is++) {
104 bong[is-firstsample]= adc[is] - bl;
105 if(bong[is-firstsample] > val_max) {
106 val_max= bong[is-firstsample]; samplemax=is;
109 if(samplemax == 0)
return 103;
110 if(samplemax > lastsample)
return 104;
111 if(samplemax < firstsample)
return 105;
114 int endslide=samplemax -nslide;
115 int beginslide=nslide;
119 for(
int i=beginslide;
i<endslide;
i++) {
120 slidingmean+= adc[
i];
123 if( islidingmean!=0) slidingmean/=double(islidingmean);
129 int k;
int nbinf=0;
int jfind=0;
131 double thres= val_max*level1;
135 if(bong[k] > thres) {
140 if(jfind == 0) nbinf=0;
142 for(k=NMAXSAMP,jfind=0;k>nbinf;k--) {
144 if(bong[k] > thres) {
149 if(nbsup == 0) nbsup=nbinf;
157 if(nbinf > 4) nbinf-=3;
159 if(nbsup < NMAXSAMP-4) nbsup+=3;
168 if(bong[k] > 0.) jfind++;
172 }
else if(jfind == 1) {
178 bing[k+1]= (
int) bong[k];
183 peak -> peakFinder(&bing[0]);
184 pkval= peak -> getPeakValue(0);
185 sigpkval= peak -> getPeakValue(1);
194 pkval+= (firstsample -1);
204 ampl=0.; timeatmax=0.;
205 int heresamplemax= samplemax-firstsample;
207 int beginfit= heresamplemax - fNum_samp_bef_max;
208 int endfit= heresamplemax + fNum_samp_aft_max;
210 int nval= endfit-beginfit +1;
211 if(nval !=
NSPARAB)
return 201;
212 for(
int kn=beginfit;kn<=endfit;kn++) {
213 if(bong[kn] <= 0) testneg=1;
215 if(testneg == 1)
return 202;
217 for(
int i=0;
i<nval;
i++) {
218 val[
i]= bong[beginfit+
i];
220 fv2[
i]= (double) (
i);
221 fv3[
i]= ((double)(
i))*((
double)(
i));
224 TVectorD y(nval,
val);
225 TVectorD
f1(nval,fv1);
226 TVectorD
f2(nval,fv2);
227 TVectorD
f3(nval,fv3);
230 bj[0]= f1*y; bj[1]=f2*y; bj[2]= f3*y;
234 aij[0]= f1*
f1; aij[1]=f1*
f2; aij[2]=f1*
f3;
235 aij[3]= f2*
f1; aij[4]=f2*
f2; aij[5]=f2*
f3;
236 aij[6]= f3*
f1; aij[7]=f3*
f2; aij[8]=f3*
f3;
244 double *par= c.GetMatrixArray();
246 timeatmax= -par[1]/(2.*par[2]);
247 ampl= par[0]-par[2]*(timeatmax*timeatmax);
251 ampl=bong[heresamplemax];
257 if((
int)timeatmax < 0)
260 timeatmax+= (beginfit + firstsample);
262 int tplus[3], tminus[3];
272 for(
int i=0;
i<3;
i++){
276 tplus[
i]=firstsample+lastsample;
281 int im = heresamplemax;
282 int iplusbound = firstsample+lastsample-im;
284 for(
int j=0;j<3;j++){
286 for(
int i=1;
i<im;
i++){
289 if (bong[im-
i]<xampl[j] && bong[im-
i+1]>xampl[j]) {
297 for(
int i=0;
i<iplusbound;
i++){
299 if (bong[im+
i]>xampl[j] && bong[im+
i+1]<xampl[j]){
308 double slopeplus = double( bong[tplus[j] +1] - bong[tplus[j] ] );
309 double slopeminus = double( bong[tminus[j]+1] - bong[tminus[j]] );
312 double timeminus=double(tminus[j])+0.5;
313 if(slopeminus!=0) timeminus=tminus[j]+(xampl[j]-double(bong[tminus[j]]))/slopeminus;
316 double timeplus=double(tplus[j])+0.5;
317 if(slopeplus!=0) timeplus=tplus[j]+(xampl[j]-double(bong[tplus[j]]))/slopeplus;
319 width[j]=timeplus-timeminus;
357 int kmax= (
int) pkval - firstsample;
360 for(Int_t
k=0;
k<kmax;
k++)
361 if(0. < bong[
k] && bong[
k] < amplx) {
364 if(bin_low == 0)
return -301.;
366 for(Int_t
k=kmax;
k>=0;
k--)
367 if(bong[
k] > amplx) {
370 if(bin_high == 0)
return -302.;
371 if(bin_high < bin_low)
return -303.;
374 if(bin_low == bin_high) {
375 T= (double) bin_high;
377 double slope= (bong[bin_high]-bong[bin_low])/((
double) (bin_high-bin_low));
378 T= (double) bin_high - (bong[bin_high] - amplx)/
slope;
386 if(anevt < 2*nevlasers) {
387 if(anevt < nevlasers) {
390 comp_trise[nevmtq0-1]= trise;
391 comp_peak[nevmtq0-1]= pkval;
394 status[nevmtq0+nevmtq1-1]= anevt;
395 comp_trise[nevmtq0+nevmtq1-1]= trise;
396 comp_peak[nevmtq0+nevmtq1-1]= pkval;
399 if(anevt < 3*nevlasers) {
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;
419 sprintf(filename,
"runMatacq%d.pedestal",gRunNumber);
420 fmatacq = fopen(filename,
"w");
421 if(fmatacq ==
nullptr) printf(
"Error while opening file : %s\n",filename);
423 double sumtrise=0.;
double sumtrise2=0.;
424 int timestop= timestart+3;
425 double mintrise=10000.;
427 for(i=0;i<nevmtq0;i++) {
428 if(comp_trise[i] > maxtrise) {
429 maxtrise=comp_trise[
i];
431 if(comp_trise[i] < mintrise) {
432 mintrise= comp_trise[
i];
434 sumtrise+=comp_trise[
i];
435 sumtrise2+=comp_trise[
i]*comp_trise[
i];
437 meantrise= sumtrise/((double) nevmtq0);
438 ss= (sumtrise2/((double) nevmtq0) - meantrise*meantrise);
441 fprintf(fmatacq,
"%d %d %d %d %f %f %f %f\n",
442 nevmtq0,color,timestart,timestop,meantrise,sigtrise,mintrise,maxtrise);
444 sumtrise=0.; sumtrise2=0.;
447 for(i=nevmtq0;i<nevmtq0+nevmtq1;i++) {
448 if(comp_trise[i] > maxtrise) {
449 maxtrise=comp_trise[
i];
451 if(comp_trise[i] < mintrise) {
452 mintrise= comp_trise[
i];
454 sumtrise+=comp_trise[
i];
455 sumtrise2+=comp_trise[
i]*comp_trise[
i];
457 meantrise= sumtrise/((double) nevmtq1);
458 ss= (sumtrise2/((double) nevmtq1) - meantrise*meantrise);
461 fprintf(fmatacq,
"%d %d %d %d %f %f %f %f\n",
462 nevmtq1,color,timestart,timestop,meantrise,sigtrise,mintrise,maxtrise);
464 int iret=fclose(fmatacq);
465 printf(
" Closing file : %d\n",iret);
472 sprintf(filename,
"badevtsMatacq%d.dat",gRunNumber);
473 fmatacq = fopen(filename,
"w");
474 if(fmatacq ==
nullptr) printf(
"Error while opening file : %s\n",filename);
477 for(Int_t
i=0;
i<nevmtq0+nevmtq1;
i++) {
478 if(comp_trise[
i] < meantrise - 3.*sigtrise) {
480 fprintf(fmatacq,
"%d \n",
status[
i]);
483 if(comp_trise[
i] > meantrise + 3.*sigtrise) {
485 fprintf(fmatacq,
"%d \n",
status[
i]);
490 int iret=fclose(fmatacq);
491 printf(
" Closing file : %d\n",iret);
501 sprintf(filename,
"runiterMatacq%d.pedestal",gRunNumber);
502 fmatacq = fopen(filename,
"w");
503 if(fmatacq ==
nullptr) printf(
"Error while opening file : %s\n",filename);
506 double sumtrise=0.;
double sumtrise2=0.;
507 int timestop= timestart+3;
508 double mintrise=10000.;
510 for(i=0;i<nevmtq0;i++) {
513 if(comp_trise[i] > maxtrise) {
514 maxtrise=comp_trise[
i];
516 if(comp_trise[i] < mintrise) {
517 mintrise= comp_trise[
i];
519 sumtrise+=comp_trise[
i];
520 sumtrise2+=comp_trise[
i]*comp_trise[
i];
523 meantrise= sumtrise/((double) nevmtqgood);
524 ss= (sumtrise2/((double) nevmtqgood) - meantrise*meantrise);
527 fprintf(fmatacq,
"%d %d %d %d %f %f %f %f\n",
528 nevmtqgood,color,timestart,timestop,meantrise,sigtrise,mintrise,maxtrise);
531 sumtrise=0.; sumtrise2=0.;
534 for(i=nevmtq0;i<nevmtq0+nevmtq1;i++) {
537 if(comp_trise[i] > maxtrise) {
538 maxtrise=comp_trise[
i];
540 if(comp_trise[i] < mintrise) {
541 mintrise= comp_trise[
i];
543 sumtrise+=comp_trise[
i];
544 sumtrise2+=comp_trise[
i]*comp_trise[
i];
547 meantrise= sumtrise/((double) nevmtqgood);
548 ss= (sumtrise2/((double) nevmtqgood) - meantrise*meantrise);
551 fprintf(fmatacq,
"%d %d %d %d %f %f %f %f\n",
552 nevmtqgood,color,timestart,timestop,meantrise,sigtrise,mintrise,maxtrise);
554 int iret=fclose(fmatacq);
555 printf(
" Closing file : %d\n",iret);
void printitermatacqData(Int_t, Int_t, Int_t)
int adc(sample_type sample)
get the ADC sample (12 bits)
static const double slope[3]
double interpolate(double)
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)