Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
netpixel.cc
Go to the documentation of this file.
1 //---------------------------------------------------
2 // WAT pixel class for network analysis
3 // S. Klimenko, University of Florida
4 //---------------------------------------------------
5 
6 #define NETPIXEL_CC
7 #include <time.h>
8 #include <iostream>
9 #include <stdexcept>
10 #include "netpixel.hh"
11 
12 using namespace std;
13 
14 ClassImp(netpixel)
15 
16 // constructors
17 
19  theta = phi = -1.;
20  clusterID = time = frequency = 0;
21  rate = 1.; likelihood = 0.; core = false;
22  ellipticity = 0.; polarisation = 0.;
23  data.clear();
24  neighbors.clear();
25 }
26 
28  theta = phi = -1.;
29  clusterID = time = frequency = 0;
30  rate = 1.; likelihood = 0.; core = false;
31  ellipticity = 0.; polarisation = 0.;
32  pixdata pix;
33 
34  data.clear();
35  neighbors.clear();
36  if(!n) return;
37 
38  pix.noiserms = 0; // average noise rms
39  pix.wave = 0; // vector of pixel's wavelet amplitudes
40  pix.w_90 = 0; // vector of pixel's phase shifted wavelet amplitudes
41  pix.asnr = 0; // vector of pixel's whitened amplitudes
42  pix.a_90 = 0; // vector of pixel's phase shifted amplitudes
43  pix.rank = 0; // vector of pixel's rank amplitudes
44  pix.index = 0; // index in the wavearray for other detectors
45 
46  data.push_back(pix);
47  data.reserve(n);
48  for(size_t i=1; i<n; i++) data.push_back(pix);
49 }
50 
51 // netpixel::operator =
53 {
54  this->clusterID = value.clusterID; // cluster ID
55  this->time = value.time; // time index for zero detector (accounts for time shift)
56  this->frequency = value.frequency; // frequency index (layer)
57  this->layers = value.layers; // number of frequency layers
58  this->rate = value.rate; // wavelet layer rate
59  this->likelihood = value.likelihood; // likelihood
60  this->ellipticity = value.ellipticity; // likelihood
61  this->polarisation= value.polarisation;// likelihood
62  this->theta = value.theta; // source angle theta index
63  this->phi = value.phi; // source angle phi index
64  this->core = value.core; // pixel type: true - core , false - halo
65  this->data = value.data; // copy data
66  this->neighbors = value.neighbors; // copy neighbors
67  this->tdAmp = value.tdAmp; // copy TD vectors
68 
69  return *this;
70 }
71 
72 // write pixel in file
73 bool netpixel::write(const FILE *fp)
74 {
75  size_t i,j;
76  size_t n = this->neighbors.size();
77  size_t m = this->data.size();
78  size_t k = this->tdAmp.size();
79  size_t I = n ? n : 1;
80 
81  k = (k==m) ? this->tdAmp[0].size() : 0;
82 
83  double db[14];
84  wavearray<double> wb(I+m*(7+k));
85 
86  // write metadata
87 
88  db[0] = (double)m; // number of detectors
89  db[1] = (double)I; // number of neighbors
90  db[2] = (double)this->clusterID; // cluster ID
91  db[3] = this->time; // time index for zero detector (accounts for time shift)
92  db[4] = this->frequency; // frequency index (layer)
93  db[5] = this->core ? 1. : 0.; // pixel type: true - core , false - halo
94  db[6] = this->rate; // wavelet layer rate
95  db[7] = this->likelihood; // likelihood
96  db[8] = this->theta; // source angle theta index
97  db[9] = this->phi; // source angle phi index
98  db[10]= this->ellipticity; // waveform ellipticity
99  db[11]= this->polarisation; // waveform polarisation
100  db[12]= this->layers; // number of layers
101  db[13] = (double)k; // number of TD amplitudes per detector
102 
103  if(fwrite(db, 14*sizeof(double), 1, (FILE*)fp)!=1) return false;
104 
105  // write neighbors
106  for(i=0; i<I; i++) wb.data[i] = n ? neighbors[i] : 0.;
107 
108  // write amplitudes
109  for(i=0; i<m; i++) {
110  wb.data[I++] = this->data[i].noiserms; // average noise rms
111  wb.data[I++] = this->data[i].wave; // vector of pixel's wavelet amplitudes
112  wb.data[I++] = this->data[i].w_90; // vector of pixel's wavelet amplitudes
113  wb.data[I++] = this->data[i].asnr; // vector of pixel's whitened amplitudes
114  wb.data[I++] = this->data[i].a_90; // vector of pixel's phase shifted amplitudes
115  wb.data[I++] = (double)this->data[i].rank; // vector of pixel's rank amplitudes
116  wb.data[I++] = (double)this->data[i].index; // index in wavearray
117  }
118 
119  // write TD amplitudes
120  for(i=0; i<m; i++)
121  for(j=0; j<k; j++)
122  wb.data[I++] = (double)this->tdAmp[i].data[j];
123 
124  if(fwrite(wb.data, I*sizeof(double), 1, (FILE*)fp)!=1) return false;
125  return true;
126 }
127 
128 // read pixel from file
129 bool netpixel::read(const FILE *fp)
130 {
131  size_t i;
132  int j;
133  pixdata pix;
134  double db[14];
135 
136  this->clear();
137 
138  // read metadata
139  if(fread(db, 14*sizeof(double), 1, (FILE*)fp)!=1) return false;
140 
141  this->clusterID = size_t(db[2]+0.1); // cluster ID
142  this->time = size_t(db[3]+0.1); // time index for zero detector
143  this->frequency = size_t(db[4]+0.1); // frequency index (layer)
144  this->core = db[5]>0. ? true : false; // pixel type: true - core , false - halo
145  this->rate = (float)db[6]; // wavelet layer rate
146  this->likelihood = (float)db[7]; // likelihood
147  this->theta = (float)db[8]; // source angle theta index
148  this->phi = (float)db[9]; // source angle phi index
149  this->ellipticity = (float)db[10]; // waveform ellipticity
150  this->polarisation = (float)db[11]; // waveform polarisation
151  this->layers = size_t(db[12]+0.1); // number of layers
152 
153  size_t m = size_t(db[0]+0.1); // number of detectors
154  size_t I = size_t(db[1]+0.1); // neighbor size
155  size_t k = size_t(db[13]+0.1); // number TD amplitudes per detector
156  size_t n = I + m*(7+k); // buffer size
157  wavearray<double> wb(n);
158  wavearray<float> tda(k);
159 
160  if(fread(wb.data, n*sizeof(double), 1, (FILE*)fp)!=1) return false;
161 
162  // get neighbors
163  for(i=0; i<I; i++) {
164  j = wb.data[i]<0. ? int(wb.data[i]-0.1) : int(wb.data[i]+0.1);
165  if(j) this->neighbors.push_back(j);
166  }
167 
168  // get data
169  for(i=0; i<m; i++) {
170  pix.noiserms = wb.data[I++]; // average noise rms
171  pix.wave = wb.data[I++]; // vector of pixel's wavelet amplitudes
172  pix.w_90 = wb.data[I++]; // vector of pixel's wavelet amplitudes
173  pix.asnr = wb.data[I++]; // vector of pixel's whitened amplitudes
174  pix.a_90 = wb.data[I++]; // vector of pixel's phase shifted amplitudes
175  pix.rank = float(wb.data[I++]); // vector of pixel's rank amplitudes
176  pix.index = int(wb.data[I++]+0.1); // index in wavearray
177  this->data.push_back(pix);
178  }
179 
180  // get TD amplitudes
181  for(i=0; i<m; i++) {
182  for(j=0; j<(int)k; j++) {
183  tda.data[j] = float(wb.data[I++]);
184  }
185  if(k) this->tdAmp.push_back(tda);
186  }
187 
188  return true;
189 }
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
float phi
Definition: netpixel.hh:99
par[0] value
float rank
Definition: netpixel.hh:22
size_t clusterID
Definition: netpixel.hh:91
std::vector< wavearray< float > > tdAmp
Definition: netpixel.hh:105
float * rank
size_t frequency
Definition: netpixel.hh:93
float likelihood
Definition: netpixel.hh:96
int n
Definition: cwb_net.C:10
std::vector< int > neighbors
Definition: netpixel.hh:106
double frequency
std::vector< pixdata > data
Definition: netpixel.hh:104
float theta
netpixel pix(nifo)
int layers
STL namespace.
Long_t size
size_t layers
Definition: netpixel.hh:94
int m
Definition: cwb_net.C:10
int j
Definition: cwb_net.C:10
i drho i
bool write(const FILE *)
Definition: netpixel.cc:73
wc clear()
double asnr
Definition: netpixel.hh:20
bool core
Definition: netpixel.hh:102
double w_90
Definition: netpixel.hh:19
float phi
double time[6]
Definition: cbc_plots.C:435
double wave
Definition: netpixel.hh:18
i() int(T_cor *100))
float polarisation
Definition: netpixel.hh:101
int index
Definition: netpixel.hh:23
void clear()
Definition: netpixel.hh:75
int k
size_t time
Definition: netpixel.hh:92
netpixel()
Definition: netpixel.cc:18
float ellipticity
Definition: netpixel.hh:100
double noiserms
Definition: netpixel.hh:17
wavearray< int > index
float theta
Definition: netpixel.hh:98
bool read(const FILE *)
Definition: netpixel.cc:129
DataType_t * data
Definition: wavearray.hh:301
float rate
Definition: netpixel.hh:95
double a_90
Definition: netpixel.hh:21
netpixel & operator=(const netpixel &)
Definition: netpixel.cc:52