Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_UniqueLags.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 "cwb2G.hh"
25 #include "config.hh"
26 #include "network.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 IN CWB USER CONFIGURATION (EXAMPLE)
35 // WORNING: This plugin works only with 3 detectors !!!
36 // ---------------------------------------------------------------------------------
37 
38 /*
39  TString opt_ulags = ""; // NOTE : add space at the end of each line
40  opt_ulags += "ulags_enabled=true "; // true/false enable/disable unique lags (default=false)
41  opt_ulags += "ulags_lagSize=599 "; // if>0 force lagSize to be fixed
42  strcpy(parPlugin,opt_ulags.Data()); // set plugin parameters
43  lagSize = 0; // mandatory, used to manage command 'cwb_inet #job 0 ced 0 #lag'
44  lagStep = 1.;
45  lagOff = 0;
46 */
47 
48 // ---------------------------------------------------------------------------------
49 // USER UniqueLags PLUGIN OPTIONS
50 // ---------------------------------------------------------------------------------
51 
52 struct uoptions {
53  bool enabled; // true/false enable/disable unique lags (default=false)
54  int lagSize; // if>0 force lagSize to be fixed
55 };
56 
57 uoptions gOPT; // global User Options
58 bool gULAG; // used to manage command 'cwb_inet #job 0 ced 0 #lag'
59 
63 
64 void
66 //!CONFIG
67 // Plugin to setup dinamically the unique lags for 2/3/4 ifos network
68 
69  if(type==CWB_PLUGIN_CONFIG) {
70  gULAG = (cfg->lagSize) ? true : false; // single lag is select by the command 'cwb_inet #job 0 ced 0 #lag'
71  }
72 
73  if(type==CWB_PLUGIN_NETWORK) {
74  ResetUserOptions(net, cfg); // set default config options
75  ReadUserOptions(cfg->parPlugin); // user config options : read from parPlugin
76  PrintUserOptions(cfg); // print config options
77  }
78 
79  if(type==CWB_PLUGIN_INIT_JOB) {
80 
81  if(!gOPT.enabled) return;
82 
83  cout << endl;
84  cout << "-----> CWB_Plugin_UniqueLags.C ";
85  cout << "type " << type << endl;
86  cout << endl;
87 
88  // get ifo id
89  int id=-1;
90  for(int n=0;n<cfg->nIFO;n++) {
91  if(ifo==net->ifoName[n]) {id=n; break;}
92  }
93  if(id>0) return; // plugin is execute only for the first ifo
94 
95  if(cfg->simulation) {cout << "CWB_Plugin_UniqueLags.C : Error - works only for background" << endl; gSystem->Exit(1);}
96  if(cfg->nIFO<2 || cfg->nIFO>4) {cout << "CWB_Plugin_UniqueLags.C : Error - implemented only for 2/3/4 ifos network" << endl; gSystem->Exit(1);}
97 
98  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
99  // get lagBuffer (used to store the contents of the user lagFile)
100  TArrayC* lagBuffer = &(gCWB2G->lagBuffer);
101  // get data range
102  double segLen = gCWB2G->GetSegEnd()-gCWB2G->GetSegBegin();
103  // get laxMax & lagSize
104  int lagMax = int(segLen/cfg->lagStep);
105  if(cfg->nIFO==2) {
106  lagMax = lagMax-lagMax%2; // force to be an even number
107  }
108  if(cfg->nIFO==3) {
109  lagMax = lagMax-lagMax%3;
110  lagMax = lagMax-lagMax%2; // force to be an even number
111  }
112  int lagSize = lagMax-1;
113 
114  if(gOPT.lagSize>0) { // if>0 force lagSize to be fixed
115  lagSize = gOPT.lagSize;
116  lagMax = lagSize+1;
117  }
118 
119  cout << endl << "CWB_Plugin_UniqueLags.C : segLen -> " << segLen << " lagMax " << lagMax << " lagSize " << lagSize << endl << endl;
120 
121  // redirect cout to buffer and return contents
122  std::stringstream buffer;
123  std::streambuf * old = std::cout.rdbuf(buffer.rdbuf());
124 
125  // generate unique lags
126  if(cfg->nIFO==2) {
127  cout << 0 << "\t" << 0 << "\t" << 0 << endl;
128  std::vector<int> v[1];
129  for(int i=1;i<lagSize;i++) {
130  int lag0 = 0;
131  int lag1 = i;
132  cout << i << "\t" << lag0 << "\t" << lag1 << endl;
133  v[0].push_back(lag1-lag0);
134  }
135  for(int k=0;k<1;k++) {
136  sort(v[k].begin(), v[k].end());
137  auto it = std::unique(v[k].begin(), v[k].end());
138  if(!(it == v[k].end())) {cout << "CWB_Plugin_UniqueLags.C : Error - Duplicate Lags" << endl; gSystem->Exit(1);}
139  }
140  }
141  if(cfg->nIFO==3) {
142  cout << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << endl;
143  std::vector<int> v[3];
144  for(int i=1;i<lagSize;i++) {
145  int lag0 = 0;
146  int lag1 = i;
147  int lag2 = (i*2)%lagSize;
148  cout << i << "\t" << lag0 << "\t" << lag1 << "\t" << lag2 << endl;
149  v[0].push_back(lag1-lag0);
150  v[1].push_back(lag2-lag0); v[2].push_back(lag2-lag1);
151  }
152  for(int k=0;k<3;k++) {
153  sort(v[k].begin(), v[k].end());
154  auto it = std::unique(v[k].begin(), v[k].end());
155  if(!(it == v[k].end())) {cout << "CWB_Plugin_UniqueLags.C : Error - Duplicate Lags" << endl; gSystem->Exit(1);}
156  }
157  }
158  if(cfg->nIFO==4) {
159  cout << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << endl;
160  std::vector<int> v[6];
161  for(int i=1;i<lagSize;i++) {
162  int lag0 = 0;
163  int lag1 = i;
164  int lag2 = (i*2)%lagSize;
165  int lag3 = (i*3)%lagSize;
166  cout << i << "\t" << lag0 << "\t" << lag1 << "\t" << lag2 << "\t" << lag3 << endl;
167  v[0].push_back(lag1-lag0);
168  v[1].push_back(lag2-lag0); v[2].push_back(lag2-lag1);
169  v[3].push_back(lag3-lag0); v[4].push_back(lag3-lag1); v[5].push_back(lag3-lag2);
170  }
171  for(int k=0;k<6;k++) {
172  sort(v[k].begin(), v[k].end());
173  auto it = std::unique(v[k].begin(), v[k].end());
174  if(!(it == v[k].end())) {cout << "CWB_Plugin_UniqueLags.C : Error - Duplicate Lags" << endl; gSystem->Exit(1);}
175  }
176  }
177 
178  // restore cout
179  std::cout.rdbuf(old);
180 
181  // set lagBuffer
182  lagBuffer->Set(buffer.str().size(),buffer.str().c_str());
183  // set end of string
184  lagBuffer->Set(lagBuffer->GetSize()+1);
185  (*lagBuffer)[lagBuffer->GetSize()-1]=0;
186  gCWB2G->lagMode[0]='s';gCWB2G->lagMode[1]=0; // change lagMode : setTimeShifts read lags from string
187  if(!gULAG) cfg->lagSize=lagSize;
188  cfg->lagMax=lagMax;
189  //cout << gCWB2G->lagBuffer.GetArray() << endl;
190  }
191 
192  return;
193 }
194 
196 
197  if(options.CompareTo("")!=0) {
198  cout << options << endl;
199  if(!options.Contains("--")) { // parameters are used only by cwb_inet
200 
201  TObjArray* token = TString(options).Tokenize(TString(' '));
202  for(int j=0;j<token->GetEntries();j++){
203 
204  TObjString* tok = (TObjString*)token->At(j);
205  TString stok = tok->GetString();
206 
207  if(stok.Contains("ulags_enabled=")) {
208  TString ulags_enabled=stok;
209  ulags_enabled.Remove(0,ulags_enabled.Last('=')+1);
210  if(ulags_enabled=="true") gOPT.enabled=true;
211  if(ulags_enabled=="false") gOPT.enabled=false;
212  }
213 
214  if(stok.Contains("ulags_lagSize=")) {
215  TString ulags_lagSize=stok;
216  ulags_lagSize.Remove(0,ulags_lagSize.Last('=')+1);
217  if(ulags_lagSize.IsDigit()) gOPT.lagSize=ulags_lagSize.Atoi();
218  if((gOPT.lagSize%2)==0) {
219  cout << "ReadUserOptions Error : ulags_lagSize = " << gOPT.lagSize << " must be odd" << endl;exit(1);
220  }
221  }
222  }
223  }
224  }
225 }
226 
228 
229  cout << "-----------------------------------------" << endl;
230  cout << "UniqueLags config options " << endl;
231  cout << "-----------------------------------------" << endl << endl;
232  if(gOPT.enabled==false) cout << "ULAGS_ENABLED = false" << endl;
233  if(gOPT.enabled==true) cout << "ULAGS_ENABLED = true " << endl;
234  cout << "ULAGS_LAG_SIZE = " << gOPT.lagSize << endl;
235  cout << endl;
236 }
237 
239  gOPT.enabled=false;
240  gOPT.lagSize=0;
241 }
242 
std::vector< char * > ifoName
Definition: network.hh:609
bool gULAG
CWB::config * cfg
void PrintUserOptions(CWB::config *cfg)
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
int j
Definition: cwb_net.C:28
i drho i
char ifo[NIFO_MAX][8]
Definition: cwb2G.hh:33
network ** net
NOISE_MDC_SIMULATION.
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
double GetSegEnd()
Definition: cwb.hh:183
jfile
Definition: cwb_job_obj.C:43
void ReadUserOptions(TString options)
int simulation
Definition: config.hh:199
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:69
i() int(T_cor *100))
char lagMode[1]
Definition: cwb.hh:294
double GetSegBegin()
Definition: cwb.hh:182
char parPlugin[1024]
Definition: config.hh:363
segLen
Definition: cwb_eced.C:24
int k
TObjArray * token
size_t lagSize
Definition: config.hh:168
void ResetUserOptions(network *net, CWB::config *cfg)
char options[256]
uoptions gOPT
int nIFO
Definition: config.hh:120
size_t lagMax
Definition: config.hh:171
TArrayC lagBuffer
Definition: cwb.hh:295
double lagStep
Definition: config.hh:169
size_t lagMax
Definition: test_config1.C:55
exit(0)
size_t lagSize
Definition: test_config1.C:52