Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_SimNoise.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 "Toolbox.hh"
32 
33 // ---------------------------------------------------------------------------------
34 // HOW TO SETUP PLUGIN SimNoise IN CWB USER CONFIGURATION (EXAMPLE)
35 // ---------------------------------------------------------------------------------
36 
37 /*
38  TString optSN = ""; // NOTE : add space at the end of each line
39 
40  optSN += "sn_strain_file_name=LIGO.txt "; // add LIGO strain file name to first detector
41  optSN += "sn_strain_file_name=Virgo.txt "; // add Virgo strain file name to second detector
42 
43  optSN += "sn_seed=1 "; // add seed for random noise generation to first detector
44  optSN += "sn_seed=2 "; // add seed for random noise generation to second detector
45 
46  strcpy(parPlugin,optSN.Data()); // set WF plugin parameters
47 */
48 
49 // ---------------------------------------------------------------------------------
50 // DEFINES
51 // ---------------------------------------------------------------------------------
52 
53 #define SN_STRAIN_FILE_NAME ""
54 #define SN_SEED 150914
55 
56 // ---------------------------------------------------------------------------------
57 // USER PLUGIN OPTIONS
58 // ---------------------------------------------------------------------------------
59 
60 struct uoptions {
61  TString strain_file_name[NIFO_MAX];
62  int seed[NIFO_MAX];
63 };
64 
65 // ---------------------------------------------------------------------------------
66 // Global Variables
67 // ---------------------------------------------------------------------------------
68 
69 uoptions gOPT; // global User Options
70 
71 // ---------------------------------------------------------------------------------
72 // FUNCTIONS
73 // ---------------------------------------------------------------------------------
74 
75 void ResetUserOptions();
78 
79 
80 void
82 
83 // Plugin to generate simulated gaussian noise
84 
85  cout << endl;
86  cout << "-----> CWB_Plugin_SimNoise.C" << endl;
87  cout << "ifo " << ifo.Data() << endl;
88  cout << "type " << type << endl;
89  cout << endl;
90 
91 
92  if(type==CWB_PLUGIN_CONFIG) {
93  cfg->dataPlugin=true; // disable read data from frames
94 
95  ResetUserOptions(); // set default config options
96  ReadUserOptions(cfg->parPlugin); // user config options : read from parPlugin
97  }
98 
99  if(type==CWB_PLUGIN_NETWORK) {
100  PrintUserOptions(cfg); // print config options
101  // check user options
102  for(int n=0;n<cfg->nIFO;n++) {
103  for(int m=n+1;m<cfg->nIFO;m++) {
104  if(gOPT.seed[n]==gOPT.seed[m]) {
105  cout << "CWB_Plugin_SimNoise Error : seed must me unique !!!!" << endl;
106  cout << endl;
107  exit(1);
108  }
109  }
110  }
111  for(int n=0;n<cfg->nIFO;n++) CWB::Toolbox::checkFile(gOPT.strain_file_name[n]);
112  }
113 
114  if(type==CWB_PLUGIN_DATA) {
115 
117 
118  int ifoID =0; for(int n=0;n<cfg->nIFO;n++) if(ifo==net->getifo(n)->Name) {ifoID=n;break;}
119 
120  int seed = gOPT.seed[ifoID];
121  TString fName = gOPT.strain_file_name[ifoID];;
122  cout << "CWB_Plugin_SimNoise " << net->getifo(ifoID)->Name << " -> seed " << seed << " - " << fName << endl;
123 
124  int size=x->size();
125  double start=x->start();
126  TB.getSimNoise(*x, fName, seed, net->nRun);
127  x->resize(size);
128  x->start(start);
129  }
130  return;
131 }
132 
134 
135  cout << "-----------------------------------------" << endl;
136  cout << "SN config options " << endl;
137  cout << "-----------------------------------------" << endl << endl;
138 
139  for(int n=0;n<cfg->nIFO;n++) {
140  cout << "SN_STRAIN_FILE_NAME " << cfg->ifo[n] << " " << gOPT.strain_file_name[n] << endl;
141  cout << "SN_SEED " << cfg->ifo[n] << " " << gOPT.seed[n] << endl;
142  }
143 
144  cout << endl;
145 }
146 
147 
149 
150  int n_strain_file_name=0;
151  int n_seed=0;
152  if(options.CompareTo("")!=0) {
153  cout << options << endl;
154  if(!options.Contains("--")) { // parameters are used only by cwb_inet
155 
156  TObjArray* token = TString(options).Tokenize(TString(' '));
157  for(int j=0;j<token->GetEntries();j++){
158 
159  TObjString* tok = (TObjString*)token->At(j);
160  TString stok = tok->GetString();
161 
162  if(stok.Contains("sn_strain_file_name=")) {
163  TString sn_strain_file_name=stok;
164  sn_strain_file_name.Remove(0,sn_strain_file_name.Last('=')+1);
165  gOPT.strain_file_name[n_strain_file_name]=sn_strain_file_name;
166  if(n_strain_file_name<(NIFO_MAX-1)) n_strain_file_name++;
167  }
168 
169  if(stok.Contains("sn_seed=")) {
170  TString sn_seed=stok;
171  sn_seed.Remove(0,sn_seed.Last('=')+1);
172  if(sn_seed.IsDigit()) gOPT.seed[n_seed]=sn_seed.Atoi();
173  if(n_seed<(NIFO_MAX-1)) n_seed++;
174  }
175 
176  }
177  }
178  }
179 }
180 
181 
183 
184  for(int n=0;n<NIFO_MAX;n++) gOPT.strain_file_name[n] = SN_STRAIN_FILE_NAME;
185  for(int n=0;n<NIFO_MAX;n++) gOPT.seed[n] = SN_SEED+n;
186 
187 }
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
CWB::config * cfg
virtual void resize(unsigned int)
Definition: wseries.cc:901
bool dataPlugin
Definition: config.hh:364
int n
Definition: cwb_net.C:28
TString("c")
size_t nRun
Definition: network.hh:572
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
CWB::Toolbox TB
Long_t size
int m
Definition: cwb_net.C:28
virtual void start(double s)
Definition: wavearray.hh:137
int j
Definition: cwb_net.C:28
void PrintUserOptions(CWB::config *cfg)
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
char ifo[NIFO_MAX][8]
network ** net
NOISE_MDC_SIMULATION.
virtual size_t size() const
Definition: wavearray.hh:145
jfile
Definition: cwb_job_obj.C:43
static void getSimNoise(wavearray< double > &u, TString fName, int seed, int run)
Definition: Toolbox.cc:5593
const int NIFO_MAX
Definition: wat.hh:22
char parPlugin[1024]
Definition: config.hh:363
void ReadUserOptions(TString options)
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
TObjArray * token
char options[256]
char Name[16]
Definition: detector.hh:327
char ifo[NIFO_MAX][8]
Definition: config.hh:124
#define SN_SEED
int nIFO
Definition: config.hh:120
#define SN_STRAIN_FILE_NAME
char fName[256]
uoptions gOPT
void ResetUserOptions()
exit(0)