Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_O3aConditioning.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Sergey Klimenko
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 "gwavearray.hh"
27 #include "regression.hh"
28 #include "TString.h"
29 #include "TObjArray.h"
30 #include "TObjString.h"
31 #include "TRandom.h"
32 #include "Toolbox.hh"
33 
34 // ---------------------------------------------------------------------------------
35 // HOW TO SETUP PLUGIN IN CWB USER CONFIGURATION (EXAMPLE)
36 // ---------------------------------------------------------------------------------
37 
38 /*
39 
40  TString opt_o3ac = ""; // NOTE : add space at the end of each line
41 
42  opt_o3ac += "o3ac_ifo=enable "; // enable 32hz of first ifo
43  opt_o3ac += "o3ac_ifo=enable "; // enable 32hz of seconf ifo
44  opt_o3ac += "o3ac_ifo=disable "; // disable 32hz of third ifo
45 
46  strcpy(parPlugin,opt_o3ac.Data()); // set plugin parameters
47 
48 */
49 
50 // ---------------------------------------------------------------------------------
51 // USER O3aConditioning PLUGIN OPTIONS
52 // ---------------------------------------------------------------------------------
53 
54 struct uoptions {
55  bool ifo[NIFO_MAX];
56 };
57 
58 uoptions gOPT; // global User Options
59 
63 
64 void
66 //!32Hz_CONDITIONING
67 // Plugin to correct PSD variability in the 16-48Hz band
68 
69  if(type==CWB_PLUGIN_NETWORK) {
70  ResetUserOptions(net, cfg); // set default config options
71  ReadUserOptions(cfg->parPlugin); // user config options : read from parPlugin
72  PrintUserOptions(cfg); // print config options
73  }
74 
76  // Marek put power 60 up-conversion regression here
77  }
78 
80  cout << endl;
81  cout << "-----> CWB_Plugin_O3aDataConditioning.C ";
82  cout << "type " << type << endl;
83  cout << endl;
84 
85  if(TString(cfg->analysis)=="1G") {
86  cout << "CWB_Plugin_O3aConditioning Error - this plugin works only with 2G" << endl;
87  gSystem->Exit(1);
88  }
89 
90  // get ifo id
91  int id=-1;
92  for(int n=0;n<cfg->nIFO;n++) {
93  if(ifo==net->ifoName[n]) {id=n; break;}
94  }
95  if(id<0) {cout << "Plugin : Error - bad ifo id" << endl; gSystem->Exit(1);}
96 
97  if(!gOPT.ifo[id]) return; // skip 32hz correction if ifo is not enabled
98 
99  wavearray<double> u,v,w,p,q,s,c;
100  WSeries<double> ws, WS;
101  detector* pD = net->getifo(id);
102  wavearray<double>* hot = pD->getHoT();
103  int M = int(hot->rate()/64+0.1); // number of WDM layers with 32 Hz bandwidth
104  WDM<double> wdm(M,M,6,10);
105  double edge = net->Edge;
106 
107  ws.Forward(*hot,wdm);
108  ws.getLayer(c, 1);
109  ws.getLayer(s,-1);
110  u = c; w = c;
111  for(int i=0; i<u.size(); i++) {
112  u.data[i]=sqrt(c.data[i]*c.data[i]+s.data[i]*s.data[i]);
113  c.data[i]/=u.data[i]>0. ? u.data[i] : 1;
114  s.data[i]/=u.data[i]>0. ? u.data[i] : 1;
115  }
116  v = u;
117  double R = v.rate(); // WDM layer rate (should be 64 Hz)
118  double T = v.stop()-v.start(); // data duration
119  v.lprFilter(4.,0,0.,edge,1); // apply lpe filter to clean layer
120  double um = u.median(edge*R,(T-edge)*R); // median of u - original
121  double vm = v.median(edge*R,(T-edge)*R); // median of v - clean
122  double vr,aa;
123 
124  v += um-vm;
125  for(int i=0; i<u.size(); i++) {
126  if(v.data[i]<0.) v.data[i]=0.; // corrected magnitude can not be negative
127  vr = u.data[i]-v.data[i]; // rms variability
128  aa = u.data[i]<2*um?(u.data[i]-um)/um:1.; // amplitude correction factor
129  if(vr<0 || aa<0) aa = 0; // no correction
130  vr *= vr<1 ? vr : 1; // quadratic correction for vr<1
131  v.data[i] = u.data[i]-vr*aa; // apply all corrections
132  w.data[i] = v.data[i]/u.data[i];
133  }
134 
135  int n = int(edge*R);
136  int m = int(0.6*R);
137 
138  p=v; q=v; q=0.;
139  for(int i=0; i<u.size(); i++) {
140  p.data[i] = 1-w.data[i];
141  if(p.data[i]>0.9) p.data[i]=0.;
142  }
143  for(int i=n+m; i<u.size()-n-m; i++) {
144  for(int j=0; j<m; j++) {
145  q.data[j] += p.data[i]*(p.data[i-j]+p.data[i+j]);
146  }
147  }
148  q *= 1/q.data[0];
149 
150  pD->nVAR.resize(u.size());
151  pD->nVAR = 1;
152 
153  for(int i=m+1; i<u.size()-m-1; i++) {
154  double sp = 0;
155  double sm = 0;
156  for(int j=8; j<m; j++) {
157  aa = p.data[i-j]; sm += aa*aa*q.data[j];
158  aa = p.data[i+j]; sp += aa*aa*q.data[j];
159  }
160  aa = sp<sm ? sm : sp;
161  aa = 1./(1.+aa); // multiplicity correction
162  v.data[i] *= aa; // data
163  w.data[i] *= aa; // variability
164  if(w.data[i]==0) w.data[i]=1.e-16; // 23/08/19 fix nRMS = 0
165  pD->nVAR.data[i] = w.data[i]; // noise rms correction
166  }
167 
168  c*=v; ws.putLayer(c, 1);
169  s*=v; ws.putLayer(s,-1);
170  WS = ws;
171  ws.Inverse(); c = ws;
172  WS.Inverse(-2); s = WS;
173  *hot = c; *hot += s; *hot *= 0.5; // whitened and corected time series
174  pD->nVAR.rate(R);
175  pD->nVAR.start(hot->start());
176  pD->nVAR.setlow(16.);
177  pD->nVAR.sethigh(48.);
178 
179  /*
180  char ofname[128];
181  sprintf(ofname,"%s_%d_variability.root",ifo.Data(),net->nRun);
182  TFile *froot = new TFile(ofname, "RECREATE");
183  gwavearray<double> gw=w;
184  gw.Write("32hz");
185  froot->Close();
186  */
187  }
188 
189  return;
190 }
191 
193 
194  int n_ifo=0;
195  if(options.CompareTo("")!=0) {
196  cout << options << endl;
197  if(!options.Contains("--")) { // parameters are used only by cwb_inet
198 
199  TObjArray* token = TString(options).Tokenize(TString(' '));
200  for(int j=0;j<token->GetEntries();j++){
201 
202  TObjString* tok = (TObjString*)token->At(j);
203  TString stok = tok->GetString();
204 
205  if(stok.Contains("o3ac_ifo=")) {
206  TString o3ac_ifo=stok;
207  o3ac_ifo.Remove(0,o3ac_ifo.Last('=')+1);
208  if(o3ac_ifo=="enable") gOPT.ifo[n_ifo]=true;
209  if(o3ac_ifo=="disable") gOPT.ifo[n_ifo]=false;
210  if(n_ifo<(NIFO_MAX-1)) n_ifo++;
211  }
212  }
213  }
214  }
215 }
216 
218 
219  cout << "-----------------------------------------" << endl;
220  cout << "O3aConditioning config options " << endl;
221  cout << "-----------------------------------------" << endl << endl;
222  for(int n=0;n<cfg->nIFO;n++) {
223  if(gOPT.ifo[n]==true) cout << "O3aC_IFO " << cfg->ifo[n] << " enabled" << endl;
224  if(gOPT.ifo[n]==false) cout << "O3aC_IFO " << cfg->ifo[n] << " disabled" << endl;
225  }
226 
227  cout << endl;
228 }
229 
231 
232  for(int n=0;n<cfg->nIFO;n++) {
233  gOPT.ifo[n]=false;
234  if(TString(net->ifoName[n])=="L1") gOPT.ifo[n]=true;
235  if(TString(net->ifoName[n])=="H1") gOPT.ifo[n]=true;
236  }
237 }
238 
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
virtual void resize(unsigned int)
Definition: wseries.cc:901
void PrintUserOptions(CWB::config *cfg)
double M
Definition: DrawEBHH.C:13
virtual void rate(double r)
Definition: wavearray.hh:141
WSeries< float > v[nIFO]
Definition: cwb_net.C:80
int n
Definition: cwb_net.C:28
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<< "\ 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
WDM< double > wdm(nLAYERS, nLAYERS, 6, 10)
void setlow(double f)
Definition: wseries.hh:125
int m
Definition: cwb_net.C:28
virtual void start(double s)
Definition: wavearray.hh:137
int j
Definition: cwb_net.C:28
i drho i
char ifo[NIFO_MAX][8]
double Edge
Definition: network.hh:578
network ** net
NOISE_MDC_SIMULATION.
wavearray< double > w
Definition: Test1.C:27
virtual size_t size() const
Definition: wavearray.hh:145
jfile
Definition: cwb_job_obj.C:43
wavearray< double > hot[2]
i() int(T_cor *100))
wavearray< double > * getHoT()
param: no parameters
Definition: detector.hh:175
const int NIFO_MAX
Definition: wat.hh:22
char parPlugin[1024]
Definition: config.hh:363
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
Definition: wseries.cc:193
TObjArray * token
uoptions gOPT
s s
Definition: cwb_net.C:155
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
char options[256]
double T
Definition: testWDM_4.C:11
virtual void lprFilter(wavearray< double > &)
Definition: wavearray.cc:1826
virtual void stop(double s)
Definition: wavearray.hh:139
char ifo[NIFO_MAX][8]
Definition: config.hh:124
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:246
int nIFO
Definition: config.hh:120
DataType_t * data
Definition: wavearray.hh:319
void ReadUserOptions(TString options)
WSeries< float > nVAR
Definition: detector.hh:359
virtual double median(size_t=0, size_t=0) const
Definition: wavearray.cc:1576
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:291
void putLayer(wavearray< DataType_t > &, double n)
param: n - layer number
Definition: wseries.cc:219
detector ** pD
void ResetUserOptions(network *net, CWB::config *cfg)