Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CWB_Plugin_Recolor.C
Go to the documentation of this file.
1 #define XIFO 4
2 
3 #pragma GCC system_header
4 
5 #include "cwb.hh"
6 #include "config.hh"
7 #include "network.hh"
8 #include "wavearray.hh"
9 #include "TString.h"
10 #include "TObjArray.h"
11 #include "TObjString.h"
12 #include "TRandom.h"
13 #include "Toolbox.hh"
14 
16 void PrintUserOptions(CWB::config* cfg, int ifoId);
17 
18 // ---------------------------------------------------------------------------------
19 // plugin parameters
20 // ---------------------------------------------------------------------------------
21 
22 TString frDir[NIFO_MAX]; // output directory for frame files
23 TString frName[NIFO_MAX]; // name to tag the frame
24 TString chName[NIFO_MAX]; // name to tag the frame channel data
25 TString frLabel[NIFO_MAX]; // label used to tag the output frame file name
26  // Ex: frDir/ifo_frLabel-GPS-LENGTH.gwf
27 TString psdFile[NIFO_MAX]; // file used to recolor the data
28 
29 // NOTE : cwb whitened data is 0 for freq<16
30 // for freq<padFreq the amplitude in frequency domain is padded
31 // with a value given by -> (famplitude at padFreq) * padFactor
32 
35 
36 bool gausNoise[NIFO_MAX]; // true/false -> gaussian/real data colored noise
37 
38 /* Example : parPlugin definition in user_parameters.C file for L1,H1 network
39  Note : definitions must be repeated for each detector
40 
41  TString optrc = ""; // NOTE : add space at the end of each line
42  optrc += "frDir=/home/vedovato/WP/RECOLOR/O1_C01_RECOLOR_tst1/recolored/L1 ";
43  optrc += "frDir=/home/vedovato/WP/RECOLOR/O1_C01_RECOLOR_tst1/recolored/H1 ";
44  optrc += "frLabel=HOFT_C01 ";
45  optrc += "frLabel=HOFT_C01 ";
46  optrc += "chName=L1:RECOLOR-CALIB_STRAIN_C01 ";
47  optrc += "chName=H1:RECOLOR-CALIB_STRAIN_C01 ";
48  optrc += "frName=LLO_4k ";
49  optrc += "frName=LHO_4k ";
50  optrc += "psdFile=$HOME_CWB/plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt ";
51  optrc += "psdFile=$HOME_CWB/plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt ";
52  optrc += "padFreq=20 ";
53  optrc += "padFreq=20 ";
54  optrc += "padFactor=1000 ";
55  optrc += "padFactor=1000 ";
56  optrc += "gausNoise=false ";
57  optrc += "gausNoise=false ";
58 
59  strcpy(parPlugin,optrc.Data()); // set plugin parameters
60 */
61 /* Note : define DQF array with CAT0 DQ files
62 
63  // dq file list
64  // {ifo, dqcat_file, dqcat[0/1/2], shift[sec], inverse[false/true], 4columns[true/false]}
65  nDQF=2;
66  dqfile dqf[nDQF]={
67  {"L1" ,"/home/vedovato/O1/DQvetos/O1_12Sep19Jan_C01/L1Cat0.txt", CWB_CAT0, 0., false, false},
68  {"H1" ,"/home/vedovato/O1/DQvetos/O1_12Sep19Jan_C01/H1Cat0.txt", CWB_CAT0, 0., false, false}
69  };
70  for(int i=0;i<nDQF;i++) DQF[i]=dqf[i];
71 */
72 
73 void
75 //!MISCELLANEA
76 // Plugin to produce recolored frames of whitened data
77 // First data are whitened then are recolored and save to file frames
78 //
79 
80  cout << endl;
81  cout << "-----> CWB_Plugin_Recolor.C" << endl;
82  cout << "ifo " << ifo.Data() << endl;
83  cout << "type " << type << endl;
84  cout << endl;
85 
87 
88  if(type==CWB_PLUGIN_CONFIG) {
89  cfg->levelR=0; // no resampling, data are whitened with yjr original sample rate
90  cfg->simulation = 0; // force non simulation mode
91  cfg->nfactor=1;
92 
93  ReadUserOptions(cfg); // user config options : read from parPlugin
94  }
95 
96  if(type==CWB_PLUGIN_INIT_JOB) {
97  // get ifo id
98  int id=-1;
99  for(int n=0;n<cfg->nIFO;n++) if(ifo==net->ifoName[n]) {id=n;break;}
100  if(id<0) {cout << "Plugin : Error - bad ifo id" << endl; gSystem->Exit(1);}
101 
102  PrintUserOptions(cfg, id); // print config options
103  }
104 
106 
107  // get ifo id
108  int id=-1;
109  for(int n=0;n<cfg->nIFO;n++) if(ifo==net->ifoName[n]) {id=n;break;}
110  if(id<0) {cout << "Plugin : Error - bad ifo id" << endl; gSystem->Exit(1);}
111 
112  TB.mkDir(frDir[id],false,false); // create output frame dir
113 
114  // data recolored
115  int size=x->size();
116  double start=x->start();
117  if(gausNoise[id]) {
118  int seed = 1000+id;
119  TB.getSimNoise(*x, psdFile[id], seed, net->nRun); // gaussian colored noise
120  } else {
121  TB.getSimNoise(*x, psdFile[id], -padFreq[id], padFactor[id]); // real data colored noise
122  }
123 
124  x->resize(size);
125  x->start(start);
126 
127  // save cleaned data into frame
128  wavearray<double> X = *x;
129  // remove scratch
130  int os = cfg->segEdge*x->rate();
131  X.start(x->start()+cfg->segEdge);
132  X.stop(x->stop()-cfg->segEdge);
133  for(int i=0;i<X.size()-2*os;i++) X[i]=X[i+os];
134  X.resize(x->size()-2*os);
135 
136  // create frame file
137  char frFile[1024];
138  sprintf(frFile,"%s/%s_%s-%d-%d.gwf",
139  frDir[id].Data(),ifo.Data(),frLabel[id].Data(),
140  int(X.start()),(int)(X.stop()-X.start()));
141 
142  // open frame file
143  CWB::frame fr(frFile,chName[id],"WRITE");
144 
145  // write frame to file
146  fr.writeFrame(X, frName[id], chName[id]);
147  cout << "CWB_Plugin_Recolor.C : write " << frFile << endl;
148 
149  fr.close();
150 
151  int nIFO=net->ifoListSize();
152  if(TString(ifo).CompareTo(net->ifoName[nIFO-1])==0) gSystem->Exit(0); // last ifo
153  }
154 
155  return;
156 }
157 
159 
160  TString options = cfg->parPlugin;
161 
162  int n_frDir=0;
163  int n_frName=0;
164  int n_frLabel=0;
165  int n_chName=0;
166  int n_psdFile=0;
167  int n_padFreq=0;
168  int n_padFactor=0;
169  int n_gausNoise=0;
170  for(int i=0;i<cfg->nIFO;i++) {
171  frDir[i]="";
172  frName[i]="";
173  frLabel[i]="";
174  chName[i]="";
175  psdFile[i]="";
176  padFreq[i]=2;
177  padFactor[i]=0;
178  gausNoise[i]=false;
179  }
180  if(options.CompareTo("")!=0) {
181  cout << options << endl;
182  if(!options.Contains("--")) { // parameters are used only by cwb_inet
183 
184  TObjArray* token = TString(options).Tokenize(TString(' '));
185  for(int j=0;j<token->GetEntries();j++){
186 
187  TObjString* tok = (TObjString*)token->At(j);
188  TString stok = tok->GetString();
189 
190  if(stok.Contains("frDir=")) {
191  frDir[n_frDir]=stok;
192  frDir[n_frDir].Remove(0,frDir[n_frDir].Last('=')+1);
193  frDir[n_frDir]=gSystem->ExpandPathName(frDir[n_frDir].Data());
194  if(n_frDir<(NIFO_MAX-1)) n_frDir++;
195  }
196 
197  if(stok.Contains("frName=")) {
198  frName[n_frName]=stok;
199  frName[n_frName].Remove(0,frName[n_frName].Last('=')+1);
200  if(n_frName<(NIFO_MAX-1)) n_frName++;
201  }
202 
203  if(stok.Contains("frLabel=")) {
204  frLabel[n_frLabel]=stok;
205  frLabel[n_frLabel].Remove(0,frLabel[n_frLabel].Last('=')+1);
206  if(n_frLabel<(NIFO_MAX-1)) n_frLabel++;
207  }
208 
209  if(stok.Contains("chName=")) {
210  chName[n_chName]=stok;
211  chName[n_chName].Remove(0,chName[n_chName].Last('=')+1);
212  if(n_chName<(NIFO_MAX-1)) n_chName++;
213  }
214 
215  if(stok.Contains("padFreq=")) {
216  TString opt=stok;
217  opt.Remove(0,opt.Last('=')+1);
218  if(opt.IsDigit()) padFreq[n_padFreq]=opt.Atoi();
219  if(padFreq[n_padFreq]<2) padFreq[n_padFreq]=2;
220  if(n_padFreq<(NIFO_MAX-1)) n_padFreq++;
221  }
222 
223  if(stok.Contains("padFactor=")) {
224  TString opt=stok;
225  opt.Remove(0,opt.Last('=')+1);
226  if(opt.IsDigit()) padFactor[n_padFactor]=opt.Atoi();
227  if(padFactor[n_padFactor]<0) padFactor[n_padFactor]=0;
228  if(n_padFactor<(NIFO_MAX-1)) n_padFactor++;
229  }
230 
231  if(stok.Contains("psdFile=")) {
232  psdFile[n_psdFile]=stok;
233  psdFile[n_psdFile].Remove(0,psdFile[n_psdFile].Last('=')+1);
234  psdFile[n_psdFile]=gSystem->ExpandPathName(psdFile[n_psdFile].Data());
235  if(n_psdFile<(NIFO_MAX-1)) n_psdFile++;
236  }
237 
238  if(stok.Contains("gausNoise=")) {
239  TString opt=stok;
240  opt.Remove(0,opt.Last('=')+1);
241  if(opt=="false") gausNoise[n_gausNoise]=false;
242  if(opt=="true") gausNoise[n_gausNoise]=true;
243  if(n_gausNoise<(NIFO_MAX-1)) n_gausNoise++;
244  }
245  }
246  }
247  }
248 
249  for(int i=0;i<cfg->nIFO;i++) {
250  if(frDir[i]=="") {cout << "CWB_Plugin_Recolor : Error - frDir["<<cfg->ifo[i]<<"] not defined" << endl; gSystem->Exit(1);}
251  if(frName[i]=="") {cout << "CWB_Plugin_Recolor : Error - frName["<<cfg->ifo[i]<<"] not defined" << endl; gSystem->Exit(1);}
252  if(chName[i]=="") {cout << "CWB_Plugin_Recolor : Error - chName["<<cfg->ifo[i]<<"] not defined" << endl; gSystem->Exit(1);}
253  if(frLabel[i]=="") {cout << "CWB_Plugin_Recolor : Error - frLabel["<<cfg->ifo[i]<<"] not defined" << endl; gSystem->Exit(1);}
254  if(psdFile[i]=="") {cout << "CWB_Plugin_Recolor : Error - psdFile["<<cfg->ifo[i]<<"] not defined" << endl; gSystem->Exit(1);}
255  if(i>=n_gausNoise) {cout << "CWB_Plugin_Recolor : Error - gausNoise["<<cfg->ifo[i]<<"] not defined" << endl; gSystem->Exit(1);}
256  }
257 }
258 
259 void PrintUserOptions(CWB::config* cfg, int ifoId) {
260 
261  cout << "-----------------------------------------" << endl;
262  cout << "Recolor config options : ifo = " << cfg->ifo[ifoId] << endl;
263  cout << "-----------------------------------------" << endl << endl;
264  cout << endl;
265  cout << "frDir : " << frDir[ifoId] << endl;
266  cout << "chName : " << chName[ifoId] << endl;
267  cout << "frName : " << frName[ifoId] << endl;
268  cout << "frLabel : " << frLabel[ifoId] << endl;
269  cout << "psdFile : " << psdFile[ifoId] << endl;
270  cout << "padFreq : " << padFreq[ifoId] << endl;
271  cout << "padFactor : " << padFactor[ifoId] << endl;
272  cout << "gausNoise : " << gausNoise[ifoId] << endl;
273  cout << endl;
274 }
std::vector< char * > ifoName
Definition: network.hh:591
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
virtual void resize(unsigned int)
Definition: wseries.cc:883
int padFactor[NIFO_MAX]
virtual size_t size() const
Definition: wavearray.hh:127
virtual void rate(double r)
Definition: wavearray.hh:123
int padFreq[NIFO_MAX]
int n
Definition: cwb_net.C:10
TString("c")
size_t nRun
Definition: network.hh:554
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
void close()
Definition: frame.cc:278
CWB::frame fr(FRLIST_NAME)
void writeFrame(wavearray< double > x, TString frName, TString chName)
Definition: frame.cc:157
Long_t size
virtual void start(double s)
Definition: wavearray.hh:119
int j
Definition: cwb_net.C:10
i drho i
bool gausNoise[NIFO_MAX]
CWB::Toolbox TB
Definition: ComputeSNR.C:5
char ifo[NIFO_MAX][8]
network ** net
NOISE_MDC_SIMULATION.
size_t ifoListSize()
Definition: network.hh:413
double segEdge
Definition: config.hh:146
#define nIFO
TString chName[NIFO_MAX]
jfile
Definition: cwb_job_obj.C:25
static void getSimNoise(wavearray< double > &u, TString fName, int seed, int run)
Definition: Toolbox.cc:4809
int simulation
Definition: config.hh:181
i() int(T_cor *100))
const int NIFO_MAX
Definition: wat.hh:4
TString frDir[NIFO_MAX]
char parPlugin[1024]
Definition: config.hh:345
TString psdFile[NIFO_MAX]
int nfactor
Definition: config.hh:183
TObjArray * token
char options[256]
TString frName[NIFO_MAX]
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
virtual void stop(double s)
Definition: wavearray.hh:121
char ifo[NIFO_MAX][8]
Definition: config.hh:106
static void mkDir(TString dir, bool question=false, bool remove=true)
Definition: Toolbox.cc:4000
void PrintUserOptions(CWB::config *cfg, int ifoId)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
int nIFO
Definition: config.hh:102
Long_t id
void ReadUserOptions(CWB::config *cfg)
virtual void resize(unsigned int)
Definition: wavearray.cc:445
TString frLabel[NIFO_MAX]
int levelR
Definition: config.hh:134
char os[1024]