Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CWB_Plugin_Gating_Fix.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
36 
37 // this plugin is called in cwb2G.cc after the production of the TF maps with max over the sky energy (TFmax)
38 // The procedure is applied for each detector and for each resolution level using the TFmax.
39 
40  cout << endl;
41  cout << "-----> CWB_Plugin_Gating_Fix.C" << endl;
42  cout << "ifo " << ifo.Data() << endl;
43  cout << "type " << type << endl;
44  cout << endl;
45 
46  if(type==CWB_PLUGIN_ECOHERENCE) {
47 
48  // WSeries contains energy (it is stored in the 0 phase amplitudes)
49 
50  // import resolution level
51  size_t gILEVEL=-1; IMPORT(size_t,gILEVEL)
52  char slevel[256];sprintf(slevel,",%d,",gILEVEL);
53 
54  int nIFO = net->ifoListSize();
55  detector* pD[NIFO_MAX]; // pointers to detectors
56  for(int n=0;n<nIFO;n++) pD[n] = net->getifo(n);
58  for(int n=0; n<nIFO; n++) WS[n] = pD[n]->getTFmap();
59 
60  int layers = WS[0]->maxLayer()+1; // numbers of frequency bins (first & last bins have df/2)
61  int slices = WS[0]->sizeZero(); // number of time bins
62 
63  double df = WS[0]->resolution(); // frequency bin resolution (hz) //FIX
64  double dt = 1./(2*df); // time bin resolution (sec) //FIX
65 
66  int rate = int(1./dt);
67 
68  cout << "layers : " << layers << "\t slices : " << slices << "\t rate : " << rate
69  << "\t dt : " << dt << "\t df : " << df << endl;
70 
71  double rTWIN = fabs(TWIN/dt-TMath::Nint(TWIN/dt));
72  if(TWIN<dt || rTWIN>1e-7) { // FIX!!! fix precision !!!
73  cout << "-----> CWB_Plugin_Gating_Fix.C : Error-> " << " TWIN=" << TWIN
74  << " is not a multiple of dt=" << dt << endl;
75  gSystem->Exit(1);
76  }
77 
78  double rTEDG = fabs(TEDG/dt-TMath::Nint(TEDG/dt));
79  if(TEDG<dt || rTEDG>1e-7) { // FIX!!! fix precision !!!
80  cout << "-----> CWB_Plugin_Gating_Fix.C : Error-> " << " TEDG=" << TEDG
81  << " is not a multiple of dt=" << dt << endl;
82  gSystem->Exit(1);
83  }
84 
85  // For each time slice (time index) we compute the sum of the pixel
86  // energy over all frequency layers (freq index)
87  // The sum is stored in the array 'se[NIFO_MAX]'
88  // se = projection of TF map energy on the time axis
90  for(int n=0; n<nIFO; n++) {
91  se[n].resize(slices); se[n]=0;
92  for(int i=0;i<slices;i++) {
93  for(int j=0;j<layers;j++) se[n][i] += WS[n]->getSample(i,j);
94  }
95  }
96 
97  // A new array 'SE[NIFO_MAX]' is obtained from the arrays 'se[NIFO_MAX]'
98  // It contains the time integrated energies over the time window TWIN
99  // NOTE : this procedure makes the energies independents from the resolution level
100  int N = int(TWIN/dt); // number of time samples in TWIN
101  if(N<1) N=1;
103  for(int n=0; n<nIFO; n++) {
104  SE[n].resize(slices); SE[n]=0;
105  for(int i=N-1;i<slices;i++) for(int j=0;j<N;j++) SE[n][i]+=se[n][i-j];
106  }
107 
108  // find the time slices to be excluded :
109  // 1) from the computation of the pixel's selection threshold
110  // 2) from the pixel's selection
111  // A time slice is marked as to be cutted when the energy SE>SETHR
112  // When a time slice is cutted also the nearby M time slices are cutted [slice-M:slice+M]
113  // where M is the number of samples contained in TEDG sec
114  int X = int(cfg->segEdge/dt+0.5); // samples in segEdge : this the is scratch time
115  int M = int(TEDG/dt)+1; // samples in TEDG sec
116  wavearray<int> sCut[NIFO_MAX]; // array which contains the slices to be cut
117  for(int n=0; n<nIFO; n++) {
118  sCut[n].resize(slices); sCut[n]=0;
119  for(int i=0;i<slices;i++) {
120  if(SE[n][i]>SETHR) {
121  int is = i-M>X ? i-M : X;
122  int es = i+M<(slices-X) ? i+M : slices-X;
123  for(int ii=is;ii<es;ii++) sCut[n][ii]=1;
124  }
125  //cout << i << " " << SE[n][i] << endl;
126  }
127  }
128 
129  // All pixels in the layers which time slice is marked as cutted are filled with a negative energy = -1e20
130  // -> these pixels do not partecipate to the computation of the pixel's selection thereshold
131  // and moreover these pixels are excluded from the selection
132  double gating_time=0.; // total time vetoed by gating
133  for(int n=0; n<nIFO; n++) {
134  for(int i=0;i<slices;i++) { // set to -1e20 the energy
135  if(sCut[n][i]) {
136  gating_time+=dt;
137  for(int j=0;j<layers;j++) WS[n]->putSample(-1e20,i,j);
138  }
139  }
140  }
141 
142  // add infos to history
143  char info[256];
144  sprintf(info,"-RES:%d-GT:%g",cfg->l_high-gILEVEL,gating_time);
145  cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
146  gCWB2G->PrintAnalysisInfo(CWB_STAGE_COHERENCE,"cwb2G::Coherence",info,false);
147  }
148 
149  return;
150 }
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
int slices
int n
Definition: cwb_net.C:10
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<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t 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
int layers
#define M
Definition: UniqSLagsList.C:3
int j
Definition: cwb_net.C:10
i drho i
#define N
#define TEDG
char ifo[NIFO_MAX][8]
Definition: cwb2G.hh:15
network ** net
NOISE_MDC_SIMULATION.
size_t ifoListSize()
Definition: network.hh:413
double segEdge
Definition: config.hh:146
#define nIFO
jfile
Definition: cwb_job_obj.C:25
int l_high
Definition: config.hh:138
void PrintAnalysisInfo(CWB_STAGE stage, TString comment, TString info, bool out=true, bool log=true)
Definition: cwb.cc:2110
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:51
i() int(T_cor *100))
const int NIFO_MAX
Definition: wat.hh:4
#define TWIN
double e
double dt
double fabs(const Complex &x)
Definition: numpy.cc:37
double resolution(int=0)
Definition: wseries.hh:137
#define SETHR
DATA_CONDITIONING.
double df
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
cout<< "live time after cat 2 : "<< detSegs_ctime<< endl;if(detSegs_ctime< segTHR){cout<< "job segment live time after cat2 < "<< segTHR<< " sec, job terminated !!!"<< endl;exit(1);}double Tb=detSegs[0].start;double Te=detSegs[0].stop;double dT=Te-Tb;char file[512], tdf00[512], tdf90[512], buFFer[1024];int rnID=int(gRandom->Rndm(13)*1.e9);if(simulation){i=NET.readMDClog(injectionList, double(long(Tb))-mdcShift);printf("GPS: %16.6f saved, injections: %d\n", double(long(Tb)), i);frTB[nIFO].shiftBurstMDCLog(NET.mdcList, ifos, mdcShift);for(int i=0;i< NET.mdcTime.size();i++) NET.mdcTime[i]+=mdcShift;vector< waveSegment > mdcSegs(NET.mdcTime.size());for(int k=0;k< NET.mdcTime.size();k++){mdcSegs[k].start=NET.mdcTime[k]-gap;mdcSegs[k].stop=NET.mdcTime[k]+gap;}vector< waveSegment > mdcSegs_dq2=slagTB.mergeSegLists(detSegs_dq2, mdcSegs);double mdcSegs_ctime=slagTB.getTimeSegList(mdcSegs_dq2);cout<< "live time in zero lag after cat2+inj : "<< mdcSegs_ctime<< endl;if(mdcSegs_ctime==0){cout<< "job segment with zero cat2+inj live time in zero lag, job terminated !!!"<< endl;exit(1);}}if(dump_infos_and_exit) exit(0);if(mask >0.) NET.setSkyMask(mask, skyMaskFile);for(i=0;i< nIFO;i++){frTB[i].readFrames(FRF[i], channelNamesRaw[i], x);x.start(x.start()+dataShift[i]);x.start(x.start()-segLen *(segID[i]-segID[0]));if(singleDetector) TB.resampleToPowerOfTwo(x);sprintf(file,"%s/%s_%d_%s_%d_%d.dat", nodedir, ifo[i], int(Tb), data_label, runID, rnID);if(dump_sensitivity_and_exit){sprintf(file,"%s/sensitivity_%s_%d_%s_job%d.txt", dump_dir, ifo[i], int(Tb), data_label, runID);cout<< endl<< "Dump Sensitivity : "<< file<< endl<< endl;TB.makeSpectrum(file, x);continue;}if(dcCal[i]>0.) x *=dcCal[i];if(fResample >0){x.FFT(1);x.resize(fResample/x.rate()*x.size());x.FFT(-1);x.rate(fResample);}pTF[i]=pD[i]-> getTFmap()
virtual void resize(unsigned int)
Definition: wavearray.cc:445
size_t sizeZero()
Definition: wseries.hh:126
int maxLayer()
Definition: wseries.hh:121
detector ** pD
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
COHERENCE.