Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_InjectMDC.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 "gnetwork.hh"
34 
35 #define WAVEFORM_NAME "Waveforms/SG554Q8d9.txt"
36 
37 void
39 
40 // Plugin to inject 'on the fly' the MDC
41 
42 /*
43 # GravEn_SimID SimHrss SimEgwR2 GravEn_Ampl Internal_x Internal_phi External_x Externa
44 l_phi External_psi FrameGPS EarthCtrGPS SimName SimHpHp SimHcHc SimHpHc
45 GEO GEOctrG
46 PS GEOfPlus GEOfCross H1 H1ctrGPS H1fPlus H1fCross H2 H2ctrGPS H2fPlus
47 H2fCross L1 L1ctrGPS L1fPlus L1fCross V1 V1ctrGPS V1fPlus V1fCross
48 
49 Waveforms/SG554Q8d9.txt 1.213000e-21 1.011301e-47 1.213000e-21 +1.000000e+00 +0.000000e+00 +7.799320e-01 +7.720941e-01 +3.397006e+00 968653615 968654066.616913 SG554Q8d9 1.471369e-42 0.000000e+00 0.000000e+00 GEO 968654066.597115 +8.635698e-01 -3.501556e-01 H1 968654066.613762 +1.334841e-01 +7.593384e-02 H2 968654066.613762 +1.334841e-01 +7.593384e-02 L1 968654066.616641 -1.870505e-02 -1.359386e-02 V1 968654066.597488 -4.561425e-01 -7.932736e-01
50 */
51 
52  if(type==CWB_PLUGIN_CONFIG) {
53  cfg->mdcPlugin=true; // disable read mdc from frames
54  }
55 
56  if(type==CWB_PLUGIN_MDC) { // mdc
57 
58  double dt = 1./x->rate();
59 
60  cout << endl;
61  cout << "-----> plugins/CWB_Plugin_InjectMDC.C" << endl;
62  cout << "ifo " << ifo.Data() << endl;
63  cout << "type " << type << endl;
64  cout << endl;
65 
66  // log burstMDC parameters
67  double burstMDC_theta = 7.799320e-01;
68  double burstMDC_phi = 7.720941e-01;
69  double burstMDC_psi = 3.397006;
70 
71  /* ------------------------------
72  earthCenterTime = _EarthCtrGPS;
73  phi = _External_phi;
74  theta = _External_x;
75  psi = _External_psi;
76  --------------------------------- */
77  double theta,phi,psi;
78  double Pi = TMath::Pi();
79  if(true) {
80  theta = acos(burstMDC_theta);
81  theta*= 180/Pi;
82  phi = burstMDC_phi > 0 ? burstMDC_phi : 2*Pi+burstMDC_phi;
83  phi*= 180/Pi;
84 // phi = sm.phi2RA(phi,_EarthCtrGPS);
85  psi = burstMDC_psi*180/Pi;
86  }
87  cout << "theta : " << theta << " phi : " << phi << " psi " << psi << endl;
88 
89  int nIFO=net->ifoListSize();
91  for(int n=0;n<nIFO;n++)ifos[n]= net->ifoName[n];
92  gnetwork gNET(nIFO,ifos);
93  for(int i=0;i<nIFO;i++) {
94  for(int j=i+1;j<nIFO;j++) {
95  cout << ifos[i].Data() << " " << ifos[j].Data() << " -> "
96  << gNET.GetDelay(ifos[i].Data(),ifos[j].Data(),phi,theta) << " sec " << endl;
97  }
98  }
99 
100 
101  char logString[1024]="";
102 
103  char GravEn_SimID[1024]="Waveforms/SG554Q8d9.txt";
104  double SimHrss = 1.213000e-21;
105  double SimEgwR2 = 1.011301e-47;
106  double GravEn_Ampl = 1.213000e-21;
107  double Internal_x = 1.0;
108  double Internal_phi = 0.0;
109  double External_x = burstMDC_theta;
110  double External_phi = burstMDC_phi;
111  double External_psi = burstMDC_psi;
112 
113  double FrameGPS = x->start();
114  //double EarthCtrGPS = FrameGPS+dt*x->size()/2.; // injected in the center of buffer
115  double EarthCtrGPS = 968654066.616913;
116  char SimName[64] = "SG554Q8d9";
117  double SimHpHp = 1.471369e-42;
118  double SimHcHc = 0;
119  double SimHpHc = 0;
120 
121  sprintf(logString,"%s",GravEn_SimID);
122  sprintf(logString,"%s %e",logString,SimHrss);
123  sprintf(logString,"%s %e",logString,SimEgwR2);
124  sprintf(logString,"%s %e",logString,GravEn_Ampl);
125  sprintf(logString,"%s %e",logString,Internal_x);
126  sprintf(logString,"%s %e",logString,Internal_phi);
127  sprintf(logString,"%s %e",logString,External_x);
128  sprintf(logString,"%s %e",logString,External_phi);
129  sprintf(logString,"%s %e",logString,External_psi);
130 
131  sprintf(logString,"%s %10.6f",logString,FrameGPS);
132  sprintf(logString,"%s %10.6f",logString,EarthCtrGPS);
133  sprintf(logString,"%s %s",logString,SimName);
134  sprintf(logString,"%s %e",logString,SimHpHp);
135  sprintf(logString,"%s %e",logString,SimHcHc);
136  sprintf(logString,"%s %e",logString,SimHpHc);
137 
138  double tShift=0;
139  double fPlus=0;
140  double fCross=0;
141  for(int i=0;i<nIFO;i++) {
142  double IFOctrGPS = EarthCtrGPS;
143  if(i>0) IFOctrGPS += gNET.GetDelay(ifos[i].Data(),ifos[0].Data(),phi,theta);
144  double IFOfPlus = gNET.GetAntennaPattern(ifos[i], phi, theta, psi, true);
145  double IFOfCross = gNET.GetAntennaPattern(ifos[i], phi, theta, psi, false);
146  if(ifos[i].CompareTo(ifo)==0) {
147  tShift=IFOctrGPS-EarthCtrGPS;
148  fPlus=IFOfPlus;
149  fCross=IFOfCross;
150  }
151  sprintf(logString,"%s %s %10.6f %e %e",logString,ifos[i].Data(),IFOctrGPS,IFOfPlus,IFOfCross);
152  }
153  cout << logString << endl;
154 
155  net->mdcList.clear();
156  net->mdcList.push_back(logString);
157  net->mdcTime.clear();
158  net->mdcTime.push_back(EarthCtrGPS);
159 
160  cout << endl << endl;
161  for (int nmdc=0; nmdc<(int)net->mdcListSize(); nmdc++) {
162  TString mdcstring(net->getmdcList(nmdc));
163 // if(nmdc==72) {
164  cout << endl << endl;
165  cout << "--------------------------------> " << nmdc << endl;
166  cout << endl << endl;
167  cout << mdcstring.Data() << endl;
168 // }
169  }
170  //gSystem->Exit(0);
171 
172  // read waveform
173  ifstream in;
174  in.open(WAVEFORM_NAME, ios::in);
175  if (!in.good()) {cout << "Error Opening File : " << WAVEFORM_NAME << endl;gSystem->Exit(1);}
176 
177  // fill mdc vector
178  (*x)=0;
179  int offset = (EarthCtrGPS-FrameGPS)*x->rate();
180  int size=0;
181  double hrss=0;
182  while (1) {
183  in >> x->data[offset+size];
184  hrss+=pow(x->data[offset+size],2);
185  if (!in.good()) break;
186  size++;
187  if ((offset+size)>=(int)x->size()) break;
188  }
189  hrss=sqrt(hrss*dt);
190  for(int i=0;i<(int)x->size();i++) x->data[i] = x->data[i]*fPlus*SimHrss/hrss;
191 
192  in.close();
193 
194  if(tShift==0) return;
195 
196  // apply time shift to mdc vector
197  x->FFTW(1);
198  TComplex C;
199  double df = x->rate()/x->size();
200  //double tShift = 10./x->rate();
201  cout << "tShift : " << tShift << endl;
202  for (int ii=0;ii<(int)x->size()/2;ii++) {
203  TComplex X(x->data[2*ii],x->data[2*ii+1]);
204  X=X*C.Exp(TComplex(0.,-2*Pi*ii*df*tShift)); // Time Shift
205  x->data[2*ii]=X.Re();
206  x->data[2*ii+1]=X.Im();
207  }
208  x->FFTW(-1);
209  }
210 
211  return;
212 }
std::vector< char * > ifoName
Definition: network.hh:609
CWB::config * cfg
static const double C
Definition: GNGen.cc:28
gnetwork * gNET
bool mdcPlugin
Definition: config.hh:365
int offset
Definition: TestSTFT_2.C:19
virtual void rate(double r)
Definition: wavearray.hh:141
int n
Definition: cwb_net.C:28
TString("c")
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
float theta
string getmdcList(size_t n)
Definition: network.hh:418
Long_t size
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
virtual void start(double s)
Definition: wavearray.hh:137
int j
Definition: cwb_net.C:28
i drho i
std::vector< double > mdcTime
Definition: network.hh:614
int nmdc
size_t mdcListSize()
Definition: network.hh:408
char ifo[NIFO_MAX][8]
network ** net
NOISE_MDC_SIMULATION.
size_t ifoListSize()
Definition: network.hh:431
#define WAVEFORM_NAME
#define nIFO
virtual size_t size() const
Definition: wavearray.hh:145
float phi
double hrss
Definition: TestMDC.C:70
float psi
jfile
Definition: cwb_job_obj.C:43
i() int(T_cor *100))
double Pi
std::vector< std::string > mdcList
Definition: network.hh:612
const int NIFO_MAX
Definition: wat.hh:22
double dt
virtual void FFTW(int=1)
Definition: wavearray.cc:896
double GetDelay(TString ifo1, TString ifo2, double phi, double theta)
Definition: gnetwork.cc:926
ifstream in
double df
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double GetAntennaPattern(double phi, double theta, double psi=0., int polarization=1)
Definition: gnetwork.cc:564
DataType_t * data
Definition: wavearray.hh:319
char GravEn_SimID[1024]
TString ifos[60]