21 #pragma GCC system_header 28 #include "TObjArray.h" 29 #include "TObjString.h" 52 cout <<
"-----> CWB_Plugin_Linear_Bilinear_Regression.C : " << ifo.Data() << endl;
56 sprintf(cmd,
"int type = %d;",type);
57 gROOT->ProcessLine(cmd);
58 sprintf(cmd,
"network* net = (network*)%p;",net);
59 gROOT->ProcessLine(cmd);
65 bool EXIT_AFTER_REGRESSION =
true;
128 IMPORT(
bool,EXIT_AFTER_REGRESSION)
129 IMPORT(
bool,APPLY_LINEAR_REGRESSION)
130 IMPORT(
bool,APPLY_BILINEAR_REGRESSION)
132 IMPORT(
bool,SAVE_OUTFRAME)
133 IMPORT(
bool,SAVE_PSD_PLOT)
134 IMPORT(
bool,SAVE_EIGEN_PLOT)
136 IMPORT(
bool,DISABLE_MDC_FROM_FRAMES)
137 IMPORT(
bool,DISABLE_MDC_FROM_PLUGIN)
138 IMPORT(
int,RESAMPLING_INDEX)
150 if(FRLIST_WITNESS==
"") {cout <<
"Error : witness frames list not defined" << endl;gSystem->Exit(1);}
151 if(CHLIST_LINEAR==
"") {cout <<
"Error : linear witness channels list not defined" << endl;gSystem->Exit(1);}
152 if(CHLIST_BILINEAR==
"") {cout <<
"Error : bilinear witness channels list not defined" << endl;gSystem->Exit(1);}
153 if(CHNAME_LINEAR==
"") {cout <<
"Error : main linear witness channel list not defined" << endl;gSystem->Exit(1);}
154 if(FRNAME==
"") {cout <<
"Error : frame name not defined" << endl;gSystem->Exit(1);}
155 if(FRLABEL==
"") {cout <<
"Error : frame label not defined" << endl;gSystem->Exit(1);}
157 IMPORT(
double,LAYER_WIDTH)
164 IMPORT(
double,L_APPLY_THRESHOLD)
165 IMPORT(
double,L_SOLVE_THRESHOLD)
166 IMPORT(
double,L_SOLVE_NEIGEN_PER_LAYER)
167 IMPORT(
char,L_SOLVE_REGULATOR)
170 IMPORT(
double,B_APPLY_THRESHOLD)
171 IMPORT(
double,B_SOLVE_THRESHOLD)
172 IMPORT(
double,B_SOLVE_NEIGEN_PER_LAYER)
173 IMPORT(
char,B_SOLVE_REGULATOR)
175 if(!APPLY_LINEAR_REGRESSION && !APPLY_BILINEAR_REGRESSION) {
176 cout <<
"Error : regression type [linear/bilinear] is not defined" << endl;
187 if(DISABLE_MDC_FROM_PLUGIN) {*x=0.;
return;}
214 if(ifo.CompareTo(net->
ifoName[0])==0) {
225 for(
int k=0;
k<(
int)net->
mdcTime.size();
k++) cout <<
k <<
" mdcTime " << MDC.
mdcTime[
k] << endl;
226 for(
int k=0;
k<(
int)net->
mdcType.size();
k++) cout <<
k <<
" mdcType " << MDC.
mdcType[
k] << endl;
237 for(
int n=0;
n<cfg->
nIFO;
n++)
if(ifo==cfg->
ifo[
n]) {xIFO=
n;
break;}
239 int runID = net->
nRun;
262 while (((SR % 2) == 0) && SR > 2*
CUT_LOW_FREQ) {SR /= 2;mm++;}
267 cout <<
"Set Frequency Range [0:" << SR/2 <<
"] = 0" << endl;
280 if(scratch>cfg->
segEdge+0.001) {
282 cout <<
"Regression Plugin : Error - filter scratch must be <= cwb scratch!!!" << endl;
283 cout <<
"filter scratch : " << scratch <<
" sec" << endl;
284 cout <<
"cwb scratch : " << cfg->
segEdge <<
" sec" << endl;
294 if(APPLY_LINEAR_REGRESSION) {
296 cout <<
"CWB_PLUGIN_DATA_MDC : Apply Linear Regression ..." << endl;
298 frame frl(FRLIST_WITNESS,
"",
"README",
true);
302 size = rr.
add(wT,
"target");
303 if(size==0) {cout <<
"Regression Plugin - empty target channel" << endl;gSystem->Exit(1);}
309 ifl.open(CHLIST_LINEAR.Data(),
ios::in);
310 if (!ifl.good()) {cout <<
"Error Opening File : " << CHLIST_LINEAR.Data() << endl;gSystem->Exit(1);}
316 if (!ifl.good())
break;
317 if(linear[0]==
'#')
continue;
318 cout <<
"read linear channel : \t" << linear << endl;
328 rr.
solve(L_SOLVE_THRESHOLD,L_SOLVE_NEIGEN_PER_LAYER,L_SOLVE_REGULATOR);
329 rr.
apply(L_APPLY_THRESHOLD);
331 if(SAVE_EIGEN_PLOT) {
332 gROOT->SetBatch(
true);
337 watplot eplot(const_cast<char*>(
"eplot"),200,20,800,500);
338 sprintf(gtitle,
"Linear Regression Filter eigenvalues");
339 eplot.
gtitle(gtitle,
"filter index",
"eigenvalue");
342 sprintf(ofName,
"%s/eigen_linear_regression_%s_%s.png",cfg->
dump_dir,ifo.Data(),flabel);
343 cout <<
"write results to " << ofName << endl;
346 eigen >> eplot; eplot >>
gfile;
354 if(APPLY_BILINEAR_REGRESSION) {
356 cout <<
"CWB_PLUGIN_DATA_MDC : Apply Bilinear Regression ..." << endl;
361 size=rr.
add(wT,
"target");
362 if(size==0) {cout <<
"Regression Plugin - empty target channel" << endl;gSystem->Exit(1);}
368 cout <<
"read main linear channel : \t" << CHNAME_LINEAR.Data() << endl << endl;
371 frame frb(FRLIST_WITNESS,
"",
"README",
true);
375 size=rr.
add(ml,const_cast<char*>(CHNAME_LINEAR.Data()));
376 if(size==0) {cout <<
"Regression Plugin - empty main linear channel" << endl;gSystem->Exit(1);}
380 iwb.open(CHLIST_BILINEAR.Data(),
ios::in);
381 if (!iwb.good()) {cout <<
"Error Opening File : " << CHLIST_BILINEAR.Data() << endl;gSystem->Exit(2);}
390 if (!iwb.good())
break;
391 if(bilinear[0]==
'#')
continue;
392 cout <<
"read bilinear channel : \t" << bilinear << endl;
396 if(!rr.
add(wb,bilinear,WFLOW,WFHIGH))
continue;
401 for(
int n=2;
n<=nBILINEAR+1;
n++) rr.
add(1,
n,
"bilinear");
402 for(
int n=1;
n<=nBILINEAR+1;
n++) rr.
mask(
n);
406 rr.
solve(B_SOLVE_THRESHOLD,B_SOLVE_NEIGEN_PER_LAYER,B_SOLVE_REGULATOR);
407 rr.
apply(B_APPLY_THRESHOLD);
410 if(SAVE_EIGEN_PLOT) {
411 gROOT->SetBatch(
true);
416 watplot eplot(const_cast<char*>(
"eplot"),200,20,800,500);
417 sprintf(gtitle,
"Linear Regression Filter eigenvalues");
418 eplot.
gtitle(gtitle,
"filter index",
"eigenvalue");
421 sprintf(ofName,
"%s/eigen_bilinear_regression_%s_%s.png",cfg->
dump_dir,ifo.Data(),flabel);
422 cout <<
"write results to " << ofName << endl;
425 eigen >> eplot; eplot >>
gfile;
433 gROOT->SetBatch(
true);
438 watplot plot(const_cast<char*>(
"plot"),200,20,800,500);
447 sprintf(gtitle,
"Dirty/Cleaned Data %s - %3.0f-%3.0f Hz",
449 plot.
gtitle(gtitle,
"frequency (Hz)",
"strain/#sqrt{Hz}");
450 plot.
goptions(
"alp logy", 1, tstart, tstop,
true, flow,fhigh,
true, 32);
453 cout <<
"write results to " << ofName << endl;
484 sprintf(ofName,
"%s/I-%s-%lu-%lu.gwf",
486 cout <<
"write frame file " << ofName << endl;
487 frame xfr(ofName,chName,
"WRITE");
517 sprintf(ofName,
"%s/R-%s-%lu-%lu.gwf",
519 cout <<
"write frame file " << ofName << endl;
520 frame cfr(ofName,chName,
"WRITE");
527 if(EXIT_AFTER_REGRESSION) {
529 if(ifo==cfg->
ifo[xIFO]) {
530 cout <<
"remove temporary file ..." << endl;
532 jname.ReplaceAll(
":/",
"");
533 cout << jname.Data() << endl;
534 gSystem->Exec(
TString(
"rm "+jname).Data());
535 cout <<
"end job" << endl;
std::vector< char * > ifoName
double L_SOLVE_NEIGEN_PER_LAYER
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)
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<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ 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
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
network ** net
NOISE_MDC_SIMULATION.
void setChName(TString chName)
virtual size_t size() const
#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