Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Test7.C
Go to the documentation of this file.
1 //Test 7: One witness channel with a little uncorrelated noise, other with more
2 //Generate white noise time series w(t), x(t), y(t), z(t)
3 //Witness channels: A(t) = 0.6*y(t) + w(t)
4 // B(t) = z(t) + 0.5*w(t)
5 //Target channel: H(t) = x(t) + 0.8*w(t)
6 //Hopefully, the code figures out that it should use A(t) and ignore B(t). The net
7 //reduction in noise should be the same as Test 2 above.
8 //* Try this with hard, soft, and mild regulators *
9 
10 {
11  //Time
12  #define LENGHT 1200
13  #define SCRATCH 32
14  #define RATE 2048
15 
16  using namespace CWB;
17 
18  //define x channel properties -> gauss 1
19  int N = RATE*(LENGHT+2*SCRATCH);
21  x.rate(RATE);
22  x.resize(N);
23  x.start(0);
24  x.stop(LENGHT+2*SCRATCH);
25 
26  //define w channel properties -> gauss 2
30 
31  // time series is filled with white noise data:
32  TRandom3 rnd(0);
33  for(int i=0; i<N; i++) x[i] = rnd.Gaus();
34  for(int i=0; i<N; i++) w[i] = rnd.Gaus();
35  for(int i=0; i<N; i++) y[i] = rnd.Gaus();
36  for(int i=0; i<N; i++) z[i] = rnd.Gaus();
37 
38  //Fill target and witness
39  wavearray<double> A = w; y*= 0.6; A += y;
40  wavearray<double> w_1 = w; w_1*= 0.5;
41  wavearray<double> B = w_1; B += z;
42  wavearray<double> H = x; w*= 0.8; H += w;
43 
44  //Make WDM transform, resolution = 1Hz
45  int lev=H.rate()/2;
46  WDM<double> wdtf(lev, 2*lev, 6, 10);
48  tfmap.Forward(H, wdtf);
49 
50  //Adding target channel
51  regression r;
52  r.add(tfmap,const_cast<char*>("hchannel"));
53 
54  //Adding witness channel
55  r.add(A,const_cast<char*>("witness"));
56  r.add(B,const_cast<char*>("witness"));
57 
58  regression r_s = r;
59  regression r_m = r;
60 
61  //Calculate prediction
62  r.setFilter(5);
63  r.setMatrix(SCRATCH);
64  r.solve(0, 20, 'h');
65  r.apply(0.2);
66 
67  wavearray<double> clean=r.getClean();
68 
69  cout << "HARD:" << endl;
70  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
71 
72  cout << "x : " << x.mean() << " " << x.rms() << endl;
73  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
74  clean -= x;
75  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
76  cout << "-------------------" << endl;
77 
78  //Calculate prediction
79  r_s.setFilter(5);
80  r_s.setMatrix(SCRATCH);
81  r_s.solve(0, 20, 's');
82  r_s.apply(0.2);
83 
84  clean=r_s.getClean();
85 
86  cout << "SOFT:" << endl;
87  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
88 
89  cout << "x : " << x.mean() << " " << x.rms() << endl;
90  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
91  clean -= x;
92  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
93  cout << "-------------------" << endl;
94 
95  //Calculate prediction
96  r_m.setFilter(5);
97  r_m.setMatrix(SCRATCH);
98  r_m.solve(0, 20, 'm');
99  r_m.apply(0.2);
100 
101  clean=r_m.getClean();
102 
103  cout << "MILD:" << endl;
104  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
105 
106  cout << "x : " << x.mean() << " " << x.rms() << endl;
107  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
108  clean -= x;
109  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
110  cout << "-------------------" << endl;
111 
112  wavearray<double> eigen=r.getVEIGEN(-1);
113  eigen.rate(22);
114  watplot plot;
115  TCanvas *c1 = plot.canvas;
116  c1->SetCanvasSize(1600,800);
117  c1->Divide(1,2);
118 
119  c1->cd(1);
120  plot.plot(eigen,const_cast<char*>("alp"),1);
121  plot.graph[0]->SetTitle("Eigen-values of all layers");
122 
123  c1->cd(2);
124  TPad* P=(TPad*)c1->GetPad(2);
125  P->Divide(3,1);
126 
127  wavearray<double> freq=r.vfreq;
129  wavearray<double> rank1=r.getRank(1);
130  wavearray<double> rank2=r.getRank(2);
131  P->cd(1);
132  TMultiGraph* mg=new TMultiGraph();
133  TGraph* g=new TGraph(freq.size(),freq.data,rank.data);
134  g->SetLineColor(1);
135  mg->Add(g);
136  TGraph* g1=new TGraph(freq.size(),freq.data,rank1.data);
137  g1->SetLineColor(2);
138  mg->Add(g1);
139  TGraph* g2=new TGraph(freq.size(),freq.data,rank2.data);
140  g2->SetLineColor(3);
141  mg->Add(g2);
142  mg->Draw(const_cast<char*>("alp"));
143  mg->SetTitle("HARD: Ranking for all layers");
144 
145  wavearray<double> freq_s=r_s.vfreq;
146  wavearray<double> rank_s=r_s.getRank(0);
147  wavearray<double> rank1_s=r_s.getRank(1);
148  wavearray<double> rank2_s=r_s.getRank(2);
149  P->cd(2);
150  TMultiGraph* mg_s=new TMultiGraph();
151  TGraph* g_s=new TGraph(freq_s.size(),freq_s.data,rank_s.data);
152  g_s->SetLineColor(1);
153  mg_s->Add(g_s);
154  TGraph* g1_s=new TGraph(freq_s.size(),freq_s.data,rank1_s.data);
155  g1_s->SetLineColor(2);
156  mg_s->Add(g1_s);
157  TGraph* g2_s=new TGraph(freq_s.size(),freq_s.data,rank2_s.data);
158  g2_s->SetLineColor(3);
159  mg_s->Add(g2_s);
160  mg_s->Draw(const_cast<char*>("alp"));
161  mg_s->SetTitle("SOFT: Ranking for all layers");
162 
163  wavearray<double> freq_m=r_m.vfreq;
164  wavearray<double> rank_m=r_m.getRank(0);
165  wavearray<double> rank1_m=r_m.getRank(1);
166  wavearray<double> rank2_m=r_m.getRank(2);
167  P->cd(3);
168  TMultiGraph* mg_m=new TMultiGraph();
169  TGraph* g_m=new TGraph(freq_m.size(),freq_m.data,rank_m.data);
170  g_m->SetLineColor(1);
171  mg_m->Add(g_m);
172  TGraph* g1_m=new TGraph(freq_m.size(),freq_m.data,rank1_m.data);
173  g1_m->SetLineColor(2);
174  mg_m->Add(g1_m);
175  TGraph* g2_m=new TGraph(freq_m.size(),freq_m.data,rank2_m.data);
176  g2_m->SetLineColor(3);
177  mg_m->Add(g2_m);
178  mg_m->Draw(const_cast<char*>("alp"));
179  mg_m->SetTitle("MILD: Ranking for all layers");
180 
181  c1->SaveAs("Test7.png");
182 
183  exit(0);
184 
185 }
virtual size_t size() const
Definition: wavearray.hh:127
wavearray< double > y
Definition: Test7.C:28
TF1 * g2
Definition: slag.C:248
static double g(double e)
Definition: GNGen.cc:98
void setMatrix(double edge=0., double f=1.)
Definition: regression.cc:407
wavearray< double > x
Definition: Test7.C:20
Definition: ced.hh:24
virtual void rate(double r)
Definition: wavearray.hh:123
float * rank
#define B
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
std::vector< TGraph * > graph
Definition: watplot.hh:176
TRandom3 P
Definition: compare_bkg.C:296
wavearray< double > w
Definition: Test7.C:27
size_t add(WSeries< double > &target, char *name, double fL=0., double fH=0.)
Definition: regression.cc:73
virtual void start(double s)
Definition: wavearray.hh:119
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
wavearray< double > z
Definition: Test7.C:29
virtual double mean() const
Definition: wavearray.cc:1053
TRandom3 rnd(0)
virtual double rms()
Definition: wavearray.cc:1188
TCanvas * canvas
Definition: watplot.hh:174
x plot
#define SCRATCH
TCanvas * c1
TF1 * g1
Definition: compare_bkg.C:505
void apply(double threshold=0., char c='a')
Definition: regression.cc:691
wavearray< double > getRank(int n)
Definition: regression.hh:134
WSeries< double > tfmap
void solve(double th, int nE=0, char c='s')
Definition: regression.cc:592
wavearray< double > vfreq
Definition: regression.hh:171
static double A
Definition: geodesics.cc:8
size_t setFilter(size_t)
Definition: regression.cc:258
wavearray< double > getVEIGEN(int n=-1)
Definition: regression.cc:339
wavearray< double > getClean()
Definition: regression.hh:117
regression r
Definition: Regression_H1.C:44
WDM< double > wdtf(lev, 2 *lev, 6, 10)
int N
Definition: Test7.C:19
#define LENGHT
virtual void stop(double s)
Definition: wavearray.hh:121
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
DataType_t * data
Definition: wavearray.hh:301
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:445
TMultiGraph * mg
#define RATE
exit(0)