Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_SNR.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 <vector>
36 
37 void
39 //!NOISE_MDC_SIMULATION
40 // Plugin used in simulation mode to compute and save the mdc SNR (terminate after the read noise/mdc stage)
41 
42  cout << endl;
43  cout << "-----> CWB_Plugin_SNR.C" << endl;
44  cout << "ifo " << ifo.Data() << endl;
45  cout << "type " << type << endl;
46  cout << endl;
47 
48  // set sim in simulation mode = 2
49  if(type==CWB_PLUGIN_CONFIG) {
50  cfg->simulation = 2;
51  cfg->nfactor = 1;
52  cfg->factors[0] = 1;
53  }
54 
55  if(type==CWB_PLUGIN_OREADDATA) {
56 
57  if(cfg->simulation!=2) {
58  cout << "CWB_Plugin_SNR.C - Error : this pluging is implemented only in simulation mode = 2" << endl;
59  gSystem->Exit(1);
60  }
61 
62  // create output root file to store snr infos
63  char snrFile[1024];
64  sprintf(snrFile,"%s/snr_%s_%d.root",cfg->output_dir,cfg->data_label,NET->nRun);
65  TFile* froot = new TFile(snrFile, "RECREATE");
66  if(froot==NULL) {
67  cout << "CWB_Plugin_SNR.C - Error opening root file : " << snrFile << endl;
68  gSystem->Exit(1);
69  }
70  froot->cd();
71 
72  // create mdc tree
73  int nIFO = NET->ifoListSize(); // number of detectors
74  injection mdc(nIFO);
75  TTree* mdc_tree = mdc.setTree();
76  // add iSNR branch to mdc_tree
77  char ciSNR[16]; sprintf(ciSNR,"iSNR[%1d]/F",nIFO);
78  float* iSNR = new float[nIFO];
79  mdc_tree->Branch("iSNR", iSNR, ciSNR);
80 
81  NET->setVeto(cfg->iwindow); // select mdc
82  // in pipeline is done in the coherence stage
83 
84  int N = NET->mdc__ID.size(); // number of injectios
85 
86  std::vector<size_t> mdc__ID = NET->mdc__ID; // save a copy mdc__ID
87 
88  NET->mdc__ID.resize(1); // resize to 1 to save single event
89  for (int k=0;k<N;k++) { // loop over mdc
90  int ID = mdc__ID[k];
91  NET->mdc__ID[0] = ID;
92  for(int i=0; i<nIFO; i++) {
93  detector* pD = NET->getifo(i);
94  iSNR[i] = pD->ISNR.data[ID]; // fill mdc with iSNR
95  //cout << k << " SNR " << iSNR[i] << endl;
96  }
97  mdc.output(mdc_tree,NET,1); // fill tree with mdc parameters
98  }
99 
100  NET->mdc__ID = mdc__ID; // restore mdc__ID
101 
102  mdc_tree->Write(); // save tree
103  froot->Close();
104 
105  delete iSNR;
106 
107  gSystem->Exit(0); // terminate job
108 
109  }
110 
111  return;
112 }
113 
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
CWB::config * cfg
double iwindow
Definition: config.hh:200
TString("c")
void output(TTree *, network *, double, bool=true)
Definition: injection.cc:602
size_t nRun
Definition: network.hh:572
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
TString mdc[4]
TTree * setTree()
Definition: injection.cc:223
std::vector< size_t > mdc__ID
Definition: network.hh:615
i drho i
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
COHERENCE.
#define N
char ifo[NIFO_MAX][8]
size_t ifoListSize()
Definition: network.hh:431
#define nIFO
jfile
Definition: cwb_job_obj.C:43
double setVeto(double=5.)
param: time window around injections
Definition: network.cc:3487
int simulation
Definition: config.hh:199
char output_dir[1024]
Definition: config.hh:318
network NET
Definition: cwb_dump_inj.C:30
std::vector< double > iSNR[NIFO_MAX]
int k
int nfactor
Definition: config.hh:201
TFile * froot
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
DataType_t * data
Definition: wavearray.hh:319
double factors[FACTORS_MAX]
Definition: config.hh:202
char data_label[1024]
Definition: config.hh:332
wavearray< double > ISNR
Definition: detector.hh:372
detector ** pD