Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_MDC_Frames.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 //!NOISE_MDC_SIMULATION
20 // Plugin used to setup frame files and log MDC 'on the fly' using simulation=4
21 
22 #define XIFO 4
23 
24 #pragma GCC system_header
25 
26 #include "cwb.hh"
27 #include "config.hh"
28 #include "network.hh"
29 #include "wavearray.hh"
30 #include "TString.h"
31 #include "TObjArray.h"
32 #include "TObjString.h"
33 #include "TRandom.h"
34 #include "TComplex.h"
35 #include "TMath.h"
36 #include "cwb2G.hh"
37 #include "mdc.hh"
38 #include <vector>
39 
40 
41 void
43 
44  if(type==CWB_PLUGIN_CONFIG) {
45  cfg->mdcPlugin=true; // disable read mdc from frames
46  }
47 
48  if(type==CWB_PLUGIN_MDC) {
49 
50  cout << "Execute CWB_Plugin_MDC_Frames.C : Inject On The Fly MDC ..." << endl;
51 
52  int ifoID =0; for(int n=0;n<cfg->nIFO;n++) if(ifo==net->getifo(n)->Name) {ifoID=n;break;}
53 
54  int nIFO = net->ifoListSize(); // number of detectors
55  int gIFACTOR = -1; IMPORT(int,gIFACTOR)
56  int xstart = (int)x->start();
57  int xstop = (int)x->stop();
58  int segEdge = int(cfg->segEdge);
59 
60  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
61 
62  // Export parms to the config plugin
63  static bool cfg_init = false;
64  if(!cfg_init) { // declaration is made only one time to avoid cling error
66  cfg_init=true;
67  }
68  CWB_PLUGIN_EXPORT(gIFACTOR)
69 
70  // Export MDC frame files & log from plugin config
71  std::vector<TString> mdcPar;
72  CWB_PLUGIN_EXPORT(mdcPar)
73  // Export mdcType
74  std::vector<std::string> mdcType;
75  CWB_PLUGIN_EXPORT(mdcType)
76  // Export channelName
77  std::vector<std::string> channelName;
78  CWB_PLUGIN_EXPORT(channelName)
79 
80  // read plugin config
81  cfg->configPlugin.Exec();
82 
83  TString injectionList = mdcPar[0];
84  TString frFiles = mdcPar[1];
85  cout << "injectionList : " << injectionList << endl;
86  cout << "frFiles : " << frFiles << endl;
87 
88  // open frame file
89  CWB::frame fr;
90  fr.open(frFiles.Data());
91  fr.setVerbose();
92  fr.setRetryTime(cfg->frRetryTime);
93  fr.setSRIndex(TMath::Nint(TMath::Log2(cfg->inRate))); // force data to be resampled to inRate
94  int nfrFiles = fr.getNfiles();
95  cout << "MDC " << " -> nfrFiles : " << nfrFiles << endl;
96  if(cfg->mdc_shift.startMDC<0) { // the mdc shift is automatically selected
97  // read mdc range from mdc frl files
98  waveSegment mdc_range = fr.getFrRange();
99  cout << "mdc_range : " << mdc_range.start << " " << mdc_range.stop << endl;
100  cfg->mdc_shift.startMDC=mdc_range.start;
101  cfg->mdc_shift.stopMDC=mdc_range.stop;
102  }
103  double mdcShift = CWB::Toolbox::getMDCShift(cfg->mdc_shift, xstart);
104  cout << "mdcShift : " << mdcShift << endl;
105 
106  // read injection list
107  net->mdcList.clear();
108  net->mdcType.clear();
109  net->mdcTime.clear();
110  vector<TString> ifos(nIFO);
111  for(int n=0;n<nIFO;n++) ifos[n] = net->getifo(n)->Name;
112  int i=net->readMDClog(const_cast<char*>(injectionList.Data()),double(long(gCWB2G->Tb))-mdcShift);
113  for(int i=0;i<(int)net->mdcTime.size();i++) net->mdcTime[i]+=mdcShift;
114  printf("GPS: %16.6f saved, injections: %d\n",double(long(gCWB2G->Tb)),i);
115  net->mdcType=mdcType;
116 
117  // read frame file
118  frfile FRF = fr.getFrList(xstart-mdcShift+segEdge, xstop-mdcShift-segEdge, segEdge);
119  fr.readFrames(FRF,const_cast<char*>(channelName[ifoID].c_str()),*x);
120  x->start(x->start()+mdcShift);
121  if(x->rate()!=cfg->inRate)
122  {cout << "CWB_Plugin_MDC_Frames.C - input rate from frame " << x->rate()
123  << " do not match the one defined in config : " << cfg->inRate << endl;gSystem->Exit(1);}
124 
125  // print MDC injections list
126  cout.precision(14);
127  if(ifo.CompareTo(net->ifoName[0])==0) {
128  //for(int k=0;k<(int)net->mdcList.size();k++) cout << k << " mdcList " << net->mdcList[k] << endl;
129  //for(int k=0;k<(int)net->mdcTime.size();k++) cout << k << " mdcTime " << net->mdcTime[k] << endl;
130  for(int k=0;k<(int)net->mdcType.size();k++) cout << k << " mdcType " << net->mdcType[k] << endl;
131  }
132 
133  }
134 
135  return;
136 }
std::vector< char * > ifoName
Definition: network.hh:609
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
CWB::config * cfg
double startMDC
Definition: Toolbox.hh:106
double start
Definition: network.hh:55
TMacro configPlugin
Definition: config.hh:362
size_t readMDClog(char *, double=0., int=11, int=12)
param: MDC log file param: approximate gps time
Definition: network.cc:3370
bool mdcPlugin
Definition: config.hh:365
virtual void rate(double r)
Definition: wavearray.hh:141
int n
Definition: cwb_net.C:28
TString("c")
double Tb
Definition: cwb.hh:281
double stopMDC
Definition: Toolbox.hh:107
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
CWB::frame fr(FRLIST_NAME)
char frFiles[NIFO_MAX+1][256]
Definition: test_config1.C:166
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
std::vector< std::string > mdcType
Definition: network.hh:613
virtual void start(double s)
Definition: wavearray.hh:137
double segEdge
Definition: test_config1.C:49
i drho i
std::vector< double > mdcTime
Definition: network.hh:614
char ifo[NIFO_MAX][8]
Definition: cwb2G.hh:33
network ** net
NOISE_MDC_SIMULATION.
size_t ifoListSize()
Definition: network.hh:431
waveSegment getFrRange()
Definition: frame.hh:107
char injectionList[1024]
double mdcShift
Definition: cwb_net.C:196
double segEdge
Definition: config.hh:164
#define nIFO
jfile
Definition: cwb_job_obj.C:43
#define CWB_PLUGIN_EXPORT(VAR)
Definition: CWB_Plugin.h:18
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:69
i() int(T_cor *100))
std::vector< std::string > mdcList
Definition: network.hh:612
printf("total live time: non-zero lags = %10.1f \, liveTot)
void setVerbose(bool verbose=true)
Definition: frame.hh:137
frfile FRF[nIFO+1]
Definition: cwb_net.C:269
int k
int frRetryTime
Definition: config.hh:344
int getNfiles()
Definition: frame.hh:110
int nfrFiles[nIFO+1]
Definition: cwb_net.C:192
void setSRIndex(int srIndex)
Definition: frame.hh:114
static double getMDCShift(mdcshift mshift, double time)
Definition: Toolbox.cc:2296
int * xstart
mdcshift mdc_shift
Definition: config.hh:211
char Name[16]
Definition: detector.hh:327
virtual void stop(double s)
Definition: wavearray.hh:139
int gIFACTOR
void readFrames(char *filename, char *channel, wavearray< double > &w)
Definition: frame.cc:828
frfile getFrList(int istart, int istop, int segEdge)
Definition: frame.cc:527
int nIFO
Definition: config.hh:120
void setRetryTime(int frRetryTime=60)
Definition: frame.hh:141
void open(TString ioFile, TString chName="", Option_t *option="", bool onDisk=false, TString label=".gwf", unsigned int mode=0)
Definition: frame.cc:230
double stop
Definition: network.hh:56
size_t inRate
Definition: config.hh:132
TString ifos[60]