Logo coherent WaveBurst  
Library Reference Guide
Logo
cluster.hh
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Sergey Klimenko
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 // Wavelet Analysis Tool
20 // Sergey Klimenko, University of Florida
21 // universal data container for cluster analysis
22 // used with DMT and ROOT
23 //
24 
25 #ifndef WAVECLUSTER_HH
26 #define WAVECLUSTER_HH
27 
28 #include <iostream>
29 #include "wavearray.hh"
30 #include <vector>
31 #include <list>
32 #include "WaveDWT.hh"
33 #include "wseries.hh"
34 
35 typedef std::vector<int> vector_int;
36 
37 
38 class wavepixel {
39  public:
40  // need all this crap to use stl::vector<wavepixel> class
42  time = 0;
43  frequency = 0;
44  rate = 1.;
45  clusterID = 0;
46  variability = 1.;
47  noiserms = 1.;
48  index = 0;
49  neighbors.clear();
50  amplitude.clear();
51  }
52  virtual ~wavepixel(){}
53  bool operator == (const wavepixel &) const {return true;}
54  bool operator < (const wavepixel &) const {return true;}
55 
56  size_t clusterID; // cluster ID
57  size_t time; // time index
58  size_t frequency; // frequency index (layer)
59  size_t index; // position in list
60  float rate; // wavelet layer rate
61  float variability; // average noise variability
62  double noiserms; // average noise rms
63  bool core; // pixel type: true - core , false - halo
64  std::vector<int> neighbors; // vector of links to neighbors
65  std::vector<double> amplitude; // vector of pixel's amplitudes
66 };
67 
68 
70 {
71  public:
72 
73  // constructors
74 
75  //: Default constructor
76  wavecluster();
77 
78  //: initialize from binary WSeries<double>
79  //!param: input WSeries
80  //!param: true if halo, false if no halo included
81  wavecluster(WSeries<double>&, bool=false);
82 
83  //: Copy constructor
84  //!param: value - object to copy from
85  wavecluster(const wavecluster&);
86 
87  //: destructor
88  virtual ~wavecluster();
89 
90  // operators
91 
92  wavecluster& operator= (const wavecluster&);
93 
94  // accessors
95 
96  //: initialize wavecluster class from binary WSeries<double>;
97  //!param: false - core only, true - core + halo
98  //!return cluster list size
99  virtual size_t init(WSeries<double>&, bool=false);
100 
101  //: initialize wavecluster class from binary WSeries<double>;
102  //!param: max number of pixels in clusters to be cleaned (<4);
103  //!param: false - core only, true - core + halo
104  //!return pixel occupancy
105  virtual double setMask(WSeries<double>&, int=1, bool=false);
106 
107  //: Get the pixel list size
108  inline size_t size() { return pList.size(); }
109 
110  //: set black pixel probability
111  inline void setbpp(double P) { bpp = P; return; }
112  //: get black pixel probability
113  inline double getbpp() { return bpp; }
114 
115  //: set low frequency for variability correction
116  inline void setlow(double f) { low = f; return; }
117  //: get low frequency
118  inline double getlow() { return low; }
119 
120  //: set high frequency for variability correction
121  inline void sethigh(double f) { high = f; return; }
122  //: get low frequency
123  inline double gethigh() { return high; }
124 
125  //: set noise array
126  inline void set(WSeries<double> &n) { nRMS = n; return; }
127  //: set variability array
128  inline void set(wavearray<float> &v) { nVAR = v; return; }
129 
130  /* set noise rms in amplitude array
131  * @memo save pixel noise rms
132  * @param rms array (WSeries<double>)
133  * @param low frequency for lowpass filter correction
134  * @param not used
135  */
136  void setrms(WSeries<double> &, double=-1., double=-1.);
137 
138  /* set noise variabilty in amplitude array
139  * @memo save pixel noise variabilty
140  * @param variability array (wavearray<float>)
141  * @param low frequency for variability correction
142  * @param high frequency for variability correction
143  */
144  void setvar(wavearray<float> &, double=-1., double=-1.);
145 
146  //: Get the the minimum size of the pixel's amplitude vector in the list
147  // return - (minimum_size) if the vector size is different
148  // for different pixels
149  inline int asize();
150 
151  //: set selection cuts vector used in mask(), occupancy(), getCluster()
152  //!param: cluster ID number
153  //!return void
154  inline void ignore(size_t i=0) {
155  if(i>0 && i<=sCuts.size()) sCuts[i-1] = true;
156  else if(i==0) { for(i=0; i<sCuts.size(); i++) sCuts[i] = false; }
157  }
158 
159  //: remove halo pixels from pixel list
160  //!param: if true - de-cluster pixels
161  //!return size of the list
162  virtual size_t cleanhalo(bool=false);
163 
164  //: push amplitudes from input WSeries to this pList.amplitude vector
165  //!param: this and WSeries objects should have the same tree type
166  //! and the approximation level size
167  //!param: start time offset: start-a.start, illegal if negative
168  //!return size of amplitude vector
169  virtual size_t apush(WSeries<double> &a, double=0.);
170 
171  //: append input cluster list
172  //!param: input cluster list
173  //!return size of appended list
174  virtual size_t append(wavecluster &);
175 
176  //: merge clusters in the list
177  //!param: non
178  //!return size of merged list
179  virtual size_t merge(double=0.);
180 
181  //: time coincidence between cluster lists
182  //!param: input cluster list
183  //!return size of the coincidence list
184  virtual size_t coincidence(wavecluster &, double=1.);
185 
186  //: set clusterID field for pixels in pList vector
187  //: create cList structure - list of references to cluster's pixels
188  //!return number of clusters
189  virtual size_t cluster();
190 
191  //: recursively calculate clusterID pixels in pList vector
192  //!param: pixel index in pList vector
193  //!return cluster volume (total number of pixels)
194  virtual size_t cluster(wavepixel*);
195 
196  //: access function to get cluster parameters passed selection cuts
197  //!param: string with parameter name
198  //!param: amplitude field index
199  //!param: rate index, if 0 ignore rate for calculation of cluster parameters
200  //!return wavearray object with parameter values for clusters
201  wavearray<float> get(char*, int=0, size_t=0);
202 
203  //: return noise RMS for selected pixel in pMask
204  //!param: pixel time, sec
205  //!param: pixel low frequency
206  //!param: pixel high frequency
207  double getNoiseRMS(double, double, double);
208 
209 // data members
210 
211  double start; // interval start GPS time
212  double stop; // interval stop GPS time
213  double low; // low frequency boubdary
214  double high; // high frequency boundary
215  double bpp; // black pixel probability
216  double shift; // time shift
217  int ifo; // detector index: 1/2/3 - L1/H1/H2
218  int run; // run ID
219 
220  //: pixel list
221  std::vector<wavepixel> pList;
222  //: selection cuts
223  std::vector<bool> sCuts;
224  //: cluster list created by cluster() with pixel reference to pList
225  std::list<vector_int> cList;
226  //: cluster type defined by rate
227  std::vector<vector_int> cRate;
228  //: calibrated noise RMS
230  //: noise variability
232 
233 }; // class wavecluster
234 
235 //: compare function to sort pixel objects
236 int compare_pix(const void*, const void*);
237 
238 inline int wavecluster::asize(){
239  size_t M = pList.size();
240  size_t n = 10000;
241  size_t N = 0;
242  size_t m,k;
243  if(!M) return 0;
244  for(k=0; k<M; k++){
245  m = (&(pList[k]))->amplitude.size();
246  if(m<n) n = m;
247  if(m>N) N = m;
248  }
249  if(N-n) {
250  printf("wavecluster::asize(): invalid size of amplitude vector: %d %d\n",(int)N,(int)n);
251  }
252  return n;
253 }
254 
255 
256 #endif // WAVECLUSTER_HH
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 
269 
270 
271 
272 
273 
274 
std::vector< vector_int > cRate
Definition: cluster.hh:227
std::vector< int > vector_int
Definition: cluster.hh:35
size_t time
Definition: cluster.hh:57
double M
Definition: DrawEBHH.C:13
double bpp
Definition: cluster.hh:215
std::vector< pixel > cluster
Definition: wavepath.hh:61
wavearray< double > a(hp.size())
WSeries< float > v[nIFO]
Definition: cwb_net.C:80
double gethigh()
Definition: cluster.hh:123
int n
Definition: cwb_net.C:28
float variability
Definition: cluster.hh:61
std::vector< wavepixel > pList
Definition: cluster.hh:221
void setbpp(double P)
Definition: cluster.hh:111
double bpp
Definition: test_config1.C:22
size_t index
Definition: cluster.hh:59
void ignore(size_t i=0)
param: cluster ID number return void
Definition: cluster.hh:154
int m
Definition: cwb_net.C:28
i drho i
#define N
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
double getbpp()
Definition: cluster.hh:113
double stop
Definition: cluster.hh:212
double low
Definition: cluster.hh:213
nc append(pix)
wavearray< float > nVAR
Definition: cluster.hh:231
void sethigh(double f)
Definition: cluster.hh:121
int asize()
Definition: cluster.hh:238
double start
Definition: cluster.hh:211
void setlow(double f)
Definition: cluster.hh:116
printf("total live time: non-zero lags = %10.1f \, liveTot)
double high
Definition: cluster.hh:214
float rate
Definition: cluster.hh:60
int k
size_t size()
Definition: cluster.hh:108
virtual ~wavepixel()
Definition: cluster.hh:52
int compare_pix(const void *, const void *)
Definition: cluster.cc:33
double shift
Definition: cluster.hh:216
size_t clusterID
Definition: cluster.hh:56
WSeries< double > nRMS
Definition: cluster.hh:229
double getlow()
Definition: cluster.hh:118
wavepixel()
Definition: cluster.hh:41
bool operator<(const wavepixel &) const
Definition: cluster.hh:54
std::vector< double > amplitude
Definition: cluster.hh:65
double noiserms
Definition: cluster.hh:62
bool operator==(const wavepixel &) const
Definition: cluster.hh:53
bool core
Definition: cluster.hh:63
std::vector< int > neighbors
Definition: cluster.hh:64
std::list< vector_int > cList
Definition: cluster.hh:225
init()
Definition: revMonster.cc:12
size_t frequency
Definition: cluster.hh:58
std::vector< bool > sCuts
Definition: cluster.hh:223