Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CWB_Plugin_HandleWhiteDataWDM.C
Go to the documentation of this file.
1 #define XIFO 4
2 
3 #pragma GCC system_header
4 
5 #include "cwb.hh"
6 #include "config.hh"
7 #include "network.hh"
8 #include "wavearray.hh"
9 #include "TString.h"
10 #include "TObjArray.h"
11 #include "TObjString.h"
12 #include "TRandom.h"
13 #include "Toolbox.hh"
14 #include "watplot.hh"
15 
16 
17 void
19 //!DATA_HANDLING
20 // Plugin to handle whitened input data after its WDM transform (only for 2G analysis !!!)
21 
22 // #define PLOT_WDM_TF // Plot WDM Scalogram
23 // #define DATA_COMPARISON // Compare data before/after WDM data handling
24  #define DATA_HANDLING // example of data handling
25  #define COPY_HANDLED_DATA // copy handled data to into the original x array
26 
27  cout << endl;
28  cout << "-----> CWB_Plugin_HandleWhiteDataWDM.C" << endl;
29  cout << "ifo " << ifo.Data() << endl;
30  cout << "type " << type << endl;
31  cout << endl;
32 
33  if(type==CWB_PLUGIN_WHITE) {
34 
35  if(TString(cfg->analysis)!="2G") {
36  cout << "CWB_Plugin_HandleWhiteDataWDM.C : Error - analysis type must be 2G !!!" << endl;
37  gSystem->Exit(1);
38  }
39 
40  wavearray<double> y = *x; // copy original data to y (contains the final handled data)
41  WSeries<double> w; // temporary array for data manipulation
42  WDM<double>* pwdm = NULL;
43 
44  for(int level=cfg->l_high; level>=cfg->l_low; level--) { // loop over levels
45 
46  int layers = level>0 ? 1<<level : 0; // get layers
47  cout << "level : " << level << " layers : " << layers << endl;
48 
49  pwdm = net->getwdm(layers+1); // get pointer to wdm transform
50  if(pwdm==NULL) {
51  cout << "CWB_Plugin_HandleWhiteDataWDM.C : Error - WDM not defined !!!" << endl;
52  gSystem->Exit(1);
53  }
54 
55  w.Forward(y,*pwdm); // apply wdm transformation
56 
57 #ifdef DATA_HANDLING
58  // example of data handling
59  double R = x->rate();
60 
61  double dF = R/(2*layers); // frequency resolution
62  double dT = layers/R; // time resolution
63 
64  cout << "WDM Decomposition Level : " << w.getLevel()
65  << " dF : " << dF << " Hz " << " dT : " << 1000*dT << " ms " <<endl;
66 
67  // Compute Energy
68  int M = w.getLevel();
69  int L = pwdm->maxLayer();
70  cout << "WDM Decomposition Level : " << M << " Layers " << L << endl;
71 
72  int mF = int(w.size()/pwdm->nSTS);
73  int nTC = w.size()/(M+1)/mF; // # of Time Coefficients
74  // Extract map00 & map90 : size = (M+1)*nTC
75  double* map00 = pwdm->pWWS;
76  double* map90 = map00 + (mF-1)*(M+1)*nTC;
77 
80  double E00=0;
81  double E90=0;
82  // this example show the corrispondence between map00,map90 and xx,XX
83  for(int j=0;j<M+1;j++) { // loop over the layers
84  w.getLayer(xx,j); // extract phase 00 @ layer j
85  w.getLayer(XX,-j); // extract phase 90 @ layer j
86  // for phase 00 -> (xx[i] = map00[i*(M+1)+j])
87  // for phase 90 -> (XX[i] = map90[i*(M+1)+j])
88  for(int i=0;i<xx.size();i++) {
89  //cout << j << " P00 " << xx[i] << " " << map00[i*(M+1)+j]
90  //<< " P90 " << XX[i] << " " << map90[i*(M+1)+j] << endl;
91  }
92  for(int i=0;i<xx.size();i++) E00+=xx[i]*xx[i];
93  for(int i=0;i<XX.size();i++) E90+=XX[i]*XX[i];
94  }
95  cout << "E00 = " << E00 << endl;
96  cout << "E90 = " << E90 << endl;
97 #endif
98 
99 #ifdef PLOT_WDM_TF
100  // Plot WDM Scalogram
101  watplot WTS(const_cast<char*>("wdm"));
102  //scalogram maps
103  double start = w.start();
104  double stop = w.start()+w.size()/w.rate();
105  double flow = 64;
106  double fhigh = 2048;
107  WTS.plot(&w, 2, start, stop,const_cast<char*>("COLZ"));
108  WTS.hist2D->GetYaxis()->SetRangeUser(flow, fhigh);
109  // dump spectrum
110  char fname[1024];
111  sprintf(fname,"%s_wdm_scalogram_%d_lev%d.root", ifo.Data(), int(w.start()),w.getLevel());
112  cout << endl << "Dump WDM Scalogram : " << fname << endl << endl;
113  WTS.canvas->Print(fname);
114 #endif
115 
116  w.Inverse(); // inverse transform
117  y = w; // copy manipulated data to y
118  }
119 
120 #ifdef DATA_COMPARISON
121  // Compare data before/after WDM data handling
123 
124  watplot plot(const_cast<char*>("plot"),200,20,800,500);
125  char gtitle[256];
126  sprintf(gtitle,"WDM : Original(black) - After WDM Forward/Inverse Tranform(Red)");
127  plot.gtitle(gtitle,"time(sec)","amplitude");
128  double start = z.start()+cfg->segEdge;
129  double stop = z.start()+z.size()/z.rate()-cfg->segEdge;
130  plot.goptions("alp", 1, start, stop);
131  // draw signal
132  z-=*x; // difference
133  //*x >> plot;
134  z >> plot;
135 
136  int nEdge = cfg->segEdge*y.rate();
137  double ez=0;
138  for(int i=nEdge;i<(int)y.size()-nEdge;i++) ez+=y[i]*y[i];
139  double ex=0;
140  for(int i=nEdge;i<(int)x->size()-nEdge;i++) ex+=x->data[i]*x->data[i];
141  cout << "Energy of Difference / Energy of Input Data " << ez/ex << endl;
142 
143  //TString gfile=ifo+"_WDM_data_comparison.png"; // save plot the difference to png file
144  TString gfile=ifo+"_WDM_data_comparison.root"; // save plot the difference to root file
145  plot >> gfile;
146 #endif
147 
148 #ifdef COPY_HANDLED_DATA
149  // copy handled data to into the original x array
150  for(int i=0;i<(int)x->size();i++) x->data[i]=y[i];
151 #endif
152  }
153 
154  return;
155 }
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
char analysis[8]
Definition: config.hh:99
virtual size_t size() const
Definition: wavearray.hh:127
void gtitle(TString title="", TString xtitle="", TString ytitle="")
Definition: watplot.cc:1237
virtual void rate(double r)
Definition: wavearray.hh:123
wavearray< double > z
Definition: Test10.C:32
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
TString("c")
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
plot gtitle(gtitle,"frequency (Hz)","strain/#sqrt{Hz}")
int layers
#define M
Definition: UniqSLagsList.C:3
DataType_t * pWWS
Definition: WaveDWT.hh:123
virtual void start(double s)
Definition: wavearray.hh:119
int j
Definition: cwb_net.C:10
#define COPY_HANDLED_DATA
i drho i
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
char ifo[NIFO_MAX][8]
network ** net
NOISE_MDC_SIMULATION.
TH2F * hist2D
Definition: watplot.hh:175
virtual int maxLayer()
Definition: Wavelet.hh:71
WDM< double > * getwdm(size_t M)
param: number of wdm layers
Definition: network.hh:430
wavearray< double > w
Definition: Test1.C:27
double segEdge
Definition: config.hh:146
TCanvas * canvas
Definition: watplot.hh:174
int getLevel()
Definition: wseries.hh:91
x plot
jfile
Definition: cwb_job_obj.C:25
wavearray< double > xx
Definition: TestFrame1.C:11
unsigned long nSTS
Definition: WaveDWT.hh:125
int l_high
Definition: config.hh:138
watplot * WTS
Definition: ChirpMass.C:115
i() int(T_cor *100))
double fhigh
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
Definition: wseries.cc:175
char fname[1024]
void goptions(char *opt=NULL, int col=1, double t1=0., double t2=0., bool fft=false, float f1=0., float f2=0., bool psd=false, float t3=0., bool oneside=false)
Definition: watplot.cc:1202
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
double flow
int l_low
Definition: config.hh:137
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
TString gfile
DataType_t * data
Definition: wavearray.hh:301
double dT
Definition: testWDM_5.C:12
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:273
wavearray< double > y
Definition: Test10.C:31