Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_PE.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 "TComplex.h"
32 #include "TGraphAsymmErrors.h"
33 #include "TMath.h"
34 #include "mdc.hh"
35 #include "cwb2G.hh"
36 #include "watplot.hh"
37 #include "gwavearray.hh"
38 #include "network.hh"
39 #include <fstream>
40 #include <vector>
41 
42 // ---------------------------------------------------------------------------------
43 // TO BE DONE
44 // ---------------------------------------------------------------------------------
45 
46 // MEDIAN SKYMAP, reformat of xCED SkyMap TAB
47 // FIX WAVEFORM INJECTION in RedoAnalysis, must be excluded CAT2 , we can use TH1D for random selection
48 // ADD SVN Version to DumpUserOptions ---> (DONE)
49 // FIX output format of DumpUserOptions ---> (DONE)
50 // FIX xCED Spectrograms when pe_noise=0, only detected waveform is displayed ---> (DONE)
51 // ADD GPS time offset to the time plots ---> (DONE)
52 // ADD WDM TF maps ?
53 // ADD descriptions for each TAB in the xCED
54 // SAVE injected whitened signal ---> (DONE)
55 // SAVE all PE/waveform in the output ROOT file ---> (DONE)
56 // For simulation=0 set window +/- iwindow/2 around the event ---> (DONE)
57 // SAVE pe_config to root output file
58 // DUMP to CED dir all PE parameters ---> (DONE)
59 // ADD Checks of the input PE config parameters ---> (DONE)
60 // FIX pe_noise=2 when cedDump=false -> the TF is cleaned and whitened noise is deleted.
61 // USE pe_ced_options to select tabs to be included into xCED ---> (DONE)
62 // IMPLEMENT command : cwb_condor mtpe jobID ---> (DONE)
63 // FIX iSNR,oSNR for non simulation PE : the output SNRnet plot is zero
64 // add check on ISTAGE, PE can only be executed with FULL stage ---> (DONE)
65 // add TF PCA likelihood/null ---> (DONE)
66 
67 // ---------------------------------------------------------------------------------
68 // HOW TO CONFIGURE PLUGIN
69 // the following is an example : must be included in the config/user_parameters.C file
70 // see the DumpUserOptions function for the full description of parameters
71 // ---------------------------------------------------------------------------------
72 /*
73  plugin = TMacro(gSystem->ExpandPathName("$HOME_CWB/plugins/CWB_Plugin_PE.C")); // Macro source
74 
75  TString optpe = ""; // NOTE : add space at the end of each line
76  optpe += "pe_retry=100 "; // number of trials
77  optpe += "pe_gps=1167559936 "; // only gps +/- iwindow is analyzed
78  optpe += "pe_noise=0 "; // signal used for trials : 0/1/2 reconstructed/injected/(original=reconstructed+noise)
79  optpe += "pe_signal=0 "; // waveform is injected in the whitened HoT and apply Coherent+SuperCluster+Likelihood stage
80  optpe += "pe_amp_cal_err=0.1 "; // max percentage of amplitude miscalibration (uniform in -0.9,+1.1) -> det 1
81  optpe += "pe_phs_cal_err=10 "; // max phase (degrees) of phase miscalibration (uniform in -10,+10) -> det 1
82  optpe += "pe_amp_cal_err=0.1 "; // ... -> det 2
83  optpe += "pe_phs_cal_err=10 "; // ... -> det 2
84  optpe += "pe_ced_dump=-1 "; // dump CED at gLRETRY=PE_CED_DUMP
85  optpe += "pe_skymask=0 "; // disable -> search over all sky
86 
87  //optpe += "pe_multitask=true "; // enable/disable multitask (only for 1 job and simulation=0/4, dag is generated with cwb_condor mtpe jobID)
88  // for simulation=0 user must define : optpe += "pe_retry=100 ";
89  // for simulation=4 user must define : nfactor=xx, factor[0]=yy : where xx>0 and yy>0
90 
91  // CED options (only if cedDump=true)
92  optpe += "pe_ced_enable=tfmap ";
93  optpe += "pe_ced_enable=rdr ";
94  optpe += "pe_ced_enable=skymap ";
95  optpe += "pe_ced_enable=rec ";
96  optpe += "pe_ced_enable=inj ";
97  optpe += "pe_ced_disable=rinj ";
98  optpe += "pe_ced_enable=cm ";
99  optpe += "pe_ced_enable=distr ";
100  optpe += "pe_ced_enable=null ";
101  optpe += "pe_ced_disable=pca ";
102 
103  // OUTPUT options (only if cedDump=false)
104  optpe += "pe_output_enable=inj "; // save injection to the output root file
105  optpe += "pe_output_enable=rec "; // save reconstructed waveform to the output root file
106  optpe += "pe_output_enable=med "; // save median to the output root file
107  optpe += "pe_output_enable=p50 "; // save percentile 50 to the output root file
108  optpe += "pe_output_enable=p90 "; // save percentile 90 to the output root file
109  optpe += "pe_output_enable=avr "; // save averaged waveform to the output root file
110  optpe += "pe_output_enable=rms "; // save RMS to the output root file
111 
112  strcpy(parPlugin,optpe.Data()); // set PE plugin parameters
113  strcpy(comment,"pe configuration example");
114 
115 */
116 
117 // ---------------------------------------------------------------------------------
118 // DEFINES
119 // ---------------------------------------------------------------------------------
120 
121 #define nTRIALS 100 // number of trials for noise statistic (GetNoiseStatistic)
122 
123 #define PE_INDEX "$HOME_CWB/www/pe_index_modern.html" // html template used for pe index report page
124 
125 //#define PLOT_TYPE "root"
126 #define PLOT_TYPE "png"
127 //#define SAVE_WAVE2SPARSE_PLOT
128 //#define SAVE_REDUCED_INJ
129 
130 #define PLOT_MEDIAN // plot median,lower50 boud,upper50 bound,lower90 boud,upper90 bound
131  // if commented we plot average,rms,2*rms
132 
133 //#define SAVE_SKYPROB // save gSKYPROB
134 #define SKYMASK_RADIUS 0.1 // used to define skymask
135 
136 #define MAX_TRIALS 1000
137 
138 #define EFRACTION_CUT 0.98 // energy threshold for time and frequency cuts
139 //#define SET_WAVEFORM_CUTS // enable time and frequency cuts
140 
141 // default pe user options
142 #define PE_TRIALS 100 // number of trials
143 #define PE_SIGNAL 0 // signal used for trials : 0/1/2 reconstructed/injected/(original=reconstructed+noise)
144  // note : option 1 can be used only in simulation mode
145 #define PE_NOISE 1 // noise used for trials : 0/1/2
146  // 0 - waveform is injected in the whitened HoT and apply Coherent+SuperCluster+Likelihood stages
147  // 1 - add gaussian noise to likelihood sparse map and apply Likelihood stage
148  // 2 - add whitened HoT to likelihood sparse map and apply Likelihood stage
149 #define PE_AMP_CAL_ERR 0 // max percentage of amplitude miscalibration if>0 (uniform in -max,+max) else (gaus(max))
150 #define PE_PHS_CAL_ERR 0 // max phase (degrees) of phase miscalibration if>0 (uniform in -max,+max) else (gaus(max))
151 #define PE_SKYMASK 0 // skymask used for trials : 0(def)/1/2
152  // 0 : disable -> search over all sky
153  // 1 : skymask with SKYMASK_RADIUS and source selected according the reconstructed skymap probability
154  // 2 : skymask select only the sky position where the waveform is reconstructed
155 #define PE_SEED 0 // 0 : seed used by PE for ramdom generation
156 #define PE_GPS 0 // default 0 - if >0 only gps +/- iwindow is analyzed
157 
158 #define PE_MULTITASK false // if enabled, PE trials are executed by different jobs in multitask : only simulation=0 and single event (gps>0)
159 
160 #define NOISE_SIGMA 1.0 // noise sigma used in AddNoiseAndCalErrToSparse
161 
162 #define PE_CED_DUMP -1 // dump CED at gLRETRY=PE_CED_DUMP
163 
164 #define PE_CED_TFMAP true // Shows the Time-Frequency Maps -> Spectrograms, Scalograms, TF Like,Null
165 #define PE_CED_RDR true // Shows Reconstructed Detector Response tab
166 #define PE_CED_PSD true // Shows Power Spectral Density tab
167 #define PE_CED_SKYMAP true // Shows SkyMaps
168 #define PE_CED_REC true // Shows Reconstructed Waveforms/Instantaneous-Frequency with errors
169 #define PE_CED_INJ true // Shows Injected vs Reconstructed Waveforms/Instantaneous-Frequency with errors
170 #define PE_CED_rINJ false // Shows Reduced Injected vs Reconstructed Waveforms with errors
171 #define PE_CED_CM true // Shows Chirp Mass Value/Error Distributions
172 #define PE_CED_DISTR false // Shows Residuals Distributions
173 #define PE_CED_NULL true // Shows Null Pixels Distributions
174 #define PE_CED_PCA false // Shows PCA likelihood TF plot
175 
176 #define PE_OUTPUT_INJ false // save injected into the output root file
177 #define PE_OUTPUT_REC false // save reconstructed into the output root file
178 #define PE_OUTPUT_WHT false // save whitened data into the output root file
179 #define PE_OUTPUT_DAT false // save rec+nois data into the output root file
180 #define PE_OUTPUT_MED false // save median into the output root file
181 #define PE_OUTPUT_P50 false // save percentile 50 into the output root file
182 #define PE_OUTPUT_P90 false // save percentile 90 into the output root file
183 #define PE_OUTPUT_AVR false // save averaged into the output root file
184 #define PE_OUTPUT_RMS false // save rms into the output root file
185 
186 // ---------------------------------------------------------------------------------
187 // FUNCTIONS
188 // ---------------------------------------------------------------------------------
189 
190 void ClearVectors();
192 
193 double GetSparseMapData(SSeries<double>* SS, bool phase, int index);
194 
195 void SetOutputFile(network* NET, netevent* &EVT, CWB::config* cfg, bool dump_pe);
196 void DumpOutputFile(network* NET, netevent* &EVT, CWB::config* cfg, int ID, int k, int factor);
198 void CreateIndexHTML(TString dirCED, int nIFO, TString* ifo, bool sim=false);
199 void WriteBodyHTML(TString html_template, TString html_tag_beg, TString html_tag_end, ofstream* out, int nIFO=1, TString* ifo=NULL);
200 
201 void Wave2Sparse(network* NET, CWB::config* cfg, char type);
203 int RedoAnalysis(TFile* jfile, CWB::config* cfg, network* NET);
204 void ReplaceSuperclusterData(TFile*& jfile, CWB::config* cfg, network* NET, double gps=0);
205 
206 void GetChirpMassStatistic(std::vector<double>* vCHIRP);
207 void GetFactorsStatistic(int nIFO);
208 void GetSNRnetStatistic(int nIFO);
209 void GetNullPixels(std::vector<double>* aNUL, std::vector<double>* ANUL,
210  network* NET, CWB::config* cfg, int lag, int id);
211 void GetNoisePixels(std::vector<double>* aNSE, std::vector<double>* ANSE,
212  network* NET, CWB::config* cfg, int lag, int id);
213 std::vector<int> ComputeStatisticalErrors(network* NET, CWB::config* cfg, int ID);
214 void SaveSkyProb(network* NET, CWB::config* cfg, int id);
215 void SetEventWindow(CWB::config* cfg, double gps);
216 skymap GetSkyProb(network* NET, int id);
218 void DumpSkyProb(skymap* skyprob, network* NET, netevent* &EVT, TString odir);
219 
220 void SetWaveformCuts(wavearray<double>* x, double bT, double eT, double bF, double eF);
221 wavearray<double> GetCutWaveform(wavearray<double> x, double bT, double eT, double bF, double eF);
222 
224 double GetTimeBoundaries(wavearray<double> x, double P, double& bT, double& eT);
225 double GetFrequencyBoundaries(wavearray<double> x, double P, double& bF, double& eF);
227 
228 std::vector<netpixel> DoPCA(network* NET, CWB::config* cfg, int lag, int id);
229 void ResetPCA(network* NET, CWB::config* cfg, netcluster* pwc, std::vector<netpixel>* vPIX, int ID);
230 
231 std::vector<wavearray<double> > GetPCAWaveform(network* NET, CWB::config* cfg, int lag, int id);
232 std::vector<wavearray<double> > GetInjWaveform(network* NET, netevent* EVT, int id, double factor);
233 std::vector<wavearray<double> > GetRecWaveform(network* NET, netevent* EVT, int id);
234 std::vector<wavearray<double> > GetWhitenedData(network* NET, CWB::config* cfg);
235 std::vector<wavearray<double> > GetWaveform(network* NET, int lag, int id, char type, bool shift=true);
236 std::vector<wavearray<double> > GetSigWaveform(network* NET, CWB::config* cfg, int lag, int id);
237 
238 void SetSkyMask(network* NET, CWB::config* cfg, double theta, double phi, double radius);
239 
244 
246 
248 
251  bool fft=false, TString pdir="", double P=0.99, EColor col1=kRed, EColor col2=kBlue, EColor col3=(EColor)418);
252 void PlotWaveformErrors(TString ofname, TString title, CWB::config* cfg, wavearray<double>* wrec,
253  wavearray<double>* wavr, wavearray<double>* werr, wavearray<double>* wref, TString pdir="", double P=0.99);
256  wavearray<double>* wl90, wavearray<double>* wu90, wavearray<double>* wref, TString pdir, double P, bool freq=false);
257 void PlotFrequencyErrors(TString ofname, TString title, CWB::config* cfg, wavearray<double>* frec,
258  wavearray<double>* favr, wavearray<double>* ferr, wavearray<double>* wref, TString pdir, double P);
259 void PlotWaveforms(network* NET, CWB::config* cfg, int ID, TString pdir="");
260 void PlotResiduals(int ID, TString pdir="", int sim=true, char type='w');
261 void PlotSNRnet(int nIFO, TString pdir, int sim=true);
262 void PlotChirpMass(int gtype, TString pdir, int sim=true);
263 void PlotFactors(int gtype, int nIFO, TString pdir);
264 void GetNullStatistic(std::vector<double>* vNUL, std::vector<double>* vNSE, int ifoId, TString ifoName, TString gtype, TString pdir="");
265 void PlotTimeFrequencyPCA(network* NET, netevent* EVT, CWB::config* cfg, int id, int lag, TString pdir);
266 void PlotSpectrogram(TString type, network* NET, netevent* &EVT, CWB::config* cfg, TString pdir);
267 
268 void DumpRecWavePE(network* NET, TString pdir="");
269 void DumpInjWavePE(network* NET, TString pdir="");
270 
271 void LoadFromMultiTaskJobOutput(int runID, CWB::config* cfg);
272 
273 // ---------------------------------------------------------------------------------
274 // USER CONFIG OPTIONS
275 // ---------------------------------------------------------------------------------
276 
277 struct uoptions {
278  int trials;
279  int signal;
280  int noise;
281  float amp_cal_err[NIFO_MAX];
282  float phs_cal_err[NIFO_MAX];
283  int id;
284  int skymask;
285  int seed; // default 0
286  double gps; // default 0 - if >0 only gps +/- iwindow is analyzed
287 
288  bool multitask; // if enabled, PE trials are executed by different jobs in multitask : only simulation=0 and single event (gps>0)
289 
290  int ced_dump; // dump CED at gLRETRY=ced_dump (-1 = disable)
291 
292  bool ced_tfmap; // Shows the Time-Frequency Maps -> Spectrograms, Scalograms, TF Like,Null
293  bool ced_rdr; // Shows Reconstructed Detector Response
294  bool ced_psd; // Show Power Spectral Density
295  bool ced_skymap; // Shows SkyMaps
296  bool ced_rec; // Shows Reconstructed Waveforms/Instantaneous-Frequency with errors
297  bool ced_inj; // Shows Injected vs Reconstructed Waveforms/Instantaneous-Frequency with errors
298  bool ced_rinj; // Shows Reduced Injected vs Reconstructed Waveforms with errors
299  bool ced_cm; // Shows Chirp Mass Value/Error Distributions
300  bool ced_distr; // Shows Residuals Distributions
301  bool ced_null; // Shows Null Pixels Distributions
302  bool ced_pca; // Shows PCA likelihood TF plot
303 
304  bool output_inj; // save injected into the output root file
305  bool output_rec; // save reconstructed into the output root file
306  bool output_wht; // save whitened data into the output root file
307  bool output_dat; // save rec+nois data into the output root file
308  bool output_med; // save median into the output root file
309  bool output_p50; // save percentile 50 into the output root file
310  bool output_p90; // save percentile 90 into the output root file
311  bool output_avr; // save averaged into the output root file
312  bool output_rms; // save rms into the output root file
313 };
314 
315 void ResetUserOptions();
317 void PrintUserOptions(CWB::config* cfg);
319 
320 // ----------------------------------------------------
321 // ROOT Output PE Parameters
322 // ----------------------------------------------------
323 
324 struct PE { // structure for output for estimated parameters
325 
326  int trials; // number of effective trials
327  float erR[11]; // probability distribution of residuals
328  float erF[11]; // probability distribution of frequency residuals
329  float nstat[2*7*NIFO_MAX]; // null pixel statistic, for each detector
330  // 0->7 : Null 00
331  // 7->13 : Null 90
332  // gPE.stat[0] = Null Pixels Mean
333  // gPE.stat[1] = Null Pixels RMS
334  // gPE.stat[2] = Noise Pixels Mean
335  // gPE.stat[3] = Noise Pixels RMS
336  // gPE.stat[4] = Noise Pixels Chi2
337  // gPE.stat[5] = KolmogorovTest
338  // gPE.stat[6] = AndersonDarlingTest
339  float snet[2]; // SNRnet statistic, 0 -> avr, 1 -> rms
340  float ff[2]; // Fitting Factor statistic, 0 -> avr, 1 -> rms
341  float of[2]; // Overlap Factor statistic, 0 -> avr, 1 -> rms
342  float mch[2]; // chirp mass statistic, 0 -> avr, 1 -> rms
343 
349  wavearray<double>* wL50[NIFO_MAX];
355 };
356 
357 // ---------------------------------------------------------------------------------
358 // Global Variables
359 // ---------------------------------------------------------------------------------
360 
361 uoptions gOPT; // global User Options
362 PE gPE; // global output for estimated parameters
363 TTree* gTREE; // output tree file name
364 TString gOUTPUT; // output root file name
366 bool gCEDDUMP; // save user_parameters cedDump
367 
368 double gITHETA; // injected theta sky position (EVT->theta[1])
369 double gIPHI; // injected phy sky position (EVT->phi[1])
370 double gOTHETA; // reconstructed theta sky position (EVT->theta[3]) : the maximum of detection statistic
371 double gOPHI; // reconstructed phy sky position (EVT->phi[3]) : the maximum of detection statistic
372 
373 skymap gSKYPROB; // saved reconstructed probability skymap
374 TH1D gHSKYPROB; // used to extract random skyloc for skymask
375 
376 double gBT, gET; // time ranges used for cutted injections (EFRACTION_CUT)
377 double gBF, gEF; // freq ranges used for cutted injections (EFRACTION_CUT)
378 
379 wavearray<double> gHOT[NIFO_MAX]; // HoT time series used to save whitened data
380 
381 double gINRATE; // input data sampling rate
382 int gRATEANA; // analysis data rate
383 
384 int gMTRIAL; // trial ID, used to process a single trial when PE is executed in multitask mode (only with simulation=0)
385 int gID; // ID of the detected event, used in multitask mode to exclude from the processing the ID!=gID
386 
387 double gSEGGPS; // segment start time
388 
389 // ---------------------------------------------------------------------------------
390 // waveforms (vectors index is ifos)
391 // ---------------------------------------------------------------------------------
392 
393 std::vector<wavearray<double> > vINJ; // injected
394 std::vector<wavearray<double> > vREC; // signal reconstructed by wave packet
395 std::vector<wavearray<double> > vWHT; // whitened data (in the vREC time range)
396 std::vector<wavearray<double> > vPCA; // reconstructed by PCA
397 std::vector<wavearray<double> > vDAT; // noise+signal reconstructed by wave packet
398 std::vector<wavearray<double> > vNUL; // vDAT-vREC
399 std::vector<wavearray<double> > cINJ; // injected (cutted) on TF sub-space of the reconstructed waveform vREC
400 
401 std::vector<wavearray<double> > vAVR; // average reconstructed amplitude
402 std::vector<wavearray<double> > vRMS; // rms
403 
404 std::vector<wavearray<double> > vMED; // median reconstructed amplitude
405 std::vector<wavearray<double> > vL50; // = vMED - 50% Lower Bound
406 std::vector<wavearray<double> > vU50; // = vMED - 50% Upper Bound
407 std::vector<wavearray<double> > vL90; // = 90% Lower Bound - vMED
408 std::vector<wavearray<double> > vU90; // = 90% Upper Bound - vMED
409 
410 std::vector<wavearray<double> > fREC; // instantaneous reconstructed frequency
411 std::vector<wavearray<double> > fINJ; // instantaneous cutted injected frequency
412 std::vector<wavearray<double> > fAVR; // instantaneous averaged reconstructed frequency
413 std::vector<wavearray<double> > fRMS; // rms of instantaneous averaged frequency
414 
415 std::vector<wavearray<double> > fMED; // median instantaneous reconstructed frequency
416 std::vector<wavearray<double> > fL50; // 50% Lower Bound
417 std::vector<wavearray<double> > fU50; // 50% Upper Bound
418 std::vector<wavearray<double> > fL90; // 90% Lower Bound
419 std::vector<wavearray<double> > fU90; // 90% Upper Bound
420 
421 std::vector<double > vRES; // normalized residual energy
422 std::vector<double > fRES; // normalized frequency weighted residuals
423 
424 std::vector<wavearray<double> > wREC[MAX_TRIALS]; // reconstructed signal in the trials
425 
426 std::vector<double> iSNR[NIFO_MAX]; // input SNR^2
427 std::vector<double> oSNR[NIFO_MAX]; // reconstructed SNR^2
428 std::vector<double> ioSNR[NIFO_MAX]; // iSNR*oSNR
429 std::vector<double> vLIKELIHOOD; // likelihood
430 
431 std::vector<double> aNUL[NIFO_MAX]; // null 00 phase amplitudes
432 std::vector<double> ANUL[NIFO_MAX]; // null 90 phase amplitudes
433 
434 std::vector<double> aNSE[NIFO_MAX]; // noise 00 phase amplitudes
435 std::vector<double> ANSE[NIFO_MAX]; // noise 90 phase amplitudes
436 
437 std::vector<double> vCHIRP[6]; // 0 -> injected chirp mass
438  // 1 -> reconstructed chirp mass
439  // 2 -> reconstructed chirp mass error
440  // 3 -> ellipticity parameter
441  // 4 -> pixel fraction
442  // 5 -> energy fraction
443 
444 skymap wSKYPROB[MAX_TRIALS]; // sky probability trials
445 skymap mSKYPROB; // sky probability median
446 
447 // ---------------------------------------------------------------------------------
448 // sparse maps
449 // ---------------------------------------------------------------------------------
450 
451 std::vector<SSeries<double> > vSS[NIFO_MAX]; // original sparse maps
452 std::vector<SSeries<double> > jSS[NIFO_MAX]; // injected
453 std::vector<SSeries<double> > rSS[NIFO_MAX]; // reconstructed
454 std::vector<SSeries<double> > dSS[NIFO_MAX]; // noise+signal reconstructed by wave packet
455 
456 void
458 //!MISCELLANEA
459 // Plugin used for Parameters Estimation
460 
461  if(type==CWB_PLUGIN_CONFIG) {
462  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
463 
464  if(gCWB2G->istage!=CWB_STAGE_FULL) {cout<< "CWB_Plugin_PE - Error : PE can be executed only in CWB_STAGE_FULL mode" << endl;exit(1);}
465 
466  if(cfg->pattern<=0) {
467  cout << "CWB_Plugin_PE Error : PE enable only with pattern>0 !!!" << endl;
468  exit(1);
469  }
470  cfg->outPlugin=true; // disable built-in output root file
471  gINRATE=cfg->inRate; // input data sampling rate
472  gRATEANA=gCWB2G->rateANA; // analysis data rate
473  gID=0; // used in multitask mode
474 
475  ResetUserOptions(); // set default config options
476  ReadUserOptions(cfg->parPlugin); // user config options : read from parPlugin
477  TString cwb_inet_options=TString(gSystem->Getenv("CWB_INET_OPTIONS")); // overwrite parPlugin
478  ReadUserOptions(cwb_inet_options); // user config options : read from command line
479 
480  if(gOPT.ced_inj && gOPT.ced_rinj) gOPT.ced_rinj=false;
481 
482  if(gOPT.multitask) {
483  if(cfg->simulation==4 && cfg->nfactor!=1) {
484  cout<< "CWB_Plugin_PE - Error : when simulation=4, PE multitask can be executed only with nfactors=1" << endl;exit(1);
485  }
486  }
487 
488  if(cfg->cedDump) { // if at least one of the output options is enabled
489  // then we enable the output root file even when cedDump=true
490  if(gOPT.output_inj || gOPT.output_rec ||
491  gOPT.output_med || gOPT.output_p50 ||
492  gOPT.output_p90 || gOPT.output_avr ||
493  gOPT.output_rms || gOPT.output_wht || gOPT.output_dat) cfg->online=true;
494  }
495 
496  // get gMTRIAL
497  // NOTE : trial ID, used to process a single trial when PE is executed in multitask mode
498  // can be used only for simulation=0 and gOPT.gps>0 (single event) !!!
499  gMTRIAL=gOPT.trials;
500  if(gOPT.multitask) {
501  TString gtrial=TString(gSystem->Getenv("CWB_MDC_FACTOR"));
502  if(gtrial.CompareTo("")!=0) {
503  if(!gtrial.IsDigit()) {cout<< "CWB_Plugin_PE - Error : when simulation=0, CWB_MDC_FACTOR must be an interger > 0" << endl;exit(1);}
504  gMTRIAL=gtrial.Atoi();
505  if(gMTRIAL==0) {cout<< "CWB_Plugin_PE - Error : when simulation=0, CWB_MDC_FACTOR must be an interger > 0" << endl;exit(1);}
506  if(gMTRIAL!=gOPT.trials) { // multitask jobs
507  // add trial to data_label -> different output files for each trial
508  sprintf(cfg->data_label,"%s_trial%d",cfg->data_label,gMTRIAL);
509  cout << "CWB_Plugin_PE - MultiTask Mode : new data_label = " << cfg->data_label << endl;
510  // disable ooptions not used in multitask mode
511  cfg->cedDump=false;
512  gOPT.output_inj=false;
513  gOPT.output_rec=false;
514  gOPT.output_wht=false;
515  gOPT.output_dat=false;
516  gOPT.output_med=false;
517  gOPT.output_p50=false;
518  gOPT.output_p90=false;
519  gOPT.output_avr=false;
520  gOPT.output_rms=false;
521  } else { // last multitask job : collect all output from multitask jobs
522  LoadFromMultiTaskJobOutput(gCWB2G->runID, cfg); // read wREC,gSKYPROB from multitalk output root files
523  }
524  bool last_trial = (gMTRIAL==gOPT.trials) ? true : false;
525  if(!last_trial) {gOPT.trials=1;gMTRIAL*=-1;}
526  }
527  }
528 
529  gCEDDUMP=cfg->cedDump; // save user_parameter cedDump
530 
531  gRandom->SetSeed(gOPT.seed); // set seed for PE random generation
532 
533  SetEventWindow(cfg, gOPT.gps); // if gps>0 only gps +/- iwindow is analyzed
534 
535  // check input PE config parameters
536 
537  if(gOPT.signal!=0 && gOPT.signal!=1 && gOPT.signal!=2) {
538  cout << endl;
539  cout << "CWB_Plugin_PE Error : option pe_signal not allowed : must be (0/1/2) !!!" << endl;
540  cout << endl;
541  exit(1);
542  }
543 
544  if(cfg->simulation==0 && gOPT.signal==1) {
545  cout << endl;
546  cout << "CWB_Plugin_PE Error : option pe_signal=1 is allowed only in simulation mode !!!" << endl;
547  cout << endl;
548  exit(1);
549  }
550 
551  if(cfg->simulation==0 && gOPT.skymask==3) {
552  cout << endl;
553  cout << "CWB_Plugin_PE Error : option pe_skymask=3 is allowed only in simulation mode !!!" << endl;
554  cout << endl;
555  exit(1);
556  }
557  }
558 
559  if(type==CWB_PLUGIN_INIT_JOB) {
560  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
561 
562  if(gOPT.gps<gCWB2G->GetSegBegin() || gOPT.gps>gCWB2G->GetSegEnd()) {
563  cout.precision(14);
564  cout << "CWB_Plugin_PE - Error : gps time must be within the segment interval: "
565  << gCWB2G->GetSegBegin() << "\t" << gCWB2G->GetSegEnd() << endl;exit(1);
566  cout.precision(6);
567  }
568  }
569 
570  if(type==CWB_PLUGIN_NETWORK) {
571  PrintUserOptions(cfg); // print config options
572  }
573 
575  if(NET->mdcTime.size()>1) {
576  cout << endl;
577  cout << "CWB_Plugin_PE Error : detected " << NET->mdcTime.size() << " injections."
578  << " Must be only one injection per segment !!!" << endl;
579  cout << endl;
580  exit(1);
581  }
582  }
583 
585  // save whitened HoT
586  int ifoID =0; for(int n=0;n<cfg->nIFO;n++) if(ifo==NET->getifo(n)->Name) {ifoID=n;break;}
587  gHOT[ifoID] = *x;
588  }
589 
590  if(type==CWB_PLUGIN_ILIKELIHOOD) { // INIT CWB LIKELIHOOD STAGE (once for each lag)
591  NET->wfsave=true; // enable waveform save
592 
593  // export gLRETRY
594  if(gOPT.multitask) EXPORT(int,gLRETRY,"gLRETRY = 1;")
595  else EXPORT(int,gLRETRY,TString::Format("gLRETRY = %d;",gOPT.trials).Data())
596 
597  ReplaceSuperclusterData(jfile, cfg, NET, gOPT.gps); // save in jfile max size supercluster
598  }
599 
600  if(type==CWB_PLUGIN_XLIKELIHOOD) { // BEFORE EVENT RECONSTRUCTION (for each event repeated gOPT.trials)
601 
602  wavearray<double> cid = NET->getwc(0)->get((char*)"ID", 0,'S',0); // get cluster ID
603  if(cid.size()==0) return;
604  int ID = size_t(cid.data[cid.size()-1]+0.1);
605 
606  if(gOPT.trials==0) return;
607 
608  // import gLRETRY
609  int gLRETRY=-1; IMPORT(int,gLRETRY)
610  cout << endl;
611  cout << "-------------------------------------------------------------------" << endl;
612  cout << "-----> CWB_Plugin_PE.C -> ID : " << ID
613  << " -> gLRETRY : " << gLRETRY << "/" << gOPT.trials << endl;
614  cout << "-------------------------------------------------------------------" << endl;
615 
616  // -------------------------------------------------
617  // FIRST TRIAL
618  // reconstruct signal with original noise (full sky)
619  // -------------------------------------------------
620  if(gLRETRY==gOPT.trials) {
621  ClearVectors();
622  cfg->cedDump=false;
623  }
624 
625  // -----------------------------------------------------------------------------------
626  // AFTER FIRST TRIAL
627  // reconstruct signal with reconstructed signal + gaussian noise & (calib. errors)
628  // -----------------------------------------------------------------------------------
629  if(gLRETRY!=gOPT.trials) {
630 
631  // SKYMASK
632  if(gOPT.skymask==1) {
633  // select random sky position from sky probability gHSKYPROB
634  int isky = (int)gHSKYPROB.GetRandom();
635  double th = 90-gSKYPROB.getTheta(isky);
636  double ph = gSKYPROB.getPhi(isky);
637 
638  SetSkyMask(NET, cfg, th, ph, SKYMASK_RADIUS);
639  }
640  if(gOPT.skymask==2) {
641  // select reconstructed sky position (the maximum of detection statistic : waveform is reconstructed in such position)
642  SetSkyMask(NET, cfg, gOTHETA, gOPHI, SKYMASK_RADIUS);
643  }
644  if(gOPT.skymask==3) {
645  // select injected sky position : only in simulation mode
646  SetSkyMask(NET, cfg, gITHETA, gIPHI, SKYMASK_RADIUS);
647  }
648 
649  // ADD NOISE (& ADD CALIBRATION ERRORS)
650  // add noise to the sparse map of the reconstructed event
651  // Note : calibration errors are applied only if gOPT.noise is enabled !!!
652  char jtype='r';
653  if(gOPT.signal==0) jtype='r'; // use reconstructed waveform for trials
654  if(gOPT.signal==1) jtype='j'; // use injected waveform for trials
655  if(gOPT.signal==2) jtype='v'; // use data for trials
656  if(gOPT.noise) AddNoiseAndCalErrToSparse(NET, cfg, jtype);
657 
658  // DUMP CED
659  cfg->cedDump=false;
660  if((gOPT.ced_dump>=0) && (gLRETRY==gOPT.ced_dump)) cfg->cedDump=true;
661  }
662 
663  // -------------------------------------------------
664  // LAST TRIAL
665  // reconstruct signal with original noise (full sky)
666  // -------------------------------------------------
667  if((gLRETRY==0)&&(gMTRIAL==gOPT.trials)) { // use original injection setup
668 
669  // SKYMASK
670  // select detected sky position (waveform is reconstructed in such poosition)
671  //SetSkyMask(NET, cfg, gOTHETA, gOPHI, SKYMASK_RADIUS);
672  // restore full sky search for the last trial
673  SetSkyMask(NET, cfg, 0, 0, 360); // full sky search
674 
675  if(gOPT.noise!=0) {
676  // restore original sparse maps
677  int nIFO = NET->ifoListSize(); // number of detectors
678  for(int n=0;n<nIFO;n++) {
679  detector* pD = NET->getifo(n);
680  pD->vSS=vSS[n];
681  }
682  }
683 
684  // DUMP CED
685  cfg->cedDump=gCEDDUMP; // restore user_parameter cedDump (executed in the last trial)
686  }
687  }
688 
689  if(type==CWB_PLUGIN_OLIKELIHOOD) { // AFTER EVENT RECONSTRUCTION (for each event repeated gOPT.trials)
690 
691  // import trials
692  int gLRETRY=-1; IMPORT(int,gLRETRY)
693 
694  // import ifactor
695  int gIFACTOR=-1; IMPORT(int,gIFACTOR)
696  double factor = cfg->simulation==3||cfg->simulation==4 ? -gIFACTOR : cfg->factors[gIFACTOR];
697  double ofactor=0;
698  if(cfg->simulation==4) ofactor=-gIFACTOR;
699  else if(cfg->simulation==3) ofactor=-gIFACTOR;
700  else ofactor=factor;
701 
702  int nIFO = NET->ifoListSize(); // number of detectors
703  int K = NET->nLag; // number of time lag
704  int rate = 0; // select all resolutions
705  netevent* EVT;
707 
708  SetOutputFile(NET, EVT, cfg, false); // set output root file
709 
710  for(int k=0; k<K; k++) { // loop over the lags
711 
712  id = NET->getwc(k)->get(const_cast<char*>("ID"), 0, 'L', rate);
713 
714  if(id.size()==0) cfg->cedDump=gCEDDUMP; // rejected -> restore user_parameter cedDump
715 
716  for(int j=0; j<(int)id.size(); j++) { // loop over cluster index
717 
718  int ID = size_t(id.data[j]+0.5);
719 
720  if(NET->getwc(k)->sCuts[ID-1]!=-1) continue; // skip rejected/processed clusters
721 
722  EVT->output2G(NULL,NET,ID,k,ofactor); // get reconstructed parameters
723 
724  for(int n=0; n<nIFO; n++) { // save SNR
725  iSNR[n].push_back(EVT->iSNR[n]);
726  oSNR[n].push_back(EVT->oSNR[n]);
727  ioSNR[n].push_back(EVT->ioSNR[n]);
728  }
729  for(int n=0; n<6; n++) { // save chirp mass parameters
730  vCHIRP[n].push_back(EVT->chirp[n]);
731  }
732  vLIKELIHOOD.push_back(EVT->likelihood); // save likelihood
733 
734  // print event parameters
735  cout << endl;
736  cout << "event parameters : ID -> " << ID << endl;
737  for(int n=0;n<nIFO;n++) printf("rec_time %s : %.4f\n",NET->ifoName[n], EVT->time[n]);
738  cout << "rec_theta : " << EVT->theta[0] << " rec_phi : " << EVT->phi[0] << endl;
739  cout << "SNRnet : " << sqrt(EVT->likelihood) << " netcc[0] : " << EVT->netcc[0]
740  << " rho[0] : " << EVT->rho[0] << " size : " << EVT->size[0] << endl;
741 
742  if(gOPT.trials==0) {
743  DumpOutputFile(NET, EVT, cfg, ID, k, ofactor); // dump event to output root file
744  continue;
745  }
746 
747  // -------------------------------------------------
748  // FIRST TRIAL
749  // reconstruct signal with original noise (full sky)
750  // -------------------------------------------------
751  if((gLRETRY==gOPT.trials) || (gOPT.multitask && gLRETRY==1)) {
752  // get waveforms
753  if(cfg->simulation) {
754  vINJ = GetInjWaveform(NET, EVT, ID, factor); // get injected waveform
755  if(vINJ.size()!=nIFO) {
756  cout << "CWB_Plugin_PE Error : Injection Waveform Not Found !!!" << endl;
757  exit(1);
758  }
759  cINJ = vINJ; // cINJ is overwritten by GetSigWaveform
760  }
761  vREC = GetRecWaveform(NET, EVT, ID); // get reconstructed waveform
762  vWHT = GetWhitenedData(NET, cfg); // get whitened data (in the vREC time range)
763  vDAT = GetWaveform(NET, k, ID, 'W'); // get reconstructed+noise waveform
764  vNUL = GetWaveform(NET, k, ID, 'N'); // get noise-reconstructed waveform
765  for(int n=0;n<nIFO;n++) { // compute the istantaneous frequency of reconstructed waveform
766  fREC.push_back(CWB::Toolbox::getHilbertIFrequency(vREC[n]));
767  }
768 
769  Wave2Sparse(NET,cfg,'v'); // save original sparse map to vSS
770  Wave2Sparse(NET,cfg,'r'); // rec to rSS
771  Wave2Sparse(NET,cfg,'d'); // dat to dSS
772  if(cfg->simulation) Wave2Sparse(NET,cfg,'j'); // inj to jSS
773  // get injected waveform on TF sub-space of the reconstructed waveform vREC
774  if(cfg->simulation) {
775  cINJ = GetSigWaveform(NET, cfg, k, ID);
776  for(int n=0;n<nIFO;n++) { // compute the istantaneous frequency of cutted injected waveform
777  fINJ.push_back(CWB::Toolbox::getHilbertIFrequency(cINJ[n]));
778  }
779  }
780 
781  if(gOPT.skymask==1) SaveSkyProb(NET,cfg,ID); // save sky probability, used for trials
782 
783  GetNullPixels(aNUL, ANUL, NET, cfg, k, ID); // get null pixels in TF domain
784  GetNoisePixels(aNSE, ANSE, NET, cfg, k, ID); // get noise pixels in TF domain
785  for(int n=0; n<nIFO; n++) { // fill gPE.nstat output
786  GetNullStatistic(&aNUL[n], &aNSE[n], n, NET->ifoName[n], "null_00");
787  GetNullStatistic(&ANUL[n], &ANSE[n], n, NET->ifoName[n], "null_90");
788  }
789 
790  // save event parameters
791  gSEGGPS = EVT->gps[0]; // save segment start time (sec)
792  gITHETA = EVT->theta[1]; gIPHI = EVT->phi[1]; // save injected sky position
793  gOTHETA = EVT->theta[3]; gOPHI = EVT->phi[3]; // save reconstructed sky poosition (the maximum of detection statistic)
794 
795  //vPCA = GetPCAWaveform(NET, cfg, k, ID); // get pca waveform
796  }
797 
798  // -----------------------------------------------------------------------------------
799  // AFTER FIRST TRIAL
800  // reconstruct signal with reconstructed signal + gaussian noise & (calib. errors)
801  // -----------------------------------------------------------------------------------
802  if(gLRETRY!=gOPT.trials) {
803  wREC[gLRETRY] = GetRecWaveform(NET, EVT, ID); // get reconstructed waveform
804  wSKYPROB[gLRETRY] = GetSkyProb(NET, ID); // get sky probability
805  gID=ID; // used in multitask mode
806  }
807 
808  // -------------------------------------------------
809  // LAST TRIAL
810  // reconstruct signal with original noise (full sky)
811  // -------------------------------------------------
812  if(gLRETRY==0) {
813  std::vector<int> nrec = ComputeStatisticalErrors(NET, cfg, ID);
814  if(cfg->simulation) GetFactorsStatistic(nIFO); // fill gPE.ff, gPE.of
815  GetSNRnetStatistic(nIFO); // fill gPE.snet
816  GetChirpMassStatistic(vCHIRP); // fill gPE.mch
817  mSKYPROB = GetMedianSkyProb(NET); // get median sky probability
818 
819  SetOutputFile(NET, EVT, cfg, true); // set output root file
820  DumpOutputFile(NET, EVT, cfg, ID, k, ofactor); // dump event to output root file
821  if(cfg->cedDump) {
822  TString dirCED = DumpCED(NET, EVT, cfg, ofactor); // dump CED
823  cout << "dirCED : " << dirCED << endl;
824  DumpSkyProb(&mSKYPROB, NET, EVT, dirCED); // dump median mSKYPROB to fits file
825  TString ifo[NIFO_MAX];
826  for(int n=0; n<nIFO; n++) ifo[n]=NET->ifoName[n];
827  CreateIndexHTML(dirCED, nIFO,ifo,cfg->simulation); // create html file
828  if(nrec.size()) {
829  PlotWaveforms(NET,cfg,ID,dirCED); // plot waveforms
830  if(gOPT.ced_distr) {
831  PlotResiduals(ID,dirCED,cfg->simulation,'w'); // plot residual enegy
832  PlotResiduals(ID,dirCED,cfg->simulation,'f'); // plot frequency residual enegy
833  gStyle->SetOptFit(1111);
834  PlotSNRnet(nIFO,dirCED,cfg->simulation); // plot SNRnet
835  }
836  if(gOPT.ced_cm) {
837  for(int n=1;n<6;n++) PlotChirpMass(n,dirCED,cfg->simulation); // plot mchirp
838  }
839  PlotFactors(0,nIFO,dirCED); // plot fitting factor
840  PlotFactors(1,nIFO,dirCED); // plot overlap factor;
841  if(gOPT.ced_null) {
842  for(int n=0; n<nIFO; n++) { // plot null statistic
843  GetNullStatistic(&aNUL[n], &aNSE[n], n, ifo[n], "null_00", dirCED);
844  GetNullStatistic(&ANUL[n], &ANSE[n], n, ifo[n], "null_90", dirCED);
845  }
846  }
847  gStyle->SetOptFit(0000);
848  DumpRecWavePE(NET,dirCED); // dumps rec waveform/time/freq/errors array in ASCII format.
849  if(cfg->simulation) DumpInjWavePE(NET,dirCED); // dumps inj waveform/time in ASCII format.
850  }
851  DumpUserOptions(dirCED, cfg); // dump PE user options
852 
853  if(gOPT.ced_pca) PlotTimeFrequencyPCA(NET, EVT, cfg, ID, k, dirCED); // plot tf likelihood pca
854  if(gOPT.ced_null) PlotSpectrogram("null", NET, EVT, cfg, dirCED); // plot null spectrograms
855  if(gOPT.ced_null) PlotSpectrogram("signal", NET, EVT, cfg, dirCED); // plot reconstructed signal spectrograms
856  if(cfg->simulation) PlotSpectrogram("injection", NET, EVT, cfg, dirCED); // plot injected signal spectrograms
857  }
858 
859  for(int n=0;n<nIFO;n++) {
860  detector* pD = NET->getifo(n);
861  pD->vSS=vSS[n]; // restore original sparse maps
862  if(!cfg->simulation) ClearWaveforms(pD); // release waveform memory
863  }
864  }
865  }
866  }
867 
868  jfile->cd();
869  if(EVT) delete EVT;
870  }
871 
872  // if gOPT.noise=0 the reconstructed is injected in the whitened data and Coherence+SuperCluster is done
873  if(type==CWB_PLUGIN_OLIKELIHOOD) {
874  if(gOPT.noise==0) {
875  int gLRETRY=-1; IMPORT(int,gLRETRY)
876  int csize=0;
877  do {
878  cout << endl;
879  cout << "-------------------------------------------------------------------" << endl;
880  cout << "-----> CWB_Plugin_PE.C -> RedoAnalysis : "
881  << " -> gLRETRY : " << gLRETRY << "/" << gOPT.trials << endl;
882  cout << "-------------------------------------------------------------------" << endl;
883  csize = RedoAnalysis(jfile, cfg, NET);
884  EXPORT(int,gLRETRY,TString::Format("gLRETRY = %d;",--gLRETRY).Data())
885  } while(csize==0 && gLRETRY>0);
886  EXPORT(int,gLRETRY,TString::Format("gLRETRY = %d;",++gLRETRY).Data())
887  }
888  }
889 
890  return;
891 }
892 
893 std::vector<netpixel> DoPCA(network* NET, CWB::config* cfg, int lag, int id) {
894 
895  double ee;
896 
897  size_t nIFO = NET->ifoList.size();
898 
899  float En = 2*NET->acor*NET->acor*nIFO; // network energy threshold in the sky loop
900 
901  int size = NET->a_00.size();
902  int f_ = NIFO/4;
903 
904  netpixel* pix;
905  netcluster* pwc = NET->getwc(lag);
906  std::vector<netpixel> vPIX;
907 
908  std::vector<int> pI = NET->wdmMRA.getXTalk(pwc, id, false); // buffer for pixel IDs
909  int V = pI.size();
910  if(V>cfg->BATCH) return vPIX; // attach TD amp to pixels < V
911 
912  wavearray<float> xi(size); xi=0; // PC 00 array
913  wavearray<float> XI(size); XI=0; // PC 90 array
914 
915  __m128* _xi = (__m128*) xi.data; // set pointer to PC 00 array
916  __m128* _XI = (__m128*) XI.data; // set pointer to PC 90 array
917 
918  __m128* _aa = (__m128*) NET->a_00.data; // set pointer to 00 array
919  __m128* _AA = (__m128*) NET->a_90.data; // set pointer to 90 array
920 
921  int nPC = 0;
922  for(int j=0; j<V; j++) {
923  int jf = j*f_; // source sse pointer increment
924  _sse_zero_ps(_xi+jf); // zero MRA amplitudes
925  _sse_zero_ps(_XI+jf); // zero MRA amplitudes
926  ee = _sse_abs_ps(_aa+jf,_AA+jf); // total pixel energy / quadrature
927  if(ee>En) nPC++; else ee=0.; // count core pixels
928  NET->rNRG.data[j] = ee; // init residual energy array
929  NET->pNRG.data[j] = NET->rNRG.data[j]; // init residual energy array
930  }
931 
932  nPC = NET->_sse_mra_ps(xi.data,XI.data,En,nPC); // get principal components
933 
934  for(int j=0; j<V; j++) { // loop over principal components
935  pix = pwc->getPixel(id,pI[j]);
936  vPIX.push_back(*pix); // save original pixels
937  pix->core = false;
938  ee = NET->pNRG.data[j]; // total pixel energy
939  if(ee<En) continue;
940  pix->core = true;
941  for(int i=0; i<nIFO; i++) {
942  pix->setdata(double(xi.data[j*NIFO+i]),'S',i); // store 00 whitened response PC
943  pix->setdata(double(XI.data[j*NIFO+i]),'P',i); // store 90 whitened response PC
944  }
945  }
946 
947  return vPIX;
948 }
949 
950 void ResetPCA(network* NET, CWB::config* cfg, netcluster* pwc, std::vector<netpixel>* vPIX, int ID) {
951 
952  std::vector<int> pI = NET->wdmMRA.getXTalk(pwc, ID, false); // buffer for pixel IDs
953  int V = pI.size();
954  if(V>cfg->BATCH) return; // attach TD amp to pixels < V
955  for(int j=0; j<V; j++) {
956  netpixel* pix = pwc->getPixel(ID,pI[j]);
957  *pix = (*vPIX)[j];
958  }
959 
960  while(!vPIX->empty()) vPIX->pop_back();
961  vPIX->clear(); std::vector<netpixel>().swap(*vPIX);
962 }
963 
964 std::vector<wavearray<double> > GetPCAWaveform(network* NET, CWB::config* cfg, int lag, int id) {
965 
966  std::vector<wavearray<double> > xPCA; // reconstructed
967 
968  std::vector<netpixel> vPIX;
969  vPIX = DoPCA(NET, cfg, lag, id); // do PCA analysis
970 
971  int nIFO = NET->ifoListSize(); // number of detectors
972  netcluster* pwc = NET->getwc(lag);
973 
974  if(NET->getMRAwave(id,lag,'S',0,true)) { // reconstruct whitened shifted pd->waveForm
975  detector* pd;
976  for(int i=0; i<nIFO; i++) { // loop over detectors
977  pd = NET->getifo(i);
978  wavearray<double>* wf = &pd->waveForm;
979  wf->start(pwc->start+pd->waveForm.start());
980  xPCA.push_back(*wf);
981  }
982  }
983 
984  ResetPCA(NET, cfg, pwc, &vPIX, id); // restore WP pwc
985 
986  return xPCA;
987 }
988 
989 void PlotTimeFrequencyPCA(network* NET, netevent* EVT, CWB::config* cfg, int id, int lag, TString pdir) {
990 
991  std::vector<netpixel> vPIX;
992  vPIX = DoPCA(NET, cfg, lag, id); // do PCA analysis
993 
994  int nIFO = NET->ifoListSize(); // number of detectors
995  netcluster* pwc = NET->getwc(lag);
996 
997  TString xtitle = TString::Format("Time (sec) : GPS OFFSET = %.3f",EVT->gps[0]);
998 
999  watplot WTS(const_cast<char*>("wts"));
1000  WTS.canvas->cd();
1001  char fname[1024];
1002  sprintf(fname, "%s/pca_l_tfmap_scalogram.png",pdir.Data());
1003  cout << "write " << fname << endl;
1004  WTS.plot(pwc, 1, nIFO, 'L', 0, const_cast<char*>("COLZ"));
1005  WTS.hist2D->GetYaxis()->SetRangeUser(EVT->low[0],EVT->high[0]);
1006  WTS.hist2D->GetXaxis()->SetTitle(xtitle);
1007  WTS.canvas->Print(fname);
1008  WTS.clear();
1009 /*
1010  sprintf(fname, "%s/pca_n_tfmap_scalogram.png",pdir.Data());
1011  cout << "write " << fname << endl;
1012  WTS.plot(pwc, 1, nIFO, 'N', 0, const_cast<char*>("COLZ"));
1013  WTS.canvas->Print(fname);
1014  WTS.clear();
1015 */
1016 
1017  ResetPCA(NET, cfg, pwc, &vPIX, id); // restore WP pwc
1018 
1019 }
1020 
1021 std::vector<wavearray<double> > GetInjWaveform(network* NET, netevent* EVT, int ID, double factor) {
1022 
1023  std::vector<wavearray<double> > xINJ; // injected
1024 
1025  int nIFO = NET->ifoListSize(); // number of detectors
1026 
1027  double recTime = EVT->time[0]; // rec event time det=0
1028 
1029  injection INJ(nIFO);
1030  // get inj ID
1031  int M = NET->mdc__IDSize();
1032  double injTime = 1.e12;
1033  int injID = -1;
1034  for(int m=0; m<M; m++) {
1035  int mdcID = NET->getmdc__ID(m);
1036  double T = fabs(recTime - NET->getmdcTime(mdcID));
1037  if(T<injTime && INJ.fill_in(NET,mdcID)) {
1038  injTime = T;
1039  injID = mdcID;
1040  }
1041  }
1042 
1043  if(INJ.fill_in(NET,injID)) { // get inj parameters
1044 
1045  wavearray<double>** pwfINJ = new wavearray<double>*[nIFO];
1046 
1047  // extract whitened injected & reconstructed waveforms
1048  for(int n=0; n<nIFO; n++) {
1049 
1050  detector* pd = NET->getifo(n);
1051 
1052  pwfINJ[n] = INJ.pwf[n];
1053  if (pwfINJ[n]==NULL) {
1054  cout << "CWB_Plugin_Boostrap.C : Error : Injected waveform not saved !!! : detector "
1055  << NET->ifoName[n] << endl;
1056  continue;
1057  }
1058 
1059  double rFactor = 1.;
1060  rFactor *= factor>0 ? factor : 1;
1061  wavearray<double>* wf = pwfINJ[n];
1062  *wf*=rFactor; // injected wf is multiplied by the custom factor
1063  xINJ.push_back(*wf);
1064  *wf*=1./rFactor; // restore injected amplitude
1065  }
1066  delete [] pwfINJ;
1067  }
1068 
1069  return xINJ;
1070 }
1071 
1072 std::vector<wavearray<double> > GetRecWaveform(network* NET, netevent* EVT, int ID) {
1073 
1074  std::vector<wavearray<double> > xREC; // reconstructed
1075 
1076  int nIFO = NET->ifoListSize(); // number of detectors
1077 
1078  wavearray<double>** pwfREC = new wavearray<double>*[nIFO];
1079  for(int n=0; n<nIFO; n++) {
1080 
1081  detector* pd = NET->getifo(n);
1082  int idSize = pd->RWFID.size();
1083  int wfIndex=-1;
1084  for(int mm=0; mm<idSize; mm++) if (pd->RWFID[mm]==ID) wfIndex=mm;
1085 
1086  if(wfIndex<0) {
1087  cout << "CWB_Plugin_Boostrap.C : Error : Reconstructed waveform not saved !!! : ID -> "
1088  << ID << " : detector " << NET->ifoName[n] << endl;
1089  continue;
1090  }
1091  if(wfIndex>=0) pwfREC[n] = pd->RWFP[wfIndex];
1092 
1093  wavearray<double>* wf = pwfREC[n];
1094  xREC.push_back(*wf);
1095  }
1096  delete [] pwfREC;
1097 
1098  return xREC;
1099 }
1100 
1101 std::vector<wavearray<double> > GetWaveform(network* NET, int lag, int id, char type, bool shift) {
1102 
1103  if(type!='S' && type!='s' && type!='W' && type!='w' && type!='N' && type!='n') {
1104  cout << "GetWaveform : not valid type : Abort" << endl; exit(1);
1105  }
1106 
1107  std::vector<wavearray<double> > vWAV; // reconstructed
1108 
1109  int nIFO = NET->ifoListSize(); // number of detectors
1110  netcluster* pwc = NET->getwc(lag);
1111 
1112  if(type=='S' || type=='s') {
1113  NET->getMRAwave(id,lag,'S',0,shift); // reconstruct whitened shifted pd->waveForm
1114  detector* pd;
1115  for(int i=0; i<nIFO; i++) { // loop over detectors
1116  pd = NET->getifo(i);
1117  wavearray<double>* wf = &pd->waveForm;
1118  wf->start(pwc->start+pd->waveForm.start());
1119  vWAV.push_back(*wf);
1120  }
1121  }
1122 
1123  if(type=='W' || type=='w') {
1124  NET->getMRAwave(id,lag,type,0,shift); // reconstruct+noise whitened shifted pd->waveBand
1125  detector* pd;
1126  for(int i=0; i<nIFO; i++) { // loop over detectors
1127  pd = NET->getifo(i);
1128  wavearray<double>* wf = &pd->waveBand;
1129  wf->start(pwc->start+pd->waveBand.start());
1130  vWAV.push_back(*wf);
1131  }
1132  }
1133 
1134  if(type=='N' || type=='n') {
1135  NET->getMRAwave(id,lag,'W',0,shift); // reconstruct+noise whitened shifted pd->waveBand
1136  NET->getMRAwave(id,lag,'S',0,shift); // reconstruct whitened shifted pd->waveForm
1137  detector* pd;
1138  for(int i=0; i<nIFO; i++) { // loop over detectors
1139  pd = NET->getifo(i);
1140  pd->waveNull = pd->waveBand;
1141  pd->waveNull-= pd->waveForm;
1142  wavearray<double>* wf = &pd->waveNull;
1143  wf->start(pwc->start+pd->waveNull.start());
1144  vWAV.push_back(*wf);
1145  }
1146  }
1147 
1148  return vWAV;
1149 }
1150 
1151 std::vector<wavearray<double> > GetSigWaveform(network* NET, CWB::config* cfg, int lag, int id) {
1152 // get injected waveform on TF sub-space of the reconstructed waveform vREC
1153 
1154  std::vector<wavearray<double> > vSIG; // reconstructed
1155 
1156  int nIFO = NET->ifoListSize(); // number of detectors
1157  netcluster* pwc = NET->getwc(lag);
1158 
1159  std::vector<int> pI = NET->wdmMRA.getXTalk(pwc, id, false); // buffer for pixel IDs
1160 
1161  netpixel* pix = pwc->getPixel(id,pI[0]);
1162 
1163  int tsize=1;
1164 
1165  int V = pI.size();
1166  if(!V) return vSIG;
1167  int V4 = V + (V%4 ? 4 - V%4 : 0);
1168  int V44 = V4 + 4;
1169 
1170  float En = 2*NET->acor*NET->acor*nIFO; // network energy threshold in the sky loop
1171 
1172  float *pd[NIFO], *pD[NIFO];
1173  float *v00[NIFO],*v90[NIFO];
1174  float *pa[NIFO], *pA[NIFO];
1175 
1176  float* ptmp;
1177  int i,j;
1178 
1179  std::vector<float*> _DAT; // vectors for packet amplitudes
1180  std::vector<float*> _vtd; // vectors of TD amplitudes
1181  std::vector<float*> _vTD; // vectors of TD amplitudes
1182 
1183  if(_DAT.size()) _avx_free_ps(_DAT); // container for data packet amplitudes
1184  if(_vtd.size()) _avx_free_ps(_vtd); // array for 00 amplitudes
1185  if(_vTD.size()) _avx_free_ps(_vTD); // array for 90 amplitudes
1186  for(i=0; i<NIFO; i++) {
1187  ptmp = (float*)_mm_malloc((V4*3+8)*sizeof(float),32);
1188  for(j=0; j<(V4*3+8); j++) ptmp[j]=0; _DAT.push_back(ptmp); // concatenated arrays {amp}{AMP}{norm}{n,N,c,s}
1189  ptmp = (float*)_mm_malloc(tsize*V4*sizeof(float),32);
1190  for(j=0; j<tsize*V4; j++) ptmp[j]=0; _vtd.push_back(ptmp); // array of aligned vectors
1191  ptmp = (float*)_mm_malloc(tsize*V4*sizeof(float),32);
1192  for(j=0; j<tsize*V4; j++) ptmp[j]=0; _vTD.push_back(ptmp); // array of aligned vectors
1193  }
1194 
1195  std::vector<float*> _AVX; // vectors for network pixel statistics
1196  if(_AVX.size()) _avx_free_ps(_AVX);
1197  float* p_et = (float*)_mm_malloc(V4*sizeof(float),32); // 0
1198  for(j=0; j<V4; j++) p_et[j]=0; _AVX.push_back(p_et);
1199  float* pMSK = (float*)_mm_malloc(V44*sizeof(float),32); // 1 - pixel mask
1200  for(j=0; j<V44; j++) pMSK[j]=0; _AVX.push_back(pMSK); pMSK[V4]=nIFO;
1201  float* p_fp = (float*)_mm_malloc(V44*sizeof(float),32); // 2- |f+|^2 (0:V4), +norm (V4:V4+4)
1202  for(j=0; j<V44; j++) p_fp[j]=0; _AVX.push_back(p_fp);
1203  float* p_fx = (float*)_mm_malloc(V44*sizeof(float),32); // 3- |fx|^2 (0:V4), xnorm (V4:V4+4)
1204  for(j=0; j<V44; j++) p_fx[j]=0; _AVX.push_back(p_fx);
1205  float* p_si = (float*)_mm_malloc(V4*sizeof(float),32); // 4
1206  for(j=0; j<V4; j++) p_si[j]=0; _AVX.push_back(p_si);
1207  float* p_co = (float*)_mm_malloc(V4*sizeof(float),32); // 5
1208  for(j=0; j<V4; j++) p_co[j]=0; _AVX.push_back(p_co);
1209  float* p_uu = (float*)_mm_malloc((V4+16)*sizeof(float),32); // 6 - 00+ unit vector(0:V4), norm(V4), cos(V4+4)
1210  for(j=0; j<V4+16; j++) p_uu[j]=0; _AVX.push_back(p_uu);
1211  float* p_UU = (float*)_mm_malloc((V4+16)*sizeof(float),32); // 7 - 90+ unit vector(0:V4), norm(V4), sin(V4+4)
1212  for(j=0; j<V4+16; j++) p_UU[j]=0; _AVX.push_back(p_UU);
1213  float* p_vv = (float*)_mm_malloc((V4+16)*sizeof(float),32); // 8- 00x unit vector(0:V4), norm(V4), cos(V4+4)
1214  for(j=0; j<V4+16; j++) p_vv[j]=0; _AVX.push_back(p_vv);
1215  float* p_VV = (float*)_mm_malloc((V4+16)*sizeof(float),32); // 9- 90x unit vector(0:V4), norm(V4), sin(V4+4)
1216  for(j=0; j<V4+16; j++) p_VV[j]=0; _AVX.push_back(p_VV);
1217  float* p_au = (float*)_mm_malloc(V4*sizeof(float),32); // 10
1218  for(j=0; j<V4; j++) p_au[j]=0; _AVX.push_back(p_au);
1219  float* p_AU = (float*)_mm_malloc(V4*sizeof(float),32); // 11
1220  for(j=0; j<V4; j++) p_AU[j]=0; _AVX.push_back(p_AU);
1221  float* p_av = (float*)_mm_malloc(V4*sizeof(float),32); // 12
1222  for(j=0; j<V4; j++) p_av[j]=0; _AVX.push_back(p_av);
1223  float* p_AV = (float*)_mm_malloc(V4*sizeof(float),32); // 13
1224  for(j=0; j<V4; j++) p_AV[j]=0; _AVX.push_back(p_AV);
1225  float* p_uv = (float*)_mm_malloc(V4*4*sizeof(float),32); // 14 special array for GW norm calculation
1226  for(j=0; j<V4*4; j++) p_uv[j]=0; _AVX.push_back(p_uv);
1227  float* p_ee = (float*)_mm_malloc(V4*sizeof(float),32); // 15 + energy array
1228  for(j=0; j<V4; j++) p_ee[j]=0; _AVX.push_back(p_ee);
1229  float* p_EE = (float*)_mm_malloc(V4*sizeof(float),32); // 16 x energy array
1230  for(j=0; j<V4; j++) p_EE[j]=0; _AVX.push_back(p_EE);
1231  float* pTMP=(float*)_mm_malloc(V4*4*NIFO*sizeof(float),32); // 17 temporary array for _avx_norm_ps()
1232  for(j=0; j<V4*4*NIFO; j++) pTMP[j]=0; _AVX.push_back(pTMP);
1233  float* p_ni = (float*)_mm_malloc(V4*sizeof(float),32); // 18 + network index
1234  for(j=0; j<V4; j++) p_ni[j]=0; _AVX.push_back(p_ni);
1235  float* p_ec = (float*)_mm_malloc(V4*sizeof(float),32); // 19 + coherent energy
1236  for(j=0; j<V4; j++) p_ec[j]=0; _AVX.push_back(p_ec);
1237  float* p_gn = (float*)_mm_malloc(V4*sizeof(float),32); // 20 + Gaussian noise correction
1238  for(j=0; j<V4; j++) p_gn[j]=0; _AVX.push_back(p_gn);
1239  float* p_ed = (float*)_mm_malloc(V4*sizeof(float),32); // 21 + energy disbalance
1240  for(j=0; j<V4; j++) p_ed[j]=0; _AVX.push_back(p_ed);
1241  float* p_rn = (float*)_mm_malloc(V4*sizeof(float),32); // 22 + sattelite noise in TF domain
1242  for(j=0; j<V4; j++) p_rn[j]=0; _AVX.push_back(p_rn);
1243 
1244  double R = NET->getifo(0)->TFmap.rate();
1245  for(int j=0; j<V; j++) {
1246  netpixel* pix = pwc->getPixel(id,pI[j]);
1247  if(!pix->core) continue; // select only core pixels
1248  for(int n=0; n<nIFO; n++) {
1249  int index = pix->data[n].index;
1250  int ires = int(TMath::Log2(R/pix->rate))-cfg->l_low;
1251  double aa = GetSparseMapData(&jSS[n][ires], true, index);
1252  double AA = GetSparseMapData(&jSS[n][ires], false , index);
1253  //aa = GetSparseMapData(&rSS[n][ires], true, index);
1254  //AA = GetSparseMapData(&rSS[n][ires], false , index);
1255  _vtd[n][j] = aa; // copy 00 data
1256  _vTD[n][j] = AA; // copy 90 data
1257  }
1258  }
1259 
1260  for(int i=0; i<NIFO; i++) { // set up zero delay and packet pointers
1261  pd[i] = _DAT[i];
1262  pD[i] = _DAT[i]+V4;
1263  pa[i] = _vtd[i];
1264  pA[i] = _vTD[i];
1265  v00[i] = pa[i];
1266  v90[i] = pA[i];
1267  }
1268 
1269  En=0.0001;
1270  int M;
1271  double Eo=0;
1272  wavearray<float> D_snr;
1273  Eo = _avx_loadata_ps(v00,v90,pd,pD,En,_AVX,V4); // calculate data stats and store in _AVX
1274  Eo = _avx_packet_ps(pd,pD,_AVX,V4); // get data packet
1275  D_snr = NET->_avx_norm_ps(pd,pD,_AVX,V4); // data packet energy snr
1276  M = _avx_setAMP_ps(pd,pD,_AVX,V4); // set data packet amplitudes for data
1277 
1278  for(int j=0; j<V; j++) { // loop over principle components
1279  pix = pwc->getPixel(id,pI[j]);
1280  pix->likelihood = (pMSK[j]>0) ? (p_ee[j]+p_EE[j])/2 : 0; // total pixel energy
1281  if(pMSK[j]>0) pix->core = true;
1282  //pix->core = true;
1283  for(int i=0; i<nIFO; i++) {
1284  pix->setdata(double(pd[i][j]),'S',i); // 00 whitened
1285  pix->setdata(double(pD[i][j]),'P',i); // 90 whitened
1286  }
1287  }
1288  vSIG = GetWaveform(NET, lag, id, 'S', false); // get reconstructed+noise waveform
1289 
1290 #ifdef SAVE_REDUCED_INJ
1291  for(int i=0; i<nIFO; i++) {
1292  char title[256];
1293  char ofname[256];
1294  sprintf(title,"%s (TIME) : vREC(red) - vSIG(blue)",NET->ifoName[i]);
1295  sprintf(ofname,"%s_vREC_vSIG_time_id_%d.%s",NET->ifoName[i],id,"root");
1296  PlotWaveform(ofname, title, cfg,&vREC[i], &vSIG[i], NULL, NULL, false); // time
1297  sprintf(title,"%s (TIME) : vINJ(red) - vSIG(blue)",NET->ifoName[i]);
1298  sprintf(ofname,"%s_vINJ_vSIG_time_id_%d.%s",NET->ifoName[i],id,"root");
1299  PlotWaveform(ofname, title, cfg,&vINJ[i], &vSIG[i], NULL, NULL, false); // time
1300  }
1301 #endif
1302 
1303  if(_AVX.size()) _avx_free_ps(_AVX);
1304  if(_DAT.size()) _avx_free_ps(_DAT); // container for data packet amplitudes
1305  if(_vtd.size()) _avx_free_ps(_vtd); // array for 00 amplitudes
1306  if(_vTD.size()) _avx_free_ps(_vTD); // array for 90 amplitudes
1307 
1308  return vSIG;
1309 }
1310 
1312 
1313  gPE.ff[0]=0; gPE.ff[1]=0;
1314  gPE.of[0]=0; gPE.of[1]=0;
1315 
1316  int size = iSNR[0].size();
1317  if(size==0) return;
1318 
1319  for(int i=0;i<size;i++) {
1320  double isnr=0; for(int n=0;n<nIFO;n++) isnr+= iSNR[n][i];
1321  double osnr=0; for(int n=0;n<nIFO;n++) osnr+= oSNR[n][i];
1322  double iosnr=0; for(int n=0;n<nIFO;n++) iosnr+=ioSNR[n][i];
1323  double ff = iosnr/sqrt(isnr*isnr); // fitting factor
1324  double of = iosnr/sqrt(isnr*osnr); // overlap factor
1325 
1326  gPE.ff[0] += ff;
1327  gPE.ff[1] += pow(ff,2);
1328 
1329  gPE.of[0] += of;
1330  gPE.of[1] += pow(of,2);
1331  }
1332 
1333  gPE.ff[0] /= size;
1334  gPE.ff[1] = sqrt(gPE.ff[1]/size-gPE.ff[0]*gPE.ff[0]);
1335 
1336  gPE.of[0] /= size;
1337  gPE.of[1] = sqrt(gPE.of[1]/size-gPE.of[0]*gPE.of[0]);
1338 }
1339 
1340 void GetChirpMassStatistic(std::vector<double>* vCHIRP) {
1341 
1342  gPE.mch[0]=0;
1343  gPE.mch[1]=0;
1344 
1345  int size = vCHIRP[1].size();
1346  if(size==0) return;
1347 
1348  for(int i=0;i<size;i++) {
1349  gPE.mch[0] += vCHIRP[1][i];
1350  gPE.mch[1] += pow(vCHIRP[1][i],2);
1351  }
1352 
1353  gPE.mch[0] /= size;
1354  gPE.mch[1] = sqrt(gPE.mch[1]/size-gPE.mch[0]*gPE.mch[0]);
1355 }
1356 
1358 
1359  gPE.snet[0]=0;
1360  gPE.snet[1]=0;
1361 
1362  int size = iSNR[0].size();
1363  if(size==0) return;
1364 
1365  for(int i=0;i<size;i++) {
1366  double osnr=0;
1367  for(int n=0;n<nIFO;n++) osnr+=oSNR[n][i];
1368  gPE.snet[0] += sqrt(osnr);
1369  gPE.snet[1] += osnr;
1370  }
1371 
1372  gPE.snet[0] /= size;
1373  gPE.snet[1] = sqrt(gPE.snet[1]/size-gPE.snet[0]*gPE.snet[0]);
1374 }
1375 
1376 void GetNullPixels(std::vector<double>* aNUL, std::vector<double>* ANUL,
1377  network* NET, CWB::config* cfg, int lag, int id) {
1378 // get null pixels in TF domain
1379 // we use delayed vSS amplitudes and the reconstructed TF pixels save in the NET->a_00,NET->a_90 arrays
1380 
1381  size_t nIFO = NET->ifoList.size();
1382 
1383  netcluster* pwc = NET->getwc(lag);
1384 
1385  // the TD amplitudes are cleaned by the likelihoodWP function, must be computed again
1386  int sCuts = pwc->sCuts[id-1]; // save cluster status
1387  pwc->sCuts[id-1] = 0; // cluster must be enabled (mark as done by likelihoodWP)
1388  pwc->setcore(false,id);
1389  pwc->loadTDampSSE(*NET, 'a', cfg->BATCH, cfg->BATCH); // attach TD amp to pixels
1390 
1391  std::vector<int> pI = NET->wdmMRA.getXTalk(pwc, id, true); // buffer for pixel IDs
1392  int V = pI.size();
1393 
1394  netpixel* pix = pwc->getPixel(id,pI[0]);
1395  int tsize = pix->tdAmp[0].size();
1396  if(!tsize || tsize&1) { // tsize%1 = 1/0 = power/amplitude
1397  cout<<"GetNullPixels error: wrong pixel TD data\n";
1398  exit(1);
1399  }
1400  tsize /= 2;
1401  cout << "tsize :" << tsize << endl;
1402  int V4 = V + (V%4 ? 4 - V%4 : 0);
1403  std::vector<int>* vtof = &(pwc->nTofF[id-1]);
1404 
1405  for(int n=0; n<2*7*nIFO; n++) gPE.nstat[n]=0;
1406 
1407  int cnt[NIFO_MAX];
1408  for(int m=0; m<nIFO; m++) cnt[m]=0;
1409 
1410  float* a_00 = NET->a_00.data; // set pointer to 00 array of reconstructed signal
1411  float* a_90 = NET->a_90.data; // set pointer to 90 array of reconstructed signal
1412 
1413  double R = NET->getifo(0)->TFmap.rate();
1414  for(int j=0; j<V; j++) {
1415  netpixel* pix = pwc->getPixel(id,pI[j]);
1416  //if(!pix->core) continue; // select only core pixels
1417  float ee=0;
1418  for(int m=0; m<nIFO; m++) {
1419  double ss = a_00[j*NIFO+m];
1420  double SS = a_90[j*NIFO+m];
1421  ee += pow(ss,2)+pow(SS,2);
1422  }
1423  if(ee==0) continue; // only core pixels are selected
1424  for(int m=0; m<nIFO; m++) {
1425  int index = pix->data[m].index;
1426  int ires = int(TMath::Log2(R/pix->rate))-cfg->l_low;
1427  // get original sparse map amplitudes
1428  //double dd = GetSparseMapData(&vSS[m][ires], true, index);
1429  //double DD = GetSparseMapData(&vSS[m][ires], false , index);
1430  //double dd = GetSparseMapData(&dSS[m][ires], true, index);
1431  //double DD = GetSparseMapData(&dSS[m][ires], false , index);
1432 
1433  // get shifted data (signal+noise) amplitudes
1434  int l = (*vtof)[m]+tsize/2;
1435  double dd = pix->tdAmp[m].data[l]; // copy TD 00 data
1436  double DD = pix->tdAmp[m].data[l+tsize]; // copy TD 90 data
1437 
1438  //double ss = GetSparseMapData(&rSS[m][ires], true, index);
1439  //double SS = GetSparseMapData(&rSS[m][ires], false , index);
1440  // get reconstructed amplitudes (shifted)
1441  double ss = a_00[j*NIFO+m];
1442  double SS = a_90[j*NIFO+m];
1443 
1444  // 00 phase
1445  aNUL[m].push_back(dd-ss);
1446 
1447  // 90 phase
1448  ANUL[m].push_back(DD-SS);
1449 
1450  cnt[m]++;
1451  }
1452  }
1453 
1454  pwc->sCuts[id-1] = sCuts; // restore cluster status
1455  pwc->clean(id); // cean TD ammplitudes
1456 
1457  return;
1458 }
1459 
1461 
1462  int layer = SS->GetLayer(index);
1463  int start = SS->sparseLookup[layer]; // sparse table layer offset
1464  int end = SS->sparseLookup[layer+1]-1; // sparse table layer+1 offset
1465 
1466  int i = SS->binarySearch(SS->sparseIndex.data,start,end,index);
1467 
1468  if(i<0) return 0;
1469 
1470  return phase ? SS->sparseMap00[i] : SS->sparseMap90[i];
1471 }
1472 
1475  bool fft, TString pdir, double P, EColor col1, EColor col2, EColor col3) {
1476 
1477  watplot PTS(const_cast<char*>("ptspe"),200,20,800,500);
1478 
1479  //cout << "Print " << ofname << endl;
1480  double tmin=1.e20;
1481  if(wref==NULL) return;
1482  if(wf1==NULL) return;
1483  else tmin=wf1->start();
1484  if(wf2!=NULL) if(wf2->start()<tmin) tmin=wf2->start();
1485  if(wf3!=NULL) if(wf3->start()<tmin) tmin=wf3->start();
1486 
1487  tmin=gSEGGPS;
1488 
1489  wf1->start(wf1->start()-tmin);
1490  if(wf2!=NULL) if(wf2!=wf1) wf2->start(wf2->start()-tmin);
1491  if(wf3!=NULL) if(wf3!=wf1 && wf3!=wf2) wf3->start(wf3->start()-tmin);
1492  if(wref!=wf1 && wref!=wf2 && wref!=wf3) wref->start(wref->start()-tmin);
1493 
1494  double bT, eT;
1495  GetTimeBoundaries(*wref, P, bT, eT);
1496 
1497  if(fft) {
1498  wavearray<double> wf=*wf1; int k=0;
1499  for(int i=0;i<wf1->size();i++) {
1500  double time=i/wf1->rate()+wf1->start();
1501  if(time>bT && time<eT) wf[k++]=wf1->data[i];
1502  }
1503  wf.resize(k);
1504  PTS.plot(&wf, const_cast<char*>("AL"), col1, 0, 0, true, cfg->fLow, cfg->fHigh);
1505  } else {
1506  PTS.plot(wf1, const_cast<char*>("AL"), col1, bT, eT);
1507  PTS.graph[0]->GetXaxis()->SetRangeUser(bT, eT);
1508  }
1509  PTS.graph[0]->SetLineWidth(1);
1510  PTS.graph[0]->SetTitle(title);
1511 
1512  TString xtitle = TString::Format("Time (sec) : GPS OFFSET = %.3f",tmin);
1513  PTS.graph[0]->GetXaxis()->SetTitle(xtitle);
1514 
1515  if(wf2!=NULL) {
1516  if(fft) {
1517  if(wf2!=NULL) {
1518  wavearray<double> wf=*wf2; int k=0;
1519  for(int i=0;i<wf2->size();i++) {
1520  double time=i/wf2->rate()+wf2->start();
1521  if(time>bT && time<eT) wf[k++]=wf2->data[i];
1522  }
1523  wf.resize(k);
1524  PTS.plot(&wf, const_cast<char*>("SAME"), col2, 0, 0, true, cfg->fLow, cfg->fHigh);
1525  }
1526  } else {
1527  if(wf2!=NULL) PTS.plot(wf2, const_cast<char*>("SAME"), col2, 0, 0);
1528  }
1529  if(wf2!=NULL) PTS.graph[1]->SetLineWidth(2);
1530  }
1531 
1532  if(wf3!=NULL) {
1533  if(fft) {
1534  if(wf3!=NULL) {
1535  wavearray<double> wf=*wf3; int k=0;
1536  for(int i=0;i<wf3->size();i++) {
1537  double time=i/wf3->rate()+wf3->start();
1538  if(time>bT && time<eT) wf[k++]=wf3->data[i];
1539  }
1540  wf.resize(k);
1541  PTS.plot(&wf, const_cast<char*>("SAME"), col3, 0, 0, true, cfg->fLow, cfg->fHigh);
1542  }
1543  } else {
1544  if(wf3!=NULL) PTS.plot(wf3, const_cast<char*>("SAME"), col3, 0, 0);
1545  }
1546  if(wf3!=NULL) PTS.graph[2]->SetLineWidth(1);
1547  }
1548 
1549  wf1->start(wf1->start()+tmin);
1550  if(wf2!=NULL) if(wf2!=wf1) wf2->start(wf2->start()+tmin);
1551  if(wf3!=NULL) if(wf3!=wf1 && wf3!=wf2) wf3->start(wf3->start()+tmin);
1552  if(wref!=wf1 && wref!=wf2 && wref!=wf3) wref->start(wref->start()+tmin);
1553 
1554  if(fft) {
1555  PTS.canvas->SetLogx();
1556  PTS.canvas->SetLogy();
1557  }
1558 
1559  if(ofname!="") {
1560  ofname = TString(pdir)+TString("/")+ofname;
1561  PTS.canvas->Print(ofname);
1562  cout << "write : " << ofname << endl;
1563  }
1564 }
1565 
1567 
1568  double R=wf1->rate();
1569 
1570  double b_wf1 = wf1->start();
1571  double e_wf1 = wf1->start()+wf1->size()/R;
1572  double b_wf2 = wf2->start();
1573  double e_wf2 = wf2->start()+wf2->size()/R;
1574 
1575  int o_wf1 = b_wf1>b_wf2 ? 0 : int((b_wf2-b_wf1)*R+0.5);
1576  int o_wf2 = b_wf1<b_wf2 ? 0 : int((b_wf1-b_wf2)*R+0.5);
1577 
1578  double startXCOR = b_wf1>b_wf2 ? b_wf1 : b_wf2;
1579  double endXCOR = e_wf1<e_wf2 ? e_wf1 : e_wf2;
1580  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
1581 
1582  double wf11=0.;
1583  double wf22=0.;
1584  double wf12=0.;
1585  for(int i=0;i<sizeXCOR;i++) wf12 += wf1->data[i+o_wf1] * wf2->data[i+o_wf2];
1586  for(int i=0;i<wf1->size();i++) wf11 += pow(wf1->data[i],2);
1587  for(int i=0;i<wf2->size();i++) wf22 += pow(wf2->data[i],2);
1588 
1589  double FF = wf12/sqrt(wf11*wf22);
1590 
1591  return FF;
1592 }
1593 
1595 
1596  double R=wf1->rate();
1597 
1598  double b_wf1 = wf1->start();
1599  double e_wf1 = wf1->start()+wf1->size()/R;
1600  double b_wf2 = wf2->start();
1601  double e_wf2 = wf2->start()+wf2->size()/R;
1602 
1603  int o_wf1 = b_wf1>b_wf2 ? 0 : int((b_wf2-b_wf1)*R+0.5);
1604  int o_wf2 = b_wf1<b_wf2 ? 0 : int((b_wf1-b_wf2)*R+0.5);
1605 
1606  double startXCOR = b_wf1>b_wf2 ? b_wf1 : b_wf2;
1607  double endXCOR = e_wf1<e_wf2 ? e_wf1 : e_wf2;
1608  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
1609 
1610  wavearray<double> wfdif(sizeXCOR);
1611  wfdif=0.;
1612  wfdif.rate(R);
1613  wfdif.start(b_wf1+double(o_wf1)/R);
1614 
1615  for(int i=0;i<sizeXCOR;i++) wfdif[i] = wf1->data[i+o_wf1] - wf2->data[i+o_wf2];
1616 
1617  return wfdif;
1618 }
1619 
1621 
1622  detector* pD = NET->getifo(ifoID);
1623 
1624  int nRES = cfg->l_high-cfg->l_low+1; // number of frequency resolution levels
1625  for(int i=0;i<nRES;i++) {
1626  // rebuild wseries from sparse table only with core pixels
1627  bool core = true;
1628  SSeries<double> ss = pD->vSS[i];
1629  ss.Expand(core);
1630  ss.Inverse();
1631 
1632  char title[256];
1633  char ofname[256];
1634  sprintf(title,"%s (TIME) : INJ(red) - SM(blue)",NET->ifoName[ifoID]);
1635  sprintf(ofname,"%s_INJ_SM_time_id_%d_res_%d.%s",NET->ifoName[ifoID],ID,i,PLOT_TYPE);
1636  PlotWaveform(ofname, title, cfg, wf, &ss, NULL, NULL, false); // time
1637  }
1638 }
1639 
1641 
1642  int n_amp_cal_err=0;
1643  int n_phs_cal_err=0;
1644  if(options.CompareTo("")!=0) {
1645  cout << options << endl;
1646  if(!options.Contains("--")) { // parameters are used only by cwb_inet
1647 
1648  TObjArray* token = TString(options).Tokenize(TString(' '));
1649  for(int j=0;j<token->GetEntries();j++){
1650 
1651  TObjString* tok = (TObjString*)token->At(j);
1652  TString stok = tok->GetString();
1653 
1654  if(stok.Contains("pe_trials=") || stok.Contains("pe_retry=")) {
1655  TString pe_trials=stok;
1656  pe_trials.Remove(0,pe_trials.Last('=')+1);
1657  if(pe_trials.IsDigit()) gOPT.trials=pe_trials.Atoi();
1658  if(gOPT.trials>MAX_TRIALS) {
1659  cout << "ReadUserOptions Error : trials must be <= MAX_TRIALS : " << MAX_TRIALS << endl;exit(1);
1660  }
1661  }
1662 
1663  if(stok.Contains("pe_ced_dump=")) {
1664  TString pe_ced_dump=stok;
1665  pe_ced_dump.Remove(0,pe_ced_dump.Last('=')+1);
1666  if(pe_ced_dump.IsDigit()) gOPT.ced_dump=pe_ced_dump.Atoi();
1667  }
1668 
1669  if(stok.Contains("pe_ced_enable=")) {
1670  TString pe_ced_enable=stok;
1671  pe_ced_enable.Remove(0,pe_ced_enable.Last('=')+1);
1672  if(pe_ced_enable=="tfmap") gOPT.ced_tfmap = true;
1673  if(pe_ced_enable=="rdr") gOPT.ced_rdr = true;
1674  if(pe_ced_enable=="psd") gOPT.ced_psd = true;
1675  if(pe_ced_enable=="skymap") gOPT.ced_skymap = true;
1676  if(pe_ced_enable=="rec") gOPT.ced_rec = true;
1677  if(pe_ced_enable=="inj") gOPT.ced_inj = true;
1678  if(pe_ced_enable=="rinj") gOPT.ced_rinj = true;
1679  if(pe_ced_enable=="cm") gOPT.ced_cm = true;
1680  if(pe_ced_enable=="distr") gOPT.ced_distr = true;
1681  if(pe_ced_enable=="null") gOPT.ced_null = true;
1682  if(pe_ced_enable=="pca") gOPT.ced_pca = true;
1683  }
1684 
1685  if(stok.Contains("pe_ced_disable=")) {
1686  TString pe_ced_disable=stok;
1687  pe_ced_disable.Remove(0,pe_ced_disable.Last('=')+1);
1688  if(pe_ced_disable=="tfmap") gOPT.ced_tfmap = false;
1689  if(pe_ced_disable=="rdr") gOPT.ced_rdr = false;
1690  if(pe_ced_disable=="psd") gOPT.ced_psd = false;
1691  if(pe_ced_disable=="skymap") gOPT.ced_skymap = false;
1692  if(pe_ced_disable=="rec") gOPT.ced_rec = false;
1693  if(pe_ced_disable=="inj") gOPT.ced_inj = false;
1694  if(pe_ced_disable=="rinj") gOPT.ced_rinj = false;
1695  if(pe_ced_disable=="cm") gOPT.ced_cm = false;
1696  if(pe_ced_disable=="distr") gOPT.ced_distr = false;
1697  if(pe_ced_disable=="null") gOPT.ced_null = false;
1698  if(pe_ced_disable=="pca") gOPT.ced_pca = false;
1699  }
1700 
1701  if(stok.Contains("pe_seed=")) {
1702  TString pe_seed=stok;
1703  pe_seed.Remove(0,pe_seed.Last('=')+1);
1704  if(pe_seed.IsDigit()) gOPT.seed=pe_seed.Atoi();
1705  }
1706 
1707  if(stok.Contains("pe_gps=")) {
1708  TString pe_gps=stok;
1709  pe_gps.Remove(0,pe_gps.Last('=')+1);
1710  if(pe_gps.IsFloat()) gOPT.gps=pe_gps.Atof();
1711  }
1712 
1713  if(stok.Contains("pe_amp_cal_err=")) {
1714  TString pe_amp_cal_err=stok;
1715  pe_amp_cal_err.Remove(0,pe_amp_cal_err.Last('=')+1);
1716  if(pe_amp_cal_err.IsFloat()) gOPT.amp_cal_err[n_amp_cal_err]=pe_amp_cal_err.Atof();
1717  if(n_amp_cal_err<(NIFO_MAX-1)) n_amp_cal_err++;
1718  }
1719 
1720  if(stok.Contains("pe_phs_cal_err=")) {
1721  TString pe_phs_cal_err=stok;
1722  pe_phs_cal_err.Remove(0,pe_phs_cal_err.Last('=')+1);
1723  if(pe_phs_cal_err.IsFloat()) gOPT.phs_cal_err[n_phs_cal_err]=pe_phs_cal_err.Atof();
1724  if(n_phs_cal_err<(NIFO_MAX-1)) n_phs_cal_err++;
1725  }
1726 
1727  if(stok.Contains("pe_skymask=")) {
1728  TString pe_skymask=stok;
1729  pe_skymask.Remove(0,pe_skymask.Last('=')+1);
1730  if(pe_skymask=="false") gOPT.skymask=0;
1731  if(pe_skymask=="true") gOPT.skymask=1;
1732  if(pe_skymask.IsDigit()) gOPT.skymask=pe_skymask.Atoi();
1733  }
1734 
1735  if(stok.Contains("pe_signal=")) {
1736  TString pe_signal=stok;
1737  pe_signal.Remove(0,pe_signal.Last('=')+1);
1738  if(pe_signal.IsDigit()) gOPT.signal=pe_signal.Atoi();
1739  }
1740 
1741  if(stok.Contains("pe_noise=")) {
1742  TString pe_noise=stok;
1743  pe_noise.Remove(0,pe_noise.Last('=')+1);
1744  if(pe_noise=="false") gOPT.noise=0;
1745  if(pe_noise=="true") gOPT.noise=1;
1746  if(pe_noise.IsDigit()) gOPT.noise=pe_noise.Atoi();
1747  }
1748 
1749  if(stok.Contains("pe_multitask=")) {
1750  TString pe_multitask=stok;
1751  pe_multitask.Remove(0,pe_multitask.Last('=')+1);
1752  if(pe_multitask=="true") gOPT.multitask=true;
1753  if(pe_multitask=="false") gOPT.multitask=false;
1754  }
1755 
1756  if(stok.Contains("pe_output_enable=")) {
1757  TString pe_output_enable=stok;
1758  pe_output_enable.Remove(0,pe_output_enable.Last('=')+1);
1759  if(pe_output_enable=="inj") gOPT.output_inj=true;
1760  if(pe_output_enable=="rec") gOPT.output_rec=true;
1761  if(pe_output_enable=="wht") gOPT.output_wht=true;
1762  if(pe_output_enable=="dat") gOPT.output_dat=true;
1763  if(pe_output_enable=="med") gOPT.output_med=true;
1764  if(pe_output_enable=="p50") gOPT.output_p50=true;
1765  if(pe_output_enable=="p90") gOPT.output_p90=true;
1766  if(pe_output_enable=="avr") gOPT.output_avr=true;
1767  if(pe_output_enable=="rms") gOPT.output_rms=true;
1768  }
1769 
1770  if(stok.Contains("pe_output_disable=")) {
1771  TString pe_output_disable=stok;
1772  pe_output_disable.Remove(0,pe_output_disable.Last('=')+1);
1773  if(pe_output_disable=="inj") gOPT.output_inj=false;
1774  if(pe_output_disable=="rec") gOPT.output_rec=false;
1775  if(pe_output_disable=="wht") gOPT.output_wht=false;
1776  if(pe_output_disable=="dat") gOPT.output_dat=false;
1777  if(pe_output_disable=="med") gOPT.output_med=false;
1778  if(pe_output_disable=="p50") gOPT.output_p50=false;
1779  if(pe_output_disable=="p90") gOPT.output_p90=false;
1780  if(pe_output_disable=="avr") gOPT.output_avr=false;
1781  if(pe_output_disable=="rms") gOPT.output_rms=false;
1782  }
1783 
1784  }
1785  }
1786  }
1787 }
1788 
1790 
1791  cout << "-----------------------------------------" << endl;
1792  cout << "PE config options " << endl;
1793  cout << "-----------------------------------------" << endl << endl;
1794  cout << "PE_TRIALS " << gOPT.trials << endl;
1795  cout << "PE_SIGNAL " << gOPT.signal << endl;
1796  cout << "PE_NOISE " << gOPT.noise << endl;
1797  for(int n=0;n<cfg->nIFO;n++) {
1798  cout << "PE_AMP_CAL_ERR " << cfg->ifo[n] << " " << gOPT.amp_cal_err[n] << endl;
1799  cout << "PE_PHS_CAL_ERR " << cfg->ifo[n] << " " << gOPT.phs_cal_err[n] << endl;
1800  }
1801  cout << "PE_SKYMASK " << gOPT.skymask << endl;
1802  cout << "PE_SEED " << gOPT.seed << endl;
1803  cout.precision(14);
1804  cout << "PE_GPS " << gOPT.gps << endl;
1805  cout.precision(6);
1806 
1807  cout << "PE_MULTITASK " << gOPT.multitask << endl;
1808 
1809  cout << "PE_CED_DUMP " << gOPT.ced_dump << endl;
1810 
1811  cout << "PE_CED_TFMAP " << gOPT.ced_tfmap << endl;
1812  cout << "PE_CED_RDR " << gOPT.ced_rdr << endl;
1813  cout << "PE_CED_PSD " << gOPT.ced_psd << endl;
1814  cout << "PE_CED_SKYMAP " << gOPT.ced_skymap << endl;
1815  cout << "PE_CED_REC " << gOPT.ced_rec << endl;
1816  cout << "PE_CED_INJ " << gOPT.ced_inj << endl;
1817  cout << "PE_CED_rINJ " << gOPT.ced_rinj << endl;
1818  cout << "PE_CED_CM " << gOPT.ced_cm << endl;
1819  cout << "PE_CED_DISTR " << gOPT.ced_distr << endl;
1820  cout << "PE_CED_NULL " << gOPT.ced_null << endl;
1821  cout << "PE_CED_PCA " << gOPT.ced_pca << endl;
1822 
1823  cout << "PE_OUTPUT_INJ " << gOPT.output_inj << endl;
1824  cout << "PE_OUTPUT_REC " << gOPT.output_rec << endl;
1825  cout << "PE_OUTPUT_WHT " << gOPT.output_wht << endl;
1826  cout << "PE_OUTPUT_DAT " << gOPT.output_dat << endl;
1827  cout << "PE_OUTPUT_MED " << gOPT.output_med << endl;
1828  cout << "PE_OUTPUT_P50 " << gOPT.output_p50 << endl;
1829  cout << "PE_OUTPUT_P90 " << gOPT.output_p90 << endl;
1830  cout << "PE_OUTPUT_AVR " << gOPT.output_avr << endl;
1831  cout << "PE_OUTPUT_RMS " << gOPT.output_rms << endl;
1832 
1833  cout << endl;
1834 }
1835 
1837 
1838  TString ofName = odir+"/pe_config.txt";
1839 
1840  ofstream out;
1841  out.open(ofName,ios::out);
1842  if(!out.good()) {cout << "DumpUserOptions : Error Opening File : " << ofName << endl;exit(1);}
1843 
1844  TString info="";
1845  TString tabs="\t\t\t\t";
1846 
1847  char version[128];
1848  sprintf(version,"WAT Version : %s - SVN Revision : %s - Tag/Branch : %s",watversion('f'),watversion('r'),watversion('b'));
1849 
1850  out << endl;
1851  out << "--------------------------------" << endl;
1852  out << "PE version " << endl;
1853  out << "--------------------------------" << endl;
1854  out << endl;
1855  out << version << endl;
1856  out << endl;
1857 
1858  out << "--------------------------------" << endl;
1859  out << "PE config options " << endl;
1860  out << "--------------------------------" << endl;
1861  out << endl;
1862 
1863  out << "pe_trials " << gOPT.trials << endl;
1864  info = "// number of trials (def=100)";
1865  out << tabs << info << endl;
1866 
1867  out << "pe_signal " << gOPT.signal << endl;
1868  info = "// signal used for trials : 0(def)/1/2";
1869  out << tabs << info << endl;
1870  info = "// 0 - reconstructed waveform";
1871  out << tabs << info << endl;
1872  info = "// 1 - injected waveform (available only in simulation mode)";
1873  out << tabs << info << endl;
1874  info = "// 2 - original waveform = (reconstructed+null)";
1875  out << tabs << info << endl;
1876 
1877  out << "pe_noise " << gOPT.noise << endl;
1878  info = "// noise used for trials : 0/1(def)/2 ";
1879  out << tabs << info << endl;
1880  info = "// 0 - waveform is injected in the whitened HoT and apply Coherent+SuperCluster+Likelihood stages";
1881  out << tabs << info << endl;
1882  info = "// 1 - add gaussian noise to likelihood sparse maps and apply Likelihood stage";
1883  out << tabs << info << endl;
1884  info = "// 2 - add whitened HoT to likelihood sparse maps and apply Likelihood stage";
1885  out << tabs << info << endl;
1886 
1887  for(int n=0;n<cfg->nIFO;n++) {
1888  out << "pe_amp_cal_err " << cfg->ifo[n] << " " << gOPT.amp_cal_err[n] << endl;
1889  }
1890  info = "// max percentage of amplitude miscalibration : def(0) -> disabled";
1891  out << tabs << info << endl;
1892  info = "// if>0 -> uniform in [1-pe_amp_cal_err,1+pe_amp_cal_err] else gaus(1,pe_amp_cal_err)";
1893  out << tabs << info << endl;
1894 
1895  for(int n=0;n<cfg->nIFO;n++) {
1896  out << "pe_phs_cal_err " << cfg->ifo[n] << " " << gOPT.phs_cal_err[n] << endl;
1897  }
1898  info = "// max phase (degrees) miscalibration : def(0) -> disabled";
1899  out << tabs << info << endl;
1900  info = "// if>0 -> uniform in [-pe_phs_cal_err,+pe_phs_cal_err] else gaus(pe_phs_cal_err)";
1901  out << tabs << info << endl;
1902 
1903  out << "pe_multitask " << (gOPT.multitask ? "enable" : "disable") << endl;
1904  info = "// if enabled, PE trials are executed by different jobs in multitask : only simulation=0 and single event (gps>0)";
1905  out << tabs << info << endl;
1906 
1907  out << "pe_ced_dump " << gOPT.ced_dump << endl;
1908  info = "// dump CED at gLRETRY=PE_CED_DUMP (def(-1) -> disabled)";
1909  out << tabs << info << endl;
1910 
1911  out << "pe_skymask " << gOPT.skymask << endl;
1912  info = "// skymask used for trials : 0(def)/1/2/3 ";
1913  out << tabs << info << endl;
1914  info = "// 0 - disable -> search over all sky";
1915  out << tabs << info << endl;
1916  out << tabs << "// 1 - skymask with radius " << SKYMASK_RADIUS << "(deg) and source selected according the reconstructed skymap probability " << endl;
1917  info = "// 2 - skymask select only the sky position where the waveform is reconstructed (the maximum of detection statistic)";
1918  out << tabs << info << endl;
1919  info = "// 3 - skymask select only the sky position where the waveform has been injected";
1920  out << tabs << info << endl;
1921 
1922  out << "pe_seed " << gOPT.seed << endl;
1923  info = "// seed used by PE for random generation - 0(def) -> random seed";
1924  out << tabs << info << endl;
1925 
1926  out.precision(14);
1927  out << "pe_gps " << gOPT.gps << endl;
1928  info = "// if >0 only gps +/- iwindow is analyzed - 0(def) -> disabled";
1929  out << tabs << info << endl;
1930  out.precision(6);
1931 
1932  out << endl;
1933  out << "pe_ced tfmap " << (gOPT.ced_tfmap ? "enable" : "disable") << endl;
1934  info = "// tfmap - pe_ced_enable(def)/disable : Shows/Hides the Time-Frequency Maps Tab -> Spectrograms, Scalograms, TF Likelihood,Null";
1935  out << tabs << info << endl;
1936  out << "pe_ced rdr " << (gOPT.ced_rdr ? "enable" : "disable") << endl;
1937  info = "// rdr - pe_ced_enable(def)/disable : Shows/Hides Reconstructed Detector Response Tab";
1938  out << tabs << info << endl;
1939  out << "pe_ced psd " << (gOPT.ced_psd ? "enable" : "disable") << endl;
1940  info = "// psd - pe_ced_enable(def)/disable : Shows/Hides Power Spectral Density Tab";
1941  out << tabs << info << endl;
1942  out << "pe_ced skymap " << (gOPT.ced_skymap ? "enable" : "disable") << endl;
1943  info = "// skymap - pe_ced_enable(def)/disable : Shows/Hides SkyMaps Tab";
1944  out << tabs << info << endl;
1945  out << "pe_ced rec " << (gOPT.ced_rec ? "enable" : "disable") << endl;
1946  info = "// rec - pe_ced_enable(def)/disable : Shows/Hides Reconstructed Waveforms/Instantaneous-Frequency with errors Tab";
1947  out << tabs << info << endl;
1948  out << "pe_ced inj " << (gOPT.ced_inj ? "enable" : "disable") << endl;
1949  info = "// inj - pe_ced_enable(def)/disable : Showsi/Hides Injection' tab reports the comparison with the injected whitened waveform";
1950  out << tabs << info << endl;
1951  out << "pe_ced rinj " << (gOPT.ced_rinj ? "enable" : "disable") << endl;
1952  info = "// rinj - pe_ced_enable/disable(def) : Shows/Hides Injection' tab reports the comparison with the injected whitened waveform";
1953  out << tabs << info << endl;
1954  info = " in time-frequency subspace of the PointEstimated waveform";
1955  out << tabs << info << endl;
1956  out << "pe_ced cm " << (gOPT.ced_cm ? "enable" : "disable") << endl;
1957  info = "// cm - pe_ced_enable(def)/disable : Shows/Hides Chirp Mass Value/Error Distributions Tab";
1958  out << tabs << info << endl;
1959  out << "pe_ced distr " << (gOPT.ced_distr ? "enable" : "disable") << endl;
1960  info = "// distr - pe_ced_enable/disable(def) : Shows/Hides Residuals Distributions Tab";
1961  out << tabs << info << endl;
1962  out << "pe_ced null " << (gOPT.ced_null ? "enable" : "disable") << endl;
1963  info = "// null - pe_ced_enable/disable(def) : Shows/Hides Null Pixels Distributions Tab";
1964  out << tabs << info << endl;
1965  out << "pe_ced pca " << (gOPT.ced_pca ? "enable" : "disable") << endl;
1966  info = "// pca - pe_ced_enable/disable(def) : Shows/Hides PCA likelihood TF plot in the Time-Frequency Maps Tab";
1967  out << tabs << info << endl;
1968 
1969  out.close();
1970 }
1971 
1973 
1974  gOPT.trials = PE_TRIALS;
1975  gOPT.signal = PE_SIGNAL;
1976  gOPT.noise = PE_NOISE;
1977  for(int n=0;n<NIFO_MAX;n++) gOPT.amp_cal_err[n] = PE_AMP_CAL_ERR;
1978  for(int n=0;n<NIFO_MAX;n++) gOPT.phs_cal_err[n] = PE_PHS_CAL_ERR;
1979  gOPT.skymask = PE_SKYMASK;
1980  gOPT.seed = PE_SEED;
1981  gOPT.gps = PE_GPS;
1982 
1983  gOPT.multitask = PE_MULTITASK;
1984 
1985  gOPT.ced_dump = PE_CED_DUMP;
1986 
1987  gOPT.ced_tfmap = PE_CED_TFMAP;
1988  gOPT.ced_rdr = PE_CED_RDR;
1989  gOPT.ced_psd = PE_CED_PSD;
1990  gOPT.ced_skymap = PE_CED_SKYMAP;
1991  gOPT.ced_rec = PE_CED_REC;
1992  gOPT.ced_inj = PE_CED_INJ;
1993  gOPT.ced_rinj = PE_CED_rINJ;
1994  gOPT.ced_cm = PE_CED_CM;
1995  gOPT.ced_distr = PE_CED_DISTR;
1996  gOPT.ced_null = PE_CED_NULL;
1997  gOPT.ced_pca = PE_CED_PCA;
1998 
1999  gOPT.output_inj = PE_OUTPUT_INJ;
2000  gOPT.output_rec = PE_OUTPUT_REC;
2001  gOPT.output_wht = PE_OUTPUT_WHT;
2002  gOPT.output_dat = PE_OUTPUT_DAT;
2003  gOPT.output_med = PE_OUTPUT_MED;
2004  gOPT.output_p50 = PE_OUTPUT_P50;
2005  gOPT.output_p90 = PE_OUTPUT_P90;
2006  gOPT.output_avr = PE_OUTPUT_AVR;
2007  gOPT.output_rms = PE_OUTPUT_RMS;
2008 }
2009 
2010 void SetOutputFile(network* NET, netevent* &EVT, CWB::config* cfg, bool dump_pe) {
2011 
2012  // import slagShift
2013  float* gSLAGSHIFT=NULL; IMPORT(float*,gSLAGSHIFT)
2014 
2015  int nIFO = NET->ifoListSize(); // number of detectors
2016 
2017  // search output root file in the system list
2018  TFile* froot = NULL;
2019  TList *files = (TList*)gROOT->GetListOfFiles();
2020  gOUTPUT="";
2021  if (files) {
2022  TIter next(files);
2023  TSystemFile *file;
2024  TString fname;
2025  bool check=false;
2026  while ((file=(TSystemFile*)next())) {
2027  fname = file->GetName();
2028  // set output root file as the current file
2029  if(fname.Contains("wave_")) {
2030  froot=(TFile*)file;froot->cd();
2031  gOUTPUT=fname;
2032  gOUTPUT.ReplaceAll(".root.tmp",".txt");
2033  //cout << "output file name : " << fname << endl;
2034  }
2035  }
2036  if(!froot) {
2037  cout << "CWB_Plugin_Boostrap.C : Error - output root file not found" << endl;
2038  gSystem->Exit(1);
2039  }
2040  } else {
2041  cout << "CWB_Plugin_Boostrap.C : Error - output root file not found" << endl;
2042  gSystem->Exit(1);
2043  }
2044 
2045  if(dump_pe) {
2046  if(gOPT.output_inj) if(cfg->simulation) for(int n=0;n<nIFO;n++) gPE.wINJ[n] = &vINJ[n];
2047  if(gOPT.output_rec) for(int n=0;n<nIFO;n++) gPE.wREC[n] = &vREC[n];
2048  if(gOPT.output_wht) for(int n=0;n<nIFO;n++) gPE.wWHT[n] = &vWHT[n];
2049  if(gOPT.output_dat) for(int n=0;n<nIFO;n++) gPE.wDAT[n] = &vDAT[n];
2050  if(gOPT.output_med) for(int n=0;n<nIFO;n++) gPE.wMED[n] = &vMED[n];
2051  if(gOPT.output_p50) for(int n=0;n<nIFO;n++) gPE.wL50[n] = &vL50[n];
2052  if(gOPT.output_p50) for(int n=0;n<nIFO;n++) gPE.wU50[n] = &vU50[n];
2053  if(gOPT.output_p90) for(int n=0;n<nIFO;n++) gPE.wL90[n] = &vL90[n];
2054  if(gOPT.output_p90) for(int n=0;n<nIFO;n++) gPE.wU90[n] = &vU90[n];
2055  if(gOPT.output_avr) for(int n=0;n<nIFO;n++) gPE.wAVR[n] = &vAVR[n];
2056  if(gOPT.output_rms) for(int n=0;n<nIFO;n++) gPE.wRMS[n] = &vRMS[n];
2057  }
2058 
2059  gTREE = (TTree *) froot->Get("waveburst");
2060  if(gTREE!=NULL) {
2061  EVT = new netevent(gTREE,nIFO);
2062  if(dump_pe) {
2063  gTREE->Branch("pe_trials",&gPE.trials,"pe_trials/I");
2064  gTREE->Branch("pe_erR",gPE.erR,TString::Format("pe_erR[%i]/F",11));
2065  gTREE->Branch("pe_erF",gPE.erF,TString::Format("pe_erF[%i]/F",11));
2066  gTREE->Branch("pe_nstat",gPE.nstat,TString::Format("pe_nstat[%i]/F",2*7*cfg->nIFO));
2067  gTREE->Branch("pe_snet",gPE.snet,TString::Format("pe_snet[%i]/F",2));
2068  gTREE->Branch("pe_ff",gPE.ff,TString::Format("pe_ff[%i]/F",2));
2069  gTREE->Branch("pe_of",gPE.of,TString::Format("pe_of[%i]/F",2));
2070  gTREE->Branch("pe_mch",gPE.mch,TString::Format("pe_mch[%i]/F",2));
2071 
2072  for(int n=0;n<nIFO;n++) {
2073  if(gOPT.output_inj) if(cfg->simulation) gTREE->Branch(TString::Format("pe_wINJ_%d",n).Data(),"wavearray<double>",&gPE.wINJ[n],32000,0);
2074  if(gOPT.output_rec) gTREE->Branch(TString::Format("pe_wREC_%d",n).Data(),"wavearray<double>",&gPE.wREC[n],32000,0);
2075  if(gOPT.output_wht) gTREE->Branch(TString::Format("pe_wWHT_%d",n).Data(),"wavearray<double>",&gPE.wWHT[n],32000,0);
2076  if(gOPT.output_dat) gTREE->Branch(TString::Format("pe_wDAT_%d",n).Data(),"wavearray<double>",&gPE.wDAT[n],32000,0);
2077  if(gOPT.output_med) gTREE->Branch(TString::Format("pe_wMED_%d",n).Data(),"wavearray<double>",&gPE.wMED[n],32000,0);
2078  if(gOPT.output_p50) gTREE->Branch(TString::Format("pe_wL50_%d",n).Data(),"wavearray<double>",&gPE.wL50[n],32000,0);
2079  if(gOPT.output_p50) gTREE->Branch(TString::Format("pe_wU50_%d",n).Data(),"wavearray<double>",&gPE.wU50[n],32000,0);
2080  if(gOPT.output_p90) gTREE->Branch(TString::Format("pe_wL90_%d",n).Data(),"wavearray<double>",&gPE.wL90[n],32000,0);
2081  if(gOPT.output_p90) gTREE->Branch(TString::Format("pe_wU90_%d",n).Data(),"wavearray<double>",&gPE.wU90[n],32000,0);
2082  if(gOPT.output_avr) gTREE->Branch(TString::Format("pe_wAVR_%d",n).Data(),"wavearray<double>",&gPE.wAVR[n],32000,0);
2083  if(gOPT.output_rms) gTREE->Branch(TString::Format("pe_wRMS_%d",n).Data(),"wavearray<double>",&gPE.wRMS[n],32000,0);
2084  }
2085 
2086  if(gOPT.multitask&&(gMTRIAL!=gOPT.trials)) { // save reconstricted waveforms and skyprob when multitask mode
2087  for(int n=0;n<nIFO;n++) gTREE->Branch(TString::Format("mtpe_wREC_%d",n).Data(),"wavearray<double>",&wREC[0][n],32000,0);
2088  gTREE->Branch("mtpe_skyprob","skymap",&wSKYPROB[0], 32000,0);
2089  }
2090  }
2091  } else {
2092  EVT = new netevent(nIFO);
2093  gTREE = EVT->setTree();
2094  }
2095  EVT->setSLags(gSLAGSHIFT); // set slags into netevent
2096  EVT->Psave=cfg->Psave;
2097 }
2098 
2099 void DumpOutputFile(network* NET, netevent* &EVT, CWB::config* cfg, int ID, int k, int factor) {
2100 
2101  if(cfg->dump) EVT->dopen(gOUTPUT.Data(),const_cast<char*>("a"),false);
2102  EVT->output2G(gTREE,NET,ID,k,factor); // get reconstructed parameters
2103  if(cfg->dump) EVT->dclose();
2104  if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1; // mark as processed
2105 }
2106 
2108 
2109  while(!vINJ.empty()) vINJ.pop_back();
2110  vINJ.clear(); std::vector<wavearray<double> >().swap(vINJ);
2111  while(!vREC.empty()) vREC.pop_back();
2112  vREC.clear(); std::vector<wavearray<double> >().swap(vREC);
2113  while(!vWHT.empty()) vWHT.pop_back();
2114  vWHT.clear(); std::vector<wavearray<double> >().swap(vWHT);
2115  while(!vPCA.empty()) vPCA.pop_back();
2116  vPCA.clear(); std::vector<wavearray<double> >().swap(vPCA);
2117  while(!vDAT.empty()) vDAT.pop_back();
2118  vDAT.clear(); std::vector<wavearray<double> >().swap(vDAT);
2119  while(!vNUL.empty()) vNUL.pop_back();
2120  vNUL.clear(); std::vector<wavearray<double> >().swap(vNUL);
2121  while(!cINJ.empty()) cINJ.pop_back();
2122  cINJ.clear(); std::vector<wavearray<double> >().swap(cINJ);
2123 
2124  while(!vAVR.empty()) vAVR.pop_back();
2125  vAVR.clear(); std::vector<wavearray<double> >().swap(vAVR);
2126  while(!vRMS.empty()) vRMS.pop_back();
2127  vRMS.clear(); std::vector<wavearray<double> >().swap(vRMS);
2128 
2129  while(!vMED.empty()) vMED.pop_back();
2130  vMED.clear(); std::vector<wavearray<double> >().swap(vMED);
2131  while(!vL50.empty()) vL50.pop_back();
2132  vL50.clear(); std::vector<wavearray<double> >().swap(vL50);
2133  while(!vU50.empty()) vU50.pop_back();
2134  vU50.clear(); std::vector<wavearray<double> >().swap(vU50);
2135  while(!vL90.empty()) vL90.pop_back();
2136  vL90.clear(); std::vector<wavearray<double> >().swap(vL90);
2137  while(!vU90.empty()) vU90.pop_back();
2138  vU90.clear(); std::vector<wavearray<double> >().swap(vU90);
2139 
2140  while(!fREC.empty()) fREC.pop_back();
2141  fREC.clear(); std::vector<wavearray<double> >().swap(fREC);
2142  while(!fINJ.empty()) fINJ.pop_back();
2143  fINJ.clear(); std::vector<wavearray<double> >().swap(fINJ);
2144  while(!fAVR.empty()) fAVR.pop_back();
2145  fAVR.clear(); std::vector<wavearray<double> >().swap(fAVR);
2146  while(!fRMS.empty()) fRMS.pop_back();
2147  fRMS.clear(); std::vector<wavearray<double> >().swap(fRMS);
2148 
2149  while(!fMED.empty()) fMED.pop_back();
2150  fMED.clear(); std::vector<wavearray<double> >().swap(fMED);
2151  while(!fL50.empty()) fL50.pop_back();
2152  fL50.clear(); std::vector<wavearray<double> >().swap(fL50);
2153  while(!fU50.empty()) fU50.pop_back();
2154  fU50.clear(); std::vector<wavearray<double> >().swap(fU50);
2155  while(!fL90.empty()) fL90.pop_back();
2156  fL90.clear(); std::vector<wavearray<double> >().swap(fL90);
2157  while(!fU90.empty()) fU90.pop_back();
2158  fU90.clear(); std::vector<wavearray<double> >().swap(fU90);
2159 
2160  while(!vRES.empty()) vRES.pop_back();
2161  vRES.clear(); std::vector<double >().swap(vRES);
2162  while(!fRES.empty()) fRES.pop_back();
2163  fRES.clear(); std::vector<double >().swap(fRES);
2164 
2165  for(int n=0;n<MAX_TRIALS;n++) {
2166  while(!wREC[n].empty()) wREC[n].pop_back();
2167  wREC[n].clear(); std::vector<wavearray<double> >().swap(wREC[n]);
2168  }
2169 
2170  for(int n=0;n<NIFO_MAX;n++) {
2171  while(!iSNR[n].empty()) iSNR[n].pop_back();
2172  iSNR[n].clear(); std::vector<double>().swap(iSNR[n]);
2173  while(!oSNR[n].empty()) oSNR[n].pop_back();
2174  oSNR[n].clear(); std::vector<double>().swap(oSNR[n]);
2175  while(!ioSNR[n].empty()) ioSNR[n].pop_back();
2176  ioSNR[n].clear(); std::vector<double>().swap(ioSNR[n]);
2177  }
2178 
2179  for(int n=0;n<6;n++) {
2180  while(!vCHIRP[n].empty()) vCHIRP[n].pop_back();
2181  vCHIRP[n].clear(); std::vector<double>().swap(vCHIRP[n]);
2182  }
2183 
2184  while(!vLIKELIHOOD.empty()) vLIKELIHOOD.pop_back();
2185  vLIKELIHOOD.clear(); std::vector<double >().swap(vLIKELIHOOD);
2186 
2187  for(int n=0;n<NIFO_MAX;n++) {
2188  while(!aNUL[n].empty()) aNUL[n].pop_back();
2189  aNUL[n].clear(); std::vector<double>().swap(aNUL[n]);
2190  while(!ANUL[n].empty()) ANUL[n].pop_back();
2191  ANUL[n].clear(); std::vector<double>().swap(ANUL[n]);
2192  }
2193 
2194  for(int n=0;n<NIFO_MAX;n++) {
2195  while(!aNSE[n].empty()) aNSE[n].pop_back();
2196  aNSE[n].clear(); std::vector<double>().swap(aNSE[n]);
2197  while(!ANSE[n].empty()) ANSE[n].pop_back();
2198  ANSE[n].clear(); std::vector<double>().swap(ANSE[n]);
2199  }
2200 
2201  for(int n=0;n<NIFO_MAX;n++) {
2202  while(!vSS[n].empty()) vSS[n].pop_back();
2203  vSS[n].clear(); std::vector<SSeries<double> >().swap(vSS[n]);
2204  while(!rSS[n].empty()) rSS[n].pop_back();
2205  rSS[n].clear(); std::vector<SSeries<double> >().swap(rSS[n]);
2206  while(!jSS[n].empty()) jSS[n].pop_back();
2207  jSS[n].clear(); std::vector<SSeries<double> >().swap(jSS[n]);
2208  while(!dSS[n].empty()) dSS[n].pop_back();
2209  dSS[n].clear(); std::vector<SSeries<double> >().swap(dSS[n]);
2210  }
2211 }
2212 
2213 void PlotWaveforms(network* NET, CWB::config* cfg, int ID, TString pdir) {
2214 
2215  int nIFO = NET->ifoListSize(); // number of detectors
2216 
2217  wavearray<double> wDIF,wALI,wENV;
2218 
2219  char title[256]; char ofname[256];
2220  for(int n=0; n<nIFO; n++) {
2221 
2222  // COMPUTE SN, TString pdirR
2223 /*
2224  double SNR=0;
2225  for(int j=0;j<vREC[n].size();j++) SNR+=pow(vREC[n].data[j],2);
2226  cout << "SNR " << NET->ifoName[n] << " " << sqrt(SNR) << endl;
2227  double NUL=0;
2228  for(int j=0;j<vNUL[n].size();j++) NUL+=pow(vNUL[n].data[j],2);
2229  cout << "NUL " << NET->ifoName[n] << " " << sqrt(NUL) << endl;
2230 */
2231 /*
2232  // PLOT -> SPARSE MAP
2233  PlotSparse(n, NET, cfg, ID, &vINJ[n]);
2234 */
2235 /*
2236  // PLOT -> INJ : PCA : REC
2237  sprintf(title,"%s (TIME) : vINJ(red) - vPCA(blue) - vREC(green)",NET->ifoName[n]);
2238  sprintf(ofname,"%s_vINJ_vPCA_vREC_time_id_%d.%s",NET->ifoName[n],ID,PLOT_TYPE);
2239  PlotWaveform(ofname, title, cfg, &vINJ[n], &vPCA[n], &vREC[n],NULL, false,pdir); // time
2240  sprintf(title,"%s (FFT) : vINJ(red) - vPCA(blue) - vREC(green)",NET->ifoName[n]);
2241  //sprintf(ofname,"%s_vINJ_vPCA_vREC_fft_id_%d.%s",NET->ifoName[n],ID,PLOT_TYPE);
2242  //PlotWaveform(ofname, title, cfg, &vINJ[n], &vPCA[n], &vREC[n],NULL, true,pdir); // fft
2243 */
2244 
2245 #ifdef SET_WAVEFORM_CUTS
2246  // PLOT -> cINJ : cINJ-vARV : vRMS
2247  wDIF = GetDifWaveform(&cINJ[n], &vAVR[n]);
2248  sprintf(title,"%s (TIME) : cINJ(red) - cINJ-vAVR(blue) - vRMS(green)",NET->ifoName[n]);
2249  sprintf(ofname,"%s_cINJ_cINJvAVR_vRMS_time.%s",NET->ifoName[n],PLOT_TYPE);
2250  PlotWaveform(ofname, title, cfg, &cINJ[n], &wDIF, &vRMS[n], NULL, false, pdir);
2251 #endif
2252 /*
2253  // PLOT -> cINJ : wREC
2254  sprintf(title,"%s (TIME) : cINJ(red) - wREC(blue)",NET->ifoName[n]);
2255  sprintf(ofname,"%s_cINJ_wREC_time.%s",NET->ifoName[n],PLOT_TYPE);
2256  PlotWaveform(ofname, title, cfg, &cINJ[n], &wREC[0][n], NULL, NULL, false, pdir);
2257 */
2258 
2259 #ifdef SET_WAVEFORM_CUTS
2260  // PLOT -> cINJ : vREC : vAVR
2261  sprintf(title,"%s (TIME) : cINJ(red) - vREC(blue) - vAVR(green)",NET->ifoName[n]);
2262  sprintf(ofname,"%s_cINJ_vREC_vAVR_time.%s",NET->ifoName[n],PLOT_TYPE);
2263  PlotWaveform(ofname, title, cfg, &cINJ[n], &vREC[n], &vAVR[n], NULL, false, pdir);
2264 #endif
2265 
2266 #ifdef SET_WAVEFORM_CUTS
2267  // PLOT -> cINJ : cINJ
2268  sprintf(title,"%s (TIME) : cINJ(red) - cINJ(blue)",NET->ifoName[n]);
2269  sprintf(ofname,"%s_cINJ_cINJ_time.%s",NET->ifoName[n],PLOT_TYPE);
2270  PlotWaveform(ofname, title, cfg, &cINJ[n], &cINJ[n], NULL, NULL, false, pdir);
2271 #endif
2272 
2273  if(gOPT.ced_rec) {
2274  // PLOT -> vWHT vs vREC
2275  // NOTE : this plot overwrite the standard IFO_wf_signal.png/IFO_wf_signal_fft.png/ plots
2276  // the band signal is the now the whitend data
2277  double scale = sqrt(1<<cfg->levelR);
2278  vWHT[n]*=1/scale;
2279  vREC[n]*=1/scale;
2280  sprintf(ofname,"%s_wf_signal.%s",NET->ifoName[n],PLOT_TYPE);
2281  PlotWaveform(ofname, "", cfg, &vWHT[n], &vREC[n], NULL, &vREC[n], false, pdir,0.999,(EColor)16,kRed);
2282  sprintf(ofname,"%s_wf_signal_fft.%s",NET->ifoName[n],PLOT_TYPE);
2283  PlotWaveform(ofname, "", cfg, &vWHT[n], &vREC[n], NULL, &vREC[n], true, pdir,0.999,(EColor)16,kRed);
2284  vWHT[n]*=scale;
2285  vREC[n]*=scale;
2286  }
2287 
2288  for(int j=0;j<2;j++) {
2289 
2290  TString tag = j==0 ? "time" : "time_zoom"; // file tag
2291  double P = j==0 ? 0.995 : 0.9; // time zoom
2292 
2293  // RECONSTRUCTED
2294 
2295  if(gOPT.ced_rec) {
2296 
2297  // PLOT -> vAVR(vMED) : vRMS(PERC)
2298  //wENV = GetWaveformEnvelope(&vREC[n]);
2299  sprintf(title,"%s (TIME) : vREC (red) - vRMS:2vRMS (grey:light_gray)",NET->ifoName[n]);
2300  sprintf(ofname,"%s_vREC_vRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2301 #ifdef PLOT_MEDIAN
2302  PlotWaveformAsymmErrors(ofname, "", cfg, &vREC[n], &vMED[n], &vL50[n], &vU50[n], &vL90[n], &vU90[n], &vREC[n], pdir, P);
2303 #else
2304  PlotWaveformErrors(ofname, "", cfg, &vREC[n], &vAVR[n], &vRMS[n], &vREC[n], pdir, P);
2305 #endif
2306 
2307  // PLOT -> vREC-vAVR(vMED) : vRMS(PERC)
2308 #ifdef PLOT_MEDIAN
2309  wDIF = GetDifWaveform(&vREC[n], &vMED[n]);
2310 #else
2311  wDIF = GetDifWaveform(&vREC[n], &vAVR[n]);
2312 #endif
2313  sprintf(title,"%s (TIME) : vREC-vAVR(red) - 2*vRMS(gray)",NET->ifoName[n]);
2314  sprintf(ofname,"%s_vRECvAVR_vRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2315 #ifdef PLOT_MEDIAN
2316  PlotWaveformAsymmErrors(ofname, "", cfg, &wDIF, &wDIF, &vL50[n], &vU50[n], &vL90[n], &vU90[n], &vREC[n], pdir, P);
2317 #else
2318  PlotWaveformErrors(ofname, "", cfg, &wDIF, &wDIF, &vRMS[n], &vREC[n], pdir, P);
2319 #endif
2320 
2321  // PLOT -> fAVR : fRMS(fMED)
2322  sprintf(title,"%s (FREQ) : fREC (red) - fRMS:2fRMS (grey:light_gray)",NET->ifoName[n]);
2323  sprintf(ofname,"%s_fREC_fRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2324 #ifdef PLOT_MEDIAN
2325  PlotWaveformAsymmErrors(ofname, "", cfg, &fREC[n], &fMED[n], &fL50[n], &fU50[n], &fL90[n], &fU90[n], &vREC[n], pdir, P, true);
2326 #else
2327  PlotFrequencyErrors(ofname, "", cfg, &fREC[n], &fAVR[n], &fRMS[n], &vREC[n], pdir, P);
2328 #endif
2329 
2330  // PLOT -> vREC : vDAT-vREC : vRMS
2331  wDIF = GetDifWaveform(&vDAT[n], &vREC[n]);
2332  sprintf(title,"%s (TIME) : vREC(red) - vDAT-vREC(blue) - vRMS(green)",NET->ifoName[n]);
2333  sprintf(ofname,"%s_vREC_vDATvREC_vRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2334  PlotWaveform(ofname, "", cfg, &vREC[n], &wDIF, &vRMS[n], &vREC[n], false, pdir, P);
2335  }
2336 
2337  if(!cfg->simulation) continue;
2338 
2339  // RECONSTRUCTED vs INJECTED
2340 
2341  if(gOPT.ced_inj) {
2342  // PLOT -> vINJ : vAVR(vMED) : vRMS(PERC)
2343  wALI = GetAlignedWaveform(&vINJ[n], &vREC[n]);
2344  sprintf(title,"%s (TIME) : vINJ (red) - vRMS:2vRMS (grey:light_gray)",NET->ifoName[n]);
2345  sprintf(ofname,"%s_vINJ_vRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2346 #ifdef PLOT_MEDIAN
2347  PlotWaveformAsymmErrors(ofname, "", cfg, &wALI, &vMED[n], &vL50[n], &vU50[n], &vL90[n], &vU90[n], &vREC[n], pdir, P);
2348 #else
2349  PlotWaveformErrors(ofname, "", cfg, &wALI, &vAVR[n], &vRMS[n], &vREC[n], pdir, P);
2350 #endif
2351 
2352  // PLOT -> fINJ : fAVE(fMED) : fRMS(PERC)
2353  sprintf(title,"%s (FREQ) : fINJ (red) - fRMS:2fRMS (grey:light_gray)",NET->ifoName[n]);
2354  sprintf(ofname,"%s_fINJ_fRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2355 #ifdef PLOT_MEDIAN
2356  PlotWaveformAsymmErrors(ofname, "", cfg, &fINJ[n], &fMED[n], &fL50[n], &fU50[n], &fL90[n], &fU90[n], &vREC[n], pdir, P, true);
2357 #else
2358  PlotFrequencyErrors(ofname, "", cfg, &fINJ[n], &fAVR[n], &fRMS[n], &vREC[n], pdir, P);
2359 #endif
2360 
2361  // PLOT -> vAVR(vMED)-vINJ : vRMS(PERC)
2362 #ifdef PLOT_MEDIAN
2363  wDIF = GetDifWaveform(&vMED[n], &vINJ[n]);
2364 #else
2365  wDIF = GetDifWaveform(&vAVR[n], &vINJ[n]);
2366 #endif
2367  wDIF = GetAlignedWaveform(&wDIF, &vREC[n]);
2368  sprintf(title,"%s (TIME) : vAVR-vINJ(red) - 2*vRMS(gray)",NET->ifoName[n]);
2369  sprintf(ofname,"%s_vAVRvINJ_vRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2370 #ifdef PLOT_MEDIAN
2371  PlotWaveformAsymmErrors(ofname, "", cfg, &wDIF, &wDIF, &vL50[n], &vU50[n], &vL90[n], &vU90[n], &vREC[n], pdir, P);
2372 #else
2373  PlotWaveformErrors(ofname, "", cfg, &wDIF, &wDIF, &vRMS[n], &vREC[n], pdir, P);
2374 #endif
2375  }
2376 
2377  // RECONSTRUCTED vs reduced INJECTED
2378 
2379  if(gOPT.ced_rinj) {
2380 
2381  // PLOT -> vAVR(vMED)-cINJ : vRMS(PERC)
2382 #ifdef PLOT_MEDIAN
2383  wDIF = GetDifWaveform(&vMED[n], &cINJ[n]);
2384 #else
2385  wDIF = GetDifWaveform(&vAVR[n], &cINJ[n]);
2386 #endif
2387  wDIF = GetAlignedWaveform(&wDIF, &vREC[n]);
2388  sprintf(title,"%s (TIME) : vAVR-cINJ(red) - 2*vRMS(gray)",NET->ifoName[n]);
2389  sprintf(ofname,"%s_vAVRcINJ_vRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2390 #ifdef PLOT_MEDIAN
2391  PlotWaveformAsymmErrors(ofname, "", cfg, &wDIF, &wDIF, &vL50[n], &vU50[n], &vL90[n], &vU90[n], &vREC[n], pdir, P);
2392 #else
2393  PlotWaveformErrors(ofname, "", cfg, &wDIF, &wDIF, &vRMS[n], &vREC[n], pdir, P);
2394 #endif
2395 
2396  // PLOT -> cINJ : vAVR(vMED) : vRMS(PERC)
2397  sprintf(title,"%s (TIME) : cINJ (red) - vRMS:2vRMS (grey:light_gray)",NET->ifoName[n]);
2398  sprintf(ofname,"%s_cINJ_vRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2399 #ifdef PLOT_MEDIAN
2400  PlotWaveformAsymmErrors(ofname, "", cfg, &cINJ[n], &vMED[n], &vL50[n], &vU50[n], &vL90[n], &vU90[n], &vREC[n], pdir, P);
2401 #else
2402  PlotWaveformErrors(ofname, "", cfg, &cINJ[n], &vAVR[n], &vRMS[n], &vREC[n], pdir, P);
2403 #endif
2404 
2405  // PLOT -> fINJ : fAVR(PERC) : fRMS
2406  sprintf(title,"%s (FREQ) : fINJ (red) - fRMS:2fRMS (grey:light_gray)",NET->ifoName[n]);
2407  sprintf(ofname,"%s_fINJ_fRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2408 #ifdef PLOT_MEDIAN
2409  PlotWaveformAsymmErrors(ofname, "", cfg, &fINJ[n], &fMED[n], &fL50[n], &fU50[n], &fL90[n], &fU90[n], &vREC[n], pdir, P, true);
2410 #else
2411  PlotFrequencyErrors(ofname, "", cfg, &fINJ[n], &fAVR[n], &fRMS[n], &vREC[n], pdir, P);
2412 #endif
2413 
2414  // PLOT -> cINJ : vREC : vRMS
2415  sprintf(title,"%s (TIME) : cINJ(red) - vREC(blue) - vRMS(green)",NET->ifoName[n]);
2416  sprintf(ofname,"%s_cINJ_vREC_vRMS_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2417  PlotWaveform(ofname, "", cfg, &cINJ[n], &vREC[n], &vRMS[n], &vREC[n], false, pdir, P);
2418 
2419  // PLOT -> vINJ : vINJ-cINJ : vINJcINJ
2420  wDIF = GetDifWaveform(&vINJ[n], &cINJ[n]);
2421  wDIF = GetAlignedWaveform(&wDIF, &vREC[n]);
2422  wALI = GetAlignedWaveform(&vINJ[n], &vREC[n]);
2423  sprintf(title,"%s (TIME) : vINJ(red) - cINJ(blue) - vINJ-cINJ(green)",NET->ifoName[n]);
2424  sprintf(ofname,"%s_vINJ_cINJ_vINJcINJ_%s.%s",NET->ifoName[n],tag.Data(),PLOT_TYPE);
2425  PlotWaveform(ofname, "", cfg, &wALI, &cINJ[n], &wDIF, &vREC[n], false, pdir, P);
2426  }
2427  }
2428 /*
2429  // FITTING FACTOR
2430  double FF1 = FittingFactor(&cINJ[n], &vREC[n]);
2431  double FF2 = FittingFactor(&cINJ[n], &vPCA[n]);
2432  cout << NET->ifoName[n] << " -> Fitting Factor - inj/rec = " << FF1 << " inj/pca = " << FF2 << endl;
2433 */
2434  }
2435 }
2436 
2437 void SetSkyMask(network* NET, CWB::config* cfg, double theta, double phi, double radius) {
2438 
2439  // --------------------------------------------------------
2440  // define SetSkyMask
2441  // --------------------------------------------------------
2442  sprintf(cfg->skyMaskFile,"--theta %f --phi %f --radius %f",90-theta,phi,radius);
2443  cout << endl << "SetSkyMask : " << cfg->skyMaskFile << endl << endl;
2444  gCWB.SetSkyMask(NET,cfg,cfg->skyMaskFile,'e');
2445 
2446 }
2447 
2449 
2450  if(type!='j' && type!='r' && type!='v') {
2451  cout << "AddNoiseAndCalErrToSparse - Error : wrong wave type" << endl; exit(1);
2452  }
2453 
2454  double d2r = TMath::Pi()/180.;
2455 
2456  int m;
2457  int nIFO = NET->ifoListSize(); // number of detectors
2458  int nRES = NET->wdmListSize(); // number of frequency resolution levels
2459 
2460  // update vSS maps
2463  SSeries<double>* p;
2464  WDM<double>* pwdm = NULL;
2465 
2466  for(int n=0; n<nIFO; n++) { // create random time series
2467  p = NET->getifo(n)->getSTFmap(0);
2468  WF[n].resize(p->wdm_nSTS);
2469  WF[n].rate(p->wdm_rate);
2470  WF[n].start(p->wdm_start);
2471 
2472  int size = WF[n].size();
2473  double rate = WF[n].rate();
2474  int jS,jE,jW,k;
2475  double dt,df,ts;
2476  TComplex C;
2477  switch(gOPT.noise) {
2478  case 1: // gaussian noise
2479  for(int i=0; i<WF[n].size(); i++) {
2480  WF[n].data[i] = gRandom->Gaus(0,NOISE_SIGMA);
2481  }
2482  cout << "AddNoiseAndCalErrToSparse - Info : add gaussian noise to waveform type : " << type << endl;
2483  break;
2484  case 2: // data noise
2485  w = *(NET->getifo(n)->getTFmap()); // get whitened data
2486  w.Inverse(); // get level 0
2487  // apply time shift to input whitened data (integer number of sammples)
2488  jS = cfg->segEdge*rate;
2489  jE = size-jS;
2490  jW = rate*cfg->iwindow/2;
2491  k = gRandom->Uniform(jS+jW,jE-jW); // select random offset (excludes +/- iwindow/2 around the event)
2492  WF[n] = w;
2493  for(int i=jS; i<jE; i++) {
2494  WF[n].data[k++] = w.data[i];
2495  if(k==jE) k=jS;
2496  }
2497  // apply time shift to input whitened data (fraction of dt)
2498  WF[n].FFTW(1);
2499  dt = 1./rate;
2500  df = rate/size;
2501  ts = gRandom->Uniform(0.,dt); // select a random time shift within the sample time range
2502  for (int j=0;j<size/2;j++) {
2503  TComplex X(WF[n].data[2*j],WF[n].data[2*j+1]);
2504  X=X*C.Exp(TComplex(0.,-2*PI*j*df*ts));
2505  WF[n].data[2*j]=X.Re();
2506  WF[n].data[2*j+1]=X.Im();
2507  }
2508  WF[n].FFTW(-1);
2509  printf("Info : %s add data noise with time shift : %.5f sec to waveform type : %c\n",NET->getifo(n)->Name,(double)k/rate+ts,type);
2510  break;
2511  default:
2512  WF[n]=0;
2513  break;
2514  }
2515  }
2516 
2517  // fill waveform sparse maps
2518  for(int n=0; n<nIFO; n++) {
2519  double A = 1;
2520  if(gOPT.amp_cal_err[n]) {
2521  double amp_cal_err = 1;
2522  if(gOPT.amp_cal_err[n]>0) amp_cal_err = gRandom->Uniform(1-gOPT.amp_cal_err[n],1+gOPT.amp_cal_err[n]);
2523  else amp_cal_err = gRandom->Gaus(1,fabs(gOPT.amp_cal_err[n]));
2524  cout << NET->ifoName[n] << " -> amp_cal_err : " << amp_cal_err << endl;
2525  A = amp_cal_err;
2526  }
2527  double C=1,S=0;
2528  if(gOPT.phs_cal_err[n]) {
2529  double phs_cal_err = 0;
2530  if(gOPT.phs_cal_err[n]>0) phs_cal_err = gRandom->Uniform(-gOPT.phs_cal_err[n],gOPT.phs_cal_err[n]);
2531  else phs_cal_err = gRandom->Gaus(0,fabs(gOPT.phs_cal_err[n]));
2532  cout << NET->ifoName[n] << " -> phs_cal_err : " << phs_cal_err << endl;
2533  C = cos(-phs_cal_err*d2r);
2534  S = sin(-phs_cal_err*d2r);
2535  }
2536  for(int j=0; j<nRES; j++) {
2537  w.Forward(WF[n],*(NET->wdmList[j]));
2538  int k = NET->getifo(n)->getSTFind(w.wrate()); // pointer to sparse TF array
2539  p = NET->getifo(n)->getSTFmap(k); // pointer to sparse TF array
2540  for(int l=0; l<p->sparseMap00.size(); l++) {
2541  m = p->sparseIndex[l];
2542  double aa,AA;
2543  if(type=='r') { // reconstructed waveform
2544  aa = rSS[n][k].sparseMap00[l];
2545  AA = rSS[n][k].sparseMap90[l];
2546  }
2547  if(type=='j') { // injected waveform
2548  aa = jSS[n][k].sparseMap00[l];
2549  AA = jSS[n][k].sparseMap90[l];
2550  }
2551  if(type=='v') { // original sparse map (reconstructed+noise)
2552  aa = vSS[n][k].sparseMap00[l];
2553  AA = vSS[n][k].sparseMap90[l];
2554  }
2555  // add calibration error
2556  aa*=A; AA*=A;
2557  // add phase error
2558  double bb = C*aa + S*AA;
2559  double BB = -S*aa + C*AA ;
2560  // add gaussian noise
2561  p->sparseMap00[l]=bb+w.data[m];
2562  p->sparseMap90[l]=BB+w.data[m+w.maxIndex()+1];
2563  }
2564  }
2565  }
2566  return;
2567 }
2568 
2569 void Wave2Sparse(network* NET, CWB::config* cfg, char type) {
2570 
2571  if(type!='j' && type!='r' && type!='v' && type!='d') {
2572  cout << "Wave2Sparse - Error : wrong wave type" << endl; exit(1);
2573  }
2574 
2575  // init waveform sparse maps
2576  int nIFO = NET->ifoListSize(); // number of detectors
2577  for(int n=0;n<nIFO;n++) {
2578  detector* pD = NET->getifo(n);
2579  if(type=='v') vSS[n]=pD->vSS;
2580  if(type=='r') rSS[n]=pD->vSS;
2581  if(type=='j') jSS[n]=pD->vSS;
2582  if(type=='d') dSS[n]=pD->vSS;
2583  }
2584  if(type=='v') return;
2585 
2586  int nRES = cfg->l_high-cfg->l_low+1; // number of frequency resolution levels
2587 
2588  // build waveform array
2590  for(int n=0; n<nIFO; n++) {
2591  WF[n].resize(vSS[n][0].wdm_nSTS);
2592  WF[n].rate(vSS[n][0].wdm_rate);
2593  WF[n].start(vSS[n][0].wdm_start);
2594  WF[n]=0;
2595  if(type=='j') {
2596  int wos = double(vINJ[n].start()-WF[n].start())*WF[n].rate();
2597  for (int i=0;i<vINJ[n].size();i++) WF[n][wos+i] = vINJ[n][i];
2598  }
2599  if(type=='r') {
2600  int wos = double(vREC[n].start()-WF[n].start())*WF[n].rate();
2601  for (int i=0;i<vREC[n].size();i++) WF[n][wos+i] = vREC[n][i];
2602  }
2603  if(type=='d') {
2604  int wos = double(vDAT[n].start()-WF[n].start())*WF[n].rate();
2605  for (int i=0;i<vDAT[n].size();i++) WF[n][wos+i] = vDAT[n][i];
2606  }
2607 
2608 #ifdef SAVE_WAVE2SPARSE_PLOT
2609  gwavearray<double> gw(&WF[n]);
2610  gw.Draw(GWAT_TIME);
2611  watplot* plot = gw.GetWATPLOT();
2612  TString gfile;
2613  if(type=='r') gfile=TString::Format("%s/WAVE2SPARSE_REC_%s.root",".",NET->ifoName[n]);
2614  if(type=='j') gfile=TString::Format("%s/WAVE2SPARSE_INJ_%s.root",".",NET->ifoName[n]);
2615  if(type=='d') gfile=TString::Format("%s/WAVE2SPARSE_DAT_%s.root",".",NET->ifoName[n]);
2616  (*plot) >> gfile;
2617 #endif
2618  }
2619 
2620  // fill waveform sparse maps
2621  WSeries<double> w;
2622  WDM<double>* pwdm = NULL;
2623  double r00,r90;
2624  for(int n=0; n<nIFO; n++) {
2625  for(int i=0; i<nRES; i++) {
2626  w.Forward(WF[n],*(NET->wdmList[i]));
2627  int k = NET->getifo(n)->getSTFind(w.wrate()); // pointer to sparse TF array
2628 
2629  int size;
2630  if(type=='r') size = rSS[n][k].sparseMap00.size();
2631  if(type=='j') size = jSS[n][k].sparseMap00.size();
2632  if(type=='d') size = dSS[n][k].sparseMap00.size();
2633 
2634  for(int j=0; j<size; j++) {
2635  int index;
2636  if(type=='r') index = rSS[n][k].sparseIndex[j];
2637  if(type=='j') index = jSS[n][k].sparseIndex[j];
2638  if(type=='d') index = dSS[n][k].sparseIndex[j];
2639  double v00 = w.pWavelet->pWWS[index];
2640  double v90 = w.pWavelet->pWWS[index+w.maxIndex()+1];
2641  if(type=='r') {
2642  rSS[n][k].sparseMap00[j]=v00;
2643  rSS[n][k].sparseMap90[j]=v90;
2644  }
2645  if(type=='j') {
2646  jSS[n][k].sparseMap00[j]=v00;
2647  jSS[n][k].sparseMap90[j]=v90;
2648  }
2649  if(type=='d') {
2650  dSS[n][k].sparseMap00[j]=v00;
2651  dSS[n][k].sparseMap90[j]=v90;
2652  }
2653  }
2654  }
2655  }
2656 }
2657 
2658 std::vector<int> ComputeStatisticalErrors(network* NET, CWB::config* cfg, int ID) {
2659 
2660  int nIFO = NET->ifoListSize(); // number of detectors
2661  std::vector<int> nrec(nIFO); // number of averaged
2662 
2663 #ifdef SET_WAVEFORM_CUTS
2664  // get time and frequency ranges
2665  gBT=1e20; gET=0;
2666  gBF=1e20; gEF=0;
2667  for(int n=0;n<nIFO;n++) {
2668  double bT,eT,bF,eF;
2669  GetTimeBoundaries(vREC[n], EFRACTION_CUT, bT, eT);
2670  GetFrequencyBoundaries(vREC[n], EFRACTION_CUT, bF, eF);
2671  if(bT<gBT) gBT=bT; if(eT>gET) gET=eT;
2672  if(bF<gBF) gBF=bF; if(eF>gEF) gEF=eF;
2673  }
2674  cout << endl;
2675  cout << "CUT TIME RANGE : " << gBT-gBT << " " << gET-gBT << endl;
2676  cout << "CUT FREQ RANGE : " << gBF << " " << gEF << endl;
2677  cout << endl;
2678 #endif
2679 
2680  // copy cINJ (only the vREC time range) into winj
2681  wavearray<double> winj[NIFO_MAX];
2683  if(cfg->simulation) {
2684  for(int n=0;n<nIFO;n++) {
2685  winj[n] = GetAlignedWaveform(&cINJ[n], &vREC[n]);
2686  finj[n] = CWB::Toolbox::getHilbertIFrequency(winj[n]);
2687 #ifdef SET_WAVEFORM_CUTS
2688  SetWaveformCuts(&winj[n], gBT, gET, gBF, gEF);
2689  cINJ.push_back(GetAlignedWaveform(&winj[n], &vREC[n]));
2690 #endif
2691  }
2692  }
2693 
2694  // compute average of wREC (only the vREC time range) into wavr
2697  for(int n=0;n<nIFO;n++) {
2698  nrec[n]=0;
2699  for(int i=0;i<gOPT.trials;i++) {
2700  if(wREC[i].size()) { // event detected
2701  wrec[i][n] = GetAlignedWaveform(&wREC[i][n], &vREC[n]);
2702  frec[i][n] = CWB::Toolbox::getHilbertIFrequency(wrec[i][n]);
2703 #ifdef SET_WAVEFORM_CUTS
2704  SetWaveformCuts(&wrec[i][n], gBT, gET, gBF, gEF);
2705 #endif
2706  nrec[n]++;
2707  } else { // event rejected (set to 0)
2708  wrec[i][n] = vREC[n]; wrec[i][n]=0;
2709  frec[i][n] = wrec[i][n];
2710  }
2711  }
2712  if(nrec[n]==0) {nrec.clear();return nrec;} // return if no events are detects
2713  }
2714 
2715  gPE.trials = nrec[0]; // save number of effective trials
2716  cout << endl << "ComputeStatisticalErrors - detected/trials : " << nrec[0] << "/" << gOPT.trials << endl << endl;
2717 
2718  // compute vAVR & vRMS
2719  wavearray<double> wavr[NIFO_MAX];
2720  wavearray<double> wrms[NIFO_MAX];
2721  for(int n=0;n<nIFO;n++) {
2722  wrms[n] = wrec[0][n]; wrms[n] = 0;
2723  wavr[n] = wrec[0][n]; wavr[n] = 0;
2724  for(int i=0;i<gOPT.trials;i++) {
2725  wavr[n] += wrec[i][n];
2726  for(int j=0;j< wrec[i][n].size();j++) wrms[n][j] += wrec[i][n][j]*wrec[i][n][j];
2727  }
2728  wavr[n] *= 1./nrec[n];
2729 
2730  wrms[n] *= 1./nrec[n];
2731  for(int j=0;j< wrms[n].size();j++) {
2732  wrms[n][j] -= wavr[n][j]*wavr[n][j];
2733  wrms[n][j] = sqrt(wrms[n][j]);
2734  }
2735 
2736  vAVR.push_back(wavr[n]);
2737  vRMS.push_back(wrms[n]);
2738  }
2739 
2740  // compute vMED, vL50, vU50, vL90, vU90
2741  wavearray<double> wmed[NIFO_MAX];
2742  wavearray<double> wl50[NIFO_MAX];
2743  wavearray<double> wu50[NIFO_MAX];
2744  wavearray<double> wl90[NIFO_MAX];
2745  wavearray<double> wu90[NIFO_MAX];
2746  for(int n=0;n<nIFO;n++) {
2747  wmed[n] = wrec[0][n]; wmed[n] = 0;
2748  wl50[n] = wrec[0][n]; wl50[n] = 0;
2749  wu50[n] = wrec[0][n]; wu50[n] = 0;
2750  wl90[n] = wrec[0][n]; wl90[n] = 0;
2751  wu90[n] = wrec[0][n]; wu90[n] = 0;
2752 
2753  int ntry = gPE.trials; // number of detected events in the trials
2754  int *index = new int[ntry];
2755  float *value = new float[ntry];
2756  for(int j=0;j<wrec[0][n].size();j++) {
2757 
2758  int k=0; for(int i=0;i<gOPT.trials;i++) if(wREC[i].size()) value[k++] = wrec[i][n][j]; // select detected events
2759  TMath::Sort(ntry,value,index,false);
2760 
2761  int imed = (ntry*50.)/100.; if(imed>=ntry) imed=ntry-1;
2762  wmed[n][j] = value[index[imed]];
2763 
2764  int il50 = (ntry*25.)/100.; if(il50>=ntry) il50=ntry-1;
2765  int iu50 = (ntry*75.)/100.; if(iu50>=ntry) iu50=ntry-1;
2766  int il90 = (ntry*5.)/100.; if(il90>=ntry) il90=ntry-1;
2767  int iu90 = (ntry*95.)/100.; if(iu90>=ntry) iu90=ntry-1;
2768 
2769  wl50[n][j] = wmed[n][j]>0 ? wmed[n][j]-value[index[il50]] : value[index[iu50]]-wmed[n][j];
2770  wu50[n][j] = wmed[n][j]>0 ? value[index[iu50]]-wmed[n][j] : wmed[n][j]-value[index[il50]];
2771  wl90[n][j] = wmed[n][j]>0 ? wmed[n][j]-value[index[il90]] : value[index[iu90]]-wmed[n][j];
2772  wu90[n][j] = wmed[n][j]>0 ? value[index[iu90]]-wmed[n][j] : wmed[n][j]-value[index[il90]];
2773  }
2774  delete [] index;
2775  delete [] value;
2776 
2777  vMED.push_back(wmed[n]);
2778  vL50.push_back(wl50[n]);
2779  vU50.push_back(wu50[n]);
2780  vL90.push_back(wl90[n]);
2781  vU90.push_back(wu90[n]);
2782  }
2783 
2784  // compute fAVR & fRMS
2785  wavearray<double> favr[NIFO_MAX];
2786  wavearray<double> frms[NIFO_MAX];
2787  for(int n=0;n<nIFO;n++) {
2788  frms[n] = frec[0][n]; frms[n] = 0;
2789  favr[n] = frec[0][n]; favr[n] = 0;
2790  for(int i=0;i<gOPT.trials;i++) {
2791  favr[n] += frec[i][n];
2792  for(int j=0;j< frec[i][n].size();j++) frms[n][j] += frec[i][n][j]*frec[i][n][j];
2793  }
2794  favr[n] *= 1./nrec[n];
2795 
2796  frms[n] *= 1./nrec[n];
2797  for(int j=0;j< frms[n].size();j++) {
2798  frms[n][j] -= favr[n][j]*favr[n][j];
2799  frms[n][j] = sqrt(frms[n][j]);
2800  }
2801 
2802  fAVR.push_back(favr[n]);
2803  fRMS.push_back(frms[n]);
2804  }
2805 
2806  // compute fMED, fL50, fU50, fL90, fU90
2807  wavearray<double> fmed[NIFO_MAX];
2808  wavearray<double> fl50[NIFO_MAX];
2809  wavearray<double> fu50[NIFO_MAX];
2810  wavearray<double> fl90[NIFO_MAX];
2811  wavearray<double> fu90[NIFO_MAX];
2812  for(int n=0;n<nIFO;n++) {
2813  fmed[n] = frec[0][n]; fmed[n] = 0;
2814  fl50[n] = frec[0][n]; fl50[n] = 0;
2815  fu50[n] = frec[0][n]; fu50[n] = 0;
2816  fl90[n] = frec[0][n]; fl90[n] = 0;
2817  fu90[n] = frec[0][n]; fu90[n] = 0;
2818 
2819  int ntry = gPE.trials; // number of detected events in the trials
2820  int *index = new int[ntry];
2821  float *value = new float[ntry];
2822  for(int j=0;j<frec[0][n].size();j++) {
2823 
2824  int k=0; for(int i=0;i<gOPT.trials;i++) if(wREC[i].size()) value[k++] = frec[i][n][j]; // select detected events
2825  TMath::Sort(ntry,value,index,false);
2826 
2827  int imed = (ntry*50.)/100.; if(imed>=ntry) imed=ntry-1;
2828  fmed[n][j] = value[index[imed]];
2829 
2830  int il50 = (ntry*25.)/100.; if(il50>=ntry) il50=ntry-1;
2831  int iu50 = (ntry*75.)/100.; if(iu50>=ntry) iu50=ntry-1;
2832  int il90 = (ntry*5.)/100.; if(il90>=ntry) il90=ntry-1;
2833  int iu90 = (ntry*95.)/100.; if(iu90>=ntry) iu90=ntry-1;
2834 
2835  fl50[n][j] = fmed[n][j]>0 ? fmed[n][j]-value[index[il50]] : value[index[iu50]]-fmed[n][j];
2836  fu50[n][j] = fmed[n][j]>0 ? value[index[iu50]]-fmed[n][j] : fmed[n][j]-value[index[il50]];
2837  fl90[n][j] = fmed[n][j]>0 ? fmed[n][j]-value[index[il90]] : value[index[iu90]]-fmed[n][j];
2838  fu90[n][j] = fmed[n][j]>0 ? value[index[iu90]]-fmed[n][j] : fmed[n][j]-value[index[il90]];
2839  }
2840  delete [] index;
2841  delete [] value;
2842 
2843  fMED.push_back(fmed[n]);
2844  fL50.push_back(fl50[n]);
2845  fU50.push_back(fu50[n]);
2846  fL90.push_back(fl90[n]);
2847  fU90.push_back(fu90[n]);
2848  }
2849 
2850  // ---------------------------------------------------
2851  // compute residuals energy
2852  // ---------------------------------------------------
2853  double eavr=0; // energy avr^2
2854  for(int n=0;n<nIFO;n++) {
2855  for(int j=0;j< wavr[n].size();j++) eavr += pow(wavr[n][j],2);
2856  }
2857  for(int i=0;i<gOPT.trials;i++) {
2858  if(wREC[i].size()) { // event detected
2859  double eres=0; // residual energy (rec-avr)^2
2860  for(int n=0;n<nIFO;n++) {
2861  for(int j=0;j< wavr[n].size();j++) {
2862  eres += pow(wrec[i][n][j]-wavr[n][j],2);
2863  }
2864  }
2865  // add normalized residual energy of wrec to vRES
2866  vRES.push_back(eres/eavr);
2867  }
2868  }
2869  double jres=0; // residual energy (inj-avr)^2
2870  if(cfg->simulation) {
2871  for(int n=0;n<nIFO;n++) {
2872  for(int j=0;j< wavr[n].size();j++) {
2873  jres += pow(winj[n][j]-wavr[n][j],2);
2874  }
2875  }
2876  jres/=eavr;
2877  }
2878  // add normalized residual energy of winj to vRES
2879  vRES.push_back(jres);
2880 
2881  // compute probability distribution of residuals
2882  int size = vRES.size()-1;
2883  wavearray<int> index(size);
2884  wavearray<double> eres(size);
2885  for(int i=0;i<size;i++) eres[i] = vRES[i];
2886  TMath::Sort(size,const_cast<double*>(eres.data),index.data,false);
2887  gPE.erR[0] = jres;
2888  for(int i=1;i<10;i++) gPE.erR[i]=eres[index[int(i*size/10.)]];
2889  gPE.erR[10]=0;
2890  for(int i=0;i<size;i++) {
2891  if(eres[i]<=jres) gPE.erR[10]+=1.;
2892  }
2893  gPE.erR[10]/=size;
2894  // print probability distribution of residuals
2895  cout.precision(3);
2896  cout << endl << "gPE.erR : ";
2897  for(int i=0;i<10;i++) cout << gPE.erR[i] << "/";
2898  cout << gPE.erR[10] << endl << endl;
2899 
2900  // ---------------------------------------------------
2901  // compute frequency residuals
2902  // ---------------------------------------------------
2903  eavr=0; // energy wavr^4*favr^2
2904  for(int n=0;n<nIFO;n++) {
2905  for(int j=0;j< wavr[n].size();j++) eavr += pow(wavr[n][j],4)*pow(favr[n][j],2);
2906  }
2907  for(int i=0;i<gOPT.trials;i++) {
2908  if(wREC[i].size()) { // event detected
2909  double eres=0; // weighted frequency residual energy wavr^4*(frec-favr)^2
2910  for(int n=0;n<nIFO;n++) {
2911  for(int j=0;j<wavr[n].size();j++) {
2912  eres += pow(wavr[n][j],4)*pow(frec[i][n][j]-favr[n][j],2);
2913  }
2914  }
2915  // add normalized frequency residual energy of frec to fRES
2916  fRES.push_back(eres/eavr);
2917  }
2918  }
2919  jres=0; // weighted frequency residual energy wavr^4*(finj-favr)^2
2920  if(cfg->simulation) {
2921  for(int n=0;n<nIFO;n++) {
2922  for(int j=0;j< wavr[n].size();j++) {
2923  jres += pow(wavr[n][j],4)*pow(finj[n][j]-favr[n][j],2);
2924  }
2925  }
2926  jres/=eavr;
2927  }
2928  // add normalized frequency residual energy of finj to fRES
2929  fRES.push_back(jres);
2930 
2931  // compute probability distribution of residuals
2932  for(int i=0;i<size;i++) eres[i] = fRES[i];
2933  TMath::Sort(size,const_cast<double*>(eres.data),index.data,false);
2934  gPE.erF[0] = jres;
2935  for(int i=1;i<10;i++) gPE.erF[i]=eres[index[int(i*size/10.)]];
2936  gPE.erF[10]=0;
2937  for(int i=0;i<size;i++) {
2938  if(eres[i]<=jres) gPE.erF[10]+=1.;
2939  }
2940  gPE.erF[10]/=size;
2941  // print probability distribution of frequency residuals
2942  cout.precision(3);
2943  cout << endl << "gPE.erF : ";
2944  for(int i=0;i<10;i++) cout << gPE.erF[i] << "/";
2945  cout << gPE.erF[10] << endl << endl;
2946 
2947  return nrec;
2948 }
2949 
2951 
2952  wavearray<double> wf = *wf2;
2953  wf=0;
2954 
2955  if(wf1==NULL) return wf;
2956  if(wf1->size()==0) return wf;
2957 
2958  double R=wf1->rate();
2959 
2960  double b_wf1 = wf1->start();
2961  double e_wf1 = wf1->start()+wf1->size()/R;
2962  double b_wf2 = wf2->start();
2963  double e_wf2 = wf2->start()+wf2->size()/R;
2964 
2965  int o_wf1 = b_wf1>b_wf2 ? 0 : int((b_wf2-b_wf1)*R+0.5);
2966  int o_wf2 = b_wf1<b_wf2 ? 0 : int((b_wf1-b_wf2)*R+0.5);
2967 
2968  double startXCOR = b_wf1>b_wf2 ? b_wf1 : b_wf2;
2969  double endXCOR = e_wf1<e_wf2 ? e_wf1 : e_wf2;
2970  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
2971 
2972  for(int i=0;i<sizeXCOR;i++) wf[i+o_wf2] = wf1->data[i+o_wf1];
2973 
2974  return wf;
2975 }
2976 
2978 
2979  wavearray<double> wfq;
2980 
2981  if(wf==NULL) return wfq;
2982  if(wf->size()==0) return wfq;
2983 
2984  wfq = *wf;
2985 
2986  CWB::mdc::PhaseShift(wfq,90);
2987  for(int i=0;i<wf->size();i++) wfq[i] = sqrt(pow(wf->data[i],2)+pow(wfq[i],2));
2988 
2989  return wfq;
2990 }
2991 
2993 
2994  std::vector<float>* vP;
2995  std::vector<int>* vI;
2996 
2997  skymap skyprob = NET->getifo(0)->tau;
2998  skyprob = 0;
2999 
3000  // save the probability skymap
3001  if(NET->wc_List[0].p_Map.size()) {
3002 
3003  vP = &(NET->wc_List[0].p_Map[id-1]);
3004  vI = &(NET->wc_List[0].p_Ind[id-1]);
3005 
3006  skyprob = NET->getifo(0)->tau;
3007  skyprob = 0.;
3008 
3009  for(int j=0; j<int(vP->size()); j++) {
3010  int i = (*vI)[j];
3011  double th = skyprob.getTheta(i);
3012  double ph = skyprob.getPhi(i);
3013  int k=skyprob.getSkyIndex(th, ph);
3014  skyprob.set(k,(*vP)[j]);
3015  }
3016  }
3017 
3018  return skyprob;
3019 }
3020 
3021 void SaveSkyProb(network* NET, CWB::config* cfg, int id) {
3022 
3023  std::vector<float>* vP;
3024  std::vector<int>* vI;
3025 
3026  // save the probability skymap
3027  if(NET->wc_List[0].p_Map.size()) {
3028 
3029  vP = &(NET->wc_List[0].p_Map[id-1]);
3030  vI = &(NET->wc_List[0].p_Ind[id-1]);
3031 
3032  gSKYPROB = NET->getifo(0)->tau;
3033  gSKYPROB = 0.;
3034 
3035  for(int j=0; j<int(vP->size()); j++) {
3036  int i = (*vI)[j];
3037  double th = gSKYPROB.getTheta(i);
3038  double ph = gSKYPROB.getPhi(i);
3039  int k=gSKYPROB.getSkyIndex(th, ph);
3040  gSKYPROB.set(k,(*vP)[j]);
3041  }
3042  }
3043 
3044  gHSKYPROB.SetBins(gSKYPROB.size(),0,gSKYPROB.size()-1);
3045 
3046  double PROB=0;
3047  for(int l=0;l<gSKYPROB.size();l++) PROB+=gSKYPROB.get(l);
3048  cout << "PROB : " << PROB << endl;
3049  for(int l=0;l<gSKYPROB.size();l++) gHSKYPROB.SetBinContent(l,gSKYPROB.get(l));
3050 
3051 /*
3052  wavearray<int> index(gSKYPROB.size());
3053  wavearray<float> skyprob(gSKYPROB.size());
3054  for(int l=0;l<gSKYPROB.size();l++) skyprob[l]=gSKYPROB.get(l);
3055  TMath::Sort(int(gSKYPROB.size()),const_cast<float*>(skyprob.data),index.data,true);
3056  double THR = PROB>0.998 ? 0.998 : PROB;
3057  double prob=0;
3058  int L=0;
3059  skymap SkyMask = gSKYPROB;
3060  for(int l=0;l<gSKYPROB.size();l++) {
3061  prob+=skyprob[index[l]];
3062  if(prob>THR && L>1000) SkyMask.set(index[l],0); else {SkyMask.set(index[l],1);L++;}
3063  }
3064  cout << "PROB(0.99) : " << prob << " " << L << endl;
3065  //NET->setSkyMask(SkyMask,'e');
3066  //NET->setIndexMode(0);
3067 */
3068 
3069 #ifdef SAVE_SKYPROB
3070  // plot gSKYPROB
3072  //gSM.SetOptions("hammer","Celestial",2);
3073  gSM.SetOptions("","Geographic");
3074  gSM.SetZaxisTitle("probability");
3075  gSM.Draw(1);
3076  //TH2D* hsm = gSM.GetHistogram();
3077  //hsm->GetZaxis()->SetTitleOffset(0.85);
3078  //hsm->GetZaxis()->SetTitleSize(0.03);
3079  gSM.Print(TString::Format("%s/gSkyprob_%d.png",".",id));
3080 #endif
3081 }
3082 
3083 void PlotResiduals(int ID, TString pdir, int sim, char type) {
3084 
3085  std::vector<double > xRES = type=='f' ? fRES : vRES;
3086 
3087  int size = xRES.size()-1; // last index of xRES contains the residual of injection
3088  double jres = xRES[size]; // residual of injection
3089  if(size==0) return;
3090 
3091  double hmin=1e20;
3092  double hmax=0;
3093  for(int i=0;i<size;i++) {if(xRES[i]>hmax) hmax=xRES[i]; if(xRES[i]<hmin) hmin=xRES[i];}
3094  hmin-=0.4*(hmax-hmin);
3095  hmax+=0.4*(hmax-hmin);
3096  hmax*=1.2;if(hmax>1) hmax=1;
3097 
3098  // plot residuals
3099  TCanvas* cres = new TCanvas("residuals", "residuals", 200, 20, 600, 600);
3100  TH1F* hres = new TH1F("residuals","residuals",100,hmin,hmax);
3101  for(int i=0;i<size;i++) hres->Fill(xRES[i]);
3102 
3103  // make it cumulative
3104  double integral = hres->ComputeIntegral();
3105  if (integral==0) {cout << "PlotResiduals : Empty histogram !!!" << endl;return;}
3106  double* cumulative = hres->GetIntegral();
3107  for (int i=0;i<hres->GetNbinsX();i++) hres->SetBinContent(i,cumulative[i]/integral);
3108  //cout << "integral " << integral << endl;
3109  hres->SetLineWidth(2);
3110 
3111  hres->Draw();
3112 
3113  hres->GetXaxis()->SetTitle("residuals");
3114  hres->GetXaxis()->SetTitleOffset(1.4);
3115  hres->GetXaxis()->SetLabelOffset(0.02);
3116  hres->GetXaxis()->SetNoExponent();
3117  hres->GetXaxis()->SetMoreLogLabels();
3118  if(type=='f') {
3119  hres->GetXaxis()->SetRangeUser(0.001,1.0);
3120  } else {
3121  hres->GetXaxis()->SetRangeUser(0.01,1.0);
3122  }
3123 
3124  hres->GetYaxis()->SetTitle("probability");
3125  hres->GetYaxis()->SetTitleOffset(1.6);
3126  hres->GetYaxis()->SetLabelOffset(0.02);
3127  hres->GetYaxis()->SetNoExponent();
3128  hres->GetYaxis()->SetRangeUser(0.01,1.0);
3129 
3130  cres->SetLogx();
3131  cres->SetLogy();
3132  cres->SetGridx();
3133  cres->SetGridy();
3134 
3135  // draw vertical line at the jres value
3136  float ymax = hres->GetMaximum();
3137  TLine *line = new TLine(jres,0,jres,ymax);
3138  line->SetLineWidth(2);
3139  line->SetLineColor(kRed);
3140  if(sim) line->Draw();
3141 
3142  // print probability distribution of residuals
3143  cout.precision(3);
3144  if(type=='f') {
3145  cout << endl << "---------> gPE.erF : ";
3146  for(int i=0;i<10;i++) cout << gPE.erF[i] << "/";
3147  cout << gPE.erF[10] << endl << endl;
3148  } else {
3149  cout << endl << "---------> gPE.erR : ";
3150  for(int i=0;i<10;i++) cout << gPE.erR[i] << "/";
3151  cout << gPE.erR[10] << endl << endl;
3152  }
3153 
3154  gStyle->SetLineColor(kBlack);
3155  char title[256];
3156  if(type=='f') {
3157  sprintf(title,"Cumulative distribution of freq residuals errors (entries=%d - prob inj = %2.2g)",size,gPE.erF[10]);
3158  } else {
3159  sprintf(title,"Cumulative distribution of residuals errors (entries=%d - prob inj = %2.2g)",size,gPE.erR[10]);
3160  }
3161  hres->SetTitle(title);
3162  hres->SetStats(kFALSE);
3163  if(type=='f') {
3164  cres->Print(TString::Format("%s/fresiduals_errors.%s",pdir.Data(),PLOT_TYPE));
3165  } else {
3166  cres->Print(TString::Format("%s/residuals_errors.%s",pdir.Data(),PLOT_TYPE));
3167  }
3168 
3169  delete line;
3170  delete hres;
3171  delete cres;
3172 }
3173 
3174 void PlotSNRnet(int nIFO, TString pdir, int sim) {
3175 
3176  int size = sim ? iSNR[0].size() : vLIKELIHOOD.size();
3177  if(size==0) return;
3178 
3179  double hmin=1e20;
3180  double hmax=0;
3181  for(int i=0;i<size;i++) {
3182  double osnr=0;
3183  if(sim) for(int n=0;n<nIFO;n++) osnr+=oSNR[n][i];
3184  else osnr+=vLIKELIHOOD[i];
3185  osnr=sqrt(osnr);
3186  if(osnr>hmax) hmax=osnr;
3187  if(osnr<hmin) hmin=osnr;
3188  }
3189  hmin-=0.4*(hmax-hmin);
3190  hmax+=0.4*(hmax-hmin);
3191 
3192  double isnr=0;
3193  if(sim) {
3194  for(int n=0;n<nIFO;n++) isnr+=iSNR[n][0];
3195  isnr=sqrt(isnr);
3196  if(isnr<hmin) hmin=0.8*isnr;
3197  if(isnr>hmax) hmax=1.2*isnr;
3198  }
3199 
3200  // plot SNRnet
3201  TCanvas* csnr = new TCanvas("SNRnet", "SNRnet", 200, 20, 600, 600);
3202  TH1F* hsnr = new TH1F("SNRnet","SNRnet",10,hmin,hmax);
3203  for(int i=0;i<size;i++) {
3204  double osnr=0;
3205  if(sim) for(int n=0;n<nIFO;n++) osnr+=oSNR[n][i];
3206  else osnr+=vLIKELIHOOD[i];
3207  hsnr->Fill(sqrt(osnr));
3208  }
3209  hsnr->SetLineWidth(2);
3210 
3211  hsnr->Draw();
3212 
3213  hsnr->GetXaxis()->SetTitle("SNRnet");
3214  hsnr->GetXaxis()->SetTitleOffset(1.4);
3215  hsnr->GetXaxis()->SetLabelOffset(0.02);
3216  hsnr->GetXaxis()->SetNoExponent();
3217 
3218  hsnr->GetYaxis()->SetTitle("counts");
3219  hsnr->GetYaxis()->SetTitleOffset(1.6);
3220  hsnr->GetYaxis()->SetLabelOffset(0.02);
3221  hsnr->GetYaxis()->SetNoExponent();
3222 
3223  csnr->SetLogy();
3224  csnr->SetGridx();
3225  csnr->SetGridy();
3226 
3227  // draw vertical line at the jres value
3228  float ymax = hsnr->GetMaximum();
3229  TLine *line = new TLine(isnr,0,isnr,ymax);
3230  line->SetLineWidth(2);
3231  line->SetLineColor(kRed);
3232  if(sim) line->Draw();
3233 
3234  hsnr->Fit("gaus","q0");
3235  TF1* gauss = (TF1*)hsnr->GetFunction("gaus");
3236  if(gauss) {
3237  gauss->Draw("SAME");
3238  gauss->SetLineColor(kGreen);
3239  gauss->SetLineWidth(2);
3240  }
3241 
3242  char title[256];
3243  if(sim) sprintf(title,"SNRnet Distribution (entries=%d - SNRnet inj = %2.2g)",size,isnr);
3244  else sprintf(title,"SNRnet Distribution (entries=%d)",size);
3245  hsnr->SetTitle(title);
3246  hsnr->SetStats(kTRUE);
3247  csnr->Print(TString::Format("%s/SNRnet.%s",pdir.Data(),PLOT_TYPE));
3248  hsnr->SetStats(kFALSE);
3249 
3250  delete line;
3251  delete hsnr;
3252  delete csnr;
3253 }
3254 
3255 void PlotChirpMass(int gtype, TString pdir, int sim) {
3256 
3257  // gtype=1 -> reconstructed chirp mass
3258  // gtype=2 -> reconstructed chirp mass error
3259  // gtype=3 -> ellipticity parameter
3260  // gtype=4 -> pixel fraction
3261  // gtype=5 -> energy fraction
3262 
3263  if(gtype<1 || gtype>5) return;
3264 
3265  TString gname = "";
3266  if(gtype==1) gname="chirp_mass";
3267  if(gtype==2) gname="chirp_mass_err";
3268  if(gtype==3) gname="chirp_ell";
3269  if(gtype==4) gname="chirp_pfrac";
3270  if(gtype==5) gname="chirp_efrac";
3271 
3272  int size = vCHIRP[gtype].size();
3273  if(size==0) return;
3274 
3275  double hmin=1e20;
3276  double hmax=0;
3277  for(int i=0;i<size;i++) {
3278  double omchirp = vCHIRP[gtype][i]; // reconstructed mchirp
3279  if(omchirp>hmax) hmax=omchirp;
3280  if(omchirp<hmin) hmin=omchirp;
3281  }
3282  hmin-=0.4*(hmax-hmin);
3283  hmax+=0.4*(hmax-hmin);
3284 
3285  double imchirp=vCHIRP[0][0]; // injected mchirp
3286  if(sim && gtype==1) {
3287  if(imchirp<hmin) hmin=0.8*imchirp;
3288  if(imchirp>hmax) hmax=1.2*imchirp;
3289  }
3290 
3291  // plot mchirp
3292  TCanvas* cmchirp = new TCanvas("mchirp", "mchirp", 200, 20, 600, 600);
3293  TH1F* hmchirp = new TH1F("mchirp","mchirp",10,hmin,hmax);
3294  for(int i=0;i<size;i++) hmchirp->Fill(vCHIRP[gtype][i]);
3295  hmchirp->SetLineWidth(2);
3296 
3297  hmchirp->Draw();
3298 
3299  hmchirp->GetXaxis()->SetTitle(gname);
3300  hmchirp->GetXaxis()->SetTitleOffset(1.4);
3301  hmchirp->GetXaxis()->SetLabelOffset(0.02);
3302  hmchirp->GetXaxis()->SetNoExponent();
3303 
3304  hmchirp->GetYaxis()->SetTitle("counts");
3305  hmchirp->GetYaxis()->SetTitleOffset(1.6);
3306  hmchirp->GetYaxis()->SetLabelOffset(0.02);
3307  hmchirp->GetYaxis()->SetNoExponent();
3308 
3309  cmchirp->SetLogy();
3310  cmchirp->SetGridx();
3311  cmchirp->SetGridy();
3312 
3313  // draw vertical line at the jres value
3314  float ymax = hmchirp->GetMaximum();
3315  TLine *line = new TLine(imchirp,0,imchirp,ymax);
3316  line->SetLineWidth(2);
3317  line->SetLineColor(kRed);
3318  if(sim && gtype==1) line->Draw();
3319 /*
3320  hmchirp->Fit("gaus","q0");
3321  TF1* gaus = (TF1*)hmchirp->GetFunction("gaus");
3322  if(gaus) {
3323  gaus->Draw("SAME");
3324  gaus->SetLineColor(kGreen);
3325  gaus->SetLineWidth(2);
3326  }
3327 */
3328  gStyle->SetLineColor(kBlack);
3329  char title[256];
3330  if(sim && gtype==1) sprintf(title,"%s distribution (entries=%d - inj chirp mass = %2.2g)",gname.Data(),size,imchirp);
3331  else sprintf(title,"%s distribution (entries=%d)",gname.Data(),size);
3332  hmchirp->SetTitle(title);
3333  hmchirp->SetStats(kTRUE);
3334  cmchirp->Print(TString::Format("%s/%s.%s",pdir.Data(),gname.Data(),PLOT_TYPE));
3335  hmchirp->SetStats(kFALSE);
3336 
3337  delete line;
3338  delete hmchirp;
3339  delete cmchirp;
3340 }
3341 
3342 void PlotFactors(int gtype, int nIFO, TString pdir) {
3343 
3344  // if gtype=0 -> Fitting Factor
3345  // if gtype=1 -> Overlap Factor
3346 
3347  if(gtype!=0 && gtype!=1) return;
3348 
3349  int size = iSNR[0].size();
3350  if(size==0) return;
3351 
3352  double hmin=1e20;
3353  double hmax=0;
3354  for(int i=0;i<size;i++) {
3355  double isnr=0; for(int n=0;n<nIFO;n++) isnr+= iSNR[n][i];
3356  double osnr=0; for(int n=0;n<nIFO;n++) osnr+= oSNR[n][i];
3357  double iosnr=0; for(int n=0;n<nIFO;n++) iosnr+=ioSNR[n][i];
3358  double ff = iosnr/sqrt(isnr*isnr); // fitting factor
3359  double of = iosnr/sqrt(isnr*osnr); // overlap factor
3360  double factor = gtype==0 ? ff : of;
3361  if(factor>hmax) hmax=factor; if(factor<hmin) hmin=factor;
3362  }
3363  hmin-=0.4*(hmax-hmin);
3364  hmax+=0.4*(hmax-hmin);
3365 
3366  // plot Factors
3367  TCanvas* cf = new TCanvas("Factors", "Factors", 200, 20, 600, 600);
3368  TH1F* hf = new TH1F("Factors","Factors",10,hmin,hmax);
3369  for(int i=0;i<size;i++) {
3370  double isnr=0; for(int n=0;n<nIFO;n++) isnr+= iSNR[n][i];
3371  double osnr=0; for(int n=0;n<nIFO;n++) osnr+= oSNR[n][i];
3372  double iosnr=0; for(int n=0;n<nIFO;n++) iosnr+=ioSNR[n][i];
3373  double ff = iosnr/sqrt(isnr*isnr); // fitting factor
3374  double of = iosnr/sqrt(isnr*osnr); // overlap factor
3375  double factor = gtype==0 ? ff : of;
3376  hf->Fill(factor);
3377  }
3378  hf->SetLineWidth(2);
3379 
3380  hf->Draw();
3381 
3382  if(gtype==0) hf->GetXaxis()->SetTitle("Fitting Factor");
3383  if(gtype==1) hf->GetXaxis()->SetTitle("Overlap Factor");
3384  hf->GetXaxis()->SetTitleOffset(1.4);
3385  hf->GetXaxis()->SetLabelOffset(0.02);
3386  hf->GetXaxis()->SetNoExponent();
3387 
3388  hf->GetYaxis()->SetTitle("counts");
3389  hf->GetYaxis()->SetTitleOffset(1.6);
3390  hf->GetYaxis()->SetLabelOffset(0.02);
3391  hf->GetYaxis()->SetNoExponent();
3392 
3393  cf->SetLogy();
3394  cf->SetGridx();
3395  cf->SetGridy();
3396 
3397  char title[256];
3398  if(gtype==0) sprintf(title,"Fitting Factor Distribution (entries=%d)",size);
3399  if(gtype==1) sprintf(title,"Overlap Factor Distribution (entries=%d)",size);
3400  hf->SetTitle(title);
3401  gStyle->SetLineColor(kBlack);
3402  hf->SetStats(kTRUE);
3403  if(gtype==0) cf->Print(TString::Format("%s/FittingFactor.%s",pdir.Data(),PLOT_TYPE));
3404  if(gtype==1) cf->Print(TString::Format("%s/OverlapFactor.%s",pdir.Data(),PLOT_TYPE));
3405  hf->SetStats(kFALSE);
3406 
3407  delete hf;
3408  delete cf;
3409 }
3410 
3411 void GetNullStatistic(std::vector<double>* vNUL, std::vector<double>* vNSE, int ifoId, TString ifoName, TString gtype, TString pdir) {
3412 
3413  if(vNUL->size()==0 || vNSE->size()==0) return;
3414 
3415  double xmin=1e20;
3416  double xmax=0;
3417  for(int i=0;i<vNUL->size();i++) {
3418  if((*vNUL)[i]>xmax) xmax=(*vNUL)[i]; if((*vNUL)[i]<xmin) xmin=(*vNUL)[i];
3419  }
3420  xmin *= xmin>0 ? 0.5 : 1.5;
3421  xmax *= xmax>0 ? 1.5 : 0.5;
3422  if(fabs(xmin)>fabs(xmax)) xmax=fabs(xmin)*xmax/fabs(xmax); else xmin=fabs(xmax)*xmin/fabs(xmin);
3423 
3424  TH1F* hnul = new TH1F("null","null",10,xmin,xmax);
3425  for(int i=0;i<vNUL->size();i++) hnul->Fill((*vNUL)[i]);
3426  hnul->SetLineWidth(2);
3427  hnul->SetLineColor(kRed);
3428 
3429  TH1F* hnse = new TH1F("noise","noise",10,xmin,xmax);
3430  for(int i=0;i<vNSE->size();i++) hnse->Fill((*vNSE)[i]);
3431  double scale = double(hnul->GetEntries())/hnse->GetEntries();
3432  hnse->Scale(scale);
3433  hnse->SetLineWidth(2);
3434  hnse->SetLineColor(kBlack);
3435 
3436  double ymin=0.9;
3437  double ymax=0;
3438  for(int i=0;i<=hnul->GetNbinsX();i++) {
3439  double binc = hnul->GetBinContent(i);
3440  if(binc>ymax) ymax=binc;
3441  }
3442  for(int i=0;i<=hnse->GetNbinsX();i++) {
3443  double binc = hnse->GetBinContent(i);
3444  if(binc>ymax) ymax=binc;
3445  }
3446  ymax *= 1.1;
3447  hnse->GetYaxis()->SetRangeUser(ymin,ymax);
3448 
3449  double KS = hnul->Integral() ? hnul->KolmogorovTest(hnse,"N") : 0.;
3450  double AD = hnul->Integral() ? hnul->AndersonDarlingTest(hnse) : 0;
3451 
3452  hnul->Fit("gaus","q0");
3453  TF1* gaus = (TF1*)hnul->GetFunction("gaus");
3454  double chi2 = gaus ? gaus->GetChisquare()/gaus->GetNDF() : 0;
3455 
3456  if(pdir!="") {
3457  // plot null
3458  TCanvas* cnul = new TCanvas("cnull", "cnull", 200, 20, 600, 600);
3459 
3460  hnse->Draw();
3461  hnul->Draw("same");
3462 
3463  hnse->GetXaxis()->SetTitle(gtype);
3464  hnse->GetXaxis()->SetTitleOffset(1.4);
3465  hnse->GetXaxis()->SetLabelOffset(0.02);
3466  hnse->GetXaxis()->SetNoExponent();
3467 
3468  hnse->GetYaxis()->SetTitle("counts");
3469  hnse->GetYaxis()->SetTitleOffset(1.6);
3470  hnse->GetYaxis()->SetLabelOffset(0.02);
3471  hnse->GetYaxis()->SetNoExponent();
3472 
3473  cnul->SetLogy();
3474  cnul->SetGridx();
3475  cnul->SetGridy();
3476 
3477  hnse->Fit("gaus","q0");
3478  gaus = (TF1*)hnse->GetFunction("gaus");
3479  if(gaus) {
3480  gaus->Draw("SAME");
3481  gaus->SetLineColor(kGreen);
3482  gaus->SetLineWidth(2);
3483  }
3484 
3485  char title[256];
3486  sprintf(title,"%s : %s (entries=%d) : KS=%0.2f : AD=%0.2f : CHI2=%0.2f",ifoName.Data(),gtype.Data(),vNUL->size(),KS,AD,chi2);
3487  hnse->SetTitle(title);
3488  hnse->SetStats(kTRUE);
3489  cnul->Print(TString::Format("%s/%s_%s_dist.%s",pdir.Data(),ifoName.Data(),gtype.Data(),PLOT_TYPE));
3490  hnse->SetStats(kFALSE);
3491 
3492  delete hnul;
3493  delete hnse;
3494  delete cnul;
3495 
3496  } else { // fill gPE.nstat
3497 
3498  int I = 2*7*ifoId; // offset
3499  if(gtype=="null_90") I+=7;
3500 
3501  gPE.nstat[I+0] = hnul->GetMean();
3502  gPE.nstat[I+1] = hnul->GetRMS();
3503  gPE.nstat[I+2] = hnse->GetMean();
3504  gPE.nstat[I+3] = hnse->GetRMS();
3505  gPE.nstat[I+4] = chi2;
3506  gPE.nstat[I+5] = KS;
3507  gPE.nstat[I+6] = AD;
3508 
3509  cout << endl;
3510  cout << " Pixels Statistic : " << ifoName << " " << gtype << endl;
3511  cout << " Null Pixels Mean : " << gPE.nstat[I+0] << endl;
3512  cout << " Null Pixels RMS : " << gPE.nstat[I+1] << endl;
3513  cout << " Noise Pixels Mean : " << gPE.nstat[I+2] << endl;
3514  cout << " Noise Pixels RMS : " << gPE.nstat[I+3] << endl;
3515  cout << " Noise Pixels Chi2 : " << gPE.nstat[I+4] << endl;
3516  cout << " KolmogorovTest : " << gPE.nstat[I+5] << endl;
3517  cout << " AndersonDarlingTest : " << gPE.nstat[I+6] << endl;
3518  cout << endl;
3519 
3520  delete hnul;
3521  delete hnse;
3522  }
3523 }
3524 
3526 
3527  double a;
3528  double E=0.,T=0.;
3529  int size=(int)x.size();
3530  double rate=x.rate();
3531  for(int j=0;j<size;j++) {
3532  a = x[j];
3533  T += a*a*j/rate; // central time
3534  E += a*a; // energy
3535  }
3536  T = E>0 ? T/E : 0.5*size/rate;
3537 
3538  return T;
3539 }
3540 
3541 double GetTimeBoundaries(wavearray<double> x, double P, double& bT, double& eT) {
3542 
3543  if(P<0) P=0;
3544  if(P>1) P=1;
3545 
3546  int N = x.size();
3547 
3548  double E = 0; // signal energy
3549  double avr = 0; // average
3550  for(int i=0;i<N;i++) {avr+=i*x[i]*x[i]; E+=x[i]*x[i];}
3551  int M=int(avr/E); // central index
3552 
3553  // search range which contains percentage P of the total energy E
3554  int jB=0;
3555  int jE=N-1;
3556  double a,b;
3557  double sum = ((M>=0)&&(M<N)) ? x[M]*x[M] : 0.;
3558  for(int j=1; j<N; j++) {
3559  a = ((M-j>=0)&&(M-j<N)) ? x[M-j] : 0.;
3560  b = ((M+j>=0)&&(M+j<N)) ? x[M+j] : 0.;
3561  if(a) jB=M-j;
3562  if(b) jE=M+j;
3563  sum += a*a+b*b;
3564  if(sum/E > P) break;
3565  }
3566 
3567  bT = x.start()+jB/x.rate();
3568  eT = x.start()+jE/x.rate();
3569 
3570  return eT-bT;
3571 }
3572 
3574 
3575  double a;
3576  double E=0.,F=0.;
3577  int size=(int)x.size();
3578  double rate=x.rate();
3579  x.FFTW(1);
3580  double dF=(rate/(double)size)/2.;
3581  for(int j=0;j<size;j+=2) {
3582  a = x[j]*x[j]+x[j+1]*x[j+1];
3583  F += a*j*dF; // central frequency
3584  E += a; // energy
3585  }
3586  F = E>0 ? F/E : 0.5*rate;
3587 
3588  return F;
3589 }
3590 
3591 double GetFrequencyBoundaries(wavearray<double> x, double P, double& bF, double& eF) {
3592 
3593  if(P<0) P=0;
3594  if(P>1) P=1;
3595 
3596  int N = x.size();
3597 
3598  x.FFTW(1);
3599 
3600  double E = 0; // signal energy
3601  double avr = 0; // average
3602  for(int i=0;i<N;i++) {avr+=i*x[i]*x[i]; E+=x[i]*x[i];}
3603  int M=int(avr/E); // central index
3604 
3605  // search range which contains percentage P of the total energy E
3606  int jB=0;
3607  int jE=N-1;
3608  double a,b;
3609  double sum = ((M>=0)&&(M<N)) ? x[M]*x[M] : 0.;
3610  for(int j=1; j<N; j++) {
3611  a = ((M-j>=0)&&(M-j<N)) ? x[M-j] : 0.;
3612  b = ((M+j>=0)&&(M+j<N)) ? x[M+j] : 0.;
3613  if(a) jB=M-j;
3614  if(b) jE=M+j;
3615  sum += a*a+b*b;
3616  if(sum/E > P) break;
3617  }
3618 
3619  double dF=(x.rate()/(double)x.size())/2.;
3620 
3621  bF = jB*dF;
3622  eF = jE*dF;
3623 
3624  return eF-bF;
3625 }
3626 
3627 wavearray<double> GetCutWaveform(wavearray<double> x, double bT, double eT, double bF, double eF) {
3628 
3629  bT-=x.start();
3630  eT-=x.start();
3631 
3632  int size=(int)x.size();
3633 
3634  // cut time range bT,eT
3635  double T=0.;
3636  double dT = 1./x.rate();
3637  for(int j=0;j<size;j++) {
3638  T = j*dT;
3639  if(T<bT || T>eT) x[j]=0;
3640  }
3641 
3642  // cut frequency range bF,eF
3643  double F=0.;
3644  double dF=(x.rate()/(double)x.size())/2.;
3645  x.FFTW(1);
3646  for(int j=0;j<size;j+=2) {
3647  F = j*dF;
3648  if(F<bF || F>eF) {x[j]=0;x[j+1]=0;}
3649  }
3650  x.FFTW(-1);
3651 
3652  return x;
3653 }
3654 
3655 void SetWaveformCuts(wavearray<double>* x, double bT, double eT, double bF, double eF) {
3656 
3657  bT-=x->start();
3658  eT-=x->start();
3659 
3660  int size=(int)x->size();
3661 
3662  // cut time range bT,eT
3663  double T=0.;
3664  double dT = 1./x->rate();
3665  for(int j=0;j<size;j++) {
3666  T = j*dT;
3667  if(T<bT || T>eT) x->data[j]=0;
3668  }
3669 
3670  // cut frequency range bF,eF
3671  double F=0.;
3672  double dF=(x->rate()/(double)x->size())/2.;
3673  x->FFTW(1);
3674  for(int j=0;j<size;j+=2) {
3675  F = j*dF;
3676  if(F<bF || F>eF) {x->data[j]=0;x->data[j+1]=0;}
3677  }
3678  x->FFTW(-1);
3679 }
3680 
3681 TString DumpCED(network* NET, netevent* &EVT, CWB::config* cfg, double ofactor) {
3682 
3683  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
3684  int gIFACTOR=-1; IMPORT(int,gIFACTOR)
3685 
3686  int nIFO = NET->ifoListSize(); // number of detectors
3687  double factor = cfg->factors[gIFACTOR];
3688 
3689  char sfactor[32];
3690  if(cfg->simulation==3) {
3691  if(factor<0) sprintf(sfactor,"n%g",fabs(factor));
3692  if(factor==0) sprintf(sfactor,"z%g",factor);
3693  if(factor>0) sprintf(sfactor,"p%g",factor);
3694  } else sprintf(sfactor,"%g",factor);
3695 
3696  char out_CED[1024];
3697  if(cfg->simulation) {
3698  char sim_label[512];
3699  sprintf(sim_label,"%d_%d_%s_%s_job%d",int(gCWB2G->Tb),int(gCWB2G->dT),cfg->data_label,sfactor,gCWB2G->runID);
3700  sprintf(out_CED,"%s/ced_%s_%d",cfg->nodedir,sim_label,gSystem->GetPid());
3701  } else {
3702  char prod_label[512];
3703  sprintf(prod_label,"%d_%d_%s_slag%d_lag%lu_%lu_job%d",
3704  int(gCWB2G->Tb),int(gCWB2G->dT),cfg->data_label,gCWB2G->slagID,cfg->lagOff,cfg->lagSize,gCWB2G->runID);
3705  sprintf(out_CED,"%s/ced_%s_%d",cfg->nodedir,prod_label,gSystem->GetPid());
3706  }
3707  cout << out_CED << endl;
3708 
3709  // restore whitened data into the detector TF map
3710  if(gOPT.noise==0) {
3711  for(int n=0; n<nIFO; n++) {
3712  WSeries<double>* pTF = NET->getifo(n)->getTFmap();
3713  *pTF = gHOT[n];
3714  }
3715  }
3716 
3717  cout<<"DumpCED : dump ced to disk ..." <<endl;
3718  CWB::ced ced(NET, EVT, out_CED);
3719  cfg->cedRHO=0;
3720  switch(gCWB2G->istage) {
3721  case CWB_STAGE_FULL:
3722  case CWB_STAGE_INIT:
3723  // use TF map & inj signals
3724  ced.SetOptions(cfg->simulation,cfg->cedRHO,cfg->inRate);
3725  for(int n=0; n<nIFO; n++) {gCWB2G->pTF[n]->setlow(cfg->fLow); gCWB2G->pTF[n]->sethigh(cfg->fHigh);}
3726  break;
3727  default:
3728  // use sparse map & inj signals
3729  ced.SetOptions(cfg->simulation,cfg->cedRHO,cfg->inRate,true);
3730  }
3731  if(gCWB2G->singleDetector) ced.SetChannelName(cfg->channelNamesRaw[0]);
3732  bool fullCED = gCWB2G->singleDetector ? false : true;
3733  ced.Write(ofactor,fullCED);
3734 
3735  char ifostr[20]="";
3736  if(gCWB2G->singleDetector) {
3737  sprintf(ifostr,"%s%s",ifostr,NET->ifoName[0]);
3738  } else {
3739  for(int n=0; n<nIFO; n++) sprintf(ifostr,"%s%s",ifostr,NET->ifoName[n]);
3740  }
3741 
3742  char dirCED[1024];
3743  sprintf(dirCED, "%s/%s", out_CED, ifostr);
3744  if(gCWB2G->singleDetector) {
3745  sprintf(dirCED, "%s_%.3f",dirCED,EVT->start[0]);
3746  } else {
3747  for(int n=0; n<nIFO; n++) sprintf(dirCED, "%s_%.3f",dirCED,EVT->start[n]);
3748  }
3749 
3750  return dirCED;
3751 }
3752 
3753 void CreateIndexHTML(TString dirCED, int nIFO, TString* ifo, bool sim) {
3754 
3755  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
3756  if(gCWB2G->singleDetector) nIFO=1;
3757 
3758  // ------------------------------------------------------------------------------------
3759  // expand html file paths
3760  // ------------------------------------------------------------------------------------
3761 
3762  TString pe_index = gSystem->ExpandPathName(PE_INDEX);
3763 
3764  // ------------------------------------------------------------------------------------
3765  // check if environmental variables are defined
3766  // ------------------------------------------------------------------------------------
3767  if(gSystem->Getenv("HOME_CED_WWW")==NULL) {
3768  cout << "Error : environment HOME_CED_WWW is not defined!!! " << endl;exit(1);}
3769 
3770  char ofileName[256]="";
3771  sprintf(ofileName,"%s/pe_index.html",dirCED.Data());
3772  cout << "ofileName : " << ofileName << endl;
3773 
3774  // -------------------------------------------------------------------------------
3775  // open output file
3776  // -------------------------------------------------------------------------------
3777  ofstream out;
3778  out.open(ofileName,ios::out);
3779  if(!out.good()) {cout << "Error Opening File : " << ofileName << endl;exit(1);}
3780  // HEADER
3781  WriteBodyHTML(pe_index, "PE_HEADER_BEG", "PE_HEADER_END", &out);
3782  // BODY
3783  WriteBodyHTML(pe_index, "PE_BODY_BEG", "PE_BODY_END", &out);
3784  // TABBERS
3785  int sbody_height = 0;
3786  out << "<div class=\"tabber\">" << endl;
3787  // -------------------------------------------------------------------------------
3788  // Time-Frequency Maps
3789  // -------------------------------------------------------------------------------
3790  if(gOPT.ced_tfmap) {
3791  out << "<div class=\"tabbertab\">" << endl;
3792  out << " <h2>Time-Frequency Maps</h2>" << endl;
3793  sbody_height = 1000+nIFO*400;
3794  if(gOPT.ced_pca) sbody_height += 600;
3795  out << " <iframe src=\"tfmap_body.html\" width=\"100%\" "
3796  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3797  out << "</div>" << endl;
3798  }
3799  // -------------------------------------------------------------------------------
3800  // Reconstructed Detector Responses
3801  // -------------------------------------------------------------------------------
3802  if(gOPT.ced_rdr) {
3803  out << "<div class=\"tabbertab\">" << endl;
3804  out << " <h2>Reconstructed Detector Responses</h2>" << endl;
3805  if(!sim) sbody_height = 350+nIFO*450;
3806  else sbody_height = 350+nIFO*1340;
3807  out << " <iframe src=\"rec_signal_body.html\" width=\"100%\" "
3808  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3809  out << "</div>" << endl;
3810  }
3811  // -------------------------------------------------------------------------------
3812  // Power Spectral Density
3813  // -------------------------------------------------------------------------------
3814  if(gOPT.ced_psd) {
3815  out << "<div class=\"tabbertab\">" << endl;
3816  out << " <h2>PSD</h2>" << endl;
3817  sbody_height = 350+(nIFO+1)*750;
3818  out << " <iframe src=\"psd_body.html\" width=\"100%\" "
3819  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3820  out << "</div>" << endl;
3821  }
3822  // -------------------------------------------------------------------------------
3823  // SkyMaps
3824  // -------------------------------------------------------------------------------
3825  sbody_height = 2050;
3826  if(gOPT.ced_skymap && !gCWB2G->singleDetector) {
3827  out << "<div class=\"tabbertab\">" << endl;
3828  out << " <h2>SkyMaps</h2>" << endl;
3829  out << " <iframe src=\"skymap_body.html\" width=\"100%\" "
3830  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3831  out << "</div>" << endl;
3832  }
3833  // -------------------------------------------------------------------------------
3834  // Reconstructed vs Data/Average
3835  // -------------------------------------------------------------------------------
3836  if(gOPT.ced_rec) {
3837  out << "<div class=\"tabbertab\">" << endl;
3838  out << " <h2>Waveform Errors</h2>" << endl;
3839  sbody_height = 370+nIFO*880;
3840  out << " <iframe src=\"rec_avr_signal_body.html\" width=\"100%\" "
3841  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3842  out << "</div>" << endl;
3843  }
3844  // -------------------------------------------------------------------------------
3845  // Reconstructed vs Injection
3846  // -------------------------------------------------------------------------------
3847  if(sim && gOPT.ced_inj) {
3848  out << "<div class=\"tabbertab\">" << endl;
3849  out << " <h2>Injection</h2>" << endl;
3850  sbody_height = 390+nIFO*880;
3851  out << " <iframe src=\"rec_inj_signal_body.html\" width=\"100%\" "
3852  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3853  out << "</div>" << endl;
3854  }
3855  // -------------------------------------------------------------------------------
3856  // -------------------------------------------------------------------------------
3857  // Reconstructed vs Reduced Injection
3858  // -------------------------------------------------------------------------------
3859  if(sim && gOPT.ced_rinj) {
3860  out << "<div class=\"tabbertab\">" << endl;
3861  out << " <h2>Injection</h2>" << endl;
3862  sbody_height = 390+nIFO*320;
3863  out << " <iframe src=\"rec_inj_signal_body.html\" width=\"100%\" "
3864  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3865  out << "</div>" << endl;
3866  }
3867  // -------------------------------------------------------------------------------
3868  // Chirp Mass Distributions
3869  // -------------------------------------------------------------------------------
3870  if(gOPT.ced_cm) {
3871  sbody_height = 2100;
3872  out << "<div class=\"tabbertab\">" << endl;
3873  out << " <h2>Chirp Mass</h2>" << endl;
3874  out << " <iframe src=\"mchirp_body.html\" width=\"100%\" "
3875  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3876  out << "</div>" << endl;
3877  }
3878  // -------------------------------------------------------------------------------
3879  // Distributions
3880  // -------------------------------------------------------------------------------
3881  if(gOPT.ced_distr) {
3882  sbody_height = 2000;
3883  out << "<div class=\"tabbertab\">" << endl;
3884  out << " <h2>Distributions</h2>" << endl;
3885  out << " <iframe src=\"distribution_body.html\" width=\"100%\" "
3886  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3887  out << "</div>" << endl;
3888  }
3889  // -------------------------------------------------------------------------------
3890  // Null Pixels Distribution
3891  // -------------------------------------------------------------------------------
3892  if(gOPT.ced_null) {
3893  sbody_height = 100+nIFO*1300;
3894  out << "<div class=\"tabbertab\">" << endl;
3895  out << " <h2>Null Pixels</h2>" << endl;
3896  out << " <iframe src=\"nstat_body.html\" width=\"100%\" "
3897  << " height=\"" << sbody_height << "px\" frameborder=\"0\"></iframe>" << endl;
3898  out << "</div>" << endl;
3899  }
3900  // -------------------------------------------------------------------------------
3901  // close output file
3902  // -------------------------------------------------------------------------------
3903  out << "</div>" << endl;
3904  out.close();
3905 
3906 
3907  if(gOPT.ced_tfmap) {
3908  out.open(TString::Format("%s/tfmap_body.html",dirCED.Data()).Data(),ios::out);
3909  // TFMAPS
3910  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
3911  WriteBodyHTML(pe_index, "PE_TFMAP_HEADER_BEG", "PE_TFMAP_HEADER_END", &out);
3912  WriteBodyHTML(pe_index, "PE_TFMAP_BEG", "PE_TFMAP_END", &out, nIFO, ifo);
3913  // LIKELIHOOD
3914  out << "<p><br /></p> " << endl;
3915  out << "<p><br /></p> " << endl;
3916  WriteBodyHTML(pe_index, "PE_LIKELIHOOD_BEG", "PE_LIKELIHOOD_END", &out);
3917  // POLARGRAMS : NOT IMPLEMENTED IN WP !!!
3918  //out << "<p><br /></p> " << endl;
3919  //out << "<p><br /></p> " << endl;
3920  //WriteBodyHTML(pe_index, "PE_POLARGRAM_BEG", "PE_POLARGRAM_END", &out);
3921  if(gOPT.ced_pca) WriteBodyHTML(pe_index, "PE_PCA_BEG", "PE_PCA_END", &out);
3922  out.close();
3923  }
3924 
3925  // RECONSTRUCTED SIGNAL
3926  if(gOPT.ced_rdr) {
3927  out.open(TString::Format("%s/rec_signal_body.html",dirCED.Data()).Data(),ios::out);
3928  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
3929  WriteBodyHTML(pe_index, "PE_REC_SIGNAL_HEADER_BEG", "PE_REC_SIGNAL_HEADER_END", &out);
3930  for(int n=0;n<nIFO;n++) {
3931  WriteBodyHTML(pe_index, "PE_IFO_SIGNAL_BEG", "PE_IFO_SIGNAL_END", &out, 1, &ifo[n]);
3932  if(sim) {
3933  WriteBodyHTML(pe_index, "PE_INJ_SIGNAL_BEG", "PE_INJ_SIGNAL_END", &out, 1, &ifo[n]);
3934  }
3935  WriteBodyHTML(pe_index, "PE_REC_SIGNAL_BEG", "PE_REC_SIGNAL_END", &out, 1, &ifo[n]);
3936  out << "<p><br /></p> " << endl;
3937  out << "<p><br /></p> " << endl;
3938  }
3939  out.close();
3940  }
3941 
3942  // PSD
3943  if(gOPT.ced_psd) {
3944  out.open(TString::Format("%s/psd_body.html",dirCED.Data()).Data(),ios::out);
3945  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
3946  WriteBodyHTML(pe_index, "PE_PSD_HEADER_BEG", "PE_PSD_HEADER_END", &out);
3947  for(int n=0;n<nIFO;n++) {
3948  WriteBodyHTML(pe_index, "PE_IFO_PSD_BEG", "PE_IFO_PSD_END", &out, 1, &ifo[n]);
3949  WriteBodyHTML(pe_index, "PE_PSD_BEG", "PE_PSD_END", &out, 1, &ifo[n]);
3950  out << "<p><br /></p> " << endl;
3951  out << "<p><br /></p> " << endl;
3952  }
3953  out.close();
3954  }
3955 
3956  // SKYMAP
3957  if(gOPT.ced_skymap && !gCWB2G->singleDetector) {
3958  out.open(TString::Format("%s/skymap_body.html",dirCED.Data()).Data(),ios::out);
3959  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
3960  WriteBodyHTML(pe_index, "PE_SKYMAP_BEG", "PE_SKYMAP_END", &out);
3961  out.close();
3962  }
3963 
3964  // RECONSTRUCTED vs DATA/AVERAGE
3965  if(gOPT.ced_rec) {
3966  out.open(TString::Format("%s/rec_avr_signal_body.html",dirCED.Data()).Data(),ios::out);
3967  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
3968  WriteBodyHTML(pe_index, "PE_REC_AVR_SIGNAL_HEADER_BEG", "PE_REC_AVR_SIGNAL_HEADER_END", &out);
3969  for(int n=0;n<nIFO;n++) {
3970  WriteBodyHTML(pe_index, "PE_REC_AVR_SIGNAL_BEG", "PE_REC_AVR_SIGNAL_END", &out, 1, &ifo[n]);
3971  out << "<p><br /></p> " << endl;
3972  out << "<p><br /></p> " << endl;
3973  }
3974  out.close();
3975  }
3976 
3977  // RECONSTRUCTED vs INJECTED
3978  if(sim && (gOPT.ced_inj || gOPT.ced_rinj)) {
3979  out.open(TString::Format("%s/rec_inj_signal_body.html",dirCED.Data()).Data(),ios::out);
3980  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
3981  if(gOPT.ced_inj) WriteBodyHTML(pe_index, "PE_REC_INJ_SIGNAL_0_HEADER_BEG", "PE_REC_INJ_SIGNAL_0_HEADER_END", &out);
3982  if(gOPT.ced_rinj) WriteBodyHTML(pe_index, "PE_REC_INJ_SIGNAL_HEADER_BEG", "PE_REC_INJ_SIGNAL_HEADER_END", &out);
3983  if(sim) {
3984  for(int n=0;n<nIFO;n++) {
3985  if(gOPT.ced_inj) WriteBodyHTML(pe_index, "PE_REC_INJ_SIGNAL_0_BEG", "PE_REC_INJ_SIGNAL_0_END", &out, 1, &ifo[n]);
3986  if(gOPT.ced_rinj) WriteBodyHTML(pe_index, "PE_REC_INJ_SIGNAL_BEG", "PE_REC_INJ_SIGNAL_END", &out, 1, &ifo[n]);
3987  out << "<p><br /></p> " << endl;
3988  out << "<p><br /></p> " << endl;
3989  }
3990  }
3991  out.close();
3992  }
3993 
3994 
3995  // DISTRIBUTION
3996  if(gOPT.ced_distr) {
3997  out.open(TString::Format("%s/distribution_body.html",dirCED.Data()).Data(),ios::out);
3998  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
3999  WriteBodyHTML(pe_index, "PE_DISTRIBUTION_BEG", "PE_DISTRIBUTION_END", &out);
4000  if(sim) WriteBodyHTML(pe_index, "PE_FACTORS_DISTRIBUTION_BEG", "PE_FACTORS_DISTRIBUTION_END", &out);
4001  out.close();
4002  }
4003 
4004  // NULL PIXELS DISTRIBUTION
4005  if(gOPT.ced_null) {
4006  out.open(TString::Format("%s/nstat_body.html",dirCED.Data()).Data(),ios::out);
4007  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
4008  WriteBodyHTML(pe_index, "PE_NULPIX_DISTRIBUTION_HEADER_BEG", "PE_NULPIX_DISTRIBUTION_HEADER_END", &out);
4009  for(int n=0;n<nIFO;n++) {
4010  WriteBodyHTML(pe_index, "PE_NULPIX_DISTRIBUTION_BEG", "PE_NULPIX_DISTRIBUTION_END", &out, 1, &ifo[n]);
4011  out << "<p><br /></p> " << endl;
4012  out << "<p><br /></p> " << endl;
4013  }
4014  out.close();
4015  }
4016 
4017  // MCHIRP DISTRIBUTION
4018  if(gOPT.ced_cm) {
4019  out.open(TString::Format("%s/mchirp_body.html",dirCED.Data()).Data(),ios::out);
4020  WriteBodyHTML(pe_index, "PE_JSCRIPT_BEG", "PE_JSCRIPT_END", &out);
4021  WriteBodyHTML(pe_index, "PE_MCHIRP_DISTRIBUTION_HEADER_BEG", "PE_MCHIRP_DISTRIBUTION_HEADER_END", &out);
4022  WriteBodyHTML(pe_index, "PE_MCHIRP_DISTRIBUTION_BEG", "PE_MCHIRP_DISTRIBUTION_END", &out);
4023  out.close();
4024  }
4025 
4026  // copy tabber javascript to CED directory
4027  char cmd[1024];
4028  sprintf(cmd,"cp ${HOME_WAT}//html/etc/html/tabber.css %s",dirCED.Data());
4029  gSystem->Exec(cmd);
4030  sprintf(cmd,"cp ${HOME_WAT}//html/etc/html/tabber.js %s",dirCED.Data());
4031  gSystem->Exec(cmd);
4032  // overwrite CED index.html
4033  sprintf(cmd,"mv %s/pe_index.html %s/index.html",dirCED.Data(),dirCED.Data());
4034  gSystem->Exec(cmd);
4035 
4036  return;
4037 }
4038 
4039 void WriteBodyHTML(TString html_template, TString html_tag_beg, TString html_tag_end, ofstream* out, int nIFO, TString* ifo) {
4040 
4041  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
4042  if(gCWB2G->singleDetector) nIFO=1;
4043 
4044  // get SITE_CLUSTER
4045  TString site_cluster="VIRTUALBOX"; // default value
4046  if(gSystem->Getenv("SITE_CLUSTER")!=NULL) {
4047  site_cluster=TString(gSystem->Getenv("SITE_CLUSTER"));
4048  }
4049  TString cluster_site_logo = "cluster_site_logo_modern.png";
4050  TString cluster_site_url1 = "http://www.ligo.caltech.edu/";
4051  TString cluster_site_name1 = "LIGO Homepage";
4052  TString cluster_site_url2 = "https://www.virgo-gw.eu/";
4053  TString cluster_site_name2 = "VIRGO Homepage";
4054  if(site_cluster=="ATLAS") {
4055  cluster_site_logo = "atlas_logo_modern.png";
4056  cluster_site_url1 = "http://www.aei.mpg.de/14026/AEI_Hannover/";
4057  cluster_site_name1 = "AEI Hannover Homepage";
4058  cluster_site_url2 = "http://www.aei.mpg.de/14026/AEI_Hannover";
4059  cluster_site_name2 = "AEI Hannover Homepage";
4060  }
4061  if(site_cluster=="CIT") {
4062  cluster_site_logo = "ligo_virgo_logo_modern.png";
4063  cluster_site_url1 = "http://www.ligo.caltech.edu/";
4064  cluster_site_name1 = "LIGO Homepage";
4065  cluster_site_url2 = "https://www.virgo-gw.eu/";
4066  cluster_site_name2 = "VIRGO Homepage";
4067  }
4068  if(site_cluster=="VIRTUALBOX") {
4069  cluster_site_logo = "cluster_site_logo_modern.png";
4070  cluster_site_url1 = "https://www.gw-openscience.org/about/";
4071  cluster_site_name1 = "GWOSC Homepage";
4072  cluster_site_url2 = "https://www.gw-openscience.org/about/";
4073  cluster_site_name2 = "GWOSC Homepage";
4074  }
4075 
4076  // get HOME_WWW
4077  TString home_www="~waveburst/waveburst"; // default value
4078  if(gSystem->Getenv("HOME_WWW")!=NULL) {
4079  home_www=TString(gSystem->Getenv("HOME_WWW"));
4080  }
4081 
4082  // get HOME_CED_WWW
4083  TString home_ced_www="~waveburst/waveburst/ced-1.0-modern"; // default value
4084  if(gSystem->Getenv("HOME_CED_WWW")!=NULL) {
4085  home_ced_www=TString(gSystem->Getenv("HOME_CED_WWW"));
4086  }
4087 
4088  // get CWB_DOC_URL
4089  TString cwb_doc_url="https://ldas-jobs.ligo.caltech.edu/~waveburst/doc"; // default value
4090  if(gSystem->Getenv("CWB_DOC_URL")!=NULL) {
4091  cwb_doc_url=TString(gSystem->Getenv("CWB_DOC_URL"));
4092  }
4093 
4094  // get CWB_GIT_URL
4095  TString cwb_git_url="https://git.ligo.org"; // default value
4096  if(gSystem->Getenv("CWB_GIT_URL")!=NULL) {
4097  cwb_git_url=TString(gSystem->Getenv("CWB_GIT_URL"));
4098  }
4099 
4100  // get issues URL (Ex: https://gitlab.com/groups/gwburst/-/issues)
4101  TString cwb_git_issues_url=cwb_git_url;
4102  TString partA=cwb_git_issues_url;
4103  TString partB=cwb_git_issues_url;
4104  partA.Remove(partA.Last('/'),partA.Sizeof()-1);
4105  partB.Remove(0,partB.Last('/')+1);
4106  cwb_git_issues_url=partA+"/groups/"+partB+"/-/issues";
4107 
4108 
4109  char line[1024];
4110  bool output=false;
4111  for(int n=0;n<nIFO;n++) {
4112  ifstream in;
4113  in.open(html_template.Data(),ios::in);
4114  if(!in.good()) {cout << "Error Opening File : " << html_template.Data() << endl;exit(1);}
4115  while(1) {
4116  in.getline(line,1024);
4117  if(!in.good()) break;
4118  TString sline = line;
4119  if(sline.Contains(html_tag_beg)&&!output) output=true;
4120  if(sline.Contains(html_tag_end)&& output) {output=false;break;}
4121  if(ifo!=NULL) sline.ReplaceAll("IFO",ifo[n]);
4122  sline.ReplaceAll("xNTRIALS",TString::Format("%d",(int)vCHIRP[0].size()-1).Data());
4123  sline.ReplaceAll("xINRATE",TString::Format("%d",(int)gINRATE));
4124  sline.ReplaceAll("xRATEANA",TString::Format("%d",(int)gRATEANA));
4125 #ifdef PLOT_MEDIAN
4126  sline.ReplaceAll("xMEAN","Median");
4127  sline.ReplaceAll("xSIGMA","50% Percentile");
4128  sline.ReplaceAll("x2SIGMA","90% Percentile");
4129 #else
4130  sline.ReplaceAll("xMEAN","Mean");
4131  sline.ReplaceAll("xSIGMA","RMS");
4132  sline.ReplaceAll("x2SIGMA","2RMS");
4133 #endif
4134  sline.ReplaceAll("HOME_CED_WWW",home_ced_www.Data());
4135  sline.ReplaceAll("CWB_DOC_URL",cwb_doc_url.Data());
4136  sline.ReplaceAll("HOME_WWW",home_www.Data());
4137  if(cwb_doc_url!="") {
4138  sline.ReplaceAll("<!--CWB_DOC_URL","");
4139  sline.ReplaceAll("CWB_DOC_URL-->","");
4140  sline.ReplaceAll("XCWB_DOC_URL",cwb_doc_url.Data());
4141  }
4142  // replace HOME_CED_WWW, HOME_CED_WWW, CWB_DOC_URL with used defined values (watenv)
4143  sline.ReplaceAll("HOME_WWW",home_www);
4144  sline.ReplaceAll("HOME_CED_WWW",home_ced_www);
4145  if(cwb_doc_url.Contains("gwburst.gitlab.io")) { // public cWB documentation
4146  sline.ReplaceAll("/CWB_DOC_URL/cwb/man",cwb_doc_url);
4147  } else {
4148  sline.ReplaceAll("CWB_DOC_URL",cwb_doc_url);
4149  }
4150  sline.ReplaceAll("CWB_GIT_URL",cwb_git_url);
4151  sline.ReplaceAll("CWB_GIT_ISSUES_URL",cwb_git_issues_url);
4152  sline.ReplaceAll("CLUSTER_SITE_LOGO",cluster_site_logo);
4153  sline.ReplaceAll("CLUSTER_SITE_URL1",cluster_site_url1);
4154  sline.ReplaceAll("CLUSTER_SITE_NAME1",cluster_site_name1);
4155  sline.ReplaceAll("CLUSTER_SITE_URL2",cluster_site_url2);
4156  sline.ReplaceAll("CLUSTER_SITE_NAME2",cluster_site_name2);
4157 
4158  sline.ReplaceAll(TString("=\"/http"), TString("=\"http"));
4159  sline.ReplaceAll(TString("=\"//"), TString("=\"/"));
4160 
4161  if(output) (*out) << sline.Data() << endl;
4162  }
4163  in.close();
4164  }
4165 }
4166 
4167 void
4169 
4170  int n;
4171 
4172  n = ifo->IWFP.size();
4173  for (int i=0;i<n;i++) {
4175  delete wf;
4176  }
4177  ifo->IWFP.clear();
4178  ifo->IWFID.clear();
4179 
4180  n = ifo->RWFP.size();
4181  for (int i=0;i<n;i++) {
4183  delete wf;
4184  }
4185  ifo->RWFP.clear();
4186  ifo->RWFID.clear();
4187 }
4188 
4190  wavearray<double>* favr, wavearray<double>* ferr, wavearray<double>* wref, TString pdir, double P) {
4191 
4192  int size = frec->size();
4193 
4194  wavearray<double> time(size);
4195  wavearray<double> etime(size); etime=0;
4196  for (int i=0; i<size; i++) time.data[i] = i/frec->rate()+(wref->start()-gSEGGPS);
4197 
4198  wavearray<double> f2err=*ferr; f2err*=2.;
4199 
4200  TString xtitle = TString::Format("Time (sec) : GPS OFFSET = %.3f",gSEGGPS);
4201 
4202  double bT, eT;
4203  GetTimeBoundaries(*wref, P, bT, eT);
4204  bT-=gSEGGPS;
4205  eT-=gSEGGPS;
4206  for(int i=0;i<frec->size();i++) {
4207  double xtime = i/wref->rate();
4208  if(xtime>bT && xtime<eT) continue;
4209  frec->data[i]=0;
4210  favr->data[i]=0;
4211  ferr->data[i]=0;
4212  f2err.data[i]=0;
4213  }
4214 
4215  TGraphErrors* e2gr = new TGraphErrors(size,time.data,favr->data,etime.data,f2err.data);
4216  e2gr->SetLineColor(17);
4217  e2gr->SetFillStyle(1001);
4218  e2gr->SetFillColor(17);
4219  e2gr->GetXaxis()->SetTitle(xtitle);
4220  e2gr->GetYaxis()->SetTitle("frequency (hz)");
4221  e2gr->SetTitle(title);
4222  e2gr->GetXaxis()->SetTitleFont(42);
4223  e2gr->GetXaxis()->SetLabelFont(42);
4224  e2gr->GetXaxis()->SetLabelOffset(0.012);
4225  e2gr->GetXaxis()->SetTitleOffset(1.5);
4226  e2gr->GetYaxis()->SetTitleFont(42);
4227  e2gr->GetYaxis()->SetLabelFont(42);
4228  e2gr->GetYaxis()->SetLabelOffset(0.01);
4229  e2gr->GetYaxis()->SetTitleOffset(1.4);
4230 
4231 
4232  TGraphErrors* egr = new TGraphErrors(size,time.data,favr->data,etime.data,ferr->data);
4233  egr->SetLineColor(15);
4234  egr->SetFillStyle(1001);
4235  egr->SetFillColor(15);
4236 
4237  TGraph* agr = new TGraph(size,time.data,favr->data);
4238  agr->SetLineWidth(1);
4239  agr->SetLineColor(kWhite);
4240  agr->SetLineStyle(1);
4241 
4242  TGraph* gr = new TGraph(size,time.data,frec->data);
4243  gr->SetLineWidth(1);
4244  gr->SetLineColor(2);
4245 
4246  TCanvas* canvas = new TCanvas("frec", "frec",200,20,800,500);
4247  canvas->cd();
4248  canvas->SetGridx();
4249  canvas->SetGridy();
4250 
4251  e2gr->GetXaxis()->SetRangeUser(bT, eT);
4252  e2gr->Draw("AP4");
4253  egr->Draw("P4same");
4254  agr->Draw("Lsame");
4255  gr->Draw("Lsame");
4256 
4257  if(ofname!="") {
4258  ofname = TString(pdir)+TString("/")+ofname;
4259  canvas->Print(ofname);
4260  cout << "write : " << ofname << endl;
4261  }
4262 
4263  delete canvas;
4264  delete e2gr;
4265  delete egr;
4266  delete agr;
4267  delete gr;
4268 }
4269 
4271  wavearray<double>* wavr, wavearray<double>* werr, wavearray<double>* wref, TString pdir, double P) {
4272 
4273  int size = wrec->size();
4274 
4275  wavearray<double> time(size);
4276  wavearray<double> etime(size); etime=0;
4277  for (int i=0; i<size; i++) time.data[i] = i/wrec->rate()+(wref->start()-gSEGGPS);
4278 
4279  wavearray<double> w2err=*werr; w2err*=2.;
4280 
4281  TString xtitle = TString::Format("Time (sec) : GPS OFFSET = %.3f",gSEGGPS);
4282 
4283  TGraphErrors* e2gr = new TGraphErrors(size,time.data,wavr->data,etime.data,w2err.data);
4284  e2gr->SetLineColor(17);
4285  e2gr->SetFillStyle(1001);
4286  e2gr->SetFillColor(17);
4287  e2gr->GetXaxis()->SetTitle(xtitle);
4288  e2gr->GetYaxis()->SetTitle("magnitude");
4289  e2gr->SetTitle(title);
4290  e2gr->GetXaxis()->SetTitleFont(42);
4291  e2gr->GetXaxis()->SetLabelFont(42);
4292  e2gr->GetXaxis()->SetLabelOffset(0.012);
4293  e2gr->GetXaxis()->SetTitleOffset(1.5);
4294  e2gr->GetYaxis()->SetTitleFont(42);
4295  e2gr->GetYaxis()->SetLabelFont(42);
4296  e2gr->GetYaxis()->SetLabelOffset(0.01);
4297  e2gr->GetYaxis()->SetTitleOffset(1.4);
4298 
4299  TGraphErrors* egr = new TGraphErrors(size,time.data,wavr->data,etime.data,werr->data);
4300  egr->SetLineColor(15);
4301  egr->SetFillStyle(1001);
4302  egr->SetFillColor(15);
4303 
4304  TGraph* agr = new TGraph(size,time.data,wavr->data);
4305  agr->SetLineWidth(1);
4306  agr->SetLineColor(kWhite);
4307  agr->SetLineStyle(1);
4308 
4309  TGraph* gr = new TGraph(size,time.data,wrec->data);
4310  gr->SetLineWidth(1);
4311  gr->SetLineColor(2);
4312 
4313  TCanvas* canvas = new TCanvas("wrec", "wrec",200,20,800,500);
4314  canvas->cd();
4315  canvas->SetGridx();
4316  canvas->SetGridy();
4317 
4318  double bT, eT;
4319  GetTimeBoundaries(*wref, P, bT, eT);
4320  bT-=gSEGGPS;
4321  eT-=gSEGGPS;
4322  e2gr->GetXaxis()->SetRangeUser(bT, eT);
4323  e2gr->Draw("A3");
4324  egr->Draw("3same");
4325  agr->Draw("Lsame");
4326  gr->Draw("Lsame");
4327 
4328  if(ofname!="") {
4329  ofname = TString(pdir)+TString("/")+ofname;
4330  canvas->Print(ofname);
4331  cout << "write : " << ofname << endl;
4332  }
4333 
4334  delete canvas;
4335  delete e2gr;
4336  delete egr;
4337  delete agr;
4338  delete gr;
4339 }
4340 
4343  wavearray<double>* wl90, wavearray<double>* wu90, wavearray<double>* wref, TString pdir, double P, bool freq) {
4344 
4345  int size = wrec->size();
4346 
4347  wavearray<double> time(size);
4348  wavearray<double> etime(size); etime=0;
4349  for (int i=0; i<size; i++) time[i] = i/wrec->rate()+(wref->start()-gSEGGPS);
4350 
4351  double bT, eT;
4352  GetTimeBoundaries(*wref, P, bT, eT);
4353  bT-=gSEGGPS;
4354  eT-=gSEGGPS;
4355 
4356  // set to 0 the frequency values outside the time range -> fix the y scale autoscale
4357  // info : this procedure modify the frequency input data but it is not relevant
4358  if(freq) {
4359  for(int i=0;i<wrec->size();i++) {
4360  if(time[i]>bT && time[i]<eT) continue;
4361  wrec->data[i]=0; wmed->data[i]=0; wl50->data[i]=0; wu50->data[i]=0; wl90->data[i]=0; wu90->data[i]=0;
4362  }
4363  }
4364 
4365  TString xtitle = TString::Format("Time (sec) : GPS OFFSET = %.3f",gSEGGPS);
4366 
4367  TGraphAsymmErrors* egr90 = new TGraphAsymmErrors(size,time.data,wmed->data,etime.data,etime.data,wl90->data,wu90->data);
4368  egr90->SetLineColor(17);
4369  egr90->SetFillStyle(1001);
4370  egr90->SetFillColor(17);
4371  egr90->GetXaxis()->SetTitle(xtitle);
4372  if(freq) egr90->GetYaxis()->SetTitle("frequency (hz)");
4373  else egr90->GetYaxis()->SetTitle("magnitude");
4374  egr90->SetTitle(title);
4375  egr90->GetXaxis()->SetTitleFont(42);
4376  egr90->GetXaxis()->SetLabelFont(42);
4377  egr90->GetXaxis()->SetLabelOffset(0.012);
4378  egr90->GetXaxis()->SetTitleOffset(1.5);
4379  egr90->GetYaxis()->SetTitleFont(42);
4380  egr90->GetYaxis()->SetLabelFont(42);
4381  egr90->GetYaxis()->SetLabelOffset(0.01);
4382  egr90->GetYaxis()->SetTitleOffset(1.4);
4383 
4384  TGraphAsymmErrors* egr50 = new TGraphAsymmErrors(size,time.data,wmed->data,etime.data,etime.data,wl50->data,wu50->data);
4385  egr50->SetLineColor(15);
4386  egr50->SetFillStyle(1001);
4387  egr50->SetFillColor(15);
4388 
4389  TGraph* agr = new TGraph(size,time.data,wmed->data);
4390  agr->SetLineWidth(1);
4391  agr->SetLineColor(kWhite);
4392  agr->SetLineStyle(1);
4393 
4394  TGraph* gr = new TGraph(size,time.data,wrec->data);
4395  gr->SetLineWidth(1);
4396  gr->SetLineColor(2);
4397 
4398  TCanvas* canvas = new TCanvas("wrec", "wrec",200,20,800,500);
4399  canvas->cd();
4400  canvas->SetGridx();
4401  canvas->SetGridy();
4402 
4403  egr90->GetXaxis()->SetRangeUser(bT, eT);
4404  egr90->Draw("A3");
4405  egr50->Draw("3same");
4406  agr->Draw("Lsame");
4407  gr->Draw("Lsame");
4408 
4409  if(ofname!="") {
4410  ofname = TString(pdir)+TString("/")+ofname;
4411  canvas->Print(ofname);
4412  cout << "write : " << ofname << endl;
4413  }
4414 
4415  delete canvas;
4416  delete egr50;
4417  delete egr90;
4418  delete agr;
4419  delete gr;
4420 }
4421 
4422 // Dumps reconstructed waveform/time/freq/errors array in ASCII format.
4424 
4425  int nIFO = NET->ifoListSize(); // number of detectors
4426 
4427  char ofname[256];
4428  for(int n=0; n<nIFO; n++) {
4429 
4430  sprintf(ofname,"%s/%s_pe_wave.dat",pdir.Data(),NET->ifoName[n]);
4431 
4432  ofstream out;
4433  out.open(ofname,ios::out);
4434  if (!out.good()) {cout << "Error Opening Output File : " << ofname << endl;exit(1);}
4435  cout << "Create Output File : " << ofname << endl;
4436  out.precision(19);
4437 
4438  // write header
4439  out << "#whitened data : time," <<
4440  " amp_point, amp_mean, amp_rms," <<
4441  " amp_median, amp_lower_50_perc, amp_lower_90_perc, amp_upper_50_perc, amp_upper_90_perc," <<
4442  " frq_point, frq_mean, frq_rms," <<
4443  " frq_median, frq_lower_50_perc, frq_lower_90_perc, frq_upper_50_perc, frq_upper_90_perc" << endl;
4444 
4445  // write data
4446  int size = vREC[n].size();
4447  double dt=1./vREC[n].rate();
4448  //netcluster* pwc = NET->getwc(0);
4449  //detector* pD = NET->getifo(n);
4450  //double toffset = pwc->start+pD->waveForm.start();
4451  for (int i=0; i<size; i++) {
4452  double time = i*dt+vREC[n].start();
4453 
4454  double vl50 = vMED[n][i]-fabs(vL50[n][i]);
4455  double vu50 = vMED[n][i]+fabs(vU50[n][i]);
4456  double vl90 = vMED[n][i]-fabs(vL90[n][i]);
4457  double vu90 = vMED[n][i]+fabs(vU90[n][i]);
4458 
4459  double fl50 = fMED[n][i]-fabs(fL50[n][i]);
4460  double fu50 = fMED[n][i]+fabs(fU50[n][i]);
4461  double fl90 = fMED[n][i]-fabs(fL90[n][i]);
4462  double fu90 = fMED[n][i]+fabs(fU90[n][i]);
4463 
4464  out << time
4465  << " " << vREC[n][i] << " " << vAVR[n][i] << " " << vRMS[n][i]
4466  << " " << vMED[n][i] << " " << vl50 << " " << vl90 << " " << vu50 << " " << vu90
4467  << " " << fREC[n][i] << " " << fAVR[n][i] << " " << fRMS[n][i]
4468  << " " << fMED[n][i] << " " << fl50 << " " << fl90 << " " << fu50 << " " << fu90
4469  << endl;
4470  }
4471 
4472  out.close();
4473  }
4474 }
4475 
4476 // Dumps injected waveform/time array in ASCII format.
4478 
4479  int nIFO = NET->ifoListSize(); // number of detectors
4480 
4481  char ofname[256];
4482  for(int n=0; n<nIFO; n++) {
4483 
4484  sprintf(ofname,"%s/%s_inj_pe.dat",pdir.Data(),NET->ifoName[n]);
4485 
4486  ofstream out;
4487  out.open(ofname,ios::out);
4488  if (!out.good()) {cout << "Error Opening Output File : " << ofname << endl;exit(1);}
4489  cout << "Create Output File : " << ofname << endl;
4490  out.precision(19);
4491 
4492  // write header
4493  out << "# time white_amp" << endl;
4494 
4495  // write data
4496  int size = vINJ[n].size();
4497  double dt=1./vINJ[n].rate();
4498  for (int i=0; i<size; i++) {
4499  double time = i*dt+vINJ[n].start();
4500  out << time << " " << vINJ[n][i] << endl;
4501  }
4502 
4503  out.close();
4504  }
4505 }
4506 
4508 
4509  // import global variables
4510  int gLRETRY=-1; IMPORT(int,gLRETRY)
4511  int gIFACTOR=-1; IMPORT(int,gIFACTOR)
4512  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
4513 
4514  if(gLRETRY==0) return 1;
4515 
4516  bool use_original_data = (gLRETRY==1) ? true : false;
4517  // when multitask only in the last trial the original data is used
4518  if(gOPT.multitask) use_original_data = (gMTRIAL==gOPT.trials) ? true : false;
4519 
4520  if(use_original_data) cout << endl << "Last Trial : Analysis of the original data" << endl << endl;
4521 
4522  int nRES = cfg->l_high-cfg->l_low+1; // number of frequency resolution levels
4523  int nIFO = NET->ifoListSize(); // number of detectors
4524 
4525  vector<TString> delObjList;
4526  // supercluster clusters and parse maps are removed
4527  delObjList.push_back("supercluster");
4528  delObjList.push_back("sparse");
4529  TString jname = jfile->GetPath();
4530  jname.ReplaceAll(":/","");
4531  jfile->Close();
4532  gCWB2G->FileGarbageCollector(jname,"",delObjList);
4533 
4534  // circular shift in the range [jS,jE] randomly whitened ifos HoT & add rec/inj waveforms into @ the same rec time
4535  int size,rate;
4536  int jS,jE,jW,k;
4538  for(int n=0; n<nIFO; n++) { // create random time series
4539 
4540  // select waveform (reconstructed/injected) to be added to the whitened HoT
4542  if(gOPT.signal==0) wf=vREC[n]; // reconstructed
4543  if(gOPT.signal==1) wf=GetAlignedWaveform(&vINJ[n], &vREC[n]); // injected
4544  if(gOPT.signal==2) wf=vDAT[n]; // reconstructed+null
4545 
4546  // apply amplitude mis-calibration amp_cal_err
4547  if((!use_original_data) && gOPT.amp_cal_err[n]) { // in the last try (gLRETRY==1) we use the original data
4548  double amp_cal_err = 1;
4549  if(gOPT.amp_cal_err[n]>0) amp_cal_err = gRandom->Uniform(1-gOPT.amp_cal_err[n],1+gOPT.amp_cal_err[n]);
4550  else amp_cal_err = gRandom->Gaus(1,fabs(gOPT.amp_cal_err[n]));
4551  cout << "Apply Amplitude Mis-Calibration (" << gOPT.amp_cal_err[n] <<"%) "
4552  << NET->ifoName[n] << " -> amp_cal_err : " << amp_cal_err << endl;
4553  wf*=amp_cal_err;
4554  }
4555  // apply phase mis-calibration phs_cal_err
4556  if((!use_original_data) && gOPT.phs_cal_err[n]) { // in the last try (gLRETRY==1) we use the original data
4557  double phs_cal_err = 0;
4558  if(gOPT.phs_cal_err[n]>0) phs_cal_err = gRandom->Uniform(-gOPT.phs_cal_err[n],gOPT.phs_cal_err[n]);
4559  else phs_cal_err = gRandom->Gaus(0,fabs(gOPT.phs_cal_err[n]));
4560  cout << "Apply Phase Mis-Calibration (" << gOPT.phs_cal_err[n] <<" deg) "
4561  << NET->ifoName[n] << " -> phs_cal_err : " << phs_cal_err << " deg" << endl;
4562  CWB::mdc::PhaseShift(wf,phs_cal_err);
4563  }
4564 
4565  pTF = NET->getifo(n)->getTFmap();
4566  size = gHOT[n].size();
4567  rate = gHOT[n].rate();
4568  // apply time shift to input whitened data (integer number of sammples)
4569  jS = cfg->segEdge*rate;
4570  jE = size-jS;
4571  jW = rate*cfg->iwindow/2;
4572  k = gRandom->Uniform(jS+jW,jE-jW); // select random offset (excludes +/- iwindow/2 around the event)
4573  if(use_original_data) { // in the last try we restore the original data
4574  *gCWB2G->hot[n] = gHOT[n];
4575  } else {
4576  printf("Info : %s data time shift : %.5f sec\n",NET->getifo(n)->Name,(double)(k-jS)/rate);
4577  for(int i=jS; i<jE; i++) {
4578  gCWB2G->hot[n]->data[k++] = gHOT[n].data[i];
4579  if(k==jE) k=jS;
4580  }
4581  *(gCWB2G->hot[n]) = AddWaveforms(gCWB2G->hot[n],&wf); // add waveform (reconstructed/injected) to whitened HoT
4582  }
4583  pTF->Forward(*(gCWB2G->hot[n]),*(NET->wdmList[nRES-1]));
4584  }
4585 
4586  // perform coherence and supercluster stages
4587  gCWB2G->Coherence(gIFACTOR);
4588  gCWB2G->SuperCluster(gIFACTOR);
4589 
4590  NET->setDelayIndex(gCWB2G->TDRate);
4591  if(gCWB2G->singleDetector) NET->setIndexMode(cfg->mode); // when nIFO=1 exclude duplicate delay configurations
4592 
4593  // set low-rate TD filters
4594  for(int k=0; k<nRES; k++) gCWB2G->pwdm[k]->setTDFilter(cfg->TDSize, cfg->upTDF);
4595  NET->setDelayIndex(gCWB2G->TDRate);
4596 
4597  jfile = new TFile(jname);
4598  ReplaceSuperclusterData(jfile, cfg, NET, gOPT.gps); // save in jfile only max size supercluster
4599 
4600  // read sparse map from job file
4601  cout << "Loading sparse TF map ... " << endl;
4602  for(int n=0; n<nIFO; n++) {
4603  detector* pD = NET->getifo(n);
4604  pD->sclear(); // clear vector with sparse maps
4605  TString ifo=NET->ifoName[n];
4606  for(int i=0; i<nRES; i++) {
4607  char swname[32];
4608  if(cfg->simulation) sprintf(swname,"sparse/%s-level:%d:%d",ifo.Data(),gIFACTOR,i+cfg->l_low);
4609  else sprintf(swname,"sparse/%s-level:%d",ifo.Data(),i+cfg->l_low);
4610  SSeries<double>* psw = (SSeries<double>*)jfile->Get(swname);
4611  if(psw==NULL) {
4612  cout << "CWB_Plugin_PE - Likelihood : sparse map " << swname
4613  << " not exist in job file" << endl;exit(1);
4614  }
4615  SSeries<double> SS = *psw;
4616  pD->vSS.push_back(SS);
4617  delete psw;
4618  }
4619  cout<<endl;
4620  }
4621 
4622  netcluster* pwc = NET->getwc(0);
4623  pwc->cData.clear();
4624  // read cluster list & metadata netcluster object
4625  int cycle = cfg->simulation ? gIFACTOR : Long_t(NET->wc_List[0].shift);
4626  vector<int> clist = pwc->read(jfile,"supercluster","clusters",0,cycle);
4627  return clist.size();
4628 }
4629 
4631 
4632  wavearray<double> wf = *wf1;
4633 
4634  if(wf1==NULL) return wf;
4635  if(wf1->size()==0) return wf;
4636 
4637  double R=wf1->rate();
4638 
4639  double b_wf1 = wf1->start();
4640  double e_wf1 = wf1->start()+wf1->size()/R;
4641  double b_wf2 = wf2->start();
4642  double e_wf2 = wf2->start()+wf2->size()/R;
4643 
4644  int o_wf1 = b_wf1>b_wf2 ? 0 : int((b_wf2-b_wf1)*R+0.5);
4645  int o_wf2 = b_wf1<b_wf2 ? 0 : int((b_wf1-b_wf2)*R+0.5);
4646 
4647  double startXCOR = b_wf1>b_wf2 ? b_wf1 : b_wf2;
4648  double endXCOR = e_wf1<e_wf2 ? e_wf1 : e_wf2;
4649  int sizeXCOR = int((endXCOR-startXCOR)*R+0.5);
4650 
4651  for(int i=0;i<sizeXCOR;i++) wf[i+o_wf1] += wf2->data[i+o_wf2];
4652 
4653  return wf;
4654 }
4655 
4656 void SetEventWindow(CWB::config* cfg, double gps) {
4657 
4658  if(gps<0) return;
4659 
4660  // dq file list
4661  // {ifo, dqcat_file, dqcat[0/1/2], shift[sec], inverse[false/true], 4columns[true/false]}
4662 
4663  for(int n=0; n<cfg->nIFO; n++) {
4664 
4665  strcpy(cfg->DQF[cfg->nDQF].ifo, cfg->ifo[n]);
4666  sprintf(cfg->DQF[cfg->nDQF].file, "%s/%s_%s.gps_%d",cfg->tmp_dir,cfg->ifo[n],cfg->data_label,int(gps));
4667  cfg->DQF[cfg->nDQF].cat = CWB_CAT2;
4668  cfg->DQF[cfg->nDQF].shift = 0.;
4669  cfg->DQF[cfg->nDQF].invert = false;
4670  cfg->DQF[cfg->nDQF].c4 = true;
4671  cfg->nDQF++;
4672 
4673  cout << cfg->DQF[cfg->nDQF-1].file << endl;
4674 
4675  ofstream out;
4676  out.open(cfg->DQF[cfg->nDQF-1].file,ios::out);
4677  cout << "Write file : " << cfg->DQF[cfg->nDQF-1].file << endl;
4678  if (!out.good()) {cout << "Error Opening File : " << cfg->DQF[cfg->nDQF-1].file << endl;exit(1);}
4679  out.precision(14);
4680  int istart = int(gps)-cfg->iwindow;
4681  int istop = int(gps)+cfg->iwindow;
4682  out << "1 " << istart << " " << istop << " " << 2*cfg->iwindow << endl;
4683  out.close();
4684  }
4685 }
4686 
4688 // compute median sky probability
4689 
4690  skymap skyprob = NET->getifo(0)->tau;
4691  skyprob=0;
4692 
4693  int ntry=0; for(int i=0;i<gOPT.trials;i++) if(wREC[i].size()) ntry++; // number of detected events
4694 
4695  int *index = new int[ntry];
4696  float *value = new float[ntry];
4697 
4698  int L = skyprob.size();
4699  double sum=0;
4700  for(int l=0;l<L;l++) { // for each sky location compute median sky probability
4701 
4702  int k=0; for(int i=0;i<gOPT.trials;i++) if(wREC[i].size()) value[k++] = wSKYPROB[i].get(l);
4703  TMath::Sort(ntry,value,index,false);
4704 
4705  int imed = (ntry*50.)/100.; if(imed>=ntry) imed=ntry-1;
4706 
4707  skyprob.set(l,value[index[imed]]); // save median sky probability
4708 
4709  sum+=value[index[imed]];
4710  }
4711 
4712  // normalize sky probability
4713  if(sum>0) for(int l=0;l<L;l++) skyprob.set(l,skyprob.get(l)/sum);
4714 
4715  delete [] index;
4716  delete [] value;
4717 
4718  return skyprob;
4719 }
4720 
4722 
4723  skymap skyprobcc = NET->getifo(0)->tau;
4724 
4725  // convert skyprob in celestial coordinates
4726  int L = skyprobcc.size();
4727  for(int l=0; l<L; l++) {
4728  double th = skyprob->getTheta(l);
4729  double ph = skyprob->getPhi(l);
4730 
4731  double ra = skyprob->getRA(l);
4732  int k=skyprob->getSkyIndex(th, ra);
4733  skyprobcc.set(k,skyprob->get(l));
4734  }
4735 
4736  // dump skyprobcc to fits file
4737  char fname[1024];
4738  if(skyprobcc.getType()) { // check if it is healpix
4739  sprintf(fname, "%s/mskyprobcc.%s", odir.Data(), "fits");
4740 
4741  // build fits configur info
4742  TString analysis = "2G";
4743  if(NET->MRA) analysis+=":MRA";
4744  if(NET->pattern==0) analysis+=":Packet(0)";
4745  if((NET->pattern!=0 && NET->pattern<0)) analysis+=TString::Format(":Packet(%d)",NET->pattern);
4746  if((NET->pattern!=0 && NET->pattern>0)) analysis+=TString::Format(":Packet(+%d)",NET->pattern);
4747 
4748  char configur[64]="";
4749  char search = NET->tYPe;
4750  if (search=='r') sprintf(configur,"%s un-modeled",analysis.Data());
4751  if (search=='i') sprintf(configur,"%s iota-wave",analysis.Data());
4752  if (search=='p') sprintf(configur,"%s psi-wave",analysis.Data());
4753  if((search=='l')||(search=='s')) sprintf(configur,"%s linear",analysis.Data());
4754  if((search=='c')||(search=='g')) sprintf(configur,"%s circular",analysis.Data());
4755  if((search=='e')||(search=='b')) sprintf(configur,"%s elliptical",analysis.Data());
4756  skyprobcc.Dump2fits(fname,EVT->time[0],configur,const_cast<char*>("PROB"),const_cast<char*>("pix-1"),'C');
4757  }
4758 
4759 }
4760 
4762 
4763  int nIFO = cfg->nIFO;
4764 
4765  char beginString[1024];
4766  sprintf(beginString,"wave_");
4767  char endString[1024];
4768  sprintf(endString,"_job%d.root",runID);
4769  char containString[1024];
4770  sprintf(containString,"%s_trial",cfg->data_label);
4771 
4772  vector<TString> fileList = CWB::Toolbox::getFileListFromDir(cfg->output_dir,endString,beginString,containString,containString);
4773 
4774  wavearray<double>* mtpe_wREC[NIFO_MAX];
4775  for(int i=0;i<nIFO;i++) mtpe_wREC[i] = new wavearray<double>;
4776  skymap* mtpe_skyprob = new skymap(int(0));
4777  float* chirp = new float[6];
4778  float* isnr = new float[nIFO];
4779  float* osnr = new float[nIFO];
4780  float* iosnr = new float[nIFO];
4781  float likelihood;
4782 
4783  char command[1024];
4784  int nfile = fileList.size();
4785  for(int n=0;n<nfile;n++) {
4786  cout << n << " " << fileList[n].Data() << endl;
4787 
4788  TFile* froot = new TFile(fileList[n].Data(),"READ");
4789  if(froot==NULL) {
4790  cout << "CWB_Plugin_PE Error : Failed to open file : " << fileList[n].Data() << endl;
4791  gSystem->Exit(1);
4792  }
4793  TTree* itree = (TTree*)froot->Get("waveburst");
4794  if(itree==NULL) {
4795  cout << "CWB_Plugin_PE Error : Failed to open tree waveburst from file : " << fileList[n].Data() << endl;
4796  gSystem->Exit(1);
4797  }
4798 
4799  for(int i=0;i<nIFO;i++) itree->SetBranchAddress(TString::Format("mtpe_wREC_%d",i).Data(),&mtpe_wREC[i]);
4800  itree->SetBranchAddress("mtpe_skyprob",&mtpe_skyprob);
4801  itree->SetBranchAddress("chirp",chirp);
4802  itree->SetBranchAddress("likelihood",&likelihood);
4803 
4804  itree->GetEntry(0); // read wREC,skyprob objects
4805 
4806  // check if objects are not null
4807  for(int i=0;i<nIFO;i++) {
4808  if(mtpe_wREC[i]==NULL) {
4809  cout << "CWB_Plugin_PE Error : Object wavearray not exist !!! " << endl;
4810  gSystem->Exit(1);
4811  }
4812  }
4813  if(mtpe_skyprob==NULL) {
4814  cout << "CWB_Plugin_PE Error : Object skymap not exist !!! " << endl;
4815  gSystem->Exit(1);
4816  }
4817 
4818  // fill object vectors
4819  wSKYPROB[gOPT.trials-n-1] = *mtpe_skyprob; // restore sky probability
4820 
4821  for(int i=0;i<nIFO;i++)
4822  wREC[gOPT.trials-n-1].push_back(*mtpe_wREC[i]); // restore reconstructed waveform
4823 
4824  for(int i=0;i<nIFO;i++) { // restore SNR
4825  iSNR[i].push_back(isnr[i]);
4826  oSNR[i].push_back(osnr[i]);
4827  ioSNR[i].push_back(iosnr[i]);
4828  }
4829 
4830  for(int j=0; j<6; j++) vCHIRP[j].push_back(chirp[j]); // restore chirp mass parameters
4831 
4832  vLIKELIHOOD.push_back(likelihood); // restore likelihood
4833 
4834  froot->Close();
4835 
4836  // remove temporary root file
4837  sprintf(command,"/bin/rm %s",fileList[n].Data());
4838  cout << command << endl;
4839  gSystem->Exec(command);
4840  }
4841 
4842  for(int i=0;i<nIFO;i++) delete mtpe_wREC[i];
4843  delete mtpe_skyprob;
4844  delete [] chirp;
4845  delete [] isnr;
4846  delete [] osnr;
4847  delete [] iosnr;
4848 }
4849 
4850 void GetNoisePixels(std::vector<double>* aNSE, std::vector<double>* ANSE,
4851  network* NET, CWB::config* cfg, int lag, int id) {
4852 // get noise statistic in TF domain using random event TF patterns
4853 // this is used for Kolmogorov test of the residuals
4854 
4855  size_t nIFO = NET->ifoList.size();
4856 
4857  netcluster* pwc = NET->getwc(lag);
4858  std::vector<int> pI = NET->wdmMRA.getXTalk(pwc, id, false); // buffer for pixel IDs
4859  netpixel* pix = pwc->getPixel(id,pI[0]);
4860  int V = pI.size();
4861  if(!V) return;
4862 
4863  int nRES = NET->wdmListSize(); // number of frequency resolution levels
4864 
4865  double R = NET->getifo(0)->TFmap.rate();
4866 
4867  double rate = gHOT[0].rate();
4868  int size = gHOT[0].size();
4869 
4870  int layers_high = 1<<cfg->l_high;
4871 
4872  // compute the minimum index in the super cluster
4873  int index_min=2*gHOT[0].size();
4874  for(int k=0; k<V; k++) {
4875  netpixel* pix = pwc->getPixel(id,pI[k]);
4876  for(int n=0; n<nIFO; n++) {
4877  int index = pix->data[n].index;
4878  if(index<index_min) index_min=index;
4879  }
4880  }
4881  index_min = index_min-(index_min%layers_high); // set index_min a multiple of layers_high
4882 
4883  // find range where to select noise data
4884  int jS = cfg->segEdge*rate;
4885  int jE = size-jS;
4886  int jW = rate*cfg->iwindow;
4887 
4889  for(int n=0; n<nIFO; n++) {
4890  for(int j=0;j<nRES;j++) { // j=0 -> l_high : j=nRES-1 -> l_low
4891  w.Forward(gHOT[n],*(NET->wdmList[nRES-1-j]));
4892  for(int m=0; m<nTRIALS; m++) {
4893  int index_off = gRandom->Uniform(jS,jE-jW); // select random offset (excludes last iwindow range)
4894  index_off = index_off-(index_off%layers_high); // set index_off a multiple of layers_high
4895  for(int k=0; k<V; k++) {
4896  netpixel* pix = pwc->getPixel(id,pI[k]);
4897  int index = pix->data[n].index;
4898  int ires = int(TMath::Log2(R/pix->rate))-cfg->l_low;
4899  int ilayers = 1<<(ires+cfg->l_low);
4900  index = index_off+(index-index_min); // shift pixels
4901  if(ires==j) {
4902  // get original sparse map amplitudes
4903  //double dd = GetSparseMapData(&vSS[n][ires], true, index);
4904  //double DD = GetSparseMapData(&vSS[n][ires], false , index);
4905  // get the shifted amplitudes
4906  double dd = w.data[index];
4907  double DD = w.data[index+w.maxIndex()+1];
4908  aNSE[n].push_back(dd);
4909  ANSE[n].push_back(DD);
4910  }
4911  }
4912  }
4913  }
4914  }
4915  return;
4916 }
4917 
4919 
4920  if(type!="data" && type!="null" && type!="signal" && type!="injection") {
4921  cout << "CWB_Plugin_PE Error : wrong PlotSpectrogram type, must be data/null/signal" << endl;
4922  exit(1);
4923  }
4924 
4925  int nIFO = NET->ifoListSize(); // number of detectors
4926  char fname[1024];
4927 
4928  for(int n=0; n<nIFO; n++) {
4929  WSeries<double>* pTF = NET->getifo(n)->getTFmap();
4930  if(type=="null") {
4931  wavearray<double> wf = vREC[n];
4932  wf*=-1;
4933  *pTF = AddWaveforms(&gHOT[n],&wf); // sub waveform (reconstructed/injected) to whitened HoT
4934  }
4935  if(type=="signal") {
4936  wavearray<double> wf = vREC[n];
4937  *pTF=0;
4938  *pTF = AddWaveforms(pTF,&wf); // reconstructed signal
4939  }
4940  if(type=="injection") {
4941  wavearray<double> wf = vINJ[n];
4942  *pTF=0;
4943  *pTF = AddWaveforms(pTF,&wf); // injected signal
4944  }
4945 
4946  *pTF*=1./sqrt(1<<cfg->levelR);
4947 
4948  TString xtitle = TString::Format("Time (sec) : GPS OFFSET = %.3f",EVT->gps[n]);
4949 
4950  if(pTF->size()==0) continue;
4951  if(pTF->getLevel()>0) pTF->Inverse();
4952 
4953  int nfact=4;
4954  int nfft=nfact*512;
4955  int noverlap=nfft-10;
4956  double fparm=nfact*6;
4957  int ystart = int((EVT->start[n]-EVT->gps[n]-1)*pTF->rate());
4958  int ystop = int((EVT->stop[n]-EVT->gps[n]+1)*pTF->rate());
4959  ystart-=nfft;
4960  ystop+=nfft;
4961  int ysize=ystop-ystart;
4962  wavearray<double> y;y.resize(ysize);y.rate(pTF->rate());y.start(ystart/pTF->rate());
4963 
4964  // stft use dt=y.rate() to normalize data but whitened data are already normalized by dt
4965  // so before stft data must be divided by 1./sqrt(dt)
4966  for(int i=0;i<(int)y.size();i++) y.data[i]=pTF->data[i+ystart]/sqrt(y.rate());
4967 
4968  CWB::STFT stft(y,nfft,noverlap,"energy","gauss",fparm);
4969 
4970  TCanvas* canvas;
4971  double tstart = nfft/pTF->rate()+ystart/pTF->rate();
4972  double tstop = (ysize-nfft)/pTF->rate()+ystart/pTF->rate();
4973 
4974  tstart+=0.9;tstop-=0.9;
4975  stft.Draw(tstart,tstop,pTF->getlow(),pTF->gethigh(),0,0,1);
4976  stft.GetHistogram()->GetXaxis()->SetTitle(xtitle);
4977  sprintf(fname, "%s/%s_%s_spectrogram_0.png", pdir.Data(), NET->ifoName[n], type.Data());
4978  canvas = stft.GetCanvas();
4979  stft.Print(fname);
4980  canvas->SetLogy(true);
4981  stft.GetHistogram()->GetXaxis()->SetTitle(xtitle);
4982  sprintf(fname, "%s/%s_%s_spectrogram_logy_0.png", pdir.Data(), NET->ifoName[n], type.Data());
4983  stft.Print(fname);
4984 
4985  y.resize(0);
4986  }
4987 }
4988 
4989 std::vector<wavearray<double> > GetWhitenedData(network* NET, CWB::config* cfg) {
4990  // get whitened data (in the vREC time range)
4991 
4992  std::vector<wavearray<double> > xWHT; // temporary stuff
4993 
4994  int nIFO = NET->ifoListSize(); // number of detectors
4995 
4996  for(int n=0; n<nIFO; n++) {
4997  xWHT.push_back(GetAlignedWaveform(&gHOT[n], &vREC[n]));
4998  }
4999  return xWHT;
5000 }
5001 
5002 // the following function replace the supercluster clusters with the max size supercluster
5003 void ReplaceSuperclusterData(TFile*& jfile, CWB::config* cfg, network* NET, double gps) {
5004  // gps=0 -> select cluster with max size
5005  // gps>0 -> select cluster nearest to gps time
5006 
5007  int gIFACTOR=-1; IMPORT(int,gIFACTOR)
5008  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
5009 
5010  int cycle = cfg->simulation ? gIFACTOR : Long_t(NET->wc_List[0].shift);
5011 
5012  netcluster* pwc = NET->getwc(0);
5013  pwc->clear();
5014 
5015  // read cluster list & metadata netcluster object
5016  vector<int> clist = pwc->read(jfile,"supercluster","clusters",0,cycle);
5017  //pwc->print();
5018 
5019  if(clist.size()==0) return;
5020 
5021  // find max size supercluster index
5022  int maxk=0;
5023  int npixels=0; // total loaded pixels per lag
5024  int msize=0;
5025  for(int k=0;k<(int)clist.size();k++) { // loop over the cluster list
5026  // read pixels & tdAmp into netcluster pwc
5027  pwc->read(jfile,"supercluster","clusters",-2,cycle,0,clist[k]);
5028  int psize = pwc->size()-npixels;
5029  if(psize>msize) {maxk=k;msize=psize;}
5030  npixels+=psize;
5031  }
5032 
5033  // find min abs(gps-time) supercluster index
5034  int mink=0;
5035  double mtime=1.e20;
5036  wavearray<double> ctime = pwc->get((char*)"time",0,'L',0); // get cluster time
5037  for(int k=0; k<ctime.size(); k++) { // loop over clusters
5038  if(fabs(ctime[k]+pwc->start-gps)<mtime) {mink=k;mtime=fabs(ctime[k]+pwc->start-gps);}
5039  }
5040 
5041  int kindex = gps>0 ? mink : maxk;
5042 
5043  pwc->clear();
5044  // read max supercluster (pixels & tdAmp) into netcluster pwc
5045  pwc->read(jfile,"supercluster","clusters",-1,cycle,0,clist[kindex]);
5046 
5047  // supercluster are removed from jfile
5048  vector<TString> delObjList;
5049  delObjList.push_back("supercluster");
5050  TString jname = jfile->GetPath();
5051  jname.ReplaceAll(":/","");
5052  jfile->Close();
5053  gCWB2G->FileGarbageCollector(jname,"",delObjList);
5054 
5055  // max supercluster is stored in jfile
5056  jfile = new TFile(jname,"UPDATE");
5057  gCWB2G->jfile=jfile;
5058  if(jfile==NULL||!jfile->IsOpen())
5059  {cout << "CWB_Plugin_PE.C - Error opening : " << jname << endl;exit(1);}
5060  pwc->write(jfile,"supercluster","clusters",0,cycle);
5061  pwc->write(jfile,"supercluster","clusters",-1,cycle);
5062 
5063  jfile->Write();
5064 }
monster wdmMRA
list of pixel pointers for MRA
Definition: network.hh:651
std::vector< char * > ifoName
Definition: network.hh:609
std::vector< wavearray< double > > fL50
void SetOptions(int simulation, double rho, double inRate, bool useSparse=false, char *gtype=const_cast< char *>("png"), int paletteId=0)
Definition: ced.hh:88
void sethigh(double f)
Definition: wseries.hh:132
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
CWB::config * cfg
size_t rateANA
Definition: cwb.hh:279
gskymap * gSM
static float _sse_abs_ps(__m128 *_a)
Definition: watsse.hh:137
uoptions gOPT
double iwindow
Definition: config.hh:200
skymap wSKYPROB[MAX_TRIALS]
double FittingFactor(wavearray< double > *wf1, wavearray< double > *wf2)
static const double C
Definition: GNGen.cc:28
std::vector< SSeries< double > > dSS[NIFO_MAX]
#define NIFO
Definition: wat.hh:74
size_t write(const char *file, int app=0)
Definition: netcluster.cc:3008
wavearray< double > GetWaveformEnvelope(wavearray< double > *wf)
#define PE_CED_TFMAP
int noverlap
Definition: TestDelta.C:20
size_t nLag
Definition: network.hh:573
void GetNullPixels(std::vector< double > *aNUL, std::vector< double > *ANUL, network *NET, CWB::config *cfg, int lag, int id)
TChain sim("waveburst")
double getlow() const
Definition: wseries.hh:129
Float_t * rho
biased null statistics
Definition: netevent.hh:112
#define PLOT_TYPE
std::vector< wavearray< double > > fINJ
std::vector< wavearray< double > > vREC
char xtitle[1024]
TString ofName
Float_t * high
min frequency
Definition: netevent.hh:104
static vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="", TString containString="", bool fast=false)
Definition: Toolbox.cc:5108
#define PE_GPS
size_t TDSize
Definition: config.hh:217
std::vector< wavearray< double > > GetSigWaveform(network *NET, CWB::config *cfg, int lag, int id)
double M
Definition: DrawEBHH.C:13
void FileGarbageCollector(TString ifName, TString ofName="", vector< TString > delObjList=vector< TString >())
Definition: cwb.cc:2338
TString cwb_doc_url
std::vector< wavearray< double > > wREC[MAX_TRIALS]
std::vector< double > vCHIRP[6]
std::vector< netcluster > wc_List
Definition: network.hh:610
par [0] value
void setSLags(float *slag)
Definition: netevent.cc:426
void PlotWaveforms(network *NET, CWB::config *cfg, int ID, TString pdir="")
int wdm_start
Definition: sseries.hh:196
void SetSkyMask(network *NET, CWB::config *cfg, double theta, double phi, double radius)
TString site_cluster
Definition: cwb_mkdir.C:69
TString gOUTPUT
void GetFactorsStatistic(int nIFO)
bool singleDetector
used for the stage stuff
Definition: cwb.hh:277
void DumpRecWavePE(network *NET, TString pdir="")
Double_t * start
cluster duration = stopW-startW
Definition: netevent.hh:99
WSeries< double > * pTF[NIFO_MAX]
pointers to detectors
Definition: cwb.hh:264
std::vector< double > * getmdcTime()
Definition: network.hh:422
WDM< double > * pwdm[NRES_MAX]
Definition: cwb2G.hh:80
virtual void rate(double r)
Definition: wavearray.hh:141
void PlotChirpMass(int gtype, TString pdir, int sim=true)
std::vector< wavearray< float > > tdAmp
Definition: netpixel.hh:123
Float_t * low
average center_of_snr frequency
Definition: netevent.hh:103
double cedRHO
Definition: config.hh:298
void Print(TString pname)
Definition: STFT.cc:315
float factor
char skyMaskFile[1024]
Definition: config.hh:308
size_t upTDF
Definition: config.hh:216
wavearray< double > a(hp.size())
std::vector< wavearray< double > > fU50
float likelihood
Definition: netpixel.hh:114
std::vector< wavearray< double > > fREC
std::vector< wavearray< double > > vDAT
wavearray< double > GetCutWaveform(wavearray< double > x, double bT, double eT, double bF, double eF)
wavearray< double > AddWaveforms(wavearray< double > *wf1, wavearray< double > *wf2)
#define EFRACTION_CUT
int n
Definition: cwb_net.C:28
void ResetUserOptions()
wavearray< double > gHOT[NIFO_MAX]
static void _sse_zero_ps(__m128 *_p)
Definition: watsse.hh:44
void PlotFactors(int gtype, int nIFO, TString pdir)
double dT
Definition: cwb.hh:283
wavearray< float > _avx_norm_ps(float **, float **, std::vector< float *> &, int)
Definition: network.hh:1365
bool invert
Definition: Toolbox.hh:88
wavearray< float > a_90
buffer for cluster sky 00 amplitude
Definition: network.hh:653
TTree * setTree()
Definition: netevent.cc:434
char * watversion(char c='s')
Definition: watversion.hh:21
TString("c")
#define PE_OUTPUT_MED
size_t setIndexMode(size_t=0)
Definition: network.cc:8105
void SetEventWindow(CWB::config *cfg, double gps)
char ifo[32]
Definition: Toolbox.hh:84
#define PE_CED_DISTR
TFile * jfile
output root file
Definition: cwb.hh:259
double Tb
Definition: cwb.hh:281
std::vector< wavearray< double > > vRMS
int ID
Definition: TestMDC.C:70
Int_t * size
cluster volume
Definition: netevent.hh:80
double gSEGGPS
void ResetPCA(network *NET, CWB::config *cfg, netcluster *pwc, std::vector< netpixel > *vPIX, int ID)
size_t maxIndex()
Definition: wseries.hh:149
#define PE_CED_PCA
#define PE_CED_NULL
ofstream out
Definition: cwb_merge.C:214
std::vector< double > aNUL[NIFO_MAX]
static void PhaseShift(wavearray< double > &x, double pShift=0.)
Definition: mdc.cc:2955
void DumpSkyProb(skymap *skyprob, network *NET, netevent *&EVT, TString odir)
#define PE_OUTPUT_P90
#define PE_OUTPUT_DAT
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
std::vector< pixdata > data
Definition: netpixel.hh:122
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:2207
std::vector< wavearray< double > * > RWFP
Definition: detector.hh:382
std::vector< wavearray< double > > GetInjWaveform(network *NET, netevent *EVT, int id, double factor)
bool c4
Definition: Toolbox.hh:89
int _sse_mra_ps(float *, float *, float, int)
Definition: network.hh:1276
double fLow
Definition: config.hh:140
void PlotWaveform(TString ofname, TString title, CWB::config *cfg, wavearray< double > *wf1, wavearray< double > *wf2, wavearray< double > *wf3, wavearray< double > *wref, bool fft=false, TString pdir="", double P=0.99, EColor col1=kRed, EColor col2=kBlue, EColor col3=(EColor) 418)
char odir[1024]
float theta
int nfact
Definition: TestDelta.C:18
int wdm_nSTS
Definition: sseries.hh:197
double gIPHI
int pattern
Definition: config.hh:241
netpixel pix(nifo)
netcluster * pwc
Definition: cwb_job_obj.C:38
int nfft
Definition: TestDelta.C:19
#define PE_OUTPUT_P50
TH2F * ph
int GetLayer(int index)
Definition: sseries.hh:122
std::vector< wavearray< double > > vMED
std::vector< TGraph * > graph
Definition: watplot.hh:194
return wmap canvas
CWB_STAGE istage
Definition: cwb.hh:247
double gOPHI
#define PE_CED_DUMP
bool cedDump
Definition: config.hh:297
void setlow(double f)
Definition: wseries.hh:125
int slagID
Definition: cwb.hh:291
std::vector< SSeries< double > > vSS[NIFO_MAX]
std::vector< wavearray< double > > cINJ
string search
Definition: cWB_conf.py:110
char ifostr[64]
dqfile DQF[DQF_MAX]
Definition: config.hh:349
std::vector< wavearray< double > > vINJ
void Coherence(int ifactor)
Definition: cwb2G.cc:773
double getTheta(size_t i)
Definition: skymap.hh:224
Float_t * ioSNR
reconstructed snr waveform
Definition: netevent.hh:139
std::vector< wavearray< double > > vNUL
static wavearray< double > getHilbertIFrequency(wavearray< double > x)
Definition: Toolbox.cc:6935
#define PE_CED_SKYMAP
waveform wf
TString DumpCED(network *NET, netevent *&EVT, CWB::config *cfg, double factor)
std::vector< double > fRES
size_t setcore(bool core, int id=0)
Definition: netcluster.cc:243
void Draw(int dpaletteId=1, Option_t *option="colfz")
Definition: gskymap.cc:460
Long_t size
WSeries< double > waveBand
Definition: detector.hh:356
double gITHETA
#define SKYMASK_RADIUS
std::vector< wavearray< double > > fL90
int m
Definition: cwb_net.C:28
#define PE_INDEX
std::vector< double > oSNR[NIFO_MAX]
DataType_t * pWWS
Definition: WaveDWT.hh:141
int wdm_rate
Definition: sseries.hh:195
char command[1024]
Definition: cwb_compile.C:44
virtual void start(double s)
Definition: wavearray.hh:137
int j
Definition: cwb_net.C:28
bool getMRAwave(size_t ID, size_t lag, char atype='S', int mode=0, bool tof=false)
Definition: network.cc:3666
i drho i
std::vector< double > mdcTime
Definition: network.hh:614
double gethigh() const
Definition: wseries.hh:136
void setTDFilter(int nCoeffs, int L=1)
Definition: WDM.cc:639
char nodedir[1024]
Definition: config.hh:352
skymap tau
Definition: detector.hh:346
std::vector< double > ANUL[NIFO_MAX]
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:150
wavearray< int > sparseIndex
Definition: sseries.hh:180
std::vector< SSeries< double > > jSS[NIFO_MAX]
std::vector< detector * > ifoList
Definition: network.hh:608
TH1D gHSKYPROB
std::vector< double > ioSNR[NIFO_MAX]
#define N
double gBF
bool outPlugin
Definition: config.hh:369
#define PE_CED_CM
size_t wdmListSize()
Definition: network.hh:446
bool core
Definition: netpixel.hh:120
#define PE_OUTPUT_RMS
char ifo[NIFO_MAX][8]
void dopen(const char *fname, char *mode, bool header=true)
Definition: netevent.hh:312
Definition: cwb2G.hh:33
TTree * gTREE
TH2F * hist2D
Definition: watplot.hh:193
void Draw(double t1=0.0, double t2=0.0, double f1=0.0, double f2=0.0, double z1=0.0, double z2=0.0, int dpaletteId=DUMMY_PALETTE_ID, Option_t *option="colfz")
Definition: STFT.cc:94
cout<< "Selected Pixels : "<< nPix<< endl;wc.cluster(1, 1);SSeries< double > ss
size_t ifoListSize()
Definition: network.hh:431
bool online
Definition: config.hh:118
std::vector< wavearray< double > > vL90
iseg push_back(seg)
#define PI
Definition: watfun.hh:32
void clean(int cID=0)
Definition: netcluster.hh:451
int Psave
Definition: config.hh:193
void clear()
Definition: watplot.hh:58
wavearray< double > w
Definition: Test1.C:27
double segEdge
Definition: config.hh:164
#define nIFO
void wrate(double r)
Definition: wseries.hh:120
size_t getSkyIndex(double th, double ph)
param: theta param: phi
Definition: skymap.cc:720
std::vector< wavearray< double > > GetRecWaveform(network *NET, netevent *EVT, int id)
CWB_CAT cat
Definition: Toolbox.hh:86
wavearray< float > pNRG
buffers for cluster residual energy
Definition: network.hh:655
skymap mSKYPROB
size_t mode
Definition: config.hh:275
double tstart
virtual size_t size() const
Definition: wavearray.hh:145
TCanvas * canvas
Definition: watplot.hh:192
int getLevel()
Definition: wseries.hh:109
float phi
#define PE_OUTPUT_AVR
double GetSegEnd()
Definition: cwb.hh:183
gWSeries< double > gw(w)
void PlotWaveformAsymmErrors(TString ofname, TString title, CWB::config *cfg, wavearray< double > *wrec, wavearray< double > *wmed, wavearray< double > *wl50, wavearray< double > *wu50, wavearray< double > *wl90, wavearray< double > *wu90, wavearray< double > *wref, TString pdir, double P, bool freq=false)
double ra
Definition: ConvertGWGC.C:46
std::vector< wavearray< double > > vU50
wavearray< double > freq
Definition: Regression_H1.C:79
char file[1024]
Definition: Toolbox.hh:85
x plot
jfile
Definition: cwb_job_obj.C:43
void output2G(TTree *, network *, size_t, int, double)
Definition: netevent.cc:711
static float _avx_packet_ps(float **p, float **q, std::vector< float *> &pAVX, int I)
Definition: watavx.hh:754
size_t lagOff
Definition: config.hh:170
Int_t Psave
number of detectors
Definition: netevent.hh:66
TGraph * gr
int simulation
Definition: config.hh:199
int l_high
Definition: config.hh:156
int nDQF
Definition: config.hh:348
#define PE_SKYMASK
std::vector< double > wRMS[NIFO_MAX]
void PlotSparse(int ifoID, network *NET, CWB::config *cfg, int ID, wavearray< double > *wf)
#define PE_CED_rINJ
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:69
#define PE_CED_PSD
watplot * WTS
Definition: ChirpMass.C:119
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
Double_t * gps
average center_of_gravity time
Definition: netevent.hh:95
double getRA(size_t i)
Definition: skymap.hh:215
void SuperCluster(int ifactor)
Definition: cwb2G.cc:962
wavearray< int > sparseLookup
Definition: sseries.hh:178
i() int(T_cor *100))
#define nTRIALS
double GetTimeBoundaries(wavearray< double > x, double P, double &bT, double &eT)
char output_dir[1024]
Definition: config.hh:318
double TDRate
Definition: cwb2G.hh:78
network NET
Definition: cwb_dump_inj.C:30
double Pi
void setDelayIndex(double rate)
param: MDC log file
Definition: network.cc:2896
const int NIFO_MAX
Definition: wat.hh:22
double gEF
void PlotFrequencyErrors(TString ofname, TString title, CWB::config *cfg, wavearray< double > *frec, wavearray< double > *favr, wavearray< double > *ferr, wavearray< double > *wref, TString pdir, double P)
int BATCH
Definition: config.hh:245
TH2D * GetHistogram()
Definition: STFT.hh:71
std::vector< netpixel > DoPCA(network *NET, CWB::config *cfg, int lag, int id)
char tmp_dir[1024]
Definition: config.hh:325
Double_t * stop
GPS start time of the cluster.
Definition: netevent.hh:100
double GetSegBegin()
Definition: cwb.hh:182
char parPlugin[1024]
Definition: config.hh:363
static void _avx_free_ps(std::vector< float *> &v)
Definition: watavx.hh:40
wavearray< float > a_00
wdm multi-resolution analysis
Definition: network.hh:652
std::vector< WDM< double > * > wdmList
Definition: network.hh:617
WSeries< double > pTF[nRES]
Definition: revMonster.cc:8
double start
Definition: netcluster.hh:379
printf("total live time: non-zero lags = %10.1f \, liveTot)
int l
TIter next(twave->GetListOfBranches())
char fname[1024]
std::vector< wavearray< double > > fRMS
double shift
Definition: Toolbox.hh:87
#define PE_OUTPUT_INJ
void GetNoisePixels(std::vector< double > *aNSE, std::vector< double > *ANSE, network *NET, CWB::config *cfg, int lag, int id)
std::vector< int > RWFID
Definition: detector.hh:381
int Write(double factor, bool fullCED=true)
Definition: ced.cc:607
std::vector< wavearray< double > > fAVR
void SetOutputFile(network *NET, netevent *&EVT, CWB::config *cfg, bool dump_pe)
size_t mdc__IDSize()
Definition: network.hh:414
char channelNamesRaw[NIFO_MAX][50]
Definition: config.hh:310
void SetChannelName(char *chName)
Definition: ced.hh:101
std::vector< double > iSNR[NIFO_MAX]
void ClearVectors()
bool gCEDDUMP
char output[256]
int k
int pattern
Definition: network.hh:601
double tstop
Float_t * netcc
effective correlated SNR
Definition: netevent.hh:113
void ClearWaveforms(detector *ifo)
int nfactor
Definition: config.hh:201
std::vector< wavearray< double > * > IWFP
Definition: detector.hh:379
void PlotSNRnet(int nIFO, TString pdir, int sim=true)
std::vector< double > wAVR[NIFO_MAX]
void DumpOutputFile(network *NET, netevent *&EVT, CWB::config *cfg, int ID, int k, int factor)
#define PE_CED_INJ
double gINRATE
void PlotResiduals(int ID, TString pdir="", int sim=true, char type='w')
static double A
Definition: geodesics.cc:26
TObjArray * token
double acor
Definition: network.hh:585
#define PE_SIGNAL
size_t lagSize
Definition: config.hh:168
double F
#define PE_CED_RDR
size_t loadTDampSSE(network &net, char c, size_t BATCH=10000, size_t LOUD=0)
Definition: netcluster.cc:3317
void DumpInjWavePE(network *NET, TString pdir="")
Definition: skymap.hh:63
#define PE_MULTITASK
std::vector< int > IWFID
Definition: detector.hh:378
#define PE_TRIALS
#define PE_AMP_CAL_ERR
PE gPE
double GetFrequencyBoundaries(wavearray< double > x, double P, double &bF, double &eF)
size_t size()
Definition: netcluster.hh:147
TString ofileName
Definition: MergeTrees.C:37
skymap GetMedianSkyProb(network *NET)
char tag[256]
Definition: cwb_merge.C:92
TFile * froot
netpixel * getPixel(size_t n, size_t i)
Definition: netcluster.hh:413
void WriteBodyHTML(TString html_template, TString html_tag_beg, TString html_tag_end, ofstream *out, int nIFO=1, TString *ifo=NULL)
cwb gCWB
double dt
virtual void FFTW(int=1)
Definition: wavearray.cc:896
std::vector< wavearray< double > > vWHT
std::vector< wavearray< double > > vAVR
void PrintUserOptions(CWB::config *cfg)
int l_low
Definition: config.hh:155
char options[256]
#define EXPORT(TYPE, VAR, CMD)
Definition: config.cc:92
double getPhi(size_t i)
Definition: skymap.hh:164
WSeries< double > TFmap
Definition: detector.hh:354
double GetCentralFrequency(wavearray< double > x)
std::vector< double > vLIKELIHOOD
#define PE_SEED
skymap gSKYPROB
char title[256]
Definition: SSeriesExample.C:1
Float_t * phi
sqrt(h+*h+ + hx*hx)
Definition: netevent.hh:87
bool wfsave
Definition: network.hh:600
double gps
#define PE_CED_REC
void sclear()
Definition: detector.hh:191
netevent EVT(itree, nifo)
double GetCentralTime(wavearray< double > x)
Float_t * theta
[0]-reconstructed, [1]-injected phi angle, [2]-RA
Definition: netevent.hh:88
Double_t * time
beam pattern coefficients for hx
Definition: netevent.hh:94
double T
Definition: testWDM_4.C:11
double gET
void Expand(bool bcore=true)
Definition: sseries.cc:415
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
COHERENCE.
static float _avx_setAMP_ps(float **p, float **q, std::vector< float *> &pAVX, int I)
Definition: watavx.hh:956
void PlotWaveformErrors(TString ofname, TString title, CWB::config *cfg, wavearray< double > *wrec, wavearray< double > *wavr, wavearray< double > *werr, wavearray< double > *wref, TString pdir="", double P=0.99)
ifstream in
std::vector< int > sCuts
Definition: netcluster.hh:392
WSeries< double > waveForm
Definition: detector.hh:355
void Wave2Sparse(network *NET, CWB::config *cfg, char type)
void dclose()
Definition: netevent.hh:321
double xtime
Definition: cwb_dump_sjob.C:28
wavearray< double > ts(N)
double fHigh
Definition: config.hh:141
void GetChirpMassStatistic(std::vector< double > *vCHIRP)
std::vector< wavearray< double > > GetWhitenedData(network *NET, CWB::config *cfg)
WSeries< double > * getTFmap()
param: no parameters
Definition: detector.hh:179
cout<< "Starting reading output directory ..."<< endl;vector< TString > fileList
int getType()
Definition: skymap.hh:296
wavearray< int > index
char Name[16]
Definition: detector.hh:327
char ifo[NIFO_MAX][8]
Definition: config.hh:124
double fabs(const Complex &x)
Definition: numpy.cc:55
#define MAX_TRIALS
double GetSparseMapData(SSeries< double > *SS, bool phase, int index)
void GetNullStatistic(std::vector< double > *vNUL, std::vector< double > *vNSE, int ifoId, TString ifoName, TString gtype, TString pdir="")
wavearray< float > sparseMap00
Definition: sseries.hh:181
int SetSkyMask(network *net, CWB::config *cfg, char *options, char skycoord, double skyres=-1)
Definition: cwb.cc:2484
wavearray< float > sparseMap90
Definition: sseries.hh:182
int gRATEANA
int gIFACTOR
std::vector< wavearray< double > > vL50
TCanvas * GetCanvas()
Definition: STFT.hh:70
char cmd[1024]
std::vector< int > ComputeStatisticalErrors(network *NET, CWB::config *cfg, int ID)
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:246
strcpy(RunLabel, RUN_LABEL)
int cnt
Float_t likelihood
Definition: netevent.hh:124
Meyer< double > S(1024, 2)
double df
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:439
void DumpUserOptions(TString odir, CWB::config *cfg)
std::vector< SSeries< double > > rSS[NIFO_MAX]
void PlotSpectrogram(TString type, network *NET, netevent *&EVT, CWB::config *cfg, TString pdir)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
static float _avx_loadata_ps(float **p, float **q, float **u, float **v, float En, std::vector< float *> &pAVX, int I)
Definition: watavx.hh:634
void CreateIndexHTML(TString dirCED, int nIFO, TString *ifo, bool sim=false)
float erR[11]
std::vector< clusterdata > cData
Definition: netcluster.hh:391
wavearray< double > GetDifWaveform(wavearray< double > *wf1, wavearray< double > *wf2)
TTree * itree
void SaveSkyProb(network *NET, CWB::config *cfg, int id)
TString gfile
void set(size_t i, double a)
param: sky index param: value to set
Definition: skymap.hh:122
std::vector< double > aNSE[NIFO_MAX]
std::vector< wavearray< double > > vPCA
int nIFO
Definition: config.hh:120
std::vector< wavearray< double > > GetPCAWaveform(network *NET, CWB::config *cfg, int lag, int id)
watplot * GetWATPLOT()
Definition: gwavearray.hh:88
int RedoAnalysis(TFile *jfile, CWB::config *cfg, network *NET)
Definition: cwb.hh:136
DataType_t * data
Definition: wavearray.hh:319
wavearray< float > rNRG
buffer for cluster sky 90 amplitudes
Definition: network.hh:654
const int nRES
Definition: revMonster.cc:7
TString jname
Long_t id
Definition: ced.hh:44
double factors[FACTORS_MAX]
Definition: config.hh:202
double get(size_t i)
param: sky index
Definition: skymap.cc:699
#define PE_NOISE
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:456
skymap GetSkyProb(network *NET, int id)
double dT
Definition: testWDM_5.C:12
#define NOISE_SIGMA
wavearray< double > * hot[NIFO_MAX]
wavelet pointers: pwdm[0] - l_high, wdm[nRES-1] l_low
Definition: cwb2G.hh:81
wavearray< double > wINJ[NIFO_MAX]
void ReplaceSuperclusterData(TFile *&jfile, CWB::config *cfg, network *NET, double gps=0)
SSeries< double > * getSTFmap(size_t n)
Definition: detector.hh:187
double ctime
wavearray< double > GetAlignedWaveform(wavearray< double > *wf1, wavearray< double > *wf2)
char line[1024]
string version
Definition: cWB_conf.py:108
char data_label[1024]
Definition: config.hh:332
Bool_t fill_in(network *, int, bool=true)
Definition: injection.cc:349
float rate
Definition: netpixel.hh:113
std::vector< SSeries< double > > vSS
Definition: detector.hh:352
int runID
Definition: cwb.hh:246
std::vector< wavearray< double > > vU90
int gMTRIAL
size_t read(const char *)
Definition: netcluster.cc:3115
size_t size()
Definition: skymap.hh:136
WSeries< double > waveNull
Definition: detector.hh:357
#define PE_PHS_CAL_ERR
size_t getmdc__ID(size_t n)
Definition: network.hh:426
std::vector< wavearray< double > > GetWaveform(network *NET, int lag, int id, char type, bool shift=true)
ofstream finj
double shift[NIFO_MAX]
void AddNoiseAndCalErrToSparse(network *NET, CWB::config *cfg, char type)
wavearray< double > ** pwf
[x1,y1,z1,x2,y2,z2] components of spin vector
Definition: injection.hh:101
virtual void resize(unsigned int)
Definition: wavearray.cc:463
double gOTHETA
void Print(TString pname)
Definition: gskymap.cc:1122
bool MRA
Definition: network.hh:599
int check
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:291
wavearray< double > y
Definition: Test10.C:31
int gID
int getSTFind(double r)
Definition: detector.hh:182
char tYPe
Definition: network.hh:588
std::vector< wavearray< double > > fU90
size_t inRate
Definition: config.hh:132
void PlotTimeFrequencyPCA(network *NET, netevent *EVT, CWB::config *cfg, int id, int lag, TString pdir)
void SetOptions(TString projection="hammer", TString coordinate="Geographic", double resolution=1, bool goff=false)
Definition: gskymap.cc:84
double fparm
Definition: TestDelta.C:22
std::vector< double > ANSE[NIFO_MAX]
#define PE_OUTPUT_REC
Float_t * chirp
range to source: [0/1]-rec/inj
Definition: netevent.hh:128
int levelR
Definition: config.hh:152
void GetSNRnetStatistic(int nIFO)
void Draw(GWAT_DRAW type=GWAT_TIME, TString options="ALP", Color_t color=kBlack)
Definition: gwavearray.cc:89
detector ** pD
void ReadUserOptions(TString options)
std::vector< double > vRES
#define PE_OUTPUT_WHT
double gBT
void LoadFromMultiTaskJobOutput(int runID, CWB::config *cfg)
CWB::STFT * stft
Definition: ChirpMass.C:121
std::vector< wavearray< double > > fMED
void SetZaxisTitle(TString zAxisTitle)
Definition: gskymap.hh:150
int binarySearch(int array[], int start, int end, int key)
Definition: sseries.cc:461
std::vector< vector_int > nTofF
Definition: netcluster.hh:404
exit(0)
bool setdata(double a, char type='R', size_t n=0)
Definition: netpixel.hh:58
Float_t * iSNR
energy of reconstructed responses Sk*Sk
Definition: netevent.hh:137
void SetWaveformCuts(wavearray< double > *x, double bT, double eT, double bF, double eF)
double avr
void clear()
Definition: netcluster.hh:427
Float_t * oSNR
injected snr waveform
Definition: netevent.hh:138
bool dump
Definition: config.hh:295