21 #pragma GCC system_header 29 #include "TObjArray.h" 30 #include "TObjString.h" 66 #define CE_eAMP 1 // max percentage of amplitude error (1 -> no amplitude error) 67 #define CE_ePHS 0 // max phase (degrees) phase error (0 -> no phase error) 68 #define CE_eTIM 0 // max time (sec) error (0 -> no time error) 69 #define CE_SEED 150914 // seed used by CE for ramdom generation 70 #define CE_TYPE "fixed" // CE type: fixed(default)/uniform/gussian 78 #define CE_CFILE "" // is the file that contains the list of eamp/epha vs frequency 80 #define CE_GDUMP false // if true -> dump in/out injections to root file in the working dir 'report/dump', used only for debugging 81 #define CE_VERBOSE false // if true -> output debug infos 134 if(gOPT.type[
n]==
"file") {
136 cout <<
"CWB_Plugin_CE : check if calibration file defined in plugin parameter ce_cfile=" << gOPT.cfile <<
" exist" << endl;
148 if(gOPT.type[
n]==
"file") {
149 gMDC->SetInspiralCLB(gOPT.cfile);
163 if(ifoid<0) {cout <<
"CWB_Plugin_CE : Error - bad ifo ifoid" << endl; gSystem->Exit(1);}
169 if((gOPT.gdump) && (
gFDUMP==
"")) {
171 jname.ReplaceAll(
":/",
"");
172 jname.ReplaceAll(
".root",
"_ce_gdump.root");
176 cout << endl <<
"CWB_Plugin_CE : Created file: " <<
gFDUMP << endl << endl;
183 gRandom->SetSeed(seed);
185 if(gOPT.verbose) cout <<
"CWB_Plugin_CE : injection_id=" << nmdc <<
"\trun=" << NET->
nRun 186 <<
"\tifoid=" << ifoid <<
"\tfactor=" << ifactor <<
"\tseed=" << seed << endl;
189 TObjArray*
token = mdcstring.Tokenize(
' ');
190 TObjString* iname = (TObjString*)token->At(11);
191 TString wavename = iname->GetString();
192 TObjString*
itime = (TObjString*)token->At(10);
193 TString wavetime = itime->GetString();
194 double mdctime = wavetime.Atof();
201 if(istart<0) istart=0;
202 if(istop>(
int)x->
size()) istop=x->
size();
203 int isize = istop-istart;
214 if(gOPT.type[ifoid]==
"file") {
245 name = TString::Format(
"%s_INJ_Time_InOut_%d",ifo.Data(),TMath::Nint(mdctime));
246 plot->
canvas->Write(name.Data());
251 name = TString::Format(
"%s_INJ_FFT_InOut_%d",ifo.Data(),TMath::Nint(mdctime));
252 plot->
canvas->Write(name.Data());
257 if(ifoid==cfg->
nIFO-1) {
259 ofdump.ReplaceAll(TString::Format(
"%s/",cfg->
tmp_dir).Data(),TString::Format(
"%s/",cfg->
dump_dir).Data());
262 cout << endl << cmd << endl << endl;
274 cout <<
"-----------------------------------------" << endl;
275 cout <<
"CE config options " << endl;
276 cout <<
"-----------------------------------------" << endl << endl;
278 cout <<
"CE_TYPE " << cfg->
ifo[
n] <<
" " << gOPT.type[
n] << endl;
279 cout <<
"CE_eAMP " << cfg->
ifo[
n] <<
" " << gOPT.eamp[
n] << endl;
280 cout <<
"CE_ePHS " << cfg->
ifo[
n] <<
" " << gOPT.ephs[
n] << endl;
281 cout <<
"CE_eTIM " << cfg->
ifo[
n] <<
" " << gOPT.etim[
n] << endl << endl;
283 cout <<
"CE_CFILE " << gOPT.cfile << endl;
284 cout <<
"CE_SEED " << gOPT.seed << endl;
285 cout <<
"CE_GDUMP " << gOPT.gdump << endl;
286 cout <<
"CE_VERBOSE " << gOPT.verbose << endl;
297 if(!out.good()) {cout <<
"DumpUserOptions : Error Opening File : " << ofName << endl;
exit(1);}
306 out <<
"--------------------------------" << endl;
307 out <<
"CE config options " << endl;
308 out <<
"--------------------------------" << endl;
312 out <<
"ce_eamp " << cfg->
ifo[
n] <<
" " << gOPT.eamp[
n] << endl;
314 info =
"// max percentage of amplitude miscalibration : def(0) -> disabled";
315 out << tabs << info << endl;
318 out <<
"ce_ephs " << cfg->
ifo[
n] <<
" " << gOPT.ephs[
n] << endl;
320 info =
"// max phase (degrees) miscalibration : def(0) -> disabled";
321 out << tabs << info << endl;
324 out <<
"ce_etim " << cfg->
ifo[
n] <<
" " << gOPT.etim[
n] << endl;
326 info =
"// max time (sec) miscalibration : def(0) -> disabled";
327 out << tabs << info << endl;
330 out <<
"ce_type " << cfg->
ifo[
n] <<
" " << gOPT.type[
n] << endl;
333 out <<
"ce_seed " << gOPT.seed << endl;
334 info =
"// seed used by CE for random generation - 0(def) -> random seed";
335 out << tabs << info << endl;
337 out <<
"ce_gdump " << gOPT.gdump << endl;
338 out << tabs << info << endl;
340 out <<
"ce_verbose " << gOPT.verbose << endl;
341 out << tabs << info << endl;
343 out <<
"ce_cfile " << gOPT.cfile << endl;
344 out << tabs << info << endl;
369 if(options.CompareTo(
"")!=0) {
370 cout << options << endl;
371 if(!options.Contains(
"--")) {
374 for(
int j=0;
j<token->GetEntries();
j++){
376 TObjString* tok = (TObjString*)token->At(
j);
377 TString stok = tok->GetString();
379 if(stok.Contains(
"ce_eamp=")) {
381 ce_eamp.Remove(0,ce_eamp.Last(
'=')+1);
382 if(ce_eamp.IsFloat()) gOPT.eamp[n_eamp]=ce_eamp.Atof();
386 if(stok.Contains(
"ce_ephs=")) {
388 ce_ephs.Remove(0,ce_ephs.Last(
'=')+1);
389 if(ce_ephs.IsFloat()) gOPT.ephs[n_ephs]=ce_ephs.Atof();
393 if(stok.Contains(
"ce_etim=")) {
395 ce_etim.Remove(0,ce_etim.Last(
'=')+1);
396 if(ce_etim.IsFloat()) gOPT.etim[n_etim]=ce_etim.Atof();
400 if(stok.Contains(
"ce_type=")) {
402 type.Remove(0,type.Last(
'=')+1);
403 gOPT.type[n_type]=type;
407 if(stok.Contains(
"ce_cfile=")) {
409 cfile.Remove(0,cfile.Last(
'=')+1);
413 if(stok.Contains(
"ce_seed=")) {
415 ce_seed.Remove(0,ce_seed.Last(
'=')+1);
416 if(ce_seed.IsDigit()) gOPT.seed=ce_seed.Atoi();
419 if(stok.Contains(
"ce_gdump=")) {
421 gdump.Remove(0,gdump.Last(
'=')+1);
425 if(stok.Contains(
"ce_verbose=")) {
427 verbose.Remove(0,verbose.Last(
'=')+1);
428 gOPT.verbose=verbose;
452 int ibeg=0;
int iend=0;
454 if(x[
i]!=0 && ibeg==0) ibeg=
i;
457 int ilen=iend-ibeg+1;
460 isize = isize + (isize%4 ? 4 - isize%4 : 0);
462 w.rate(x.
rate()); w=0;
464 for(
int i=0;
i<ilen;
i++) {w[
i+isize/4]=x[ibeg+
i];x[ibeg+
i]=0;}
466 gMDC->CalibrateInspiral(w, ifo, time, simulation_id);
469 for(
int i=0;
i<(
int)w.size();
i++) {
470 int j=ibeg-isize/4+
i;
480 in.open(gOPT.cfile.Data(),
ios::in);
482 cout << endl <<
"CWB_Plugin_CE - " 483 <<
"Error Opening Calibration File : " << gOPT.cfile.Data() << endl;
487 std::map<TString, int> hsample;
491 in.getline(hline,4*1024);
495 for(
int j=0;
j<token->GetEntries();
j++) {
497 sheader.ReplaceAll(
" " ,
"");
502 first_sheader=sheader;
504 hsample[sheader] =
j;
507 hsample[first_sheader] = token->GetEntries();
511 int hsize=token->GetEntries();
512 std::vector<double> sample(hsample.size());
513 double min_diff_time=1e20;
514 double nearest_time=time;
516 for(
int i=0;i<hsize;i++) in >> sample[
i];
517 sample[hsize]=sample[0];
518 if(!in.good())
break;
519 if(
fabs(time-sample[hsample[
"time"]])<min_diff_time) {
520 min_diff_time=
fabs(time-sample[hsample[
"time"]]);
521 nearest_time=sample[hsample[
"time"]];
522 simulation_id=sample[hsample[
"simulation_id"]];
541 if(gOPT.verbose) cout << endl;
545 if(gOPT.eamp[ifoid]!=0) {
546 if(gOPT.type[ifoid]==
"fixed") eamp = 1.+gOPT.eamp[ifoid];
547 if(gOPT.type[ifoid]==
"uniform") eamp = gRandom->Uniform(1-
fabs(gOPT.eamp[ifoid]),1+
fabs(gOPT.eamp[ifoid]));
548 if(gOPT.type[ifoid]==
"gaussian") eamp = gRandom->Gaus(1,
fabs(gOPT.eamp[ifoid]));
550 if(gOPT.verbose) cout <<
"CWB_Plugin_CE : selected amplitude error (" << gOPT.eamp[ifoid] <<
"%) -> eamp : " << eamp << endl;
555 if(gOPT.ephs[ifoid]!=0) {
556 if(gOPT.type[ifoid]==
"fixed") ephs = gOPT.ephs[ifoid];
557 if(gOPT.type[ifoid]==
"uniform") ephs = gRandom->Uniform(-
fabs(gOPT.ephs[ifoid]),
fabs(gOPT.ephs[ifoid]));
558 if(gOPT.type[ifoid]==
"gaussian") ephs = gRandom->Gaus(0,
fabs(gOPT.ephs[ifoid]));
560 if(gOPT.verbose) cout <<
"CWB_Plugin_CE : selected phase error (" << gOPT.ephs[ifoid] <<
" deg) -> ephs : " << ephs <<
" deg" << endl;
565 if(gOPT.etim[ifoid]!=0) {
566 if(gOPT.type[ifoid]==
"fixed") etim = gOPT.etim[ifoid];
567 if(gOPT.type[ifoid]==
"uniform") etim = gRandom->Uniform(-
fabs(gOPT.etim[ifoid]),
fabs(gOPT.etim[ifoid]));
568 if(gOPT.type[ifoid]==
"gaussian") etim = gRandom->Gaus(0,
fabs(gOPT.etim[ifoid]));
570 if(gOPT.verbose) cout <<
"CWB_Plugin_CE : selected time error (" << gOPT.etim[ifoid] <<
" sec) -> etim : " << etim <<
" sec" << endl;
573 if(gOPT.verbose) cout << endl;
576 if(eamp!=1) x *= eamp;
std::vector< char * > ifoName
virtual void rate(double r)
char * watversion(char c='s')
static void PhaseShift(wavearray< double > &x, double pShift=0.)
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
string getmdcList(size_t n)
virtual void start(double s)
virtual size_t size() const
#define IMPORT(TYPE, VAR)
void SetCalibrationErrors(wavearray< double > &x, int ifoid)
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
static void TimeShift(wavearray< double > &x, double tShift=0.)
void PrintUserOptions(CWB::config *cfg)
double GetNearestCalibrationEntry(double time, int &simulation_id)
double fabs(const Complex &x)
void DumpUserOptions(TString odir, CWB::config *cfg)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
virtual void resize(unsigned int)
void ReadUserOptions(TString options)
void Draw(GWAT_DRAW type=GWAT_TIME, TString options="ALP", Color_t color=kBlack)