Logo coherent WaveBurst  
Library Reference Guide
Logo
DrawPowerSpectrumSphericalHarmonic.C
Go to the documentation of this file.
1 //
2 // this example draw power spectrum of the spherical harmonic coefficients
3 // Author : Gabriele Vedovato
4 // fitsName = fits file name
5 
6 
7 //#define DELAY // use as input a delay skymap between 2 detectors
8 #define SRC_FREQ 200 // main frequency of input signal
9 #define SRC_TH 90 // source theta
10 #define SRC_PH 0 // source phy
11 
12 //#define FP_DPF // use as input the Fp component of network antenna pattern in the DPF
13 //#define FX_DP // use as input the Fx component of network antenna pattern in the DPFF
14 #define FITS // use as input the fits skymap (fitsName = fits file name)
15 //#define ALMS // use as imput a skymap with user defined spherical harmonic coefficients
16 //#define PIXEL // use as input a user defined skymap (pixel defined by user)
17 
18 #define PSPHA 1. // power spectrum threshold
19 //#define PSPHA 0.999999
20 //#define PSPHA 0.99
21 
22 #define NLMAX 256 // l max of the spherical harmonic coefficients
23 //#define NLMAX 512
24 //#define NLMAX 1024
25 
26 #define HEALPIX_ORDER 7 // healpix skymap order
27 
29 
30  #include <complex>
31 
32  TString ifo[3] = {"L1","H1","V1"};
33  gnetwork* gNET = new gnetwork(3,ifo);
34  detector* pD[3];
35  for(int i=0;i<3;i++) pD[i] = gNET->getifo(i);
36 
37  double frequency = SRC_FREQ;
38  double sph = SRC_PH;
39  double sth = SRC_TH;
40 
41  skymap sm(int(HEALPIX_ORDER));
42  int rings=1;
43  for(int i=0;i<=HEALPIX_ORDER;i++) rings=2*rings+1;
44  cout << "rings " << rings << endl;
45  if(NLMAX>(rings+1)/2) {
46  cout << "Error : helpix resolution is " << HEALPIX_ORDER
47  << " number of rings " << rings << endl;
48  cout << " NLMAX=" << NLMAX << " must be <= (rings+1)/2=" << (rings+1)/2 << endl;
49  exit(1);
50  }
51  int L = sm.size();
52  for(int l=0;l<L;l++) {
53  double th = sm.getTheta(l);
54  double ph = sm.getPhi(l);
55 
56 #ifdef DELAY
57  double ifo0d1_pos_delay=gNET->GetDelay(ifo[0], ifo[1], sph, sth);
58  double delay01=pD[0]->getTau(th,ph)-pD[1]->getTau(th,ph);
59  delay01-=ifo0d1_pos_delay;
60  if(frequency>0) {
61  double fdelay=fabs(fmod(delay01,0.5/frequency));
62  int idelay = int((fabs(delay01)-fdelay)/(0.5/frequency));
63  delay01 = idelay%2==0 ? fdelay : (0.5/frequency)-fdelay;
64  }
65  double ifo1d2_pos_delay=gNET->GetDelay(ifo[1], ifo[2], sph, sth);
66  double delay12=pD[1]->getTau(th,ph)-pD[2]->getTau(th,ph);
67  delay12-=ifo1d2_pos_delay;
68  if(frequency>0) {
69  double fdelay=fabs(fmod(delay12,0.5/frequency));
70  int idelay = int((fabs(delay12)-fdelay)/(0.5/frequency));
71  delay12 = idelay%2==0 ? fdelay : (0.5/frequency)-fdelay;
72  }
73  double ifo0d2_pos_delay=gNET->GetDelay(ifo[0], ifo[2], sph, sth);
74  double delay02=pD[0]->getTau(th,ph)-pD[2]->getTau(th,ph);
75  delay02-=ifo0d2_pos_delay;
76  if(frequency>0) {
77  double fdelay=fabs(fmod(delay02,0.5/frequency));
78  int idelay = int((fabs(delay02)-fdelay)/(0.5/frequency));
79  delay02 = idelay%2==0 ? fdelay : (0.5/frequency)-fdelay;
80  }
81  //sm.set(l,delay01);
82  sm.set(l,delay01+delay12);
83  //sm.set(l,delay01+delay12+delay02);
84 #endif
85 
86  //sm.set(l,gNET->GetDelay("L1","V1",ph,th)); //
87  //sm.set(l,gNET->GetDelay("H1","L1",ph,th)); //
88 #ifdef FX_DPF
89  sm.set(l,gNET->GetAntennaPattern(ph, th, 0, 0)); // Fx
90 #endif
91 #ifdef FP_DPF
92  sm.set(l,gNET->GetAntennaPattern(ph, th, 0, 1)); // Fp
93 #endif
94  }
95 
96 #ifdef FITS
97  skymap smf(const_cast<char*>(fitsName.Data()));
98  sm = smf;
99  int order = sm.getOrder();
100  // get number of rings
101  rings=1;
102  for(int i=0;i<=order;i++) rings=2*rings+1;
103  cout << "rings " << rings << endl;
104  if(NLMAX>(rings+1)/2) {
105  cout << "Error : helpix resolution is " << order
106  << " number of rings " << rings << endl;
107  cout << " NLMAX=" << NLMAX << " must be <= (rings+1)/2=" << (rings+1)/2 << endl;
108  exit(1);
109  }
110 // wat::Alm galm = sm.getAlm(NLMAX);
111 // galm(0,0)=complex<double>(1,0);
112 // sm.setAlm(galm);
113 #endif
114 
115 #ifdef PIXEL
116  sm.set(100000,1);
117 #endif
118 
119 #ifdef ALMS
120  int nlmax = NLMAX;
121  wat::Alm alm(nlmax,nlmax);
122  //alm(0,0)=complex<double>(1,0);
123  alm(3,2)=complex<double>(1,0);
124  sm.setAlm(alm);
125 #endif
126 
127  cout << endl;
128  wat::Alm oalm = sm.getAlm(NLMAX);
129  double norm=0;
130  int lmax=0;
131  double psmax=0;
132  for(int l=0;l<=oalm.Lmax();l++) {
133  int limit = TMath::Min(l,oalm.Mmax());
134  double ps=0;
135  for (int m=0; m<=limit; m++) {
136  double mod = pow(oalm(l,m).real(),2)+pow(oalm(l,m).imag(),2);
137  norm+=mod;
138  ps+=mod;
139  }
140  if(ps>psmax) {psmax=ps;lmax=l;}
141  }
142  cout << "lmax : " << lmax << endl;
143 
144  int n1=0;
145  double x1[NLMAX+1];
146  double y1[NLMAX+1];
147  int n2=0;
148  double x2[NLMAX+1];
149  double y2[NLMAX+1];
150  for(int l=0;l<=oalm.Lmax();l++) {
151  double ps=0;
152  int limit = TMath::Min(l,oalm.Mmax());
153  for (int m=0; m<=limit; m++) {
154  double mod = pow(oalm(l,m).real(),2)+pow(oalm(l,m).imag(),2);
155  ps+=mod;
156  }
157  if(l%2) {x1[n1]=l;y1[n1]=ps/norm;n1++;}
158  else {x2[n2]=l;y2[n2]=ps/norm;n2++;}
159  //cout << l << " " << y[l] << endl;
160  }
161  TCanvas* c = new TCanvas();
162  c->SetLogy();
163  TGraph* gr1 = new TGraph(n1,x1,y1);
164  gr1->SetMarkerColor(kBlack);
165  gr1->SetLineColor(kBlack);
166  TGraph* gr2 = new TGraph(n2,x2,y2);
167  gr2->SetMarkerColor(kRed);
168  gr2->SetLineColor(kRed);
169  //gr->GetHistogram()->GetYaxis()->SetRangeUser(0,1e-4);
170  TMultiGraph* mg = new TMultiGraph();
171  mg->Add(gr2);
172  mg->Add(gr1);
173  mg->Draw("alp");
174 //return;
175 
176  cout << "norm : " << norm << endl;
177  double snorm=0;
178  wat::Alm ialm(NLMAX,NLMAX);
179 
180  double pspha = PSPHA;
181  if(pspha<=1) {
182  int N = oalm.Lmax()*(2*oalm.Mmax()+1);
183 
184  double* alm_a = new double[N];
185  int* alm_l = new int[N];
186  int* alm_m = new int[N];
187  N=0;
188  for(int l=0;l<=oalm.Lmax();l++) {
189  int limit = TMath::Min(l,oalm.Mmax());
190  for (int m=0; m<=limit; m++) {
191  alm_a[N] = pow(oalm(l,m).real(),2)+pow(oalm(l,m).imag(),2);
192  alm_l[N] = l;
193  alm_m[N] = m;
194  N++;
195  }
196  }
197 
198  int* index = new int[N];
199  TMath::Sort(N, alm_a, index, true);
200 
201  double norm=0;
202  for(int i=0;i<N;i++) norm+=alm_a[index[i]];
203  for(int i=0;i<N;i++) alm_a[index[i]]/=norm;
204 
205 
206  double cum=0;
207  int icum=0;
208  for (int i=0;i<N;i++) {
209  cum+=alm_a[index[i]];
210  if(cum>pspha) {icum=i+1;break;}
211  }
212  for(int i=0;i<icum;i++) {
213  int ll = alm_l[index[i]];
214  int mm = alm_m[index[i]];
215  ialm(ll,mm)=complex<double>(oalm(ll,mm).real(),oalm(ll,mm).imag());
216  double mod = pow(oalm(ll,mm).real(),2)+pow(oalm(ll,mm).imag(),2);
217 // cout << i << " " << ll << " " << mm << " "
218 // << oalm(ll,mm).real() << " " << oalm(ll,mm).imag() << " " << 100*mod/norm << endl;
219  }
220  delete [] index;
221  delete [] alm_a;
222  delete [] alm_l;
223  delete [] alm_m;
224  }
225 
226  sm=0;
227 /*
228  for(int l=0;l<=ialm.Lmax();l++) {
229  int limit = TMath::Min(l,ialm.Mmax());
230 // for (int m=0; m<=limit; m++) if(l%2) ialm(l,m)=0; // set 0 odd components
231  for (int m=0; m<=limit; m++) if(!(l%2)) ialm(l,m)=0; // set 0 even components
232  }
233 */
234  sm.setAlm(ialm);
235 // sm.rotate(0,90,90); // rotate skymap
236  gskymap* gsm = new gskymap(sm);
237  gsm->Draw();
238 }
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
int Mmax() const
Returns the maximum m.
Definition: alm.hh:72
gnetwork * gNET
TString("c")
double frequency
TH2F * ph
void DrawPowerSpectrumSphericalHarmonic(TString fitsName="")
double getTheta(size_t i)
Definition: skymap.hh:224
void Draw(int dpaletteId=1, Option_t *option="colfz")
Definition: gskymap.cc:460
int m
Definition: cwb_net.C:28
i drho i
#define N
char ifo[NIFO_MAX][8]
int Lmax() const
Returns the maximum l.
Definition: alm.hh:70
i() int(T_cor *100))
int getOrder()
Definition: skymap.hh:314
int l
Definition: skymap.hh:63
Definition: alm.hh:193
double GetDelay(TString ifo1, TString ifo2, double phi, double theta)
Definition: gnetwork.cc:926
double getPhi(size_t i)
Definition: skymap.hh:164
wavearray< int > index
double fabs(const Complex &x)
Definition: numpy.cc:55
double getTau(double, double)
param: source theta,phi angles in degrees
Definition: detector.cc:698
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
size_t size()
Definition: skymap.hh:136
TMultiGraph * mg
TGraphErrors * gr2
detector ** pD
exit(0)