40 template<
class DataType_t>
52 template<
class DataType_t>
65 template<
class DataType_t>
78 template<
class DataType_t>
93 template<
class DataType_t>
102 template<
class DataType_t>
116 template<
class DataType_t>
124 double df = this->
rate()/I/4.;
125 if(I==1)
return this->
rate()/2.;
127 if(
pWavelet->BinaryTree())
return 2*df*(i+0.5);
128 df = this->
rate()/(1<<I);
130 while(i--){ f += 2*
df; df*=2; }
134 template<
class DataType_t>
151 if(j==J) {error =
true;
break;}
156 cout<<
"wseries::mul(): "<<x.
size()<<
" "<<y.
size()<<endl;
162 if(error) {cout<<
"wseries::mul() error!\n";
exit(1);}
166 template<
class DataType_t>
175 if(I<2 || f>=this->
rate()/2.)
return I;
176 double df = this->
rate()/(I-1)/2.;
178 df = this->
rate()/I/2.;
179 if(
pWavelet->BinaryTree())
return int(f/df);
180 df = this->
rate()/(1<<I);
183 while(ff<f){ ff += 2*
df; df*=2; i++; }
192 template<
class DataType_t>
210 cout<<
"WSeries::getLayer(): data length mismatch: "<<this->
limit(s)<<
" "<<this->
size()<<
"\n";
218 template<
class DataType_t>
224 cout<<
"WSeries::putLayer(): invalid array size.\n";
233 template<
class DataType_t>
245 template<
class DataType_t>
260 throw std::invalid_argument
261 (
"WSeries::Forward(): data is not allocated");
265 template<
class DataType_t>
278 template<
class DataType_t>
290 template<
class DataType_t>
307 throw std::invalid_argument
308 (
"WSeries::Inverse(): data is not allocated");
312 template<
class DataType_t>
321 cout<<
"WSeries::bandpass ERROR: no transformation is specified"<<endl;
330 for(
size_t i=0;
i<I;
i++) {
332 if(freq<flow || freq>fhigh) {
339 template<
class DataType_t>
354 size_t n = this->
pWavelet->m_WaveType==
WDMT ? size_t((fl+dF/2.)/dF+0.1) : size_t(fl/dF+0.1);
355 size_t m = this->
pWavelet->m_WaveType==
WDMT ? size_t((fh+dF/2.)/dF+0.1)-1 : size_t(fh/dF+0.1)-1;
361 for(i=0; i<
int(M); i++) {
363 if((f1>=0 && i>n) && (f2>=0 && i<=
m))
continue;
364 if((f1<0 && i<n) || (f2<0 && i>
m))
continue;
365 if((f1<0 && f2>=0 && i<n))
continue;
366 if((f1>=0 && f2<0 && i>=m))
continue;
375 template<
class DataType_t>
399 double aa,ee,EE,uu,UU,dd,DD,em,
ss,cc,nn;
400 double shape,
mean,alp;
402 int J = this->
size()/2;
403 if(pattern==0)
return 1.;
411 int p[] = {0,0,0,0,0,0,0,0,0};
416 if(c!=
'a'||c!=
'A') this->
resize(J);
423 else if(pattern==2) {
427 else if(pattern==3) {
432 else if(pattern==4) {
437 else if(pattern==5) {
438 p[1]=M+1; p[2]=-M-1; p[3]=2*M+2; p[4]=-2*M-2;
442 else if(pattern==6) {
443 p[1]=-M+1; p[2]=M-1; p[3]=-2*M+2; p[4]=2*M-2;
447 else if(pattern==7) {
448 p[1]=1; p[2]=-1; p[3]=
M; p[4]=-
M;
452 else if(pattern==8) {
453 p[1]=M+1; p[2]=-M+1; p[3]= M-1; p[4]=-M-1;
457 else if(pattern==9) {
458 p[1]=1; p[2]=-1; p[3]=
M; p[4]=-
M;
459 p[5]=M+1; p[6]=M-1; p[7]=-M+1; p[8]=-M-1;
462 }
else { shape = mean = 1.; }
467 for(
int j=jb;
j<je;
j++) {
469 if(m<mL || m>mH) {this->
data[
j]=0.;
continue;}
470 q = in.
data+
j; Q = q+J;
471 ss = q[p[1]]*Q[p[1]]+q[p[2]]*Q[p[2]]+q[p[3]]*Q[p[3]]+q[p[4]]*Q[p[4]]
472 + q[p[5]]*Q[p[5]]+q[p[6]]*Q[p[6]]+q[p[7]]*Q[p[7]]+q[p[8]]*Q[p[8]];
473 ee = q[p[1]]*q[p[1]]+q[p[2]]*q[p[2]]+q[p[3]]*q[p[3]]+q[p[4]]*q[p[4]]
474 + q[p[5]]*q[p[5]]+q[p[6]]*q[p[6]]+q[p[7]]*q[p[7]]+q[p[8]]*q[p[8]];
475 EE = Q[p[1]]*Q[p[1]]+Q[p[2]]*Q[p[2]]+Q[p[3]]*Q[p[3]]+Q[p[4]]*Q[p[4]]
476 + Q[p[5]]*Q[p[5]]+Q[p[6]]*Q[p[6]]+Q[p[7]]*Q[p[7]]+Q[p[8]]*Q[p[8]];
477 ss+= q[p[0]]*Q[p[0]]*(mean-8);
478 ee+= q[p[0]]*q[p[0]]*(mean-8);
479 EE+= Q[p[0]]*Q[p[0]]*(mean-8);
482 nn = sqrt(cc*cc+ss*ss);
483 if(ee+EE<nn) nn=ee+EE;
484 aa = sqrt((ee+EE+nn)/2) + sqrt((ee+EE-nn)/2);
485 em = (c==
'e'||c==
'l'||mean==1.) ? (ee+EE)/2. : aa*aa/4;
486 alp = shape-
log(shape)/3;
489 if(em<alp) {em=0;
continue;}
490 em-= alp*(1+
log(em/alp));
494 nn = sqrt((1+cc)*(1+cc)+ss*ss)/2;
495 this->
data[
j]=aa*cc/nn; this->
data[
j+J]=aa*ss/nn/2;
496 }
else {this->
data[
j] = em;}
497 if(hist && em>0.01) hist->Fill(sqrt(em));
503 template<
class DataType_t>
519 cout<<
"wseries::maxEnergy(): illegal wavelet\n";
532 for(
int k=N;
k<=
K;
k+=
N) {
547 for(
int k=N;
k<=
K;
k+=
N) {
563 int m = abs(pattern);
564 if(m==5 || m==6 || m==9) {
571 if(!pattern)
return 1.;
575 template<
class DataType_t>
586 double fff = (nR-nL)*tmp.
wavecount(0.001)/double(nn);
587 double med = tmp.
waveSplit(nL,nR,nR-
int(0.5*fff));
588 double amp, aaa, bbb,
rms, alp;
590 aaa = bbb = 0.; nn = 0;
591 for(
int i=nL;
i<nR;
i++) {
592 amp = (double)this->
data[
i];
593 if(amp>0.01 && amp<20*med) {
594 aaa += amp; bbb +=
log(amp); nn++;
597 alp =
log(aaa/nn)-bbb/nn;
598 alp = (3-alp+sqrt((alp-3)*(alp-3)+24*alp))/12./alp;
599 double avr = med*(3*alp+0.2)/(3*alp-0.8);
602 double ALP = med*alp/
avr;
603 for(
int i=0;
i<this->
size();
i++) {
604 amp = (double)this->
data[
i]*alp/avr;
605 if(amp<ALP) {this->
data[
i]=0.;
continue;}
606 this->
data[
i] = amp-ALP*(1+
log(amp/ALP));
611 rms = 1./tmp.waveSplit(nL,nR,nR-
int(0.3173*fff));
613 for(
int i=0;
i<this->
size();
i++) {
615 if(hist &&
i>nL &&
i<nR) hist->Fill(sqrt(this->
data[
i]));
621 template<
class DataType_t>
632 std::vector<double>
vR;
633 std::vector<double> vF;
634 int mBand, mRate, level;
636 double time,
freq,
a,
A,ee,EE,
ss,cc,gg,b,
B;
637 double mean = 2.*N-1;
638 double shape = N-
log(N)/
N;
640 mBand = 0; mRate = 0;
641 for(
int n=0;
n<
N;
n++) {
643 vR.push_back(pws[
n]->
wrate());
645 vJ.push_back(pws[
n]->
size()/2);
646 if(vM[
n]>mBand) {mBand = vM[
n]; nn=
n;}
652 time = pws[nn]->
size()/pws[nn]->
wrate()/2;
653 J = mRate*
int(time+0.1);
654 cout<<
"debug1: "<<mBand<<
" "<<mRate<<
" "<<J<<
" "<<pws[nn]->
size()<<endl;
662 this->
pWavelet->nSTS = (J/mBand)*(mBand-1);
664 int nL =
int(this->
Edge*mRate*mBand);
665 int nR = this->
size()-nL-1;
667 for(
int i=0;
i<this->
size();
i++) {
668 time = double(
i/mBand)/mRate;
669 freq = (
i%mBand)*vF[nn];
671 for(
int n=1;
n<
N;
n++) {
672 j =
int(time*vR[
n-1]+0.1)*vM[
n-1];
673 j+=
int(freq/vF[
n-1]+0.1);
675 A = pws[
n]->
data[j+vJ[
n-1]];
676 j =
int(time*vR[
n]+0.1)*vM[
n];
677 j+=
int(freq/vF[
n]+0.1);
679 B = pws[
n]->
data[j+vJ[
n]];
685 gg = sqrt(cc*cc+4*ss*ss);
686 a = sqrt((ee+EE+gg)/2);
687 A = sqrt((ee+EE-gg)/2);
691 this->
data[
i] = (a+
A)*(a+A)/mean/2.;
692 if(hist &&
i>nL &&
i<nR) hist->Fill(this->
data[
i]);
701 template<
class DataType_t>
715 template<
class DataType_t>
730 template<
class DataType_t>
735 cout <<
"WSeries::operator[]: Illegal argument: "<<this->
limit()<<
" "<<this->
size()<<
"\n";
741 template<
class DataType_t>
745 template<
class DataType_t>
749 template<
class DataType_t>
753 template<
class DataType_t>
762 template<
class DataType_t>
766 template<
class DataType_t>
770 template<
class DataType_t>
780 cout<<
"WSeries::operator* : wavelet tree type mismatch."<<endl;
789 for(i=0; i<= max_layer; i++)
795 template<
class DataType_t>
804 cout<<
"WSeries::operator+ : wavelet tree type mismatch."<<endl;
813 for(i=0; i<= max_layer; i++)
819 template<
class DataType_t>
828 cout<<
"WSeries::operator- : wavelet tree type mismatch."<<endl;
837 for(i=0; i<= max_layer; i++)
843 template<
class DataType_t>
850 if(max_layer == a.
size()) {
851 for(i=0; i< max_layer; i++) {
859 else cout<<
"WSeries::operator* - no operation is performed"<<endl;
866 template<
class DataType_t>
871 int n = this->
size();
874 if (app == 1)
strcpy (mode,
"a");
878 if ( (fp = fopen(fname, mode)) == NULL ) {
879 cout <<
" Dump() error: cannot open file " << fname <<
". \n";
884 fprintf( fp,
"# start time: -start %lf \n", this->
Start );
885 fprintf( fp,
"# sampling rate: -rate %lf \n", this->
Rate );
886 fprintf( fp,
"# number of samples: -size %d \n", (
int)this->
Size );
887 fprintf( fp,
"# number of layers: -n %d \n", m );
890 for (i = 0; i <
m; i++) {
893 for(j = 0; j <
n; j++)
fprintf( fp,
"%e ", (
float)a.
data[j]);
900 template<
class DataType_t>
905 p->wavearray<DataType_t>::resize(n);
914 template<
class DataType_t>
919 p->wavearray<DataType_t>::resample(f,nF);
924 wRate = p->wavearray<DataType_t>::rate();
925 f_high = p->wavearray<DataType_t>::rate()/2.;
928 template<
class DataType_t>
931 #if !defined (__SUNPRO_CC) 936 register float* q = NULL;
937 register float* p = NULL;
946 if(!
pWavelet->BinaryTree())
return 1.;
949 int nj = this->
size()/ni;
953 bool CROSS = t<0 || f<0;
968 p[
j] = (float)x.
data[j];
969 q[j] = (
float)y.
data[
j];
981 if(p[j]==0. && q[j]==0.)
continue;
983 is = i-f<0 ? 0 : i-
f;
984 js = j-t<0 ? 0 : j-
t;
985 ie = i+f>n ?
n : i+
f;
986 je = j+t>m ?
m : j+
t;
990 for(u=is; u<=ie; u++)
991 for(v=js; v<=je; v++){
992 if(CROSS && !(i==u || j==v))
continue;
993 if(B[u][v]!=0.) energy +=
log(
fabs(B[u][v]));
995 if(energy < threshold) x.
data[
j]=0;
1000 for(u=is; u<=ie; u++)
1001 for(v=js; v<=je; v++){
1002 if(CROSS && !(i==u || j==v))
continue;
1003 if(A[u][v]!=0.) energy +=
log(
fabs(A[u][v]));
1005 if(energy < threshold) y.
data[
j]=0;
1019 template<
class DataType_t>
1025 size_t N = a.
size();
1032 DataType_t* p = NULL;
1033 DataType_t* q = NULL;
1034 DataType_t* P = NULL;
1035 DataType_t*
Q = NULL;
1038 cout<<
"WSeries::operator- : wavelet tree type mismatch."<<endl;
1044 for(k=0; k<= max_layer; k++){
1056 if(!n && w>=0.) n++;
1065 for(i=x.
start(); i<
N; i+=step)
1067 if(this->
data[i] == 0.)
continue;
1082 if(*p>0) { E += *p; m++; }
1087 if(
gammaCL(E,m) > S-
log(
double(m))) pass =
true;
1091 else this->
data[
i] = 0;
1099 for(k=max_layer+1; k<= size_t(
maxLayer()); k++) {
1104 return double(event)/this->
size();
1108 template<
class DataType_t>
1125 template<
class DataType_t>
1128 if(offset<T) offset =
T;
1136 if(mode<2) a.
lprFilter(T,mode,stride,offset);
1137 else a.
spesla(T,stride,offset);
1145 template<
class DataType_t>
1165 double segT = this->
stop()-this->
start();
1166 if(t <= 0.) t = segT-2.*
offset;
1168 int m = mode<0 ? -1 : 1;
1170 this->
w_mode = abs(mode);
1171 if(stride > t || stride<=0.) stride =
t;
1172 size_t K = size_t((segT-2.*offset)/stride);
1184 getLayer(aa,-(i+0.01)); aa*=aa; a*=
a; a+=aa;
1187 if(b.
size() != K+1) cout<<
"wseries::white(): array size mismatch\n";
1203 template<
class DataType_t>
1212 if(!nRMS.
size())
return false;
1217 int m = mode<0 ? -1 : 1;
1222 double R = this->
wrate();
1227 this->
w_mode = abs(mode);
1230 cout<<
"wseries::white error: mismatch between WSeries and nRMS\n";
1234 for(i=(1-m)/2; i<I; i++){
1241 for(j=0; j<J; j++) {
1245 if(t >= To+K*dT) r = na.
data[
K];
1246 else if(t <= To) r = na.
data[0];
1248 if(t > T) {k++; T+=
dT;}
1249 r = (na.
data[k-1]*(dT-T+
t) + na.
data[k]*(T-t))/dT;
1251 xx.
data[
j] *= abs(mode)<=1 ? DataType_t(1./r) : DataType_t(1./r/r);
1259 template<
class DataType_t>
1271 if(!
pWavelet->BinaryTree()) { v = 1.;
return v; }
1280 v.
data[i/
k] += x>0. ? 1./x/
x : 0.;
1286 for(i=0; i<v.
size(); i++)
1295 template<
class DataType_t>
1298 if(fl<0.) fl = this->
getlow();
1299 if(fh<0.) fh = this->
gethigh();
1300 double tsRate = this->
rate();
1304 size_t N = this->
size()/
M;
1305 size_t ml = size_t(2.*M*fl/tsRate+0.5);
1306 size_t mh = size_t(2.*M*fh/tsRate+0.5);
1310 size_t nL = ml+
int((mh-
int(ml))/4.+0.5);
1311 size_t nR = mh-
int((mh-
int(ml))/4.+0.5);
1312 size_t n = size_t(
fabs(t)*tsRate/M);
1323 if(!
pWavelet->BinaryTree() || mh<ml+8 || nL<1)
1324 { v = 1.;
return v; }
1332 laYer[inDex[
j]] =
j;
1338 p = this->
data + i*
M;
1339 for(j=0; j<
M; j++){ pp[
j] = &(p[inDex[
j]]); }
1342 v.
data[
i] = float(*pp[nR] - *pp[nL-1])/2./0.6745;
1364 if(laYer[j]>=ml && laYer[j]<mh) *p /= (DataType_t)v.
data[i];
1373 template<
class DataType_t>
1378 register DataType_t* P=NULL;
1379 register DataType_t** pp;
1380 DataType_t
A, aL, aR;
1382 size_t nS, kS, nL, nR, lS;
1385 size_t nsub = t>0. ? size_t(this->
size()/this->
wrate()/t+0.1) : 1;
1391 if((f>1. ||
bpp!=1.) && mode) {
1392 cout<<
"WSeries fraction(): invalid bpp: "<<
bpp<<
" fraction="<<f<<endl;
1400 pp = (DataType_t **)malloc(
sizeof(DataType_t*));
1411 lS = nS*nsub<S.
size() ? S.
size()-nS*nsub : 0;
1415 for(k=0; k<nsub; k++) {
1419 if(k+1 == nsub) nS += lS;
1421 nL = nS&1 ? nS/2 : nS/2-1;
1424 if(nL<1 || nR>nS-1) {
1425 cout<<
"WSeries::fraction() error: too short wavelet layer"<<endl;
1430 pp = (DataType_t **)realloc(pp,nS*
sizeof(DataType_t*));
1435 for(j=0; j<nS; j++) pp[j] = p + j*kS;
1439 aL = *pp[nL]; aR = *pp[nR];
1441 for(j=0; j<nS; j++){
1444 if(j<nL) *P = (DataType_t)
fabs(A - aL);
1445 else if(j>nR) *P = (DataType_t)
fabs(A - aR);
1446 else { *P = 0; nZero++; }
1454 if(mode == 1)
continue;
1458 for(j=0; j<nS; j++){
1459 if(a.
data[j] == 0.)
continue;
1460 do{ r =
int(nS*drand48()-0.1);}
1461 while(p[r*kS] != 0);
1462 p[r*kS] = a.
data[
j];
1471 if(drand48() > f) { this->
data[
i] = 0; nZero++; }
1476 for(i=0; i<
M; i++) {
1477 if(this->
data[i]==0.) nZero++;
1482 return double(this->
size()-nZero)/double(this->
size());
1486 template<
class DataType_t>
1492 double tsRate = this->
rate();
1496 size_t il = size_t(2.*M*
getlow()/tsRate);
1497 size_t ih = size_t(2.*M*
gethigh()/tsRate+0.5);
1499 double ratio = double(this->
size());
1503 cout<<
"WSeries::significance(): invalid low and high: ";
1504 cout<<
"low = "<<il<<
" high = "<<ih<<endl;
1513 if(i>=il && i<=ih)
continue;
1521 for(j=0; j<
k; j++) p[j*m] = 0;
1523 ratio /= this->
size();
1529 size_t n = size_t(
fabs(T)*tsRate/S.
stride()/ratio+0.1);
1530 if(n<1) n = S.
size();
1539 nB = size_t(
bpp*nS*ratio);
1541 if(!nS || !nB || tsRate<=0. || m*S.
size()!=this->
size()) {
1542 cout<<
"WSeries::significance() error: invalid parameters"<<endl;
1546 l = (S.
size()-k*
n)*m;
1551 pp = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1561 for(j=0; j<nS; j++) {
1562 if(*p == 0.) {p++;
continue;}
1563 *p = (DataType_t)
fabs(
double(*p));
1568 if(nP>2) this->
waveSort(pp,0,nP-1);
1570 for(j=0; j<nP; j++) {
1571 if(!i && l && pp[j]>=this->
data+l)
continue;
1572 *pp[
j] = nP<nB ? (DataType_t)
log(
double(nP)/(nP-
j)) :
1573 (DataType_t)
log(
double(nB)/(nP-
j));
1580 p = this->
data+i*nS+
l;
1585 return double(nZero)/ratio/this->
size();
1589 template<
class DataType_t>
1593 DataType_t*
px=NULL;
1608 size_t N = S.
size();
1616 nB = size_t(
bpp*nS);
1621 if(!nS || !nB || this->
rate()<=0. || m*S.
size()!=this->
size()) {
1622 cout<<
"WSeries::significance() error: invalid WSeries"<<endl;
1626 pp = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1627 xx = (DataType_t *)malloc(nS*
sizeof(DataType_t));
1628 qq = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1629 yy = (DataType_t *)malloc(nS*
sizeof(DataType_t));
1632 for(j=0; j<nS; j++){
1645 aL = *pp[nL]; aR = *pp[nR];
1647 for(j=0; j<nL; j++) yy[j] = (DataType_t)
fabs(*pp[j] - aL);
1648 for(j=nR; j<nS; j++) yy[j+nL-nR] = (DataType_t)
fabs(*pp[j] - aR);
1652 for(j=0; j<nB; j++) {
1654 if(index>nL) index+=nR-nL;
1656 if(next != index/m)
continue;
1657 this->
data[index-next*m+i*
m] = (DataType_t)
log(
double(nB)/(nB-
j));
1663 for(j=0; j<
m; j++) { *(px++) = *p; *p++ = 0;}
1668 if(next>2*n) next = 0;
1669 if(last>2*n) last = 0;
1678 return double(nBlack)/double(this->
size());
1682 template<
class DataType_t>
1695 double tsRate = this->
rate();
1704 size_t il = size_t(2.*M*
getlow()/tsRate);
1705 size_t ih = size_t(2.*M*
gethigh()/tsRate+0.5);
1709 cout<<
"WSeries::significance(): invalid low and high: ";
1710 cout<<
"low = "<<il<<
" high = "<<ih<<endl;
1717 for(j=0; j<il; j++){ this->
getLayer(wa,j); wa=1234567891.; this->
putLayer(wa,j); }
1718 for(j=ih; j<
M; j++){ this->
getLayer(wa,j); wa=1234567891.; this->
putLayer(wa,j); }
1724 size_t N = S.
size();
1725 size_t k = size_t(t*this->
wrate());
1726 size_t n = size_t(T*this->
wrate()/2.);
1728 if(t<=0. || k<1) k = 1;
1729 if(T<=0. || n<1) n = 1;
1732 size_t nW = (2*n+
k)*M;
1738 nB = size_t(
bpp*nS);
1743 if(!nS || !nB || this->
rate()<=0. || M*S.
size()!=this->
size()) {
1744 cout<<
"WSeries::significance() error: invalid WSeries"<<endl;
1748 pp = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1749 px = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1750 py = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1751 xx = (DataType_t *)malloc(nS*
sizeof(DataType_t));
1752 yy = (DataType_t *)malloc(nS*
sizeof(DataType_t));
1756 for(i=0; i<nW; i++){
1757 if(*p != 1234567891.){
1770 cout<<
"wseries::rSignificance() error 1 - illegal sample count"<<endl;
1774 for(i=0; i<
N; i+=
k){
1778 aL = *px[nL]; aR = *px[nR];
1780 for(j=0; j<nL; j++) yy[j] = (DataType_t)
fabs(*px[j] - aL);
1781 for(j=nR; j<nS; j++) yy[j+nL-nR] = (DataType_t)
fabs(*px[j] - aR);
1783 if(nB != nS-nR+nL) {
1784 cout<<
"wseries::rSignificance: nB="<<nB<<
", N="<<nS-nR+nL<<endl;
1790 for(j=0; j<nB; j++) {
1792 if(index>nL) index+=nR-nL;
1796 if(index>=i*M && index<(i+k)*M) {
1797 if(this->data[index]!=0) {
1798 cout<<
"WSeries::rSignificance error: "<<this->data[
index]<<endl;
1800 this->data[
index] = DataType_t(
log(
double(nB)/(nB-j)));
1805 for(l=i; l<i+
k; l++){
1808 for(j=0; j<
M; j++) {
1809 if(*p != 1234567891.) { xx[J] = *p; pp[J++]=p; }
1814 cout<<
"wseries::rSignificance() error 2 - illegal sample count"<<endl;
1820 if(next==2*n+k) next = 0;
1821 if(last==2*n+k) last = 0;
1831 return double(nBlack)/double(this->
size());
1836 template<
class DataType_t>
1862 cout<<
"WSeries::significance(): invalid low and high: ";
1863 cout<<
"low = "<<il<<
" high = "<<ih<<endl;
1870 for(j=0; j<il; j++){ this->
getLayer(wa,j); wa=1234567891.; this->
putLayer(wa,j); }
1871 for(j=ih; j<
M; j++){ this->
getLayer(wa,j); wa=1234567891.; this->
putLayer(wa,j); }
1877 size_t N = S.
size();
1878 size_t k = size_t(t*this->
wrate());
1879 size_t n = size_t(T*this->
wrate()/2.);
1881 if(t<=0. || k<1) k = 1;
1882 if(T<=0. || n<1) n = 1;
1885 size_t nW = (2*n+
k)*M;
1891 nB = size_t(
bpp*nS);
1896 if(!nS || !nB || this->
rate()<=0. || M*S.
size()!=this->
size()) {
1897 cout<<
"WSeries::gSignificance() error: invalid WSeries"<<endl;
1901 pp = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1902 px = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1903 py = (DataType_t **)malloc(nS*
sizeof(DataType_t*));
1904 xx = (DataType_t *)malloc(nS*
sizeof(DataType_t));
1905 yy = (DataType_t *)malloc(nS*
sizeof(DataType_t));
1909 for(i=0; i<nW; i++){
1910 if(*p != 1234567891.){
1923 cout<<
"wseries::gSignificance() error 1 - illegal sample count"<<endl;
1927 for(i=0; i<
N; i+=
k){
1931 aL = *px[nL]; aR = *px[nR];
1933 for(j=0; j<nL; j++) yy[j] = (DataType_t)
fabs(*px[j]);
1934 for(j=nR; j<nS; j++) yy[j+nL-nR] = (DataType_t)
fabs(*px[j]);
1936 if(nB != nS-nR+nL) {
1937 cout<<
"wseries::gSignificance: nB="<<nB<<
", N="<<nS-nR+nL<<endl;
1943 for(j=0; j<nB; j++) {
1945 if(index>nL) index+=nR-nL;
1947 *(pp[
index]) = pow(*py[j]+1.11/2,2)/2./1.07 +
log(
bpp);
1951 for(l=i; l<i+
k; l++){
1954 for(j=0; j<
M; j++) {
1955 if(*p != 1234567891.) { xx[J] = *p; pp[J++]=p; }
1960 cout<<
"wseries::gSignificance() error 2 - illegal sample count"<<endl;
1966 if(next==2*n+k) next = 0;
1967 if(last==2*n+k) last = 0;
1977 return double(nBlack)/double(this->
size());
1982 template<
class DataType_t>
2003 pc = ∾ pp = ≈ pm = p = NULL;
2008 for(k=1; k<=max_layer; k++){
2013 if(pp!=NULL) mp = pp->
size()/pc->
size();
2014 if(pm!=NULL) mm = pc->
size()/pm->
size();
2018 for(i=0; i<=
n; i++) {
2021 if(pc->
data[i] == 0.)
continue;
2022 if(pc->
data[i] > 9.7) cout<<
"pixclean: "<<pc->
data[
i]<<endl;
2024 if(i>0 && pc->
data[i-1]!=0.)
continue;
2025 if(i<n && pc->
data[i+1]!=0.)
continue;
2035 for(j=nm; j<
np; j++) {
2036 if(pp->
data[j] != 0) {
2052 for(j=nm; j<
np; j++) {
2053 if(pm->
data[j] != 0) {
2061 if(pc->
data[i]<S) {a.
data[
i]=0;
event--;}
2071 p = pm==NULL ? &am :
pm;
2077 return double(event)/this->
size();
2081 template<
class DataType_t>
2086 register DataType_t* P=NULL;
2087 register DataType_t** pp;
2091 size_t nS, kS, mS, nL, nR;
2096 if((f>=1. ||
bpp!=1.) && mode) {
2097 cout<<
"WSeries percentile(): invalid bpp: "<<
bpp<<
" fraction="<<f<<endl;
2102 if(pin) *
this = *pin;
2108 size_t n0 = S.
size();
2109 if(n0) pp = (DataType_t **)malloc(n0*
sizeof(DataType_t*));
2123 nL = size_t(f*nS/2.+0.5);
2126 if(nL<2 || nR>nS-2) {
2127 cout<<
"WSeries::percentile() error: too short wavelet layer"<<endl;
2132 pp = (DataType_t **)realloc(pp,nS*
sizeof(DataType_t*));
2136 for(j=0; j<nS; j++) pp[j] = p + j*kS;
2140 aL = double(*pp[nL-1]); aR = double(*pp[nR]);
2142 for(j=0; j<nS; j++){
2143 P = pp[
j]; A = double(*P);
2148 if(j<nL) *P = DataType_t(
fabs(A - aL));
2149 else if(j>nR) *P = DataType_t(
fabs(A - aR));
2150 else { *P = 0; nZero++; }
2152 if(mode == -1)
continue;
2153 if(pin) pin->
data[mS+P-p] = *P;
2154 if(j>nL && j<nR)
continue;
2155 a.
data[(P-p)/kS] = *P;
2157 if(j>=nR) pp[nL+j-nR] = P;
2160 if(mode == -1)
continue;
2165 if(abs(mode)!=1) b =
a;
2167 for(j=0; j<nL; j++){
2170 x =
log(
double(nL)/(nL-j));
2171 *pp[
j] = mode==1 ? DataType_t(x) : 0;
2172 if(mode>1) a.
data[
r]=DataType_t(x);
2175 if(abs(mode)==1)
continue;
2179 for(j=0; j<nL; j++){
2181 do{ r =
int(nS*drand48()-0.1);}
2182 while(p[r*kS] != 0);
2183 p[r*kS] = a.
data[(P-p)/kS];
2184 if(pin) pin->
data[mS+r*kS] = b.
data[(P-p)/kS];
2192 if(drand48() > f) { this->
data[
i] = 0; nZero++; }
2198 if(this->
data[i]==0) nZero++;
2202 return double(this->
size()-nZero)/double(this->
size());
2206 template<
class DataType_t>
2217 double tsRate = this->
rate();
2219 double tleft, trigh;
2222 double cstep = 1./a.
rate();
2223 double sTart = this->
start();
2224 double sTop = this->
start()+this->
size()/tsRate;
2244 for(i=0; i<a.
size(); i++) {
2245 if(a.
start()+i/a.
rate() < sTart)
continue;
2254 for(i=0; i<g.
size(); i++) {
2255 if(g.
start()+i/g.
rate() < sTart)
continue;
2269 cout<<
"WSeries<DataType_t>::calibrate() no calibration data\n";
2282 righ += tsRate/2./S.
stride();
2283 if(righ > n*df)
break;
2288 while(left+count*df < righ){
2293 count++; pR++; pC++;
2301 for(i=0; i<alp.
size(); i++){
2303 if(alp.
data[i]<=0. || gam.
data[i]<=0.) {
2304 cout<<
"WSeries<DataType_t>::calibrate() zero alpha error\n";
2311 reH = 1.+(reH-1.)*gam.
data[
i];
2313 x.data[
i] = sqrt(reH*reH+imH*imH);
2327 sTart = alp.
start();
2328 sTop = alp.
start()+(alp.
size()-1)*cstep;
2331 trigh = sTart+cstep;
2336 if(t <= sTart) *p *= (DataType_t)
x.data[0];
2337 else if(t >= sTop) *p *= (DataType_t)
x.data[alp.
size()-1];
2339 if(t>trigh) { tleft=trigh; trigh+=cstep; m++; }
2340 c = (t-tleft)/cstep;
2341 *p *= DataType_t(
x.data[m]*(1-c) +
x.data[m+1]*c);
2351 template<
class DataType_t>
2359 template <
class DataType_t>
2365 if (R__b.IsReading()) {
2366 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v) { }
2378 if(!bWWS) m_WaveType=-1;
2380 switch(m_WaveType) {
2420 R__b.SetByteCount(R__c, kTRUE);
2426 #define CLASS_INSTANTIATION(class_) template class WSeries< class_ >; 2431 #undef CLASS_INSTANTIATION wavearray< double > t(hp.size())
void mul(WSeries< DataType_t > &)
virtual void resize(unsigned int)
double gammaCL(double x, double n)
virtual double stop() const
static double g(double e)
virtual void rate(double r)
wavearray< double > a(hp.size())
virtual double percentile(double=0., int=0, WSeries< DataType_t > *=NULL)
param: f - black pixel fraction param: m - mode options: f = 0 - returns black pixel occupancy m = 1 ...
virtual void edge(double s)
virtual WSeries< float > variability(double=0., double=-1., double=-1.)
param: first - time window to calculate normalization constants second - low frequency boundary for c...
virtual WSeries< DataType_t > & operator+=(WSeries< DataType_t > &)
void bandpass(wavearray< DataType_t > &ts, double flow, double fhigh, int n=-1)
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1) *itime+ifreq;double time=itime *dT;double freq=(ifreq >0) ? ifreq *dF :dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
wavearray< DataType_t > & operator=(const wavearray< DataType_t > &)
virtual void setSlice(const std::slice &s)
virtual double rSignificance(double, double=1., double=0.)
param: T - sliding window duration in seconds param: f - black pixel fraction param: t - sliding step...
std::slice getSlice(double n)
virtual Wavelet * Clone() const
return: Wavelet* - duplicate of *this, allocated on heap
virtual wavearray< DataType_t > & operator*=(wavearray< DataType_t > &)
virtual void start(double s)
virtual WSeries< DataType_t > & operator*=(WSeries< DataType_t > &)
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
cout<< "Selected Pixels : "<< nPix<< endl;wc.cluster(1, 1);SSeries< double > ss
virtual double significance(double, double=1.)
param: n - sub-interval duration in seconds param: f - black pixel fraction options: f = 0 - returns ...
fprintf(stdout,"start=%f duration=%f rate=%f\, x.start(), x.size()/x.rate(), x.rate())
void setWavelet(const Wavelet &w)
virtual void waveSplit(DataType_t **pp, size_t l, size_t r, size_t m) const
virtual size_t size() const
size_t wavecount(double x, int n=0)
virtual double rate() const
virtual double gSignificance(double, double=1., double=0.)
param: T - sliding window duration in seconds param: f - black pixel fraction param: t - sliding step...
virtual wavearray< double > filter(size_t)
param: n - number of decomposition steps algorithm: 1) do forward wavelet transform with n decomposit...
double maxEnergy(wavearray< DataType_t > &ts, Wavelet &w, double=0, int=1, int=0, TH1F *=NULL)
virtual WSeries< DataType_t > & operator-=(WSeries< DataType_t > &)
virtual double fraction(double=0., double=0., int=0)
param: t - sub interval duration. If can not divide on integer
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
TIter next(twave->GetListOfBranches())
#define CLASS_INSTANTIATION(class_)
virtual double start() const
virtual double coincidence(WSeries< DataType_t > &, int=0, int=0, double=0.)
param: WSeries object used for coincidence param: coincidence window in seconds return pixel occupanc...
virtual wavearray< DataType_t > & operator+=(wavearray< DataType_t > &)
virtual size_t limit() const
virtual double edge() const
virtual std::slice getSlice() const
virtual WSeries< DataType_t > & operator[](const std::slice &)
void wavescan(WSeries< DataType_t > **, int, TH1F *=NULL)
virtual void lprFilter(wavearray< double > &)
virtual std::slice getSlice(const double)
wavearray< double > ts(N)
virtual double mean() const
virtual void resample(double, int=6)
virtual void stop(double s)
virtual wavearray< DataType_t > & operator-=(wavearray< DataType_t > &)
double fabs(const Complex &x)
void print()
param: int n if n<0, zero pixels defined in mask (regression) if n>=0, zero all pixels except ones de...
virtual void spesla(double, double, double=0.)
double Gamma2Gauss(TH1F *=NULL)
virtual void waveSort(DataType_t **pp, size_t l=0, size_t r=0) const
virtual double Coincidence(WSeries< DataType_t > &, double=0., double=0.)
param: WSeries object used for coincidence param: coincidence window in seconds param: threshold on s...
virtual void lprFilter(double, int=0, double=0., double=0.)
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
strcpy(RunLabel, RUN_LABEL)
Meyer< double > S(1024, 2)
virtual DataType_t max() const
virtual void median(double t, bool norm=false)
WSeries< DataType_t > & operator=(const wavearray< DataType_t > &)
virtual double pixclean(double=0.)
param: S - threshold on pixel significance return pixel occupancy.
virtual wavearray< double > white(double, int=0, double=0., double=0.) const
WaveDWT< DataType_t > * pWavelet
double wdmPacket(int pattern, char opt='L', TH1F *=NULL)
virtual void resize(unsigned int)
virtual double median(size_t=0, size_t=0) const
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
void putLayer(wavearray< DataType_t > &, double n)
param: n - layer number
virtual void Dump(const char *, int=0)
virtual double rsignificance(size_t=0, double=1.)
param: n - sub-interval duration in domain units param: f - black pixel fraction options: f = 0 - ret...
virtual WSeries< double > calibrate(size_t, double, d_complex *, d_complex *, wavearray< double > &, wavearray< double > &, size_t ch=0)
param: number of samples in calibration arrays R & C param: frequency resolution param: pointer to re...
void cpf(const wavearray< DataType_t > &, int=0, int=0, int=0)
virtual WSeries< double > white(double, int, double=0., double=0.)
what it does: each wavelet layer is devided into k intervals.