Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_NN.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 "watplot.hh"
35 #include <vector>
36 
37 //#define WATPLOT // enable event monster plots
38 #define MDC_OTF // enable MDC On The Fly
39 #define NOISE_OTF // enable NOISE On The Fly
40 
41 void
43 //!NOISE_MDC_SIMULATION
44 // Plugin to include netcluster event stricture into the output wave root file (used in NN)
45 
46  cout << endl;
47  cout << "-----> CWB_Plugin_NN.C" << endl;
48  cout << "ifo " << ifo.Data() << endl;
49  cout << "type " << type << endl;
50  cout << endl;
51 
52  if(type==CWB_PLUGIN_CONFIG) {
53 #ifdef NOISE_OTF
54  cfg->dataPlugin=true; // disable read data from frames
55 #endif
56 #ifdef MDC_OTF
57  cfg->mdcPlugin=true; // disable read mdc from frames
58 #endif
59  cfg->outPlugin=true; // disable built-in output root file
60  }
61 
62 
63 #ifdef NOISE_OTF
64  if(type==CWB_PLUGIN_DATA) {
65 
67 
68  int seed;
69  if(ifo.CompareTo("L1")==0) seed=1000;
70  if(ifo.CompareTo("H1")==0) seed=2000;
71  if(ifo.CompareTo("V1")==0) seed=3000;
72  if(ifo.CompareTo("J1")==0) seed=4000;
73  if(ifo.CompareTo("A2")==0) seed=5000;
74  if(ifo.CompareTo("Y2")==0) seed=6000;
75  if(ifo.CompareTo("Y3")==0) seed=7000;
76 
77  TString fName;
78  if(ifo.CompareTo("L1")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
79  if(ifo.CompareTo("H1")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
80  if(ifo.CompareTo("V1")==0) fName="plugins/strains/advVIRGO_sensitivity_12May09_8khz_one_side.txt";
81  if(ifo.CompareTo("J1")==0) fName="plugins/strains/LCGT_sensitivity_8khz_one_side.txt";
82  if(ifo.CompareTo("A2")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
83  if(ifo.CompareTo("Y2")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
84  if(ifo.CompareTo("Y3")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
85 
86  int size=x->size();
87  double start=x->start();
88  TB.getSimNoise(*x, fName, seed, NET->nRun);
89  x->resize(size);
90  x->start(start);
91  }
92 #endif
93 
94 #ifdef MDC_OTF
95  if(type==CWB_PLUGIN_MDC) {
96 
97  char cmd[128];
98  sprintf(cmd,"network* net = (network*)%p;",NET);
99  gROOT->ProcessLine(cmd);
100 
101  CWB::mdc MDC(NET);
102 
103  // ---------------------------------
104  // read plugin config
105  // ---------------------------------
106 
107  cfg->configPlugin.Exec();
108 
109  // ---------------------------------
110  // set list of mdc waveforms
111  // ---------------------------------
112 
113  IMPORT(CWB::mdc,MDC)
114  MDC.Print();
115 
116  // ---------------------------------
117  // get mdc data
118  // ---------------------------------
119 
120  MDC.Get(*x,ifo);
121 
122  // ---------------------------------
123  // set mdc list in the network class
124  // ---------------------------------
125 
126  if(ifo.CompareTo(NET->ifoName[0])==0) {
127  NET->mdcList.clear();
128  NET->mdcType.clear();
129  NET->mdcTime.clear();
130  NET->mdcList=MDC.mdcList;
131  NET->mdcType=MDC.mdcType;
132  NET->mdcTime=MDC.mdcTime;
133  }
134 
135  cout.precision(14);
136  for(int k=0;k<(int)NET->mdcList.size();k++) cout << k << " mdcList " << MDC.mdcList[k] << endl;
137  for(int k=0;k<(int)NET->mdcTime.size();k++) cout << k << " mdcTime " << MDC.mdcTime[k] << endl;
138  for(int k=0;k<(int)NET->mdcType.size();k++) cout << k << " mdcType " << MDC.mdcType[k] << endl;
139  }
140 #endif
141 
142  if(type==CWB_PLUGIN_OLIKELIHOOD) {
143 
144  if(TString(cfg->analysis)!="2G") {
145  cout << "CWB_Plugin_NN.C -> CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
146  gSystem->Exit(1);
147  }
148 
149 #ifdef WATPLOT
150  watplot WTS(const_cast<char*>("wts"));
151 #endif
152 
153  // import ifactor
154  int gIFACTOR=-1; IMPORT(int,gIFACTOR)
155  cout << "-----> CWB_Plugin_NN.C -> " << " gIFACTOR : " << gIFACTOR << endl;
156 
157  // import slagShift
158  float* gSLAGSHIFT=NULL; IMPORT(float*,gSLAGSHIFT)
159 
160  int nIFO = NET->ifoListSize(); // number of detectors
161  int K = NET->nLag; // number of time lag
162  netevent* EVT;
164  double factor = cfg->simulation==3||cfg->simulation==4 ? -gIFACTOR : cfg->factors[gIFACTOR];
165  int rate = 0; // select all resolutions
166 
167  // search output root file in the system list
168  TFile* froot = NULL;
169  TList *files = (TList*)gROOT->GetListOfFiles();
170  TString outDump="";
171  if (files) {
172  TIter next(files);
173  TSystemFile *file;
174  TString fname;
175  bool check=false;
176  while ((file=(TSystemFile*)next())) {
177  fname = file->GetName();
178  // set output root file as the current file
179  if(fname.Contains("wave_")) {
180  froot=(TFile*)file;froot->cd();
181  outDump=fname;
182  outDump.ReplaceAll(".root.tmp",".txt");
183  cout << "output file name : " << fname << endl;
184  }
185  }
186  if(!froot) {
187  cout << "CWB_Plugin_NN.C : Error - output root file not found" << endl;
188  gSystem->Exit(1);
189  }
190  } else {
191  cout << "CWB_Plugin_NN.C : Error - output root file not found" << endl;
192  gSystem->Exit(1);
193  }
194 
195  netcluster* pwc = new netcluster();
196  TTree* net_tree = (TTree *) froot->Get("waveburst");
197  if(net_tree!=NULL) {
198  EVT = new netevent(net_tree,nIFO);
199  net_tree->SetBranchAddress("netcluster",&pwc);
200  } else {
201  EVT = new netevent(nIFO);
202  net_tree = EVT->setTree();
203  // add new netcluster leaf
204  net_tree->Branch("netcluster","netcluster",&pwc,32000,0);
205  }
206  EVT->setSLags(gSLAGSHIFT); // set slags into netevent
207 
208  for(int k=0; k<K; k++) { // loop over the lags
209 
210  id = NET->getwc(k)->get(const_cast<char*>("ID"), 0, 'L', rate);
211 
212  for(int j=0; j<(int)id.size(); j++) { // loop over cluster index
213 
214  int ID = size_t(id.data[j]+0.5);
215 
216  if(NET->getwc(k)->sCuts[ID-1]!=-1) continue; // skip rejected/processed clusters
217 
218  std::vector<int> sCuts = NET->getwc(k)->sCuts; // save cCuts
219  // set sCuts=1 to the events which must be not copied with cps to pwc
220  for(int i=0; i<(int)sCuts.size(); i++) if(i!=ID-1) NET->getwc(k)->sCuts[i]=1;
221 
222  // after cpf, pwc contains only one event
223  // ID can not be used to get the event, to get event use ID=1 (ex: for watplot)
224  pwc->cpf(*(NET->getwc(k))); // note: likelihood2G delete tdAmp
225  NET->getwc(k)->sCuts = sCuts; // restore cCuts
226 
227  double ofactor=0;
228  if(cfg->simulation==4) ofactor=-factor;
229  else if(cfg->simulation==3) ofactor=-gIFACTOR;
230  else ofactor=factor;
231  if(cfg->dump) EVT->dopen(outDump.Data(),const_cast<char*>("a"),false);
232  EVT->output2G(net_tree,NET,ID,k,ofactor); // get reconstructed parameters
233  if(cfg->dump) EVT->dclose();
234  if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1; // mark as processed
235 
236 #ifdef WATPLOT // monster event display
237  WTS.canvas->cd();
238  char fname2[1024];
239  sprintf(fname2, "l_tfmap_scalogram_%d.png",ID);
240  cout << "write " << fname2 << endl;
241  WTS.plot(pwc, 1, nIFO, 'L', 0, const_cast<char*>("COLZ")); // use ID=1
242  WTS.canvas->Print(fname2);
243  WTS.clear();
244 #endif
245  }
246  }
247 
248  jfile->cd();
249 
250  if(pwc) delete pwc;
251  if(EVT) delete EVT;
252  }
253 
254  return;
255 }
256 
std::vector< char * > ifoName
Definition: network.hh:609
CWB::config * cfg
char analysis[8]
Definition: config.hh:117
TString outDump
virtual void resize(unsigned int)
Definition: wseries.cc:901
size_t nLag
Definition: network.hh:573
void setSLags(float *slag)
Definition: netevent.cc:426
TMacro configPlugin
Definition: config.hh:362
TString Get(wavearray< double > &x, TString ifo)
Definition: mdc.cc:1529
bool mdcPlugin
Definition: config.hh:365
std::vector< std::string > mdcList
Definition: mdc.hh:389
float factor
bool dataPlugin
Definition: config.hh:364
TTree * setTree()
Definition: netevent.cc:434
TString("c")
std::vector< std::string > mdcType
Definition: mdc.hh:390
size_t nRun
Definition: network.hh:572
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<< "\ 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
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
COHERENCE.
Definition: CWB_Plugin_NN.C:42
netcluster * pwc
Definition: cwb_job_obj.C:38
CWB::Toolbox TB
bool cedDump
Definition: config.hh:297
std::vector< std::string > mdcType
Definition: network.hh:613
CWB::mdc * MDC
Long_t size
virtual void start(double s)
Definition: wavearray.hh:137
int j
Definition: cwb_net.C:28
i drho i
std::vector< double > mdcTime
Definition: network.hh:614
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
bool outPlugin
Definition: config.hh:369
void Print(int level=0)
Definition: mdc.cc:2736
char ifo[NIFO_MAX][8]
void dopen(const char *fname, char *mode, bool header=true)
Definition: netevent.hh:312
size_t ifoListSize()
Definition: network.hh:431
void clear()
Definition: watplot.hh:58
#define nIFO
virtual size_t size() const
Definition: wavearray.hh:145
TCanvas * canvas
Definition: watplot.hh:192
jfile
Definition: cwb_job_obj.C:43
void output2G(TTree *, network *, size_t, int, double)
Definition: netevent.cc:711
static void getSimNoise(wavearray< double > &u, TString fName, int seed, int run)
Definition: Toolbox.cc:5593
TTree * net_tree
Definition: mdc.hh:248
int simulation
Definition: config.hh:199
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:69
watplot * WTS
Definition: ChirpMass.C:119
i() int(T_cor *100))
network NET
Definition: cwb_dump_inj.C:30
std::vector< std::string > mdcList
Definition: network.hh:612
TIter next(twave->GetListOfBranches())
char fname[1024]
int k
size_t cpf(const netcluster &, bool=false, int=0)
Definition: netcluster.cc:117
TFile * froot
netevent EVT(itree, nifo)
std::vector< int > sCuts
Definition: netcluster.hh:392
void dclose()
Definition: netevent.hh:321
int gIFACTOR
char cmd[1024]
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:439
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
Long_t id
double factors[FACTORS_MAX]
Definition: config.hh:202
std::vector< double > mdcTime
Definition: mdc.hh:392
char fName[256]
int check
bool dump
Definition: config.hh:295