Logo coherent WaveBurst  
Library Reference Guide
Logo
CreateSkyMask.C
Go to the documentation of this file.
1 //
2 // Create SkyMask for CWB analysis
3 // Author : Gabriele Vedovato
4 
5 //#define OFILE_NAME "L1H1V1_EarthSkyMask_2DetMask_FxThr_0d01.txt"
6 //#define Fx_THR 0.01
7 
8 #define OFILE_NAME "L1H1V1_EarthSkyMask_2DetMask_FxThr_0d02.txt"
9 #define Fx_THR 0.02
10 
11 size_t setSkyMask(double, char*, bool*, int);
12 
14 
15 void CreateSkyMask() {
16 
17  skymap sm(0.4,0,180,0,360);
18  int L = sm.size();
19 
20  detector L1(const_cast<char*>("L1"));
21  detector H1(const_cast<char*>("H1"));
22  detector V1(const_cast<char*>("V1"));
23 
24  gnetwork sp_l1h1; sp_l1h1.add(&L1);sp_l1h1.add(&H1);
25  gnetwork sp_l1v1; sp_l1v1.add(&L1);sp_l1v1.add(&V1);
26  gnetwork sp_v1h1; sp_v1h1.add(&V1);sp_v1h1.add(&H1);
27 
28  for (int l=0;l<L;l++) {
29  double phi = sm.getPhi(l);
30  double theta = sm.getTheta(l);
31 
32  double Fp_l1h1 = sp_l1h1.GetAntennaPattern(phi,theta,0,true);
33  double Fx_l1h1 = sp_l1h1.GetAntennaPattern(phi,theta,0,false);
34 
35  double Fp_l1v1 = sp_l1v1.GetAntennaPattern(phi,theta,0,true);
36  double Fx_l1v1 = sp_l1v1.GetAntennaPattern(phi,theta,0,false);
37 
38  double Fp_v1h1 = sp_v1h1.GetAntennaPattern(phi,theta,0,true);
39  double Fx_v1h1 = sp_v1h1.GetAntennaPattern(phi,theta,0,false);
40 
41  //if(Fx_l1h1<Fx_THR || Fx_l1v1<Fx_THR || Fx_v1h1<Fx_THR) sm.set(l,0); else sm.set(l,1);
42  if(Fx_l1h1<Fx_THR || Fx_l1v1<Fx_THR || Fx_v1h1<Fx_THR) sm.set(l,1); else sm.set(l,0);
43  }
44 
45  int n=0;
46  for (int l=0;l<L;l++) if(sm.get(l)==1) n++;
47  cout << 100*(double)n/(double)L << endl;
48  double REJECTED_SKY_PIXEL_PERCENTAGE = (double)n/(double)L;
49 
50  //sm+=-sm.max();
51  //sm*=-1;
52 
53 #ifdef OFILE_NAME
54  ofstream out;
55  out.open(OFILE_NAME, ios::out);
56  if (!out.good()) {cout << "Error Opening File : " << OFILE_NAME << endl;exit(1);}
57  for (int l=0;l<L;l++) out << l << " " << sm.get(l) << endl;
58  out.close();
59 
60  bool* mask = new bool[L];
61  setSkyMask((double)REJECTED_SKY_PIXEL_PERCENTAGE, (char*)OFILE_NAME, (bool*)mask, (int)L);
62  for (int l=0;l<L;l++) sm.set(l,(double)mask[l]);
63 #endif
64 
65  gSM = new gskymap(sm);
66  gSM->Draw();
67  return;
68 }
69 
70 
71 // read skyMask
72 size_t setSkyMask(double f, char* file, bool* mask, int L) {
73  int i;
74  size_t n = 0;
75  size_t l;
76  char str[1024];
77  FILE* in;
78  char* pc;
79  double a;
80 
81  wavearray<double> skyHole(L); // static sky mask describing "holes"
82  wavearray<double> probability(L); // sky probability
83 
84  if(!L) return 0;
85  if(!file) return 0;
86  if(!strlen(file)) return 0;
87 
88  if( (in=fopen(file,"r"))==NULL ) return 0;
89 
90  while(fgets(str,1024,in) != NULL){
91 
92  if(str[0] == '#') continue;
93  if((pc = strtok(str," \t")) == NULL) continue;
94  if(pc) i = atoi(pc); // sky index
95  if((pc = strtok((char*)NULL," \t")) == NULL) continue;
96  if(pc && i>=0 && i<int(L)) {
97  skyHole.data[i] = atof(pc); // probability
98 // nSkyStat.set(i, atof(pc));
99  n++;
100  }
101  }
102  a = skyHole.mean()*skyHole.size();
103  skyHole *= a>0. ? 1./a : 0.;
104  if(f==0.) { skyHole = 1.; return n; }
105 
106  double* p = skyHole.data;
107  double** pp = (double **)malloc(L*sizeof(double*));
108  for(l=0; l<L; l++) pp[l] = p + l;
109 
110  probability.waveSort(pp,0,L-1);
111 
112  a = double(L);
113  for(l=0; l<L; l++) {
114  a -= 1.;
115  *pp[l] = a/L<f ? 0. : 1.;
116  //if(*pp[l] == 0.) nSkyStat.set(pp[l]-p,*pp[l]);
117  if(*pp[l] == 0.) mask[pp[l]-p]=false; else mask[pp[l]-p]=true;
118  }
119  free(pp);
120  return n;
121 }
122 
123 
double pc
Definition: DrawEBHH.C:15
size_t add(detector *)
param: detector structure return number of detectors in the network
Definition: network.cc:2559
wavearray< double > a(hp.size())
size_t setSkyMask(double, char *, bool *, int)
Definition: CreateSkyMask.C:72
int n
Definition: cwb_net.C:28
ofstream out
Definition: cwb_merge.C:214
float theta
void CreateSkyMask()
Definition: CreateSkyMask.C:15
double getTheta(size_t i)
Definition: skymap.hh:224
void Draw(int dpaletteId=1, Option_t *option="colfz")
Definition: gskymap.cc:460
i drho i
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
virtual size_t size() const
Definition: wavearray.hh:145
float phi
char str[1024]
detector V1((char *)"V1")
Definition: DrawGNET.C:11
#define OFILE_NAME
Definition: CreateSkyMask.C:8
gskymap * gSM
Definition: CreateSkyMask.C:13
int l
gNET add & L1
Definition: DrawGNET.C:9
Definition: skymap.hh:63
double getPhi(size_t i)
Definition: skymap.hh:164
ifstream in
virtual double mean() const
Definition: wavearray.cc:1071
virtual void waveSort(DataType_t **pp, size_t l=0, size_t r=0) const
Definition: wavearray.cc:1421
double mask
double GetAntennaPattern(double phi, double theta, double psi=0., int polarization=1)
Definition: gnetwork.cc:564
void set(size_t i, double a)
param: sky index param: value to set
Definition: skymap.hh:122
DataType_t * data
Definition: wavearray.hh:319
detector H1((char *)"H1")
Definition: DrawGNET.C:10
double get(size_t i)
param: sky index
Definition: skymap.cc:699
#define REJECTED_SKY_PIXEL_PERCENTAGE
size_t size()
Definition: skymap.hh:136
#define Fx_THR
Definition: CreateSkyMask.C:9
exit(0)