Logo coherent WaveBurst  
Config Reference Guide
Logo
CWB_Plugin_Gating.C
Go to the documentation of this file.
1 #define XIFO 4
2 
3 #pragma GCC system_header
4 
5 #include "cwb.hh"
6 #include "cwb2G.hh"
7 #include "config.hh"
8 #include "network.hh"
9 #include "wavearray.hh"
10 #include "TString.h"
11 #include "TObjArray.h"
12 #include "TObjString.h"
13 #include "TRandom.h"
14 #include "Toolbox.hh"
15 
16 //!DATA_CONDITIONING
17 
18 // This plugin implements the time gating in the pixel's selection stage.
19 // Gating is a veto of the pixels belonging to a time interval.
20 // This plugin is used to exclude from the analysis the pixels
21 // in a time interval where there is a huge glitch.
22 // Huge glitches are harmful because they affect the correct estimation
23 // of the selection threshold and could mask the nearby events at lower SNR.
24 // Warning : events with high SNR can be rejected by this procedure (see SETHR)
25 
26 #define SETHR 1000000 // Is the threshold which define the time slices to be cutted
27  // Warning : this value depends on the frequency interval [fHigh:fLow]
28 
29 #define TWIN 0.5 // Is the window (sec) used to integrate the energies in time
30  // TWIN must be a multiple of the greatest time resolution used in the analysis
31 
32 #define TEDG 1.5 // Is the time window (sec) to be cutted when the time integrated energy is > SETHR
33 
34 void
35 CWB_Plugin(TFile* jfile, CWB::config* cfg, network* net, WSeries<double>* x, TString ifo, int type) {
36 
37 // this plugin is called in cwb2G.cc to the whitened data at the beginning of the COHERENT stage
38 
39 // cout << endl;
40 // cout << "-----> CWB_Plugin_Gating.C" << endl;
41 // cout << "ifo " << ifo.Data() << endl;
42 // cout << "type " << type << endl;
43 // cout << endl;
44 
45  if(type==CWB_PLUGIN_CONFIG) {
46  cout << endl;
47  cout << "-----> CWB_Plugin_Gating.C" << endl;
48  cout << endl;
49  }
50 
51  if(type==CWB_PLUGIN_ICOHERENCE) {
52 
53  // get data range
54  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
55  double Tb = gCWB2G->GetSegBegin()-cfg->segEdge;
56  double Te = gCWB2G->GetSegEnd()+cfg->segEdge;
57 
58 
59  //cout << "CWB_Plugin_Gating.C - " << "Tb : " << int(Tb) << " Te : " << int(Te) << endl;
60 
61  int nIFO = (gCWB2G->IsSingleDetector()) ? 1 : net->ifoListSize(); // number of detectors
62  int size = net->getifo(0)->getHoT()->size(); // number of time bins
63  double rate = net->getifo(0)->getHoT()->rate(); // rate
64  double dt = 1./rate; // time bin resolution (sec)
65 
66  //cout << "-----> CWB_Plugin_Gating.C - size : " << size << "\t rate : " << rate << "\t dt : " << dt << " length(sec) " << size*dt << endl;
67 
68  wavearray<double>* hot[NIFO_MAX];
69  for(int n=0; n<nIFO; n++) hot[n] = net->getifo(n)->getHoT(); // whitened data
70 
71  // A new array 'SE' is obtained from the arrays 'hot whitened data'
72  // It contains the time integrated energies over the time window TWIN
73  // A time sample is marked as to be vetoed when the energy SE>SETHR
74  // When a time sample 'i' is vetoed also the nearby M time size are vetoed [i-M:i+M]
75  // where M is the number of samples contained in TEDG sec
76 
77  int X = int(cfg->segEdge/dt+0.5); // samples in segEdge : this the is scratch time
78  int M = int(TEDG/dt)+1; // samples in TEDG sec
79  int N = int(TWIN/dt); // number of time samples in TWIN
80  if(N<1) N=1;
81  vector<waveSegment> glist; // gating segment list
82  wavearray<double> SE(size);
83  wavearray<int> sVeto(size); // array which contains samples to be vetoed
84 
85  int gsize=0;
86  for(int n=0; n<nIFO; n++) { // loop over detectors
87  SE=0;
88 // for(int i=N-1;i<size;i++) for(int j=0;j<N;j++) SE[i]+=pow(hot[n]->data[i-j],2);
89 
90  for(int j=0;j<N;j++) SE[N-1]+=pow(hot[n]->data[N-1-j],2);
91  for(int i=N;i<size;i++) {
92  SE[i] = SE[i-1];
93  SE[i] -= pow(hot[n]->data[i-N],2);
94  SE[i] += pow(hot[n]->data[i],2);
95  }
96 
97  sVeto=0;
98  for(int i=0;i<size;i++) {
99  if(SE[i]>SETHR) {
100  int is = i-M>X ? i-M : X;
101  int es = i+M<(size-X) ? i+M : size-X;
102  for(int k=is;k<es;k++) sVeto[k]=1;
103  }
104  }
105  // array derivative -> gating_start=1, gating_stop=-1
106  sVeto[0]=0;sVeto[size-1]=0;
107  for(int i=0;i<size-1;i++) sVeto[i]=sVeto[i+1]-sVeto[i];
108 
109  // build the gating segment list
110  waveSegment gseg; // gating segment
111  gseg.index = 0;
112  for(int i=0;i<size;i++) {
113  if(sVeto[i]== 1) gseg.start = Tb+int(i*dt); // round to nearest lower integer
114  if(sVeto[i]==-1) {
115  gseg.stop = Tb+int(i*dt+0.5); // round to nearest higher integer
116  gseg.index++;
117  glist.push_back(gseg);
118  }
119  }
120 
121  if(glist.size()>0) {
122  cout << endl;
123  cout.precision(10);
124  for(int j=gsize;j<glist.size();j++) {
125  cout << j << " -----> CWB_Plugin_Gating.C - " << net->getifo(n)->Name << " gating time : start="
126  << glist[j].start << " stop=" << glist[j].stop << " len=" << glist[j].stop-glist[j].start << endl;
127  }
128  cout << endl;
129  gsize=glist.size();
130  }
131  }
132 
133  double gating_time = 0; // total gating time
134  if(glist.size()) {
135  glist = CWB::Toolbox::unionSegments(glist); // Join & sort a waveSegment list
136  gating_time = CWB::Toolbox::getTimeSegList(glist); // get total gating time
137  glist = CWB::Toolbox::invertSegments(glist); // Invert waveSegment list
138  net->segList = CWB::Toolbox::mergeSegLists(glist,net->segList); // merge gating veto list to the net->segList
139  }
140 
141  cout<< "-----> CWB_Plugin_Gating.C - gating time : " << gating_time << endl << endl;
142 
143  // add infos to history
144  char info[256];
145  sprintf(info,"-GT:%g",gating_time);
146  gCWB2G->PrintAnalysisInfo(CWB_STAGE_COHERENCE,"cwb2G::Coherence",info,false);
147  }
148 
149  return;
150 }
nIFO
#define SETHR
DATA_CONDITIONING.
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
#define TWIN
#define TEDG
shift breaksw case n
Definition: cwb_clchunk.csh:75
shift breaksw case M
string network
Definition: cWB_conf.py:7