Logo coherent WaveBurst  
Library Reference Guide
Logo
DrawMatchPE.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #define ALPHA 0.1
20 
21 #define MAX_GW 100
22 
23 
24 void DrawMatchPE(TString ifname, TString odir, TString label, bool title=true) {
25 
26  // init blind colors
27  Color_t color[4];
28  color[0] = CWB::Toolbox::getTableau10BlindColor("DarkOrange1");
29  color[1] = CWB::Toolbox::getTableau10BlindColor("DeepSkyBlue4");
30  color[2] = CWB::Toolbox::getTableau10BlindColor("DarkGray");
31  color[3] = CWB::Toolbox::getTableau10BlindColor("SandyBrown");
32 
33  ifstream in;
34  in.open(ifname.Data(),ios::in);
35  if (!in.good()) {cout << "Error Opening File : " << ifname.Data() << endl;exit(1);}
36 
37  int N=0;
38  double match[MAX_GW],pvalue[MAX_GW],X[MAX_GW],zero[MAX_GW];
39  double median[MAX_GW],l99[MAX_GW],l90[MAX_GW],l50[MAX_GW],u50[MAX_GW],u90[MAX_GW],u99[MAX_GW];
40  char gw_name[MAX_GW][256];
41  char dummy[256];
42  while(1) {
43  in >> gw_name[N] >> dummy >> dummy >> match[N] >> dummy >> pvalue[N] >> dummy >> median[N]
44  >> dummy >> l99[N] >> dummy >> l90[N] >> dummy >> l50[N] >> dummy >> u50[N] >> dummy >> u90[N] >> dummy >> u99[N];
45  if(!in.good()) break;
46  cout <<" "<< gw_name[N] <<" "<< match[N] <<" "<< pvalue[N] <<" "<< median[N]
47  <<" "<< l99[N] <<" "<< l90[N] <<" "<< l50[N] <<" "<< u50[N] <<" "<< u90[N] <<" "<< u99[N] << endl;;
48  zero[N]=0.;
49 
50  l50[N] = fabs(median[N]-l50[N]);
51  u50[N] = fabs(u50[N]-median[N]);
52 
53  l90[N] = (median[N]-l90[N]);
54  u90[N] = (u90[N]-median[N]);
55 
56  l99[N] = fabs(median[N]-l99[N]);
57  u99[N] = fabs(u99[N]-median[N]);
58 
59  X[N]=N+1;
60  N++;
61  }
62  in.close();
63 
64  int *index = new int[N];
65  TMath::Sort(N,match,index,false);
66 
67  double smatch[MAX_GW];
68  double smedian[MAX_GW],sl99[MAX_GW],sl90[MAX_GW],sl50[MAX_GW],su50[MAX_GW],su90[MAX_GW],su99[MAX_GW];
69  double xmax=0,ymax=0;
70  TString sgw_name[MAX_GW];
71  for(int n=0;n<N;n++) {
72  X[n]/=N;
73  smatch[n]=match[index[n]];
74  smedian[n]=median[index[n]];
75  sl50[n]=l50[index[n]];
76  su50[n]=u50[index[n]];
77  sl90[n]=l90[index[n]];
78  su90[n]=u90[index[n]];
79  sl99[n]=l99[index[n]];
80  su99[n]=u99[index[n]];
81  sgw_name[n]=gw_name[index[n]];
82  if(smatch[n]>xmax) xmax=smatch[n];
83  if(smedian[n]+su99[n]>ymax) ymax=smedian[n]+su99[n];
84  cout << n << "\t" << sgw_name[n] << "\tmatch " << smatch[n] << "\tmedian " << smedian[n] << "\tlow90 " << sl90[n] << "\tup90 " << su90[n] << endl;
85  }
86 
87  TCanvas* canvas = new TCanvas("fom", "fom", 300,40, 800, 800);
88  canvas->SetGrid();
89  canvas->SetLeftMargin(0.15);
90  canvas->SetBottomMargin(0.15);
91 
92  gStyle->SetGridStyle(3);
93  gStyle->SetGridWidth(1);
94  gStyle->SetFrameBorderMode(0);
95  gStyle->SetTitleTextColor(kBlack);
96  gStyle->SetTitleFont(12,"D");
97 
98  // draw frame
99  TH2F *frame = new TH2F("frame","",1000,0.,1,1000,0.,1);
100  if(title) frame->SetTitle(TString("Matching")+" ( "+label+" )"); else frame->SetTitle("");
101  frame->SetStats(0);
102  frame->GetXaxis()->SetTitle("OnSource Match");
103  frame->GetYaxis()->SetTitle("OffSource Match");
104  frame->GetXaxis()->SetTitleOffset(1.50);
105  frame->GetYaxis()->SetTitleOffset(1.50);
106  frame->GetXaxis()->CenterTitle(kTRUE);
107  frame->GetYaxis()->CenterTitle(kTRUE);
108  frame->GetXaxis()->SetTitleFont(132);
109  frame->GetXaxis()->SetLabelFont(132);
110  frame->GetYaxis()->SetTitleFont(132);
111  frame->GetYaxis()->SetLabelFont(132);
112  frame->GetXaxis()->SetTitleSize(0.04);
113  frame->GetXaxis()->SetLabelSize(0.04);
114  frame->GetYaxis()->SetTitleSize(0.04);
115  frame->GetYaxis()->SetLabelSize(0.04);
116  frame->GetYaxis()->SetLabelOffset(0.01);
117  frame->GetXaxis()->SetNdivisions(9);
118  frame->GetYaxis()->SetNdivisions(9);
119  frame->LabelsOption("x");
120  frame->Draw();
121 
122  // draw match
123  TGraphAsymmErrors* gmatch = new TGraphAsymmErrors(N,match,median,zero,zero,l90,u90);
124  gmatch->SetMarkerStyle(20);
125  gmatch->SetMarkerSize(1.0);
126  gmatch->SetLineWidth(1);
127  gmatch->SetLineColor(kBlack);
128  gmatch->SetMarkerColor(color[0]);
129  gmatch->Draw("PSAME");
130 
131  // Draw diagonal
132  double xdiag[2]={0,1};
133  double ydiag[2]={0,1};
134  TGraph* gdiag = new TGraph(2,xdiag,ydiag);
135  gmatch->SetLineColor(color[1]);
136  gdiag->SetLineStyle(9);
137  gdiag->Draw("SAME");
138 
139  // draw legend
140  TLegend *leg = new TLegend(0.4047619,0.1614987,0.8897243,0.2635659,NULL,"brNDC");
141  leg->SetBorderSize(1);
142  leg->SetTextAlign(22);
143  leg->SetTextFont(12);
144  leg->SetLineColor(1);
145  leg->SetLineStyle(1);
146  leg->SetLineWidth(1);
147  leg->SetFillColor(0);
148  leg->SetFillStyle(1001);
149  leg->SetTextSize(0.03);
150  leg->SetLineColor(kBlack);
151  leg->SetFillColor(kWhite);
152  leg->AddEntry(gmatch,"median ( 90% confidence )","lp");
153  leg->AddEntry(gdiag,"null hypothesis","lp");
154  leg->Draw();
155 
156  if(odir!="") odir=odir+"/";
157  TString ofname=odir+gSystem->BaseName(ifname);;
158  ofname.ReplaceAll(".txt","_match.png");
159 
160  canvas->Print(ofname);
161 }
162 
void DrawMatchPE(TString ifname, TString odir, TString label, bool title=true)
Definition: DrawMatchPE.C:24
int n
Definition: cwb_net.C:28
TString("c")
char odir[1024]
double median(std::vector< double > &vec)
Definition: wavegraph.cc:485
return wmap canvas
#define N
TString label
Definition: MergeTrees.C:21
char title[256]
Definition: SSeriesExample.C:1
ifstream in
wavearray< int > index
double fabs(const Complex &x)
Definition: numpy.cc:55
static Int_t getTableau10BlindColor(Int_t index)
Definition: Toolbox.cc:7275
#define MAX_GW
Definition: DrawMatchPE.C:21
exit(0)