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