Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_job_obj.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 // Coherent WaveBurst production script for GW network (obsolete)
20 
21 {
22 
23  #include <vector>
24 
25 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26 // declarations
27 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28 
29  TFile* jfile;
30  TDirectory* cdsim;
31  TDirectory* cdprod;
32 
33  char tdf00[1024];
34  char tdf90[1024];
35  char end_CED[1024];
36 
41  WSeries<double> wM; // mdc WSeries
42 
43  jfile = gROOT->GetFile();
44  jfile->ReOpen("UPDATE");
45  if(jfile==NULL) {cout << "Error opening input root file " << endl;exit(1);}
46  jfile->ls();
47 
48  // read network object
49  network NET = *(network*)jfile->Get("net");
50  // read config object
51  CWB::config config = *(CWB::config*)jfile->Get("config");
52  // restore config parameters in CINT
53  config.Export();
54 
55  if(simulation) cdsim = (TDirectory*)jfile->Get("sim");
56  else cdprod = (TDirectory*)jfile->Get("prod");
57 
58  nSky=1000;
59  NET.nSky=nSky;
60 
61  cedDump=true;
62  TObjArray* token = TString(jfile->GetName()).Tokenize(TString("/"));
63  TObjString* path_tok = (TObjString*)token->At(token->GetEntries()-1);
64  TString jname = path_tok->GetString().Data();
65  cout << jname.Data() << endl;
66 
67  // print ifo infos
68  cout << "nIFO : " << nIFO << endl;
69  for(int n=0; n<nIFO; n++) pD[n] = NET.getifo(n);
70  for(int n=0; n<nIFO; n++) pD[n]->print();
71 
72  // restore skymaps
73  NET.setSkyMaps(angle);
74  NET.setAntenna();
75  NET.setDelay(pD[0]->Name);
76 
77 /* not needed with fixed network copy constructor !!!
78  // restore network NDM & ifoName lists
79  vectorD v; v.clear();
80  for(int n=0; n<nIFO; n++) {
81  NET.NDM.push_back(v);
82  for(int m=0; m<nIFO; m++) NET.NDM[n].push_back(0);
83  NET.ifoName.push_back(pD[n]->Name);
84  }
85  cout << "NDM size " << NET.NDM.size() << endl;
86 */
87  // there is a issue in network class (no TClass for char*)
88  NET.ifoName.clear();
89  for(int n=0; n<nIFO; n++) NET.ifoName.push_back(pD[n]->Name);
90 
91  // declare netevent
92  netevent netburst(nIFO,Psave);
93 
94  // print network infos
95  double mTau=NET.getDelay("MAX"); // maximum time delay
96  double dTau=NET.getDelay(); // time delay difference
97  cout<<"maximum time delay between detectors: "<<mTau<<endl;
98  cout<<" maximum time delay difference: "<<dTau<<endl;
99  cout<<" netRHO and netCC: "<<NET.netRHO<<", "<<NET.netCC<<endl;
100  cout<<" regulator delta, gamma: "<<NET.delta <<" " <<NET.gamma<<endl<<endl;
101 
102  gSystem->Exec("/bin/date");
103  gSystem->Exec("/bin/hostname");
104 
105 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106 // data conditioning
107 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
108 
109  if(!simulation) nfactor = 1;
110  for(int iii=0; iii<nfactor; iii++) {
111  double factor=factors[iii];
112  cout<<"factor="<<factor<<endl;
113  char sfactor[32];
114  sprintf(sfactor,"factor_%g",factor);
115  // build end_CED file name
116  sprintf(end_CED,"%s/ced_%s_%g",ced_dir,jname.ReplaceAll(".root","").Data(),factor);
117 
118  for(int i=0; i<nIFO; i++) {
119  pTF[i] = (WSeries<double>*)jfile->Get(TString("proc/")+pD[i]->Name);
120  if(pTF[i]==NULL || simulation) { // process raw data
121  pTF[i] = (WSeries<double>*)jfile->Get(TString("raw/")+pD[i]->Name);
122  if(pTF[i]==NULL) {cout << "Error : data not present, job terminated!!!" << endl;return;}
123  pTF[i] = pD[i]->getTFmap();
124  *pTF[i] = *(WSeries<double>*)jfile->Get(TString("raw/")+pD[i]->Name);
125  if(simulation) {
126  wM = *(WSeries<double>*)jfile->Get(TString("raw/")+ifo[i]+TString(":mdc"));
127  wM*=factor;
128  pTF[i]->add(wM);
129  wM*=1./factor;
130  }
131  pTF[i]->lprFilter(2,0,Tlpr,4.);
132  pTF[i]->setlow(fLow);
133  pD[i]->white(60.,1,8.,20.);
134  if(simulation) pD[i]->setsim(wM,NET.getmdcTime(),10.,8.,true);
135  pTF[i]->Inverse(levelD-levelF);
136  pTF[i]->lprFilter(2,0,Tlpr,4.);
137  pTF[i]->Forward(levelD-levelF);
138  pTF[i]->sethigh(fHigh);
139  pD[i]->bandPass();
140  cout<<"After "<<pD[i]->Name<<" data conditioning"<<endl;
141  gSystem->Exec("/bin/date"); GetProcInfo();
142  } else { // process proc data
143  pTF[i] = pD[i]->getTFmap();
144  *pTF[i] = *(WSeries<double>*)jfile->Get(TString("proc/")+pD[i]->Name);
145  }
146  }
147 
148  // set the decomposition level
149  for(int i=0; i<nIFO; i++) pTF[i]->Inverse(levelD-l_low);
150  NET.setTimeShifts();
151 
152 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
153 // supercluster analysis
154 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
155 
156  int lags=1;
157  for(int j=0; j<lags; j++){
158  wc.clear();
159  TString wcdir = simulation ? TString("sim/")+sfactor : TString("prod/lag_")+j;
160  TIter nextkey(((TDirectory*)jfile->Get(wcdir))->GetListOfKeys());
161  TKey *key;while(key=(TKey*)nextkey()) wc.append(*(netcluster*)key->ReadObj());
162  int m = wc.supercluster('L',NET.e2or,true);
163  pwc = NET.getwc(j); pwc->cpf(wc,true);
164  cout<<m<<"|"<<pwc->size()<<" ";
165  }
166 
167 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168 // likelihood
169 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170 
171  TDirectory* cdced = NULL;
172  if(cedDump) {cdced = simulation ? cdsim->mkdir("ced") : cdprod->mkdir("ced"); }
173 
174  for(int i=l_low; i<=l_high; i++) {
175  sprintf(tdf00,"%s/Meyer1024wat482_00%s_L%1d.dat",filter_dir,filter,i);
176  sprintf(tdf90,"%s/Meyer1024wat482_90%s_L%1d.dat",filter_dir,filter,i);
177  NET.setDelayFilters(tdf00,tdf90);
178 
179  if(i==l_low) {
180  //NET.pOUT=true;
181  NET.setDelayIndex();
182  NET.setIndexMode(mode);
183  }
184 
185  cout<<endl;
186  cout<<"selected core pixels: "<<NET.likelihood(SEARCH(),Acore)<<" for level "<<i<<"\n";
187  cout<<"rejected weak pixels: "<<NET.netcut(NET.netRHO,'r',0,1)<<"\n"; // remove weak glitches
188  cout<<"rejected loud pixels: "<<NET.netcut(NET.netCC,'c',0,1)<<"\n"; // remove loud glitches
189  cout<<"events in the buffer: "<<NET.events()<<"\n";
190 
191  if(cedDump) {
192  if(cdced==NULL) {
193  cout<<"dump ced into "<<end_CED<<"\n";
194  CWB::ced ced(&NET,&netburst,end_CED);
195  } else {
196  //gBenchmark->Start("ced");
197  CWB::ced ced(&NET,&netburst,cdced);
198  //gBenchmark->Show("ced");
199  //gBenchmark->Reset();
200  }
201  ced.SetOptions(cedRHO);
202  ced.Write(factor);
203  }
204 
205  if(i<l_high) NET.Forward(1);
206  }
207 
208  gSystem->Exec("/bin/date"); GetProcInfo();
209  cout<<"\nSearch done\n";
210  cout<<"reconstructed events: "<<NET.events()<<"\n";
211 
212 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
213 // save data in root file
214 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
215 
216  if(simulation) cdsim->cd(); else cdprod->cd();
217 
218  TTree* net_tree = netburst.setTree();
219 
220  // build output data txt name (in the /dev/shm directory)
221  char ofile[256];
222  gRandom->SetSeed(0);
223  int rnID = int(gRandom->Rndm(13)*1.e9);
224  UserGroup_t* uinfo = gSystem->GetUserInfo();
225  TString uname = uinfo->fUser;
226  gSystem->Exec(TString("mkdir -p /dev/shm/")+uname);
227  sprintf(ofile,"/dev/shm/%s/waveburst-%d.txt",uname.Data(),rnID);
228 
229  dump=true;
230 
231  if(dump) netburst.dopen(ofile,"w");
232  netburst.output(net_tree,&NET);
233  jfile->Write();
234  if(dump) netburst.dclose();
235 
236  TMacro macro(ofile);
237  macro.Write("output.txt");
238  gSystem->Exec(TString("rm ")+ofile);
239  }
240 
241  jfile->ReOpen("READ");
242  gROOT->RefreshBrowsers();
243  gROOT->ForceStyle(0);
244 }
245 
246 
char ofile[1024]
std::vector< char * > ifoName
Definition: network.hh:609
void sethigh(double f)
Definition: wseries.hh:132
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
WSeries< double > * pTF[NIFO_MAX]
Definition: cwb_job_obj.C:40
double netCC
Definition: network.hh:596
void white(double dT=0, int wtype=1, double offset=0., double stride=0.)
what it does: see algorithm description in wseries.hh
Definition: detector.hh:258
void Export(TString fname="")
Definition: config.cc:406
char filter_dir[1024]
void setAntenna(detector *)
param: detector (use theta, phi index array)
Definition: network.cc:2846
std::vector< double > * getmdcTime()
Definition: network.hh:422
double fHigh
network NET
Definition: cwb_job_obj.C:49
float factor
int n
Definition: cwb_net.C:28
double angle
TDirectory * cdprod
Definition: cwb_job_obj.C:31
TString("c")
size_t setIndexMode(size_t=0)
Definition: network.cc:8105
TDirectory * cdsim
Definition: cwb_job_obj.C:21
void add(const wavearray< DataType_t > &, int=0, int=0, int=0)
Definition: wavearray.cc:746
netcluster * pwc
Definition: cwb_job_obj.C:38
void setlow(double f)
Definition: wseries.hh:125
virtual size_t supercluster(char atype, double S, bool core)
param: statistic: E - excess power, L - likelihood param: selection threshold T for likelihood cluste...
Definition: netcluster.cc:808
int m
Definition: cwb_net.C:28
int j
Definition: cwb_net.C:28
detector * pD[NIFO_MAX]
Definition: cwb_job_obj.C:39
i drho i
int l_low
Definition: test_config1.C:40
char ifo[NIFO_MAX][8]
char ced_dir[512]
Definition: test_config1.C:154
int Psave
Definition: test_config1.C:75
double Acore
Definition: test_config1.C:28
size_t mode
#define nIFO
char tdf90[1024]
Definition: cwb_job_obj.C:34
jfile
Definition: cwb_job_obj.C:43
char end_CED[1024]
Definition: cwb_job_obj.C:35
void Forward(size_t k)
param: number of steps
Definition: network.hh:89
int levelD
TTree * net_tree
char tdf00[1024]
Definition: cwb_job_obj.C:33
i() int(T_cor *100))
void setDelayIndex(double rate)
param: MDC log file
Definition: network.cc:2896
const int NIFO_MAX
Definition: wat.hh:22
double getDelay(const char *c="")
Definition: network.cc:2818
virtual size_t append(netcluster &wc)
param: input netcluster return size of appended pixel list
Definition: netcluster.cc:769
double cedRHO
UserGroup_t * uinfo
Definition: cwb_frdisplay.C:91
size_t cpf(const netcluster &, bool=false, int=0)
Definition: netcluster.cc:117
TObjArray * token
ss Inverse()
void setDelay(const char *="L1")
Definition: network.cc:2767
void bandPass(double f1, double f2, double a=0.)
Definition: detector.hh:283
double e2or
Definition: network.hh:584
WSeries< double > wM
Definition: cwb_job_obj.C:41
long likelihood(char='E', double=sqrt(2.), int=0, size_t=0, int=-1, bool=false)
Definition: network.cc:4446
size_t size()
Definition: netcluster.hh:147
size_t events()
Definition: network.hh:329
char filter[1024]
double fLow
WSeries< double > * getTFmap()
param: no parameters
Definition: detector.hh:179
char Name[16]
Definition: detector.hh:327
iD print()
double gamma
Definition: network.hh:592
double mTau
virtual void lprFilter(double, int=0, double=0., double=0.)
Definition: wseries.cc:1126
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:246
netcluster wc
Definition: cwb_job_obj.C:37
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:439
int nfactor
Definition: test_config1.C:83
CWB::config config
Definition: cwb_job_obj.C:51
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
bool dump
void setDelayFilters(detector *=NULL)
Definition: network.cc:7739
int l_high
Definition: test_config1.C:41
long nSky
Definition: network.hh:574
TString jname
Definition: ced.hh:44
size_t netcut(double, char='L', size_t=0, int=1)
param: threshold param: minimum cluster size processed by the corrcut param: cluster type return: num...
Definition: network.cc:2998
long nSky
simulation
Definition: cwb_eced.C:26
double Tlpr
factors[0]
Definition: cwb_eced.C:27
int setTimeShifts(size_t=1, double=1., size_t=0, size_t=0, const char *=NULL, const char *="w", size_t *=NULL)
param number of time lags param time shift step in seconds param first lag ID param maximum lag ID pa...
Definition: network.cc:7321
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:291
double delta
Definition: network.hh:591
size_t setsim(WSeries< double > &, std::vector< double > *, double=5., double=8., bool saveWF=false)
Definition: detector.cc:1377
double netRHO
Definition: network.hh:597
void GetProcInfo(TString str="")
Definition: Toolfun.hh:241
#define SEARCH(TYPE)
Definition: xroot.hh:4
bool cedDump
int levelF
void setSkyMaps(double, double=0., double=180., double=0., double=360.)
param: sky map granularity step, degrees param: theta begin, degrees param: theta end...
Definition: network.cc:2687
exit(0)
void clear()
Definition: netcluster.hh:427