Logo coherent WaveBurst  
Config Reference Guide
Logo
Create_O3_LHV_ChunkSlagRndFiles.C
Go to the documentation of this file.
1 #include <algorithm> // std::random_shuffle
2 #include <vector> // std::vector
3 #include <ctime> // std::time
4 #include <cstdlib> // std::rand, std::srand
5 #include "../../MACROS/ReadChunkList.C"
6 
7 #define SEED 150914
8 
9 #define CHUNK_FILE_LIST "Chunk_List.txt"
10 #define CHUNK_MAX_SIZE 100
11 
12 #define EXECUTE
13 
14 void Create_SlagRndFile(TString slags_dir, int chunkID, int slagMax, char* cwb_config_env, char* calibVer, char* search);
15 void shuffle(std::vector<int>& vector, int seed=150914);
16 
17 void Create_O3_LHV_ChunkSlagRndFiles(TString slags_dir, TString calibVer, TString calibType, TString search) {
18 
19  CWB::Toolbox TB;
20 
21  // get CWB_CONFIG
22  char cwb_config_env[1024] = "";
23  if(gSystem->Getenv("CWB_CONFIG")!=NULL) {
24  strcpy(cwb_config_env,TString(gSystem->Getenv("CWB_CONFIG")).Data());
25  }
26 
27  // get O3_GPS_START_CXX, O3_GPS_STOP_CXX
28  TString o3_gps_start_cxx = TString::Format("O3_GPS_START_%s",calibVer.Data());
29  double gps_start=0;
30  if(gSystem->Getenv(o3_gps_start_cxx.Data())!=NULL) {
31  gps_start=TString(gSystem->Getenv(o3_gps_start_cxx.Data())).Atof();
32  } else {
33  cout << "Error: O3_GPS_START_CXX env not defined" << endl;exit(1);
34  }
35  TString o3_gps_stop_cxx = TString::Format("O3_GPS_STOP_%s",calibVer.Data());
36  double gps_stop=0;
37  if(gSystem->Getenv(o3_gps_stop_cxx.Data())!=NULL) {
38  gps_stop=TString(gSystem->Getenv(o3_gps_stop_cxx.Data())).Atof();
39  } else {
40  cout << "Error: O3_GPS_STOP_CXX env not defined" << endl;exit(1);
41  }
42 
43  char chunk_file_list[1024];
44  sprintf(chunk_file_list,"%s/O3/CHUNKS/%s/%s",cwb_config_env,search.Data(),CHUNK_FILE_LIST);
45  cout << chunk_file_list << endl;
46 
47  int chunk[CHUNK_MAX_SIZE];
48  double start[CHUNK_MAX_SIZE];
49  double stop[CHUNK_MAX_SIZE];
50 
51  int nChunks = ReadChunkList(chunk_file_list,chunk,start,stop);
52 
53 
54  int nIFO = 3;
55 
56  char ifo[NIFO_MAX][8];
57  strcpy(ifo[0],"L1");
58  strcpy(ifo[1],"H1");
59  strcpy(ifo[2],"V1");
60 
61  vector<TString> ifos(nIFO);
62  for(int n=0;n<nIFO;n++) ifos[n]=ifo[n];
63 
64  int slagMin = 0; // if slagMax=0 -> slagMin must be < slagMax
65  int slagOff = 0;
66  size_t* slagSite = NULL; // site index starting with 0
67  char* slagFile = NULL; // slag file list
68 
69  //jobs
70  int segLen = 1200;
71 
72  // dq file list
73  // {ifo, dqcat_file, dqcat[0/1/2], shift[sec], inverse[false/true], 4columns[true/false]}
74  int nDQF=15;
75  dqfile DQF[15]={
76 
77  {"L1" ,"", CWB_CAT0, 0., false, false},
78  {"H1" ,"", CWB_CAT0, 0., false, false},
79  {"V1" ,"", CWB_CAT0, 0., false, false},
80 
81  {"L1" ,"", CWB_CAT1, 0., true, false},
82  {"H1" ,"", CWB_CAT1, 0., true, false},
83  {"V1" ,"", CWB_CAT1, 0., true, false},
84 
85  {"L1" ,"", CWB_CAT2, 0., true, false},
86  {"H1" ,"", CWB_CAT2, 0., true, false},
87  {"V1" ,"", CWB_CAT2, 0., true, false},
88 
89  {"L1" ,"", CWB_CAT1, 0., true, false},
90  {"H1" ,"", CWB_CAT1, 0., true, false},
91  {"V1" ,"", CWB_CAT1, 0., true, false},
92 
93  {"L1" ,"", CWB_CAT0, 0., false, false},
94  {"H1" ,"", CWB_CAT0, 0., false, false},
95  {"V1" ,"", CWB_CAT0, 0., false, false}
96 
97  };
98 
99  sprintf(DQF[0].file, "%s/O3/DATA/%s/DQ/%s/L1_cat0.txt",cwb_config_env,calibVer.Data(),calibType.Data());
100  sprintf(DQF[1].file, "%s/O3/DATA/%s/DQ/%s/H1_cat0.txt",cwb_config_env,calibVer.Data(),calibType.Data());
101  sprintf(DQF[2].file, "%s/O3/DATA/%s/DQ/%s/V1_cat0.txt",cwb_config_env,calibVer.Data(),calibType.Data());
102 
103  sprintf(DQF[3].file, "%s/O3/DATA/%s/DQ/%s/L1_cat1.txt",cwb_config_env,calibVer.Data(),calibType.Data());
104  sprintf(DQF[4].file, "%s/O3/DATA/%s/DQ/%s/H1_cat1.txt",cwb_config_env,calibVer.Data(),calibType.Data());
105  sprintf(DQF[5].file, "%s/O3/DATA/%s/DQ/%s/V1_cat1.txt",cwb_config_env,calibVer.Data(),calibType.Data());
106 
107  sprintf(DQF[6].file, "%s/O3/DATA/%s/DQ/%s/L1_cat2.txt",cwb_config_env,calibVer.Data(),calibType.Data());
108  sprintf(DQF[7].file, "%s/O3/DATA/%s/DQ/%s/H1_cat2.txt",cwb_config_env,calibVer.Data(),calibType.Data());
109  sprintf(DQF[8].file, "%s/O3/DATA/%s/DQ/%s/H1_cat2.txt",cwb_config_env,calibVer.Data(),calibType.Data());
110 
111  sprintf(DQF[9].file, "%s/O3/DATA/%s/DQ/%s/L1_cat4.txt",cwb_config_env,calibVer.Data(),calibType.Data());
112  sprintf(DQF[10].file, "%s/O3/DATA/%s/DQ/%s/H1_cat4.txt",cwb_config_env,calibVer.Data(),calibType.Data());
113  sprintf(DQF[11].file, "%s/O3/DATA/%s/DQ/%s/H1_cat4.txt",cwb_config_env,calibVer.Data(),calibType.Data());
114 
115 #ifdef EXECUTE
116  char ofile[1024];
117  if(search=="") {
118  sprintf(ofile,"%s/%s/slagSizeMax.lst",slags_dir.Data(),calibType.Data());
119  } else {
120  sprintf(ofile,"%s/%s/slagSizeMax.lst",slags_dir.Data(),search.Data());
121  }
122  cout << ofile << endl;
123  ofstream out;
124  out.open(ofile);
125  if (!out.good()) {cout << "Error Opening File : " << ofile << endl;exit(1);}
126  out << "# chunk slagSize" << endl << endl;
127 
128  char ofile2[1024];
129  if(search=="") {
130  sprintf(ofile2,"%s/%s/liveTimes.lst",slags_dir.Data(),calibType.Data());
131  } else {
132  sprintf(ofile2,"%s/%s/liveTimes.lst",slags_dir.Data(),search.Data());
133  }
134  cout << ofile2 << endl;
135  ofstream out2;
136  out2.open(ofile2);
137  if (!out2.good()) {cout << "Error Opening File : " << ofile2 << endl;exit(1);}
138  out2 << "# chunk liveTime_cat0\tliveTime_cat1\tliveTime_cat2" << endl << endl;
139  // write header
140  char sout2[1024];
141  sprintf(sout2,"%s %*s %*s %*s %*s %*s %*s",
142  "# chunk", 22, "liveTime_cat0(sec)", 22, "liveTime_cat0(days)",
143  22, "liveTime_cat1(sec)", 22, "liveTime_cat1(days)",
144  22, "liveTime_cat2(sec)", 22, "liveTime_cat2(days)");
145  out2 << sout2 << endl;
146 #endif
147  cout << "# chunk slagSize" << endl << endl;
148 
149  for(int k=0;k<nChunks;k++) {
150 
151  if(stop[k]<=gps_start || start[k]>=gps_stop || stop[k]>gps_stop) continue;
152 
153  sprintf(DQF[12].file, "%s/O3/CHUNKS/%s/K%02d.period",cwb_config_env,search.Data(),chunk[k]);
154  sprintf(DQF[13].file, "%s/O3/CHUNKS/%s/K%02d.period",cwb_config_env,search.Data(),chunk[k]);
155  sprintf(DQF[14].file, "%s/O3/CHUNKS/%s/K%02d.period",cwb_config_env,search.Data(),chunk[k]);
156 
157  vector<waveSegment> cat0List=TB.readSegList(nDQF, DQF, CWB_CAT0);
158  double live_time_cat0 = CWB::Toolbox::getTimeSegList(cat0List);
159  cout << endl << "live_time_cat0 : " << (int)live_time_cat0 << " (sec) - " << live_time_cat0/(24.*3600.) << " (days)" << endl;
160 
161  vector<waveSegment> cat1List=TB.readSegList(nDQF, DQF, CWB_CAT1);
162  double live_time_cat1 = CWB::Toolbox::getTimeSegList(cat1List);
163  cout << endl << "live_time_cat1 : " << (int)live_time_cat1 << " (sec) - " << live_time_cat1/(24.*3600.) << " (days)" << endl;
164 
165  vector<waveSegment> cat2List=TB.readSegList(nDQF, DQF, CWB_CAT2);
166  double live_time_cat2 = CWB::Toolbox::getTimeSegList(cat2List);
167  cout << endl << "live_time_cat2 : " << (int)live_time_cat2 << " (sec) - " << live_time_cat2/(24.*3600.) << " (days)" << endl << endl;
168 
169 #ifdef EXECUTE
170  sprintf(sout2,"K%02d %*d %*.2f %*d %*.2f %*d %*.2f",
171  chunk[k], 22, (int)live_time_cat0, 22, (live_time_cat0/(24.*3600.)),
172  22, (int)live_time_cat1, 22, (live_time_cat1/(24.*3600.)),
173  22, (int)live_time_cat2, 22, (live_time_cat2/(24.*3600.)));
174  out2 << sout2 << endl;
175 #endif
176 
177  int slagMax=TB.getSlagJobList(cat1List, segLen).size();
178 
179  char string[64]; sprintf(string,"K%02d\t%d",chunk[k],2*slagMax+1);
180  cout << "slagSize = \t" << string << endl;
181 
182  if(search=="") {
183  Create_SlagRndFile(slags_dir, chunk[k], slagMax, cwb_config_env, (char*)calibVer.Data(), (char*)calibType.Data());
184  } else {
185  Create_SlagRndFile(slags_dir, chunk[k], slagMax, cwb_config_env, (char*)calibVer.Data(), (char*)search.Data());
186  }
187 
188 #ifdef EXECUTE
189  out << string << endl;
190 #endif
191 
192  }
193 
194 #ifdef EXECUTE
195  out.close();
196  out2.close();
197 #endif
198 
199  exit(0);
200 }
201 
202 void Create_SlagRndFile(TString slags_dir, int chunkID, int slagMax, char* cwb_config_env, char* calibVer, char* search) {
203 
204  std::vector<int> RND_A(2*slagMax);
205  std::vector<int> RND_B(2*slagMax);
206  for(int n=0; n<slagMax; n++) {
207  RND_A[2*n+0]=+(n+1);
208  RND_A[2*n+1]=-(n+1);
209 
210  RND_B[2*n+0]=-(n+1);
211  RND_B[2*n+1]=+(n+1);
212  }
213 
214  shuffle(RND_A,SEED); // shuffle data RND_A
215  shuffle(RND_B,SEED); // shuffle data RND_B
216 
217  // check RND_A
218  for(int n=0; n<slagMax; n++) {
219  int A = +(n+1);
220  int B = -(n+1);
221  int nA=0;
222  int nB=0;
223  for(int n=0; n<2*slagMax; n++) {
224  if(RND_A[n]==A) nA++;
225  if(RND_A[n]==B) nB++;
226  }
227  if(nA!=1 && nB!=1) {
228  cout << "ERROR !!!" << endl;
229  exit(1);
230  }
231  }
232 
233  // check RND_B
234  for(int n=0; n<slagMax; n++) {
235  int A = +(n+1);
236  int B = -(n+1);
237  int nA=0;
238  int nB=0;
239  for(int n=0; n<2*slagMax; n++) {
240  if(RND_B[n]==A) nA++;
241  if(RND_B[n]==B) nB++;
242  }
243  if(nA!=1 && nB!=1) {
244  cout << "ERROR !!!" << endl;
245  exit(1);
246  }
247  }
248 
249  //for(int n=0; n<2*slagMax; n++) cout << n << "\t" << RND_A[n] << endl;;
250  //for(int n=0; n<2*slagMax; n++) cout << n << "\t" << RND_B[n] << endl;;
251 
252  char ofile[1024];
253  sprintf(ofile,"%s/%s/K%02d.slags",slags_dir.Data(),search,chunkID);
254  cout << endl << ofile << endl << endl;
255 
256 #ifdef EXECUTE
257  ofstream out;
258  out.open(ofile);
259  if (!out.good()) {cout << "Error Opening File : " << ofile << endl;exit(1);}
260  out << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << endl;
261  for(int n=0; n<2*slagMax; n++) {
262  out << n+1 << "\t" << 0 << "\t" << RND_A[n] << "\t" << RND_B[n] << endl;
263  }
264  out.close();
265 #endif
266 
267  return;
268 }
269 
270 void shuffle(std::vector<int>& vector, int seed) {
271 
272  TRandom3 rnd3(seed);
273 
274  size_t size = vector.size();
275 
276  if(size > 1) {
277  size_t i;
278  for(size_t i=0; i<size; i++) {
279  size_t j = int(rnd3.Uniform(0,size));
280  int t = vector[j];
281  vector[j] = vector[i];
282  vector[i] = t;
283  }
284  }
285 }
slagMin
slagMax
slagOff
nDQF
segLen
slagFile
nIFO
strcpy(analysis,"2G")
TString calibVer
#define CHUNK_FILE_LIST
#define CHUNK_MAX_SIZE
void Create_O3_LHV_ChunkSlagRndFiles(TString slags_dir, TString calibVer, TString calibType, TString search)
void Create_SlagRndFile(TString slags_dir, int chunkID, int slagMax, char *cwb_config_env, char *calibVer, char *search)
void shuffle(std::vector< int > &vector, int seed=150914)
int ReadChunkList(TString ifile, int *chunk=NULL, double *start=NULL, double *stop=NULL)
Definition: ReadChunkList.C:22
shift breaksw case t
Definition: cwb_clchunk.csh:85
shift breaksw case n
Definition: cwb_clchunk.csh:75
shift breaksw case B
string search
Definition: cWB_conf.py:63
list ifos
Definition: cWB_conf.py:23