Logo coherent WaveBurst  
Library Reference Guide
Logo
CWB_Plugin_Gating.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 "cwb2G.hh"
25 #include "config.hh"
26 #include "network.hh"
27 #include "wavearray.hh"
28 #include "TString.h"
29 #include "TObjArray.h"
30 #include "TObjString.h"
31 #include "TRandom.h"
32 #include "Toolbox.hh"
33 
34 //!DATA_CONDITIONING
35 
36 // This plugin implements the time gating in the pixel's selection stage.
37 // Gating is a veto of the pixels belonging to a time interval.
38 // This plugin is used to exclude from the analysis the pixels
39 // in a time interval where there is a huge glitch.
40 // Huge glitches are harmful because they affect the correct estimation
41 // of the selection threshold and could mask the nearby events at lower SNR.
42 // Warning : events with high SNR can be rejected by this procedure (see SETHR)
43 
44 #define SETHR 1000000 // Is the threshold which define the time slices to be cutted
45  // Warning : this value depends on the frequency interval [fHigh:fLow]
46 
47 #define TWIN 0.5 // Is the window (sec) used to integrate the energies in time
48  // TWIN must be a multiple of the greatest time resolution used in the analysis
49 
50 #define TEDG 1.5 // Is the time window (sec) to be cutted when the time integrated energy is > SETHR
51 
52 void
54 
55 // this plugin is called in cwb2G.cc to the whitened data at the beginning of the COHERENT stage
56 
57 // cout << endl;
58 // cout << "-----> CWB_Plugin_Gating.C" << endl;
59 // cout << "ifo " << ifo.Data() << endl;
60 // cout << "type " << type << endl;
61 // cout << endl;
62 
63  if(type==CWB_PLUGIN_CONFIG) {
64  cout << endl;
65  cout << "-----> CWB_Plugin_Gating.C" << endl;
66  cout << endl;
67  }
68 
69  if(type==CWB_PLUGIN_ICOHERENCE) {
70 
71  // get data range
72  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
73  double Tb = gCWB2G->GetSegBegin()-cfg->segEdge;
74  double Te = gCWB2G->GetSegEnd()+cfg->segEdge;
75 
76 
77  //cout << "CWB_Plugin_Gating.C - " << "Tb : " << int(Tb) << " Te : " << int(Te) << endl;
78 
79  int nIFO = (gCWB2G->IsSingleDetector()) ? 1 : net->ifoListSize(); // number of detectors
80  int size = net->getifo(0)->getHoT()->size(); // number of time bins
81  double rate = net->getifo(0)->getHoT()->rate(); // rate
82  double dt = 1./rate; // time bin resolution (sec)
83 
84  //cout << "-----> CWB_Plugin_Gating.C - size : " << size << "\t rate : " << rate << "\t dt : " << dt << " length(sec) " << size*dt << endl;
85 
87  for(int n=0; n<nIFO; n++) hot[n] = net->getifo(n)->getHoT(); // whitened data
88 
89  // A new array 'SE' is obtained from the arrays 'hot whitened data'
90  // It contains the time integrated energies over the time window TWIN
91  // A time sample is marked as to be vetoed when the energy SE>SETHR
92  // When a time sample 'i' is vetoed also the nearby M time size are vetoed [i-M:i+M]
93  // where M is the number of samples contained in TEDG sec
94 
95  int X = int(cfg->segEdge/dt+0.5); // samples in segEdge : this the is scratch time
96  int M = int(TEDG/dt)+1; // samples in TEDG sec
97  int N = int(TWIN/dt); // number of time samples in TWIN
98  if(N<1) N=1;
99  vector<waveSegment> glist; // gating segment list
100  wavearray<double> SE(size);
101  wavearray<int> sVeto(size); // array which contains samples to be vetoed
102 
103  int gsize=0;
104  for(int n=0; n<nIFO; n++) { // loop over detectors
105  SE=0;
106 // for(int i=N-1;i<size;i++) for(int j=0;j<N;j++) SE[i]+=pow(hot[n]->data[i-j],2);
107 
108  for(int j=0;j<N;j++) SE[N-1]+=pow(hot[n]->data[N-1-j],2);
109  for(int i=N;i<size;i++) {
110  SE[i] = SE[i-1];
111  SE[i] -= pow(hot[n]->data[i-N],2);
112  SE[i] += pow(hot[n]->data[i],2);
113  }
114 
115  sVeto=0;
116  for(int i=0;i<size;i++) {
117  if(SE[i]>SETHR) {
118  int is = i-M>X ? i-M : X;
119  int es = i+M<(size-X) ? i+M : size-X;
120  for(int k=is;k<es;k++) sVeto[k]=1;
121  }
122  }
123  // array derivative -> gating_start=1, gating_stop=-1
124  sVeto[0]=0;sVeto[size-1]=0;
125  for(int i=0;i<size-1;i++) sVeto[i]=sVeto[i+1]-sVeto[i];
126 
127  // build the gating segment list
128  waveSegment gseg; // gating segment
129  gseg.index = 0;
130  for(int i=0;i<size;i++) {
131  if(sVeto[i]== 1) gseg.start = Tb+int(i*dt); // round to nearest lower integer
132  if(sVeto[i]==-1) {
133  gseg.stop = Tb+int(i*dt+0.5); // round to nearest higher integer
134  gseg.index++;
135  glist.push_back(gseg);
136  }
137  }
138 
139  if(glist.size()>0) {
140  cout << endl;
141  cout.precision(10);
142  for(int j=gsize;j<glist.size();j++) {
143  cout << j << " -----> CWB_Plugin_Gating.C - " << net->getifo(n)->Name << " gating time : start="
144  << glist[j].start << " stop=" << glist[j].stop << " len=" << glist[j].stop-glist[j].start << endl;
145  }
146  cout << endl;
147  gsize=glist.size();
148  }
149  }
150 
151  double gating_time = 0; // total gating time
152  if(glist.size()) {
153  glist = CWB::Toolbox::unionSegments(glist); // Join & sort a waveSegment list
154  gating_time = CWB::Toolbox::getTimeSegList(glist); // get total gating time
155  glist = CWB::Toolbox::invertSegments(glist); // Invert waveSegment list
156  net->segList = CWB::Toolbox::mergeSegLists(glist,net->segList); // merge gating veto list to the net->segList
157  }
158 
159  cout<< "-----> CWB_Plugin_Gating.C - gating time : " << gating_time << endl << endl;
160 
161  // add infos to history
162  char info[256];
163  sprintf(info,"-GT:%g",gating_time);
164  gCWB2G->PrintAnalysisInfo(CWB_STAGE_COHERENCE,"cwb2G::Coherence",info,false);
165  }
166 
167  return;
168 }
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
CWB::config * cfg
double start
Definition: network.hh:55
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.
double M
Definition: DrawEBHH.C:13
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
double Te
Long_t size
static double getTimeSegList(vector< waveSegment > list)
Definition: Toolbox.cc:611
int j
Definition: cwb_net.C:28
i drho i
static vector< waveSegment > invertSegments(vector< waveSegment > &ilist)
Definition: Toolbox.cc:247
#define N
#define TEDG
char ifo[NIFO_MAX][8]
Definition: cwb2G.hh:33
network ** net
NOISE_MDC_SIMULATION.
size_t ifoListSize()
Definition: network.hh:431
static vector< waveSegment > unionSegments(vector< waveSegment > &ilist)
Definition: Toolbox.cc:119
double segEdge
Definition: config.hh:164
#define nIFO
virtual size_t size() const
Definition: wavearray.hh:145
#define SETHR
DATA_CONDITIONING.
double GetSegEnd()
Definition: cwb.hh:183
jfile
Definition: cwb_job_obj.C:43
void PrintAnalysisInfo(CWB_STAGE stage, TString comment, TString info, bool out=true, bool log=true)
Definition: cwb.cc:2129
wavearray< double > hot[2]
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:69
i() int(T_cor *100))
wavearray< double > * getHoT()
param: no parameters
Definition: detector.hh:175
const int NIFO_MAX
Definition: wat.hh:22
double GetSegBegin()
Definition: cwb.hh:182
#define TWIN
bool IsSingleDetector()
Definition: cwb.hh:185
int k
std::vector< waveSegment > segList
Definition: network.hh:616
double dt
int index
Definition: network.hh:54
double Tb
char Name[16]
Definition: detector.hh:327
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
static vector< waveSegment > mergeSegLists(vector< waveSegment > &ilist1, vector< waveSegment > &ilist2)
Definition: Toolbox.cc:350
double stop
Definition: network.hh:56