Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 1000000
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  in >> sfile >> stitle;
78  if(!in.good()) break;
79  if(sfile[0]=='#') continue;
80  ifile[NPSD]=sfile;
81  ltitle[NPSD]=stitle;
82  cout << NPSD+1 << " " << ifile[NPSD] << " " << ltitle[NPSD] << endl;
83  NPSD++;
84  }
85  in.close();
86 
87  // Read PSD files
88 
89  double freq[MAX_PSD][MAX_SIZE];
90  double psd[MAX_PSD][MAX_SIZE];
91  int lenght[MAX_PSD];
92 
93  for(int i=0;i<NPSD;i++) {
94  ifstream in;
95  in.open(ifile[i].Data(),ios::in);
96  if (!in.good()) {cout << "Error Opening File : " << ifile[i].Data() << endl;exit(1);}
97  lenght[i]=0;
98  while (1) {
99  double F,S;
100  in >> F >> S;
101  if (!in.good()) break;
102  if(S!=0) {
103  freq[i][lenght[i]]=F;
104  psd[i][lenght[i]]=S;
105  lenght[i]++;
106  }
107  }
108  in.close();
109  }
110 
111  // create plots
112 
113  // remove the red box around canvas
114  gStyle->SetFrameBorderMode(0);
115  gROOT->ForceStyle();
116 
117  gStyle->SetTitleFont(72);
118  gStyle->SetMarkerColor(50);
119  gStyle->SetLineColor(kWhite);
120  gStyle->SetTitleW(0.98);
121  gStyle->SetTitleH(0.05);
122  gStyle->SetTitleY(0.98);
123  gStyle->SetFillColor(kWhite);
124  gStyle->SetLineColor(kWhite);
125  gStyle->SetTitleFont(12,"D");
126 
127  Color_t colors[MAX_PSD] = { kBlue, kBlack, kRed, 6, 3, 8, 43, 7, 8, 4};
128  int lstyle[MAX_PSD] = {2, 0, 0, 0, 9, 9, 9, 2, 2, 2};
129 
130 
131  TCanvas *canvas = new TCanvas("Sensitivity", "psd", 300,40, 1000, 600);
132  canvas->Clear();
133  canvas->ToggleEventStatus();
134  canvas->SetLogx();
135  canvas->SetLogy();
136  canvas->SetGridx();
137  canvas->SetGridy();
138  canvas->SetFillColor(kWhite);
139 
140  TGraph* gr[MAX_PSD];
141  for(int n=0;n<NPSD;n++) gr[n] = new TGraph(lenght[n],freq[n],psd[n]);
142  for(int n=0;n<NPSD;n++) {
143  gr[n]->SetLineWidth(3);
144  gr[n]->SetMarkerColor(colors[n]);
145  gr[n]->SetLineColor(colors[n]);
146  }
147 
148  TMultiGraph* mg = new TMultiGraph();
149  mg->SetTitle("Sensitivity Curves");
150  if(title!="") mg->SetTitle(title.Data());
151  for(int n=0;n<NPSD;n++) mg->Add(gr[n]);
152  mg->Paint("APL");
153 
154  mg->GetHistogram()->GetXaxis()->SetLabelSize(0.04);
155  mg->GetHistogram()->GetYaxis()->SetLabelSize(0.04);
156  mg->GetHistogram()->GetXaxis()->SetTitleSize(0.04);
157  mg->GetHistogram()->GetYaxis()->SetTitleSize(0.04);
158  mg->GetHistogram()->GetXaxis()->SetLabelFont(42);
159  mg->GetHistogram()->GetYaxis()->SetLabelFont(42);
160  mg->GetHistogram()->GetYaxis()->SetLabelOffset(0.01);
161  mg->GetHistogram()->GetYaxis()->SetTitleOffset(1.5);
162 
163  if(min_freq>=0 && max_freq>min_freq)
164  mg->GetHistogram()->GetXaxis()->SetRangeUser(min_freq,max_freq);
165  if(min_strain>=0 && max_freq>min_strain)
166  mg->GetHistogram()->GetYaxis()->SetRangeUser(min_strain,max_strain);
167 
168  mg->GetXaxis()->SetTitle(gr[0]->GetXaxis()->GetTitle());
169  mg->GetXaxis()->SetLabelFont(42);
170  mg->GetYaxis()->SetLabelFont(42);
171  mg->GetXaxis()->SetTitleFont(42);
172  mg->GetYaxis()->SetTitleFont(42);
173  mg->GetXaxis()->SetTitleOffset(1.20);
174  mg->GetYaxis()->SetTitleOffset(1.22);
175  mg->GetXaxis()->SetTitleSize(0.04);
176  mg->GetYaxis()->SetTitleSize(0.04);
177  mg->GetXaxis()->SetTitle("Frequency (Hz) ");
178  mg->GetYaxis()->SetTitle("#frac{1}{#sqrt{Hz}} ");
179 
180  mg->Draw("APL");
181 
182  // draw the legend
183 
184  TLegend* leg;
185  double hleg = 0.8-NPSD*0.05;
186  leg = new TLegend(0.6120401,hleg,0.9615385,0.8721805,NULL,"brNDC");
187 
188  leg->SetBorderSize(1);
189  leg->SetTextAlign(22);
190  leg->SetTextFont(12);
191  leg->SetLineColor(1);
192  leg->SetLineStyle(1);
193  leg->SetLineWidth(1);
194  leg->SetFillColor(0);
195  leg->SetFillStyle(1001);
196  leg->SetTextSize(0.04);
197  leg->SetLineColor(kBlack);
198  leg->SetFillColor(kWhite);
199 
200  for(int n=0;n<NPSD;n++) {
201  char legLabel[256];
202  sprintf(legLabel,"%s",ltitle[n].Data());
203  leg->AddEntry(gr[n],legLabel,"lp");
204  }
205  leg->Draw();
206 
207  // save plot
208 
209  if(ofName!="") {
210  TString gfileName=ofName;
211  canvas->Print(gfileName);
212  TString pfileName=gfileName;
213  pfileName.ReplaceAll(".gif",".png");
214  char cmd[1024];
215  sprintf(cmd,"convert %s %s",gfileName.Data(),pfileName.Data());
216  cout << cmd << endl;
217  gSystem->Exec(cmd);
218  sprintf(cmd,"rm %s",gfileName.Data());
219  cout << cmd << endl;
220  gSystem->Exec(cmd);
221  }
222 }
223 
TString ofName
#define MAX_PSD
char cmd[1024]
int n
Definition: cwb_net.C:10
TString("c")
TLegend * leg
Definition: compare_bkg.C:246
wavearray< double > psd(33)
return wmap canvas
Long_t size
Color_t colors[16]
i drho i
char str[1024]
TGraph * gr
double F
TFile * ifile
char title[256]
Definition: SSeriesExample.C:1
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]")
Definition: slag.C:91
ifstream in
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)