Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
netcluster.hh
Go to the documentation of this file.
1 // Wavelet Analysis Tool
2 // Sergey Klimenko, University of Florida
3 // universal data container for network cluster analysis
4 // used with DMT and ROOT
5 //
6 
7 #ifndef NETCLUSTER_HH
8 #define NETCLUSTER_HH
9 
10 #include <iostream>
11 #include "wavearray.hh"
12 #include <vector>
13 #include <list>
14 #include "TH2F.h"
15 #include "TGraphErrors.h"
16 #include "TF1.h"
17 #include "WaveDWT.hh"
18 #include "wseries.hh"
19 #include "netpixel.hh"
20 #include "wat.hh"
21 #include "TNamed.h"
22 #include "TFile.h"
23 #include "TTree.h"
24 #include "WDM.hh"
25 
26 typedef std::vector<int> vector_int;
27 typedef std::vector<float> vector_float;
28 
29 class network;
30 
31 class clusterdata : public TNamed {
32 public:
35  float energy; // total cluster energy
36  float enrgsky; // cluster energy in all resolutions
37  float likenet; // signal energy
38  float netecor; // network coherent energy
39  float normcor; // normalized coherent energy
40  float netnull; // null energy in the sky loop with Gauss correction
41  float netED; // energy disbalance
42  float Gnoise; // estimated contribution of Gaussian noise
43  float likesky; // likelihood at all resolutions
44  float skycc; // network cc from the sky loop (all resolutions)
45  float netcc; // network cc for MRA or SRA analysis
46  float skyChi2; // chi2 stat from the sky loop (all resolutions)
47  float subnet; // first subNetCut statistic
48  float SUBNET; // second subNetCut statistic
49  float skyStat; // localization statistic
50  float netRHO; // coherent SNR per detector
51  float netrho; // reduced coherent SNR per detector
52  float theta; // source angle theta index
53  float phi; // source angle phi index
54  float iota; // inclination angle
55  float psi; // polarisation angle
56  float ellipticity; // waveform ellipticity
57  float cTime; // supercluster central time
58  float cFreq; // supercluster central frequency
59  float gNET; // network acceptance
60  float aNET; // network alignment
61  float iNET; // network index
62  float norm; // packet norm
63  float nDoF; // cluster degrees of freedom
64  float tmrgr; // merger time
65  float tmrgrerr; // merger time error
66  float mchirp; // chirp mass
67  float mchirperr; // chirp mass error
68  float chi2chirp; // chi2 over NDF
69  float chirpEfrac; // chirp energy fraction
70  float chirpPfrac; // chirp pixel fraction
71  float chirpEllip; // chirp ellipticity
72  int skySize; // number of sky pixels
73  int skyIndex; // index in the skymap
74  TF1 fit; //! chirp fit parameters (don't remove ! fix crash when exit from CINT)
75  TGraphErrors chirp; // chirp graph
76  wavearray<float> mchpdf; // chirp mass PDF
77  ClassDef(clusterdata,3)
78 };
79 
80 ClassImp(clusterdata)
81 
82 
83 class netcluster : public TNamed
84 {
85 public:
86 
87  // constructors
88 
89  //: Default constructor
90  netcluster();
91 
92  //: Copy constructor
93  //!param: value - object to copy from
94  netcluster(const netcluster&);
95 
96  //: destructor
97  virtual ~netcluster();
98 
99  // operators
100 
101  netcluster& operator= (const netcluster&);
102 
103  // copy function (used in = operator as x.cpf(y,false)
104  //: copy content of y into x.
105  // If no clusters are reconstructed - copy all pixels.
106  // If clusters are reconstructed - copy selected clusters.
107  // param: netcluster object y
108  // param: condition to select clusters:
109  // true - copy selected clusters with core pixels
110  // false - copy all selected clusters
111  // param: min size of BIG clusters
112  // =0 - copy all clusters regardles of their size
113  // >0 - ignore BIG clusters
114  // <0 - copy BIG clusters
115  size_t cpf(const netcluster &, bool=false, int=0);
116 
117 
118  // accessors
119 
120  //: clear lists and release memory;
121  inline void clear();
122  //: clean time delay data
123  inline void clean(int cID=0);
124  //: clean input wseries ws removing rejected clusters
125  //: output number of remaining pixels
126  int clean(WSeries<double>& ws);
127 
128  //: Get pixel list size
129  inline size_t size() { return pList.size(); }
130  //: Get pixel list capacity
131  inline size_t capacity() { return pList.capacity(); }
132  //: Get cluster list size
133  inline size_t csize() { return cList.size(); }
134  //: Get number of clusters with specified type
135  inline size_t esize(int k=2) {
136  size_t n=0;
137  for(size_t i=0; i<sCuts.size(); i++) {
138  if(k<2 && sCuts[i]==k) n++;
139  if(k>1 && sCuts[i] <1) n++;
140  }
141  return n;
142  }
143 
144  //: Get number of selected pixels
145  inline size_t psize(int k=2) {
146  size_t n=0;
147  for(size_t i=0; i<sCuts.size(); i++) {
148  if(k>1 && sCuts[i] <1) n+=cList[i].size();
149  if(k<2 && sCuts[i]==k) n+=cList[i].size();
150  }
151  return n;
152  }
153 
154  //: Get pixel pointer
155  //:parameter n - cluster ID
156  //:parameter i - pixel index in cList[n]
157  inline netpixel* getPixel(size_t n, size_t i);
158 
159  //: set black pixel probability
160  inline void setbpp(double P) { bpp = P; return; }
161  //: get black pixel probability
162  inline double getbpp() { return bpp; }
163 
164  //: set pixel core fields to be equal to the input parameter
165  // core: true/false
166  // id : set core for selected cluster id
167  size_t setcore(bool core,int id=0);
168 
169  //: set selection cuts vector used in mask(), occupancy(), getCluster()
170  //!param: cluster ID number
171  //!return void
172  inline void ignore(size_t n) {
173  if(n>0 && n<=sCuts.size()) sCuts[n-1] = 1;
174  }
175 
176  //: set sCuts vector excluding rejected clusters
177  //!param: sCuts flag
178  inline void setcuts(int n=0) {
179  for(size_t i=0; i<sCuts.size(); i++)
180  if(sCuts[i]!=1) sCuts[i] = n;
181  }
182 
183  //: remove halo pixels from pixel list
184  //!param: if false - de-cluster pixels
185  //!return size of the list
186  virtual size_t cleanhalo(bool=false);
187 
188  //: add halo pixels matching the paccket pattern to the pixel list
189  //!param: packet pattern mode
190  //!return size of the list
191  size_t addhalo(int=0);
192 
193  //: append pixel list from input cluster list
194  //: cluster metadata is lost
195  //!param: input netcluster
196  //!return size of appended pixel list
197  virtual size_t append(netcluster& wc);
198 
199  //: add netpixel object to the list
200  inline void append(netpixel& p) { pList.push_back(p); }
201 
202  // destroy supercluster neighbors links (delink superclusters)
203  // preserve links for pixels with the same wavelet resolution
204  virtual size_t delink();
205 
206  // select clusters
207  // name - parameter name
208  // thr - parameter threshold
209  virtual wavearray<double> select(char*, double);
210 
211  //:reconstruct clusters at several TF resolutions (superclusters)
212  //!param: statistic: E - excess power, L - likelihood
213  //!param: selection threshold T
214  //! for likelihood clusters, T defines a threshold on clusters
215  //! in a superclusters.
216  //!param: true - use only core pixels, false - use core & halo pixels
217  //!return size of pixel list of selected superclusters.
218  virtual size_t supercluster(char atype, double S, bool core); // used in 1G pipeline
219  virtual size_t supercluster(char atype, double S, double gap, bool core, TH1F* = NULL);
220 
221  //:merge clusters if they are close to each other
222  //! T - maximum time gap in seconds
223  //! F - maximum frequency gap in Hz
224  virtual size_t defragment(double T, double F, TH2F* = NULL);
225 
226  void PlotClusters();
227 
228  //: set clusterID field for pixels in pList vector
229  //: create cList structure - list of references to cluster's pixels
230  //!return number of clusters
231  virtual size_t cluster();
232 
233  //: recursively calculate clusterID pixels in pList vector
234  //!param: pixel pointer in pList vector
235  //!return cluster volume (total number of pixels)
236  virtual size_t cluster(netpixel* p);
237 
238  //:produce time-frequency clusters
239  //:sort pixels on index, form pixel groups,
240  //:set neighbor links for each group and cluster them
241  //!param: time gap between pixels in units of pixels
242  //!param: frequenct gap between pixels in units of pixels
243  //!return pixel number of time clusters
244  virtual size_t cluster(int kt,int kf);
245 
246  //: access function to get cluster parameters passed selection cuts
247  //!param: string with parameter name
248  //!param: index in the amplitude array, which define detector
249  //!param: character identifier for amplitude vector:
250  // 'W'-wavelet, 'S'-snr, 'R'-rank
251  //!param: rate index, if 0 ignore rate for calculation of cluster parameters
252  // if negative - extract clusters with rate = abs(rate)
253  //!return wavearray object with parameter values for clusters
254  wavearray<double> get(char* name, size_t index=0, char atype='R', int type=1, bool=true);
255 
256  //: extract WSeries for defined cluster ID
257  //!param: cluster ID
258  //!param: WSeries where to put the waveform
259  //!return: noise rms
260  double getwave(int, WSeries<double>&, char='W', size_t=0);
261 
262  // extract MRA waveforms for network net, cluster ID and detector index n
263  // works only with WDM. Create WSeries<> objects for each resolution,
264  // find principle components, fill in WSeries<>, Inverse
265  // construct waveform from MRA pixels at different resolutions
266  // atype = 'W' - get whitened detector output (Wavelet data)
267  // atype = 'w' - get detector output (Wavelet data)
268  // atype = 'S' - get whitened reconstructed response (Signal)
269  // atype = 's' - get reconstructed response (Signal)
270  // mode: -1/0/1 - return 90/mra/0 phase
271  wavearray<double> getMRAwave(network* net, int ID, size_t n, char atype='S', int mode=0);
272 
273  // write pixel structure into binary file
274  // only metadata and pixels are written
275  // first parameter is file name
276  // second parameter is the append mode 0/1 - wb/ab - new/append
277  size_t write(const char* file, int app=0);
278 
279  // write pixel structure with TD vectors attached into a file
280  // only some metadata and pixels are written, no cluster metadata is stored
281  // fp - file pointer
282  // app = 0 - store metadata
283  // app = 1 - store pixels with the TD vectors attached by setTDAmp()
284  size_t write(FILE* fp, int app=0);
285 
286  // write pixel structure with TD vectors attached into a root file
287  // froot - root file pointer
288  // tdir - internal root directory where the tree is located
289  // tname - name of tree containing the cluster
290  // app = 0 - store light netcluster
291  // app = 1 - store pixels with the TD vectors attached by setTDAmp()
292  // cycle - sim -> it is the factor id : prod -> it is the lag number
293  // irate - wavelet layer irate
294  // if irate is negative the value 'irate' is used to build the tree name
295  // this permits to create a tree for each irate
296  // cID - cluster id (cID=0 -> write all clusters)
297  size_t write(TFile *froot, TString tdir, TString tname, int app=0, int cycle=0, int irate=0, int cID=0);
298 
299  // read entire pixel structure from binary file
300  // returns number of pixels
301  size_t read(const char *);
302 
303  // read metadata and pixels stored in a file on cluster by cluster basis
304  // clusters should be contiguous in the file
305  // maxPix = 0 - read metadata
306  // maxPix > 0 - do not store TD vectors for clusters with size > maxPix
307  // maxPix < 0 - do not store TD vectors for clusters with size < maxPix
308  // clusters with no TD vectors attached are marked rejected.
309  // returns # of pixel in the cluster
310  size_t read(FILE* file, int maxPix);
311 
312  // read metadata and pixels stored in a file on cluster by cluster basis
313  // clusters should be contiguous in the file (written by write(FILE*))
314  // froot - root file pointer
315  // tdir - internal root directory where the tree is located
316  // tname - name of tree containing the cluster
317  // nmax = 0 - read metadata
318  // nmax > 0 - read no more than maxPix pixels from a cluster
319  // nmax < 0 - read all heavy pixels from a cluster
320  // nmax -2 - as for (nmax<0) & skip heavy instructions to speedup read
321  // cycle - sim -> it is factor id : prod -> it is the lag number
322  // rate - wavelet layer rate
323  // if rate is negative the value 'rate' is used to build the tree name
324  // cID - cluster ID (=0 : read all clusters)
325  std::vector<int> read(TFile* froot, TString tdir, TString tname, int nmax=0, int cycle=0, int rate=0, int cID=0);
326 
327  inline void setlow(double f) { flow=f; return; }
328  inline void sethigh(double f) { fhigh=f; return; }
329  inline double getlow() { return flow; }
330  inline double gethigh() { return fhigh; }
331 
332  // set arrays for time-delayed amplitudes in collected coherent pixels
333  // returns number of pixels to process: if count=0 - nothing to process
334  // param: input network
335  // param: 'a','A' - delayed amplitudes, 'e','E' - delayed power
336  // param: number of pixels (per resolution) to setup
337  size_t loadTDamp(network& net, char c, size_t BATCH=10000, size_t LOUD=0);
338  // fast version which uses sparse TF maps in detector class
339  size_t loadTDampSSE(network& net, char c, size_t BATCH=10000, size_t LOUD=0);
340 
341  // param 1 - cluster ID
342  // param 2 - chi2 threshold for selection of chirp pixels
343  // param 3 - tmerger cut: exclude pixels with time > tmerger+param3 - special use
344  // param 4 - threshold for pixel selection - special use
345  // returns reconstructed chirp energy
346  double mchirp(int ID, double=2.5, double=1.e20, double=0);
347 
348  // minipixels; using only P.C ; use df = sqrt(0.6* fdot)
349  double mchirpTEST(int ID);
350 
351  // draw chirp cluster
352  void chirpDraw(int id);
353 
354  // print detector parameters
355  void print(); // *MENU*
356  virtual void Browse(TBrowser *b) {print();}
357 
358  // data members
359 
360  double rate; // original Time series rate
361  double start; // interval start GPS time
362  double stop; // interval stop GPS time
363  double bpp; // black pixel probability
364  double shift; // time shift
365  double flow; // low frequency boundary
366  double fhigh; // high frequency boundary
367  size_t nPIX; // minimum number of pixels at all resolutions
368  int run; // run ID
369  bool pair; // true - 2 resolutions, false - 1 resolution
370  double nSUB; // subnetwork threshold for a single network pixel
371 
372  std::vector<netpixel> pList; // pixel list
373  std::vector<clusterdata> cData; // cluster metadata
374  std::vector<int> sCuts; /* cluster selection flags (cuts)
375  1 - rejected
376  0 - not processed / accepted
377  -1 - not complete
378  -2 - ready for processing */
379  std::vector<vector_int> cList; // cluster list defined by vector of pList references
380  std::vector<vector_int> cRate; // cluster type defined by rate
381  std::vector<float> cTime; // supercluster central time
382  std::vector<float> cFreq; // supercluster central frequency
383  std::vector<vector_float> sArea; // sky error regions
384  std::vector<vector_float> p_Map; // sky pixel map
385  std::vector<vector_int> p_Ind; // sky pixel index
386  std::vector<vector_int> nTofF; // sky time delay configuration for waveform backward correction
387 
388  ClassDef(netcluster,4)
389 
390 }; // class netcluster
391 
392 //: compare function to sort pixel objects on time
393 int compare_PIX(const void*, const void*);
394 
395 inline netpixel* netcluster::getPixel(size_t n, size_t i) {
396  if(!n) return &pList[i];
397  if(cList.size()<n) {
398  printf("getPixel(): size=%d, ID=%d\n",(int)cList.size(),(int)n);
399  return NULL;
400  }
401  if(cList[n-1].size()<=i) {
402  printf("getPixel(): size=%d, index=%d\n",(int)cList[n-1].size(),(int)i);
403  return NULL;
404  }
405  return &pList[cList[n-1][i]];
406 }
407 
408 // release vector memory
409 inline void netcluster::clear() {
410  while(!pList.empty()) pList.pop_back();
411  pList.clear(); std::vector<netpixel>().swap(pList);
412  while(!cList.empty()) cList.pop_back();
413  cList.clear(); std::vector<vector_int>().swap(cList);
414  while(!cData.empty()) cData.pop_back();
415  cData.clear(); std::vector<clusterdata>().swap(cData);
416  while(!sCuts.empty()) sCuts.pop_back();
417  sCuts.clear(); std::vector<int>().swap(sCuts);
418  while(!cRate.empty()) cRate.pop_back();
419  cRate.clear(); std::vector<vector_int>().swap(cRate);
420  while(!cTime.empty()) cTime.pop_back();
421  cTime.clear(); std::vector<float>().swap(cTime);
422  while(!cFreq.empty()) cFreq.pop_back();
423  cFreq.clear(); std::vector<float>().swap(cFreq);
424  while(!sArea.empty()) sArea.pop_back();
425  sArea.clear(); std::vector<vector_float>().swap(sArea);
426  while(!p_Map.empty()) p_Map.pop_back();
427  p_Map.clear(); std::vector<vector_float>().swap(p_Map);
428  while(!p_Ind.empty()) p_Ind.pop_back();
429  p_Ind.clear(); std::vector<vector_int>().swap(p_Ind);
430 }
431 
432 // clean time delay data
433 inline void netcluster::clean(int cID) {
434  for(int i=0; i<(int)this->cList.size(); ++i) { // loop over clusters
435  const vector_int& vint = cList[i];
436  if((cID!=0)&&((int)pList[vint[0]].clusterID!=cID)) continue;
437  for(int j=0; j<(int)vint.size(); j++) { // loop over pixels
438  if(pList[vint[j]].tdAmp.size()) pList[vint[j]].clean();
439  }
440  }
441 }
442 
443 #endif // NETCLUSTER_HH
444 
445 
446 
447 
448 
449 
450 
451 
452 
453 
454 
455 
456 
457 
458 
459 
460 
461 
void setbpp(double P)
Definition: netcluster.hh:160
float SUBNET
Definition: netcluster.hh:48
double stop
Definition: netcluster.hh:362
std::vector< int > vector_int
Definition: cluster.hh:17
std::vector< vector_int > cRate
Definition: netcluster.hh:380
int compare_PIX(const void *, const void *)
Definition: netcluster.cc:36
tuple f
Definition: cwb_online.py:91
printf("total live time: non-zero lags = %10.1f \n", liveTot)
float likenet
Definition: netcluster.hh:37
float gNET
Definition: netcluster.hh:59
int irate
std::vector< pixel > cluster
Definition: wavepath.hh:43
void append(netpixel &p)
Definition: netcluster.hh:200
par[0] name
float energy
Definition: netcluster.hh:35
int n
Definition: cwb_net.C:10
double fhigh
Definition: netcluster.hh:366
TString("c")
float netED
Definition: netcluster.hh:41
float chirpEfrac
Definition: netcluster.hh:69
int ID
Definition: TestMDC.C:70
float mchirp
Definition: netcluster.hh:66
float tmrgrerr
Definition: netcluster.hh:65
double bpp
Definition: test_config1.C:22
float chirpPfrac
Definition: netcluster.hh:70
float normcor
Definition: netcluster.hh:39
std::vector< vector_float > sArea
Definition: netcluster.hh:383
std::vector< int > vector_int
Definition: netcluster.hh:26
double getlow()
Definition: netcluster.hh:329
TRandom3 P
Definition: compare_bkg.C:296
double flow
Definition: netcluster.hh:365
float mchirp
Definition: cbc_plots.C:436
void ignore(size_t n)
param: cluster ID number return void
Definition: netcluster.hh:172
double & gap
float tmrgr
Definition: netcluster.hh:64
std::vector< vector_int > cList
Definition: netcluster.hh:379
int j
Definition: cwb_net.C:10
i drho i
double rate
Definition: netcluster.hh:360
wc clear()
size_t capacity()
Definition: netcluster.hh:131
std::vector< vector_float > p_Map
Definition: netcluster.hh:384
void setlow(double f)
Definition: netcluster.hh:327
network ** net
NOISE_MDC_SIMULATION.
float likesky
Definition: netcluster.hh:43
void clean(int cID=0)
Definition: netcluster.hh:433
size_t mode
nc append(pix)
size_t esize(int k=2)
Definition: netcluster.hh:135
int BATCH
float ellipticity
Definition: netcluster.hh:56
std::vector< float > vector_float
Definition: netcluster.hh:27
double shift
Definition: netcluster.hh:364
void sethigh(double f)
Definition: netcluster.hh:328
double getbpp()
Definition: netcluster.hh:162
i() int(T_cor *100))
std::vector< netpixel > pList
Definition: netcluster.hh:372
double fhigh
float enrgsky
Definition: netcluster.hh:36
double start
Definition: netcluster.hh:361
std::vector< vector_int > p_Ind
Definition: netcluster.hh:385
float skyStat
Definition: netcluster.hh:49
std::vector< float > cFreq
Definition: netcluster.hh:382
float netcc
Definition: netcluster.hh:45
int k
float chi2chirp
Definition: netcluster.hh:68
double F
wavearray< float > mchpdf
Definition: netcluster.hh:76
size_t size()
Definition: netcluster.hh:129
void setcuts(int n=0)
param: sCuts flag
Definition: netcluster.hh:178
virtual void Browse(TBrowser *b)
Definition: netcluster.hh:356
double gethigh()
Definition: netcluster.hh:330
TFile * froot
char tdir[256]
netpixel * getPixel(size_t n, size_t i)
Definition: netcluster.hh:395
float iota
Definition: netcluster.hh:54
float norm
Definition: netcluster.hh:62
float aNET
Definition: netcluster.hh:60
double flow
float mchirperr
Definition: netcluster.hh:67
float Gnoise
Definition: netcluster.hh:42
float iNET
Definition: netcluster.hh:61
double T
Definition: testWDM_4.C:11
TGraphErrors chirp
chirp fit parameters (don't remove ! fix crash when exit from CINT)
Definition: netcluster.hh:75
std::vector< int > sCuts
Definition: netcluster.hh:374
float netRHO
Definition: netcluster.hh:50
std::vector< float > cTime
Definition: netcluster.hh:381
int LOUD
double nSUB
Definition: netcluster.hh:370
wavearray< int > index
size_t csize()
Definition: netcluster.hh:133
string file
Definition: cwb_online.py:385
iD print()
Meyer< double > S(1024, 2)
float subnet
Definition: netcluster.hh:47
float cFreq
Definition: netcluster.hh:58
float skycc
Definition: netcluster.hh:44
std::vector< clusterdata > cData
Definition: netcluster.hh:373
float cTime
Definition: netcluster.hh:57
float netnull
Definition: netcluster.hh:40
float skyChi2
Definition: netcluster.hh:46
netcluster wc
float nDoF
Definition: netcluster.hh:63
double bpp
Definition: netcluster.hh:363
size_t nPIX
Definition: netcluster.hh:367
size_t psize(int k=2)
Definition: netcluster.hh:145
float chirpEllip
Definition: netcluster.hh:71
float netecor
Definition: netcluster.hh:38
float theta
Definition: netcluster.hh:52
std::vector< vector_int > nTofF
Definition: netcluster.hh:386
float netrho
Definition: netcluster.hh:51
void clear()
Definition: netcluster.hh:409