Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_DataConditioning.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #define XIFO 4
20 
21 #pragma GCC system_header
22 
23 #include "cwb.hh"
24 #include "config.hh"
25 #include "network.hh"
26 #include "wavearray.hh"
27 #include "TString.h"
28 #include "TObjArray.h"
29 #include "TObjString.h"
30 #include "TRandom.h"
31 #include "TComplex.h"
32 #include "TMath.h"
33 #include "mdc.hh"
34 #include "regression.hh"
35 #include <vector>
36 
37 
38 #define REGRESSION_FILTER_LENGTH 8
39 #define REGRESSION_MATRIX_FRACTION 0.95
40 #define REGRESSION_SOLVE_EIGEN_THR 0.
41 #define REGRESSION_SOLVE_EIGEN_NUM 10
42 #define REGRESSION_SOLVE_REGULATOR 'h'
43 #define REGRESSION_APPLY_THR 0.8
44 
45 #define LPR_LEVELD 8
46 #define LPR_LEVELF 6
47 #define LPR_TLPR 120.
48 
49 #define USE_REGRESSION
50 //#define USE_LPR_FILTER
51 
52 void
54 //!DATA_CONDITIONING
55 // This plugin shows how to implement a custom Data Conditioning (only 2G)
56 
57  cout << endl;
58  cout << "-----> CWB_Plugin_DataConditioning.C" << endl;
59  cout << "ifo " << ifo.Data() << endl;
60  cout << "type " << type << endl;
61  cout << endl;
62 
63  if(type==CWB_PLUGIN_CONFIG) {
64  cfg->dcPlugin=true; // disable built in dc
65  }
66 
67  if(type==CWB_PLUGIN_DATA_CONDITIONING) {
68 
69  if(TString(cfg->analysis)!="2G") {
70  cout << "CWB_Plugin_DAtaConditioning.C -> implemented only for 2G" << endl;
71  gSystem->Exit(1);
72  }
73 
76  // import global variables
77  size_t gRATEANA; IMPORT(size_t,gRATEANA)
78  void* gMDC=NULL; IMPORT(void*,gMDC)
79  WSeries<double>* xM = (WSeries<double>*)gMDC;
80 #ifdef USE_LPR_FILTER // used in 1G
81  Meyer<double> S(1024,2); // set wavelet for production
82 #endif
83 
84  // get ifo id
85  int id=-1;
86  for(int n=0;n<cfg->nIFO;n++) if(ifo==net->ifoName[n]) {id=n;break;}
87  if(id<0) {cout << "Plugin : Error - bad ifo id" << endl; gSystem->Exit(1);}
88 
89  detector* pD = net->getifo(id);
90  WSeries<double>* pTF = pD->getTFmap();
92 
93  int layers = 0;
94  for(int level=cfg->l_high; level>=cfg->l_low; level--) {
95  for(int j=0;j<net->wdmMRA.nRes;j++)
96  if(layers<net->wdmMRA.layers[j]) layers=net->wdmMRA.layers[j];
97  }
98  WDM<double> WDMwhite(layers,layers,6,10); // set whitening WDM
99  layers = gRATEANA/8;
100  WDM<double> WDMlpr(layers,layers,6,10); // set LPE filter WDM
101 
102 #ifdef USE_LPR_FILTER // used in 1G
103  pTF->Forward(*hot,S,LPR_LEVELD);
104  pTF->lprFilter(2,0,LPR_TLPR,4.);
105  pTF->Inverse();
106  *hot = *pTF; // conditioned TS
107 #endif
108 
109 #ifdef USE_REGRESSION // used in 2G
110  // regression
111  pTF->Forward(*hot,WDMlpr);
112  regression rr(*pTF,const_cast<char*>("target"),1.,cfg->fHigh);
113  rr.add(*hot,const_cast<char*>("target"));
118  *hot = rr.getClean();
119 #endif
120 
121  // whitening
122  pTF->Forward(*hot,WDMwhite);
123  pTF->setlow(cfg->fLow);
124  pTF->sethigh(cfg->fHigh);
125  pD->white(cfg->whiteWindow,0,cfg->segEdge,cfg->whiteStride); // calculate noise rms
126  pD->nRMS.bandpass(16.,0.,1); // high pass filtering at 16Hz
127  pTF->white(pD->nRMS,1); // whiten 0 phase WSeries
128  pTF->white(pD->nRMS,-1); // whiten 90 phase WSeries
129  if(cfg->simulation) { // estimated whitened MDC parms
130  wM.Forward(*xM,WDMwhite);
131  wM.setlow(cfg->fLow);
132  wM.sethigh(cfg->fHigh);
133  // zero f<fLow to avoid whitening issues when psd noise is not well defined for f<fLow
134  int layers = wM.maxLayer();
135  for(int j=0;j<layers;j++) if(wM.frequency(j)<cfg->fLow) {
136  double layer = j+0.01; // -epsilon select 0 layer for 90 phase
137  wM.getLayer(y, layer);y=0;wM.putLayer(y, layer); // 0 phase
138  wM.getLayer(y,-layer);y=0;wM.putLayer(y,-layer); // 90 phase
139  }
140  // compute mdc snr and save whiten waveforms
141  pD->setsim(wM,net->getmdcTime(),cfg->iwindow/2.,cfg->segEdge,true);
142  }
143  WSeries<double> wtmp = *pTF;
144  pTF->Inverse();
145  wtmp.Inverse(-2);
146  *hot = *pTF;
147  *hot += wtmp;
148  *hot *= 0.5;
149 
150 #ifdef USE_LPR_FILTER // used in 1G
151  pTF->Forward(*hot,S,LPR_LEVELF);
152  pTF->lprFilter(2,0,LPR_TLPR,4.);
153  pTF->Inverse();
154  *hot = *pTF; // conditioned TS
155 #endif
156 
157  }
158  return;
159 }
monster wdmMRA
list of pixel pointers for MRA
Definition: network.hh:651
std::vector< char * > ifoName
Definition: network.hh:609
void sethigh(double f)
Definition: wseries.hh:132
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
CWB::config * cfg
char analysis[8]
Definition: config.hh:117
double iwindow
Definition: config.hh:200
void white(double dT=0, int wtype=1, double offset=0., double stride=0.)
what it does: see algorithm description in wseries.hh
Definition: detector.hh:258
void setMatrix(double edge=0., double f=1.)
Definition: regression.cc:425
std::vector< double > * getmdcTime()
Definition: network.hh:422
int n
Definition: cwb_net.C:28
TString("c")
void bandpass(wavearray< DataType_t > &ts, double flow, double fhigh, int n=-1)
Definition: wseries.cc:313
#define REGRESSION_SOLVE_REGULATOR
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
double whiteWindow
Definition: config.hh:189
double fLow
Definition: config.hh:140
bool dcPlugin
Definition: config.hh:366
#define LPR_TLPR
void setlow(double f)
Definition: wseries.hh:125
int layers
#define REGRESSION_APPLY_THR
size_t add(WSeries< double > &target, char *name, double fL=0., double fH=0.)
Definition: regression.cc:91
int j
Definition: cwb_net.C:28
char ifo[NIFO_MAX][8]
double Edge
Definition: network.hh:578
network ** net
NOISE_MDC_SIMULATION.
CWB::mdc * gMDC
double segEdge
Definition: config.hh:164
jfile
Definition: cwb_job_obj.C:43
int simulation
Definition: config.hh:199
int l_high
Definition: config.hh:156
#define REGRESSION_SOLVE_EIGEN_THR
wavearray< double > hot[2]
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:69
WSeries< double > nRMS
Definition: detector.hh:358
#define REGRESSION_FILTER_LENGTH
void apply(double threshold=0., char c='a')
Definition: regression.cc:709
WSeries< double > pTF[nRES]
Definition: revMonster.cc:8
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
Definition: wseries.cc:193
int gRATEANA
void solve(double th, int nE=0, char c='s')
Definition: regression.cc:610
size_t setFilter(size_t)
Definition: regression.cc:276
wavearray< double > getClean()
Definition: regression.hh:135
WSeries< double > wM
Definition: cwb_job_obj.C:41
int l_low
Definition: config.hh:155
double whiteStride
Definition: config.hh:190
double fHigh
Definition: config.hh:141
WSeries< double > * getTFmap()
param: no parameters
Definition: detector.hh:179
Definition: Meyer.hh:36
int * layers
Definition: monster.hh:121
#define REGRESSION_SOLVE_EIGEN_NUM
virtual void lprFilter(double, int=0, double=0., double=0.)
Definition: wseries.cc:1126
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:246
Meyer< double > S(1024, 2)
int nRes
Definition: monster.hh:117
int nIFO
Definition: config.hh:120
#define LPR_LEVELD
#define REGRESSION_MATRIX_FRACTION
#define LPR_LEVELF
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:291
wavearray< double > y
Definition: Test10.C:31
void putLayer(wavearray< DataType_t > &, double n)
param: n - layer number
Definition: wseries.cc:219
size_t setsim(WSeries< double > &, std::vector< double > *, double=5., double=8., bool saveWF=false)
Definition: detector.cc:1377
double frequency(int l)
Definition: wseries.cc:117
int maxLayer()
Definition: wseries.hh:139
detector ** pD
virtual WSeries< double > white(double, int, double=0., double=0.)
what it does: each wavelet layer is devided into k intervals.
Definition: wseries.cc:1146
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.