Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CWB_Plugin_waveform.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 
21 double GetBoundaries(wavearray<double> x, double P, double& bT, double& eT);
22 
23 void
25 //!EVENT_REPORT
26 // This plugin add to the output root file the whitened recunstructed waveforms
27 
28  cout << endl;
29  cout << "-----> plugins/CWB_Plugin_waveform.C" << endl;
30  cout << "ifo " << ifo.Data() << endl;
31  cout << "type " << type << endl;
32  cout << endl;
33 
34 
35  if(type==CWB_PLUGIN_OLIKELIHOOD) {
36 
37  int i,j,k,n,m,l;
38  int nIFO = NET->ifoListSize();
39  int K = NET->nLag;
40  int M = NET->mdc__ID.size();
41  int ID;
42  char search = NET->tYPe;
43 
45 
46  bool batch = gROOT->IsBatch();
47  gROOT->SetBatch(true);
48 
49  char ifostr[20] = "";
50  char strtime[1024] = "";
51  char fname[1024];
52 
53  int minTimeDet=nIFO;
54  double minTime=1e40;
55  double eventTime[NIFO];
56  double lagTime[NIFO];
57  int ifoid[NIFO],sortid[NIFO];
58  double factor = 1;
59  detector *pD[NIFO];
60 
61 
62  netevent* EVT = new netevent(nIFO);
63 
64  // search output root file in the system list
65  TFile* froot = NULL;
66  TList *files = (TList*)gROOT->GetListOfFiles();
67  if (files) {
68  TIter next(files);
69  TSystemFile *file;
70  TString fname;
71  bool check=false;
72  while ((file=(TSystemFile*)next())) {
73  fname = file->GetName();
74  // set output root file as the current file
75  if(fname.Contains("wave_")) {froot=(TFile*)file;froot->cd();}
76  }
77  if(!froot) {
78  cout << "plugins/CWB_Plugin_waveform.C : Error - output root file not found" << endl;
79  exit(1);
80  }
81  } else {
82  cout << "plugins/CWB_Plugin_waveform.C : Error - output root file not found" << endl;
83  exit(1);
84  }
85 
86  int ndim=nIFO;
87  int run=NET->nRun;
88  int eventID;
89  float rho,netcc,frequency,likelihood;
90  float snr[NIFO];
91  double time[NIFO];
92  int lag[NIFO+1];
93  int slag[NIFO+1];
95  for(n=0; n<nIFO; n++) wave[n] = new wavearray<double>;
96  TTree* wftree = (TTree *) froot->Get("waveform");
97  if(wftree==NULL) {
98  wftree = new TTree("waveform","waveform");
99  wftree->Branch("ndim",&ndim,"ndim/I");
100  wftree->Branch("run",&run,"run/I");
101  wftree->Branch("eventID",&eventID,"eventID/I");
102  wftree->Branch("rho",&rho,"rho/F");
103  wftree->Branch("netcc",&netcc,"netcc/F");
104  wftree->Branch("likelihood",&likelihood,"likelihood/F");
105  char csnr[16];sprintf(csnr,"snr[%1d]/F",nIFO);
106  wftree->Branch("snr",snr,csnr);
107  wftree->Branch("frequency",&frequency,"frequency/F");
108  char ctime[16];sprintf(ctime,"time[%1d]/D",nIFO);
109  wftree->Branch("time",time,ctime);
110  char clag[16];sprintf(clag,"lag[%1d]/F",nIFO+1);
111  char cslag[16];sprintf(cslag,"slag[%1d]/F",nIFO+1);
112  wftree->Branch("lag",lag,clag);
113  wftree->Branch("slag",slag,cslag);
114  char label[256];
115  for(n=0; n<nIFO; n++) {
116  sprintf(label, "%s_waveform", NET->ifoName[n]);
117  wftree->Branch(label,"wavearray<double>",&wave[n],32000,0);
118  }
119  } else {
120  wftree->SetBranchAddress("ndim",&ndim);
121  wftree->SetBranchAddress("run",&run);
122  wftree->SetBranchAddress("eventID",&eventID);
123  wftree->SetBranchAddress("rho",&rho);
124  wftree->SetBranchAddress("netcc",&netcc);
125  wftree->SetBranchAddress("frequency",&frequency);
126  wftree->SetBranchAddress("likelihood",&likelihood);
127  wftree->SetBranchAddress("snr",snr);
128  wftree->SetBranchAddress("time",time);
129  wftree->SetBranchAddress("lag",lag);
130  wftree->SetBranchAddress("slag",slag);
131  char label[256];
132  for(n=0; n<nIFO; n++) {
133  wave[n] = new wavearray<double>;
134  sprintf(label, "%s_waveform", NET->ifoName[n]);
135  wftree->SetBranchAddress(label,&wave[n]);
136  }
137  }
138 
139  for(n=0; n<nIFO; n++) pD[n] = NET->getifo(n);
140 
141  int rate = int(2*NET->getifo(0)->TFmap.resolution(0)+0.5);
142 
143  for(k=0; k<K; k++) { // loop over the lags
144 
145  id = NET->getwc(k)->get(const_cast<char*>("ID"), 0, 'L', rate);
146 
147  for(j=0; j<(int)id.size(); j++) { // loop over cluster index
148 
149  ID = size_t(id.data[j]+0.5); // cluster id
150 
151  eventID = ID;
152 
153  EVT->output(NULL,NET,factor,ID,k); // get reconstructed parameters
154  if(EVT->rho[1] < cfg->cedRHO) continue; // skip events under rho threshold
155 
156  rho = EVT->rho[1];
157  netcc = EVT->netcc[0];
158  frequency = EVT->frequency[0];
159  likelihood = EVT->likelihood;
160  for(n=0; n<nIFO; n++) snr[n] = EVT->sSNR[n];
161  for(n=0; n<nIFO; n++) time[n] = EVT->time[n];
162  for(n=0; n<=nIFO; n++) lag[n] = EVT->lag[n];
163  for(n=0; n<=nIFO; n++) slag[n] = EVT->slag[n];
164 
165  int masterDet=0;
166  int lagMin=2147483647;
167  for(n=0; n<nIFO; n++) if(EVT->lag[n]<lagMin) {lagMin=int(EVT->lag[n]);masterDet=n;}
168 
169  NET->likelihood(search, NET->acor, ID, k); // exec likelihood search
170 
171  // get event network time
172  double gps_start = EVT->time[masterDet]-EVT->duration[masterDet];
173  double gps_stop = EVT->time[masterDet]+EVT->duration[masterDet];
174 
175  // create a unique label
176  //for(n=0; n<nIFO; n++) sprintf(strtime, "%s_%.3f",strtime,EVT->start[n]);
177  for(n=0; n<nIFO; n++) sprintf(strtime, "%s_%d",strtime,(int)EVT->start[n]);
178 
179  // compute event time & lags time
180  for(n=0; n<nIFO; n++) eventTime[n]=(EVT->start[n]+EVT->stop[n])/2.;
181  for(n=0; n<nIFO; n++) minTime = (eventTime[n]<minTime) ? eventTime[n] : minTime;
182  for(n=0; n<nIFO; n++) lagTime[n]=eventTime[n]-minTime;
183  for(n=0; n<nIFO; n++) minTimeDet = (eventTime[n]<=minTime) ? n : minTimeDet;
184 
185  NET->getwave(ID, k, 'W');
187  for(n=0; n<nIFO; n++) {
188  w.start(0);
189  w.rate(pD[n]->waveForm.rate());
190  w.resize(pD[n]->waveForm.size());
191  for(int i=0;i<w.size();i++) w[i]=pD[n]->waveForm.data[i];
192 
193  double bT,eT;
194  GetBoundaries(w, 0.99, bT, eT);
195  //cout << w.start() << " " << bT << " " << eT << " " << eT-bT << endl;
196 
197  // select data which contains the 0.99 of energy
198  double dt = 1./w.rate();
199  int size = (eT-bT)/dt;
200  int os = bT/dt;
201  wave[n]->resize(size);
202  wave[n]->start(w.start());
203  wave[n]->rate(w.rate());
204  for(int i=0;i<size;i++) wave[n]->data[i]=w[i+os];
205  }
206 
207  wftree->Fill();
208  } // End loop on found events
209  }
210 
211  wftree->Write("", TObject::kOverwrite);
212 
213  gROOT->SetBatch(batch); // restore batch status
214 
215  jfile->cd();
216 
217  for(n=0; n<nIFO; n++) delete wave[n];
218  delete EVT;
219  }
220 
221  if(type==CWB_PLUGIN_CLOSE_JOB) {
222  }
223 
224  return;
225 }
226 
227 
228 double
229 GetBoundaries(wavearray<double> x, double P, double& bT, double& eT) {
230 
231  if(P<0) P=0;
232  if(P>1) P=1;
233 
234  int N = x.size();
235 
236  double E = 0; // signal energy
237  double avr = 0; // average
238  for(int i=0;i<N;i++) {avr+=i*x[i]*x[i]; E+=x[i]*x[i];}
239  int M=int(avr/E); // central index
240 
241  // search range which contains percentage P of the total energy E
242  int jB=0;
243  int jE=N-1;
244  double a,b;
245  double sum = ((M>=0)&&(M<N)) ? x[M]*x[M] : 0.;
246  for(int j=1; j<N; j++) {
247  a = ((M-j>=0)&&(M-j<N)) ? x[M-j] : 0.;
248  b = ((M+j>=0)&&(M+j<N)) ? x[M+j] : 0.;
249  if(a) jB=M-j;
250  if(b) jE=M+j;
251  sum += a*a+b*b;
252  if(sum/E > P) break;
253  }
254 
255  bT = x.start()+jB/x.rate();
256  eT = x.start()+jE/x.rate();
257 
258  return eT-bT;
259 }
260 
261 
std::vector< char * > ifoName
Definition: network.hh:591
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
double rho
virtual size_t size() const
Definition: wavearray.hh:127
#define NIFO
Definition: wat.hh:56
size_t nLag
Definition: network.hh:555
Float_t * rho
biased null statistics
Definition: netevent.hh:93
Double_t * start
cluster duration = stopW-startW
Definition: netevent.hh:80
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
CWB run(runID)
bool getwave(size_t, size_t, char='W')
param: cluster ID param: delay index param: time series type return: true if time series are extracte...
Definition: network.cc:3545
wavearray< double > a(hp.size())
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")
netevent W & wave
TString("c")
size_t nRun
Definition: network.hh:554
int ID
Definition: TestMDC.C:70
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
double frequency
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
TRandom3 P
Definition: compare_bkg.C:296
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
double rate
Definition: detector.hh:323
i drho i
search
#define N
double GetBoundaries(wavearray< double > x, double P, double &bT, double &eT)
char ifo[NIFO_MAX][8]
TCut netcc("netcc","netcc[0]>0.7")
size_t ifoListSize()
Definition: network.hh:413
wavearray< double > w
Definition: Test1.C:27
#define nIFO
Float_t * frequency
GPS stop time of the cluster.
Definition: netevent.hh:83
double factor
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
COHERENCE.
double time[6]
Definition: cbc_plots.C:435
jfile
Definition: cwb_job_obj.C:25
i() int(T_cor *100))
network NET
Definition: cwb_dump_inj.C:12
TString label
Definition: MergeTrees.C:21
Double_t * stop
GPS start time of the cluster.
Definition: netevent.hh:81
TIter next(twave->GetListOfBranches())
Float_t * lag
time between consecutive events
Definition: netevent.hh:65
char fname[1024]
int k
Float_t * netcc
effective correlated SNR
Definition: netevent.hh:94
double acor
Definition: network.hh:567
Float_t * slag
time lag [sec]
Definition: netevent.hh:66
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
TFile * froot
double dt
WSeries< double > TFmap
Definition: detector.hh:336
netevent EVT(itree, nifo)
Double_t * time
beam pattern coefficients for hx
Definition: netevent.hh:75
string file
Definition: cwb_online.py:385
Float_t * sSNR
data-signal correlation Xk*Sk
Definition: netevent.hh:117
double resolution(int=0)
Definition: wseries.hh:137
Float_t likelihood
Definition: netevent.hh:105
Definition: Toolbox.hh:81
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)
Long_t id
snr * snr
Definition: ComputeSNR.C:71
double ctime
list files
Definition: cwb_online.py:529
virtual void resize(unsigned int)
Definition: wavearray.cc:445
int check
char tYPe
Definition: network.hh:570
detector ** pD
exit(0)
char os[1024]
double avr