Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CWB_Plugin_xWRC.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 "TComplex.h"
14 #include "TF2.h"
15 #include "TMath.h"
16 #include "mdc.hh"
17 #include "watplot.hh"
18 #include "gwavearray.hh"
19 #include "gskymap.hh"
20 #include <vector>
21 #include <iostream>
22 #include <algorithm>
23 
24 using namespace std;
25 
26 //#define SAVE_WHT_PLOT // enable event WHITE plots
27 //#define SAVE_WF_PLOT
28 //#define SAVE_SKYPROB
29 //#define SAVE_PLOT_WERR
30 
31 //#define SAVE_PLOT_WERR2
32 //#define SAVE_PLOT_RESIDUALS
33 //#define SAVE_MRA_PLOT // enable event MRA plots
34 //#define SAVE_WF_COMPARISON
35 
36 #define PLOT_DIR "plot"
37 
38 // ----------------------------------------------------
39 // WRC plugin functions
40 // ----------------------------------------------------
41 
43  double& enINJ, double& enREC, double& xcorINJ_REC);
44 
46 void DumpOutput(network* NET, netevent* &EVT, CWB::config* cfg, int ID, int k, int factor);
47 void GetRecWaveform(network* NET, netevent* EVT, int ID, int k, int factor);
48 void GetInjWaveform(network* NET, netevent* EVT, int ID, int k, int factor);
50 void ReadUserOptions();
51 void Clear();
52 void SetSkyMask(network* NET, CWB::config* cfg, int seed=0);
54 void Wave2Sparse(network* NET, CWB::config* cfg, char wave_type);
55 void SaveSkyProb(network* NET, CWB::config* cfg, int id);
58 double GetSparseMap(SSeries<double>* SS, bool phase, int index);
59 int _sse_mra_ps(network* NET, float* amp, float* AMP, float Eo, int K);
60 
61 void PlotFinal(int n);
62 void PlotFinal2(network* NET, int ID);
63 void PlotFinal3(network* NET, int ID, int ifoID, wavearray<double>* w1,
64  wavearray<double>* w2, TString tag, TString gtype="png");
66  CWB::config* cfg, bool fft=false, bool strain=false);
67 void PlotMRA(network* NET, int ID, int k, TString tag);
68 
69 // ----------------------------------------------------
70 // Temporary WRC structures
71 // ----------------------------------------------------
72 
74 wavearray<double> sINJ[NIFO_MAX]; // injected aligned to the same time
75 wavearray<double> rINJ[NIFO_MAX]; // injected waveform in wREC TF sub-domain
76 wavearray<double> wREC[NIFO_MAX]; // reconstructed
77 double wDINJ[NIFO_MAX]; // inj delays
78 double wDREC[NIFO_MAX]; // inj delays
79 
80 std::vector<SSeries<double> > vSS[NIFO_MAX]; // original sparse maps
81 std::vector<SSeries<double> > sSS[NIFO_MAX]; // injected aligned to the same time
82 std::vector<SSeries<double> > rSS[NIFO_MAX]; // reconstructed
83 std::vector<SSeries<double> > jSS[NIFO_MAX]; // injected
84 std::vector<WSeries<double> > vN[NIFO_MAX]; // sim noise
85 
86 std::vector<int> wTRY[NIFO_MAX];
87 std::vector<double> wAVR[NIFO_MAX];
88 std::vector<double> wRMS[NIFO_MAX];
89 
90 std::vector<wavearray<double> > vREC[NIFO_MAX]; // reconstructed
91 std::vector<double> vDREC[NIFO_MAX]; // detector rec waveform delays
92 
93 wavearray<int> sI; // shuffle index array
94 
96 TTree* net_tree = NULL;
98 bool detected=false;
99 
100 skymap rec_skyprob; // save reconstructed probability skymap
101 TH1D hist_skyprob; // used to extract random skyloc for skymask
102 
103 double inj_phi; // save injected phi
104 double inj_theta; // save injected theta
105 
106 double rec_phi; // save reconstructed phi
107 double rec_theta; // save reconstructed theta
108 
109 float rec_erA[11]; // save reconstructed error regions
110 
111 // ----------------------------------------------------
112 // Config Parameters
113 // ----------------------------------------------------
114 
115 //#define USE_wINJ // use wINJ (default wREC) (are pixels used as inj+noise in the retry)
116 //#define USE_wWHT // use wWHT (default wREC)
117 
118 #define SKYMASK_SEED 0
119 
120 #define APPLY_INJ_MRA
121 
122 
123 // user config options : default values or read from command line
130 int WRC_CED_RETRY_CONFIG=0; // dump CED at gLRETRY=WRC_CED_RETRY
133 
134 // config options used in the plugin
135 bool WRC_SKYMASK=false;
136 bool WRC_NOISE=false;
137 int WRC_RETRY=0;
138 bool WRC_AMP_CAL_ERR=false;
139 bool WRC_PHS_CAL_ERR=false;
141 int WRC_CED_RETRY=0; // dump CED at gLRETRY=WRC_CED_RETRY
142 int WRC_ID=0;
144 
145 #define AMP_CAL_ERR 0.1
146 #define PHS_CAL_ERR 10
147 
148 //#define COMPUTE_RESIDUAL_ENERGY
149 
150 // ----------------------------------------------------
151 // Output Parameters
152 // ----------------------------------------------------
153 
154 float erR[11]; // probability distribution of residuals
155 
156 #define nPAR 7
157 
158 TString parName[nPAR] = { "wrc_try",
159  "wrc_wf_noise",
160  "wrc_sm_phi",
161  "wrc_sm_theta",
162  "wrc_sm_radius",
163  "wrc_cal_amp",
164  "wrc_cal_phs"
165  };
166 float parValue[nPAR];
167 
168 float WRC_WF_NOISE=0;
171 float WRC_SM_RADIUS=0.1;
172 float WRC_CAL_AMP=0;
173 float WRC_CAL_PHS=0;
174 
175 #define WRC_PLUGIN_VERSION "v1.3"
176 
177 void
179 //!NOISE_MDC_SIMULATION
180 // This plugin is for Waveform Reconstruction Challenge (WRC) studies
181 // using the last Likelihood Stage Event Loop functionality
182 
183  cout << endl;
184  cout << "-----> CWB_Plugin_xWRC.C - " << WRC_PLUGIN_VERSION << endl;
185  cout << "ifo " << ifo.Data() << endl;
186  cout << "type " << type << endl;
187  cout << endl;
188 
189  if(type==CWB_PLUGIN_CONFIG) {
190 
191  cfg->outPlugin=true; // disable built-in output root file
192 
193  // set default config options
202 
203  // user config options : read from command line
204  ReadUserOptions();
205 
206  // print config options
207  cout << "-----------------------------------------" << endl;
208  cout << "WRC config options " << endl << endl;
209  cout << "WRC_RETRY " << WRC_RETRY << endl;
210  cout << "WRC_SKYMASK " << WRC_SKYMASK << endl;
211  cout << "WRC_NOISE " << WRC_NOISE << endl;
212  cout << "WRC_AMP_CAL_ERR " << WRC_AMP_CAL_ERR << endl;
213  cout << "WRC_PHS_CAL_ERR " << WRC_PHS_CAL_ERR << endl;
214  cout << "WRC_CED_ID " << WRC_CED_ID << endl;
215  cout << "WRC_CED_RETRY " << WRC_CED_RETRY << endl;
216  cout << "WRC_SKYMASK_REC_SKY " << WRC_SKYMASK_REC_SKY << endl;
217  cout << endl;
218  }
219 
220  if(type==CWB_PLUGIN_NETWORK) {
221  }
222 
223  if(type==CWB_PLUGIN_ILIKELIHOOD) {
224 
225  if(TString(cfg->analysis)!="2G") {
226  cout << "CWB_Plugin_xWRC.C -> CWB_PLUGIN_ILIKELIHOOD implemented only for 2G" << endl;
227  gSystem->Exit(1);
228  }
229 
230  if(NET->nLag!=1) {
231  cout << "CWB_Plugin_xWRC.C -> implemented only for zero lag" << endl;
232  gSystem->Exit(1);
233  }
234 
235  // export gLRETRY
236  EXPORT(int,gLRETRY,TString::Format("gLRETRY = %d;",WRC_RETRY).Data())
237  }
238 
239  if(type==CWB_PLUGIN_XLIKELIHOOD) {
240 
241  if(TString(cfg->analysis)!="2G") {
242  cout << "CWB_Plugin_xWRC.C -> CWB_PLUGIN_XLIKELIHOOD implemented only for 2G" << endl;
243  gSystem->Exit(1);
244  }
245 
246  // import gLRETRY
247  int gLRETRY=-1; IMPORT(int,gLRETRY)
248  cout << "-----> CWB_Plugin_xWRC.C -> " << " gLRETRY : " << gLRETRY << "/" << WRC_RETRY << " - WRC : ";
249 
250  if(WRC_NOISE) cout << "N ";
251  if(WRC_AMP_CAL_ERR) cout << "A ";
252  if(WRC_PHS_CAL_ERR) cout << "P ";
253  if(WRC_SKYMASK) cout << "S ";
254  cout << " - ";
255 #ifdef USE_wINJ // use wINJ (default wREC) (are pixels used as inj+noise in the retry)
256  cout << "wJ ";
257 #endif
258 #ifdef USE_wWHT // use wWHT (default wREC)
259  cout << "wW ";
260 #endif
261 #if !defined (USE_wINJ) && !defined (USE_wWHT)
262  cout << "wR ";
263 #endif
264  cout << endl;
265  if((WRC_NOISE||WRC_AMP_CAL_ERR||WRC_PHS_CAL_ERR) && gLRETRY<WRC_RETRY) {
266  if(rSS[0].size()>0) AddNoise2Sparse(NET,cfg, 0);
267  }
268  if(WRC_SKYMASK && gLRETRY<WRC_RETRY) SetSkyMask(NET, cfg, SKYMASK_SEED); // set new skymask
269 
270  if(gLRETRY==WRC_RETRY) { // first time
271  cfg->nSky=-999; NET->nSky=cfg->nSky;
272  } else {
273  cfg->nSky=1000; NET->nSky=cfg->nSky;
274  }
275 
276  if(WRC_CED_RETRY) {
277  if(gLRETRY==WRC_CED_RETRY) {
278  cfg->cedDump=true;
279  } else {
280  cfg->cedDump=false;
281  }
282  }
283 
284  // for each neew event the wrc config is initialized with the user input wrc values
285  if(gLRETRY==WRC_RETRY) { // first time
293 
294  // restore full skymask
295  sprintf(cfg->skyMaskFile,"--theta %f --phi %f --radius %f",0.,0.,360.);
296  //cout << cfg->skyMaskFile << endl;
297  xCWB.SetSkyMask(NET,cfg,cfg->skyMaskFile,'e');
298  }
299  }
300 
301  if(type==CWB_PLUGIN_OLIKELIHOOD) {
302 
303  if(TString(cfg->analysis)!="2G") {
304  cout << "CWB_Plugin_xWRC.C -> CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
305  gSystem->Exit(1);
306  }
307 
308  // import retry
309  int gLRETRY=-1; IMPORT(int,gLRETRY)
310 
311  // import ifactor
312  int gIFACTOR=-1; IMPORT(int,gIFACTOR)
313  double factor = cfg->simulation==3||cfg->simulation==4 ? -gIFACTOR : cfg->factors[gIFACTOR];
314  double ofactor=0;
315  if(cfg->simulation==4) ofactor=-factor;
316  else if(cfg->simulation==3) ofactor=-gIFACTOR;
317  else ofactor=factor;
318 
319  int nIFO = NET->ifoListSize(); // number of detectors
320  int rate = 0; // select all resolutions
321  int zlag = 0; // zelect only zero lag
322  netevent* EVT;
323 
324  SetOutput(NET, EVT, cfg); // set output root file
325 
326  wavearray<double>id = NET->getwc(zlag)->get(const_cast<char*>("ID"), 0, 'L', rate);
327 
328  for(int j=0; j<(int)id.size(); j++) { // loop over cluster index
329 
330  int ID = size_t(id.data[j]+0.5);
331 
332  if(NET->getwc(zlag)->sCuts[ID-1]!=-1) continue; // skip rejected/processed clusters
333 
334  if(WRC_ID>0 && ID!=WRC_ID) { // skip wrc analysis if ID!=WRC_ID
335  EXPORT(int,gLRETRY,"gLRETRY = 0;")
336  NET->getwc(zlag)->sCuts[ID-1]=1; // mark as processed
337  continue;
338  }
339 
340  if(WRC_CED_ID) { // enable/disable CED
341  if(ID==WRC_CED_ID) {
342  cfg->cedDump=true;
343  } else {
344  cfg->cedDump=false;
345  }
346  }
347 
348  if(gLRETRY==WRC_RETRY) { // mark event as detected
349  detected=true;
350  cout << "-----> Event Detected ID = " << ID << endl;
351  }
352 
353  GetRecWaveform(NET, EVT, ID, zlag, ofactor); // get & save reconstructed waveform
354 
355 #if defined (SAVE_PLOT_WERR) || defined (SAVE_PLOT_WERR2) || (SAVE_WHT_PLOT)
356  if(gLRETRY<WRC_RETRY) {
357  for(int n=0; n<nIFO; n++) {
358  wavearray<double>* wfINJ = &wINJ[n]; // injected waveform
359  wavearray<double>* wfREC = &vREC[n][vREC[n].size()-1]; // reconstructed waveform
360  ComputeErrorWF(wfINJ, wfREC, n);
361  }
362 #ifdef SAVE_WHT_PLOT
363  PlotWaveform(NET->ifoName[n], wfINJ, wfREC, cfg, false, false); // time
364  PlotWaveform(NET->ifoName[n], wfINJ, wfREC, cfg, true, false); // fft
365 #endif
366  }
367 
368  if(gLRETRY==0 && detected) { // last time
369  // final computation of the waveform errors
370  for(int n=0;n<nIFO;n++) {
371  for(int j=0;j<wAVR[n].size();j++) {
372  if(wTRY[n][j]==0) continue;
373  wAVR[n][j]/=wTRY[n][j];
374  wRMS[n][j]/=wTRY[n][j];
375  wRMS[n][j]-=wAVR[n][j]*wAVR[n][j];
376  wRMS[n][j] =sqrt(wRMS[n][j]);
377  //cout << n << " " << j << " wINJ : " << wINJ[n][j] << " wAVR : " << wAVR[n][j]
378  // << " wRMS : " << wRMS[n][j] << endl;
379  }
380 #ifdef SAVE_PLOT_WERR
381  PlotFinal(n);
382 #endif
383  }
384 #ifdef SAVE_PLOT_WERR2
385  PlotFinal2(NET, ID);
386 #endif
387  }
388 #endif
389 
390  if(gLRETRY==0 && detected) { // last time
391 #ifdef SAVE_MRA_PLOT // monster event display
392  PlotMRA(NET, ID, zlag, "last_wREC");
393 #endif
394  if(WRC_RETRY>0) ComputeErrorStatistic(NET, cfg, ID); // compute final waveform error statistic
395  DumpOutput(NET, EVT, cfg, ID, zlag, ofactor); // dump event to output root file
396  }
397 
398  // warning : must be done after DumpOutput (GetRInjWaveform destroy original pwc)
399  if(gLRETRY==WRC_RETRY) { // first time
400 #ifdef SAVE_MRA_PLOT // monster event display
401  PlotMRA(NET, ID, zlag, "wREC");
402 #endif
403 
404  GetInjWaveform(NET, EVT, ID, zlag, factor); // get & save injected waveform
405 
406  Wave2Sparse(NET,cfg,'v'); // save original sparse map to vSS
407  Wave2Sparse(NET,cfg,'r'); // rec
408  Wave2Sparse(NET,cfg,'j'); // inj
409  Wave2Sparse(NET,cfg,'s'); // wht
410  Wave2Sparse(NET,cfg,'n'); // noise
411  SaveSkyProb(NET,cfg,ID);
412 
413  GetRInjWaveform(NET, EVT, cfg, ID, zlag); // get injected waveform in wREC TF sub-domain
414  }
415 
416  // in the last loop the original event is reprocessed
417  // because must be saved on the final root file
418  if(gLRETRY==1 && detected) {
419  WRC_SKYMASK=true;
420  WRC_NOISE=false;
421  WRC_AMP_CAL_ERR=false;
422  WRC_PHS_CAL_ERR=false;
423  WRC_SKYMASK_REC_SKY=true;
424 
425  // restore original sparse maps
426  for(int n=0;n<nIFO;n++) {
427  detector* pD = NET->getifo(n);
428  pD->vSS=vSS[n];
429  }
430  }
431 
432  if(gLRETRY==0 && detected) { // last time
433 
434  // restore original sparse maps
435  for(int n=0;n<nIFO;n++) {
436  detector* pD = NET->getifo(n);
437  pD->vSS=vSS[n];
438  }
439 
440  // clean all temporary WRC structures
441  Clear();
442  detected=false;
443  }
444  }
445 
446  jfile->cd();
447 
448  if(EVT) delete EVT;
449  }
450 
451  return;
452 }
453 
455  double& enINJ, double& enREC, double& xcorINJ_REC) {
456 
457  double bINJ = wfINJ->start();
458  double eINJ = wfINJ->stop();
459  double bREC = wfREC->start();
460  double eREC = wfREC->stop();
461  //cout.precision(14);
462  //cout << "bINJ : " << bINJ << " eINJ : " << eINJ << endl;
463  //cout << "bREC : " << bREC << " eREC : " << eREC << endl;
464 
465  double R=wfINJ->rate();
466 
467  int oINJ = bINJ>bREC ? 0 : int((bREC-bINJ)*R+0.5);
468  int oREC = bINJ<bREC ? 0 : int((bINJ-bREC)*R+0.5);
469  //cout << "oINJ : " << oINJ << " oREC : " << oREC << endl;
470 
471  double startXCOR = bINJ>bREC ? bINJ : bREC;
472  double endXCOR = eINJ<eREC ? eINJ : eREC;
473  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
474  //cout << "startXCOR : " << startXCOR << " endXCOR : "
475  // << endXCOR << " sizeXCOR :" << sizeXCOR << endl;
476 
477  enINJ=0;
478  enREC=0;
479  xcorINJ_REC=0;
480  if (sizeXCOR<=0) return;
481 
482  // the enINJ, enREC, xcorINJ_REC are computed in the INJ range
483  for (int i=0;i<wfINJ->size();i++) enINJ+=wfINJ->data[i]*wfINJ->data[i];
484  for (int i=0;i<sizeXCOR;i++) enREC+=wfREC->data[i+oREC]*wfREC->data[i+oREC];
485  for (int i=0;i<sizeXCOR;i++) xcorINJ_REC+=wfINJ->data[i+oINJ]*wfREC->data[i+oREC];
486 
487  double erINJ_REC = enINJ+enREC-2*xcorINJ_REC;
488  //cout << "enINJ : " << enINJ << " enREC : " << enREC
489  // << " xcorINJ_REC : " << xcorINJ_REC << " enINJREC : " << enINJ+enREC-2*xcorINJ_REC << endl;
490  //cout << "erINJ_REC/enINJ : " << erINJ_REC/enINJ << endl;
491 
492  return;
493 }
494 
496 
497  double bINJ = wfINJ->start();
498  double eINJ = wfINJ->stop();
499  double bREC = wfREC->start();
500  double eREC = wfREC->stop();
501  //cout.precision(14);
502  //cout << "bINJ : " << bINJ << " eINJ : " << eINJ << endl;
503  //cout << "bREC : " << bREC << " eREC : " << eREC << endl;
504 
505  double R=wfINJ->rate();
506 
507  int oINJ = bINJ>bREC ? 0 : int((bREC-bINJ)*R+0.5);
508  int oREC = bINJ<bREC ? 0 : int((bINJ-bREC)*R+0.5);
509  //cout << "oINJ : " << oINJ << " oREC : " << oREC << endl;
510 
511  double startXCOR = bINJ>bREC ? bINJ : bREC;
512  double endXCOR = eINJ<eREC ? eINJ : eREC;
513  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
514  //cout << "startXCOR : " << startXCOR << " endXCOR : "
515  // << endXCOR << " sizeXCOR :" << sizeXCOR << endl;
516 
517  for (int i=0;i<sizeXCOR;i++) {
518  wTRY[ifoID][i+oINJ]+=1;
519  wAVR[ifoID][i+oINJ]+=wfREC->data[i+oREC];
520  wRMS[ifoID][i+oINJ]+=wfREC->data[i+oREC]*wfREC->data[i+oREC];
521  }
522 
523  return;
524 }
525 
526 void PlotMRA(network* NET, int ID, int k, TString tag) {
527 
528  if(NET->getwc(k)->sCuts[ID-1]!=-1) return; // no events
529 
530  // set sCuts=1 for the events which must be not copied with cps to pwc
531  std::vector<int> sCuts = NET->getwc(k)->sCuts; // save sCuts
532  for(int i=0; i<(int)sCuts.size(); i++) if(i!=ID-1) NET->getwc(k)->sCuts[i]=1;
533  // after cpf, pwc contains only one event
534  // ID can not be used to get the event, to get event use ID=1 (ex: for watplot)
535  netcluster* pwc = new netcluster();
536  pwc->cpf(*(NET->getwc(k))); // note: likelihood2G delete tdAmp
537 
538  int nIFO = NET->ifoListSize(); // number of detectors
539  watplot WTS(const_cast<char*>("wts"));
540  WTS.canvas->cd();
541  char fname[1024];
542  sprintf(fname, "%s/%s_l_tfmap_scalogram_%d.png",PLOT_DIR,tag.Data(),ID);
543  cout << "write " << fname << endl;
544  WTS.plot(pwc, 1, nIFO, 'L', 0, const_cast<char*>("COLZ"));
545  WTS.canvas->Print(fname);
546  WTS.clear();
547  sprintf(fname, "%s/%s_n_tfmap_scalogram_%d.png",PLOT_DIR,tag.Data(),ID);
548  cout << "write " << fname << endl;
549  WTS.plot(pwc, 1, nIFO, 'N', 0, const_cast<char*>("COLZ"));
550  WTS.canvas->Print(fname);
551  WTS.clear();
552 
553  if(pwc) delete pwc;
554  NET->getwc(k)->sCuts = sCuts; // restore sCuts
555 }
556 
558  CWB::config* cfg, bool fft, bool strain) {
559 
560  watplot PTS(const_cast<char*>("ptswrc"),200,20,800,500);
561 
562  //cout << "Print " << fname << endl;
563  double tmin = wfINJ->start()<wfREC->start() ? wfINJ->start() : wfREC->start();
564  wfINJ->start(wfINJ->start()-tmin);
565  wfREC->start(wfREC->start()-tmin);
566  if(fft) {
567  PTS.plot(wfINJ, const_cast<char*>("ALP"), 1, 0, 0, true, cfg->fLow, cfg->fHigh);
568  } else {
569  PTS.plot(wfINJ, const_cast<char*>("ALP"), 1, 0, 0);
570  }
571  PTS.graph[0]->SetLineWidth(1);
572  if(fft) {
573  PTS.plot(wfREC, const_cast<char*>("SAME"), 2, 0, 0, true, cfg->fLow, cfg->fHigh);
574  } else {
575  PTS.plot(wfREC, const_cast<char*>("SAME"), 2, 0, 0);
576  }
577  PTS.graph[1]->SetLineWidth(2);
578  wfINJ->start(wfINJ->start()+tmin);
579  wfREC->start(wfREC->start()+tmin);
580 
581  char label[64]="";
582  if(fft) sprintf(label,"%s","fft");
583  else sprintf(label,"%s","time");
584  if(strain) sprintf(label,"%s_%s",label,"strain");
585  else sprintf(label,"%s_%s",label,"white");
586 
587  char fname[1024];
588  sprintf(fname, "%s/%s_wf_%s_inj_rec_gps_%d.root",PLOT_DIR,ifo.Data(),label,int(tmin));
589  PTS.canvas->Print(fname);
590  cout << "write : " << fname << endl;
591  //PTS.canvas->Write(REPLACE(fname,dirCED,gtype));
592 }
593 
595 
596  // NEW SKYMAP
597 
598  gRandom->SetSeed(seed);
599  int isky = (int)hist_skyprob.GetRandom();
600  WRC_SM_THETA = 90-rec_skyprob.getTheta(isky);
601  WRC_SM_PHI = rec_skyprob.getPhi(isky);
602 
603  if(WRC_SKYMASK_REC_SKY) {
604  WRC_SM_THETA = 90-rec_theta;
606  }
607 
608 /*
609  // test code : use injected sky location for skymask
610  WRC_SM_THETA = 90-inj_theta;
611  WRC_SM_PHI = inj_phi;
612 */
613 
614  // --------------------------------------------------------
615  // define SetSkyMask
616  // --------------------------------------------------------
617  sprintf(cfg->skyMaskFile,"--theta %f --phi %f --radius %f",WRC_SM_THETA,WRC_SM_PHI,WRC_SM_RADIUS);
618  cout << cfg->skyMaskFile << endl;
619  xCWB.SetSkyMask(NET,cfg,cfg->skyMaskFile,'e');
620 
621 }
622 
623 void Wave2Sparse(network* NET, CWB::config* cfg, char wave_type) {
624 
625  if(wave_type!='j' && wave_type!='r' && wave_type!='s' && wave_type!='n' && wave_type!='v') {
626  cout << "Wave2Sparse - Error : wrong wave type" << endl; exit(1);
627  }
628 
629  gRandom->SetSeed(0);
630 
631  //cout << "-----------------> Wave2Sparse" << endl;
632 
633  // init waveform sparse maps
634  int nIFO = NET->ifoListSize(); // number of detectors
635  for(int n=0;n<nIFO;n++) {
636  detector* pD = NET->getifo(n);
637  if(wave_type=='v') vSS[n]=pD->vSS;
638  if(wave_type=='r') rSS[n]=pD->vSS;
639  if(wave_type=='j') jSS[n]=pD->vSS;
640  if(wave_type=='s') sSS[n]=pD->vSS;
641  }
642  if(wave_type=='v') return;
643 
644  int nRES = cfg->l_high-cfg->l_low+1; // number of frequency resolution levels
645 
646  // build waveform array
648  for(int n=0; n<nIFO; n++) {
649 
650  if(wave_type=='s') {
651  WF[n].resize(sSS[n][0].wdm_nSTS);
652  WF[n].rate(sSS[n][0].wdm_rate);
653  WF[n].start(sSS[n][0].wdm_start);
654  WF[n]=0;
655  int wos = double(sINJ[n].start()-WF[n].start())*WF[n].rate();
656  for (int i=0;i<sINJ[n].size();i++) WF[n][wos+i] = sINJ[n][i];
657  }
658  if(wave_type=='j') {
659  WF[n].resize(jSS[n][0].wdm_nSTS);
660  WF[n].rate(jSS[n][0].wdm_rate);
661  WF[n].start(jSS[n][0].wdm_start);
662  WF[n]=0;
663  int wos = double(wINJ[n].start()-WF[n].start())*WF[n].rate();
664  for (int i=0;i<wINJ[n].size();i++) WF[n][wos+i] = wINJ[n][i];
665  }
666  if(wave_type=='r') {
667  WF[n].resize(rSS[n][0].wdm_nSTS);
668  WF[n].rate(rSS[n][0].wdm_rate);
669  WF[n].start(rSS[n][0].wdm_start);
670  WF[n]=0;
671  int wos = double(wREC[n].start()-WF[n].start())*WF[n].rate();
672  for (int i=0;i<wREC[n].size();i++) WF[n][wos+i] = wREC[n][i];
673  }
674  if(wave_type=='n') { // noise
675  detector* pD = NET->getifo(n);
676  WF[n].resize(pD->vSS[0].wdm_nSTS);
677  WF[n].rate(pD->vSS[0].wdm_rate);
678  WF[n].start(pD->vSS[0].wdm_start);
679  WF[n]=0;
680  for (int i=0;i<WF[n].size();i++) WF[n][i] = gRandom->Gaus(0,1);
681  }
682 
683 #ifdef SAVE_WF_PLOT
684  gwavearray<double> gw(&WF[n]);
685  gw.Draw(GWAT_TIME);
686  watplot* plot = gw.GetWATPLOT();
687  TString gfile;
688  if(wave_type=='r') gfile=TString::Format("%s/REC_%s.png",PLOT_DIR,NET->ifoName[n]);
689  if(wave_type=='j') gfile=TString::Format("%s/INJ_%s.png",PLOT_DIR,NET->ifoName[n]);
690  if(wave_type=='s') gfile=TString::Format("%s/sINJ_%s.png",PLOT_DIR,NET->ifoName[n]);
691  if(wave_type!='n') (*plot) >> gfile;
692 #endif
693  }
694 
695  // fill waveform sparse maps
697  WDM<double>* pwdm = NULL;
698  double r00,r90;
699  for(int n=0; n<nIFO; n++) {
700  for(int i=0; i<nRES; i++) {
701  int level = i+cfg->l_low;
702  int layers = level>0 ? 1<<level : 0;
703  pwdm = NET->getwdm(layers+1);
704  w.Forward(WF[n],*pwdm);
705 
706  if((wave_type=='n')&&(i==nRES-1)) { // time shuffled index for noise array vN
707  sI.resize(w.sizeZero());
708  for(int j=0;j<sI.size();j++) sI[j]=j;
709  }
710 
711  int size;
712  if(wave_type=='r') size = rSS[n][i].sparseMap00.size();
713  if(wave_type=='j') size = jSS[n][i].sparseMap00.size();
714  if(wave_type=='s') size = sSS[n][i].sparseMap00.size();
715  if(wave_type=='n') vN[n].push_back(w);
716 
717  for(int j=0; j<size; j++) {
718  int index;
719  if(wave_type=='r') index = rSS[n][i].sparseIndex[j];
720  if(wave_type=='j') index = jSS[n][i].sparseIndex[j];
721  if(wave_type=='s') index = sSS[n][i].sparseIndex[j];
722  double v00 = w.pWavelet->pWWS[index];
723  double v90 = w.pWavelet->pWWS[index+w.maxIndex()+1];
724  if(wave_type=='r') {
725  rSS[n][i].sparseMap00[j]=v00;
726  rSS[n][i].sparseMap90[j]=v90;
727  }
728  if(wave_type=='j') {
729  jSS[n][i].sparseMap00[j]=v00;
730  jSS[n][i].sparseMap90[j]=v90;
731  }
732  if(wave_type=='s') {
733  sSS[n][i].sparseMap00[j]=v00;
734  sSS[n][i].sparseMap90[j]=v90;
735  }
736  }
737  }
738  }
739 }
740 
742 
743  //cout << "-----------------> AddNoise2Sparse" << endl;
744 
745  gRandom->SetSeed(seed);
746 
747  TF2 *gaus2d = new TF2("gaus2d","exp(-x*x/2)*exp(-y*y/2)", -5,5,-5,5);
748 
749  double d2r = TMath::Pi()/180.;
750  double C,S;
751 
752  // copy waveform sparse to detector sparse map
753  int nIFO = NET->ifoListSize(); // number of detectors
754  for(int n=0;n<nIFO;n++) {
755  detector* pD = NET->getifo(n);
756 #ifdef USE_wWHT // use wWHT (default wREC)
757  if(vSS[n].size()>0) pD->vSS=vSS[n];
758 #else
759  if(rSS[n].size()>0) pD->vSS=rSS[n];
760 #endif
761  }
762 
763  int nRES = cfg->l_high-cfg->l_low+1; // number of frequency resolution levels
764 
765  // random shuffle of vN[i] time indexes
766  std::srand(time(0));
767  random_shuffle(&(sI.data[0]),&(sI.data[sI.size()]));
768 
769  // add noise/mis-calibration to sparse map
770  double r00,r90;
771  for(int n=0; n<nIFO; n++) {
772  detector* pD = NET->getifo(n);
773  if(WRC_AMP_CAL_ERR) {
774  WRC_CAL_AMP = gRandom->Uniform(1-AMP_CAL_ERR,1+AMP_CAL_ERR);
775  cout << "WRC_CAL_AMP : " << WRC_CAL_AMP << endl;
776  }
777  if(WRC_PHS_CAL_ERR) {
778  WRC_CAL_PHS = gRandom->Uniform(1-PHS_CAL_ERR,1+PHS_CAL_ERR);
779  cout << "WRC_CAL_PHS : " << WRC_CAL_PHS << endl;
780  C = cos(-WRC_CAL_PHS*d2r);
781  S = sin(-WRC_CAL_PHS*d2r);
782  }
783  for(int i=0; i<nRES; i++) {
784  int size = pD->vSS[i].sparseMap00.size();
785  for(int j=0; j<size; j++) {
786  if(WRC_AMP_CAL_ERR) {
787  pD->vSS[i].sparseMap00[j]*=WRC_CAL_AMP;
788  pD->vSS[i].sparseMap90[j]*=WRC_CAL_AMP;
789  }
790  if(WRC_PHS_CAL_ERR) {
791  double aa = pD->vSS[i].sparseMap00[j];
792  double AA = pD->vSS[i].sparseMap90[j];
793 
794  pD->vSS[i].sparseMap00[j] = C*aa + S*AA;
795  pD->vSS[i].sparseMap90[j] = -S*aa + C*AA ;
796  }
797  if(WRC_NOISE) {
798  int index = pD->vSS[i].sparseIndex[j];
799 
800  int layers = vN[n][i].maxLayer()+1; // numbers of frequency bins (first & last bins have df/2)
801  int slices = vN[n][i].sizeZero(); // number of time bins
802  //cout << "layers " << layers << " slices " << slices << endl;
803 
804  int levels = (1<<(nRES-1-i));
805 
806  // index = itime*layers + ifreq;
807  int ifreq = index%layers;
808  int itime = (index-ifreq)/layers;
809  itime = levels*sI[itime/levels];
810  index = itime*layers + ifreq; // shuffled index
811 
812  r00 = vN[n][i].pWavelet->pWWS[index];
813  r90 = vN[n][i].pWavelet->pWWS[index+vN[n][i].maxIndex()+1];
814  //gaus2d->GetRandom2(r00,r90);
815 
816  pD->vSS[i].sparseMap00[j]+=r00;
817  pD->vSS[i].sparseMap90[j]+=r90;
818  }
819  }
820  }
821  }
822 }
823 
825 
826  std::vector<float>* vP;
827  std::vector<int>* vI;
828 
829  // save the probability skymap
830  if(NET->wc_List[0].p_Map.size()) {
831 
832  vP = &(NET->wc_List[0].p_Map[id-1]);
833  vI = &(NET->wc_List[0].p_Ind[id-1]);
834 
835  rec_skyprob = NET->getifo(0)->tau;
836  rec_skyprob = 0.;
837 
838  for(int j=0; j<int(vP->size()); j++) {
839  int i = (*vI)[j];
840  double th = rec_skyprob.getTheta(i);
841  double ph = rec_skyprob.getPhi(i);
842  int k=rec_skyprob.getSkyIndex(th, ph);
843  rec_skyprob.set(k,(*vP)[j]);
844  }
845  }
846 
847  hist_skyprob.SetBins(rec_skyprob.size(),0,rec_skyprob.size()-1);
848 
849  double prob=0;
850  for(int l=0;l<rec_skyprob.size();l++) prob+=rec_skyprob.get(l);
851  cout << "PROB : " << prob << endl;
852  for(int l=0;l<rec_skyprob.size();l++) hist_skyprob.SetBinContent(l,rec_skyprob.get(l));
853 
854 #ifdef SAVE_SKYPROB
855  // plot rec_skyprob
857  //gSM.SetOptions("hammer","Celestial",2);
858  gSM.SetZaxisTitle("probability");
859  gSM.Draw(1);
860  //TH2D* hsm = gSM.GetHistogram();
861  //hsm->GetZaxis()->SetTitleOffset(0.85);
862  //hsm->GetZaxis()->SetTitleSize(0.03);
863  gSM.Print(TString::Format("%s/rec_skyprob.png",PLOT_DIR));
864  exit(0);
865 #endif
866 }
867 
868 void PlotFinal(int n) {
869 
870  // draw envelope
871  gwavearray<double> geINJ=wINJ[n];
872  CWB::mdc::PhaseShift(geINJ,90);
873  for(int j=0;j<geINJ.size();j++) geINJ[j]=sqrt(wINJ[n][j]*wINJ[n][j]+geINJ[j]*geINJ[j]);
874  geINJ.Draw(GWAT_TIME);
875 
876  gwavearray<double> geAVR=wINJ[n];
877  for(int j=0;j<wAVR[n].size();j++) geAVR[j]=wAVR[n][j];
878  CWB::mdc::PhaseShift(geAVR,90);
879  for(int j=0;j<geAVR.size();j++) geAVR[j]=sqrt(wAVR[n][j]*wAVR[n][j]+geAVR[j]*geAVR[j]);
880  geINJ.Draw(&geAVR,GWAT_TIME,"SAME",kRed);
881 
882  gwavearray<double> geRMS=wINJ[n];
883  for(int j=0;j<wRMS[n].size();j++) geRMS[j]=wRMS[n][j];
884  geINJ.Draw(&geRMS,GWAT_TIME,"SAME",kBlue);
885 
886  watplot* plot = geINJ.GetWATPLOT();
887  TString gfile=TString::Format("%s/eAVR_%d.root",PLOT_DIR,n);
888  (*plot) >> gfile;
889 
890 
891  // draw frequency
892  double dt=1./wINJ[n].rate();
893  double Pi = TMath::Pi();
894  wavearray<double> xx=wINJ[n];
895  wavearray<double> XX=wINJ[n];
896  CWB::mdc::PhaseShift(XX,90);
897  gwavearray<double> gF=wINJ[n];
898  for(int j=1;j<gF.size();j++) {
899 //double angle = atan2(XX[j],xx[j])*180/Pi;
900 //angle += ceil( -angle / 360 ) * 360;
901 //gF[j]=angle;
902  gF[j]=atan2(XX[j],xx[j])-atan2(XX[j-1],xx[j-1]);
903  if(gF[j]<-Pi) gF[j]+=2*Pi;
904  if(gF[j]> Pi) gF[j]-=2*Pi;
905  gF[j]/=2*Pi*dt;
906  }
907  gF.Draw(GWAT_TIME);
908 
909  wavearray<double> yy=wINJ[n];
910  for(int j=0;j<yy.size();j++) yy[j]=wAVR[n][j];
912  CWB::mdc::PhaseShift(YY,90);
913  gwavearray<double> gFF=wINJ[n];
914  for(int j=1;j<gFF.size();j++) {
915  gFF[j]=atan2(YY[j],yy[j])-atan2(YY[j-1],yy[j-1]);
916  if(gFF[j]<-Pi) gFF[j]+=2*Pi;
917  if(gFF[j]> Pi) gFF[j]-=2*Pi;
918  gFF[j]/=2*Pi*dt;
919  }
920  gF.Draw(&gFF,GWAT_TIME,"SAME",kRed);
921 
922  plot = gF.GetWATPLOT();
923  gfile=TString::Format("%s/FREQ_%d.root",PLOT_DIR,n);
924  (*plot) >> gfile;
925 
926 
927  // draw envelope difference
928  gwavearray<double> geDIF=wINJ[n];
929  for(int j=0;j<geDIF.size();j++) geDIF[j]=geAVR[j]-geINJ[j];
930  geDIF.Draw(GWAT_TIME);
931  geDIF.Draw(&geRMS,GWAT_TIME,"SAME",kBlue);
932 
933  plot = geDIF.GetWATPLOT();
934  gfile=TString::Format("%s/eDIF_%d.root",PLOT_DIR,n);
935  (*plot) >> gfile;
936 
937 
938  // draw waveforms INJ vs AVR
939  gwavearray<double> gwAVR=wINJ[n];
940  gwAVR.Draw(GWAT_TIME);
941  for(int j=0;j<wAVR[n].size();j++) gwAVR[j]=wAVR[n][j];
942  gwAVR.Draw(GWAT_TIME,"SAME",kRed);
943  for(int j=0;j<wAVR[n].size();j++) gwAVR[j]=wRMS[n][j];
944  gwAVR.Draw(GWAT_TIME,"SAME",kBlue);
945 
946  plot = gwAVR.GetWATPLOT();
947  gfile=TString::Format("%s/wAVR_%d.root",PLOT_DIR,n);
948  (*plot) >> gfile;
949 
950  // draw waveforms REC vs AVR/INJ
951 
952  double bINJ = wINJ[n].start();
953  double eINJ = wINJ[n].stop();
954  double bREC = wREC[n].start();
955  double eREC = wREC[n].stop();
956  cout.precision(14);
957  cout << "bINJ : " << bINJ << " eINJ : " << eINJ << endl;
958  cout << "bREC : " << bREC << " eREC : " << eREC << endl;
959 
960  double R=wINJ[n].rate();
961 
962  int oINJ = bINJ>bREC ? 0 : int((bREC-bINJ)*R+0.5);
963  int oREC = bINJ<bREC ? 0 : int((bINJ-bREC)*R+0.5);
964  cout << "oINJ : " << oINJ << " oREC : " << oREC << endl;
965 
966  double startXCOR = bINJ>bREC ? bINJ : bREC;
967  double endXCOR = eINJ<eREC ? eINJ : eREC;
968  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
969  cout << "sizeXCOR : " << sizeXCOR << endl;
970  cout << "wINJ[n].size() : " << wINJ[n].size() << endl;
971  cout << "wREC[n].size() : " << wREC[n].size() << endl;
972 
973  gwavearray<double> gwREC = wINJ[n];
974  for(int j=0;j<sizeXCOR;j++) gwREC[j+oINJ]=wREC[n][j+oREC];
975  gwREC.Draw(GWAT_TIME);
976  //for(int j=0;j<wAVR[n].size();j++) gwREC[j]=wAVR[n][j];
977  for(int j=0;j<wINJ[n].size();j++) gwREC[j]=wINJ[n][j];
978  gwREC.Draw(GWAT_TIME,"SAME",kRed);
979  for(int j=0;j<wAVR[n].size();j++) gwREC[j]=wRMS[n][j];
980  gwREC.Draw(GWAT_TIME,"SAME",kBlue);
981 
982  plot = gwREC.GetWATPLOT();
983  gfile=TString::Format("%s/wREC_%d.root",PLOT_DIR,n);
984  (*plot) >> gfile;
985 }
986 
987 double GetSparseMap(SSeries<double>* SS, bool phase, int index) {
988 
989  int layer = SS->GetLayer(index);
990  int start = SS->sparseLookup[layer]; // sparse table layer offset
991  int end = SS->sparseLookup[layer+1]-1; // sparse table layer+1 offset
992 
993  int i = SS->binarySearch(SS->sparseIndex.data,start,end,index);
994 
995  if(i<0) return 0;
996 
997  return phase ? SS->sparseMap00[i] : SS->sparseMap90[i];
998 }
999 
1000 void PlotFinal2(network* NET, int ID) {
1001 
1002  double tMin,tMax;
1003  double start; // use ifoID=0 as offset
1004 
1005  int nIFO = NET->ifoListSize(); // number of detectors
1006 
1007  for(int n=0;n<nIFO;n++) {
1008 
1009  // draw waveforms INJ vs AVR
1010  gwavearray<double> gw=wINJ[n];
1011  //gwavearray<double> gw=rINJ[n];
1012 
1013  if(n==0) {
1014  start = gw.start();
1015  gw.GetTimeRange(tMin, tMax, 0.998);
1016  cout << "tMin " << tMin << " tMax " << tMax << endl;
1017  }
1018  gw.SetTimeRange(start+tMin, start+tMax);
1019  gw.Draw(GWAT_TIME, "CUSTOM");
1020  for(int j=0;j<wAVR[n].size();j++) gw[j]=wAVR[n][j];
1021  gw.Draw(GWAT_TIME,"SAME",kRed);
1022  for(int j=0;j<wAVR[n].size();j++) gw[j]=wRMS[n][j];
1023  gw.Draw(GWAT_TIME,"SAME",kBlue);
1024 
1025  watplot* plot = gw.GetWATPLOT();
1026 
1027  char gtitle[256];
1028  sprintf(gtitle,"%s : %10.3f (gps) - injected(Black) - average(Red) - rms(Blue)",gw.start(),NET->ifoName[n]);
1029  plot->gtitle(gtitle,"time(sec)","amplitude");
1030 
1031  TString gfile=TString::Format("%s/inj_vs_avr_%s_%d.root",PLOT_DIR,NET->ifoName[n],ID);
1032  //TString gfile=TString::Format("%s/rinj_vs_avr_%s_%d.root",PLOT_DIR,NET->ifoName[n],ID);
1033  (*plot) >> gfile;
1034 
1035  }
1036 }
1037 
1039 
1040  double tMin,tMax;
1041  double start; // use ifoID=0 as offset
1042 
1043  // draw waveforms INJ vs AVR
1044  gwavearray<double> gw=*w1;
1045 
1046  start = gw.start();
1047  gw.GetTimeRange(tMin, tMax, 0.998);
1048  cout << "tMin " << tMin << " tMax " << tMax << endl;
1049 
1050  gw.SetTimeRange(start+tMin, start+tMax);
1051  gw.Draw(GWAT_TIME, "CUSTOM");
1052  gw.Draw(w2,GWAT_TIME,"SAME",kRed);
1053 
1054  watplot* plot = gw.GetWATPLOT();
1055 
1056  char gtitle[256];
1057  sprintf(gtitle,"%s : %10.3f (gps) - %s",gw.start(),NET->ifoName[ifoID],tag.Data());
1058  plot->gtitle(gtitle,"time(sec)","amplitude");
1059 
1060  TString gfile=TString::Format("%s/%s_%s_%d.%s",PLOT_DIR,tag.Data(),NET->ifoName[ifoID],ID,gtype.Data());
1061  (*plot) >> gfile;
1062 
1063 }
1064 
1066 
1067  int nIFO = NET->ifoListSize(); // number of detectors
1068 
1069  double enINJ[NIFO_MAX], enREC[NIFO_MAX], xcorINJ_REC[NIFO_MAX];
1070 
1071  // shift all data to the first ifo arrival time
1072  for(int n=0;n<nIFO;n++) {
1073  CWB::mdc::TimeShift(wREC[n],-wDREC[n]);
1074  if(cfg->simulation) CWB::mdc::TimeShift(wINJ[n],-wDINJ[n]);
1075  if(cfg->simulation) CWB::mdc::TimeShift(rINJ[n],-wDREC[n]);
1076  for(int i=0;i<vREC[n].size();i++) {
1077  CWB::mdc::TimeShift(vREC[n][i],-vDREC[n][i]);
1078  }
1079  }
1080 
1081  double rnum=0;
1082  double rden=0;
1083 /*
1084  for(int n=0;n<nIFO;n++) {
1085  ComputeResidualEnergy(&wINJ[n], &wREC[n], enINJ[n], enREC[n], xcorINJ_REC[n]);
1086  //cout << n << " RESIDUAL : " << (enINJ[n]+enREC[n]-2*xcorINJ_REC[n])/enINJ[n] << endl;
1087  rnum+=(enINJ[n]+enREC[n]-2*xcorINJ_REC[n]);
1088  rden+=enINJ[n];
1089  }
1090  cout << "NET RESIDUAL : " << rnum/rden << endl;
1091 */
1092  // copy wINJ (only the wREC time range) into winj
1094  if(cfg->simulation) {
1095  for(int n=0;n<nIFO;n++) {
1096  winj[n]=wREC[n];
1097  winj[n]=0;
1098 
1099  double bINJ = wINJ[n].start();
1100  double eINJ = wINJ[n].stop();
1101  double bREC = wREC[n].start();
1102  double eREC = wREC[n].stop();
1103 
1104  double R=wINJ[0].rate();
1105 
1106  int oINJ = bINJ>bREC ? 0 : int((bREC-bINJ)*R+0.5);
1107  int oREC = bINJ<bREC ? 0 : int((bINJ-bREC)*R+0.5);
1108 
1109  double startXCOR = bINJ>bREC ? bINJ : bREC;
1110  double endXCOR = eINJ<eREC ? eINJ : eREC;
1111  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
1112 
1113  if (sizeXCOR<=0) continue;
1114 
1115  for (int j=0;j<sizeXCOR;j++) winj[n][j+oREC]+=wINJ[n].data[j+oINJ];
1116  }
1117  }
1118 
1119  // copy vREC (only the wREC time range) into wavr
1121  for(int n=0;n<nIFO;n++) {
1122  wavr[n]=wREC[n];
1123  wavr[n]=0;
1124  double bINJ = wREC[n].start();
1125  double eINJ = wREC[n].stop();
1126  for(int i=0;i<vREC[n].size();i++) {
1127 
1128  double bREC = vREC[n][i].start();
1129  double eREC = vREC[n][i].stop();
1130  //cout.precision(14);
1131  //cout << "bINJ : " << bINJ << " eINJ : " << eINJ << endl;
1132  //cout << "bREC : " << bREC << " eREC : " << eREC << endl;
1133 
1134  double R=wREC[n].rate();
1135 
1136  int oINJ = bINJ>bREC ? 0 : int((bREC-bINJ)*R+0.5);
1137  int oREC = bINJ<bREC ? 0 : int((bINJ-bREC)*R+0.5);
1138  //cout << "oINJ : " << oINJ << " oREC : " << oREC << endl;
1139 
1140  double startXCOR = bINJ>bREC ? bINJ : bREC;
1141  double endXCOR = eINJ<eREC ? eINJ : eREC;
1142  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
1143  //cout << "startXCOR : " << startXCOR << " endXCOR : "
1144  // << endXCOR << " sizeXCOR :" << sizeXCOR << endl;
1145 
1146  if (sizeXCOR<=0) continue;
1147 
1148  for (int j=0;j<sizeXCOR;j++) wavr[n][j+oINJ]+=vREC[n][i].data[j+oREC];
1149  }
1150  wavr[n]*=1./vREC[n].size();
1151  }
1152 
1153  wavearray<float> vRES(vREC[0].size());
1154 
1155  for(int i=0;i<vREC[0].size();i++) {
1156  rnum=0;
1157  rden=0;
1158  for(int n=0;n<nIFO;n++) {
1159  ComputeResidualEnergy(&wavr[n], &vREC[n][i], enINJ[n], enREC[n], xcorINJ_REC[n]);
1160  //cout << i << " " << n << " RESIDUAL : " << (enINJ[n]+enREC[n]-2*xcorINJ_REC[n])/enINJ[n] << endl;
1161  rnum+=(enINJ[n]+enREC[n]-2*xcorINJ_REC[n]);
1162  rden+=enINJ[n];
1163  }
1164  //cout << "vRECvsAVR NET RESIDUAL : " << rnum/rden << endl;
1165  vRES[i]=rnum/rden;
1166  }
1167 
1168  double jres=0;
1169  if(cfg->simulation) {
1170  rnum=0;
1171  rden=0;
1172  for(int n=0;n<nIFO;n++) {
1173  ComputeResidualEnergy(&wavr[n], &winj[n], enINJ[n], enREC[n], xcorINJ_REC[n]);
1174  //cout << n << " RESIDUAL : " << (enINJ[n]+enREC[n]-2*xcorINJ_REC[n])/enINJ[n] << endl;
1175  rnum+=(enINJ[n]+enREC[n]-2*xcorINJ_REC[n]);
1176  rden+=enINJ[n];
1177  }
1178  //cout << "INJvsAVR NET RESIDUAL : " << rnum/rden << endl;
1179 
1180  rnum=0;
1181  rden=0;
1182  for(int n=0;n<nIFO;n++) {
1183  ComputeResidualEnergy(&wavr[n], &rINJ[n], enINJ[n], enREC[n], xcorINJ_REC[n]);
1184  //cout << n << " RESIDUAL : " << (enINJ[n]+enREC[n]-2*xcorINJ_REC[n])/enINJ[n] << endl;
1185  rnum+=(enINJ[n]+enREC[n]-2*xcorINJ_REC[n]);
1186  rden+=enINJ[n];
1187  }
1188  jres=rnum/rden;
1189  //cout << "rINJvsAVR NET RESIDUAL : " << rnum/rden << endl;
1190  }
1191 
1192  rnum=0;
1193  rden=0;
1194  for(int n=0;n<nIFO;n++) {
1195  ComputeResidualEnergy(&wavr[n], &wREC[n], enINJ[n], enREC[n], xcorINJ_REC[n]);
1196  //cout << n << " RESIDUAL : " << (enINJ[n]+enREC[n]-2*xcorINJ_REC[n])/enINJ[n] << endl;
1197  rnum+=(enINJ[n]+enREC[n]-2*xcorINJ_REC[n]);
1198  rden+=enINJ[n];
1199  }
1200  //cout << "RECvsAVR NET RESIDUAL : " << rnum/rden << endl;
1201 
1202 #ifdef SAVE_WF_COMPARISON
1203  for(int n=0;n<nIFO;n++) {
1204 // PlotFinal3(NET, ID, n, &wavr[n], &wavr[n], "AVRvsAVR","root");
1205 // PlotFinal3(NET, ID, n, &winj[n], &winj[n], "INJvsINJ","root");
1206 // PlotFinal3(NET, ID, n, &wREC[n], &wREC[n], "RECvsREC","root");
1207 
1208  PlotFinal3(NET, ID, n, &rINJ[n], &winj[n], "rINJvsINJ","root");
1209  PlotFinal3(NET, ID, n, &rINJ[n], &wREC[n], "rINJvsREC","root");
1210  PlotFinal3(NET, ID, n, &rINJ[n], &wavr[n], "rINJvsAVR","root");
1211 
1212  PlotFinal3(NET, ID, n, &winj[n], &wavr[n], "INJvsAVR","root");
1213  PlotFinal3(NET, ID, n, &wREC[n], &wavr[n], "RECvsAVR","root");
1214  }
1215 #endif
1216 
1217  wavearray<int> index(vRES.size());
1218  TMath::Sort(int(vRES.size()),const_cast<float*>(vRES.data),index.data,false);
1219 
1220  erR[0] = jres;
1221 
1222  for(int i=1;i<10;i++) erR[i]=vRES[index[i*int(vRES.size()/10.)]];
1223 
1224  erR[10]=0;
1225  for(int i=0;i<vRES.size();i++) {
1226  if(vRES[i]<=jres) erR[10]+=1.;
1227  }
1228  erR[10]/=vRES.size();
1229 
1230  cout.precision(3);
1231  cout << "erR : ";
1232  for(int i=0;i<10;i++) cout << erR[i] << "/";
1233  cout << erR[10] << endl;
1234 
1235 #ifdef SAVE_PLOT_RESIDUALS
1236 
1237  // plot residuals
1238  TCanvas* canvas2= new TCanvas("canvas2", "canvas2", 200, 20, 600, 600);
1239  TH1F* hres = new TH1F("residuals","residuals",10,0,1);
1240  for(int i=0;i<vRES.size();i++) hres->Fill(vRES[i]);
1241 
1242  hres->Draw();
1243  canvas2->SetLogy();
1244 
1245  float ymax = hres->GetMaximum();
1246  TLine *line = new TLine(jres,0,jres,ymax);
1247  line->SetLineColor(kRed);
1248  line->Draw();
1249 
1250  gStyle->SetLineColor(kWhite);
1251  hres->SetTitle("Distribution of residuals");
1252  hres->SetStats(kTRUE);
1253  canvas2->Print(TString::Format("%s/residuals_%d.png",PLOT_DIR,ID));
1254 
1255  delete hres;
1256  delete canvas2;
1257 
1258 #endif
1259 }
1260 
1261 void Clear() {
1262 
1263  sI.resize(0);
1264  for(int n=0;n<NIFO_MAX;n++) {
1265 
1266  wINJ[n].resize(0);
1267  sINJ[n].resize(0);
1268  wREC[n].resize(0);
1269 
1270  while(!vSS[n].empty()) vSS[n].pop_back();
1271  vSS[n].clear(); std::vector<SSeries<double> >().swap(vSS[n]);
1272  while(!sSS[n].empty()) sSS[n].pop_back();
1273  sSS[n].clear(); std::vector<SSeries<double> >().swap(sSS[n]);
1274  while(!rSS[n].empty()) rSS[n].pop_back();
1275  rSS[n].clear(); std::vector<SSeries<double> >().swap(rSS[n]);
1276  while(!jSS[n].empty()) jSS[n].pop_back();
1277  jSS[n].clear(); std::vector<SSeries<double> >().swap(jSS[n]);
1278 
1279  while(!vN[n].empty()) vN[n].pop_back();
1280  vN[n].clear(); std::vector<WSeries<double> >().swap(vN[n]);
1281 
1282  while(!wTRY[n].empty()) wTRY[n].pop_back();
1283  wTRY[n].clear(); std::vector<int >().swap(wTRY[n]);
1284 
1285  while(!wAVR[n].empty()) wAVR[n].pop_back();
1286  wAVR[n].clear(); std::vector<double >().swap(wAVR[n]);
1287 
1288  while(!wRMS[n].empty()) wRMS[n].pop_back();
1289  wRMS[n].clear(); std::vector<double >().swap(wRMS[n]);
1290 
1291  while(!vDREC[n].empty()) vDREC[n].pop_back();
1292  vDREC[n].clear(); std::vector<double >().swap(vDREC[n]);
1293 
1294  while(!vREC[n].empty()) vREC[n].pop_back();
1295  vREC[n].clear(); std::vector<wavearray<double> >().swap(vREC[n]);
1296 
1297  }
1298 }
1299 
1301 
1302  TString cwb_inet_options=TString(gSystem->Getenv("CWB_INET_OPTIONS"));
1303  if(cwb_inet_options.CompareTo("")!=0) {
1304  TString inet_options = cwb_inet_options;
1305  cout << inet_options << endl;
1306  if(!inet_options.Contains("--")) { // parameters are used only by cwb_inet
1307 
1308  TObjArray* token = TString(inet_options).Tokenize(TString(' '));
1309  for(int j=0;j<token->GetEntries();j++){
1310 
1311  TObjString* tok = (TObjString*)token->At(j);
1312  TString stok = tok->GetString();
1313 
1314  if(stok.Contains("wrc_id=")) {
1315  TString wrc_id=stok;
1316  wrc_id.Remove(0,wrc_id.Last('=')+1);
1317  if(wrc_id.IsDigit()) WRC_ID=wrc_id.Atoi();
1319  cout << "WRC_ID : " << WRC_ID << endl;
1320  }
1321 
1322  if(stok.Contains("wrc_retry=")) {
1323  TString wrc_retry=stok;
1324  wrc_retry.Remove(0,wrc_retry.Last('=')+1);
1325  if(wrc_retry.IsDigit()) WRC_RETRY=wrc_retry.Atoi();
1327  cout << "WRC_RETRY : " << WRC_RETRY << endl;
1328  }
1329 
1330  if(stok.Contains("wrc_ced_id=")) {
1331  TString wrc_ced_id=stok;
1332  wrc_ced_id.Remove(0,wrc_ced_id.Last('=')+1);
1333  if(wrc_ced_id.IsDigit()) WRC_CED_ID=wrc_ced_id.Atoi();
1335  cout << "WRC_CED_ID : " << WRC_CED_ID << endl;
1336  }
1337 
1338  if(stok.Contains("wrc_ced_retry=")) {
1339  TString wrc_ced_retry=stok;
1340  wrc_ced_retry.Remove(0,wrc_ced_retry.Last('=')+1);
1341  if(wrc_ced_retry.IsDigit()) WRC_CED_RETRY=wrc_ced_retry.Atoi();
1343  cout << "WRC_CED_RETRY : " << WRC_CED_RETRY << endl;
1344  }
1345 
1346  if(stok.Contains("wrc_skymask=")) {
1347  TString wrc_skymask=stok;
1348  wrc_skymask.Remove(0,wrc_skymask.Last('=')+1);
1349  if(wrc_skymask=="true") WRC_SKYMASK=true;
1350  if(wrc_skymask=="false") WRC_SKYMASK=false;
1352  }
1353 
1354  if(stok.Contains("wrc_noise=")) {
1355  TString wrc_noise=stok;
1356  wrc_noise.Remove(0,wrc_noise.Last('=')+1);
1357  if(wrc_noise=="true") WRC_NOISE=true;
1358  if(wrc_noise=="false") WRC_NOISE=false;
1360  }
1361 
1362  }
1363  }
1364  }
1365 }
1366 
1367 int _sse_mra_ps(network* NET, float* amp, float* AMP, float Eo, int K) {
1368 // fast multi-resolution analysis inside sky loop
1369 // select max E pixel and either scale or skip it based on the value of residual
1370 // pointer to 00 phase amplitude of monster pixels
1371 // pointer to 90 phase amplitude of monster pixels
1372 // Eo - energy threshold
1373 // K - max number of principle components to extract
1374 // returns number of MRA pixels
1375 
1376  int j,n,mm,J;
1377  int k = 0;
1378  int m = 0;
1379  int f = NIFO/4;
1380  int V = (int)NET->rNRG.size();
1381  float* ee = NET->rNRG.data; // residual energy
1382  float* c = NULL;
1383  float E2 = Eo/2; // threshold
1384  float E;
1385  float mam[NIFO];
1386  float mAM[NIFO];
1387 
1388  __m128* _m00 = (__m128*) mam;
1389  __m128* _m90 = (__m128*) mAM;
1390  __m128* _amp = (__m128*) amp;
1391  __m128* _AMP = (__m128*) AMP;
1392  __m128* _a00 = (__m128*) NET->a_00.data;
1393  __m128* _a90 = (__m128*) NET->a_90.data;
1394 
1395  while(k<K){
1396 
1397  for(j=0; j<V; ++j) if(ee[j]>ee[m]) m=j; // find max pixel
1398  if(ee[m]<=Eo) break; mm = m*f;
1399 
1400  //cout<<k<<" "<<" V= "<<V<<" m="<<m<<" ee[m]="<<ee[m];
1401 
1402  float cc = 0.;
1403 
1404  _sse_zero_ps(_m00);
1405  _sse_zero_ps(_m90);
1406 
1407  J = NET->wdmMRA.getXTalk(m)->size()/7;
1408  c = NET->wdmMRA.getXTalk(m)->data; // c1*c2+c3*c4=c1*c3+c2*c4=0
1409  for(j=0; j<J; j++) {
1410  n = int(c[0]+0.1);
1411  if(ee[n]>Eo) {
1412  _sse_rotadd_ps(_a00+n*f,c[1],_a90+n*f,c[3],_m00); // construct 00 vector
1413  _sse_rotadd_ps(_a00+n*f,c[2],_a90+n*f,c[4],_m90); // construct 90 vector
1414  }
1415  if(ee[n]>0) cc += c[5];
1416  c += 7;
1417  }
1418  _sse_mul_ps(_m00,cc>1?1./cc:0.7);
1419  _sse_mul_ps(_m90,cc>1?1./cc:0.7);
1420  E = _sse_abs_ps(_m00,_m90); // get PC energy
1421 
1422  if(E > ee[m]) { // correct overtuning PC
1423  _sse_cpf_ps(mam,_a00+mm); // store a00 for max pixel
1424  _sse_cpf_ps(mAM,_a90+mm); // store a90 for max pixel
1425  }
1426  _sse_add_ps(_amp+mm,_m00); // update 00 PC
1427  _sse_add_ps(_AMP+mm,_m90); // update 90 PC
1428 
1429  J = NET->wdmMRA.getXTalk(m)->size()/7;
1430  c = NET->wdmMRA.getXTalk(m)->data; // c1*c2+c3*c4=c1*c3+c2*c4=0
1431  for(j=0; j<J; j++) {
1432  n = int(c[0]+0.1);
1433  if(E<E2 && n!=m) {c+=7; continue;}
1434  if(ee[n]>Eo) {
1435  ee[n] = _sse_rotsub_ps(_m00,c[1],_m90,c[2],_a00+n*f); // subtract PC from a00
1436  ee[n]+= _sse_rotsub_ps(_m00,c[3],_m90,c[4],_a90+n*f); // subtract PC from a90
1437  ee[n]+= 1.e-6;
1438  }
1439  c += 7;
1440  }
1441  //cout<<" "<<ee[m]<<" "<<k<<" "<<E<<" "<<EE<<" "<<endl;
1442  //cout<<" "<<m<<" "<<cc<<" "<<ee[m]<<" "<<E<<" "<<pp[m]<<endl;
1443  k++;
1444  }
1445  return k;
1446 }
1447 
1449 
1450  // import slagShift
1451  float* gSLAGSHIFT=NULL; IMPORT(float*,gSLAGSHIFT)
1452 
1453  int nIFO = NET->ifoListSize(); // number of detectors
1454 
1455  // search output root file in the system list
1456  TFile* froot = NULL;
1457  TList *files = (TList*)gROOT->GetListOfFiles();
1458  outDump="";
1459  if (files) {
1460  TIter next(files);
1461  TSystemFile *file;
1462  TString fname;
1463  bool check=false;
1464  while ((file=(TSystemFile*)next())) {
1465  fname = file->GetName();
1466  // set output root file as the current file
1467  if(fname.Contains("wave_")) {
1468  froot=(TFile*)file;froot->cd();
1469  outDump=fname;
1470  outDump.ReplaceAll(".root.tmp",".txt");
1471  //cout << "output file name : " << fname << endl;
1472  }
1473  }
1474  if(!froot) {
1475  cout << "CWB_Plugin_xWRC.C : Error - output root file not found" << endl;
1476  gSystem->Exit(1);
1477  }
1478  } else {
1479  cout << "CWB_Plugin_xWRC.C : Error - output root file not found" << endl;
1480  gSystem->Exit(1);
1481  }
1482 
1483  net_tree = (TTree *) froot->Get("waveburst");
1484  if(net_tree!=NULL) {
1485  EVT = new netevent(net_tree,nIFO);
1486  for(int j=0;j<nPAR;j++) net_tree->SetBranchAddress(parName[j],&parValue[j]);
1487  net_tree->SetBranchAddress("erR",erR);
1488  } else {
1489  EVT = new netevent(nIFO);
1490  net_tree = EVT->setTree();
1491  for(int j=0;j<nPAR;j++)
1492  net_tree->Branch(parName[j],&parValue[j],TString::Format("%s/F",parName[j].Data()));
1493  net_tree->Branch("erR",erR,TString::Format("erR[%i]/F",11));
1494  }
1495  EVT->setSLags(gSLAGSHIFT); // set slags into netevent
1496  EVT->Psave=cfg->Psave;
1497 }
1498 
1499 void DumpOutput(network* NET, netevent* &EVT, CWB::config* cfg, int ID, int k, int factor) {
1500 
1501  for(int j=0;j<11;j++) NET->getwc(k)->sArea[ID-1][j]=rec_erA[j]; // restore erA
1502  if(cfg->dump) EVT->dopen(outDump.Data(),const_cast<char*>("a"),false);
1503  EVT->output2G(net_tree,NET,ID,k,factor); // get reconstructed parameters
1504  if(cfg->dump) EVT->dclose();
1505  if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1; // mark as processed
1506 }
1507 
1508 void GetRecWaveform(network* NET, netevent* EVT, int ID, int k, int factor) {
1509 
1510  // import retry
1511  int gLRETRY=-1; IMPORT(int,gLRETRY)
1512 
1513  int nIFO = NET->ifoListSize(); // number of detectors
1514 
1515  EVT->output2G(NULL,NET,ID,k,factor); // get reconstructed parameters
1516 
1517  cout << "rec_theta : " << EVT->theta[0] << " rec_phi : " << EVT->phi[0] << endl;
1518 
1519  wavearray<double>** pwfREC = new wavearray<double>*[nIFO];
1520  for(int n=0; n<nIFO; n++) {
1521 
1522  detector* pd = NET->getifo(n);
1523  int idSize = pd->RWFID.size();
1524  int wfIndex=-1;
1525  for(int mm=0; mm<idSize; mm++) if (pd->RWFID[mm]==ID) wfIndex=mm;
1526 
1527  if(wfIndex<0) {
1528  cout << "CWB_Plugin_xWRC.C : Error : Reconstructed waveform not saved !!! : ID -> "
1529  << ID << " : detector " << NET->ifoName[n] << endl;
1530  continue;
1531  }
1532  if(wfIndex>=0) pwfREC[n] = pd->RWFP[wfIndex];
1533  wavearray<double>* wfREC = pwfREC[n]; // array of reconstructed waveforms
1534 
1535  double delay = EVT->time[n]-EVT->time[0];
1536  //cout << "DEB DELAY : " << n << " " << delay << endl;
1537 
1538  // save tst rec waveforms
1539  if(gLRETRY<WRC_RETRY) {
1540  vREC[n].push_back(*wfREC);
1541  vDREC[n].push_back(delay);
1542  }
1543  // save inj/rec waveforms
1544  if(gLRETRY==WRC_RETRY) { // first time
1545  wREC[n]=*wfREC;
1546  wDREC[n]=delay;
1547 
1548  // save injected/reconstruced sky location
1549  rec_theta = EVT->theta[0]; // rec theta
1550  rec_phi = EVT->phi[0]; // rec phi
1551 
1552  for(int j=0;j<11;j++) rec_erA[j] = EVT->erA[j];
1553  }
1554 
1555  // save wrc parameters
1556  parValue[0]=WRC_RETRY-gLRETRY;
1557  if(WRC_NOISE) parValue[1]=1; else parValue[1]=0;
1558  parValue[2]=WRC_SM_PHI;
1561  parValue[5]=WRC_CAL_AMP;
1562  parValue[6]=WRC_CAL_PHS;
1563  }
1564  delete [] pwfREC;
1565 }
1566 
1567 void GetInjWaveform(network* NET, netevent* EVT, int ID, int k, int factor) {
1568 
1569  // import retry
1570  int gLRETRY=-1; IMPORT(int,gLRETRY)
1571 
1572  int nIFO = NET->ifoListSize(); // number of detectors
1573 
1574  double recTime = EVT->time[0]; // rec event time det=0
1575 
1576  injection INJ(nIFO);
1577  // get inj ID
1578  int M = NET->mdc__IDSize();
1579  double injTime = 1.e12;
1580  int injID = -1;
1581  for(int m=0; m<M; m++) {
1582  int mdcID = NET->getmdc__ID(m);
1583  double T = fabs(recTime - NET->getmdcTime(mdcID));
1584  if(T<injTime && INJ.fill_in(NET,mdcID)) {
1585  injTime = T;
1586  injID = mdcID;
1587  }
1588  }
1589 
1590  if(INJ.fill_in(NET,injID)) { // get inj parameters
1591 
1592  wavearray<double>** pwfINJ = new wavearray<double>*[nIFO];
1593 
1594  // extract whitened injected & reconstructed waveforms
1595  for(int n=0; n<nIFO; n++) {
1596 
1597  detector* pd = NET->getifo(n);
1598 
1599  pwfINJ[n] = INJ.pwf[n];
1600  if (pwfINJ[n]==NULL) {
1601  cout << "CWB_Plugin_xWRC.C : Error : Injected waveform not saved !!! : detector "
1602  << NET->ifoName[n] << endl;
1603  continue;
1604  }
1605 
1606  double rFactor = 1.;
1607  rFactor *= factor>0 ? factor : 1;
1608  wavearray<double>* wfINJ = pwfINJ[n]; // array of injected waveforms
1609  *wfINJ*=rFactor; // injected wf is multiplied by the custom factor
1610 
1611  // save inj waveforms
1612  wINJ[n]=*wfINJ;
1613 
1614  //double delay = INJ.time[n]-INJ.time[0];
1615  double delay = EVT->time[n]-EVT->time[0];
1616  sINJ[n]=*wfINJ; CWB::mdc::TimeShift(sINJ[n],-delay);
1617  wDINJ[n]=delay;
1618 
1619  wTRY[n].resize(wINJ[n].size());
1620  wAVR[n].resize(wINJ[n].size());
1621  wRMS[n].resize(wINJ[n].size());
1622  for(int j=0;j<wINJ[n].size();j++) {wTRY[n][j]=0;wAVR[n][j]=0;wRMS[n][j]=0;};
1623 
1624  // save injected/reconstruced sky location
1625  inj_theta = EVT->theta[1]; // inj theta
1626  inj_phi = EVT->phi[1]; // inj phi
1627 
1628  *wfINJ*=1./rFactor; // restore injected amplitude
1629  }
1630  delete [] pwfINJ;
1631  }
1632 }
1633 
1635 
1636  int nIFO = NET->ifoListSize(); // number of detectors
1637 
1638  netcluster* pwc = NET->getwc(k);
1639 
1640  std::vector<int>* vint = &(pwc->cList[ID-1]); // pixel list
1641  int V = vint->size(); // cluster size
1642  if(!V) return;
1643 
1644  int irate=0;
1645  if(cfg->optim) { // extract optimal rate
1646  vector_int* pv = pwc->cRate.size() ? &(pwc->cRate[ID-1]) : NULL;
1647  irate = pv!=NULL ? (*pv)[0] : 0;
1648  }
1649  bool isPCs = !(cfg->optim&&std::isupper(cfg->search)); // are Principal Components ?
1650 
1651  detector* pD = NET->getifo(0);
1652  double R = pD->TFmap.rate();
1653 
1654  // ------------------------------------------------------------------
1655  // Find max pixel parameters
1656  // ------------------------------------------------------------------
1657 
1658  int K=0;
1659  for(int n=0; n<V; n++) {
1660  netpixel* pix = pwc->getPixel(ID,n);
1661  if(pix->layers%2==0) {
1662  cout << "CWB_Plugin_eWRC.C - Error : is enabled only for WDM (2G)" << endl;
1663  exit(1);
1664  }
1665  for(int m=0; m<nIFO; m++) {
1666 #ifdef APPLY_INJ_MRA
1667  NET->a_00[n*NIFO+m]=0;
1668  NET->a_90[n*NIFO+m]=0;
1669 #endif
1670  pix->setdata(0,'S',m);
1671  pix->setdata(0,'P',m);
1672  }
1673 #ifdef APPLY_INJ_MRA
1674  NET->rNRG[n]=0;
1675 #endif
1676  if(!pix->core) continue; // select only the principal components pixels
1677  if((irate)&&(irate != int(pix->rate+0.5))) continue; // if irate!=0 skip rate!=irate
1678  for(int m=0; m<nIFO; m++) {
1679  int index = pix->data[m].index;
1680  int ires = int(TMath::Log2(R/pix->rate))-cfg->l_low;
1681  double aa = GetSparseMap(&sSS[m][ires], true, index);
1682  double AA = GetSparseMap(&sSS[m][ires], false , index);
1683  pix->setdata(aa,'S',m);
1684  pix->setdata(AA,'P',m);
1685 #ifdef APPLY_INJ_MRA
1686  NET->a_00[n*NIFO+m]=aa;
1687  NET->a_90[n*NIFO+m]=AA;
1688  NET->rNRG[n]+=aa*aa+AA*AA;
1689 #endif
1690  }
1691 K++;
1692  }
1693 
1694 #ifdef SAVE_MRA_PLOT // monster event display
1695  PlotMRA(NET, ID, k, "rINJ");
1696 #endif
1697 
1698 #ifdef APPLY_INJ_MRA
1699 
1700  int V4 = V + (V%4 ? 4 - V%4 : 0);
1701  int V44 = V4 + 4;
1702 
1703  wavearray<float> amp(NIFO*V44); amp=0;
1704  wavearray<float> AMP(NIFO*V44); AMP=0;
1705  float Eo = 1e-3; // must be > 1e-6
1706  //float Eo = 2*cfg->Acore*cfg->Acore*nIFO;
1707 
1708  _sse_mra_ps(NET, amp.data, AMP.data, Eo, K);
1709  for(int n=0; n<V; n++) {
1710  netpixel* pix = pwc->getPixel(ID,n);
1711  if(pix->layers%2==0) {
1712  cout << "CWB_Plugin_eWRC.C - Error : is enabled only for WDM (2G)" << endl;
1713  exit(1);
1714  }
1715  for(int m=0; m<nIFO; m++) {
1716  pix->setdata(0,'S',m);
1717  pix->setdata(0,'P',m);
1718  }
1719  if(!pix->core) continue; // select only the principal components pixels
1720  if((irate)&&(irate != int(pix->rate+0.5))) continue; // if irate!=0 skip rate!=irate
1721  for(int m=0; m<nIFO; m++) {
1722  double aa = amp[n*NIFO+m];
1723  double AA = AMP[n*NIFO+m];
1724  pix->setdata(aa,'S',m);
1725  pix->setdata(AA,'P',m);
1726  }
1727  }
1728 
1729 #ifdef SAVE_MRA_PLOT // monster event display
1730  PlotMRA(NET, ID, k, "mra_rINJ");
1731 #endif
1732 
1733 #endif
1734 
1735  //NET->getMRAwave(ID,0,'S',0,true);
1736  NET->getMRAwave(ID,0,'S',0,false);
1737 
1738  for(int n=0; n<nIFO; n++) {
1739  detector* pD = NET->getifo(n);
1740  rINJ[n]=pD->waveForm;
1741  rINJ[n].start(pwc->start+pD->waveForm.start());
1742  CWB::mdc::TimeShift(rINJ[n],wDINJ[n]);
1743  }
1744  return;
1745 }
int WRC_CED_RETRY
monster wdmMRA
list of pixel pointers for MRA
Definition: network.hh:633
wavearray< double > gwREC[NIFO_MAX]
std::vector< char * > ifoName
Definition: network.hh:591
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
char analysis[8]
Definition: config.hh:99
gskymap * gSM
static float _sse_abs_ps(__m128 *_a)
Definition: watsse.hh:119
TString outDump
std::vector< int > vector_int
Definition: cluster.hh:17
double wDINJ[NIFO_MAX]
virtual size_t size() const
Definition: wavearray.hh:127
static const double C
Definition: GNGen.cc:10
void AddNoise2Sparse(network *NET, CWB::config *cfg, int seed=0)
#define NIFO
Definition: wat.hh:56
void PlotFinal(int n)
size_t nLag
Definition: network.hh:555
std::vector< int > wTRY[NIFO_MAX]
std::vector< vector_int > cRate
Definition: netcluster.hh:380
bool WRC_NOISE
#define PLOT_DIR
int WRC_ID
void gtitle(TString title="", TString xtitle="", TString ytitle="")
Definition: watplot.cc:1237
int slices
void ComputeErrorWF(wavearray< double > *wfINJ, wavearray< double > *wfREC, int ifoID)
bool optim
Definition: config.hh:104
void PlotWaveform(TString ifo, wavearray< double > *wfINJ, wavearray< double > *wfREC, CWB::config *cfg, bool fft=false, bool strain=false)
std::vector< netcluster > wc_List
Definition: network.hh:592
void SaveSkyProb(network *NET, CWB::config *cfg, int id)
void setSLags(float *slag)
Definition: netevent.cc:404
double GetSparseMap(SSeries< double > *SS, bool phase, int index)
TCanvas * canvas2
Definition: compare_bkg.C:57
tuple f
Definition: cwb_online.py:91
std::vector< WSeries< double > > vN[NIFO_MAX]
void PlotFinal2(network *NET, int ID)
std::vector< double > * getmdcTime()
Definition: network.hh:404
virtual void rate(double r)
Definition: wavearray.hh:123
int irate
void Clear()
#define SKYMASK_SEED
char skyMaskFile[1024]
Definition: config.hh:290
int n
Definition: cwb_net.C:10
static void _sse_zero_ps(__m128 *_p)
Definition: watsse.hh:26
float WRC_CAL_AMP
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
wavearray< float > a_90
buffer for cluster sky 00 amplitude
Definition: network.hh:635
TTree * setTree()
Definition: netevent.cc:412
TString("c")
int WRC_CED_ID_CONFIG
int ID
Definition: TestMDC.C:70
size_t maxIndex()
Definition: wseries.hh:131
static void PhaseShift(wavearray< double > &x, double pShift=0.)
Definition: mdc.cc:2926
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
std::vector< pixdata > data
Definition: netpixel.hh:104
double phase
wavearray< double > get(char *name, size_t index=0, char atype='R', int type=1, bool=true)
param: string with parameter name param: index in the amplitude array, which define detector param: c...
Definition: netcluster.cc:2188
std::vector< wavearray< double > * > RWFP
Definition: detector.hh:364
bool WRC_SKYMASK_REC_SKY
double fLow
Definition: config.hh:122
std::vector< vector_float > sArea
Definition: netcluster.hh:383
netpixel pix(nifo)
netcluster * pwc
Definition: cwb_job_obj.C:20
wavearray< double > rINJ[NIFO_MAX]
TH2F * ph
void Wave2Sparse(network *NET, CWB::config *cfg, char wave_type)
int GetLayer(int index)
Definition: sseries.hh:104
std::vector< TGraph * > graph
Definition: watplot.hh:176
plot gtitle(gtitle,"frequency (Hz)","strain/#sqrt{Hz}")
bool cedDump
Definition: config.hh:279
wavearray< int > sI
static float _sse_rotsub_ps(__m128 *_u, float c, __m128 *_v, float s, __m128 *_a)
Definition: watsse.hh:381
int layers
STL namespace.
double getTheta(size_t i)
Definition: skymap.hh:206
void DumpOutput(network *NET, netevent *&EVT, CWB::config *cfg, int ID, int k, int factor)
static void _sse_cpf_ps(float *a, __m128 *_p)
Definition: watsse.hh:289
Long_t size
#define M
Definition: UniqSLagsList.C:3
size_t layers
Definition: netpixel.hh:94
int m
Definition: cwb_net.C:10
DataType_t * pWWS
Definition: WaveDWT.hh:123
std::vector< vector_int > cList
Definition: netcluster.hh:379
virtual void start(double s)
Definition: wavearray.hh:119
int j
Definition: cwb_net.C:10
bool getMRAwave(size_t ID, size_t lag, char atype='S', int mode=0, bool tof=false)
Definition: network.cc:3635
i drho i
skymap tau
Definition: detector.hh:328
void plot(wavearray< double > &, char *=NULL, int=1, double=0., double=0., bool=false, float=0., float=0., bool=false, float=0., bool=false)
Definition: watplot.cc:132
void Draw(int dpaletteId=0, Option_t *option="colfz")
Definition: gskymap.cc:442
wavearray< int > sparseIndex
Definition: sseries.hh:162
static void _sse_rotadd_ps(__m128 *_u, float c, __m128 *_v, float s, __m128 *_a)
Definition: watsse.hh:370
int WRC_ID_CONFIG
TString parName[nPAR]
bool outPlugin
Definition: config.hh:351
bool core
Definition: netpixel.hh:102
char ifo[NIFO_MAX][8]
void dopen(const char *fname, char *mode, bool header=true)
Definition: netevent.hh:291
double rec_theta
size_t ifoListSize()
Definition: network.hh:413
bool WRC_PHS_CAL_ERR
cwb xCWB
WDM< double > * getwdm(size_t M)
param: number of wdm layers
Definition: network.hh:430
int Psave
Definition: config.hh:175
void clear()
Definition: watplot.hh:40
wavearray< double > w
Definition: Test1.C:27
#define nIFO
size_t getSkyIndex(double th, double ph)
param: theta param: phi
Definition: skymap.cc:702
TCanvas * canvas
Definition: watplot.hh:174
gWSeries< double > gw(w)
double factor
x plot
bool WRC_SKYMASK
double time[6]
Definition: cbc_plots.C:435
jfile
Definition: cwb_job_obj.C:25
void output2G(TTree *, network *, size_t, int, double)
Definition: netevent.cc:687
wavearray< double > xx
Definition: TestFrame1.C:11
double rec_phi
TTree * net_tree
void GetInjWaveform(network *NET, netevent *EVT, int ID, int k, int factor)
Int_t Psave
number of detectors
Definition: netevent.hh:48
int simulation
Definition: config.hh:181
int l_high
Definition: config.hh:138
int WRC_CED_RETRY_CONFIG
std::vector< double > wRMS[NIFO_MAX]
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:51
char search
Definition: config.hh:103
watplot * WTS
Definition: ChirpMass.C:115
bool WRC_PHS_CAL_ERR_CONFIG
xtalk getXTalk(int nLay1, size_t indx1, int nLay2, size_t indx2)
param: numbers of layers identifying the resolution of the first pixel param: TF map index of the fir...
Definition: monster.cc:351
wavearray< int > sparseLookup
Definition: sseries.hh:160
i() int(T_cor *100))
network NET
Definition: cwb_dump_inj.C:12
TString label
Definition: MergeTrees.C:21
double Pi
std::vector< SSeries< double > > rSS[NIFO_MAX]
const int NIFO_MAX
Definition: wat.hh:4
std::vector< SSeries< double > > sSS[NIFO_MAX]
wavearray< double > wREC[NIFO_MAX]
void ComputeErrorStatistic(network *NET, CWB::config *cfg, int ID)
double wDREC[NIFO_MAX]
wavearray< float > a_00
wdm multi-resolution analysis
Definition: network.hh:634
bool WRC_SKYMASK_CONFIG
void PlotFinal3(network *NET, int ID, int ifoID, wavearray< double > *w1, wavearray< double > *w2, TString tag, TString gtype="png")
int gIFACTOR
double start
Definition: netcluster.hh:361
bool detected
TIter next(twave->GetListOfBranches())
char fname[1024]
void SetOutput(network *NET, netevent *&EVT, CWB::config *cfg)
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
COHERENCE.
std::vector< int > RWFID
Definition: detector.hh:363
size_t mdc__IDSize()
Definition: network.hh:396
bool WRC_SKYMASK_REC_SKY_CONFIG
double inj_phi
int k
double GetTimeRange(double &tMin, double &tMax, double efraction=0.9999999)
Definition: gwavearray.cc:341
int _sse_mra_ps(network *NET, float *amp, float *AMP, float Eo, int K)
size_t cpf(const netcluster &, bool=false, int=0)
Definition: netcluster.cc:99
std::vector< double > wAVR[NIFO_MAX]
TObjArray * token
void SetTimeRange(double tMin, double tMax)
Definition: gwavearray.hh:57
#define nPAR
Definition: skymap.hh:45
long nSky
Definition: config.hh:281
skymap rec_skyprob
float WRC_SM_PHI
double e
float WRC_SM_RADIUS
wavearray< double > yy
Definition: TestFrame5.C:12
wavearray< double > sINJ[NIFO_MAX]
std::vector< SSeries< double > > vSS[NIFO_MAX]
int ifreq
char tag[256]
Definition: cwb_merge.C:74
TFile * froot
netpixel * getPixel(size_t n, size_t i)
Definition: netcluster.hh:395
double dt
float rec_erA[11]
int WRC_CED_ID
static void TimeShift(wavearray< double > &x, double tShift=0.)
Definition: mdc.cc:2874
int l_low
Definition: config.hh:137
#define EXPORT(TYPE, VAR, CMD)
Definition: config.cc:74
#define AMP_CAL_ERR
double getPhi(size_t i)
Definition: skymap.hh:146
WSeries< double > TFmap
Definition: detector.hh:336
void GetRecWaveform(network *NET, netevent *EVT, int ID, int k, int factor)
void ComputeResidualEnergy(wavearray< double > *wfINJ, wavearray< double > *wfREC, double &enINJ, double &enREC, double &xcorINJ_REC)
Float_t * phi
sqrt(h+*h+ + hx*hx)
Definition: netevent.hh:68
void PlotMRA(network *NET, int ID, int k, TString tag)
bool WRC_AMP_CAL_ERR
netevent EVT(itree, nifo)
void ReadUserOptions()
Float_t * theta
[0]-reconstructed, [1]-injected phi angle, [2]-RA
Definition: netevent.hh:69
Double_t * time
beam pattern coefficients for hx
Definition: netevent.hh:75
double T
Definition: testWDM_4.C:11
TLine * line
Definition: compare_bkg.C:482
static void _sse_add_ps(__m128 *_a, __m128 *_b)
Definition: watsse.hh:230
std::vector< int > sCuts
Definition: netcluster.hh:374
WSeries< double > waveForm
Definition: detector.hh:337
void dclose()
Definition: netevent.hh:300
double fHigh
Definition: config.hh:123
double inj_theta
bool WRC_AMP_CAL_ERR_CONFIG
wavearray< int > index
virtual void stop(double s)
Definition: wavearray.hh:121
double fabs(const Complex &x)
Definition: numpy.cc:37
string file
Definition: cwb_online.py:385
void SetSkyMask(network *NET, CWB::config *cfg, int seed=0)
wavearray< float > sparseMap00
Definition: sseries.hh:163
int SetSkyMask(network *net, CWB::config *cfg, char *options, char skycoord, double skyres=-1)
Definition: cwb.cc:2465
wavearray< float > sparseMap90
Definition: sseries.hh:164
TH1D hist_skyprob
Float_t * erA
noise rms
Definition: netevent.hh:89
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
Meyer< double > S(1024, 2)
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:421
int l
Definition: cbc_plots.C:434
std::vector< double > vDREC[NIFO_MAX]
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
int WRC_RETRY_CONFIG
float erR[11]
TString gfile
void set(size_t i, double a)
param: sky index param: value to set
Definition: skymap.hh:104
#define PHS_CAL_ERR
static void _sse_mul_ps(__m128 *_a, float b)
Definition: watsse.hh:38
watplot * GetWATPLOT()
Definition: gwavearray.hh:70
Definition: cwb.hh:119
DataType_t * data
Definition: wavearray.hh:301
wavearray< float > rNRG
buffer for cluster sky 90 amplitudes
Definition: network.hh:636
long nSky
Definition: network.hh:556
const int nRES
Definition: revMonster.cc:7
double * itime
int WRC_RETRY
double factors[FACTORS_MAX]
Definition: config.hh:184
double get(size_t i)
param: sky index
Definition: skymap.cc:681
bool WRC_NOISE_CONFIG
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:438
wavearray< double > wINJ[NIFO_MAX]
Bool_t fill_in(network *, int, bool=true)
Definition: injection.cc:325
list files
Definition: cwb_online.py:529
float rate
Definition: netpixel.hh:95
std::vector< SSeries< double > > vSS
Definition: detector.hh:334
float parValue[nPAR]
size_t size()
Definition: skymap.hh:118
size_t getmdc__ID(size_t n)
Definition: network.hh:408
for(int i=0;i< 101;++i) Cos2[2][i]=0
wavearray< double > ** pwf
[x1,y1,z1,x2,y2,z2] components of spin vector
Definition: injection.hh:82
virtual void resize(unsigned int)
Definition: wavearray.cc:445
void Print(TString pname)
Definition: gskymap.cc:1104
int check
size_t sizeZero()
Definition: wseries.hh:126
#define WRC_PLUGIN_VERSION
float WRC_SM_THETA
std::vector< wavearray< double > > vREC[NIFO_MAX]
void Draw(GWAT_DRAW type=GWAT_TIME, TString options="ALP", Color_t color=kBlack)
Definition: gwavearray.cc:71
detector ** pD
void GetRInjWaveform(network *NET, netevent *EVT, CWB::config *cfg, int ID, int k)
std::vector< double > vRES
float WRC_CAL_PHS
void SetZaxisTitle(TString zAxisTitle)
Definition: gskymap.hh:132
int binarySearch(int array[], int start, int end, int key)
Definition: sseries.cc:443
exit(0)
std::vector< SSeries< double > > jSS[NIFO_MAX]
bool setdata(double a, char type='R', size_t n=0)
Definition: netpixel.hh:40
float WRC_WF_NOISE
bool dump
Definition: config.hh:277