Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_netEvent.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 "gwavearray.hh"
36 #include <vector>
37 
38 TFile* GetRootFile(network* NET);
39 
40 void
42 //!MISCELLANEA
43 // Write user parameters to the output root file
44 
45  cout << endl;
46  cout << "-----> CWB_Plugin_netEvent.C" << endl;
47  cout << "ifo " << ifo.Data() << endl;
48  cout << "type " << type << endl;
49  cout << endl;
50 
51  float UserParms[NIFO_MAX]; // UserParms
52 
53  if(type==CWB_PLUGIN_CONFIG) {
54  cfg->outPlugin=true; // disable built-in output root file
55  }
56 
57  if(type==CWB_PLUGIN_ILIKELIHOOD) {
58 
59  // search output root file in the system list
60  TFile* froot = GetRootFile(NET);
61 
62  netevent* EVT;
63  int nIFO = NET->ifoListSize(); // number of detectors
64  TTree* net_tree = (TTree *) froot->Get("waveburst");
65  if(net_tree==NULL) {
66  EVT = new netevent(nIFO);
67  net_tree = EVT->setTree();
68  net_tree->Branch("UserParms",UserParms,TString::Format("UserParms[%i]/F",cfg->nIFO));
69  }
70  }
71 
72  if(type==CWB_PLUGIN_OLIKELIHOOD) {
73 
74  if(TString(cfg->analysis)!="2G") {
75  cout << "CWB_Plugin_netEvent.C -> "
76  << "CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
77  gSystem->Exit(1);
78  }
79 
80  // import ifactor
81  int gIFACTOR=-1; IMPORT(int,gIFACTOR)
82  cout << "-----> CWB_Plugin_netEvent.C -> "
83  << " gIFACTOR : " << gIFACTOR << endl;
84 
85  // import slagShift
86  float* gSLAGSHIFT=NULL; IMPORT(float*,gSLAGSHIFT)
87 
88  int nIFO = NET->ifoListSize(); // number of detectors
89  int K = NET->nLag; // number of time lag
90  netevent* EVT;
92  //double factor = cfg->simulation==3||cfg->simulation==4 ? -gIFACTOR : cfg->factors[gIFACTOR];
93  double factor = cfg->factors[gIFACTOR];
94  int rate = 0; // select all resolutions
95 
96  // search output root file in the system list
97  TFile* froot = GetRootFile(NET);
98 
99  TString outDump = froot->GetName();
100  outDump.ReplaceAll(".root.tmp",".txt");
101 
102  TTree* net_tree = (TTree *) froot->Get("waveburst");
103  if(net_tree!=NULL) {
104  EVT = new netevent(net_tree,nIFO);
105  net_tree->SetBranchAddress("UserParms",UserParms);
106  } else {
107  EVT = new netevent(nIFO);
108  net_tree = EVT->setTree();
109  net_tree->Branch("UserParms",UserParms,TString::Format("UserParms[%i]/F",cfg->nIFO));
110  }
111  EVT->setSLags(gSLAGSHIFT); // set slags into netevent
112 
113  for(int k=0; k<K; k++) { // loop over the lags
114 
115  id = NET->getwc(k)->get(const_cast<char*>("ID"), 0, 'L', rate);
116 
117  for(int j=0; j<(int)id.size(); j++) { // loop over cluster index
118 
119  int ID = size_t(id.data[j]+0.5);
120 
121  if(NET->getwc(k)->sCuts[ID-1]!=-1) continue; // skip rejected/processed clusters
122 
123  double ofactor=0;
124  if(cfg->simulation==4) ofactor=-factor;
125  else if(cfg->simulation==3) ofactor=-gIFACTOR;
126  else ofactor=factor;
127 
128  EVT->output2G(NULL,NET,ID,k,ofactor); // get reconstructed parameters
129 
130  netcluster* pwc = NET->getwc(k);
131 
132  UserParms[0]=111;
133  UserParms[1]=222;
134 
135  std::vector<int> sCuts = NET->getwc(k)->sCuts; // save cCuts
136  // set sCuts=1 to the events which must be not copied with cps to pwc
137  for(int i=0; i<(int)sCuts.size(); i++) if(i!=ID-1) NET->getwc(k)->sCuts[i]=1;
138 
139  // ID can not be used to get the event, to get event use ID=1 (ex: for watplot)
140  NET->getwc(k)->sCuts = sCuts; // restore cCuts
141 
142  if(cfg->dump) EVT->dopen(outDump.Data(),const_cast<char*>("a"),false);
143  EVT->output2G(net_tree,NET,ID,k,ofactor); // get reconstructed parameters
144  if(cfg->dump) {
145  // add UserParms to dump file
146  fprintf(EVT->fP,"UserParms: ");
147  for(int i=0; i<nIFO; i++) fprintf(EVT->fP,"%f ",UserParms[i]);
148  fprintf(EVT->fP,"\n");
149  }
150  if(cfg->dump) EVT->dclose();
151  if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1; // mark as processed
152  }
153  }
154 
155  jfile->cd();
156  if(EVT) delete EVT;
157  }
158  return;
159 }
160 
162 
163  // search output root file in the system list
164  TFile* froot = NULL;
165  TList *files = (TList*)gROOT->GetListOfFiles();
166  TString outDump="";
167  netevent* EVT;
168  int nIFO = NET->ifoListSize(); // number of detectors
169  if (files) {
170  TIter next(files);
171  TSystemFile *file;
172  TString fname;
173  bool check=false;
174  while ((file=(TSystemFile*)next())) {
175  fname = file->GetName();
176  // set output root file as the current file
177  if(fname.Contains("wave_")) {
178  froot=(TFile*)file;froot->cd();
179  outDump=fname;
180  outDump.ReplaceAll(".root.tmp",".txt");
181  //cout << "output file name : " << fname << endl;
182  }
183  }
184  if(!froot) {
185  cout << "CWB_Plugin_netEvent.C : Error - output root file not found" << endl;
186  gSystem->Exit(1);
187  }
188  } else {
189  cout << "CWB_Plugin_netEvent.C : Error - output root file not found" << endl;
190  gSystem->Exit(1);
191  }
192 
193  return froot;
194 }
195 
CWB::config * cfg
char analysis[8]
Definition: config.hh:117
TString outDump
size_t nLag
Definition: network.hh:573
void setSLags(float *slag)
Definition: netevent.cc:426
float factor
TTree * setTree()
Definition: netevent.cc:434
TString("c")
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
netcluster * pwc
Definition: cwb_job_obj.C:38
bool cedDump
Definition: config.hh:297
Long_t size
int j
Definition: cwb_net.C:28
i drho i
bool outPlugin
Definition: config.hh:369
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
fprintf(stdout,"start=%f duration=%f rate=%f\, x.start(), x.size()/x.rate(), x.rate())
#define nIFO
jfile
Definition: cwb_job_obj.C:43
void output2G(TTree *, network *, size_t, int, double)
Definition: netevent.cc:711
TTree * net_tree
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
const int NIFO_MAX
Definition: wat.hh:22
TIter next(twave->GetListOfBranches())
char fname[1024]
TFile * GetRootFile(network *NET)
int k
TFile * froot
FILE * fP
injected reconstructed xcor waveform
Definition: netevent.hh:141
netevent EVT(itree, nifo)
std::vector< int > sCuts
Definition: netcluster.hh:392
void dclose()
Definition: netevent.hh:321
int gIFACTOR
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:439
int nIFO
Definition: config.hh:120
Long_t id
double factors[FACTORS_MAX]
Definition: config.hh:202
int check
bool dump
Definition: config.hh:295