Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CWB_Plugin_pixeLHood.C
Go to the documentation of this file.
1 #define XIFO 4
2 
3 #pragma GCC system_header
4 
5 #include "cwb.hh"
6 #include "config.hh"
7 #include "network.hh"
8 #include "wavearray.hh"
9 #include "TString.h"
10 #include "TObjArray.h"
11 #include "TObjString.h"
12 #include "TRandom.h"
13 #include "TComplex.h"
14 #include "TMath.h"
15 #include "mdc.hh"
16 #include <vector>
17 #include "watplot.hh"
18 #include <stdio.h>
19 
20 #define OUTPUT_DIR "plots"
21 #define OUTPUT_TYPE "png"
22 
23 void Dump(WSeries<double> &w, double t1, double t2, const char* fname);
24 
25 void
27 //!EVENT_REPORT
28 // This plugin dump/plot the likelihood/null pixels of the detected/reconstructed event
29 
30  cout << endl;
31  cout << "-----> plugins/CWB_Plugin_pixeLHood.C" << endl;
32  cout << "ifo " << ifo.Data() << endl;
33  cout << "type " << type << endl;
34  cout << endl;
35 
36 
37  if(type==CWB_PLUGIN_OLIKELIHOOD) {
38 
39  int i,j,k,n,m,l;
40  int nIFO = NET->ifoListSize();
41  int K = NET->nLag;
42  int M = NET->mdc__ID.size();
43  int ID;
44  char search = NET->tYPe;
45 
47 
48  bool batch = gROOT->IsBatch();
49  gROOT->SetBatch(true);
50 
52 
53  char outdir[500] = OUTPUT_DIR;
54  char ifostr[20] = "";
55  char strtime[1024] = "";
56  char fname[1024];
57  char gtype[32] = OUTPUT_TYPE;
58 
59  int minTimeDet=nIFO;
60  double minTime=1e40;
61  double eventTime[NIFO];
62  double lagTime[NIFO];
63  int ifoid[NIFO],sortid[NIFO];
64  double factor = 1;
65 
66  netevent* EVT = new netevent(nIFO);
67 
68  int rate = int(2*NET->getifo(0)->TFmap.resolution(0)+0.5);
69 
70  for(k=0; k<K; k++) { // loop over the lags
71 
72  id = NET->getwc(k)->get(const_cast<char*>("ID"), 0, 'L', rate);
73 
74  for(j=0; j<(int)id.size(); j++) { // loop over cluster index
75 
76  ID = size_t(id.data[j]+0.5); // cluster id
77 
78  EVT->output(NULL,NET,factor,ID,k); // get reconstructed parameters
79  if(EVT->rho[1] < cfg->cedRHO) continue; // skip events under rho threshold
80 
81  int masterDet=0;
82  int lagMin=2147483647;
83  for(n=0; n<nIFO; n++) if(EVT->lag[n]<lagMin) {lagMin=int(EVT->lag[n]);masterDet=n;}
84 
85  NET->likelihood(search, NET->acor, ID, k); // exec likelihood search
86 
87  // get event network time
88  double gps_start = EVT->time[masterDet]-EVT->duration[masterDet];
89  double gps_stop = EVT->time[masterDet]+EVT->duration[masterDet];
90 
91  // create a unique label
92  for(n=0; n<nIFO; n++) sprintf(strtime, "%s_%.3f",strtime,EVT->start[n]);
93 
94  // dump event parameters
95  sprintf(fname, "%s/eventDump%s.%s", outdir, strtime, "txt");
96  EVT->dopen(fname,const_cast<char*>("w"));
97  EVT->output(NULL,NET,factor,ID,k);
98  EVT->dclose();
99 
100  // compute event time & lags time
101  for(n=0; n<nIFO; n++) eventTime[n]=(EVT->start[n]+EVT->stop[n])/2.;
102  for(n=0; n<nIFO; n++) minTime = (eventTime[n]<minTime) ? eventTime[n] : minTime;
103  for(n=0; n<nIFO; n++) lagTime[n]=eventTime[n]-minTime;
104  for(n=0; n<nIFO; n++) minTimeDet = (eventTime[n]<=minTime) ? n : minTimeDet;
105 
106  // set likelihood maps to optimal resolution level
107  double optRate = (NET->getwc(k)->cRate[ID-1])[0];
108  double optLayer = NET->getwc(k)->rate/optRate;
109  double optLevel = int(log10(optLayer)/log10(2));
110  for(int n=0;n<2;n++) {
112  if(n==0) pTF = &NET->pixeLHood;
113  if(n==1) pTF = &NET->pixeLNull;
114  pTF->Inverse(); // transform to time domain
115  pTF->Forward(optLevel); // transform to optimal level
116  }
117 
118  // plot likelihood map at optimal resolution level
119  WTS.canvas->cd();
120  sprintf(fname, "%s/l_tfmap_scalogram%s.%s", outdir, strtime, gtype);
121  WTS.plot(NET->pixeLHood, 0, gps_start-EVT->slag[masterDet],
122  gps_stop-EVT->slag[masterDet], const_cast<char*>("COLZ"));
123  WTS.hist2D->GetYaxis()->SetRangeUser(NET->pixeLHood.getlow(),NET->pixeLHood.gethigh());
124  WTS.hist2D->SetTitle("Scalogram");
125  WTS.canvas->Print(fname);
126  WTS.clear();
127 
128  // plot null map at optimal resolution level
129  sprintf(fname, "%s/n_tfmap_scalogram%s.%s", outdir, strtime, gtype);
130  WTS.plot(NET->pixeLNull, 0, gps_start-EVT->slag[masterDet],
131  gps_stop-EVT->slag[masterDet], const_cast<char*>("COLZ"));
132  WTS.hist2D->GetYaxis()->SetRangeUser(NET->pixeLNull.getlow(),NET->pixeLNull.gethigh());
133  WTS.hist2D->SetTitle("Scalogram");
134  WTS.canvas->Print(fname);
135  WTS.clear();
136 
137  // dump likelihood map at optimal resolution level
138  sprintf(fname, "%s/l_tfmap_scalogram%s.%s", outdir, strtime, "txt");
139  Dump(NET->pixeLHood, gps_start-EVT->slag[masterDet], gps_stop-EVT->slag[masterDet], fname);
140  // dump null map at optimal resolution level
141  sprintf(fname, "%s/n_tfmap_scalogram%s.%s", outdir, strtime, "txt");
142  Dump(NET->pixeLNull, gps_start-EVT->slag[masterDet], gps_stop-EVT->slag[masterDet], fname);
143 
144  } // End loop on found events
145  } // End loop on lags
146 
147  gROOT->SetBatch(batch); // restore batch status
148 
149  delete EVT;
150  }
151 
152  return;
153 }
154 
155 void Dump(WSeries<double> &w, double t1, double t2, const char* fname) {
156 
157  int ni = 1<<w.pWavelet->m_Level;
158  int nb = int((t1-w.start())*w.rate()/ni);
159  int nj = int((t2-t1)*w.rate())/ni;
160  int ne = nb+nj;
161  double rate=w.rate();
162  double df=rate/2/ni;
163  rate = rate/ni;
164  double dt = 1./rate;
165 
167 
168  FILE *fp;
169  if ( (fp = fopen(fname, "w")) == NULL ) {
170  cout << " Dump() error: cannot open file " << fname <<". \n";
171  return;
172  };
173 
174  for(int i=0;i<ni;i++) {
175  w.getLayer(wl,i);
176  for(int j=nb;j<=ne;j++) {
177  float t = (j+0.5)*dt;
178  float f = (i+0.5)*df;
179  float x = wl.data[j];
180  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);
181  }
182  }
183 
184  fclose(fp);
185 
186  return;
187 }
wavearray< double > t(hp.size())
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
#define NIFO
Definition: wat.hh:56
size_t nLag
Definition: network.hh:555
std::vector< vector_int > cRate
Definition: netcluster.hh:380
Float_t * rho
biased null statistics
Definition: netevent.hh:93
WSeries< double > pixeLHood
Definition: network.hh:616
tuple f
Definition: cwb_online.py:91
Double_t * start
cluster duration = stopW-startW
Definition: netevent.hh:80
fprintf(stdout,"start=%f duration=%f rate=%f\n", x.start(), x.size()/x.rate(), x.rate())
virtual void rate(double r)
Definition: wavearray.hh:123
Float_t * duration
max cluster time relative to segment start
Definition: netevent.hh:79
double cedRHO
Definition: config.hh:280
int n
Definition: cwb_net.C:10
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
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<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
wavearray< double > get(char *name, size_t index=0, char atype='R', int type=1, bool=true)
param: string with parameter name param: index in the amplitude array, which define detector param: c...
Definition: netcluster.cc:2188
char ifostr[64]
Long_t size
#define M
Definition: UniqSLagsList.C:3
int m
Definition: cwb_net.C:10
virtual void start(double s)
Definition: wavearray.hh:119
std::vector< size_t > mdc__ID
Definition: network.hh:597
int j
Definition: cwb_net.C:10
i drho i
double rate
Definition: netcluster.hh:360
search
void plot(wavearray< double > &, char *=NULL, int=1, double=0., double=0., bool=false, float=0., float=0., bool=false, float=0., bool=false)
Definition: watplot.cc:132
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
COHERENCE.
char ifo[NIFO_MAX][8]
void dopen(const char *fname, char *mode, bool header=true)
Definition: netevent.hh:291
TH2F * hist2D
Definition: watplot.hh:175
size_t ifoListSize()
Definition: network.hh:413
void clear()
Definition: watplot.hh:40
wavearray< double > w
Definition: Test1.C:27
#define nIFO
TCanvas * canvas
Definition: watplot.hh:174
double factor
jfile
Definition: cwb_job_obj.C:25
double getlow() const
Definition: wseries.hh:111
watplot * WTS
Definition: ChirpMass.C:115
i() int(T_cor *100))
network NET
Definition: cwb_dump_inj.C:12
Double_t * stop
GPS start time of the cluster.
Definition: netevent.hh:81
WSeries< double > pTF[nRES]
Definition: revMonster.cc:8
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
Definition: wseries.cc:175
Float_t * lag
time between consecutive events
Definition: netevent.hh:65
char fname[1024]
int k
void Dump(WSeries< double > &w, double t1, double t2, const char *fname)
double acor
Definition: network.hh:567
Float_t * slag
time lag [sec]
Definition: netevent.hh:66
int m_Level
Definition: Wavelet.hh:97
void output(TTree *=NULL, network *=NULL, double=0., size_t=0, int=-1)
Definition: netevent.cc:1166
long likelihood(char='E', double=sqrt(2.), int=0, size_t=0, int=-1, bool=false)
Definition: network.cc:4415
double gethigh() const
Definition: wseries.hh:118
double dt
WSeries< double > TFmap
Definition: detector.hh:336
WSeries< double > pixeLNull
Definition: network.hh:617
netevent EVT(itree, nifo)
Double_t * time
beam pattern coefficients for hx
Definition: netevent.hh:75
void dclose()
Definition: netevent.hh:300
double resolution(int=0)
Definition: wseries.hh:137
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
double df
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:421
int l
Definition: cbc_plots.C:434
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
DataType_t * data
Definition: wavearray.hh:301
Long_t id
TH1 * t1
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:438
fclose(ftrig)
#define OUTPUT_TYPE
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:273
char tYPe
Definition: network.hh:570