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 ;
230 for (
unsigned int i=1;
i<
imax;
i++){
233 if((asamp1-
base)>=amax/2. && (asamp2-
base)<=amax/2.)
235 wleft=
i-1+(amax/2.-(asamp2-
base))/(asamp1-asamp2);
239 for (
unsigned int i=
imax;
i<
N;
i++){
242 if((asamp1-
base)<=amax/2. && (asamp2-
base)>=amax/2.) {
243 wright=
i-1+((asamp2-
base)-amax/2.)/(asamp2-asamp1);
254 std::vector<double> wave = theWave.
getWave() ;
255 const double dt = theWave.
getDt() ;
257 std::vector<double> dwave ;
260 const double inv_dt = 1. /
dt;
261 dwave[0] = ( wave[1] - wave[0] ) * inv_dt ;
263 dwave[
i] = ( wave[
i+1] - wave[
i-1] ) * inv_dt * 0.5;
276 static const double c[3][4][7] =
277 { { { -0.107, -0.071, -0.036, 0.000, 0.036, 0.071, 0.107 } ,
278 { 0.012, -0.071, -0.107, -0.095, -0.036, 0.071, 0.226 } ,
279 { 0.131, -0.071, -0.179, -0.190, -0.107, 0.071, 0.345 } ,
280 { 0.250, -0.071, -0.250, -0.286, -0.179, 0.071, 0.464 } } ,
281 { { 0.087, -0.266, -0.230, 0.000, 0.230, 0.266, -0.087 } ,
282 { 0.123, -0.183, -0.218, -0.095, 0.075, 0.183, 0.115 } ,
283 { -0.008, 0.067, -0.040, -0.190, -0.246, -0.067, 0.484 } ,
284 { -0.306, 0.484, 0.306, -0.286, -0.734, -0.484, 1.020 } } ,
285 { { 0.087, -0.266, -0.230, 0.000, 0.230, 0.266, -0.087 } ,
286 { -0.049, 0.219, -0.276, -0.439, 0.018, 0.584, -0.057 } ,
287 { -0.079, 0.234, -0.063, -0.333, -0.270, 0.099, 0.413 } ,
288 { 0.269, -0.856, 0.497, 0.863, -0.543, -1.824, 1.594 } } } ;
290 const int ipoly =
m-2 ;
292 std::vector<double> wave = theWave.
getWave() ;
293 const double dt = theWave.
getDt() ;
294 const double inv_dt = 1. /
dt;
296 std::vector<double> dwave ;
302 for (
unsigned int j=0 ; j<=6 ; j++ )
303 dwave[
i] += -
c[ipoly][ifilt][6-j] * wave[j] ;
307 dwave[
i] +=
c[ipoly][ifilt][j-(
nsamples-7)] * wave[j] ;
310 for (
unsigned int j=
i-3 ; j<=
i+3 ; j++ )
311 dwave[
i] +=
c[ipoly][ifilt][j-(
i-3)] * wave[j] ;
320 std::vector<double> wave = theWave.
getWave() ;
323 std::vector<double> ac ;
327 ac[
i] += wave[
i]*wave[
i+
k] ;
338 unsigned Nsamp = (
length-Nfirst + (deltaN-1)) / deltaN ;
340 for (
unsigned i=0;
i<Nsamp;
i++) {
341 unsigned j = Nfirst +
i * deltaN ;
349 if (nBase == 0)
return 0;
374 if (iFirst >= iLast)
return 0.0;
377 std::vector<double>::const_iterator
it=theWave.
getWave().begin()+iFirst;
378 std::vector<double>::const_iterator it_e=theWave.
getWave().begin()+iLast;
379 for(;
it!=it_e;++
it) {
396 if (iFirst >= iLast)
return 0.0;
399 std::vector<double>::const_iterator
it=theWave.
getWave().begin()+iFirst;
400 std::vector<double>::const_iterator it_e=theWave.
getWave().begin()+iLast;
401 for(;
it!=it_e;++
it) {
411 const unsigned Nbase = 5 ;
414 unsigned iMax =
getMax(theWave) ;
416 for (
unsigned i=iMax-1 ;
i>0 ;
i-- )
432 std::vector<double> errorsSquared(theWave.
getErrors());
433 for (
unsigned int iError = 0; iError < errorsSquared.size(); ++iError) {
434 if (errorsSquared[iError] == 0.0)
436 errorsSquared[iError] = errorsSquared[iError] * errorsSquared[iError];
440 LArWave derivativeSquared = derivedWave * derivedWave;
443 std::vector<double> theLinearFit =
linfit(derivativeSquared.
getWave(),errorsSquared,
rho);
445 if ( theLinearFit[1] > 0. && theLinearFit[1]==theLinearFit[1] )
446 return sqrt(theLinearFit[1]);
458 float tmaxAmp =
dt *
getMax(theWave);
460 float rT0 =
dt *
getT0(theWave);
470 std::vector<double>
X,
Y ;
478 std::vector<double>
X,
Y ;
486 std::vector<double>
X,
Y ;
495 const std::vector<double>& vAmpli)
const
497 std::vector<LArWave> MWandDAC0 ;
498 unsigned nWaves = vWaves.size() ;
499 if ( nWaves != vAmpli.size() ) {
500 std::cout <<
" linearMasterWave ERROR: wrong number of amplitudes!" << std::endl ;
503 double dt = vWaves[0]->getDt() ;
504 unsigned len = vWaves[0]->getSize() ;
505 for (
unsigned k=1 ;
k<nWaves ;
k++ ) {
506 if ( vWaves[
k]->getDt() !=
dt ) {
507 std::cout <<
" linearMasterWave ERROR: waves don't have same dt" << std::endl ;
510 if ( vWaves[
k]->
getSize() != len ) {
511 std::cout <<
" linearMasterWave ERROR: waves don't have same length" << std::endl ;
517 for (
unsigned i=0 ;
i<len ;
i++ ) {
518 std::vector<double> ramp ;
519 for (
unsigned k=0 ;
k<nWaves ;
k++ ) {
520 ramp.push_back(vWaves[
k]->getSample(
i)) ;
524 if (
par.size() != 2) {
525 std::cout <<
" linearMasterWave ERROR: linear fit failed" << std::endl ;
531 MWandDAC0.push_back(dac0) ;
532 MWandDAC0.push_back(mw) ;
544 std::vector<double>
C ;
547 unsigned N =
X.size() ;
548 if (
N<2 ||
Y.size()!=
N ) {
551 double Sx=0. , Sy=0. , Sx2=0. , Sxy=0. ,
S=0. , Sy2=0. ;
552 for (
unsigned i=0;
i<
N;
i++) {
561 C[1] = (
S*Sxy - Sx*Sy ) / (
S*Sx2 - Sx*Sx ) ;
562 C[0] = ( Sy*Sx2 - Sxy*Sx ) / (
S*Sx2 - Sx*Sx ) ;
563 if (
C[1] !=
C[1] ||
C[0] !=
C[0] ) {
567 rho = (
S*Sxy - Sx*Sy ) / sqrt( (
S*Sx2-Sx*Sx) * (
S*Sy2-Sy*Sy) ) ;
575 std::vector<double>
C ;
578 unsigned N =
X.size() ;
579 if (
N>=2 &&
Y.size()==
N ) {
580 std::vector<double> logY ;
582 for (
unsigned i=0;
i<
N;
i++ ) {
583 if (
Y[
i]*
Y[0] <= 0.0 ) {
584 fprintf(
stderr,
"ERROR: exp. fit of zero-crossing wave\n") ;
587 logY[
i] =
log(fabs(
Y[
i])) ;
591 if (
Y[0] < 0.0 )
C[0] = -
C[0] ;
597 const std::vector<double>&
Y,
601 std::vector<double>
dummy;
602 if(Ndeg > 2 || (
Y.empty()) || (
X.size() !=
Y.size())) {
606 case 0: {
dummy.resize(1);
608 for(
unsigned int i=0;
i<
Y.size(); ++
i)
sum +=
Y[
i];
613 double a11,a12,a13,a21,a22,a23,a31,a32,a33;
615 double sum =0., sum2=0., sum3=0., sum4=0.;
616 for(
unsigned int i=0;
i<
X.size(); ++
i) {
623 a13 = a22 = a31 = sum2;
627 double ai11,ai12,ai13,ai21,ai22,ai23,ai31,ai32,ai33;
629 a11*(a33*a22-a32*a23) - a21*(a33*a12-a32*a13) + a31*(a23*a12-a22*a13);
630 if(fabs(
det) < 1.e-6)
return (
dummy);
631 ai11 = (a33*a22 - a32*a23);
632 ai12 = ai21 = -(a33*a12-a32*a13);
633 ai22 = a33*a11 - a31*a13;
634 ai13 = ai31 = a23*a12 - a22*a13;
635 ai23 = ai32 = -(a23*a11-a21*a13);
636 ai33 = a22*a11-a21*a12;
637 sum = 0.; sum2=0.; sum3=0.;
638 for(
unsigned int i=0;
i<
X.size(); ++
i) {
644 const double inv_det = 1. /
det;
645 dummy[0] = (ai11*
sum + ai12*sum2 + ai13*sum3) * inv_det;
646 dummy[1] = (ai21*
sum + ai22*sum2 + ai23*sum3) * inv_det;
647 dummy[2] = (ai31*
sum + ai32*sum2 + ai33*sum3) * inv_det;
658 std::vector<double>&
X,std::vector<double>&
Y)
const
667 if ( iFirst > iLast ) iFirst = iLast ;
668 unsigned vlength = iLast - iFirst + 1 ;
672 for (
unsigned i=iFirst ;
i<=iLast ;
i++ ) {
673 unsigned k =
i - iFirst ;