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