Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_pixeLHood.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 "TMath.h"
33 #include "mdc.hh"
34 #include <vector>
35 #include "watplot.hh"
36 #include <stdio.h>
37 
38 #define OUTPUT_DIR "plots"
39 #define OUTPUT_TYPE "png"
40 
41 void Dump(WSeries<double> &w, double t1, double t2, const char* fname);
42 
43 void
45 //!EVENT_REPORT
46 // This plugin dump/plot the likelihood/null pixels of the detected/reconstructed event
47 
48  cout << endl;
49  cout << "-----> plugins/CWB_Plugin_pixeLHood.C" << endl;
50  cout << "ifo " << ifo.Data() << endl;
51  cout << "type " << type << endl;
52  cout << endl;
53 
54 
55  if(type==CWB_PLUGIN_OLIKELIHOOD) {
56 
57  int i,j,k,n,m,l;
58  int nIFO = NET->ifoListSize();
59  int K = NET->nLag;
60  int M = NET->mdc__ID.size();
61  int ID;
62  char search = NET->tYPe;
63 
65 
66  bool batch = gROOT->IsBatch();
67  gROOT->SetBatch(true);
68 
69  watplot WTS(const_cast<char*>("wts"));
70 
71  char outdir[500] = OUTPUT_DIR;
72  char ifostr[20] = "";
73  char strtime[1024] = "";
74  char fname[1024];
75  char gtype[32] = OUTPUT_TYPE;
76 
77  int minTimeDet=nIFO;
78  double minTime=1e40;
79  double eventTime[NIFO];
80  double lagTime[NIFO];
81  int ifoid[NIFO],sortid[NIFO];
82  double factor = 1;
83 
84  netevent* EVT = new netevent(nIFO);
85 
86  int rate = int(2*NET->getifo(0)->TFmap.resolution(0)+0.5);
87 
88  for(k=0; k<K; k++) { // loop over the lags
89 
90  id = NET->getwc(k)->get(const_cast<char*>("ID"), 0, 'L', rate);
91 
92  for(j=0; j<(int)id.size(); j++) { // loop over cluster index
93 
94  ID = size_t(id.data[j]+0.5); // cluster id
95 
96  EVT->output(NULL,NET,factor,ID,k); // get reconstructed parameters
97  if(EVT->rho[1] < cfg->cedRHO) continue; // skip events under rho threshold
98 
99  int masterDet=0;
100  int lagMin=2147483647;
101  for(n=0; n<nIFO; n++) if(EVT->lag[n]<lagMin) {lagMin=int(EVT->lag[n]);masterDet=n;}
102 
103  NET->likelihood(search, NET->acor, ID, k); // exec likelihood search
104 
105  // get event network time
106  double gps_start = EVT->time[masterDet]-EVT->duration[masterDet];
107  double gps_stop = EVT->time[masterDet]+EVT->duration[masterDet];
108 
109  // create a unique label
110  for(n=0; n<nIFO; n++) sprintf(strtime, "%s_%.3f",strtime,EVT->start[n]);
111 
112  // dump event parameters
113  sprintf(fname, "%s/eventDump%s.%s", outdir, strtime, "txt");
114  EVT->dopen(fname,const_cast<char*>("w"));
115  EVT->output(NULL,NET,factor,ID,k);
116  EVT->dclose();
117 
118  // compute event time & lags time
119  for(n=0; n<nIFO; n++) eventTime[n]=(EVT->start[n]+EVT->stop[n])/2.;
120  for(n=0; n<nIFO; n++) minTime = (eventTime[n]<minTime) ? eventTime[n] : minTime;
121  for(n=0; n<nIFO; n++) lagTime[n]=eventTime[n]-minTime;
122  for(n=0; n<nIFO; n++) minTimeDet = (eventTime[n]<=minTime) ? n : minTimeDet;
123 
124  // set likelihood maps to optimal resolution level
125  double optRate = (NET->getwc(k)->cRate[ID-1])[0];
126  double optLayer = NET->getwc(k)->rate/optRate;
127  double optLevel = int(log10(optLayer)/log10(2));
128  for(int n=0;n<2;n++) {
130  if(n==0) pTF = &NET->pixeLHood;
131  if(n==1) pTF = &NET->pixeLNull;
132  pTF->Inverse(); // transform to time domain
133  pTF->Forward(optLevel); // transform to optimal level
134  }
135 
136  // plot likelihood map at optimal resolution level
137  WTS.canvas->cd();
138  sprintf(fname, "%s/l_tfmap_scalogram%s.%s", outdir, strtime, gtype);
139  WTS.plot(NET->pixeLHood, 0, gps_start-EVT->slag[masterDet],
140  gps_stop-EVT->slag[masterDet], const_cast<char*>("COLZ"));
141  WTS.hist2D->GetYaxis()->SetRangeUser(NET->pixeLHood.getlow(),NET->pixeLHood.gethigh());
142  WTS.hist2D->SetTitle("Scalogram");
143  WTS.canvas->Print(fname);
144  WTS.clear();
145 
146  // plot null map at optimal resolution level
147  sprintf(fname, "%s/n_tfmap_scalogram%s.%s", outdir, strtime, gtype);
148  WTS.plot(NET->pixeLNull, 0, gps_start-EVT->slag[masterDet],
149  gps_stop-EVT->slag[masterDet], const_cast<char*>("COLZ"));
150  WTS.hist2D->GetYaxis()->SetRangeUser(NET->pixeLNull.getlow(),NET->pixeLNull.gethigh());
151  WTS.hist2D->SetTitle("Scalogram");
152  WTS.canvas->Print(fname);
153  WTS.clear();
154 
155  // dump likelihood map at optimal resolution level
156  sprintf(fname, "%s/l_tfmap_scalogram%s.%s", outdir, strtime, "txt");
157  Dump(NET->pixeLHood, gps_start-EVT->slag[masterDet], gps_stop-EVT->slag[masterDet], fname);
158  // dump null map at optimal resolution level
159  sprintf(fname, "%s/n_tfmap_scalogram%s.%s", outdir, strtime, "txt");
160  Dump(NET->pixeLNull, gps_start-EVT->slag[masterDet], gps_stop-EVT->slag[masterDet], fname);
161 
162  } // End loop on found events
163  } // End loop on lags
164 
165  gROOT->SetBatch(batch); // restore batch status
166 
167  delete EVT;
168  }
169 
170  return;
171 }
172 
173 void Dump(WSeries<double> &w, double t1, double t2, const char* fname) {
174 
175  int ni = 1<<w.pWavelet->m_Level;
176  int nb = int((t1-w.start())*w.rate()/ni);
177  int nj = int((t2-t1)*w.rate())/ni;
178  int ne = nb+nj;
179  double rate=w.rate();
180  double df=rate/2/ni;
181  rate = rate/ni;
182  double dt = 1./rate;
183 
185 
186  FILE *fp;
187  if ( (fp = fopen(fname, "w")) == NULL ) {
188  cout << " Dump() error: cannot open file " << fname <<". \n";
189  return;
190  };
191 
192  for(int i=0;i<ni;i++) {
193  w.getLayer(wl,i);
194  for(int j=nb;j<=ne;j++) {
195  float t = (j+0.5)*dt;
196  float f = (i+0.5)*df;
197  float x = wl.data[j];
198  if(x>0.1) fprintf( fp,"%-3.6f \t%-3.6f \t%-3.3f \t%-3.3f \t%-3.3f\n", t, dt, f, df, x);
199  }
200  }
201 
202  fclose(fp);
203 
204  return;
205 }
wavearray< double > t(hp.size())
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
CWB::config * cfg
#define NIFO
Definition: wat.hh:74
size_t nLag
Definition: network.hh:573
std::vector< vector_int > cRate
Definition: netcluster.hh:398
double getlow() const
Definition: wseries.hh:129
Float_t * rho
biased null statistics
Definition: netevent.hh:112
TH1 * t1
WSeries< double > pixeLHood
Definition: network.hh:634
double M
Definition: DrawEBHH.C:13
Double_t * start
cluster duration = stopW-startW
Definition: netevent.hh:99
virtual void rate(double r)
Definition: wavearray.hh:141
Float_t * duration
max cluster time relative to segment start
Definition: netevent.hh:98
double cedRHO
Definition: config.hh:298
float factor
int n
Definition: cwb_net.C:28
TString("c")
int ID
Definition: TestMDC.C:70
#define OUTPUT_DIR
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
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
string search
Definition: cWB_conf.py:110
char ifostr[64]
Long_t size
int m
Definition: cwb_net.C:28
virtual void start(double s)
Definition: wavearray.hh:137
std::vector< size_t > mdc__ID
Definition: network.hh:615
int j
Definition: cwb_net.C:28
i drho i
double rate
Definition: netcluster.hh:378
double gethigh() const
Definition: wseries.hh:136
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
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
COHERENCE.
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
char ifo[NIFO_MAX][8]
void dopen(const char *fname, char *mode, bool header=true)
Definition: netevent.hh:312
TH2F * hist2D
Definition: watplot.hh:193
size_t ifoListSize()
Definition: network.hh:431
fprintf(stdout,"start=%f duration=%f rate=%f\, x.start(), x.size()/x.rate(), x.rate())
void clear()
Definition: watplot.hh:58
wavearray< double > w
Definition: Test1.C:27
#define nIFO
TCanvas * canvas
Definition: watplot.hh:192
jfile
Definition: cwb_job_obj.C:43
watplot * WTS
Definition: ChirpMass.C:119
i() int(T_cor *100))
network NET
Definition: cwb_dump_inj.C:30
Double_t * stop
GPS start time of the cluster.
Definition: netevent.hh:100
WSeries< double > pTF[nRES]
Definition: revMonster.cc:8
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
Definition: wseries.cc:193
int l
Float_t * lag
time between consecutive events
Definition: netevent.hh:84
char fname[1024]
int k
void Dump(WSeries< double > &w, double t1, double t2, const char *fname)
double acor
Definition: network.hh:585
Float_t * slag
time lag [sec]
Definition: netevent.hh:85
int m_Level
Definition: Wavelet.hh:115
void output(TTree *=NULL, network *=NULL, double=0., size_t=0, int=-1)
Definition: netevent.cc:1193
long likelihood(char='E', double=sqrt(2.), int=0, size_t=0, int=-1, bool=false)
Definition: network.cc:4446
double dt
WSeries< double > TFmap
Definition: detector.hh:354
WSeries< double > pixeLNull
Definition: network.hh:635
netevent EVT(itree, nifo)
Double_t * time
beam pattern coefficients for hx
Definition: netevent.hh:94
void dclose()
Definition: netevent.hh:321
double resolution(int=0)
Definition: wseries.hh:155
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:246
double df
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:439
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
DataType_t * data
Definition: wavearray.hh:319
Long_t id
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:456
fclose(ftrig)
#define OUTPUT_TYPE
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:291
char tYPe
Definition: network.hh:588