Logo coherent WaveBurst  
Library Reference Guide
Logo
DrawSensitivities.C
Go to the documentation of this file.
1 //
2 // Draw Detector Sensitivity Curves
3 // Author : Gabriele Vedovato
4 //
5 // how to use it
6 // root -l 'DrawSensitivities.C("strain_psd.lst")'
7 //
8 // strain_psd.lst format
9 //
10 // strain psd file name title
11 // ../plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt advLIGO_NSNS_Opt
12 //../plugins/strains/AdV_May2010.txt AdV_May2010
13 //
14 
15 #define MAX_PSD 10
16 #define MAX_SIZE 10000
17 
18 void DrawSensitivities(TString ilist_file="", TString ofName="", TString title="",
19  double min_freq=-1, double max_freq=-1, double min_strain=-1, double max_strain=-1) {
20 
21  if(ilist_file=="") {
22  cout << endl;
23  cout << "-------------------------------------------------------------------------" << endl;
24  cout << "HOW TO USE : " << endl;
25  cout << "-------------------------------------------------------------------------" << endl;
26  cout << endl;
27  cout << "root 'DrawSensitivities(\"list_of_strain_psd_file_names.txt\",\"otput_psd_file_name.png\", \\"<< endl;
28  cout << " \"psd_title\", min_freq, max_freq, min_strain, max_strain)" << endl;
29  cout << endl;
30  cout << "only list_of_strain_psd_file_names.txt is mandatory" << endl;
31  cout << "if list_of_strain_psd_file_names.txt=\"\" then print this help" << endl;
32  cout << endl;
33  cout << "-------------------------------------------------------------------------" << endl;
34  cout << "this is the strain_psd.lst format" << endl;
35  cout << "strain psd file name (list of freq & strain) title" << endl;
36  cout << "-------------------------------------------------------------------------" << endl;
37  cout << endl;
38  cout << "../plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt advLIGO_NSNS_Opt" << endl;
39  cout << "plugins/strains/AdV_May2010.txt AdV_May2010" << endl;
40  cout << endl;
41  exit(1);
42  }
43 
44  if((ofName!="")&&(!ofName.Contains(".png"))) {
45  cout << "Error Outpu File : " << ilist_file.Data() << endl;
46  cout << "Must have .png extension" << endl;
47  exit(1);
48  } else {
49  ofName.ReplaceAll(".png",".gif");
50  }
51 
52 
54  TString ltitle[MAX_PSD];
55 
56  // Read PSD file list
57  ifstream in;
58  in.open(ilist_file.Data(),ios::in);
59  if (!in.good()) {cout << "Error Opening File : " << ilist_file.Data() << endl;exit(1);}
60 
61  int size=0;
62  char str[1024];
63  int fpos=0;
64  while(true) {
65  in.getline(str,1024);
66  if (!in.good()) break;
67  if(str[0] != '#') size++;
68  }
69  in.clear(ios::goodbit);
70  in.seekg(0, ios::beg);
71  if (size==0) {cout << "Error : File " << ilist_file.Data() << " is empty" << endl;exit(1);}
72 
73  char sfile[256];
74  char stitle[256];
75  int NPSD=0;
76  while(true) {
77  fpos=in.tellg();
78  in.getline(str,1024);
79  if(str[0] == '#') continue;
80  in.seekg(fpos, ios::beg);
81 
82  in >> sfile >> stitle;
83  if(!in.good()) break;
84 
85  if(NPSD>=MAX_PSD) {cout << "Error - Input Files exceed MAX_PSD " << MAX_PSD << endl;exit(1);}
86  ifile[NPSD]=sfile;
87  ltitle[NPSD]=stitle;
88  cout << NPSD+1 << " " << ifile[NPSD] << " " << ltitle[NPSD] << endl;
89  NPSD++;
90 
91  fpos=in.tellg();
92  in.seekg(fpos+1, ios::beg);
93  }
94  in.close();
95 
96  // Read PSD files
97 
98  double freq[MAX_PSD][MAX_SIZE];
99  double psd[MAX_PSD][MAX_SIZE];
100  int lenght[MAX_PSD];
101 
102  for(int i=0;i<NPSD;i++) {
103  ifstream in;
104  in.open(ifile[i].Data(),ios::in);
105  if (!in.good()) {cout << "Error Opening File : " << ifile[i].Data() << endl;exit(1);}
106  lenght[i]=0;
107  while (1) {
108  double F,S;
109  in >> F >> S;
110  if (!in.good()) break;
111  if(S!=0) {
112  freq[i][lenght[i]]=F;
113  psd[i][lenght[i]]=S;
114  lenght[i]++;
115  }
116  if(lenght[i]>=MAX_SIZE) {cout << "Error size " << ifile[i].Data() << " > MAX_SIZE = " << MAX_SIZE << endl;exit(1);}
117  }
118  in.close();
119  }
120 
121  // create plots
122 
123  // remove the red box around canvas
124  gStyle->SetFrameBorderMode(0);
125  gROOT->ForceStyle();
126 
127  gStyle->SetTitleFont(72);
128  gStyle->SetMarkerColor(50);
129  gStyle->SetLineColor(kWhite);
130  gStyle->SetTitleW(0.98);
131  gStyle->SetTitleH(0.05);
132  gStyle->SetTitleY(0.98);
133  gStyle->SetFillColor(kWhite);
134  gStyle->SetLineColor(kWhite);
135  gStyle->SetTitleFont(12,"D");
136 
137  Color_t colors[MAX_PSD] = { kBlue, kBlack, kRed, 6, 3, 8, 43, 7, 8, 4};
138  int lstyle[MAX_PSD] = {2, 0, 0, 0, 9, 9, 9, 2, 2, 2};
139 
140 
141  TCanvas *canvas = new TCanvas("Sensitivity", "psd", 300,40, 1000, 600);
142  canvas->Clear();
143  canvas->ToggleEventStatus();
144  canvas->SetLogx();
145  canvas->SetLogy();
146  canvas->SetGridx();
147  canvas->SetGridy();
148  canvas->SetFillColor(kWhite);
149 
150  TGraph* gr[MAX_PSD];
151  for(int n=0;n<NPSD;n++) gr[n] = new TGraph(lenght[n],freq[n],psd[n]);
152  for(int n=0;n<NPSD;n++) {
153  gr[n]->SetLineWidth(3);
154  gr[n]->SetMarkerColor(colors[n]);
155  gr[n]->SetLineColor(colors[n]);
156  }
157 
158  TMultiGraph* mg = new TMultiGraph();
159  mg->SetTitle("Sensitivity Curves");
160  if(title!="") mg->SetTitle(title.Data());
161  for(int n=0;n<NPSD;n++) mg->Add(gr[n]);
162  mg->Paint("APL");
163 
164  mg->GetHistogram()->GetXaxis()->SetLabelSize(0.04);
165  mg->GetHistogram()->GetYaxis()->SetLabelSize(0.04);
166  mg->GetHistogram()->GetXaxis()->SetTitleSize(0.04);
167  mg->GetHistogram()->GetYaxis()->SetTitleSize(0.04);
168  mg->GetHistogram()->GetXaxis()->SetLabelFont(42);
169  mg->GetHistogram()->GetYaxis()->SetLabelFont(42);
170  mg->GetHistogram()->GetYaxis()->SetLabelOffset(0.01);
171  mg->GetHistogram()->GetYaxis()->SetTitleOffset(1.5);
172 
173  if(min_freq>=0 && max_freq>min_freq)
174  mg->GetHistogram()->GetXaxis()->SetRangeUser(min_freq,max_freq);
175  if(min_strain>=0 && max_freq>min_strain)
176  mg->GetHistogram()->GetYaxis()->SetRangeUser(min_strain,max_strain);
177 
178  mg->GetXaxis()->SetTitle(gr[0]->GetXaxis()->GetTitle());
179  mg->GetXaxis()->SetLabelFont(42);
180  mg->GetYaxis()->SetLabelFont(42);
181  mg->GetXaxis()->SetTitleFont(42);
182  mg->GetYaxis()->SetTitleFont(42);
183  mg->GetXaxis()->SetTitleOffset(1.20);
184  mg->GetYaxis()->SetTitleOffset(1.22);
185  mg->GetXaxis()->SetTitleSize(0.04);
186  mg->GetYaxis()->SetTitleSize(0.04);
187  mg->GetXaxis()->SetTitle("Frequency (Hz) ");
188  mg->GetYaxis()->SetTitle("#frac{1}{#sqrt{Hz}} ");
189 
190  mg->Draw("APL");
191 
192  // draw the legend
193 
194  TLegend* leg;
195  double hleg = 0.8-NPSD*0.05;
196  leg = new TLegend(0.6120401,hleg,0.9615385,0.8721805,NULL,"brNDC");
197 
198  leg->SetBorderSize(1);
199  leg->SetTextAlign(22);
200  leg->SetTextFont(12);
201  leg->SetLineColor(1);
202  leg->SetLineStyle(1);
203  leg->SetLineWidth(1);
204  leg->SetFillColor(0);
205  leg->SetFillStyle(1001);
206  leg->SetTextSize(0.04);
207  leg->SetLineColor(kBlack);
208  leg->SetFillColor(kWhite);
209 
210  for(int n=0;n<NPSD;n++) {
211  char legLabel[256];
212  sprintf(legLabel,"%s",ltitle[n].Data());
213  leg->AddEntry(gr[n],legLabel,"lp");
214  }
215  leg->Draw();
216 
217  // save plot
218 
219  if(ofName!="") {
220  TString gfileName=ofName;
221  canvas->Print(gfileName);
222  TString pfileName=gfileName;
223  pfileName.ReplaceAll(".gif",".png");
224  char cmd[1024];
225  sprintf(cmd,"convert %s %s",gfileName.Data(),pfileName.Data());
226  cout << cmd << endl;
227  gSystem->Exec(cmd);
228  sprintf(cmd,"rm %s",gfileName.Data());
229  cout << cmd << endl;
230  gSystem->Exec(cmd);
231  }
232 }
233 
TString ofName
#define MAX_PSD
int n
Definition: cwb_net.C:28
TString("c")
wavearray< double > psd(33)
return wmap canvas
Long_t size
Color_t colors[16]
i drho i
char str[1024]
wavearray< double > freq
Definition: Regression_H1.C:79
TGraph * gr
cout<<"Number of Entries: "<< num<< endl;double *slag1=new double[slag_entries];slag1=wave.GetV1();double *slag2=new double[slag_entries];slag2=wave.GetV2();char mytitle[256];double SlagMax=wave.GetMaximum("slag")+segLen/2.;double SlagMin=wave.GetMinimum("slag") -segLen/2.;int NSlag=TMath::FloorNint((SlagMax-SlagMin)/segLen);cout<< "SLAG MAX : "<< wave.GetMaximum("slag")<< " s SLAG MIN : "<< wave.GetMinimum("slag")<< " s #SLAGS : "<< NSlag-1<< endl;if(NSlag==1){cout<<"Just one slag....Skipping further execution!"<< endl;exit(0);} sprintf(mytitle,"FAR distribution over slags (post cat3 & rho>%f)", T_cut);TH2F *Slag=new TH2F("SLAG", mytitle, NSlag, SlagMin/86400., SlagMax/86400., NSlag, SlagMin/86400., SlagMax/86400.);Slag-> GetXaxis() -> SetTitle("slag[1] shift [day]")
double F
TFile * ifile
char title[256]
Definition: SSeriesExample.C:1
ifstream in
char cmd[1024]
Meyer< double > S(1024, 2)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
void DrawSensitivities(TString ilist_file="", TString ofName="", TString title="", double min_freq=-1, double max_freq=-1, double min_strain=-1, double max_strain=-1)
#define MAX_SIZE
TMultiGraph * mg
exit(0)