Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_SkyProb.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 save SkyProb into the output wave root file
45 
46  cout << endl;
47  cout << "-----> CWB_Plugin_SkyProb.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  cfg->Psave = 0; // disable save Skymap probability to root file
61  }
62 
63 
64 #ifdef NOISE_OTF
65  if(type==CWB_PLUGIN_DATA) {
66 
68 
69  int seed;
70  if(ifo.CompareTo("L1")==0) seed=1000;
71  if(ifo.CompareTo("H1")==0) seed=2000;
72  if(ifo.CompareTo("V1")==0) seed=3000;
73  if(ifo.CompareTo("J1")==0) seed=4000;
74  if(ifo.CompareTo("A2")==0) seed=5000;
75  if(ifo.CompareTo("Y2")==0) seed=6000;
76  if(ifo.CompareTo("Y3")==0) seed=7000;
77 
78  TString fName;
79  if(ifo.CompareTo("L1")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
80  if(ifo.CompareTo("H1")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
81  if(ifo.CompareTo("V1")==0) fName="plugins/strains/advVIRGO_sensitivity_12May09_8khz_one_side.txt";
82  if(ifo.CompareTo("J1")==0) fName="plugins/strains/LCGT_sensitivity_8khz_one_side.txt";
83  if(ifo.CompareTo("A2")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
84  if(ifo.CompareTo("Y2")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
85  if(ifo.CompareTo("Y3")==0) fName="plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
86 
87  int size=x->size();
88  double start=x->start();
89  TB.getSimNoise(*x, fName, seed, NET->nRun);
90  x->resize(size);
91  x->start(start);
92  }
93 #endif
94 
95 #ifdef MDC_OTF
96  if(type==CWB_PLUGIN_MDC) {
97 
98  char cmd[128];
99  sprintf(cmd,"network* net = (network*)%p;",NET);
100  gROOT->ProcessLine(cmd);
101 
102  CWB::mdc MDC(NET);
103 
104  // ---------------------------------
105  // read plugin config
106  // ---------------------------------
107 
108  cfg->configPlugin.Exec();
109 
110  // ---------------------------------
111  // set list of mdc waveforms
112  // ---------------------------------
113 
114  IMPORT(CWB::mdc,MDC)
115  MDC.Print();
116 
117  // ---------------------------------
118  // get mdc data
119  // ---------------------------------
120 
121  MDC.Get(*x,ifo);
122 
123  // ---------------------------------
124  // set mdc list in the network class
125  // ---------------------------------
126 
127  if(ifo.CompareTo(NET->ifoName[0])==0) {
128  NET->mdcList.clear();
129  NET->mdcType.clear();
130  NET->mdcTime.clear();
131  NET->mdcList=MDC.mdcList;
132  NET->mdcType=MDC.mdcType;
133  NET->mdcTime=MDC.mdcTime;
134  }
135 
136  cout.precision(14);
137  for(int k=0;k<(int)NET->mdcList.size();k++) cout << k << " mdcList " << MDC.mdcList[k] << endl;
138  for(int k=0;k<(int)NET->mdcTime.size();k++) cout << k << " mdcTime " << MDC.mdcTime[k] << endl;
139  for(int k=0;k<(int)NET->mdcType.size();k++) cout << k << " mdcType " << MDC.mdcType[k] << endl;
140  }
141 #endif
142 
143  if(type==CWB_PLUGIN_OLIKELIHOOD) {
144 
145  if(TString(cfg->analysis)!="2G") {
146  cout << "CWB_Plugin_SkyProb.C -> CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
147  gSystem->Exit(1);
148  }
149 
150 #ifdef WATPLOT
151  watplot SMS(const_cast<char*>("sms"),200,20,800,400);
152 #endif
153 
154  // import ifactor
155  int gIFACTOR=-1; IMPORT(int,gIFACTOR)
156  cout << "-----> CWB_Plugin_SkyProb.C -> " << " gIFACTOR : " << gIFACTOR << endl;
157 
158  // import slagShift
159  float* gSLAGSHIFT=NULL; IMPORT(float*,gSLAGSHIFT)
160 
161  int nIFO = NET->ifoListSize(); // number of detectors
162  int K = NET->nLag; // number of time lag
163  netevent* EVT;
165  double factor = cfg->simulation==3||cfg->simulation==4 ? -gIFACTOR : cfg->factors[gIFACTOR];
166  int rate = 0; // select all resolutions
167 
168  // search output root file in the system list
169  TFile* froot = NULL;
170  TList *files = (TList*)gROOT->GetListOfFiles();
171  TString outDump="";
172  if (files) {
173  TIter next(files);
174  TSystemFile *file;
175  TString fname;
176  bool check=false;
177  while ((file=(TSystemFile*)next())) {
178  fname = file->GetName();
179  // set output root file as the current file
180  if(fname.Contains("wave_")) {
181  froot=(TFile*)file;froot->cd();
182  outDump=fname;
183  outDump.ReplaceAll(".root.tmp",".txt");
184  cout << "output file name : " << fname << endl;
185  }
186  }
187  if(!froot) {
188  cout << "CWB_Plugin_SkyProb.C : Error - output root file not found" << endl;
189  gSystem->Exit(1);
190  }
191  } else {
192  cout << "CWB_Plugin_SkyProb.C : Error - output root file not found" << endl;
193  gSystem->Exit(1);
194  }
195 
196  TTree* net_tree = (TTree *) froot->Get("waveburst");
197  if(net_tree!=NULL) {
198  EVT = new netevent(net_tree,nIFO);
199  } else {
200  EVT = new netevent(nIFO);
201  net_tree = EVT->setTree();
202  }
203  EVT->setSLags(gSLAGSHIFT); // set slags into netevent
204 
205  skymap* Psm = new skymap(int(0));
206  net_tree->SetBranchAddress("Psm",&Psm);
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  *Psm = NET->nProbability;
219 
220  double ofactor=0;
221  if(cfg->simulation==4) ofactor=-factor;
222  else if(cfg->simulation==3) ofactor=-gIFACTOR;
223  else ofactor=factor;
224  if(cfg->dump) EVT->dopen(outDump.Data(),const_cast<char*>("a"),false);
225  EVT->output2G(net_tree,NET,ID,k,ofactor); // get reconstructed parameters
226  if(cfg->dump) EVT->dclose();
227  if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1; // mark as processed
228 
229 #ifdef WATPLOT // monster event display
230  SMS.canvas->cd();
231  char fname2[1024];
232  sprintf(fname2, "skyprob_%d.png",ID);
233  cout << "write " << fname2 << endl;
234  SMS.plot(NET->nProbability, 0);
235  SMS.canvas->Print(fname2);
236  SMS.clear();
237 #endif
238  }
239  }
240 
241  jfile->cd();
242 
243  delete Psm;
244  if(EVT) delete EVT;
245  }
246 
247  return;
248 }
249 
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
CWB::Toolbox TB
bool cedDump
Definition: config.hh:297
std::vector< std::string > mdcType
Definition: network.hh:613
#define SMS
Definition: FrDisplay.cc:126
CWB::mdc * MDC
Long_t size
virtual void start(double s)
Definition: wavearray.hh:137
int j
Definition: cwb_net.C:28
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
int Psave
Definition: config.hh:193
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
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
COHERENCE.
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:69
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
Definition: skymap.hh:63
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
skymap nProbability
Definition: network.hh:631
bool dump
Definition: config.hh:295