Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SSeriesExample.C
Go to the documentation of this file.
1 {
2  // show how the sparse map SSeries works
3 
4  //#define TEST_WRITE_READ_SPARSE_MAP
5  #define nLAYERS 32
6  #define RATE 512
7  #define DURATION 2
8 
9  int nifo=1;
10 
11  char title[256];
12 
13  // create watplot
15  TCanvas* canvas = plot->canvas;
16  canvas->Divide(2,2);
17 
18  // define wavearray time series
19  int Rate = RATE; // sampling rate (Hz)
20  int Duration = DURATION; // duration (seconds)
21  int N = Rate*Duration; // number of samples
22  wavearray<double> ts(N); // time series container
23  ts.rate(Rate); // set rate
24  ts=0; // set array to zero
25 
26  // time series is filled with SG100Q9:
27  double Q=9.;
28  double amplitude=1.;
29  double frequency=100.;
30  double duration = Q/(TMath::TwoPi()*frequency);
31  CWB::mdc::AddSGBurst(ts,amplitude, frequency, duration,0);
32 
33  // plot waveform
34  gwavearray<double> gts(&ts);
35  gts.Draw(GWAT_TIME);
36 
37  // produce the TF map:
38  WDM<double> wdm(nLAYERS, 2*nLAYERS, 4, 8); // define a WDM transform (32 bands)
39  WSeries<double> tfmap; // TF map container
40  tfmap.Forward(ts, wdm); // apply the WDM to the time series
41 
42  // compute dfxdt pixel resolution
43  double df = tfmap.resolution(); // frequency bin resolution (hz)
44  double dt = 1./(2*df); // time bin resolution (sec)
45  char tfres[64]; sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)",2*df,df);
46 
47  // plot the TF map as energy average of 0 and 90 degree phases (quadratures)
48  canvas->cd(1);
49  gPad->SetGridx(); gPad->SetGridy();
50  plot->plot(tfmap);
51  plot->hist2D->SetName("Sparse-1");;
52  sprintf(title,"%s - Res : %s","TF Map : Signal",tfres);
53  plot->hist2D->SetTitle(title);;
54 
55  // add white noise data:
56  TRandom3 rnd(1);
57  for(int i=0; i<N; i++) ts[i] += rnd.Gaus();
58  tfmap.Forward(ts, wdm); // apply the WDM to the time series
59  // plot the TF map as energy average of 0 and 90 degree phases (quadratures)
60  canvas->cd(2);
61  gPad->SetGridx(); gPad->SetGridy();
62  plot->hist2D=NULL;
63  plot->plot(tfmap);
64  plot->hist2D->SetName("Sparse-2");;
65  sprintf(title,"%s - Res : %s","TF Map : Signal + Noise",tfres);
66  plot->hist2D->SetTitle(title);;
67 
68  int layers = tfmap.maxLayer()+1; // numbers of frequency bins (first & last bins have df/2)
69  int slices = tfmap.sizeZero(); // number of time bins
70 
71  // create netpixel
72  netpixel pix(nifo);
73  pix.core = true;
74  pix.rate = tfmap.wrate();
75  pix.layers = layers;
76 
77  // create netcluster
78  netcluster wc;
79  wc.clear();
80  wc.setlow(0);
81  wc.sethigh(Rate/2.);
82  wc.start = tfmap.start();
83  wc.stop = tfmap.stop();
84  wc.rate = tfmap.rate();
85 
86  // fill netcluster with netpixels over the threshold
87  int ifoID=0;
88  int nPix=0;
89  double THRESHOLD = 4;
90  for(int i=0;i<slices;i++) {
91  for(int j=0;j<layers;j++) {
92  float A00 = tfmap.getSample(i,j+0.01); // phase 00 amplitude
93  float A90 = tfmap.getSample(i,-(j+0.01)); // phase 90 amplitude
94  // compute energy average of 0 and 90 degree phases (quadratures)
95  double EE = sqrt((A00*A00+A90*A90)/2);
96  // select pixels above the THRESHOLD
97  if(EE>THRESHOLD) {
98  //cout << i << " " << j << " " << EE << endl;
99  // fill netpixel
100  int index = i*layers+j; // sample index
101  pix.data[ifoID].index = index;
102  pix.data[ifoID].asnr = A00;
103  pix.time = index;
104  pix.frequency = j;
105  wc.append(pix); // save pixels in wc
106  nPix++;
107  }
108  }
109  }
110  cout << "Selected Pixels : " << nPix << endl;
111 
112  wc.cluster(1,1); // cluster pixels
113 
114  // create sseries and fill with netcluster
116  ss.SetMap(&tfmap); // associate tfmap to ss
117  double mTau = 0.040;
118  ss.SetHalo(mTau); // set halo
119  ss.AddCore(ifoID,&wc); // add core pixels
120  ss.UpdateSparseTable(); // update sparse map
121  ss.Shrink(); // resize to 0 the TF map : leave only the sparse map tables
122  wc.clear(); // clear netcluster
123 
124  // compute sparse statistic
125  int ncore=0; // core pixels
126  int ncluster=0; // core+halo pixels
127  int ccluster=0; // core+halo pixels associated to each core pixel
128  ncore=ss.GetSparseSize();
129  ncluster=ss.GetSparseSize(0);
130  ccluster = 2*(ss.GetHaloSlice()+ss.GetHaloSlice(true))+1;
131  ccluster*= 2*ss.GetHaloLayer()+1;
132  cout << "ncore : " << ncore << endl;
133  cout << "ncluster : " << ncluster << endl;
134  cout << "ccluster : " << ccluster << endl;
135 
136 #ifdef TEST_WRITE_READ_SPARSE_MAP
137  // write sparse map to root file
138  TFile ofile("SparseMapTest.root","RECREATE");
139  ss.Write("sparseMap");
140  ofile.Close();
141 
142  // read sparse map from root file
143  TFile ifile("SparseMapTest.root");
144  SSeries<double>* pss = (SSeries<double>*)ifile.Get("sparseMap");
145  ss = *pss;
146  delete pss;
147  ifile.Close();
148 #endif
149 
150  // rebuild wseries from sparse table only with core pixels
151  bool core = true;
152  ss.Expand(core);
153  // plot the TF ss map as energy average of 0 and 90 degree phases (quadratures)
154  canvas->cd(3);
155  gPad->SetGridx(); gPad->SetGridy();
156  plot->hist2D=NULL;
157  plot->plot(ss);
158  plot->hist2D->SetName("Sparse-3");;
159  sprintf(title,"%s - Res : %s","TF Map : Core Pixels",tfres);
160  plot->hist2D->SetTitle(title);;
161 
162  // rebuild wseries from sparse table with core+halo pixels
163  core = false;
164  ss.Expand(core);
165  // plot the TF ss map as energy average of 0 and 90 degree phases (quadratures)
166  canvas->cd(4);
167  gPad->SetGridx(); gPad->SetGridy();
168  plot->hist2D=NULL;
169  plot->plot(ss);
170  plot->hist2D->SetName("Sparse-4");;
171  sprintf(title,"%s - Res : %s","TF Map : Core + Halo Pixels",tfres);
172  plot->hist2D->SetTitle(title);;
173 
174  // apply inverse transform and plot recovered waveform vs original waveform
175  ss.Inverse();
176  gts.GetWATPLOT()->canvas->cd();
177  gts.Draw(&ss,GWAT_TIME,"SAME",kRed);
178 
179  return canvas;
180 }
double stop
Definition: netcluster.hh:362
int slices
WSeries< double > tfmap
int Duration
virtual void rate(double r)
Definition: wavearray.hh:123
double THRESHOLD
size_t frequency
Definition: netpixel.hh:93
double amplitude
std::vector< pixdata > data
Definition: netpixel.hh:104
netpixel pix(nifo)
double Q
int layers
void UpdateSparseTable()
Definition: sseries.cc:258
watplot * plot
size_t layers
Definition: netpixel.hh:94
WDM< double > wdm(nLAYERS, 2 *nLAYERS, 4, 8)
virtual void start(double s)
Definition: wavearray.hh:119
char ofile[512]
int j
Definition: cwb_net.C:10
i drho i
double rate
Definition: netcluster.hh:360
TRandom3 rnd(1)
wavearray< double > ts(N)
int ncore
void plot(wavearray< double > &, char *=NULL, int=1, double=0., double=0., bool=false, float=0., float=0., bool=false, float=0., bool=false)
Definition: watplot.cc:132
TCanvas * canvas
bool core
Definition: netpixel.hh:102
void setlow(double f)
Definition: netcluster.hh:327
TH2F * hist2D
Definition: watplot.hh:175
cout<< "Selected Pixels : "<< nPix<< endl;wc.cluster(1, 1);SSeries< double > ss
void SetMap(WSeries< DataType_t > *pws)
Definition: sseries.hh:57
void wrate(double r)
Definition: wseries.hh:102
#define RATE
TCanvas * canvas
Definition: watplot.hh:174
int ccluster
core
void Shrink()
Definition: sseries.hh:98
virtual size_t cluster()
return number of clusters
Definition: netcluster.cc:450
double dt
void sethigh(double f)
Definition: netcluster.hh:328
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double duration
double start
Definition: netcluster.hh:361
int GetSparseSize(bool bcore=true)
Definition: sseries.cc:317
virtual size_t append(netcluster &wc)
param: input netcluster return size of appended pixel list
Definition: netcluster.cc:750
size_t time
Definition: netpixel.hh:92
TFile * ifile
char tfres[64]
int ncluster
#define nLAYERS
int GetHaloLayer()
Definition: sseries.hh:69
int nifo
char title[256]
Definition: SSeriesExample.C:1
int Rate
void Expand(bool bcore=true)
Definition: sseries.cc:397
int GetHaloSlice(bool eslice=false)
Definition: sseries.hh:67
#define DURATION
wavearray< int > index
void SetHalo(double maxTau=0.042, int lHalo=1, int tHalo=-1)
Definition: sseries.cc:225
virtual void stop(double s)
Definition: wavearray.hh:121
double resolution(int=0)
Definition: wseries.hh:137
double mTau
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
void AddCore(size_t ifoID, netcluster *pwc, int ID=0)
Definition: sseries.cc:185
netcluster wc
DataType_t getSample(int n, double m)
Definition: wseries.hh:167
float rate
Definition: netpixel.hh:95
double df
int N
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:273
size_t sizeZero()
Definition: wseries.hh:126
int maxLayer()
Definition: wseries.hh:121
static void AddSGBurst(wavearray< double > &td, double a, double f, double s, double d=0.)
Definition: mdc.cc:3250
double frequency
void clear()
Definition: netcluster.hh:409