15 std::vector<double> trWave ;
17 for (
unsigned int i=0 ;
i<theWave.
getSize() ;
i++ ) {
18 if ( (
int)
i + nShift >= 0 ) trWave[
i+nShift] = theWave.
getSample(
i) ;
21 for (
unsigned int i=0 ;
i<(
unsigned int)nShift ;
i++ ) {
32 std::vector<double> trWave ;
35 const double Dt = theWave.
getDt();
36 const double inv_Dt = 1. / Dt;
37 if(fabs(tShift) > Dt) {
38 ibin =
int(tShift * inv_Dt);
39 for (
unsigned int i=0 ;
i<theWave.
getSize() ; ++
i ) {
43 for (
unsigned int i=0 ;
i<(
unsigned int)ibin ; ++
i ) {
56 std::vector<double> tranWave ;
57 tranWave.resize(trWave.size());
58 double tmpshift = tShift - ibin * Dt;
61 for(
unsigned int i=1;
i<trWave.size(); ++
i) {
62 tranWave[
i] = trWave[
i] - tmpshift * (trWave[
i] - trWave[
i-1]) * inv_Dt;
65 tranWave[trWave.size() - 1] =
baseline;
66 for(
int i=trWave.size()-2;
i>=0; --
i) {
67 tranWave[
i] = trWave[
i] - tmpshift * (trWave[
i] - trWave[
i+1]) * inv_Dt;
71 return LArWave( tranWave , Dt ) ;
76 const unsigned int N = theWave.
getSize() ;
77 unsigned int imin =
N + 1 ;
78 double amin = +9.999E+99 , asample ;
79 for (
unsigned int i=1 ;
i<
N ;
i++ ) {
91 const unsigned int N = theWave.
getSize() ;
92 unsigned int imax =
N + 1 ;
93 double amax = -9.999E+99 , asample ;
94 for (
unsigned int i=1 ;
i<
N ;
i++ ) {
107 double amax = -9.999E+99 ;
109 if(pfit.size() < 3 || pfit[2] == 0.) { tMax = -9.999E+99;
return amax; }
110 tMax = - pfit[1] / (2 * pfit[2]);
131 const unsigned int N = theWave.
getSize() ;
132 double amax = -9.999E+99;
133 for (
unsigned int i=1;
i<
N ; ++
i ) {
143 const unsigned int N=theWave.
getSize();
145 const unsigned Nbase=5;
146 double amax=-9.999E+99;
148 for (
unsigned int i=1;
i<
N ;
i++) {
150 if((asample-
base)>amax)amax = asample-
base;
153 const double inv_amax = 1. / amax;
154 for (
unsigned int i=0;
i<
N ;
i++){
156 if(asample>0)surf+=asample*inv_amax;
164 const unsigned Nbase=5;
172 for (
unsigned int i=1;
i<
imax ;
i++) {
175 if((asamp1-
base)>amax*0.10 && (asamp2-
base)<amax*0.10)
176 rT0 =
i-1+(0.10*amax-(asamp2-
base))/(asamp1-asamp2);
189 double amax =
getDMax(theWave, tmax);
192 for (
unsigned int i=
imax - 20;
i>0 ; --
i) {
194 std::vector<double> pfit =
polyfit(theWave,
i-3,
i+3, 3);
195 for(
double t=(
i+2)*theWave.
getDt();
t>=(
i-2)*theWave.
getDt();
t-= 0.05) {
196 if(pfit[0]+pfit[1]*
t+pfit[2]*
t*
t+pfit[3]*
t*
t*
t < 0.05*amax) {
211 const unsigned int N = theWave.
getSize() ;
212 unsigned int imax= 1;
213 const unsigned Nbase=5;
214 double amax=-9.999E+99;
216 for (
unsigned int i=1;
i<
N ;
i++) {
218 if((asample-
base)>amax){
220 amax = asample-
base ;
234 for (
unsigned int i=1;
i<
imax;
i++){
237 if((asamp1-
base)>=amax/2. && (asamp2-
base)<=amax/2.)
239 wleft=
i-1+(amax/2.-(asamp2-
base))/(asamp1-asamp2);
243 for (
unsigned int i=
imax;
i<
N;
i++){
246 if((asamp1-
base)<=amax/2. && (asamp2-
base)>=amax/2.) {
247 wright=
i-1+((asamp2-
base)-amax/2.)/(asamp2-asamp1);
258 std::vector<double> wave = theWave.
getWave() ;
259 const double dt = theWave.
getDt() ;
261 std::vector<double> dwave ;
264 const double inv_dt = 1. /
dt;
265 dwave[0] = ( wave[1] - wave[0] ) * inv_dt ;
267 dwave[
i] = ( wave[
i+1] - wave[
i-1] ) * inv_dt * 0.5;
280 static const double c[3][4][7] =
281 { { { -0.107, -0.071, -0.036, 0.000, 0.036, 0.071, 0.107 } ,
282 { 0.012, -0.071, -0.107, -0.095, -0.036, 0.071, 0.226 } ,
283 { 0.131, -0.071, -0.179, -0.190, -0.107, 0.071, 0.345 } ,
284 { 0.250, -0.071, -0.250, -0.286, -0.179, 0.071, 0.464 } } ,
285 { { 0.087, -0.266, -0.230, 0.000, 0.230, 0.266, -0.087 } ,
286 { 0.123, -0.183, -0.218, -0.095, 0.075, 0.183, 0.115 } ,
287 { -0.008, 0.067, -0.040, -0.190, -0.246, -0.067, 0.484 } ,
288 { -0.306, 0.484, 0.306, -0.286, -0.734, -0.484, 1.020 } } ,
289 { { 0.087, -0.266, -0.230, 0.000, 0.230, 0.266, -0.087 } ,
290 { -0.049, 0.219, -0.276, -0.439, 0.018, 0.584, -0.057 } ,
291 { -0.079, 0.234, -0.063, -0.333, -0.270, 0.099, 0.413 } ,
292 { 0.269, -0.856, 0.497, 0.863, -0.543, -1.824, 1.594 } } } ;
294 const int ipoly =
m-2 ;
296 std::vector<double> wave = theWave.
getWave() ;
297 const double dt = theWave.
getDt() ;
298 const double inv_dt = 1. /
dt;
300 std::vector<double> dwave ;
306 for (
unsigned int j=0 ; j<=6 ; j++ )
307 dwave[
i] += -
c[ipoly][ifilt][6-j] * wave[j] ;
311 dwave[
i] +=
c[ipoly][ifilt][j-(
nsamples-7)] * wave[j] ;
314 for (
unsigned int j=
i-3 ; j<=
i+3 ; j++ )
315 dwave[
i] +=
c[ipoly][ifilt][j-(
i-3)] * wave[j] ;
324 std::vector<double> wave = theWave.
getWave() ;
327 std::vector<double> ac ;
331 ac[
i] += wave[
i]*wave[
i+
k] ;
342 unsigned Nsamp = (
length-Nfirst + (deltaN-1)) / deltaN ;
344 for (
unsigned i=0;
i<Nsamp;
i++) {
345 unsigned j = Nfirst +
i * deltaN ;
353 if (nBase == 0)
return 0;
378 if (iFirst >= iLast)
return 0.0;
381 std::vector<double>::const_iterator
it=theWave.
getWave().begin()+iFirst;
382 std::vector<double>::const_iterator it_e=theWave.
getWave().begin()+iLast;
383 for(;
it!=it_e;++
it) {
400 if (iFirst >= iLast)
return 0.0;
403 std::vector<double>::const_iterator
it=theWave.
getWave().begin()+iFirst;
404 std::vector<double>::const_iterator it_e=theWave.
getWave().begin()+iLast;
405 for(;
it!=it_e;++
it) {
415 const unsigned Nbase = 5 ;
418 unsigned iMax =
getMax(theWave) ;
420 for (
unsigned i=iMax-1 ;
i>0 ;
i-- )
436 std::vector<double> errorsSquared(theWave.
getErrors());
437 for (
unsigned int iError = 0; iError < errorsSquared.size(); ++iError) {
438 if (errorsSquared[iError] == 0.0)
440 errorsSquared[iError] = errorsSquared[iError] * errorsSquared[iError];
444 LArWave derivativeSquared = derivedWave * derivedWave;
447 std::vector<double> theLinearFit =
linfit(derivativeSquared.
getWave(),errorsSquared,
rho);
449 if ( theLinearFit[1] > 0. && theLinearFit[1]==theLinearFit[1] )
450 return sqrt(theLinearFit[1]);
462 float tmaxAmp =
dt *
getMax(theWave);
464 float rT0 =
dt *
getT0(theWave);
474 std::vector<double>
X,
Y ;
482 std::vector<double>
X,
Y ;
490 std::vector<double>
X,
Y ;
499 const std::vector<double>& vAmpli)
const
501 std::vector<LArWave> MWandDAC0 ;
502 unsigned nWaves = vWaves.size() ;
503 if ( nWaves != vAmpli.size() ) {
504 std::cout <<
" linearMasterWave ERROR: wrong number of amplitudes!" << std::endl ;
507 double dt = vWaves[0]->getDt() ;
508 unsigned len = vWaves[0]->getSize() ;
509 for (
unsigned k=1 ;
k<nWaves ;
k++ ) {
510 if ( vWaves[
k]->getDt() !=
dt ) {
511 std::cout <<
" linearMasterWave ERROR: waves don't have same dt" << std::endl ;
514 if ( vWaves[
k]->
getSize() != len ) {
515 std::cout <<
" linearMasterWave ERROR: waves don't have same length" << std::endl ;
521 for (
unsigned i=0 ;
i<len ;
i++ ) {
522 std::vector<double> ramp ;
523 for (
unsigned k=0 ;
k<nWaves ;
k++ ) {
524 ramp.push_back(vWaves[
k]->getSample(
i)) ;
528 if (
par.size() != 2) {
529 std::cout <<
" linearMasterWave ERROR: linear fit failed" << std::endl ;
535 MWandDAC0.push_back(dac0) ;
536 MWandDAC0.push_back(mw) ;
548 std::vector<double>
C ;
551 unsigned N =
X.size() ;
552 if (
N<2 ||
Y.size()!=
N ) {
555 double Sx=0. , Sy=0. , Sx2=0. , Sxy=0. ,
S=0. , Sy2=0. ;
556 for (
unsigned i=0;
i<
N;
i++) {
565 C[1] = (
S*Sxy - Sx*Sy ) / (
S*Sx2 - Sx*Sx ) ;
566 C[0] = ( Sy*Sx2 - Sxy*Sx ) / (
S*Sx2 - Sx*Sx ) ;
567 if (
C[1] !=
C[1] ||
C[0] !=
C[0] ) {
571 rho = (
S*Sxy - Sx*Sy ) / sqrt( (
S*Sx2-Sx*Sx) * (
S*Sy2-Sy*Sy) ) ;
579 std::vector<double>
C ;
582 unsigned N =
X.size() ;
583 if (
N>=2 &&
Y.size()==
N ) {
584 std::vector<double> logY ;
586 for (
unsigned i=0;
i<
N;
i++ ) {
587 if (
Y[
i]*
Y[0] <= 0.0 ) {
588 fprintf(
stderr,
"ERROR: exp. fit of zero-crossing wave\n") ;
591 logY[
i] =
log(fabs(
Y[
i])) ;
595 if (
Y[0] < 0.0 )
C[0] = -
C[0] ;
601 const std::vector<double>&
Y,
605 std::vector<double>
dummy;
606 if(Ndeg > 2 || (
Y.empty()) || (
X.size() !=
Y.size())) {
610 case 0: {
dummy.resize(1);
612 for(
unsigned int i=0;
i<
Y.size(); ++
i)
sum +=
Y[
i];
617 double a11,a12,a13,a21,a22,a23,a31,a32,a33;
619 double sum =0., sum2=0., sum3=0., sum4=0.;
620 for(
unsigned int i=0;
i<
X.size(); ++
i) {
627 a13 = a22 = a31 = sum2;
631 double ai11,ai12,ai13,ai21,ai22,ai23,ai31,ai32,ai33;
633 a11*(a33*a22-a32*a23) - a21*(a33*a12-a32*a13) + a31*(a23*a12-a22*a13);
634 if(fabs(
det) < 1.e-6)
return (
dummy);
635 ai11 = (a33*a22 - a32*a23);
636 ai12 = ai21 = -(a33*a12-a32*a13);
637 ai22 = a33*a11 - a31*a13;
638 ai13 = ai31 = a23*a12 - a22*a13;
639 ai23 = ai32 = -(a23*a11-a21*a13);
640 ai33 = a22*a11-a21*a12;
641 sum = 0.; sum2=0.; sum3=0.;
642 for(
unsigned int i=0;
i<
X.size(); ++
i) {
648 const double inv_det = 1. /
det;
649 dummy[0] = (ai11*
sum + ai12*sum2 + ai13*sum3) * inv_det;
650 dummy[1] = (ai21*
sum + ai22*sum2 + ai23*sum3) * inv_det;
651 dummy[2] = (ai31*
sum + ai32*sum2 + ai33*sum3) * inv_det;
662 std::vector<double>&
X,std::vector<double>&
Y)
const
671 if ( iFirst > iLast ) iFirst = iLast ;
672 unsigned vlength = iLast - iFirst + 1 ;
676 for (
unsigned i=iFirst ;
i<=iLast ;
i++ ) {
677 unsigned k =
i - iFirst ;