Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DrawEventsToL1H1AntPat.C
Go to the documentation of this file.
1 #define XIFO 4
2 #pragma GCC system_header
3 
4 #include "constants.hh"
5 #include "gnetwork.hh"
6 
7 #include "TROOT.h"
8 #include "TSystem.h"
9 #include "TFile.h"
10 #include "TTree.h"
11 #include <fstream>
12 #include <iostream>
13 #include "TGraph.h"
14 #include "TMultiGraph.h"
15 #include "TCanvas.h"
16 #include "TH1F.h"
17 #include "TMath.h"
18 #include "TH1F.h"
19 #include "TH2F.h"
20 #include <TComplex.h>
21 #include <TStyle.h>
22 #include <TRandom.h>
23 #include <complex.h>
24 #include "TVector3.h"
25 #include "TRotation.h"
26 #include "Math/Vector3Dfwd.h"
27 #include "Math/Rotation3D.h"
28 #include "Math/Polar3D.h"
29 
30 //
31 // Draw Events & Antenna Pattern for L1H1 network
32 // Author : Gabriele Vedovato
33 
34 
35 #define RESOLUTION 2
36 //#define RESOLUTION 4
37 
38 //#define COORDINATES "cWB"
39 #define COORDINATES "Geographic"
40 
41 #define PROJECTION ""
42 //#define PROJECTION "hammer"
43 //#define PROJECTION "sinusoidal"
44 
45 //#define WRITE_PLOT
46 
47 
48 #define IFILE_NAME "merge/wave_sinegaussian_noVirgo.M4.root"
49 #define DRAW_EVENTS
50 
51 //#define DRAW_ANGULAR_DISTANCE
52 #define ANGULAR_DISTANCE 90
53 
54 //using namespace CWB;
55 
56 void DrawEventsToL1H1AntPat(bool binj=true, int polarization=3) {
57 
58  // binj=true -> select injected directions
59  // binj=false -> select reconstructed directions
60 
61  // polarization is the antenna pattern type
62 
63  if (!gROOT->GetClass("Polar3DVector")) gSystem->Load("libMathCore");
64 
65  using namespace ROOT::Math;
66 
67  double r2d = 180./TMath::Pi();
68  double d2r = TMath::Pi()/180.;
69 
70  double speed_light = watconstants::SpeedOfLightInVacuo();
71 
72  // define L1H1 network
73  int nIFO=2;
74  TString ifo[2]={"L1","H1"};
75 
76  gnetwork* gNET = new gnetwork;
77 
78  detector* pD[2];
79  for(int i=0; i<nIFO; i++) pD[i] = new detector((char*)ifo[i].Data()); // built in detector
80  for(int i=0; i<nIFO; i++) gNET->add(pD[i]);
81 
82  // setup skymap options
83  gskymap* gSM = gNET->GetGskymap();
85 
86 
87  TH2D* h2 = (TH2D*)gSM->GetHistogram();
88  h2->GetXaxis()->SetTitleSize(0.05);
89  h2->GetXaxis()->SetLabelSize(0.05);
90  h2->GetYaxis()->SetTitleSize(0.05);
91  h2->GetYaxis()->SetLabelSize(0.05);
92  h2->GetYaxis()->SetLabelFont(42);
93  h2->GetYaxis()->SetLabelFont(42);
94  h2->GetXaxis()->SetTitleFont(42);
95  h2->GetYaxis()->SetTitleFont(42);
96  h2->GetZaxis()->SetRangeUser(0,1.0);
97 
98  // draw antenna pattern
100 
101  // compute direction of D1 D2 axis -> vector v12
102  XYZVector D1(pD[0]->Rv[0],pD[0]->Rv[1],pD[0]->Rv[2]);
103  XYZVector D2(pD[1]->Rv[0],pD[1]->Rv[1],pD[1]->Rv[2]);
104  D1=D1/speed_light;
105  D2=D2/speed_light;
106  XYZVector D12 = D1-D2;
107  TVector3 vD12(D12.X(),D12.Y(),D12.Z());
108 
109  double th12 = r2d*vD12.Theta();
110  double ph12 = r2d*vD12.Phi();
111  cout << "coordinates D12 " << ph12 << " " << th12 << endl;
112  Polar3DVector v12(1, d2r*th12, d2r*ph12);
113 
114  // open reconstructed event file
115 #ifdef DRAW_EVENTS
116  TFile *ifile = TFile::Open(IFILE_NAME);
117  if(ifile==NULL) {cout<<"Error opening file : "<<IFILE_NAME<<endl;exit(1);}
118  TTree* itree = (TTree *) gROOT->FindObject("waveburst");
119  if(itree==NULL) {cout<<"Error opening tree : "<<"waveburst"<<endl;exit(1);}
120  itree->Draw("theta[0]:phi[0]:theta[1]:phi[1]","abs(time[0]-time[2])<0.1 && netcc[0]>0.7 && rho[0]>7 ","goff");
121  int isize=itree->GetSelectedRows();
122  cout << "isize : " << isize << endl;
123 
124  double* th0 = itree->GetV1();
125  double* ph0 = itree->GetV2();
126  double* th1 = itree->GetV3();
127  double* ph1 = itree->GetV4();
128 
129 #ifdef DRAW_ANGULAR_DISTANCE
130  TH1F* h1 = new TH1F("hist","hist",100,0,180);
131 #endif
132 
133  // draw events
134  double ph,th;
135  for (int i=0;i<isize;i++) {
136 
137  // compute distance (dOmega) between injected and reconstructed directions
138  Polar3DVector v0(1, d2r*th0[i], d2r*ph0[i]);
139  Polar3DVector v1(1, d2r*th1[i], d2r*ph1[i]);
140  double dot = v0.Dot(v1);
141  double dOmega = r2d*TMath::ACos(dot);
142 
143  // compute distance (dOmega12) between injected and D1 D2 axis
144  double dot12 = v12.Dot(v1);
145  double dOmega12 = r2d*TMath::ACos(dot12);
146 
147  // discart events outside the ring (width=5degrees) at distance ANGULAR_DISTANCE
148  if(fabs(dOmega12-ANGULAR_DISTANCE)>5) continue;
149 
150 #ifdef DRAW_ANGULAR_DISTANCE
151  h1->Fill(dOmega);
152 #endif
153 
154  if(binj) {ph=ph1[i]; th=th1[i];}
155  else {ph=ph0[i]; th=th0[i];}
156 
157  if(COORDINATES=="cWB") {
158  gSM->DrawMarker(ph, th, 20, 0.4, kBlack); // cWB
159  }
160  if(COORDINATES=="Geographic") {
161  double phi,theta;
162  CwbToGeographic(ph,th,phi,theta);
163  gSM->DrawMarker(phi,theta, 20, 0.4, kBlack); // Geographic
164  }
165  }
166 #endif
167 
168  // draw circle at distance -ANGULAR_DISTANCE from D1 D2 axis
169  double phi=ph12;
170  double theta=th12-ANGULAR_DISTANCE;
171  if(COORDINATES=="Geographic") CwbToGeographic(phi,theta,phi,theta);
172  gNET->DrawCircles(phi,theta,(Color_t)kWhite,1,1,true);
173 
174  gSM->GetCanvas()->Update();
175 
176  // draw angular distance
177 #ifdef DRAW_ANGULAR_DISTANCE
178  gStyle->SetLineColor(kBlack);
179  h1->Draw();
180 #endif
181 
182  // write plot
183 #ifdef WRITE_PLOT
184  TObjArray* token = TString(IFILE_NAME).Tokenize(TString('/'));
185  TObjString* sfile = (TObjString*)token->At(token->GetEntries()-1);
186  TString TITLE = sfile->GetString();
187  TString ofile = sfile->GetString();
188  ofile.ReplaceAll(".root","_EventsVsAntPat.png");
189  cout << "Write : " << ofile << endl;
190  gSM->Print(ofile);
191  gSystem->Exit(0);
192 #endif
193 }
194 
TH2D * GetHistogram()
Definition: gskymap.hh:120
gskymap * gSM
gnetwork * gNET
size_t add(detector *)
param: detector structure return number of detectors in the network
Definition: network.cc:2528
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
TString("c")
#define TITLE
Definition: TestSiteJ1.C:44
float theta
void DrawMarker(double phi, double theta, int marker, Size_t msize=1, Color_t tcolor=1)
Definition: gskymap.cc:724
TH2F * ph
int polarization
#define ANGULAR_DISTANCE
#define RESOLUTION
char ofile[512]
i drho i
int isize
char ifo[NIFO_MAX][8]
#define nIFO
float phi
detector D1
double Pi
TCanvas * GetCanvas()
Definition: gskymap.hh:119
void DrawEventsToL1H1AntPat(bool binj=true, int polarization=3)
TObjArray * token
TFile * ifile
gskymap * GetGskymap()
Definition: gnetwork.hh:26
double fabs(const Complex &x)
Definition: numpy.cc:37
void CwbToGeographic(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:396
#define COORDINATES
TTree * itree
void Print(TString pname)
Definition: gskymap.cc:1104
#define IFILE_NAME
void SetOptions(TString projection="hammer", TString coordinate="Geographic", double resolution=1, bool goff=false)
Definition: gskymap.cc:66
detector ** pD
#define PROJECTION
exit(0)
double SpeedOfLightInVacuo()
Definition: constants.hh:96