Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
13 void CreateSkyMask() {
14 
15  skymap sm(0.4,0,180,0,360);
16  int L = sm.size();
17 
21 
22  gnetwork sp_l1h1; sp_l1h1.add(&L1);sp_l1h1.add(&H1);
23  gnetwork sp_l1v1; sp_l1v1.add(&L1);sp_l1v1.add(&V1);
24  gnetwork sp_v1h1; sp_v1h1.add(&V1);sp_v1h1.add(&H1);
25 
26  for (int l=0;l<L;l++) {
27  double phi = sm.getPhi(l);
28  double theta = sm.getTheta(l);
29 
30  double Fp_l1h1 = sp_l1h1.GetAntennaPattern(phi,theta,0,true);
31  double Fx_l1h1 = sp_l1h1.GetAntennaPattern(phi,theta,0,false);
32 
33  double Fp_l1v1 = sp_l1v1.GetAntennaPattern(phi,theta,0,true);
34  double Fx_l1v1 = sp_l1v1.GetAntennaPattern(phi,theta,0,false);
35 
36  double Fp_v1h1 = sp_v1h1.GetAntennaPattern(phi,theta,0,true);
37  double Fx_v1h1 = sp_v1h1.GetAntennaPattern(phi,theta,0,false);
38 
39  //if(Fx_l1h1<Fx_THR || Fx_l1v1<Fx_THR || Fx_v1h1<Fx_THR) sm.set(l,0); else sm.set(l,1);
40  if(Fx_l1h1<Fx_THR || Fx_l1v1<Fx_THR || Fx_v1h1<Fx_THR) sm.set(l,1); else sm.set(l,0);
41  }
42 
43  int n=0;
44  for (int l=0;l<L;l++) if(sm.get(l)==1) n++;
45  cout << 100*(double)n/(double)L << endl;
46  double REJECTED_SKY_PIXEL_PERCENTAGE = (double)n/(double)L;
47 
48  //sm+=-sm.max();
49  //sm*=-1;
50 
51 #ifdef OFILE_NAME
52  ofstream out;
53  out.open(OFILE_NAME, ios::out);
54  if (!out.good()) {cout << "Error Opening File : " << OFILE_NAME << endl;exit(1);}
55  for (int l=0;l<L;l++) out << l << " " << sm.get(l) << endl;
56  out.close();
57 
58  bool* mask = new bool[L];
59  setSkyMask((double)REJECTED_SKY_PIXEL_PERCENTAGE, (char*)OFILE_NAME, (bool*)mask, (int)L);
60  for (int l=0;l<L;l++) sm.set(l,(double)mask[l]);
61 #endif
62 
63  gskymap* gSM = new gskymap(sm);
64  gSM->Draw();
65 
66 }
67 
68 
69 // read skyMask
70 size_t setSkyMask(double f, char* file, bool* mask, int L) {
71  int i;
72  size_t n = 0;
73  size_t l;
74  char str[1024];
75  FILE* in;
76  char* pc;
77  double a;
78 
79  wavearray<double> skyHole(L); // static sky mask describing "holes"
80  wavearray<double> probability(L); // sky probability
81 
82  if(!L) return 0;
83  if(!file) return 0;
84  if(!strlen(file)) return 0;
85 
86  if( (in=fopen(file,"r"))==NULL ) return 0;
87 
88  while(fgets(str,1024,in) != NULL){
89 
90  if(str[0] == '#') continue;
91  if((pc = strtok(str," \t")) == NULL) continue;
92  if(pc) i = atoi(pc); // sky index
93  if((pc = strtok((char*)NULL," \t")) == NULL) continue;
94  if(pc && i>=0 && i<int(L)) {
95  skyHole.data[i] = atof(pc); // probability
96 // nSkyStat.set(i, atof(pc));
97  n++;
98  }
99  }
100  a = skyHole.mean()*skyHole.size();
101  skyHole *= a>0. ? 1./a : 0.;
102  if(f==0.) { skyHole = 1.; return n; }
103 
104  double* p = skyHole.data;
105  double** pp = (double **)malloc(L*sizeof(double*));
106  for(l=0; l<L; l++) pp[l] = p + l;
107 
108  probability.waveSort(pp,0,L-1);
109 
110  a = double(L);
111  for(l=0; l<L; l++) {
112  a -= 1.;
113  *pp[l] = a/L<f ? 0. : 1.;
114  //if(*pp[l] == 0.) nSkyStat.set(pp[l]-p,*pp[l]);
115  if(*pp[l] == 0.) mask[pp[l]-p]=false; else mask[pp[l]-p]=true;
116  }
117  free(pp);
118  return n;
119 }
120 
121 
gskymap * gSM
double pc
Definition: DrawEBHH.C:15
virtual size_t size() const
Definition: wavearray.hh:127
size_t add(detector *)
param: detector structure return number of detectors in the network
Definition: network.cc:2528
tuple f
Definition: cwb_online.py:91
wavearray< double > a(hp.size())
size_t setSkyMask(double, char *, bool *, int)
Definition: CreateSkyMask.C:70
int n
Definition: cwb_net.C:10
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
float theta
void CreateSkyMask()
Definition: CreateSkyMask.C:13
double getTheta(size_t i)
Definition: skymap.hh:206
i drho i
void Draw(int dpaletteId=0, Option_t *option="colfz")
Definition: gskymap.cc:442
virtual double mean() const
Definition: wavearray.cc:1053
ofstream out
Definition: cwb_merge.C:196
float phi
char str[1024]
detector V1((char *)"V1")
Definition: DrawGNET.C:11
#define OFILE_NAME
Definition: CreateSkyMask.C:8
gNET add & L1
Definition: DrawGNET.C:9
Definition: skymap.hh:45
double getPhi(size_t i)
Definition: skymap.hh:146
virtual void waveSort(DataType_t **pp, size_t l=0, size_t r=0) const
Definition: wavearray.cc:1403
ifstream in
string file
Definition: cwb_online.py:385
int l
Definition: cbc_plots.C:434
double mask
double GetAntennaPattern(double phi, double theta, double psi=0., int polarization=1)
Definition: gnetwork.cc:545
void set(size_t i, double a)
param: sky index param: value to set
Definition: skymap.hh:104
DataType_t * data
Definition: wavearray.hh:301
detector H1((char *)"H1")
Definition: DrawGNET.C:10
double get(size_t i)
param: sky index
Definition: skymap.cc:681
#define REJECTED_SKY_PIXEL_PERCENTAGE
size_t size()
Definition: skymap.hh:118
#define Fx_THR
Definition: CreateSkyMask.C:9
exit(0)