Logo coherent WaveBurst  
Config Reference Guide
Logo
ComputeObsTime.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 // this macro is used to compute the coincidence and exclusive times starting from cat0 DQ
20 // it works for nifo<=3
21 // Consider for example the network with 3 detectoes H1, L1, V1, the following files are produced:
22 //
23 // single detector cat0 observation time
24 //
25 // -> H1_cat0.txt , L1_cat0.txt , V1_cat0.txt
26 //
27 // double detectors cat0 coincident observation time
28 //
29 // -> H1_L1_cat0.txt , H1_V1_cat0.txt , L1_V1_cat0.txt
30 //
31 // triple detectors cat0 coincident observation time
32 //
33 // -> H1_L1_V1_cat0.txt
34 //
35 // double detectors cat0 exclusive observation time
36 //
37 // -> H1_L1_xcat0.txt , H1_V1_xcat0.txt , L1_V1_xcat0.txt
38 //
39 // single detector cat0 exclusive observation time
40 //
41 // -> H1_xcat0.txt , L1_xcat0.txt , V1_xcat0.txt
42 //
43 // All informations and the total times for each network are dumped into a README.md file
44 //
45 
46 #define DAY (24.*3600.)
47 
48 #define MAX_IFOS 3
49 
50 void ComputeObsTime(TString DQ_dir, TString OBSTIME_dir="") {
51 
52  // read cat0 file list
53  vector<TString> ifname = CWB::Toolbox::getFileListFromDir(DQ_dir, ".txt","","_cat0",true);
54  if(ifname.size()==0) {
55  cout << "No cat0 files are present on the directory : " << DQ_dir << endl;
56  exit(1);
57  }
58 
59  // extract ifo list
60  vector<TString> ifo;
61  for(int j=0;j<ifname.size();j++) {
62  //cout << j << " " << ifname[j] << endl;
63  TString xifo = TString(gSystem->BaseName(ifname[j]))(0,2);
64  ifo.push_back(xifo);
65  }
66 
67  int nifo = ifo.size();
68 
69  if(nifo>MAX_IFOS) {
70  cout << "Error, max ifos number is : " << MAX_IFOS << endl;
71  exit(1);
72  }
73 
74  // open README.md file
75  ofstream out;
76  if(CWB::Toolbox::isFileExisting("README.md")) {
77  out.open("README.md",ios::app); // append
78  } else {
79  out.open("README.md",ios::out); // create
80  }
81  if(!out.good()) {cout << "ComputeObsTime.C - Error : Opening File : "
82  << "README.md" << endl;gSystem->Exit(1);}
83 
84  // compute single detector cat0 observation time
85 
86  out << "-------------------------------------------------------" << endl;
87  out << "single detector cat0 observation time" << endl;
88  out << "-------------------------------------------------------" << endl;
89  out << endl;
90 
91  vector<vector<waveSegment>> ifo1_seg(nifo);
92  for(int i=0;i<nifo;i++) {
93 
94  ifo1_seg[i] = CWB::Toolbox::readSegments(ifname[i]);
95 
96  double ifo1_time=CWB::Toolbox::getTimeSegList(ifo1_seg[i]);
97  out << ifo[i] << "_time = " << (int)ifo1_time << " sec - " << ifo1_time/DAY << " days" << endl;
98 
99  // dump single detector cat0 segments
100  if(OBSTIME_dir!="") {
101  TString ofname = TString::Format("%s/%s_cat0.txt",OBSTIME_dir.Data(),ifo[i].Data());
102  out << "-> " << gSystem->BaseName(ofname) << endl << endl;
103  CWB::Toolbox::dumpSegList(ifo1_seg[i],ofname);
104  }
105  }
106  out << endl;
107 
108  // compute double detectors cat0 coincident observation time
109 
110  out << "-------------------------------------------------------" << endl;
111  out << "double detectors cat0 coincident observation time" << endl;
112  out << "-------------------------------------------------------" << endl;
113  out << endl;
114 
115  vector<vector<vector<waveSegment>>> ifo2_seg(nifo);
116  for(int i=0;i<nifo;i++) {
117 
118  ifo2_seg[i].resize(nifo);
119 
120  for(int j=i+1;j<nifo;j++) {
121 
122  ifo2_seg[i][j] = CWB::Toolbox::mergeSegLists(ifo1_seg[i],ifo1_seg[j]);
123  double ifo2_time = CWB::Toolbox::getTimeSegList(ifo2_seg[i][j]);
124  out << ifo[i] << "_" << ifo[j] << "_time = " << (int)ifo2_time << " sec - " << ifo2_time/DAY << " days" << endl;
125 
126  // dump double detector cat0 coincident segments
127  if(OBSTIME_dir!="") {
128  TString ofname = TString::Format("%s/%s_%s_cat0.txt",OBSTIME_dir.Data(),ifo[i].Data(),ifo[j].Data());
129  out << "-> " << gSystem->BaseName(ofname) << endl << endl;
130  CWB::Toolbox::dumpSegList(ifo2_seg[i][j],ofname);
131  }
132  }
133  }
134  out << endl;
135 
136  // compute triple detectors cat0 coincident observation time
137 
138  out << "-------------------------------------------------------" << endl;
139  out << "triple detectors cat0 coincident observation time" << endl;
140  out << "-------------------------------------------------------" << endl;
141  out << endl;
142 
143  TString ifo3_name=ifo[0];
144  vector<waveSegment> ifo3_seg = ifo1_seg[0];
145  for(int i=1;i<nifo;i++) {
146  ifo3_seg = CWB::Toolbox::mergeSegLists(ifo3_seg,ifo1_seg[i]);
147  ifo3_name += "_"+ifo[i];
148  }
149  double ifo3_time = CWB::Toolbox::getTimeSegList(ifo3_seg);
150  out << ifo3_name+"_time = " << (int)ifo3_time << " sec - " << ifo3_time/DAY << " days" << endl;
151 
152  if(OBSTIME_dir!="") {
153  cout << endl;
154  TString ofname = TString::Format("%s/%s_cat0.txt",OBSTIME_dir.Data(),ifo3_name.Data());
155  out << "-> " << gSystem->BaseName(ofname) << endl << endl;
156  CWB::Toolbox::dumpSegList(ifo3_seg,ofname);
157  }
158  out << endl;
159 
160  vector<waveSegment> ifo3_iseg = CWB::Toolbox::invertSegments(ifo3_seg); // compute inverse ifo3 segments
161 
162  // compute double detectors cat0 exclusive observation time
163 
164  out << "-------------------------------------------------------" << endl;
165  out << "double detectors cat0 exclusive observation time" << endl;
166  out << "-------------------------------------------------------" << endl;
167  out << endl;
168 
169  vector<vector<vector<waveSegment>>> ifo2_xseg(nifo);
170  vector<vector<vector<waveSegment>>> ifo2_ixseg(nifo);
171  for(int i=0;i<nifo;i++) {
172 
173  ifo2_xseg[i].resize(nifo);
174  ifo2_ixseg[i].resize(nifo);
175 
176  for(int j=i+1;j<nifo;j++) {
177 
178  ifo2_xseg[i][j] = CWB::Toolbox::mergeSegLists(ifo2_seg[i][j],ifo3_iseg);
179  double ifo2_xtime = CWB::Toolbox::getTimeSegList(ifo2_xseg[i][j]);
180  out << ifo[i] << "_" << ifo[j] << "_xtime = " << (int)ifo2_xtime << " sec - " << ifo2_xtime/DAY << " days" << endl;
181 
182  // dump double detector cat0 coincident segments
183  if(OBSTIME_dir!="") {
184  TString ofname = TString::Format("%s/%s_%s_xcat0.txt",OBSTIME_dir.Data(),ifo[i].Data(),ifo[j].Data());
185  out << "-> " << gSystem->BaseName(ofname) << endl << endl;
186  CWB::Toolbox::dumpSegList(ifo2_xseg[i][j],ofname);
187  }
188 
189  ifo2_ixseg[i][j] = CWB::Toolbox::invertSegments(ifo2_xseg[i][j]);
190  }
191  }
192  out << endl;
193 
194  // compute single detector cat0 exclusive observation time
195 
196  out << "-------------------------------------------------------" << endl;
197  out << "single detector cat0 exclusive observation time" << endl;
198  out << "-------------------------------------------------------" << endl;
199  out << endl;
200 
201  for(int i=0;i<nifo;i++) for(int j=i+1;j<nifo;j++) ifo2_ixseg[j][i] = ifo2_ixseg[i][j];
202 
203  vector<vector<waveSegment>> ifo1_xseg(nifo);
204  for(int i=0;i<nifo;i++) {
205 
206  ifo1_xseg[i] = CWB::Toolbox::mergeSegLists(ifo1_seg[i],ifo3_iseg);
207 
208  for(int j=0;j<nifo;j++) {
209  if(j!=i) ifo1_xseg[i] = CWB::Toolbox::mergeSegLists(ifo1_xseg[i],ifo2_ixseg[i][j]);
210  }
211 
212  double ifo1_xtime=CWB::Toolbox::getTimeSegList(ifo1_xseg[i]);
213  out << ifo[i] << "_xtime = " << (int)ifo1_xtime << " sec - " << ifo1_xtime/DAY << " days" << endl;
214 
215  // dump single detector cat0 segments
216  if(OBSTIME_dir!="") {
217  TString ofname = TString::Format("%s/%s_xcat0.txt",OBSTIME_dir.Data(),ifo[i].Data());
218  out << "-> " << gSystem->BaseName(ofname) << endl << endl;
219  CWB::Toolbox::dumpSegList(ifo1_xseg[i],ofname);
220  }
221  }
222  out << endl;
223 
224  out.close();
225 
226  exit(0);
227 }
void ComputeObsTime(TString DQ_dir, TString OBSTIME_dir="")
#define DAY
#define MAX_IFOS