Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_draw_sensitivity.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 // draw sensitivity curves
20 
21 TCanvas* canvas;
22 TGraph* gr;
23 TMultiGraph* mg;
24 
25 void cwb_draw_sensitivity(TString ifname="", bool save_plot=false, bool range_fix=true) {
26 
27  if(ifname.CompareTo("")==0) {
28  if(gSystem->Getenv("CWB_SENSITIVITY_FILE_NAME")!=NULL) {
29  ifname=TString(gSystem->Getenv("CWB_SENSITIVITY_FILE_NAME"));
30  }
31  if(gSystem->Getenv("CWB_SENSITIVITY_SAVE_PLOT")!=NULL) {
32  TString cwb_save_plot=TString(gSystem->Getenv("CWB_SENSITIVITY_SAVE_PLOT"));
33  if(cwb_save_plot.CompareTo("")!=0) {
34  if(!cwb_save_plot.IsFloat()) {cout<< "Error : CWB_SENSITIVITY_SAVE_PLOT is not a number" << endl;exit(1);}
35  if((cwb_save_plot.Atoi()==0)||(cwb_save_plot.Atoi()==1)) save_plot=cwb_save_plot.Atoi();
36  }
37  }
38  if(gSystem->Getenv("CWB_SENSITIVITY_RANGE_FIX")!=NULL) {
39  TString cwb_range_fix=TString(gSystem->Getenv("CWB_SENSITIVITY_RANGE_FIX"));
40  if(cwb_range_fix.CompareTo("")!=0) {
41  if(!cwb_range_fix.IsFloat()) {cout<< "Error : CWB_SENSITIVITY_RANGE_FIX is not a number" << endl;exit(1);}
42  if((cwb_range_fix.Atoi()==0)||(cwb_range_fix.Atoi()==1)) range_fix=cwb_range_fix.Atoi();
43  }
44  }
45  }
46  if(ifname.CompareTo("")==0) {cout << "cwb_draw_sensitivity - Error : File not exist ! " << endl;exit(1);}
47 
48  TString stitle=ifname;
49  stitle.ReplaceAll(".txt","");
50  char title[512];
51  TObjArray* token = TString(stitle).Tokenize(TString("/"));
52  sprintf(title,"Sensitivity One Side - %s",((TObjString*)token->At(token->GetEntries()-1))->GetString().Data());
53 
54  ifstream in;
55  in.open(ifname.Data(), ios::in);
56  if (!in.good()) {cout << "Error Opening File : " << ifname.Data() << endl;exit(1);}
57 
58  int size=0;
59  char str[1024];
60  int fpos=0;
61  while(true) {
62  in.getline(str,1024);
63  if (!in.good()) break;
64  if(str[0] != '#') size++;
65  }
66  //cout << "size " << size << endl;
67  in.clear(ios::goodbit);
68  in.seekg(0, ios::beg);
69 
70  double* freq = new double[size];
71  double* sh = new double[size];
72  int lines=0;
73  while (1) {
74  in >> freq[lines] >> sh[lines];
75  if (!in.good()) break;
76  size=lines;
77  lines++;
78  }
79  in.close();
80 
81 
82  gStyle->SetTitleH(0.032);
83  gStyle->SetTitleW(0.98);
84  gStyle->SetTitleY(0.98);
85  gStyle->SetTitleFont(72);
86  gStyle->SetMarkerColor(50);
87  gStyle->SetLineColor(kWhite);
88 
89  gr = new TGraph(size,freq,sh);
90  gr->SetLineColor(kBlue);
91  gr->SetLineWidth(1);
92  gr->SetMarkerColor(kBlue);
93 
94  canvas = new TCanvas("Sensitivity", "ShOneSide", 300,40, 1000, 600);
95  canvas->Clear();
96  canvas->ToggleEventStatus();
97  canvas->SetLogx();
98  canvas->SetLogy();
99  canvas->SetGridx();
100  canvas->SetGridy();
101  canvas->SetFillColor(kWhite);
102 
103  // remove the red box around canvas
104  gStyle->SetFrameBorderMode(0);
105  gROOT->ForceStyle();
106 
107  gStyle->SetTitleH(0.050);
108  gStyle->SetTitleW(0.95);
109  gStyle->SetTitleY(0.98);
110  gStyle->SetTitleFont(12,"D");
111  gStyle->SetTitleColor(kBlue,"D");
112  gStyle->SetTextFont(12);
113  gStyle->SetTitleFillColor(kWhite);
114  gStyle->SetLineColor(kWhite);
115  gStyle->SetNumberContours(256);
116  gStyle->SetMarkerStyle(7);
117  gStyle->SetMarkerSize(2);
118  gStyle->SetCanvasColor(kWhite);
119  gStyle->SetStatBorderSize(1);
120 
121  mg = new TMultiGraph;
122  mg->SetTitle(title);
123  gStyle->SetTitleW(0.98);
124  gStyle->SetTitleH(0.03);
125  gStyle->SetFillColor(kWhite);
126  gStyle->SetLineColor(kWhite);
127 
128  mg->Add(gr);
129  mg->Paint("APL");
130 
131  mg->GetHistogram()->GetXaxis()->SetLabelSize(0.03);
132  mg->GetHistogram()->GetYaxis()->SetLabelSize(0.03);
133  mg->GetHistogram()->GetXaxis()->SetTitleSize(0.04);
134  mg->GetHistogram()->GetYaxis()->SetTitleSize(0.04);
135  mg->GetHistogram()->GetXaxis()->SetLabelFont(80);
136  mg->GetHistogram()->GetYaxis()->SetLabelFont(82);
137  mg->GetHistogram()->GetYaxis()->SetLabelOffset(0.01);
138  mg->GetHistogram()->GetYaxis()->SetTitleOffset(1.5);
139 
140  if(range_fix) {
141  mg->GetHistogram()->GetXaxis()->SetRangeUser(16,8*1024);
142  mg->GetHistogram()->GetYaxis()->SetRangeUser(5e-24,1e-21);
143  }
144 
145  mg->GetXaxis()->SetLabelFont(22);
146  mg->GetYaxis()->SetLabelFont(22);
147  mg->GetXaxis()->SetTitleFont(22);
148  mg->GetYaxis()->SetTitleFont(22);
149  mg->GetXaxis()->SetTitleSize(0.03);
150  mg->GetYaxis()->SetTitleSize(0.03);
151  mg->GetXaxis()->SetTitle("Frequency (Hz)");
152  mg->GetYaxis()->SetTitle("#frac{1}{#sqrt{Hz}}");
153  mg->Draw("APL");
154 
155  if(save_plot) {
156  TString ofname(ifname);
157  ofname.ReplaceAll(".txt",".gif");
158  cout << ofname.Data() << endl;
159  canvas->Print(ofname.Data());
160  char cmd[256];
161  TString pfname(ofname);
162  pfname.ReplaceAll(".gif",".png");
163  sprintf(cmd,"convert %s %s",ofname.Data(),pfname.Data());
164  cout << cmd << endl;
165  gSystem->Exec(cmd);
166  sprintf(cmd,"rm %s",ofname.Data());
167  cout << cmd << endl;
168  gSystem->Exec(cmd);
169  exit(0);
170  }
171 }
TString("c")
TCanvas * canvas
void cwb_draw_sensitivity(TString ifname="", bool save_plot=false, bool range_fix=true)
Long_t size
char str[1024]
wavearray< double > freq
Definition: Regression_H1.C:79
TGraph * gr
TObjArray * token
double e
char title[256]
Definition: SSeriesExample.C:1
ifstream in
char cmd[1024]
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
TMultiGraph * mg
exit(0)