Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_mkhtml_prod.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 production report : used by the cwb_report command
20 {
21 
22  #define NEPS 28
23  #define NEPS2 19
24 
25  #include "wat.hh"
26 
27  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
28  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
29  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
30  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_PPARAMETERS_FILE"));
31  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_UPPARAMETERS_FILE"));
32  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_EPPARAMETERS_FILE"));
33 
34  bool singleDetector=false;
35  if(nIFO==1) { // Single Detector Mode
37  config.Import();
38  config.SetSingleDetectorMode();
39  config.Export();
40  singleDetector=true;
41  }
42  if(nIFO==2) { // 2 detectors with the same name "same detector -> nIFO=1"
43  if(TString(ifo[0])==TString(ifo[1])) nIFO=1;
44  }
45 
46  // if CWB_DOC_URL is define then man infos are added to web pages
48  if(gSystem->Getenv("CWB_DOC_URL")!=NULL) {
49  cwb_doc_url=TString(gSystem->Getenv("CWB_DOC_URL"));
50  }
51 
52  // check vetoes
53  bool bcat2 = false;
54  bool bhveto = false;
55  bool bcat3 = false;
56 
57  for(int i=0;i<nVDQF;i++) if(VDQF[i].cat==CWB_CAT2) bcat2=true;
58  for(int i=0;i<nVDQF;i++) if(VDQF[i].cat==CWB_HVETO) bhveto=true;
59  for(int i=0;i<nVDQF;i++) if(VDQF[i].cat==CWB_CAT3) bcat3=true;
60 
61  TString NetCC,Rho,RhOut,RhAcor,svED,sPEN,sHRSS,sfLow,sfHigh,sfResample,spp_rho_min,spp_rho_max;
62 
63  char s[16];
64  sprintf(s,"%.2f",T_cor); NetCC=s;
65  sprintf(s,"%.2f",T_cut); Rho=s;
66  sprintf(s,"%.2f",T_out); RhOut=s;
67  sprintf(s,"%.2f",T_acor); RhAcor=s;
68  sprintf(s,"%.2f",T_vED); svED=s;
69  sprintf(s,"%.2f",T_pen); sPEN=s;
70  sprintf(s,"%.2f",fLow); sfLow=s;
71  sprintf(s,"%.2f",fHigh); sfHigh=s;
72  sprintf(s,"%.2f",pp_rho_min); spp_rho_min=s;
73  sprintf(s,"%.2f",pp_rho_max); spp_rho_max=s;
74 
75  TString psfix(data_label);
76  TFile* psp = TFile::Open(net_file_name);
77  cout<<"Opening "<<net_file_name<<endl;
78  TTree* wave_tree = (TTree*)psp->Get("waveburst");
79 
80  // create body.html file
81 
82  ofstream out;
83  char fileout[1024];
84  sprintf(fileout,"%s/body.html", pp_dir);
85  cout << fileout << endl;
86  out.open(fileout,ios::out);
87  if (!out.good()) {cout << "Error Opening File : " << fileout << endl;exit(1);}
88 
91  PP_DATA_PATH=netdir;
93  PP_DATA_DIR=netdir;
94 
96 
97  // convert eps plots to gif plots
98  vector<TString> epsList = CWB::Toolbox::getFileListFromDir(PP_DATA_PATH, ".eps");
99  for(int i=0;i<epsList.size();i++) {
100  TString ofile=epsList[i];
101  ofile.ReplaceAll(".eps",".gif");
102  char cmd[2048];
103  sprintf(cmd,"convert %s %s",epsList[i].Data(),ofile.Data());
104  cout << cmd << endl;
105  gSystem->Exec(cmd);
106  sprintf(cmd,"rm %s",epsList[i].Data());
107  cout << cmd << endl;
108  gSystem->Exec(cmd);
109  }
110 
111  // get livetime
112  char fileliv[1024];
113  sprintf(fileliv,"%s/live.txt",PP_DATA_PATH.Data());
114  cout << fileliv << endl;
115  int countlag=0;
116  double OLIVETIME = GetLiveTime(fileliv,0,0,countlag); // get zero livetime
117  double LIVETIME = GetLiveTime(fileliv,-1,-1,countlag); // get total livetime
118  LIVETIME-=OLIVETIME; // non zero live time
119  countlag-=1; // subtract the zero lag
120  cout.precision(14);
121  cout << OLIVETIME << " " << LIVETIME << endl;
122 
123  ifstream bkgin;
124  bkgin.open(html_body_prod_template,ios::in);
125  if (!bkgin.good()) {cout << "Error Opening File : " << html_body_prod_template << endl;exit(1);}
126 
127  char exec[1024];
128  char istring[1024];
129 
130  while (1) {
131  bkgin.getline(istring,256);
132  if (!bkgin.good()) break;
133  TString ostringa(istring);
134  if(bcat3||bhveto) {
135  ostringa.ReplaceAll("<!--VETO","");
136  ostringa.ReplaceAll("VETO-->","");
137  } else {
138  ostringa.ReplaceAll("<!--NOVETO","");
139  ostringa.ReplaceAll("VETONO-->","");
140  }
141  if(TString(analysis)=="1G") {
142  ostringa.ReplaceAll("<!--RHO_PF","");
143  ostringa.ReplaceAll("RHO_PF-->","");
144  } else {
145  ostringa.ReplaceAll("<!--RHO_SUBNET","");
146  ostringa.ReplaceAll("RHO_SUBNET-->","");
147  }
148  if(pp_rho_vs_rate_no_multiplicity) {
149  ostringa.ReplaceAll("<!--MULTI","");
150  ostringa.ReplaceAll("MULTI-->","");
151  }
152  ostringa.ReplaceAll("FLOW",sfLow);
153  ostringa.ReplaceAll("FHIGH",sfHigh);
154  ostringa.ReplaceAll("PP_RHO_MIN",spp_rho_min);
155  ostringa.ReplaceAll("PP_RHO_MAX",spp_rho_max);
156  ostringa.ReplaceAll("PP_DATA_DIR",PP_DATA_DIR);
157  ostringa.ReplaceAll("NETCC",NetCC);
158  ostringa.ReplaceAll("RHO",Rho);
159  ostringa.ReplaceAll("RH_OUT",RhOut);
160  ostringa.ReplaceAll("RH_ACOR",RhAcor);
161  ostringa.ReplaceAll("svED",svED);
162  TString Rate= "rate = " + RATEBACKGROUND;
163  ostringa.ReplaceAll("RATEBACKGROUND",Rate);
164  ostringa.ReplaceAll("SUBTITLE",subtitle);
165  ostringa.ReplaceAll("TITLE",title);
166  char ltime[1024];
167  sprintf(ltime, "zero lag : <font color=\"red\"> %.2f sec = %.2f days</font>",
168  OLIVETIME,OLIVETIME/86400.);
169  ostringa.ReplaceAll("LIVETIME",ltime);
170  sprintf(ltime, "non-zero lags : <font color=\"red\"> %i lags - %.2f sec = %.2f days = %.1f years </fonts>",
171  countlag,LIVETIME,LIVETIME/(float)86400.,LIVETIME/86400./365.);
172  ostringa.ReplaceAll("LIVETIM2",ltime);
173  ostringa.ReplaceAll("PLOT_LIST",pp_data_dir);
174  if(cwb_doc_url!="") {
175  ostringa.ReplaceAll("<!--CWB_DOC_URL","");
176  ostringa.ReplaceAll("CWB_DOC_URL-->","");
177  ostringa.ReplaceAll("XCWB_DOC_URL",cwb_doc_url.Data());
178  }
179 
180  ostringa.ReplaceAll("</html>","");
181  out << ostringa.Data() << endl;
182  }
183  bkgin.close();
184 
185  char _ifo[NIFO_MAX][8];
186  for(int n=0;n<nIFO;n++) {
187  if(strlen(ifo[n])>0) strcpy(_ifo[n],ifo[n]); // built in detector
188  else strcpy(_ifo[n],detParms[n].name); // user define detector
189  }
190 
191  char file_ev[1024];
192  sprintf(file_ev,"%s/events.txt",PP_DATA_PATH.Data());
193  ifstream for_ev(file_ev);
194  char file_header[1024];
195  sprintf(file_header,"%s/events_header.txt",PP_DATA_PATH.Data());
196  ofstream for_header(file_header);
197  char file_notsorted[1024];
198  sprintf(file_notsorted,"%s/events_notsorted.txt",PP_DATA_PATH.Data());
199  ofstream for_notsorted(file_notsorted);
200  char in_ev[100000];
201  while(1) {
202  for_ev.getline(in_ev,100000);
203  if (!for_ev.good()) break;
204  TString sin_ev(in_ev);
205  if (sin_ev.Contains("#")) for_header << sin_ev.Data() << endl;
206  else for_notsorted << sin_ev.Data() << endl;
207  }
208  for_header.close();
209  for_notsorted.close();
210  char file_sorted[1024];
211  sprintf(file_sorted,"%s/events_sorted.txt",PP_DATA_PATH.Data());
212  sprintf(exec,"sort -g -r --key=3 %s > %s",file_notsorted, file_sorted);
213  gSystem->Exec(exec);
214  sprintf(exec,"cat %s %s > %s/EVENTS.txt",file_header, file_sorted, PP_DATA_PATH.Data());
215  gSystem->Exec(exec);
216 
217  sprintf(file_notsorted,"%s/events_notsorted.txt",PP_DATA_PATH.Data());
218  ifstream f_ev(file_sorted);
219  char pm[2];
220  char c3[2];
221  float icc, irho, iacor, ilag, islag, ilik, ipen, icHH, ivHH, ivED, icc2, icc3; //SLAG
222  int ifreq, iband;
223  float idur;
224  int isize, irate, irun;
226  double time0, time1, time2, time3;
227  float phi, theta, psi;
228  int ecount=0;
229 
230  char os[1024];
231 
232  out << "<table border=0 cellpadding=2 class=\"datagrid\">" << endl;
233  out << "<tr align=\"center\">"<< endl;
234  out << "<td>ID</td>"<< endl;
235  if(bhveto) out << "<td>KW</td>"<< endl;
236  if(bcat3) out << "<td>cat3 </td>"<< endl;
237  out << "<td>rho["<<pp_irho<<"]</td>"<< endl;
238  out << "<td>cc["<<pp_inetcc<<"]</td>"<< endl;
239  if(TString(analysis)=="2G") out << "<td>subnet</td>"<< endl;
240 // out << "<td>ecor</td>"<< endl;
241  out << "<td>lag</td>"<< endl;
242  out << "<td>slag</td>"<< endl;
243  out << "<td>SNRnet</td>"<< endl;
244  if(TString(analysis)=="1G") out << "<td>pf</td>"<< endl;
245  if(TString(analysis)=="1G") out << "<td>vED</td>"<< endl;
246  out << "<td>freq</td>"<< endl;
247  out << "<td>bw</td>"<< endl;
248  out << "<td>dur</td>"<< endl;
249  out << "<td>size</td>"<< endl;
250  if(optim==true) out << "<td>res</td>"<< endl;
251  out << "<td>run</td>"<< endl;
252  for (int nn=0;nn<nIFO;nn++) out << "<td>GPS " << _ifo[nn] << "</td>"<< endl;
253  for (int nn=0;nn<nIFO;nn++) out << "<td>SNR " << _ifo[nn] << "</td>"<< endl;
254 /*
255  for (int nn=0;nn<nIFO;nn++) out << "<td>hrss " << _ifo[nn] << "</td>"<< endl;
256  out << "<td>phi</td>"<< endl;
257  out << "<td>theta</td>"<< endl;
258  out << "<td>psi</td>"<< endl;
259 */
260  out << "</tr>"<< endl;
261 
262  double start[5];
263  while(ecount<pp_max_nloudest_list) {
264  if (nIFO>3) {
265  f_ev>>pm>>c3>>irho>>icc>>icc2>>icc3>>iacor>>ilag>>islag>>ilik>>ipen>>icHH>>ifreq>>iband>>idur>>isize>>irate>>irun>>time0>>time1>>time2>>time3>>SNR0>>SNR1>>SNR2>>SNR3>>hrss0>>hrss1>>hrss2>>hrss3>>phi>>theta>>psi;
266  } else if (nIFO>2) {
267  f_ev>>pm>>c3>>irho>>icc>>icc2>>icc3>>iacor>>ilag>>islag>>ilik>>ipen>>icHH>>ifreq>>iband>>idur>>isize>>irate>>irun>>time0>>time1>>time2>>SNR0>>SNR1>>SNR2>>hrss0>>hrss1>>hrss2>>phi>>theta>>psi;
268  } else {
269  f_ev>>pm>>c3>>irho>>icc>>icc2>>icc3>>iacor>>ilag>>islag>>ilik>>ipen>>icHH>>ifreq>>iband>>idur>>isize>>irate>>irun>>time0>>time1>>SNR0>>SNR1>>hrss0>>hrss1>>phi>>theta>>psi;
270  }
271  if (!f_ev.good()) break;
272  TString ppm(pm);
273  TString cc3(c3);
274  if (ppm.Contains("+")) {
275  ecount++;
276  cout << ecount << " ";cout.flush();
277  out << "<tr align=\"center\">"<< endl;
278  sprintf(os,"run==%i",irun);
279  TString s_ced=GetFileLabel(wave_tree,irun,ilag,islag,segEdge,psfix);
280  char namedir[1024];
281  sprintf(namedir,"");
282  if(singleDetector&&strlen(channelNamesRaw[0])>1) {
283  start[0]=GetStart(wave_tree, 0, irun, irho, time0, time1, analysis, pp_irho);
284  sprintf(namedir, "%s_%s_%.3f", _ifo[0],channelNamesRaw[0],start[0]);
285  } else {
286  for (int nn=0; nn<nIFO; nn++) sprintf(namedir,"%s%s",namedir,_ifo[nn]);
287  for (int nn=0; nn<nIFO; nn++) {
288  start[nn]=GetStart(wave_tree, nn, irun, irho, time0, time1, analysis, pp_irho);
289  sprintf(namedir,"%s_%.3f",namedir,start[nn]);
290  }
291  }
292  sprintf(os,"<td><a href=\"ced/ced_%s/%s\" target=\"_blank\">%i</a></td>",s_ced.Data(),namedir,ecount);
293  out << os << endl;
294  if(bhveto) {
295  sprintf(os,"<td>%s</td>",ppm.Remove(0,1).Data());
296  out << os << endl;
297  }
298  if(bcat3) {
299  sprintf(os,"<td>%s</td>",cc3.Remove(0,1).Data());
300  out << os << endl;
301  }
302  sprintf(os,"<td>%.2f</td>",irho);
303  out << os << endl;
304  sprintf(os,"<td>%.2f</td>",icc);
305  out << os << endl;
306  if(TString(analysis)=="2G") {
307  sprintf(os,"<td>%.2f</td>",icc2);
308  out << os << endl;
309  }
310 /*
311  sprintf(os,"<td>%.2f</td>",iacor);
312  out << os << endl;
313 */
314  sprintf(os,"<td>%i</td>",(int)ilag);
315  out << os << endl;
316  sprintf(os,"<td>%i</td>",(int)islag);
317  out << os << endl;
318  sprintf(os,"<td>%3.1f</td>",sqrt(ilik));
319  out << os << endl;
320  sprintf(os,"<td>%.3f</td>",ipen);
321  if(TString(analysis)=="1G") out << os << endl;
322  sprintf(os,"<td>%.3f</td>",icHH);
323  if(TString(analysis)=="1G") out << os << endl;
324  sprintf(os,"<td><font color=\"black\">%i</font></td>",ifreq);
325  out << os << endl;
326  sprintf(os,"<td>%i</td>",iband);
327  out << os << endl;
328  sprintf(os,"<td>%.3f</td>",idur);
329  out << os << endl;
330  sprintf(os,"<td>%i</td>",isize);
331  out << os << endl;
332  sprintf(os,"<td>%i</td>",irate);
333  if(optim==true) out << os << endl;
334  sprintf(os,"<td>%i</td>",irun);
335  out << os << endl;
336  sprintf(os,"<td>%.2f</td>",time0);
337  out << os << endl;
338  if (nIFO>1){
339  sprintf(os,"<td>%.2f</td>",time1);
340  out << os << endl;
341  }
342  if (nIFO>2){
343  sprintf(os,"<td>%.2f</td>",time2);
344  out << os << endl;
345  }
346  if (nIFO>3){
347  sprintf(os,"<td>%.2f</td>",time3);
348  out << os << endl;
349  }
350  sprintf(os,"<td>%3.1f</td>",sqrt(SNR0));
351  out << os << endl;
352  if (nIFO>1){
353  sprintf(os,"<td>%3.1f</td>",sqrt(SNR1));
354  out << os << endl;
355  }
356  if (nIFO>2){
357  sprintf(os,"<td>%3.1f</td>",sqrt(SNR2));
358  out << os << endl;
359  }
360  if (nIFO>3){
361  sprintf(os,"<td>%3.1f</td>",sqrt(SNR3));
362  out << os << endl;
363  }
364 /*
365  sprintf(os,"<td>%.1e</td>",hrss0);
366  out << os << endl;
367  sprintf(os,"<td>%.1e</td>",hrss1);
368  out << os << endl;
369  if (nIFO>2){
370  sprintf(os,"<td>%.1e</td>",hrss2);
371  out << os << endl;
372  }
373  if (nIFO>3){
374  sprintf(os,"<td>%.1e</td>",hrss3);
375  out << os << endl;
376  }
377  sprintf(os,"<td>%.2f</td>",phi);
378  out << os << endl;
379  sprintf(os,"<td>%.2f</td>",theta);
380  out << os << endl;
381  sprintf(os,"<td>%.2f</td>",psi);
382  out << os << endl;
383 */
384  out << "</tr>" << endl;
385  }
386 
387  }
388  cout << endl;
389  f_ev.close();
390  out << "</table>" << endl;
391  out << "<p>" << endl;
392  out << endl;
393 
394  cout << exec << endl;
395  gSystem->Exec(exec);
396 
397  sprintf(file_notsorted,"%s/events_notsorted.txt",PP_DATA_PATH.Data());
398  sprintf(exec,"rm %s",file_notsorted);
399  cout << exec << endl;
400  gSystem->Exec(exec);
401  sprintf(exec,"rm %s",file_header);
402  cout << exec << endl;
403  gSystem->Exec(exec);
404 
405  out << "</table>" << endl;
406  out << "<p>" << endl;
407  out << endl;
408  out.close();
409  exit(0);
410 }
411 
char ofile[1024]
float SNR1
float hrss3
float SNR0
TString PP_DATA_PATH
static vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="", TString containString="", bool fast=false)
Definition: Toolbox.cc:5108
double T_pen
void Export(TString fname="")
Definition: config.cc:406
double time1
float idur
double fHigh
sprintf(netdir,"%s/%s", pp_dir, pp_data_dir)
char html_body_prod_template[1024]
float irho
float hrss2
char channelNamesRaw[NIFO_MAX][50]
par [0] name
int ecount
float ilik
int n
Definition: cwb_net.C:28
void GetLiveTime()
Definition: GetLiveTime.C:31
dqfile VDQF[100]
TString("c")
float icc2
double T_cor
ofstream out
Definition: cwb_merge.C:214
bool optim
int ifreq
double GetStart(TTree *tree, int nifo, int run, float rho, double time0, double time1, TString analysis, int irho)
Definition: Toolfun.hh:260
vector< TString > epsList
TString cwb_doc_url
bool bcat2
i pp_inetcc
float SNR2
cout<< "baudline_FFL : "<< baudline_FFL<< endl;ofstream out;out.open(baudline_FFL, ios::out);if(!out.good()) {cout<< "Error Opening File : "<< baudline_FFL<< endl;exit(1);} ifstream in;in.open(frFiles[ifoID], ios::in);if(!in.good()) {cout<< "Error Opening File : "<< frFiles[ifoID]<< endl;exit(1);} TString pfile_path="";char istring[1024];while(1) { in > istring
double segEdge
Definition: test_config1.C:49
int nVDQF
TString PP_DATA_DIR
i drho i
void Import(TString umacro="")
Definition: config.cc:352
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
int iband
bool singleDetector
char c3[2]
char ifo[NIFO_MAX][8]
TString GetFileLabel(TTree *tree, int run, int lag, int slag, double segEdge, TString psfix)
Definition: Toolfun.hh:218
float ivED
float ilag
#define nIFO
char data_label[512]
Definition: test_config1.C:160
double T_acor
float theta
double time2
bool bhveto
bool bcat3
float hrss1
TString _ifo[NIFO_MAX]
Definition: cwb_eced.C:31
TString RATEBACKGROUND
float iacor
double pp_rho_min
float ivHH
float icHH
char netdir[1024]
const int NIFO_MAX
Definition: wat.hh:22
double time0
float ipen
float psi
ifstream f_ev(file_sorted)
double pp_rho_max
char net_file_name[256]
float hrss0
char fileout[256]
float icc
s s
Definition: cwb_net.C:155
int isize
char title[256]
Definition: SSeriesExample.C:1
char subtitle[1024]
float icc3
int irate
ifstream in
double fLow
float SNR3
char fileliv[1024]
char pp_dir[512]
Definition: test_config1.C:155
char pp_data_dir[1024]
float islag
char cmd[1024]
strcpy(RunLabel, RUN_LABEL)
TString cc3(c3)
float phi
double T_cut
int pp_max_nloudest_list
int irun
int cat
double T_out
double T_vED
TString config
detectorParams detParms[4]
TString ppm(pm)
double time3
i drho pp_irho
void SetSingleDetectorMode()
Definition: config.cc:1352
char pm[2]
exit(0)
char os[1024]