Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DrawSkyDistributionPRC.C
Go to the documentation of this file.
1 //
2 // Draw injected/reconstructed locations of the detected events
3 // Note : this macro is used to generate the PRC report (cwb_report merge_label prc)
4 // Author : Gabriele Vedovato
5 
6 #include "TROOT.h"
7 #include "TSystem.h"
8 #include "TFile.h"
9 #include "TTree.h"
10 #include <fstream>
11 #include <iostream>
12 #include "TGraph.h"
13 #include "TMultiGraph.h"
14 #include "TCanvas.h"
15 #include "TH1F.h"
16 #include "TMath.h"
17 #include "TH1F.h"
18 #include "TH2F.h"
19 #include <TComplex.h>
20 #include <TStyle.h>
21 #include <TRandom.h>
22 #include "TVector3.h"
23 #include "TRotation.h"
24 #include "Math/Vector3Dfwd.h"
25 #include "Math/Rotation3D.h"
26 #include "constants.hh"
27 
28 #define RESOLUTION 2
29 //#define RESOLUTION 4
30 
31 //#define COORDINATES "cWB"
32 #define COORDINATES "Geographic"
33 
34 #define PROJECTION ""
35 //#define PROJECTION "hammer"
36 //#define PROJECTION "sinusoidal"
37 
38 //#define WRITE_PLOT
39 
40 #define DRAW_EVENTS
41 
42 //#define DRAW_ANGULAR_DISTANCE
43 #define ANGULAR_DISTANCE 90
44 
45 //#define DRAW_PP
46 
47 #define DISPLAY_WORLD_MAP
48 #define WORLD_MAP_DIR "$CWB_GWAT/data/"
49 
50 using namespace CWB;
51 
52 void
54  detectorParams* dP, float T_win, int pp_inetcc, float T_cor, int pp_irho, float T_cut,
55  float T_vED, float T_pen, float T_ifar, bool binj=true, TString polarization="TENSOR", bool save_antpat=false) {
56 
57  // binj=true -> select injected directions
58  // binj=false -> select reconstructed directions
59 
60  if (!gROOT->GetClass("Polar3DVector")) gSystem->Load("libMathCore");
61 
62  using namespace ROOT::Math;
63 
64  double r2d = 180./TMath::Pi();
65  double d2r = TMath::Pi()/180.;
66 
67  double speedLight = watconstants::SpeedOfLightInVacuo();
68 
69  int nIFO = ifo.size();
70 
72  for(int n=0;n<nIFO;n++) {
73  if(ifo[n]!="") pD[n] = new detector((char*)ifo[n].Data()); // built in detector
74  else pD[n] = new detector(dP[n]); // user detector
75  }
76  for(int n=0;n<nIFO;n++) cout << n << " " << pD[n]->Name << endl;
77 
78  gnetwork* gNET = new gnetwork;
79  for(int i=0; i<nIFO; i++) gNET->add(pD[i]);
80 
81  if(polarization=="SCALAR") {
82  // setting for SGW
83  for(int n=0;n<(int)gNET->ifoListSize();n++) {
84  detector *d = gNET->getifo(n);
86  }
87  }
88 
89  // setup skymap options
90  gskymap* gSM = gNET->GetGskymap();
92 
93  TH2D* h2 = (TH2D*)gSM->GetHistogram();
94  h2->GetXaxis()->SetTitleSize(0.05);
95  h2->GetXaxis()->SetLabelSize(0.05);
96  h2->GetYaxis()->SetTitleSize(0.05);
97  h2->GetYaxis()->SetLabelSize(0.05);
98  h2->GetYaxis()->SetLabelFont(42);
99  h2->GetYaxis()->SetLabelFont(42);
100  h2->GetXaxis()->SetTitleFont(42);
101  h2->GetYaxis()->SetTitleFont(42);
102  h2->GetZaxis()->SetRangeUser(0,1.0);
103 
104  if(save_antpat) { // draw antenna patterns
105 
106  char ofileName[1024];
107  TString world_map = gSystem->ExpandPathName(WORLD_MAP_DIR);
108 
109  gSM->SetWorldMapPath(world_map.Data());
110  gSM->SetWorldMap();
111  gNET->DrawAntennaPattern(2); // |fx|/|f+|
112  gNET->DrawSitesShortLabel(kBlack);
113  gNET->DrawSites(kBlack,2.0);
114  gNET->DrawSitesArms(1000000,kWhite,3.0);
115  sprintf(ofileName,"%s/antpat_alignment.png",odir.Data());
116  cout << "Write : " << ofileName << endl;
117  gSM->Print(ofileName);
118 
119  gSM->SetWorldMapPath(world_map.Data());
120  gSM->SetWorldMap();
121  gNET->DrawAntennaPattern(3); // sqrt(|F+|^2+|Fx|^2)
122  gNET->DrawSitesShortLabel(kBlack);
123  gNET->DrawSites(kBlack,2.0);
124  gNET->DrawSitesArms(1000000,kWhite,3.0);
125  sprintf(ofileName,"%s/antpat_sensitivity.png",odir.Data());
126  cout << "Write : " << ofileName << endl;
127  gSM->Print(ofileName);
128  }
129 
130  gSM->SetWorldMap(false);
131 #ifdef DRAW_PP
132  gNET->DrawAntennaPattern(3,0,true,3);
133  cout << "order : " << gSM->getOrder() << endl;
134  cout << "size : " << gSM->size() << endl;
135  int apsize = gSM->size();
136  double* ap = new double[apsize];
137  for(int i=0;i<apsize;i++) ap[i] = gSM->get(i);
138  //for(int i=0;i<apsize;i++) cout << i << " " << gSM->get(i) << endl;
139  Int_t *iap = new Int_t[apsize];
140  TMath::Sort(apsize,ap,iap,true);
141  //for(int i=0;i<apsize;i++) cout << i << " " << ap[iap[i]] << endl;
142 #else
143  gNET->DrawAntennaPattern(3,0,true);
144 #endif
145 
146  // compute direction of D1 D2 axis -> vector v12
147  XYZVector D1(pD[0]->Rv[0],pD[0]->Rv[1],pD[0]->Rv[2]);
148  XYZVector D2(pD[1]->Rv[0],pD[1]->Rv[1],pD[1]->Rv[2]);
149  D1=D1/speedLight;
150  D2=D2/speedLight;
151  XYZVector D12 = D1-D2;
152  TVector3 vD12(D12.X(),D12.Y(),D12.Z());
153 
154  double th12 = r2d*vD12.Theta();
155  double ph12 = r2d*vD12.Phi();
156  cout << "coordinates D12 " << ph12 << " " << th12 << endl;
157  Polar3DVector v12(1, d2r*th12, d2r*ph12);
158 
159  // open reconstructed event file
160 #ifdef DRAW_EVENTS
161 
162  char wave_file_name[1024];
163  sprintf(wave_file_name,"merge/wave_%s.%s.root",data_label.Data(),merge_label.Data());
164 
165  TFile* ifile = TFile::Open(wave_file_name);
166  if(ifile==NULL) {cout<<"Error opening file : "<<wave_file_name<<endl;exit(1);}
167  TTree* itree = (TTree *) gROOT->FindObject("waveburst");
168  if(itree==NULL) {cout<<"Error opening tree : "<<"waveburst"<<endl;exit(1);}
169 
170  char cut[1024];
171  char tmp[1024];
172  sprintf(cut,"abs(time[0]-time[%d])<%f && netcc[%d]>%f && rho[%d]>%f",
173  nIFO,T_win,pp_inetcc,T_cor,pp_irho,T_cut);
174  if(T_vED>0) {strcpy(tmp,cut);sprintf(cut,"%s && neted[0]/ecor<%f",tmp,T_vED);}
175  if(T_pen>0) {strcpy(tmp,cut);sprintf(cut,"%s && penalty>%f",tmp,T_pen);}
176  if(T_ifar>0) {strcpy(tmp,cut);sprintf(cut,"%s && ifar>(24.*3600.*365.)*%f",tmp,T_ifar);}
177 
178  itree->Draw("theta[0]:phi[0]:theta[1]:phi[1]",cut,"goff");
179  int isize=itree->GetSelectedRows();
180  cout << "isize : " << isize << endl;
181 
182  double* th0 = itree->GetV1();
183  double* ph0 = itree->GetV2();
184  double* th1 = itree->GetV3();
185  double* ph1 = itree->GetV4();
186 
187 #ifdef DRAW_ANGULAR_DISTANCE
188  TH1F* h1 = new TH1F("hist","hist",100,0,180);
189 #endif
190 
191  // create gskymap to store events
192  gskymap* gEVT = new gskymap((int)3);
194  *gEVT = 0;
195 
196  // draw events
197  double markerSize = isize>10000 ? 0.3 : 0.4;
198  double ph,th;
199  for (int i=0;i<isize;i++) {
200 
201  // compute distance (dOmega) between injected and reconstructed directions
202  Polar3DVector v0(1, d2r*th0[i], d2r*ph0[i]);
203  Polar3DVector v1(1, d2r*th1[i], d2r*ph1[i]);
204  //cout << th0[i] << " " << ph0[i] << " " << th1[i] << " " << ph1[i] << endl;
205  double dot = v0.Dot(v1);
206  double dOmega = r2d*TMath::ACos(dot);
207 
208  // compute distance (dOmega12) between injected and D1 D2 axis
209  double dot12 = v12.Dot(v1);
210  double dOmega12 = r2d*TMath::ACos(dot12);
211 
212  // discart events outside the ring (width=5degrees) at distance ANGULAR_DISTANCE
213 // if(fabs(dOmega12-ANGULAR_DISTANCE)>5) continue;
214 
215 #ifdef DRAW_ANGULAR_DISTANCE
216  h1->Fill(dOmega);
217 #endif
218 
219  if(binj) {ph=ph1[i]; th=th1[i];}
220  else {ph=ph0[i]; th=th0[i];}
221 
222  if(COORDINATES=="cWB") {
223  gSM->DrawMarker(ph, th, 20, markerSize, kBlack); // cWB
224  }
225  if(COORDINATES=="Geographic") {
226  double phi,theta;
227  CwbToGeographic(ph,th,phi,theta);
228  gSM->DrawMarker(phi,theta, 20, markerSize, kBlack); // Geographic
229 
230  int index = gEVT->getSkyIndex(th,ph);
231  gEVT->set(index,gEVT->get(index)+1);
232  }
233  }
234 #endif
235 
236  // draw circle at distance -ANGULAR_DISTANCE from D1 D2 axis
237  double phi=ph12;
238  double theta=th12-ANGULAR_DISTANCE;
239  if(COORDINATES=="Geographic") {
240  CwbToGeographic(phi,theta,phi,theta);
241  }
242  gNET->DrawCircles(phi,theta,(Color_t)kWhite,1,1,true);
243 
244  gSM->GetCanvas()->Update();
245 
246  // draw angular distance
247 #ifdef DRAW_ANGULAR_DISTANCE
248  gStyle->SetLineColor(kBlack);
249  h1->Draw();
250 #endif
251 
252  // write plot
253  char ofname[1024];
254  if(binj) {
255  sprintf(ofname,"%s/inj_detected_antpat.png",odir.Data());
256  } else {
257  sprintf(ofname,"%s/rec_detected_antpat.png",odir.Data());
258  }
259  cout << "Write : " << ofname << endl;
260  gSM->Print(ofname);
261  //gSystem->Exit(0);
262 
263 #ifdef DRAW_PP
264  TCanvas* canvas = new TCanvas;
265  canvas->SetGridx();
266  canvas->SetGridy();
267 
268  double* x = new double[apsize];
269  double* y = new double[apsize];
270  for(int i=0;i<apsize;i++) {
271  //x[i]=ap[iap[i]];
272  x[i]=pow(ap[iap[i]],4);
273  y[i]=gEVT->get(iap[i]);
274 //x[i]=pow(ap[i],4);
275 //y[i]=gEVT->get(i);
276  }
277  for(int i=1;i<apsize;i++) {
278  x[i]+=x[i-1];
279  y[i]+=y[i-1];
280  }
281  for(int i=0;i<apsize;i++) {
282  x[i]/=x[apsize-1];
283  y[i]/=y[apsize-1];
284  }
285  TGraph* gr = new TGraph(apsize,x,y);
286  gr->Draw("ALP");
287  gr->SetLineColor(kRed);
288  gr->SetMarkerColor(kRed);
289 
290  TH1F* hist = gr->GetHistogram();
291  hist->SetStats(kFALSE);
292  char title[256];
293  sprintf(title,"%s - pp plot",TITLE);
294  hist->SetTitle(title);
295  //hist->GetXaxis()->SetTitle("(F+^{2}+Fx^{2}) Probability");
296  hist->GetXaxis()->SetTitle("(F+^{2}+Fx^{2})^{2} Probability");
297  hist->GetYaxis()->SetTitle("Frequentist Probability");
298  hist->GetXaxis()->SetRangeUser(0,1);
299  hist->GetYaxis()->SetRangeUser(0,1);
300 
301 // for(int i=0;i<apsize;i++) cout << i << " " << ap[iap[i]] << " " << gEVT->get(iap[i]) << endl;
302 // gEVT->Draw();
303 #endif
304 
305 }
306 
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
TH2D * GetHistogram()
Definition: gskymap.hh:120
gskymap * gSM
char cut[512]
double T_ifar
double T_pen
gnetwork * gNET
size_t add(detector *)
param: detector structure return number of detectors in the network
Definition: network.cc:2528
void DrawSitesArms(double mlength=600000., Color_t lcolor=kBlack, Size_t lwidth=1.0, Style_t lstyle=1)
Definition: gnetwork.cc:295
Definition: ced.hh:24
void DrawAntennaPattern(int polarization=-1, int dpaletteId=0, bool btitle=true, int order=6)
Definition: gnetwork.cc:655
void DrawCircles(double phi, double theta, double gps, Color_t lcolor=kBlack, Width_t lwidth=1, Style_t lstyle=1, bool labels=false)
Definition: gnetwork.cc:1289
int n
Definition: cwb_net.C:10
TString("c")
#define TITLE
Definition: TestSiteJ1.C:44
void set(size_t i, double a)
Definition: gskymap.hh:110
double T_cor
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
char odir[1024]
float theta
void DrawSkyDistributionPRC(TString data_label, TString odir, TString merge_label, vector< TString > ifo, detectorParams *dP, float T_win, int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar, bool binj=true, TString polarization="TENSOR", bool save_antpat=false)
void DrawMarker(double phi, double theta, int marker, Size_t msize=1, Color_t tcolor=1)
Definition: gskymap.cc:724
TH2F * ph
return wmap canvas
#define ANGULAR_DISTANCE
i pp_inetcc
int polarization
void setPolarization(POLARIZATION polarization=TENSOR)
Definition: detector.hh:288
i drho i
int isize
char ifo[NIFO_MAX][8]
size_t ifoListSize()
Definition: network.hh:413
#define PROJECTION
#define nIFO
size_t getSkyIndex(double th, double ph)
param: theta param: phi
Definition: skymap.cc:702
TString world_map
Definition: DrawGNET.C:16
char data_label[512]
Definition: test_config1.C:160
#define WORLD_MAP_DIR
void DrawSitesShortLabel(Color_t tcolor=kBlack, Size_t tsize=0.052, Font_t tfont=32)
Definition: gnetwork.cc:407
float phi
TGraph * gr
detector D1
i() int(T_cor *100))
double Pi
int getOrder()
Definition: skymap.hh:296
const int NIFO_MAX
Definition: wat.hh:4
double * tmp
Definition: testWDM_5.C:31
void DrawSites(Color_t mcolor=kBlack, Size_t msize=2.0, Style_t mstyle=20)
Definition: gnetwork.cc:238
TCanvas * GetCanvas()
Definition: gskymap.hh:119
void SetWorldMapPath(TString worldMapPath)
Definition: gskymap.hh:138
TString merge_label
#define RESOLUTION
TFile * ifile
TString ofileName
Definition: MergeTrees.C:37
gskymap * GetGskymap()
Definition: gnetwork.hh:26
char title[256]
Definition: SSeriesExample.C:1
void SetWorldMap(bool drawWorldMap=true)
Definition: gskymap.hh:136
wavearray< int > index
double T_win
void CwbToGeographic(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:396
strcpy(RunLabel, RUN_LABEL)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double T_cut
TTree * itree
double get(size_t i)
param: sky index
Definition: skymap.cc:681
double T_vED
size_t size()
Definition: skymap.hh:118
void Print(TString pname)
Definition: gskymap.cc:1104
wavearray< double > y
Definition: Test10.C:31
void SetOptions(TString projection="hammer", TString coordinate="Geographic", double resolution=1, bool goff=false)
Definition: gskymap.cc:66
i drho pp_irho
#define COORDINATES
detector ** pD
exit(0)
double SpeedOfLightInVacuo()
Definition: constants.hh:96