Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cluster.cc
Go to the documentation of this file.
1 //---------------------------------------------------
2 // WAT cluster class
3 // S. Klimenko, University of Florida
4 //---------------------------------------------------
5 
6 #define WAVECLUSTER_CC
7 #include <time.h>
8 #include <iostream>
9 #include <stdexcept>
10 #include "cluster.hh"
11 
12 using namespace std;
13 
14 // sort wavepixel objects on time
15 int compare_pix(const void *x, const void *y){
16  wavepixel* p = *((wavepixel**)x);
17  wavepixel* q = *((wavepixel**)y);
18  double a = (p->time+0.5)/p->rate - (q->time+0.5)/q->rate;
19  if(a > 0) return 1;
20  if(a < 0) return -1;
21  return 0;
22 }
23 
24 // constructors
25 
27 {
28  pList.clear();
29  sCuts.clear();
30  cList.clear();
31  cRate.clear();
32  start = 0.;
33  stop = 0.;
34  shift = 0.;
35  bpp = 0.;
36  low = 0.;
37  high = 0.;
38  ifo = 0;
39  run = 0;
40 }
41 
43 {
44  *this = value;
45 }
46 
47 
49 {
50  init(w,halo);
51 }
52 
53 // destructor
54 
56 
57 //: operator =
58 
60 {
61  pList.clear();
62  sCuts.clear();
63  cList.clear();
64  cRate.clear();
65  pList = value.pList;
66  sCuts = value.sCuts;
67  cList = value.cList;
68  cRate = value.cRate;
69  nRMS = value.nRMS;
70  start = value.start;
71  stop = value.stop;
72  shift = value.shift;
73  bpp = value.bpp;
74  low = value.low;
75  high = value.high;
76  ifo = value.ifo;
77  run = value.run;
78  return *this;
79 }
80 
81 
82 
83 //**************************************************************************
84 // initialize wavecluster from WSeries (binary tree)
85 //**************************************************************************
86 size_t wavecluster::init(WSeries<double>& w, bool halo)
87 {
88  pList.clear();
89  sCuts.clear();
90  cList.clear();
91  cRate.clear();
92  bpp=0.; start=0.; stop=0., ifo=0; shift=0.;
93 
94  if(!w.pWavelet->BinaryTree()) return 0;
95 
96  start = w.start(); // set start time
97  stop = start+w.size()/w.wavearray<double>::rate(); // set stop time (end of time interval)
98  bpp = w.getbpp();
99  low = w.getlow();
100  high = w.gethigh();
101 
102  size_t i,j,k;
103 
104  size_t ni = w.maxLayer()+1;
105  size_t nj = w.size()/ni;
106  size_t n = ni-1;
107  size_t m = nj-1;
108  size_t nl = size_t(2.*low*ni/w.wavearray<double>::rate()); // low frequency boundary index
109  size_t nh = size_t(2.*high*ni/w.wavearray<double>::rate()); // high frequency boundary index
110 
111  if(nh>=ni) nh = ni-1;
112 
113  int L;
114  int* TF = new int[ni*nj];
115  int* p = NULL;
116  int* q = NULL;
117 
119 
120  k = 0;
121  for(i=0; i<ni; i++){
122  p = TF+i*nj;
123  w.getLayer(a,i);
124 
125  if(nj!=a.size())
126  cout<<"wavecluster::constructor() size error: "<<nj<<endl;
127 
128  for(j=0; j<nj; j++){
129  if(a.data[j]==0. || i<nl || i>nh) p[j]=0;
130  else {p[j]=-1; k++;}
131  }
132  }
133  if(!k) { delete [] TF; return 0; }
134 
135 /**************************************/
136 /* fill in the pixel list */
137 /**************************************/
138 
139  wavepixel pix;
140  pix.amplitude.clear(); // clear link pixels amplitudes
141  pix.neighbors.clear(); // clear link vector for neighbors
142  pix.clusterID = 0; // initialize cluster ID
143  L = 1<<w.getLevel(); // number of layers
144  pix.rate = float(w.wavearray<double>::rate()/L); // pixel rate
145 
146  size_t &f = pix.frequency;
147  size_t &t = pix.time;
148  size_t F,T;
149 
150  L = 0;
151 
152  for(i=0; i<ni; i++)
153  {
154  p = TF + i*nj;
155 
156  for(j=0; j<nj; j++)
157  {
158  if(p[j] != -1) continue;
159 
160  t = j; f = i; // time index; frequency index;
161  pix.core = true; // core pixel
162  pList.push_back(pix); // save pixel
163  p[j] = ++L; // save pixel index (Fortran indexing)
164 
165  if(!halo) continue;
166 
167 // include halo
168 
169  pix.core = false; // halo pixel
170 
171  F = i<n ? i+1 : i;
172  T = j<m ? j+1 : j;
173 
174  for(f = i>0 ? i-1 : i; f<=F; f++) {
175  q = TF + f*nj;
176  for(t = j>0 ? j-1 : j; t<=T; t++) {
177  if(!q[t]) {pList.push_back(pix); q[t] = ++L;}
178  }
179  }
180  }
181  }
182 
183 // set amplitude and neighbours
184 
185  std::vector<int>* pN;
186  size_t nL = pList.size();
187  slice S;
188 
189  for(k=0; k<nL; k++)
190  {
191  i = pList[k].frequency;
192  j = pList[k].time;
193  if(int(i)>w.maxLayer()) cout<<"wavecluster::constructor() maxLayer error: "<<i<<endl;
194  S = w.getSlice(i);
195 
196 // set pixel amplitude
197 
198  pList[k].amplitude.push_back(w.data[S.start()+S.stride()*j]);
199 
200 // set neighbors
201 
202  pN = &(pList[k].neighbors);
203 
204  F = i<n ? i+1 : i;
205  T = j<m ? j+1 : j;
206 
207  for(f = i>0 ? i-1 : i; f<=F; f++) {
208  q = TF + f*nj;
209  for(t = j>0 ? j-1 : j; t<=T; t++) {
210  L = (f==i && t==j) ? 0 : q[t];
211  if(L) pN->push_back(L-1);
212  }
213  }
214  }
215 
216  delete [] TF;
217  return pList.size();
218 }
219 
220 
221 //**************************************************************************
222 // cluster analysis
223 //**************************************************************************
225 {
226  size_t volume;
227  size_t i,m;
228  vector<int> refMask;
229  size_t nCluster = 0;
230  size_t n = pList.size();
231 
232  if(!pList.size()) return 0;
233 
234  cList.clear();
235  sCuts.clear();
236  cRate.clear();
237 
238  for(i=0; i<n; i++){
239  if(pList[i].clusterID) continue;
240  pList[i].clusterID = ++nCluster;
241  volume = cluster(&pList[i]);
242  refMask.clear();
243  cRate.push_back(refMask);
244  refMask.resize(volume);
245  cList.push_back(refMask);
246  sCuts.push_back(false);
247  }
248 
249  list<vector_int>::iterator it;
250  nCluster = 0;
251  if(!cList.size()) return 0;
252 
253  for(it=cList.begin(); it != cList.end(); it++) {
254  nCluster++;
255 
256  m = 0;
257  for(i=0; i<n; i++) {
258  if(pList[i].clusterID == nCluster) (*it)[m++] = i;
259  }
260 
261  if(it->size() != m) {
262  cout<<"cluster::cluster() size mismatch error: ";
263  cout<<m<<" size="<<it->size()<<" "<<nCluster<<endl;
264  }
265  if(m==1 && !pList[(*it)[0]].core) {
266  cout<<"cluster::cluster() : empty cluster. \n";
267  cout<<pList[(*it)[0]].time<<" "<<pList[(*it)[0]].frequency<<endl;
268  }
269  }
270  return nCluster;
271 }
272 
274 {
275  size_t volume = 1;
276  int i = p->neighbors.size();
277  wavepixel* q;
278 
279  while(--i >= 0){
280  q = &pList[p->neighbors[i]];
281  if(!q->clusterID){
282  q->clusterID = p->clusterID;
283  volume += cluster(q);
284  }
285  }
286  return volume;
287 }
288 
289 
290 //**************************************************************************
291 // remove halo pixels from pixel list
292 //**************************************************************************
293 size_t wavecluster::cleanhalo(bool keepid)
294 {
295  if(!pList.size() || !cList.size()) return 0;
296 
297  size_t i;
298  size_t cid = 0; // new cluster ID
299  size_t pid = 0; // new pixel ID
300 
301  wavepixel* pix = NULL;
302  list<vector_int>::iterator it;
303  std::vector<int> id;
304 
305  wavecluster x(*this);
306 
307  pList.clear();
308  sCuts.clear();
309  cList.clear();
310 
311  for(it=x.cList.begin(); it != x.cList.end(); it++) { // loop over clusters
312 
313  pix = &(x.pList[((*it)[0])]);
314  if(x.sCuts[pix->clusterID-1]) continue; // apply selection cuts
315 
316  cid++;
317  id.clear();
318  for(i=0; i<it->size(); i++) { // loop over pixels in the cluster
319  pix = &(x.pList[((*it)[i])]);
320  if(pix->core) {
321  pix->clusterID = keepid ? cid : 0;
322  pix->neighbors.clear();
323  id.push_back(pid++);
324  pList.push_back(*pix); // fill pixel list
325  }
326  }
327 
328  i = id.size();
329  if(!i) cout<<"wavecluster::cleanhalo() error: empty cluster.";
330 
331  if(keepid) {
332  cList.push_back(id); // fill cluster list
333  sCuts.push_back(false); // fill selection cuts
334  }
335 
336  if(i<2) continue;
337 
338  while(--i > 0) { // set neighbors
339  pList[id[i-1]].neighbors.push_back(id[i]);
340  pList[id[i]].neighbors.push_back(id[i-1]);
341  }
342 
343 
344  }
345  return pList.size();
346 }
347 
348 //**************************************************************************
349 // save wavelet amplitudes in cluster structure
350 //**************************************************************************
352 {
353  size_t j,k,m;
354  slice S;
355  size_t N = w.size()-1;
356  size_t M = pList.size();
357  size_t max_layer = w.maxLayer();
358  wavepixel* p = NULL; // pointer to pixel structure
359  double a;
360  float rate;
361  size_t ofFSet;
362 
363  if(!M) return 0;
364 
365  offset = fabs(offset);
366  if(fabs(w.start()+offset-start)>1.e-12) {
367  printf("wavecluster::apush: start time mismatch: dT=%16.13f",start-w.start());
368  return 0;
369  }
370 
371  for(k=0; k<M; k++){
372  p = &(pList[k]);
373 
374  if(p->frequency > max_layer) {
375  p->amplitude.push_back(0.);
376  continue;
377  }
378 
379  S = w.getSlice(p->frequency);
380  m = S.stride();
381 
382  rate = w.wavearray<double>::rate()/m; // rate at this layer
383  ofFSet = size_t(offset*w.wavearray<double>::rate()+0.5); // number of offset samples
384 
385  if(int(p->rate+0.1) != int(rate+0.1)) {
386  p->amplitude.push_back(0.);
387  continue;
388  }
389 
390  if((ofFSet/m)*m != ofFSet)
391  cout<<"wavecluster::apush(): illegal offset "<<ofFSet<<" m="<<m<<"\n";
392 
393  j = S.start()+ofFSet+S.stride()*p->time; // pixel index in cluster
394  a = j>N ? 0. : w.data[j];
395  p->amplitude.push_back(a);
396  }
397 
398  return pList[0].amplitude.size();
399 }
400 
401 //**************************************************************************
402 // append input cluster list
403 //**************************************************************************
405 {
406  size_t i,k,n;
407  size_t in = w.pList.size();
408  size_t on = pList.size();
409  size_t im = w.cList.size();
410  size_t om = cList.size();
411 
412  if(!in) { return on; }
413  if(!on) { *this = w; return in; }
414 
415  wavepixel* p = NULL; // pointer to pixel structure
416  std::vector<int>* v;
417 
418  if((w.start!=start) || (w.ifo!=ifo) || (w.shift!=shift)) {
419  printf("\n wavecluster::append(): cluster type mismatch");
420  printf("%f / %f, %f / %f, %d / %d\n",w.start,start,w.shift,shift,w.ifo,ifo);
421 
422  return on;
423  }
424 
425  if(im && !om) { // clear in clusters
426  w.sCuts.clear(); w.cList.clear(); im=0;
427  for(i=0; i<in; i++) w.pList[i].clusterID=0;
428  }
429  if(!im && om) { // clear out clusters
430  sCuts.clear(); cList.clear(); om=0;
431  for(i=0; i<on; i++) pList[i].clusterID=0;
432  }
433 
434 
435  for(i=0; i<in; i++){
436  p = &(w.pList[i]);
437  v = &(p->neighbors);
438  n = v->size();
439  for(k=0; k<n; k++) (*v)[k] += on; // new neighbors pointers
440  p->clusterID += om; // update cluster ID
441  pList.push_back(*p);
442  }
443 
444  if(!im) return pList.size();
445 
446  list<vector_int>::iterator it;
447  n = 0;
448 
449  for(it=w.cList.begin(); it != w.cList.end(); it++) {
450 
451  for(i=0; i<it->size(); i++) { // loop over pixels in the cluster
452  (*it)[i] += on; // update pixel index
453  }
454 
455  cList.push_back(*it);
456  sCuts.push_back(w.sCuts[n++]);
457  }
458 
459  return pList.size();
460 }
461 
462 //**************************************************************************
463 // merge clusters in the lists
464 //**************************************************************************
465 size_t wavecluster::merge(double S)
466 {
467  size_t i,j,k,m;
468  size_t n = pList.size();
469  int l;
470 
471  if(!n) return 0;
472 
473  wavepixel* p = NULL; // pointer to pixel structure
474  wavepixel* q = NULL; // pointer to pixel structure
475  std::vector<int>* v;
476  float eps;
477  double E;
478  bool insert;
479  double ptime, pfreq;
480  double qtime, qfreq;
481 
482  cRate.clear();
483  wavepixel** pp = (wavepixel**)malloc(n*sizeof(wavepixel*));
484 
485 // sort pixels
486 
487  for(i=0; i<n; i++) { pp[i] = &(pList[i]); pp[i]->index = i; }
488  qsort(pp, n, sizeof(wavepixel*), &compare_pix); // sorted time
489 
490 
491 // update neighbors
492 
493  for(i=0; i<n; i++) {
494  p = pp[i];
495  if(!p->core) continue;
496  ptime = (p->time+0.5)/p->rate;
497  pfreq = (p->frequency+0.5)*p->rate;
498 
499  for(j=i+1; j<n; j++){
500  q = pp[j];
501 
502  eps = 0.55/p->rate + 0.55/q->rate;
503  qtime = (q->time+0.5)/q->rate;
504 
505  if(qtime<ptime) cout<<"wavecluster::merge() error"<<endl;
506 
507  if(qtime-ptime > 1.) break;
508  if(qtime-ptime > eps) continue;
509  if(!q->core || p->rate==q->rate) continue;
510  if(!(p->rate==2*q->rate || q->rate==2*p->rate)) continue;
511 
512  eps = 0.55*(p->rate+q->rate);
513  qfreq = (q->frequency+0.5)*q->rate;
514  if(fabs(pfreq-qfreq) > eps) continue;
515 
516 // insert in p
517 
518  l = q->index;
519  insert = true;
520  v = &(p->neighbors);
521  m = v->size();
522  for(k=0; k<m; k++) {
523  if((*v)[k] == l) {insert=false; break;}
524  }
525  if(insert) v->push_back(l);
526 
527 // insert in q
528 
529  l = p->index;
530  insert = true;
531  v = &(q->neighbors);
532  m = v->size();
533  for(k=0; k<m; k++) {
534  if((*v)[k] == l) {insert=false; break;}
535  }
536  if(insert) v->push_back(l);
537 
538  }
539  }
540  free(pp);
541 
542 //***************
543  cluster();
544 //***************
545 
546  std::list<vector_int>::iterator it;
547  wavepixel* pix = NULL;
548  std::vector<int> rate;
549  std::vector<int> temp;
550  std::vector<int> sIZe;
551  std::vector<bool> cuts;
552  std::vector<double> ampl;
553  std::vector<double> amax;
554  std::vector<double> sigf;
555  std::vector<double>* pa;
556  double a;
557  bool cut;
558  size_t ID;
559  size_t max = 0;
560  size_t min = 0;
561  size_t count=0;
562 
563  for(it=cList.begin(); it != cList.end(); it++) {
564  k = it->size();
565  if(!k) cout<<"wavecluster::merge() error: empty cluster.\n";
566 
567 // fill cluster statistics
568 
569  m = 0; E = 0;
570  rate.clear();
571  ampl.clear();
572  amax.clear();
573  sigf.clear();
574  cuts.clear();
575  sIZe.clear();
576  temp.clear();
577 
578  ID = pList[((*it)[0])].clusterID;
579 
580  for(i=0; i<k; i++) {
581  pix = &(pList[((*it)[i])]);
582  if(!pix->core) continue;
583  pa = &(pix->amplitude);
584  a = pa->size()>1 ? pow((*pa)[1],2) : (*pa)[0];
585 
586  insert = true;
587  for(j=0; j<rate.size(); j++) {
588  if(rate[j] == int(pix->rate+0.1)) {
589  insert=false;
590  ampl[j] += a;
591  sIZe[j] += 1;
592  sigf[j] += (*pa)[0];
593  if(a>amax[j]) amax[j] = a;
594  }
595  }
596 
597  if(insert) {
598  rate.push_back(int(pix->rate+0.1));
599  ampl.push_back(a);
600  amax.push_back(a);
601  sIZe.push_back(1);
602  cuts.push_back(true);
603  sigf.push_back((*pa)[0]);
604  }
605 
606  m++; E += (*pa)[0];
607 
608  if(ID != pix->clusterID)
609  cout<<"wavecluster::merge() error: cluster ID mismatch.\n";
610  }
611 
612 // cut off single level clusters
613 
614  if(!rate.size()) { cout<<"k="<<k<<" id="<<ID<<endl; continue; }
615  if(rate.size()<2 || m<=2){ sCuts[ID-1] = true; continue; }
616 // sCuts[ID-1] = (gammaCL(E,m) > S-log(m-1.)) ? false : true;
617  sCuts[ID-1] = (gammaCL(E,m) > S) ? false : true;
618 
619 // coincidence between levels
620  cut = true;
621  for(i=0; i<rate.size(); i++) {
622  for(j=0; j<rate.size(); j++) {
623  if(rate[i]/2==rate[j] || rate[j]/2==rate[i]) {
624  cuts[i] = cuts[j] = cut = false;
625  }
626  }
627  }
628  if(cut || sCuts[ID-1]) { sCuts[ID-1] = true; continue; }
629 
630 // select optimal resolution
631 
632  a = -1.e99;
633  for(j=0; j<rate.size(); j++) { // select max excess power
634  if(ampl[j]-sIZe[j]>a && !cuts[j]) {max=j; a=ampl[j]-sIZe[j];}
635  }
636 
637  a = -1.e99;
638  for(j=0; j<rate.size(); j++) {
639  if(max==j) continue;
640  if(ampl[j]-sIZe[j]>a && !cuts[j]) {min=j; a=ampl[j]-sIZe[j];}
641  }
642 
643  temp.push_back(rate[max]);
644  temp.push_back(rate[min]);
645  cRate[ID-1] = temp;
646  count++;
647 
648  }
649 
650  return count;
651 }
652 
653 
654 //**************************************************************************
655 // coincidence between two clusters lists
656 //**************************************************************************
658 {
659  size_t i,j,k;
660  size_t ik = w.asize();
661  size_t ok = asize();
662 
663  if(!ik || !ok) return 0;
664 
665  k = ok>1 ? ik : 1;
666  k = k>1 ? 2 : 1;
667 
668  wavearray<float> tin = w.get((char*)"time",k); // get in time
669  wavearray<float> tou = get((char*)"time",k); // get out time
670  wavearray<float> rin = w.get((char*)"rate",0); // get in rate
671  wavearray<float> rou = get((char*)"rate",0); // get out rate
672  wavearray<float> cid = get((char*)"ID",0); // get out cluster ID
673 
674  size_t in = tin.size();
675  size_t on = tou.size();
676  double window;
677  bool cut;
678 
679  k = 0;
680 
681  for(i=0; i<on; i++){
682  cut = true;
683  for(j=0; j<in; j++){
684  window = 0.5/rou[i]+0.5/rin[j];
685  if(window<T) window = T;
686  if(fabs(tou.data[i]-tin.data[j])<window) { cut=false; break; }
687  }
688  if(cut) sCuts[int(cid[i]-0.5)] = true;
689  else k++;
690  }
691  return k;
692 }
693 
694 //**************************************************************************
695 // save noise rms in amplitude array in cluster structure
696 // input fl is used for low pass filter correction
697 //**************************************************************************
698 void wavecluster::setrms(WSeries<double>& w, double fl, double fh)
699 {
700  size_t i,j,n,m;
701  slice S;
702  size_t M = pList.size();
703  size_t max_layer = w.maxLayer()+1;
704  wavepixel* p = NULL; // pointer to pixel structure
705 
706  int k;
707  int wsize = w.size()/max_layer;
708  double wstart = w.start();
709  double wrate = w.wavearray<double>::rate();
710  double deltaF = w.gethigh()/max_layer;
711  double x,f,t,r;
712  bool C; // low pass filter correction flag
713 
714  if(fl<0.) fl = low;
715  if(fh<0.) fh = w.gethigh();
716 
717  if(!M || !w.size()) return;
718 
719  for(i=0; i<M; i++){
720  p = &(pList[i]);
721 
722  if(p->frequency >= max_layer) continue;
723 
724  f = p->frequency*p->rate/2.;
725  C = f<fl ? true : false;
726  f = C ? fl : f;
727  n = size_t(f/deltaF); // first layer in w
728  f = (p->frequency+1)*p->rate/2.;
729  m = size_t(f/deltaF); // last layer in w
730  t = start+(p->time+0.5)/p->rate;
731  k = int((t-wstart)*wrate); // time index in noise array
732 
733  if(k>=wsize) k -= k ? 1 : 0;
734  if(k<0 || n>=m || k>=wsize) {
735  cout<<"wavecluster::setrms() - invalid input\n";
736  continue;
737  }
738 
739  r = 0.;
740  for(j=n; j<m; j++) { // get noise rms for specified pixel
741  S = w.getSlice(j);
742  x = w.data[S.start()+k*S.stride()];
743  r += 1./x/x;
744  // r += C && (j<2*n) ? 2./x/x : 1./x/x;
745  }
746  r /= double(m)-double(n);
747  p->noiserms = sqrt(1./r);
748 
749  }
750  return;
751 }
752 
753 //**************************************************************************
754 // save noise variance in amplitude array in cluster structure
755 //**************************************************************************
756 void wavecluster::setvar(wavearray<float>& w, double fl, double fh)
757 {
758  size_t i;
759  size_t M = pList.size();
760  wavepixel* p = NULL; // pointer to pixel structure
761 
762  int k;
763  int wsize = w.size();
764  double wstart = w.start();
765  double f,t;
766 
767  if(!M || !w.size()) return;
768  if(fl<0.) fl = low;
769  if(fh<0.) fh = high;
770 
771  for(i=0; i<M; i++){
772  p = &(pList[i]);
773 
774  f = p->frequency*p->rate/2.;
775  if(f>=fh && f+p->rate/2. >fh) continue;
776  if(f <fl && f+p->rate/2.<=fl) continue;
777 
778  t = start+(p->time+0.5)/p->rate;
779  k = int((t-wstart)*w.rate()); // time index in variability array
780 
781  if(k>=wsize) k -= k ? 1 : 0;
782  if(k<0 || k>=wsize) {
783  cout<<"wavecluster::setvar() - invalid input\n";
784  continue;
785  }
786 
787  p->variability = w.data[k];
788  }
789  return;
790 }
791 
792 
793 double wavecluster::getNoiseRMS(double t, double fl, double fh)
794 {
795  if(!nRMS.size()) return 1.;
796 
797  size_t i;
798  size_t M = nRMS.maxLayer()+1; // number of layers in nRMS
799  size_t n = size_t(fl/(nRMS.gethigh()/M)); // first layer to get in nRMS
800  size_t m = size_t(fh/(nRMS.gethigh()/M)); // last layer to get in nRMS
801 
802  double rms = 0.;
803  double x;
804  slice S;
805 
806  int inRMS = int((t-nRMS.start())*nRMS.rate());
807  int inVAR = nVAR.size() ? int((t-nVAR.start())*nVAR.rate()) : 0;
808 
809  if(inRMS>=int(nRMS.size()/M)) inRMS -= inRMS ? 1 : 0;
810  if(inVAR>=int(nVAR.size())) inVAR -= inVAR ? 1 : 0;
811 
812  if(inRMS<0 || inVAR<0 || n>=m ||
813  inRMS >= int(nRMS.size()/M) ||
814  inVAR >= int(nVAR.size()))
815  {
816  cout<<"wavecluster::getNoiseRMS() - invalid pixel time\n";
817  return 0.;
818  }
819 
820  for(i=n; i<m; i++) { // get noise vector for specified fl-fh
821  S = nRMS.getSlice(i);
822  x = nRMS.data[S.start()+inRMS*S.stride()];
823  rms += 1./x/x;
824  }
825  rms /= double(m)-double(n);
826  rms = sqrt(1./rms);
827 
828  if(!nVAR.size() || fh<low || fl>high) return rms;
829 
830  return rms*double(nVAR.data[inVAR]);
831 }
832 
833 //**************************************************************************
834 // return cluster parameters.
835 //**************************************************************************
836 wavearray<float> wavecluster::get(char* name, int index, size_t type)
837 {
839  if(!cList.size()) return out;
840 
841  size_t k;
842  size_t mp,mm;
843  size_t it_size;
844  size_t it_core;
845  size_t out_size = 0;
846  double x,y;
847  double a,b;
848  double t,r;
849  double sum = 0.;
850  int ID, rate;
851 
852  wavearray<int> skip;
853  list<vector_int>::iterator it;
854  vector_int* pv = NULL;
855  size_t M = pList.size();
856  size_t m = abs(index);
857  if(m==0) m++;
858 
859  out.resize(cList.size());
860  out.start(start);
861  out.rate(1.);
862  out = 0.;
863 
864  char c = '0';
865 
866  if(strstr(name,"ID")) c = 'i'; // clusterID
867  if(strstr(name,"size")) c = 'k'; // size
868  if(strstr(name,"volume")) c = 'v'; // volume
869  if(strstr(name,"start")) c = 's'; // start time
870  if(strstr(name,"stop")) c = 'd'; // stop time
871  if(strstr(name,"low")) c = 'l'; // low frequency
872  if(strstr(name,"high")) c = 'h'; // high frequency
873  if(strstr(name,"time")) c = 't'; // time averaged over SNR, index>=0 - Gauss
874  if(strstr(name,"TIME")) c = 'T'; // time averaged over hrss, index>=0 - Gauss
875  if(strstr(name,"freq")) c = 'f'; // frequency averaged over SNR, index>=0 - Gauss
876  if(strstr(name,"FREQ")) c = 'F'; // frequency averaged over hrss, index>=0 - Gauss
877  if(strstr(name,"energy")) c = 'e'; // energy; index<0 - rank, index>0 - Gauss
878  if(strstr(name,"like")) c = 'Y'; // likelihood; index<0 - rank, index>0 - Gauss
879  if(strstr(name,"sign")) c = 'z'; // significance; index<0 - rank, index>0 - Gauss
880  if(strstr(name,"corr")) c = 'x'; // xcorrelation
881  if(strstr(name,"asym")) c = 'a'; // asymmetry
882  if(strstr(name,"grand")) c = 'g'; // grandAmplitude
883  if(strstr(name,"rate")) c = 'r'; // cluster rate
884  if(strstr(name,"SNR")) c = 'S'; // cluster SNR: index<0 - rank, index>0 - Gauss
885  if(strstr(name,"hrss")) c = 'H'; // log10(calibrated cluster hrss)
886  if(strstr(name,"noise")) c = 'n'; // log10(average calibrated noise)
887 
888  if(c=='0') return out;
889 
890  k = 0;
891 
892  for(it=cList.begin(); it!=cList.end(); it++){
893 
894  ID = pList[((*it)[0])].clusterID;
895  if(sCuts[ID-1]) continue; // apply selection cuts
896 
897  it_size = it->size();
898  it_core = 0;
899  skip.resize(it_size);
900 
901  pv =&(cRate[ID-1]);
902  rate = type && type<=pv->size()? (*pv)[type-1] : 0;
903 
904 // cout<<(*pv)[0]<<" "<<(*pv)[1]<<" "<<pv->size()<<endl;
905 
906  for(k=0; k<it_size; k++) { // fill skip array
907  M = (*it)[k];
908  skip.data[k] = 1;
909  if(!pList[M].core) continue;
910  if(rate && int(pList[M].rate+0.1)!=rate) continue;
911  skip.data[k] = 0;
912  it_core++;
913  }
914 
915  if(!it_core) continue; // skip cluster
916 
917  switch (c) {
918 
919  case 'i': // get cluster ID
920  M = (*it)[0];
921  out.data[out_size++] = pList[M].clusterID;
922  break;
923 
924  case 'k': // get cluster core size
925  out.data[out_size++] = float(it_core);
926  break;
927 
928  case 'r': // get cluster rate
929  for(k=0; k<it_size; k++){
930  M = (*it)[k];
931  if(!skip.data[k]) break;
932  }
933  out.data[out_size++] = pList[M].rate;
934  break;
935 
936  case 'a': // get cluster asymmetry
937  case 'x': // get cluster x-correlation parameter
938  mp = 0; mm = 0;
939  for(k=0; k<it_size; k++){
940  M = (*it)[k];
941 
942  if(skip.data[k]) continue;
943  if(pList[M].amplitude.size()<m) continue;
944 
945  x = pList[M].amplitude[m-1];
946  if(x>0.) mp++;
947  else mm++;
948  }
949  if(c == 'a') out.data[out_size++] = (float(mp)-float(mm))/(mp+mm);
950  else out.data[out_size++] = signPDF(mp,mm);
951  break;
952 
953  case 'e': // get cluster energy
954  case 'S': // get cluster SNR
955  case 'Y': // get cluster likelihood
956  case 'z': // get cluster significance
957  y = 0.;
958  for(k=0; k<it_size; k++){
959  M = (*it)[k];
960 
961  if(skip.data[k]) continue;
962  if(pList[M].amplitude.size()<m) continue;
963 
964  x = pList[M].amplitude[m-1];
965  if(index>0){ // get Gaussian statistics
966  if(c=='Y' || c=='z') y += pow(fabs(x)+1.11/2,2)/2./1.07 + log(bpp);
967  else if(c=='S') y += x*x-1.;
968  else if(c=='e') y += x*x;
969  }
970  else { // get rank statistics
971  if(c=='Y' || c=='z') y += fabs(x);
972  else if(c=='S') y += pow(sqrt(2*1.07*(fabs(x)-log(bpp)))-1.11/2.,2)-1.;
973  else if(c=='e') y += pow(sqrt(2*1.07*(fabs(x)-log(bpp)))-1.11/2.,2);
974  }
975  }
976  out.data[out_size++] = c=='z' ? gammaCL(y,it_core) : y;
977  break;
978 
979  case 'g': // get cluster grand amplitude
980  y = 0.;
981  for(k=0; k<it_size; k++){
982  M = (*it)[k];
983 
984  if(skip.data[k]) continue;
985  if(pList[M].amplitude.size()<m) continue;
986 
987  x = fabs(pList[M].amplitude[m-1]);
988  if(x>y) y = x;
989  }
990  out.data[out_size++] = y;
991  break;
992 
993  case 's': // get cluster start time
994  case 'd': // get cluster stop time
995  a = 1.e99;
996  b = 0.;
997  for(k=0; k<it_size; k++){
998  M = (*it)[k];
999  if(skip.data[k]) continue;
1000  y = 1./pList[M].rate; // time resolution
1001  x = y * pList[M].time; // pixel time relative to start
1002  if(x <a) a = x;
1003  if(x+y>b) b = x+y;
1004  }
1005  out.data[out_size++] = (c=='s') ? a : b;
1006  break;
1007 
1008  case 'l': // get low frequency
1009  case 'h': // get high frequency
1010  a = 1.e99;
1011  b = 0.;
1012  for(k=0; k<it_size; k++){
1013  M = (*it)[k];
1014  if(skip.data[k]) continue;
1015  y = pList[M].rate/2.; // frequency resolution
1016  x = y * pList[M].frequency; // pixel frequency
1017  if(x <a) a = x;
1018  if(x+y>b) b = x+y;
1019  }
1020  out.data[out_size++] = (c=='l') ? a : b;
1021  break;
1022 
1023  case 't': // get central time (SNR)
1024  case 'f': // get central frequency (SNR)
1025  case 'T': // get central time (hrss)
1026  case 'F': // get central frequency (hrss)
1027  a = 0.;
1028  b = 0.;
1029  for(k=0; k<it_size; k++) {
1030  M = (*it)[k];
1031 
1032  if(skip.data[k]) continue;
1033  if(pList[M].amplitude.size()<m) continue;
1034 
1035  r = pList[M].variability;
1036  if(c =='T' || c =='F') {
1037 // f = pList[M].frequency*pList[M].rate/2.; // low frequency
1038 // t = start+(pList[M].time+0.5)/pList[M].rate; // pixel time
1039 // r = getNoiseRMS(t,f,f+pList[M].rate/2.); // noise rms for this pixel
1040  r *= pList[M].noiserms;
1041  }
1042 
1043  x = pList[M].amplitude[m-1];
1044  t = 1./pList[M].rate;
1045  if(index>=0) { // get Gaussian statistics
1046  x = (x*x-1.)*r*r;
1047  }
1048  else { // get rank statistics
1049  x = pow(sqrt(2*1.07*(fabs(x)-log(bpp)))-1.11/2.,2)-1.;
1050  }
1051  if(x<0.) x = 0.;
1052 
1053  if(c =='t' || c =='T'){
1054 // y = 1./pList[M].rate; // time resolution
1055  a += (pList[M].time+0.5)*x; // pixel time sum
1056  b += x*pList[M].rate;
1057  }
1058  else {
1059 // y = pList[M].rate/2.; // frequency resolution
1060  a += (pList[M].frequency+0.5)*x; // pixel frequency sum
1061  b += x*2./pList[M].rate;
1062  }
1063 // b += x;
1064  }
1065  out.data[out_size++] = b>0. ? a/b : -1.;
1066  break;
1067 
1068  case 'H': // get calibrated hrss
1069  case 'n': // get calibrated noise
1070 
1071  mp = 0;
1072  sum = 0.;
1073  out.data[out_size] = 0.;
1074 // if(!nRMS.size()) { out_size++; break; } // no calibration constants
1075 
1076  for(k=0; k<it_size; k++) {
1077  M = (*it)[k];
1078 
1079  if(skip.data[k]) continue;
1080  if(pList[M].amplitude.size()<m) continue;
1081 
1082 // calculate noise RMS for pixel
1083 
1084 // f = pList[M].frequency*pList[M].rate/2.; // low frequency
1085 // t = start+(pList[M].time+0.5)/pList[M].rate; // pixel time
1086 // r = getNoiseRMS(t,f,f+pList[M].rate/2.); // noise rms for this pixel
1087 
1088  r = pList[M].variability*pList[M].noiserms;
1089  mp++;
1090 
1091  if(c == 'H'){
1092  a = pow(pList[M].amplitude[m-1],2)-1.;
1093  sum += a<0. ? 0. : a*r*r;
1094  }
1095  else {
1096  sum += 1./r/r;
1097  }
1098 
1099  }
1100 
1101  if(c == 'n') { sum = double(mp)/sum; } // noise hrss
1102  out.data[out_size++] = float(log(sum)/2./log(10.));
1103  break;
1104 
1105  case 'v':
1106  default:
1107  out.data[out_size++] = it_size;
1108  break;
1109  }
1110  }
1111  out.resize(out_size);
1112  return out;
1113 }
1114 
1115 // initialize from binary WSeries
1116 
1117 double wavecluster::setMask(WSeries<double>& w, int nc, bool halo)
1118 {
1119 #if !defined (__SUNPRO_CC)
1120  register int i;
1121  register int j;
1122  int x, y, L, k;
1123  register int* q = NULL;
1124  register int* p = NULL;
1125  int* pp;
1126  int* pm;
1127  wavepixel pix;
1128 
1130 
1131  if(!w.pWavelet->BinaryTree()) return 1.;
1132 
1133  start = w.start(); // set start time
1134  bpp = w.getbpp();
1135 
1136  int ni = w.maxLayer()+1;
1137  int nj = w.size()/ni;
1138  int n = ni-1;
1139  int m = nj-1;
1140  int nPixel = 0;
1141 
1142  int FT[ni][nj];
1143  int XY[ni][nj];
1144 
1145  for(i=0; i<ni; i++){
1146  p = FT[i];
1147  q = XY[i];
1148 
1149  w.getLayer(a,i);
1150 
1151  for(j=0; j<nj; j++){
1152  p[j] = (a.data[j]!=0) ? 1 : 0;
1153  if(p[j]) nPixel++;
1154  q[j] = 0;
1155  }
1156  }
1157 
1158  pList.clear();
1159  sCuts.clear();
1160  cList.clear();
1161 
1162  if(!nc || ni<3 || nPixel<2) return double(nPixel)/double(size());
1163 
1164 // calculate number of neighbors and ignore 1 pixel clusters
1165 
1166 // corners
1167  if(FT[0][0]) XY[0][0] = FT[0][1] + FT[1][0] + FT[1][1];
1168  if(FT[0][m]) XY[0][m] = FT[1][m] + FT[1][m-1] + FT[0][m-1];
1169  if(FT[n][0]) XY[n][0] = FT[n-1][0] + FT[n-1][1] + FT[n][1];
1170  if(FT[n][m]) XY[n][m] = FT[n][m-1] + FT[n-1][m] + FT[n-1][m-1];
1171 
1172 // up/down raws
1173  for(j=1; j<m; j++){
1174  p = FT[0];
1175  q = FT[n];
1176 
1177  if(p[j]){
1178  pp = FT[1];
1179  XY[0][j] = p[j-1]+p[j+1] + pp[j-1]+pp[j]+pp[j+1];
1180  }
1181  if(q[j]){
1182  pm = FT[n-1];
1183  XY[n][j] = q[j-1]+q[j+1] + pm[j-1]+pm[j]+pm[j+1];
1184  }
1185  }
1186 
1187  for(i=1; i<n; i++){
1188  pm = FT[i-1]; p = FT[i]; pp = FT[i+1]; q = XY[i];
1189 
1190  if(p[0]) // left side
1191  q[0] = p[1] + pm[0]+pm[1] + pp[0]+pp[1];
1192 
1193  if(p[m]) // right side
1194  q[m] = p[m-1] + pm[m]+pm[m-1] + pp[m]+pp[m-1];
1195 
1196  for(j=1; j<m; j++){
1197  if(p[j])
1198  q[j] = pm[j-1]+pm[j]+pm[j+1] + pp[j-1]+pp[j]+pp[j+1] + p[j-1]+p[j+1];
1199  }
1200  }
1201 
1202 /**************************************/
1203 /* remove clusters with 2,3 pixels */
1204 /**************************************/
1205 
1206  if(nc>1){
1207 
1208 // corners
1209  if(XY[0][0]){
1210  x = XY[0][1] + XY[1][0] + XY[1][1];
1211  if(x==1 || x==4) XY[0][0]=XY[0][1]=XY[1][0]=XY[1][1]=0;
1212  }
1213  if(XY[0][m]){
1214  x = XY[1][m] + XY[1][m-1] + XY[0][m-1];
1215  if(x==1 || x==4) XY[0][m]=XY[1][m]=XY[1][m-1]=XY[0][m-1]=0;
1216  }
1217  if(XY[n][0]){
1218  x = XY[n-1][0] + XY[n-1][1] + XY[n][1];
1219  if(x==1 || x==4) XY[n][0]=XY[n-1][0]=XY[n-1][1]=XY[n][1]=0;
1220  }
1221  if(XY[n][m]){
1222  x = XY[n-1][m] + XY[n][m-1] + XY[n-1][m-1];
1223  if(x==1 || x==4) XY[n][m]=XY[n-1][m]=XY[n][m-1]=XY[n-1][m-1]=0;
1224  }
1225 
1226 // up/down raws
1227  for(j=1; j<m; j++){
1228  p = XY[0];
1229  q = XY[n];
1230 
1231  if(p[j]==1 || p[j]==2){
1232  if(p[j-1]+p[j+1] < 4){
1233  pp = XY[1];
1234  L = p[j-1]+p[j+1] + pp[j];
1235  x = pp[j-1] + pp[j+1] + L;
1236 
1237  if(x==1 || (p[j]==2 && nc>2 && (x==2 || (x==4 && L==4))))
1238  p[j]=p[j-1]=p[j+1]=pp[j-1]=pp[j]=pp[j+1]=0;
1239  }
1240  }
1241 
1242  if(q[j]==1 || q[j]==2){
1243  if(q[j-1]+q[j+1] < 4){
1244  pm = XY[n-1];
1245  L = q[j-1]+q[j+1] + pm[j];
1246  x = pm[j-1] + pm[j+1] + L;
1247 
1248  if(x==1 || (q[j]==2 && nc>2 && (x==2 || (x==4 && L==4))))
1249  q[j]=q[j-1]=q[j+1]=pm[j-1]=pm[j]=pm[j+1]=0;
1250  }
1251  }
1252  }
1253 
1254 // regular case
1255  for(i=1; i<n; i++){
1256  pm = XY[i-1];
1257  p = XY[i];
1258  pp = XY[i+1];
1259 
1260 
1261  if(p[0]==1 || p[0]==2){ // left side
1262  if(pm[0]+pp[0] < 4){
1263  L = p[1] + pm[0] + pp[0];
1264  x = pm[1] + pp[1] + L;
1265 
1266  if(x==1 || (p[0]==2 && nc>2 && (x==2 || (x==4 && L==4))))
1267  p[0]=pm[0]=pp[0]=pm[1]=pp[1]=p[1]=0;;
1268  }
1269  }
1270 
1271  if(p[m]==1 || p[m]==2){ // right side
1272  if(pm[m]+pp[m] < 4){
1273  L = p[m-1] + pm[m] + pp[m];
1274  x = pm[m-1] + pp[m-1] + L;
1275 
1276  if(x==1 || (p[m]==2 && nc>2 && (x==2 || (x==4 && L==4))))
1277  p[m]=pm[m]=pp[m]=pm[m-1]=pp[m-1]=p[m-1]=0;
1278  }
1279  }
1280 
1281  for(j=1; j<m; j++){
1282  y = p[j];
1283  if(y == 1 || y == 2){
1284  if(pm[j]+pp[j] >3) continue;
1285  if(p[j-1]+p[j+1] >3) continue;
1286 
1287  L = pm[j]+pp[j] + p[j-1]+p[j+1];
1288  x = pm[j-1]+pm[j+1] + pp[j-1]+pp[j+1] + L;
1289 
1290  if(x==1 || (y==2 && nc>2 && (x==2 || (x==4 && L==4))))
1291  p[j]=p[j-1]=p[j+1]=pm[j-1]=pm[j]=pm[j+1]=pp[j-1]=pp[j]=pp[j+1]=0;
1292  }
1293  }
1294  }
1295  }
1296 
1297 /**************************************/
1298 /* fill in the pixel mask */
1299 /**************************************/
1300 
1301  pix.amplitude.clear(); // clear link pixels amplitudes
1302  pix.neighbors.clear(); // clear link vector for neighbors
1303  pix.clusterID = 0; // initialize cluster ID
1304  L = 1<<w.getLevel(); // number of layers
1305  pix.rate = float(w.wavearray<double>::rate()/L); // pixel bandwidth
1306 
1307  size_t &f = pix.frequency;
1308  size_t &t = pix.time;
1309 
1310  L = 0;
1311 
1312  for(i=0; i<ni; i++){
1313  p = FT[i]; q = XY[i];
1314  for(j=0; j<nj; j++)
1315  p[j] = q[j];
1316  }
1317 
1318  for(i=0; i<ni; i++){
1319  q = XY[i];
1320  p = FT[i];
1321  for(j=0; j<nj; j++){
1322  if(q[j]) {
1323  t = j; f = i; // time index; frequency index;
1324  pix.core = true; // core pixel
1325  pList.push_back(pix); // save pixel
1326  p[j] = ++L; // save pixel mask index (Fortran indexing)
1327 
1328  if(halo){ // include halo
1329  pix.core = false; // halo pixel
1330 
1331  if(i>0 && j>0) {
1332  t=j-1; f=i-1; if(!FT[f][t]) {pList.push_back(pix); FT[f][t] = ++L;}
1333  }
1334  if(i>0) {
1335  t=j; f=i-1; if(!FT[f][t]) {pList.push_back(pix); FT[f][t] = ++L;}
1336  }
1337  if(i>0 && j<m) {
1338  t=j+1; f=i-1; if(!FT[f][t]) {pList.push_back(pix); FT[f][t] = ++L;}
1339  }
1340  if(j>0) {
1341  t=j-1; f=i; if(!FT[f][t]) {pList.push_back(pix); FT[f][t] = ++L;}
1342  }
1343  if(j<m) {
1344  t=j+1; f=i; if(!FT[f][t]) {pList.push_back(pix); FT[f][t] = ++L;}
1345  }
1346  if(i<n && j>0) {
1347  t=j-1; f=i+1; if(!FT[f][t]) {pList.push_back(pix); FT[f][t] = ++L;}
1348  }
1349  if(i<n) {
1350  t=j; f=i+1; if(!FT[f][t]) {pList.push_back(pix); FT[f][t] = ++L;}
1351  }
1352  if(i<n && j<m) {
1353  t=j+1; f=i+1; if(!FT[f][t]) {pList.push_back(pix); FT[f][t] = ++L;}
1354  }
1355 
1356  }
1357  }
1358  }
1359  }
1360 
1361  register std::vector<int>* pN;
1362  int nM = pList.size();
1363  slice S;
1364 
1365  for(k=0; k<nM; k++){
1366 
1367 // set pixel amplitude
1368  i = pList[k].frequency;
1369  j = pList[k].time;
1370  if(int(i)>w.maxLayer()) cout<<"cluster::setMask() maxLayer error: "<<i<<endl;
1371  S = w.getSlice(i);
1372  pList[k].amplitude.clear();
1373  pList[k].amplitude.push_back(w.data[S.start()+S.stride()*j]);
1374 
1375 // set neighbors
1376  pN = &(pList[k].neighbors);
1377  L = 0;
1378 
1379  if(i==0 || i==n){ // first or last layer
1380  if(i==0){ p = FT[0]; q = FT[1];}
1381  if(i==n){ p = FT[n]; q = FT[n-1];}
1382 
1383  if(j==0){ // first sample
1384  if(p[1]) pN->push_back(p[1]-1);
1385  if(q[1]) pN->push_back(q[1]-1);
1386  if(q[0]) pN->push_back(q[0]-1);
1387  }
1388  else if(j==m){ // last sample
1389  if(p[m-1]) pN->push_back(p[m-1]-1);
1390  if(q[m-1]) pN->push_back(q[m-1]-1);
1391  if(q[m]<0) pN->push_back(q[m]-1);
1392  }
1393  else{ // samples in the middle
1394  if(p[j-1]) pN->push_back(p[j-1]-1);
1395  if(p[j+1]) pN->push_back(p[j+1]-1);
1396  if(q[j-1]) pN->push_back(q[j-1]-1);
1397  if(q[j]) pN->push_back(q[j]-1);
1398  if(q[j+1]) pN->push_back(q[j+1]-1);
1399  }
1400  }
1401 
1402  else{
1403  pp = FT[i+1];
1404  p = FT[i];
1405  pm = FT[i-1];
1406 
1407  if(j==0){ // first sample
1408  if(pm[0]) pN->push_back(pm[0]-1);
1409  if(pp[0]) pN->push_back(pp[0]-1);
1410  if( p[1]) pN->push_back(p[1]-1);
1411  if(pm[1]) pN->push_back(pm[1]-1);
1412  if(pp[1]) pN->push_back(pp[1]-1);
1413  }
1414  else if(j==m){
1415  if(pm[m]) pN->push_back(pm[m]-1); // last sample
1416  if(pp[m]) pN->push_back(pp[m]-1);
1417  if( p[m-1]) pN->push_back(p[m-1]-1);
1418  if(pm[m-1]) pN->push_back(pm[m-1]-1);
1419  if(pp[m-1]) pN->push_back(pp[m-1]-1);
1420  }
1421  else{
1422  if(pm[j-1]) pN->push_back(pm[j-1]-1);
1423  if(pm[j]) pN->push_back(pm[j]-1);
1424  if(pm[j+1]) pN->push_back(pm[j+1]-1);
1425  if( p[j-1]) pN->push_back(p[j-1]-1);
1426  if( p[j+1]) pN->push_back(p[j+1]-1);
1427  if(pp[j-1]) pN->push_back(pp[j-1]-1);
1428  if(pp[j]) pN->push_back(pp[j]-1);
1429  if(pp[j+1]) pN->push_back(pp[j+1]-1);
1430  }
1431  }
1432 
1433  L = pList[k].neighbors.size();
1434  x = pList[k].core ? XY[i][j] : L;
1435  if((x != L && !halo) || L>8){
1436  cout<<"cluster::getMask() vector size error: "<<L<<" reserved: "<<x<<endl;
1437  cout<<"k="<<k<<" i="<<i<<" j="<<j<<endl;
1438  }
1439  }
1440 #endif
1441  return double(pList.size())/double(size());
1442 }
1443 
1444 
1445 
1446 
1447 
1448 
1449 
1450 
1451 
1452 
1453 
1454 
1455 
wavearray< double > t(hp.size())
std::vector< vector_int > cRate
Definition: cluster.hh:209
char cut[512]
std::vector< int > vector_int
Definition: cluster.hh:17
virtual size_t size() const
Definition: wavearray.hh:127
static const double C
Definition: GNGen.cc:10
virtual size_t append(wavecluster &)
param: input cluster list return size of appended list
Definition: cluster.cc:404
virtual ~wavecluster()
Definition: cluster.cc:55
double gammaCL(double x, double n)
Definition: watfun.hh:113
size_t time
Definition: cluster.hh:39
double bpp
Definition: cluster.hh:197
par[0] value
virtual size_t cluster()
return number of clusters
Definition: cluster.cc:224
tuple f
Definition: cwb_online.py:91
printf("total live time: non-zero lags = %10.1f \n", liveTot)
double min(double x, double y)
Definition: eBBH.cc:13
int offset
Definition: TestSTFT_2.C:19
virtual void rate(double r)
Definition: wavearray.hh:123
std::vector< pixel > cluster
Definition: wavepath.hh:43
CWB run(runID)
wavearray< double > a(hp.size())
wavearray< float > get(char *, int=0, size_t=0)
param: string with parameter name param: amplitude field index param: rate index, if 0 ignore rate fo...
Definition: cluster.cc:836
WSeries< float > v[nIFO]
Definition: cwb_net.C:62
par[0] name
int n
Definition: cwb_net.C:10
float variability
Definition: cluster.hh:43
std::vector< wavepixel > pList
Definition: cluster.hh:203
int ID
Definition: TestMDC.C:70
int count
Definition: compare_bkg.C:373
wavecluster & operator=(const wavecluster &)
Definition: cluster.cc:59
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<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t 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
double bpp
Definition: test_config1.C:22
size_t index
Definition: cluster.hh:41
double amplitude
virtual double setMask(WSeries< double > &, int=1, bool=false)
param: max number of pixels in clusters to be cleaned (<4); param: false - core only, true - core + halo return pixel occupancy
Definition: cluster.cc:1117
netpixel pix(nifo)
STL namespace.
std::slice getSlice(double n)
Definition: wseries.hh:134
virtual size_t init(WSeries< double > &, bool=false)
param: false - core only, true - core + halo return cluster list size
Definition: cluster.cc:86
Long_t size
#define M
Definition: UniqSLagsList.C:3
int m
Definition: cwb_net.C:10
virtual void start(double s)
Definition: wavearray.hh:119
int j
Definition: cwb_net.C:10
i drho i
#define N
char ifo[NIFO_MAX][8]
double stop
Definition: cluster.hh:194
double low
Definition: cluster.hh:195
wavearray< double > w
Definition: Test1.C:27
ofstream out
Definition: cwb_merge.C:196
wavecluster()
Definition: cluster.cc:26
int getLevel()
Definition: wseries.hh:91
double signPDF(const size_t m, const size_t k)
Definition: watfun.hh:79
virtual size_t coincidence(wavecluster &, double=1.)
param: input cluster list return size of the coincidence list
Definition: cluster.cc:657
void setvar(wavearray< float > &, double=-1., double=-1.)
Definition: cluster.cc:756
double getlow() const
Definition: wseries.hh:111
int asize()
Definition: cluster.hh:220
double getbpp() const
Definition: wseries.hh:99
i() int(T_cor *100))
double start
Definition: cluster.hh:193
bool log
Definition: WaveMDC.C:41
int compare_pix(const void *x, const void *y)
Definition: cluster.cc:15
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
Definition: wseries.cc:175
double high
Definition: cluster.hh:196
virtual size_t merge(double=0.)
param: non return size of merged list
Definition: cluster.cc:465
void setrms(WSeries< double > &, double=-1., double=-1.)
Definition: cluster.cc:698
float rate
Definition: cluster.hh:42
int k
double F
double e
double shift
Definition: cluster.hh:198
double gethigh() const
Definition: wseries.hh:118
regression r
Definition: Regression_H1.C:44
virtual size_t apush(WSeries< double > &a, double=0.)
param: this and WSeries objects should have the same tree type and the approximation level size param...
Definition: cluster.cc:351
size_t clusterID
Definition: cluster.hh:38
bool BinaryTree()
Definition: Wavelet.hh:79
virtual size_t cleanhalo(bool=false)
param: if true - de-cluster pixels return size of the list
Definition: cluster.cc:293
double T
Definition: testWDM_4.C:11
ifstream in
wavearray< int > index
WSeries< double > nRMS
Definition: cluster.hh:211
double fabs(const Complex &x)
Definition: numpy.cc:37
Meyer< double > S(1024, 2)
int l
Definition: cbc_plots.C:434
DataType_t * data
Definition: wavearray.hh:301
Long_t id
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:438
std::vector< double > amplitude
Definition: cluster.hh:47
double noiserms
Definition: cluster.hh:44
double getNoiseRMS(double, double, double)
param: pixel time, sec param: pixel low frequency param: pixel high frequency
Definition: cluster.cc:793
bool core
Definition: cluster.hh:45
size_t stride() const
Definition: wslice.hh:75
double shift[NIFO_MAX]
volume[m][l]
Definition: cbc_plots.C:678
virtual void resize(unsigned int)
Definition: wavearray.cc:445
wavearray< double > y
Definition: Test10.C:31
std::vector< int > neighbors
Definition: cluster.hh:46
char pm[8]
std::list< vector_int > cList
Definition: cluster.hh:207
size_t start() const
Definition: wslice.hh:67
int maxLayer()
Definition: wseries.hh:121
init()
Definition: revMonster.cc:12
size_t frequency
Definition: cluster.hh:40
std::vector< bool > sCuts
Definition: cluster.hh:205