3 #pragma GCC system_header
10 #include "TObjArray.h"
11 #include "TObjString.h"
34 cout <<
"-----> CWB_Plugin_Linear_Bilinear_Regression.C : " << ifo.Data() << endl;
38 sprintf(cmd,
"int type = %d;",type);
39 gROOT->ProcessLine(cmd);
40 sprintf(cmd,
"network* net = (network*)%p;",net);
41 gROOT->ProcessLine(cmd);
47 bool EXIT_AFTER_REGRESSION =
true;
110 IMPORT(
bool,EXIT_AFTER_REGRESSION)
111 IMPORT(
bool,APPLY_LINEAR_REGRESSION)
112 IMPORT(
bool,APPLY_BILINEAR_REGRESSION)
114 IMPORT(
bool,SAVE_OUTFRAME)
115 IMPORT(
bool,SAVE_PSD_PLOT)
116 IMPORT(
bool,SAVE_EIGEN_PLOT)
118 IMPORT(
bool,DISABLE_MDC_FROM_FRAMES)
119 IMPORT(
bool,DISABLE_MDC_FROM_PLUGIN)
120 IMPORT(
int,RESAMPLING_INDEX)
132 if(FRLIST_WITNESS==
"") {cout <<
"Error : witness frames list not defined" << endl;gSystem->Exit(1);}
133 if(CHLIST_LINEAR==
"") {cout <<
"Error : linear witness channels list not defined" << endl;gSystem->Exit(1);}
134 if(CHLIST_BILINEAR==
"") {cout <<
"Error : bilinear witness channels list not defined" << endl;gSystem->Exit(1);}
135 if(CHNAME_LINEAR==
"") {cout <<
"Error : main linear witness channel list not defined" << endl;gSystem->Exit(1);}
136 if(FRNAME==
"") {cout <<
"Error : frame name not defined" << endl;gSystem->Exit(1);}
137 if(FRLABEL==
"") {cout <<
"Error : frame label not defined" << endl;gSystem->Exit(1);}
139 IMPORT(
double,LAYER_WIDTH)
146 IMPORT(
double,L_APPLY_THRESHOLD)
147 IMPORT(
double,L_SOLVE_THRESHOLD)
148 IMPORT(
double,L_SOLVE_NEIGEN_PER_LAYER)
149 IMPORT(
char,L_SOLVE_REGULATOR)
152 IMPORT(
double,B_APPLY_THRESHOLD)
153 IMPORT(
double,B_SOLVE_THRESHOLD)
154 IMPORT(
double,B_SOLVE_NEIGEN_PER_LAYER)
155 IMPORT(
char,B_SOLVE_REGULATOR)
157 if(!APPLY_LINEAR_REGRESSION && !APPLY_BILINEAR_REGRESSION) {
158 cout <<
"Error : regression type [linear/bilinear] is not defined" << endl;
169 if(DISABLE_MDC_FROM_PLUGIN) {*x=0.;
return;}
196 if(ifo.CompareTo(net->
ifoName[0])==0) {
207 for(
int k=0;
k<(
int)net->
mdcTime.size();
k++) cout <<
k <<
" mdcTime " << MDC.
mdcTime[
k] << endl;
208 for(
int k=0;
k<(
int)net->
mdcType.size();
k++) cout <<
k <<
" mdcType " << MDC.
mdcType[
k] << endl;
219 for(
int n=0;
n<cfg->
nIFO;
n++)
if(ifo==cfg->
ifo[
n]) {xIFO=
n;
break;}
221 int runID = net->
nRun;
244 while (((SR % 2) == 0) && SR > 2*
CUT_LOW_FREQ) {SR /= 2;mm++;}
249 cout <<
"Set Frequency Range [0:" << SR/2 <<
"] = 0" << endl;
262 if(scratch>cfg->
segEdge+0.001) {
264 cout <<
"Regression Plugin : Error - filter scratch must be <= cwb scratch!!!" << endl;
265 cout <<
"filter scratch : " << scratch <<
" sec" << endl;
266 cout <<
"cwb scratch : " << cfg->
segEdge <<
" sec" << endl;
276 if(APPLY_LINEAR_REGRESSION) {
278 cout <<
"CWB_PLUGIN_DATA_MDC : Apply Linear Regression ..." << endl;
280 frame frl(FRLIST_WITNESS,
"",
"README",
true);
284 size = rr.
add(wT,
"target");
285 if(size==0) {cout <<
"Regression Plugin - empty target channel" << endl;gSystem->Exit(1);}
291 ifl.open(CHLIST_LINEAR.Data(),
ios::in);
292 if (!ifl.good()) {cout <<
"Error Opening File : " << CHLIST_LINEAR.Data() << endl;gSystem->Exit(1);}
298 if (!ifl.good())
break;
299 if(linear[0]==
'#')
continue;
300 cout <<
"read linear channel : \t" << linear << endl;
310 rr.
solve(L_SOLVE_THRESHOLD,L_SOLVE_NEIGEN_PER_LAYER,L_SOLVE_REGULATOR);
311 rr.
apply(L_APPLY_THRESHOLD);
313 if(SAVE_EIGEN_PLOT) {
314 gROOT->SetBatch(
true);
320 sprintf(gtitle,
"Linear Regression Filter eigenvalues");
321 eplot.
gtitle(gtitle,
"filter index",
"eigenvalue");
324 sprintf(ofName,
"%s/eigen_linear_regression_%s_%s.png",cfg->
dump_dir,ifo.Data(),flabel);
325 cout <<
"write results to " << ofName << endl;
328 eigen >> eplot; eplot >>
gfile;
336 if(APPLY_BILINEAR_REGRESSION) {
338 cout <<
"CWB_PLUGIN_DATA_MDC : Apply Bilinear Regression ..." << endl;
343 size=rr.
add(wT,
"target");
344 if(size==0) {cout <<
"Regression Plugin - empty target channel" << endl;gSystem->Exit(1);}
350 cout <<
"read main linear channel : \t" << CHNAME_LINEAR.Data() << endl << endl;
353 frame frb(FRLIST_WITNESS,
"",
"README",
true);
358 if(size==0) {cout <<
"Regression Plugin - empty main linear channel" << endl;gSystem->Exit(1);}
362 iwb.open(CHLIST_BILINEAR.Data(),
ios::in);
363 if (!iwb.good()) {cout <<
"Error Opening File : " << CHLIST_BILINEAR.Data() << endl;gSystem->Exit(2);}
372 if (!iwb.good())
break;
373 if(bilinear[0]==
'#')
continue;
374 cout <<
"read bilinear channel : \t" << bilinear << endl;
378 if(!rr.
add(wb,bilinear,WFLOW,WFHIGH))
continue;
383 for(
int n=2;
n<=nBILINEAR+1;
n++) rr.
add(1,
n,
"bilinear");
384 for(
int n=1;
n<=nBILINEAR+1;
n++) rr.
mask(
n);
388 rr.
solve(B_SOLVE_THRESHOLD,B_SOLVE_NEIGEN_PER_LAYER,B_SOLVE_REGULATOR);
389 rr.
apply(B_APPLY_THRESHOLD);
392 if(SAVE_EIGEN_PLOT) {
393 gROOT->SetBatch(
true);
399 sprintf(gtitle,
"Linear Regression Filter eigenvalues");
400 eplot.
gtitle(gtitle,
"filter index",
"eigenvalue");
403 sprintf(ofName,
"%s/eigen_bilinear_regression_%s_%s.png",cfg->
dump_dir,ifo.Data(),flabel);
404 cout <<
"write results to " << ofName << endl;
407 eigen >> eplot; eplot >>
gfile;
415 gROOT->SetBatch(
true);
429 sprintf(gtitle,
"Dirty/Cleaned Data %s - %3.0f-%3.0f Hz",
431 plot.
gtitle(gtitle,
"frequency (Hz)",
"strain/#sqrt{Hz}");
432 plot.
goptions(
"alp logy", 1, tstart, tstop,
true, flow,fhigh,
true, 32);
435 cout <<
"write results to " << ofName << endl;
466 sprintf(ofName,
"%s/I-%s-%lu-%lu.gwf",
468 cout <<
"write frame file " << ofName << endl;
469 frame xfr(ofName,chName,
"WRITE");
499 sprintf(ofName,
"%s/R-%s-%lu-%lu.gwf",
501 cout <<
"write frame file " << ofName << endl;
502 frame cfr(ofName,chName,
"WRITE");
509 if(EXIT_AFTER_REGRESSION) {
511 if(ifo==cfg->
ifo[xIFO]) {
512 cout <<
"remove temporary file ..." << endl;
514 jname.ReplaceAll(
":/",
"");
515 cout << jname.Data() << endl;
516 gSystem->Exec(
TString(
"rm "+jname).Data());
517 cout <<
"end job" << endl;
std::vector< char * > ifoName
double L_SOLVE_NEIGEN_PER_LAYER
virtual size_t size() const
void gtitle(TString title="", TString xtitle="", TString ytitle="")
void setMatrix(double edge=0., double f=1.)
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
TString Get(wavearray< double > &x, TString ifo)
std::vector< std::string > mdcList
virtual void rate(double r)
bool APPLY_BILINEAR_REGRESSION
void setFrName(TString frName)
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
double B_SOLVE_NEIGEN_PER_LAYER
std::vector< std::string > mdcType
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}")
std::vector< std::string > mdcType
size_t add(WSeries< double > &target, char *name, double fL=0., double fH=0.)
virtual void start(double s)
std::vector< double > mdcTime
network ** net
NOISE_MDC_SIMULATION.
void setChName(TString chName)
#define IMPORT(TYPE, VAR)
std::vector< std::string > mdcList
void apply(double threshold=0., char c='a')
bool APPLY_LINEAR_REGRESSION
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
char channelNamesRaw[NIFO_MAX][50]
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)
bool DISABLE_MDC_FROM_PLUGIN
void solve(double th, int nE=0, char c='s')
void setSRIndex(int srIndex)
wavearray< double > getVEIGEN(int n=-1)
wavearray< double > getClean()
virtual void stop(double s)
bool DISABLE_MDC_FROM_FRAMES
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
void unmask(int n, double flow=0., double fhigh=0.)
void mask(int n, double flow=0., double fhigh=0.)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
std::vector< double > mdcTime
virtual void resize(unsigned int)
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
void putLayer(wavearray< DataType_t > &, double n)
param: n - layer number