Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_mkhtml_sim.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 // make the html simulation report : used by the cwb_report command
20 {
21 
22  #define NMDC_MAX 64
23 
24  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
25  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
26  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
27  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_PPARAMETERS_FILE"));
28  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_UPPARAMETERS_FILE"));
29  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_EPPARAMETERS_FILE"));
30 
31  // initialize the ifo name (takes into account the non built-in detectors)
33  for(int n=0;n<nIFO;n++) {
34  if(strlen(ifo[n])!=0) strcpy(IFO[n],ifo[n]); else strcpy(IFO[n],detParms[n].name);
35  }
36 
37  // If fad is enable & simulation==4 & multi=true
38  // FAD multi plot for each mdc set are substituted in the sim report
39  // page to the eff_freq plots
40  TString pp_fad_multi = "FALSE";
41  if(pp_fad!="" && simulation==4) {
42  // get multi parameter from pp_fad
43  pp_fad_multi = CWB::Toolbox::getParameter(pp_fad,"--multi");
44  if(pp_fad_multi=="") pp_fad_multi="false";
45  pp_fad_multi.ToUpper();
46  }
47 
48  // read injection file types
49  char imdc_set[NMDC_MAX][128]; // injection set
50  size_t imdc_type[NMDC_MAX]; // injection type
51  char imdc_name[NMDC_MAX][128]; // injection name
52  double imdc_fcentral[NMDC_MAX]; // injection central frequencies
53  double imdc_fbandwidth[NMDC_MAX]; // injection bandwidth frequencies
54  size_t imdc_index[NMDC_MAX]; // type reference array
55  size_t imdc_iset[NMDC_MAX]; // injection set index
56 
57  int ninj=ReadInjType(mdc_inj_file,NMDC_MAX,imdc_set,imdc_type,
58  imdc_name,imdc_fcentral,imdc_fbandwidth);
59  if(ninj==0) {cout << "cwb_mkhtml_sim.C : Error - no injection - terminated" << endl;exit(1);}
60 
62  int nset=0;
63  for(int i=0;i<ninj;i++) {
64  bool bnew=true;
65  for(int j=0;j<nset;j++) if(imdc_set[i]==imdc_set_name[j]) bnew=false;
66  if(bnew) imdc_set_name[nset++]=imdc_set[i];
67  }
68  cout << "nset : " << nset << endl;
69 
70  // copy injection file list mdc types to report data dir
71 
72  char cmd[1024];
73  sprintf(cmd,"cp %s %s/%s/injectionList.txt",mdc_inj_file,pp_dir,pp_data_dir);
74  cout << cmd << endl;
75  gSystem->Exec(cmd);
76 
77  // create body.html file
78 
83 
84  ofstream out;
85  char fileout[256];
86  sprintf(fileout,"%s/body.html", pp_dir);
87  cout << fileout << endl;
88  out.open(fileout,ios::out);
89  if (!out.good()) {cout << "cwb_mkhtml_sim.C : Error Opening File : " << fileout << endl;exit(1);}
90 
91  // if CWB_DOC_URL is define then man infos are added to web pages
93  if(gSystem->Getenv("CWB_DOC_URL")!=NULL) {
94  cwb_doc_url=TString(gSystem->Getenv("CWB_DOC_URL"));
95  }
96 
97  out << "<hr>" << endl;
98  char plot_list[1024];
99  sprintf(plot_list,"<a target=\"_parent\" name=\"Full Plot List\" href=\"%s\"><h3>Full Plot List</h3></a>",pp_data_dir);
100  if(cwb_doc_url!="") out<<"<table width=100%> <tr> <td align=\"left\">"<<endl;
101  out << plot_list << endl;
102  if(cwb_doc_url!="") {
103  out<<"</td>"<<endl;
104  out<<"<td align=\"right\">"<<endl;
105  out<<"<a target=\"_parent\" href=\""<<cwb_doc_url.Data()
106  <<"/cwb/man/Simulation-part.html#Simulation-part\">infos</a>"<<endl;
107  out<<"</td> </tr> </table>"<<endl;
108  }
109 
110  // read evt_parameters_ALL.txt
111  char evt_par_fname[2048];
112  ifstream in_evt_par;
113  sprintf(evt_par_fname,"%s/evt_parameters_ALL.txt",PP_DATA_PATH.Data());
114  in_evt_par.open(evt_par_fname,ios::in);
115  if(!in_evt_par.good())
116  {cout << "cwb_mkhtml_sim.C : Error Opening File : " << evt_par_fname << endl;exit(1);}
117  int epar_id;
118  TString epar_mdc_name;
119  float f_mean,f_rms,t_mean,t_rms;
120  TString EPAR_MDC_NAME[NMDC_MAX];
121  float F_MEAN[NMDC_MAX],T_RMS[NMDC_MAX];
122  int ecnt=0;
123  while (1) {
124  in_evt_par >> epar_id >> epar_mdc_name >> f_mean >> f_rms >> t_mean >> t_rms;
125  if (!in_evt_par.good()) break;
126  EPAR_MDC_NAME[ecnt]=epar_mdc_name;
127  F_MEAN[ecnt]=f_mean;
128  T_RMS[ecnt]=t_rms;
129  cout << "EVT_PAR : " << EPAR_MDC_NAME[ecnt] << " " << F_MEAN[ecnt] << " " << T_RMS[ecnt] << endl;
130  ecnt++;
131  }
132  in_evt_par.close();
133 
134  char outwrite[2048];
135  char file[2048];
136  for (int iset=0;iset<nset;iset++) {
137 
138  cout << "MDC Set: " << iset << " " << endl;
139  char th_psfix[256];
140  sprintf(th_psfix,"_%d_%d",int(T_cor*100),int(T_cut*10));
141  //TString threshold(th_psfix);
142  TString threshold("");
143  cout << "DIR: " << PP_DATA_PATH.Data() << endl;
144 
145 /* ?
146  char file_fit[2048];
147  ofstream out_fit;
148  sprintf(file_fit,"%s/fit_parameters_%s.txt",PP_DATA_PATH.Data(),threshold.Data());
149  out_fit.open(file_fit,ios::out);
150  int set_count=0;
151 */
152 
153  cout << imdc_set_name[iset].Data() << endl;
154  char file[256];
155  sprintf(file,"%s/fit_parameters_%s%s.txt",PP_DATA_PATH.Data(),imdc_set_name[iset].Data(),threshold.Data());
156  cout << file << endl;
157  ifstream simin_hb;
158  simin_hb.open(file,ios::in);
159  if (!simin_hb.good()) {cout << "cwb_mkhtml_sim.C : Error Opening File : " << file << endl;exit(1);}
160  int hb_count;
161  TString hb_piumeno, hb_temp_wave;
162  float hb_chi2, hb_err, hb_par1, hb_par2, hb_par3;
163  double hb_hrss10[NMDC_MAX], hb_hrss50[NMDC_MAX], hb_hrss90[NMDC_MAX];
164  TF1* gfit;
165  TString hb_waveform[NMDC_MAX];
166  for (int i=0; i<NMDC_MAX; i++) {
167  hb_hrss10[i]=0;
168  hb_hrss50[i]=0;
169  hb_hrss90[i]=0;
170  hb_waveform[i]="";
171  }
172  int maxcount=0;
173  while (1) {
174  simin_hb >> hb_count >> hb_chi2 >> hb_hrss50[maxcount] >> hb_piumeno
175  >> hb_err >> hb_par1 >> hb_par2 >> hb_par3 >> hb_temp_wave;
176  if (!simin_hb.good()) break;
177  hb_waveform[maxcount]=(TString)hb_temp_wave;
178 /* ?
179  out_fit << " " << set_count << " " << hb_chi2 << " " << hb_hrss50[maxcount]
180  << " " << hb_piumeno << " " << hb_err << " " << hb_par1 << " "
181  << hb_par2 << " " << hb_par3 << " " << hb_temp_wave << endl;
182  set_count++;
183 */
184  double inf = simulation==2 ? log10(factors[0]/2.) : -23;
185  double sup = simulation==2 ? log10(2.*factors[nfactor-1]) : -18.5;
186 
187  if(simulation==1 && pp_factor2distance) {
188  inf = log10(pp_factor2distance/factors[nfactor-1]);
189  sup = log10(pp_factor2distance/factors[0]);
190  }
191 
192  double par0=TMath::Log10(hb_hrss50[maxcount]);
193  gfit = new TF1("logNfit",logNfit,pow(10.0,inf),pow(10.0,sup),5);
194  gfit->SetNpx(100000);
195  gfit->SetParameters(par0,hb_par1,hb_par2,hb_par3,pp_factor2distance);
196  hb_hrss10[maxcount]=gfit->GetX(.1,pow(10.0,inf),pow(10.0,sup));
197  hb_hrss90[maxcount]=gfit->GetX(.9,pow(10.0,inf),pow(10.0,sup));
198  if(gfit->Eval(hb_hrss90[maxcount])<0.89) hb_hrss90[maxcount]=-1;
199  maxcount++;
200  }
201 
202  // table title
203  out << "<font color=\"red\" style=\"font-weight:bold;\">"" <center>\t<p><h2>Detection efficiency for injections "
204  << imdc_set_name[iset].Data() << "</h2>\t<p><center></font>" << endl;
205  out <<"<table cellspacing=\"0\" cellpadding=\"6\" border=\"1\" align=\"center\">" << endl;
206 
207  // table row 1 (description)
208  out <<"<tr align=\"center\">"<<endl;
209 /* ?
210  sprintf(file,"%s/fit_parameters_%s.txt",PP_DATA_DIR.Data(),threshold.Data());
211 */
212  sprintf(file,"%s/fit_parameters_%s.txt",PP_DATA_DIR.Data(),imdc_set_name[iset].Data());
213  out <<"<th colspan=\"4\"><a target=\"_parent\" href="<<file<<">fit pararameter</a></th>"<<endl;
214  if(pp_fad_multi=="FALSE") {
215  if(pp_factor2distance) {
216  out <<"<th colspan=\""<<nIFO+4<<"\">distance vs frequency</th>"<<endl;
217  } else {
218  out <<"<th colspan=\""<<nIFO+4<<"\">efficiency vs frequency</th>"<<endl;
219  }
220  } else {
221  out <<"<th colspan=\""<<nIFO+4<<"\">False Alarm Density vs rho</th>"<<endl;
222  }
223  out <<"</tr>"<<endl;
224 
225  // table row 2 (figures)
226  out<<"<tr align=\"center\">"<<endl;
227  sprintf(outwrite,
228  "<td colspan=\"4\" align=\"center\"><a target=\"_parent\" href=\"%s/eff_%s%s.gif\"><img src=\"%s/eff_%s%s.gif\" height=300></a></td>",
229  PP_DATA_DIR.Data(),imdc_set_name[iset].Data(),threshold.Data(),PP_DATA_DIR.Data(),imdc_set_name[iset].Data(),threshold.Data());
230  out << outwrite << endl;
231  if(pp_fad_multi=="FALSE") {
232  sprintf(outwrite,
233  "<td colspan=\"%d\" align=\"center\"><a target=\"_parent\" href=\"%s/eff_freq_%s.gif\"><img src=\"%s/eff_freq_%s.gif\" height=300></a></td>",
234  nIFO+4,PP_DATA_DIR.Data(),imdc_set_name[iset].Data(),PP_DATA_DIR.Data(),imdc_set_name[iset].Data());
235  } else {
236  sprintf(outwrite,
237  "<td colspan=\"%d\" align=\"center\"><a target=\"_parent\" href=\"%s/../fad/fad_rho_%s.gif\"><img src=\"%s/../fad/fad_rho_%s.gif\" height=300></a></td>",
238  nIFO+4,PP_DATA_DIR.Data(),imdc_set_name[iset].Data(),PP_DATA_DIR.Data(),imdc_set_name[iset].Data());
239  }
240  out << outwrite << endl;
241  out<<"</tr>"<<endl;
242 
243  // table row 3 (mdc_name/hrss10%/hrss50%/hrss90%/ifo_hrss_nre/time/freq/eff titles)
244  out<<"<tr align=\"center\">"<<endl;
245  out <<"<td> waveform </td>"<<endl;
246  if(simulation==1 && pp_factor2distance) {
247  out <<"<td> distance@10% </td>"<<endl;
248  out <<"<td> distance@50% </td>"<<endl;
249  out <<"<td> distance@90% </td>"<<endl;
250  } else if(simulation==2) {
251  out <<"<td> snr@10% </td>"<<endl;
252  out <<"<td> snr@50% </td>"<<endl;
253  out <<"<td> snr@90% </td>"<<endl;
254  } else {
255  out <<"<td> hrss@10% </td>"<<endl;
256  out <<"<td> hrss@50% </td>"<<endl;
257  out <<"<td> hrss@90% </td>"<<endl;
258  }
259  for (int nn=0;nn<nIFO;nn++) out << "<th>"<<IFO[nn]<<"</th>"<<endl;
260  out<<"<th>time (rms)</th>"<<endl;
261  out<<"<th>freq (mean)</th>"<<endl;
262  out<<"<th>eff</th>"<<endl;
263  out<<"</tr>"<<endl;
264 
265  // table row 4 (mdc_name/hrss10%/hrss50%/hrss90% values)
266  out<<"<tr align=\"center\">"<<endl;
267 
268  sprintf(outwrite,"<td>%s",hb_waveform[0].Data()); out << outwrite << endl;
269  for (int i=1; i<maxcount; i++) {
270  sprintf(outwrite,"<br>%s",hb_waveform[i].Data()); out << outwrite << endl;
271  }
272  out<<"</td>"<<endl;
273 
274  if(pp_show_eff_fit_curve) { // write hrss@10/50/90 from efficiency fits
275 
276  sprintf(outwrite,"<td> %.2e",hb_hrss10[0]); out << outwrite << endl;
277  for (int i=1; i<maxcount; i++) {
278  sprintf(outwrite,"<br>%.2e",hb_hrss10[i]); out << outwrite << endl;
279  }
280  out<<"</td>"<<endl;
281 
282  sprintf(outwrite,"<td> %.2e",hb_hrss50[0]); out << outwrite << endl;
283  for (int i=1; i<maxcount; i++) {
284  sprintf(outwrite,"<br>%.2e",hb_hrss50[i]); out << outwrite << endl;
285  }
286  out<<"</td>"<<endl;
287 
288  if(hb_hrss90[0]>0) {
289  sprintf(outwrite,"<td> %.2e",hb_hrss90[0]); out << outwrite << endl;
290  } else {
291  sprintf(outwrite,"<td> NA"); out << outwrite << endl;
292  }
293  for (int i=1; i<maxcount; i++) {
294  if(hb_hrss90[i]>0) {
295  sprintf(outwrite,"<br>%.2e",hb_hrss90[i]); out << outwrite << endl;
296  } else {
297  sprintf(outwrite,"<br>NA"); out << outwrite << endl;
298  }
299  }
300  out<<"</td>"<<endl;
301 
302  } else { // write blanck spaces
303 
304  for(int k=0;k<3;k++) {
305  out << "<td> " << endl;
306  for (int i=1; i<maxcount; i++) out << "<br>" << endl;
307  out<<"</td>"<<endl;
308  }
309  }
310 
311  // table row 4 (ifo_hrss_nre/time/freq/eff links)
312  for (int nn=0;nn<nIFO;nn++) {
313  out << "<td>" << endl;
314  for (int i=0; i<maxcount; i++) {
315  sprintf(outwrite,"<a target=\"_parent\" href=\"%s/hrss_%s_%s.gif\">hrss</a> / ",
316  PP_DATA_DIR.Data(),IFO[nn],hb_waveform[i].Data());
317  sprintf(outwrite,"%s<a target=\"_parent\" href=\"%s/nre_%s_%s.gif\">nre</a><br>",
318  outwrite,PP_DATA_DIR.Data(),IFO[nn],hb_waveform[i].Data());
319  out << outwrite << endl;
320  }
321  out << "</td>" << endl;
322  }
323 
324  out << "<td align=\'right\'>" << endl;
325  for (int i=0; i<maxcount; i++) {
326  int ik=0;for(int k=0;k<ecnt;k++) if(EPAR_MDC_NAME[k]==hb_waveform[i]) ik=k;
327  sprintf(outwrite,"<a target=\"_parent\" href=\"%s/t_%s.gif\">%3.1f ms</a><br>",
328  PP_DATA_DIR.Data(),hb_waveform[i].Data(),1000*T_RMS[ik]);
329  out << outwrite << endl;
330  }
331  out << "</td>" << endl;
332 
333  out << "<td align=\'right\'>" << endl;
334  for (int i=0; i<maxcount; i++) {
335  int ik=0;for(int k=0;k<ecnt;k++) if(EPAR_MDC_NAME[k]==hb_waveform[i]) ik=k;
336  sprintf(outwrite,"<a target=\"_parent\" href=\"%s/f_%s.gif\">%3.2f Hz</a><br>",
337  PP_DATA_DIR.Data(),hb_waveform[i].Data(),F_MEAN[ik]);
338  out << outwrite << endl;
339  }
340  out << "</td>" << endl;
341 
342  out << "<td>" << endl;
343  for (int i=0; i<maxcount; i++) {
344  sprintf(outwrite,"<a target=\"_parent\" href=\"%s/%s.gif\">plot</a> / ",
345  PP_DATA_DIR.Data(),hb_waveform[i].Data());
346  out << outwrite << endl;
347 
348  sprintf(outwrite,"<a target=\"_parent\" href=\"%s/eff_%s.txt\">txt</a><br>",
349  PP_DATA_DIR.Data(),hb_waveform[i].Data());
350  out << outwrite << endl;
351  }
352  out << "</td>" << endl;
353 
354  out << "</tr>" << endl;
355 
356  out << "</table>" << endl;
357 /* ?
358  out_fit.close();
359 */
360 
361  out << "<p>" << endl;
362  out << endl;
363  }
364  out.close();
365  exit(0);
366 }
367 
TString cwb_doc_url
int ninj
par [0] name
int n
Definition: cwb_net.C:28
char fileout[256]
TString("c")
size_t imdc_type[NMDC_MAX]
double T_cor
TString PP_DATA_PATH
int j
Definition: cwb_net.C:28
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
char IFO[NIFO_MAX][NMDC_MAX]
TString * imdc_set_name
#define NMDC_MAX
char ifo[NIFO_MAX][8]
#define nIFO
int nset
char mdc_inj_file[1024]
Definition: cwb_dump_inj.C:98
double imdc_fcentral[NMDC_MAX]
size_t imdc_iset[NMDC_MAX]
char netdir[1024]
const int NIFO_MAX
Definition: wat.hh:22
ofstream out
char imdc_name[NMDC_MAX][128]
TString pp_fad_multi
int k
double imdc_fbandwidth[NMDC_MAX]
int ReadInjType(TString ifName, int ntype_max, char set[][128], size_t type[], char name[][128], double fcentral[], double fbandwidth[])
Definition: Toolfun.hh:816
TString PP_DATA_DIR
char imdc_set[NMDC_MAX][128]
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:6727
ifstream in
size_t imdc_index[NMDC_MAX]
char pp_dir[512]
Definition: test_config1.C:155
char pp_data_dir[1024]
char cmd[1024]
strcpy(RunLabel, RUN_LABEL)
int nfactor
Definition: test_config1.C:83
double T_cut
simulation
Definition: cwb_eced.C:26
detectorParams detParms[4]
factors[0]
Definition: cwb_eced.C:27
Double_t logNfit(Double_t *x, Double_t *par)
Definition: Toolfun.hh:42
sprintf(netdir,"%s/%s", pp_dir, pp_data_dir)
exit(0)