12 #include <TGraphErrors.h>
13 #include <TSpectrum.h>
70 name =
"hrawpulse"; name +=
ch;
72 name =
"hsubpulse"; name +=
ch;
77 name =
"grawpulse"; name +=
ch;
81 name =
"gsubpulse"; name +=
ch;
88 name =
"hPed0_"; name +=
ch;
89 hPed0 =
new TH1F(name,name,16384,-0.5,16383.5);
110 TString name =
"h2Template"; name +=
ch;
114 name =
"h2Residuals"; name +=
ch;
169 for (
int isamp=0; isamp<
nsamples; isamp++)
171 hRawPulse->SetBinContent( isamp+1, y[isamp] );
172 gRawPulse->SetPoint( isamp, Double_t(isamp), y[isamp] );
189 for (
int isamp=0; isamp<
nsamples; isamp++)
193 gSubPulse->SetPoint( isamp, (Double_t)isamp, invert*(y[isamp]-
ped0) );
215 for(
int isamp=0; isamp<
nsamples; isamp++ )
218 hRawPulse->SetBinContent( isamp+1, y[isamp] );
219 gRawPulse->SetPoint( isamp, x[isamp], y[isamp] );
233 for (
int isamp=0; isamp<
nsamples; isamp++)
241 gSubPulse->SetPoint( isamp, x[isamp], invert*(y[isamp]-
ped0) );
254 double step_size = 0.01;
256 for (
double ix=0; ix<
nsamples; ix += step_size)
258 Double_t val = s3.Eval(ix);
315 for (
int isamp=sampmin; isamp<=sampmax; isamp++)
339 for (
int isamp=0; isamp<
n; isamp++)
342 if ( x>=begin && x<=end )
380 for (
int isamp=minpedsamp; isamp<=maxpedsamp; isamp++)
410 for (
int isamp=0; isamp<
n; isamp++)
414 if ( x>= minpedx && x<= maxpedx)
442 for (
int isamp=0; isamp<
n; isamp++)
444 if ( y[isamp] > threshold )
446 if ( isamp==(n-1) || y[isamp+1] > threshold )
453 if ( sample == -1 )
return -9999.;
456 Double_t dx = x[sample] - x[sample-1];
457 Double_t
dy = y[sample] - y[sample-1];
458 Double_t dt1 = y[sample] - threshold;
460 Double_t t0 = x[sample] - dt1*(dx/
dy);
475 Double_t
ymax = TMath::MaxElement(n,y);
478 Double_t threshold = fraction_threshold *
ymax;
482 for (
int isamp=0; isamp<
n; isamp++)
484 if ( y[isamp] > threshold )
486 if ( isamp==(n-1) || y[isamp+1] > threshold )
493 if ( sample == -1 )
return -9999.;
496 Double_t dx = x[sample] - x[sample-1];
497 Double_t
dy = y[sample] - y[sample-1];
498 Double_t dt1 = y[sample] - threshold;
500 Double_t t0 = x[sample] - dt1*(dx/
dy);
511 cout <<
"ERROR y == 0" << endl;
516 Double_t t0 = y[max_samp];
520 Double_t ymax = TMath::MaxElement(n,y);
533 for (
int ix=0; ix<
n; ix++)
535 if (x[ix]>=xmin && x[ix]<=xmax)
538 Double_t dx = (x[ix+1]-x[ix-1])/2.0;
546 void OnlBbcSig::LocMax(Double_t& x_at_max, Double_t& ymax, Double_t xminrange, Double_t xmaxrange)
554 if ( xmaxrange <= xminrange )
556 xminrange = -DBL_MAX;
562 for (
int i=0;
i<
n;
i++)
565 if ( x[
i] < xminrange )
continue;
566 if ( x[
i] > xmaxrange )
break;
585 if ( xmaxrange <= xminrange )
587 xminrange = -DBL_MAX;
593 for (
int i=0;
i<
n;
i++)
596 if ( x[
i] < xminrange )
continue;
597 if ( x[
i] > xmaxrange )
break;
613 cout <<
"CH " <<
ch << endl;
614 for (
int isamp=0; isamp<
nsamples; isamp++)
616 gpulse->GetPoint(isamp,x,y);
617 cout << isamp <<
"\t" << x <<
"\t" << y << endl;
630 if (junk[0] ==
'w' || junk[0] ==
's')
632 TString name =
"ch"; name +=
ch; name +=
".png";
633 gPad->SaveAs( name );
642 Double_t xx = x[0]-par[1];
657 else if ( xx > template_endtime )
675 int ilow = TMath::FloorNint( index );
676 int ihigh = TMath::CeilNint( index );
681 cout <<
"ERROR, ilow ihigh " << ilow <<
"\t" << ihigh << endl;
682 cout <<
" " << xx <<
" " << x[0] <<
" " << par[1] << endl;
705 f = par[0]*(y0+((y1-y0)/(x1-x0))*(xx-x0));
714 if (
verbose>0 ) cout <<
"Fitting ch " << ch << endl;
754 Double_t x_at_max,
ymax;
770 cout <<
"FitTemplate " <<
f_ampl <<
"\t" <<
f_time << endl;
807 TString name =
"hAmpl"; name +=
ch;
808 hAmpl =
new TH1F(name,name,17100,-100,17000);
812 TString name =
"hTime"; name +=
ch;
813 hTime =
new TH1F(name,name,3100,0,31);
826 double step_size =
h2Template->GetXaxis()->GetBinWidth(1);
828 for (
double ix=0; ix<
nsamples; ix += step_size)
830 Double_t val = s3.Eval(ix);
851 for (
double ix=0; ix<
nsamples; ix += step_size)
853 Double_t val = s3.Eval(ix);
857 Double_t dy_mid = val - 0.5*
f_ampl;
858 Double_t dy_prev = val - s3.Eval(ix-step_size);
859 Double_t dx_prev = step_size;
861 f_time = ix - (dy_mid/dy_prev)*dx_prev;
875 for (
int isamp=0; isamp<
nsamples; isamp++)
880 Double_t fillvalues[2] = {0.};
881 fillvalues[0] = x -
f_time;
887 h2Template->Fill(fillvalues[0],fillvalues[1]);
901 if (
verbose ) cout <<
"In OnlBbcSig::MakeAndWriteTemplate" << endl;
905 TString name =
h2Template->GetName(); name +=
"_py";
906 TH1 *hprojy =
h2Template->ProjectionY(name,1,1,
"e");
908 gaus->SetLineColor(2);
919 TString fitarg =
"R";
920 if (
verbose==0 ) fitarg +=
"NQ";
930 Double_t ncounts = hprojy->Integral();
936 else if ( ncounts<100. )
941 Double_t peak = hprojy->GetBinContent( hprojy->GetMaximumBin() );
942 Double_t mean = hprojy->GetBinCenter( hprojy->GetMaximumBin() );
943 Double_t rms = hprojy->GetRMS();
946 gaus->SetParameters(peak,mean,rms);
948 if ( ncounts>=10 ) hprojy->Fit(gaus,fitarg);
977 out << ch <<
"\t" << template_npointsx <<
"\t" <<
template_begintime <<
"\t" << template_endtime << endl;
978 oerr << ch <<
"\t" << template_npointsx <<
"\t" <<
template_begintime <<
"\t" << template_endtime << endl;
983 if (
ibin%10==9) out << endl;
987 if (
ibin%10==9) oerr << endl;
999 TString name =
"hAmpl"; name +=
ch;
1000 hAmpl =
new TH1F(name,name,17100,-100,17000);
1004 TString name =
"hTime"; name +=
ch;
1005 hTime =
new TH1F(name,name,3100,0,31);
1011 if ( f_ampl<template_min_good_amplitude || f_ampl>template_max_good_amplitude )
return;
1014 if (
verbose ) cout <<
"ampl time " << ch <<
"\t" <<
f_ampl <<
"\t" << f_time << endl;
1016 hTime->Fill( f_time );
1019 for (
int isamp=0; isamp<
nsamples; isamp++)
1024 Double_t fillvalues[2] = {0};
1025 fillvalues[0] = x -
f_time;
1029 fillvalues[1] = y/
f_ampl;
1031 h2Template->Fill( fillvalues[0], fillvalues[1] );
1040 Int_t temp_ch = -9999;
1041 Int_t temp_nsamples;
1042 Double_t temp_begintime;
1043 Double_t temp_endtime;
1049 while ( shapefile >> temp_ch >> temp_nsamples >> temp_begintime >> temp_endtime )
1051 if (
verbose ) cout <<
"shape " << temp_ch <<
"\t" << temp_nsamples <<
"\t" << temp_begintime <<
"\t" << temp_endtime << endl;
1052 if ( temp_ch != ch )
1054 cerr <<
"ERROR in shape: ch is " << temp_ch <<
"but should be " << ch << endl;
1059 for (
int isamp=0; isamp<temp_nsamples; isamp++)
1061 shapefile >> temp_val;
1062 template_y.push_back( temp_val );
1065 cout << template_y[isamp] <<
" ";
1066 if ( isamp%10==9 ) cout << endl;
1074 while ( sherrfile >> temp_ch >> temp_nsamples >> temp_begintime >> temp_endtime )
1076 if (
verbose ) cout <<
"sherr " << temp_ch <<
"\t" << temp_nsamples <<
"\t" << temp_begintime <<
"\t" << temp_endtime << endl;
1077 if ( temp_ch != ch )
1079 cerr <<
"ERROR in sherr: ch is " << temp_ch <<
" but should be " << ch << endl;
1084 for (
int isamp=0; isamp<temp_nsamples; isamp++)
1086 sherrfile >> temp_val;
1091 if ( isamp%10==9 ) cout << endl;
1098 TString name =
"template_fcn"; name +=
ch;