23 for(
int k=0;
k<=100;
k++)
33 TMatacq::TMatacq(
int Ntot,
int Nsamp1,
int Nsamp2,
int cut,
int Nbef,
int Naft,
int niv1,
int niv2,
int niv3,
int nevl,
int NSlide)
38 nsigcut= (double) cut;
39 fNum_samp_bef_max= Nbef;
40 fNum_samp_aft_max= Naft;
41 level1= ((double) niv1)/100.;
42 level2= ((double) niv2)/100.;
43 level3= ((double) niv3)/100.;
47 for(
int k=0;
k<nevlasers;
k++)
49 for(
int k=0;
k<nevlasers;
k++)
67 double dsum=0.,dsum2=0.;
73 if(Nsamp != fNsamples) {
74 printf(
"found different number of samples fNsamples=%d Nsamp=%d\n",fNsamples,Nsamp);
78 for(
k=0;
k<presample;
k++) {
80 dsum2+= adc[
k]*adc[
k];
82 bl=dsum/((double) presample);
83 double ss= (dsum2/((double) presample)-bl*bl);
86 for(ithr=0,
k=presample;
k<endsample;
k++) {
87 if(adc[
k] > (bl+nsigcut*sigbl) && ithr == 0) {
88 ithr=1; firstsample=
k;
92 if(ithr == 0)
return 101;
94 for(ithr=0,
k=firstsample;
k<Nsamp;
k++) {
95 if(adc[
k] < (bl+nsigcut*sigbl) && ithr == 0) {
99 if(ithr == 0) lastsample= Nsamp;
103 val_max=0.; samplemax=0;
104 for (Int_t is=firstsample;is<lastsample;is++) {
105 bong[is-firstsample]= adc[is] - bl;
106 if(bong[is-firstsample] > val_max) {
107 val_max= bong[is-firstsample]; samplemax=is;
110 if(samplemax == 0)
return 103;
111 if(samplemax > lastsample)
return 104;
112 if(samplemax < firstsample)
return 105;
115 int endslide=samplemax -nslide;
116 int beginslide=nslide;
120 for(
int i=beginslide;
i<endslide;
i++) {
121 slidingmean+= adc[
i];
124 if( islidingmean!=0) slidingmean/=double(islidingmean);
130 int k;
int nbinf=0;
int jfind=0;
132 double thres= val_max*level1;
136 if(bong[k] > thres) {
141 if(jfind == 0) nbinf=0;
143 for(k=NMAXSAMP,jfind=0;k>nbinf;k--) {
145 if(bong[k] > thres) {
150 if(nbsup == 0) nbsup=nbinf;
158 if(nbinf > 4) nbinf-=3;
160 if(nbsup < NMAXSAMP-4) nbsup+=3;
169 if(bong[k] > 0.) jfind++;
173 }
else if(jfind == 1) {
179 bing[k+1]= (int) bong[k];
184 peak -> peakFinder(&bing[0]);
185 pkval= peak -> getPeakValue(0);
186 sigpkval= peak -> getPeakValue(1);
195 pkval+= (firstsample -1);
205 ampl=0.; timeatmax=0.;
206 int heresamplemax= samplemax-firstsample;
208 int beginfit= heresamplemax - fNum_samp_bef_max;
209 int endfit= heresamplemax + fNum_samp_aft_max;
211 int nval= endfit-beginfit +1;
212 if(nval !=
NSPARAB)
return 201;
213 for(
int kn=beginfit;kn<=endfit;kn++) {
214 if(bong[kn] <= 0) testneg=1;
216 if(testneg == 1)
return 202;
218 for(
int i=0;
i<nval;
i++) {
219 val[
i]= bong[beginfit+
i];
221 fv2[
i]= (double) (
i);
222 fv3[
i]= ((double)(
i))*((
double)(
i));
225 TVectorD
y(nval,val);
226 TVectorD
f1(nval,fv1);
227 TVectorD
f2(nval,fv2);
228 TVectorD
f3(nval,fv3);
231 bj[0]= f1*
y; bj[1]=f2*
y; bj[2]= f3*
y;
235 aij[0]= f1*
f1; aij[1]=f1*
f2; aij[2]=f1*
f3;
236 aij[3]= f2*
f1; aij[4]=f2*
f2; aij[5]=f2*
f3;
237 aij[6]= f3*
f1; aij[7]=f3*
f2; aij[8]=f3*
f3;
245 double *par= c.GetMatrixArray();
247 timeatmax= -par[1]/(2.*par[2]);
248 ampl= par[0]-par[2]*(timeatmax*timeatmax);
252 ampl=bong[heresamplemax];
258 if((
int)timeatmax < 0)
261 timeatmax+= (beginfit + firstsample);
263 int tplus[3], tminus[3];
273 for(
int i=0;
i<3;
i++){
277 tplus[
i]=firstsample+lastsample;
282 int im = heresamplemax;
283 int iplusbound = firstsample+lastsample-im;
285 for(
int j=0;
j<3;
j++){
287 for(
int i=1;
i<im;
i++){
290 if (bong[im-
i]<xampl[
j] && bong[im-
i+1]>xampl[
j]) {
298 for(
int i=0;
i<iplusbound;
i++){
300 if (bong[im+
i]>xampl[
j] && bong[im+
i+1]<xampl[
j]){
309 double slopeplus = double( bong[tplus[
j] +1] - bong[tplus[
j] ] );
310 double slopeminus = double( bong[tminus[j]+1] - bong[tminus[j]] );
313 double timeminus=double(tminus[j])+0.5;
314 if(slopeminus!=0) timeminus=tminus[
j]+(xampl[
j]-double(bong[tminus[j]]))/slopeminus;
317 double timeplus=double(tplus[j])+0.5;
318 if(slopeplus!=0) timeplus=tplus[
j]+(xampl[
j]-double(bong[tplus[j]]))/slopeplus;
320 width[
j]=timeplus-timeminus;
336 double t20= interpolate(ampl*level2);
341 double t80= interpolate(ampl*level3);
358 int kmax= (int) pkval - firstsample;
361 for(Int_t
k=0;
k<kmax;
k++)
362 if(0. < bong[
k] && bong[
k] < amplx) {
365 if(bin_low == 0)
return -301.;
367 for(Int_t
k=kmax;
k>=0;
k--)
368 if(bong[
k] > amplx) {
371 if(bin_high == 0)
return -302.;
372 if(bin_high < bin_low)
return -303.;
375 if(bin_low == bin_high) {
376 T= (double) bin_high;
378 double slope= (bong[bin_high]-bong[bin_low])/((
double) (bin_high-bin_low));
379 T= (double) bin_high - (bong[bin_high] - amplx)/
slope;
387 if(anevt < 2*nevlasers) {
388 if(anevt < nevlasers) {
391 comp_trise[nevmtq0-1]= trise;
392 comp_peak[nevmtq0-1]= pkval;
395 status[nevmtq0+nevmtq1-1]= anevt;
396 comp_trise[nevmtq0+nevmtq1-1]= trise;
397 comp_peak[nevmtq0+nevmtq1-1]= pkval;
400 if(anevt < 3*nevlasers) {
403 comp_trise[nevmtq0-1]= trise;
404 comp_peak[nevmtq0-1]= pkval;
407 status[nevmtq0+nevmtq1-1]= anevt;
408 comp_trise[nevmtq0+nevmtq1-1]= trise;
409 comp_peak[nevmtq0+nevmtq1-1]= pkval;
420 sprintf(filename,
"runMatacq%d.pedestal",gRunNumber);
421 fmatacq = fopen(filename,
"w");
422 if(fmatacq ==
NULL) printf(
"Error while opening file : %s\n",filename);
424 double sumtrise=0.;
double sumtrise2=0.;
425 int timestop= timestart+3;
426 double mintrise=10000.;
428 for(i=0;i<nevmtq0;i++) {
429 if(comp_trise[i] > maxtrise) {
430 maxtrise=comp_trise[
i];
432 if(comp_trise[i] < mintrise) {
433 mintrise= comp_trise[
i];
435 sumtrise+=comp_trise[
i];
436 sumtrise2+=comp_trise[
i]*comp_trise[
i];
438 meantrise= sumtrise/((double) nevmtq0);
439 ss= (sumtrise2/((double) nevmtq0) - meantrise*meantrise);
442 fprintf(fmatacq,
"%d %d %d %d %f %f %f %f\n",
443 nevmtq0,color,timestart,timestop,meantrise,sigtrise,mintrise,maxtrise);
445 sumtrise=0.; sumtrise2=0.;
448 for(i=nevmtq0;i<nevmtq0+nevmtq1;i++) {
449 if(comp_trise[i] > maxtrise) {
450 maxtrise=comp_trise[
i];
452 if(comp_trise[i] < mintrise) {
453 mintrise= comp_trise[
i];
455 sumtrise+=comp_trise[
i];
456 sumtrise2+=comp_trise[
i]*comp_trise[
i];
458 meantrise= sumtrise/((double) nevmtq1);
459 ss= (sumtrise2/((double) nevmtq1) - meantrise*meantrise);
462 fprintf(fmatacq,
"%d %d %d %d %f %f %f %f\n",
463 nevmtq1,color,timestart,timestop,meantrise,sigtrise,mintrise,maxtrise);
465 int iret=fclose(fmatacq);
466 printf(
" Closing file : %d\n",iret);
473 sprintf(filename,
"badevtsMatacq%d.dat",gRunNumber);
474 fmatacq = fopen(filename,
"w");
475 if(fmatacq ==
NULL) printf(
"Error while opening file : %s\n",filename);
478 for(Int_t
i=0;
i<nevmtq0+nevmtq1;
i++) {
479 if(comp_trise[
i] < meantrise - 3.*sigtrise) {
481 fprintf(fmatacq,
"%d \n",
status[
i]);
484 if(comp_trise[
i] > meantrise + 3.*sigtrise) {
486 fprintf(fmatacq,
"%d \n",
status[
i]);
491 int iret=fclose(fmatacq);
492 printf(
" Closing file : %d\n",iret);
502 sprintf(filename,
"runiterMatacq%d.pedestal",gRunNumber);
503 fmatacq = fopen(filename,
"w");
504 if(fmatacq ==
NULL) printf(
"Error while opening file : %s\n",filename);
507 double sumtrise=0.;
double sumtrise2=0.;
508 int timestop= timestart+3;
509 double mintrise=10000.;
511 for(i=0;i<nevmtq0;i++) {
514 if(comp_trise[i] > maxtrise) {
515 maxtrise=comp_trise[
i];
517 if(comp_trise[i] < mintrise) {
518 mintrise= comp_trise[
i];
520 sumtrise+=comp_trise[
i];
521 sumtrise2+=comp_trise[
i]*comp_trise[
i];
524 meantrise= sumtrise/((double) nevmtqgood);
525 ss= (sumtrise2/((double) nevmtqgood) - meantrise*meantrise);
528 fprintf(fmatacq,
"%d %d %d %d %f %f %f %f\n",
529 nevmtqgood,color,timestart,timestop,meantrise,sigtrise,mintrise,maxtrise);
532 sumtrise=0.; sumtrise2=0.;
535 for(i=nevmtq0;i<nevmtq0+nevmtq1;i++) {
538 if(comp_trise[i] > maxtrise) {
539 maxtrise=comp_trise[
i];
541 if(comp_trise[i] < mintrise) {
542 mintrise= comp_trise[
i];
544 sumtrise+=comp_trise[
i];
545 sumtrise2+=comp_trise[
i]*comp_trise[
i];
548 meantrise= sumtrise/((double) nevmtqgood);
549 ss= (sumtrise2/((double) nevmtqgood) - meantrise*meantrise);
552 fprintf(fmatacq,
"%d %d %d %d %f %f %f %f\n",
553 nevmtqgood,color,timestart,timestop,meantrise,sigtrise,mintrise,maxtrise);
555 int iret=fclose(fmatacq);
556 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)