Logo coherent WaveBurst  
Config Reference Guide
Logo
Create_O2_LHV_ChunkSlagRndFiles.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 #include <algorithm> // std::random_shuffle
20 #include <vector> // std::vector
21 #include <ctime> // std::time
22 #include <cstdlib> // std::rand, std::srand
23 #include "../../MACROS/ReadChunkList.C"
24 
25 #define SEED 150914
26 
27 #define CHUNK_FILE_LIST "Chunk_List.txt"
28 #define CHUNK_MAX_SIZE 100
29 
30 #define EXECUTE
31 
32 void Create_SlagRndFile(TString slags_dir, int chunkID, int slagMax, char* cwb_config_env, char* calibVer, char* calibType);
33 void shuffle(std::vector<int>& vector, int seed=150914);
34 
35 void Create_O2_LHV_ChunkSlagRndFiles(TString slags_dir, TString calibVer, TString calibType) {
36 
37  CWB::Toolbox TB;
38 
39  // get CWB_CONFIG
40  char cwb_config_env[1024] = "";
41  if(gSystem->Getenv("CWB_CONFIG")!=NULL) {
42  strcpy(cwb_config_env,TString(gSystem->Getenv("CWB_CONFIG")).Data());
43  }
44 
45  char chunk_file_list[1024];
46  sprintf(chunk_file_list,"%s/O2/CHUNKS/%s",cwb_config_env,CHUNK_FILE_LIST);
47  cout << chunk_file_list << endl;
48 
49  int chunk[CHUNK_MAX_SIZE];
50  double start[CHUNK_MAX_SIZE];
51  double stop[CHUNK_MAX_SIZE];
52 
53  int nChunks = ReadChunkList(chunk_file_list,chunk,start,stop);
54 
55 
56  int nIFO = 3;
57 
58  char ifo[NIFO_MAX][8];
59  strcpy(ifo[0],"L1");
60  strcpy(ifo[1],"H1");
61  strcpy(ifo[2],"V1");
62 
63  vector<TString> ifos(nIFO);
64  for(int n=0;n<nIFO;n++) ifos[n]=ifo[n];
65 
66  int slagMin = 0; // if slagMax=0 -> slagMin must be < slagMax
67  int slagOff = 0;
68  size_t* slagSite = NULL; // site index starting with 0
69  char* slagFile = NULL; // slag file list
70 
71  //jobs
72 // int segLen = 1200;
73 int segLen = 1127;
74 
75  // dq file list
76  // {ifo, dqcat_file, dqcat[0/1/2], shift[sec], inverse[false/true], 4columns[true/false]}
77  int nDQF=13;
78  dqfile DQF[13]={
79 
80  {"L1" ,"", CWB_CAT0, 0., false, false},
81  {"H1" ,"", CWB_CAT0, 0., false, false},
82  {"V1" ,"", CWB_CAT0, 0., false, false},
83 
84  {"L1" ,"", CWB_CAT1, 0., true, false},
85  {"H1" ,"", CWB_CAT1, 0., true, false},
86  {"V1" ,"", CWB_CAT1, 0., true, false},
87 
88  {"L1" ,"", CWB_CAT2, 0., true, false},
89  {"H1" ,"", CWB_CAT2, 0., true, false},
90 
91  {"L1" ,"", CWB_CAT1, 0., true, false},
92  {"H1" ,"", CWB_CAT1, 0., true, false},
93 
94  {"L1" ,"", CWB_CAT0, 0., false, false},
95  {"H1" ,"", CWB_CAT0, 0., false, false},
96  {"V1" ,"", CWB_CAT0, 0., false, false}
97 
98  };
99 
100  sprintf(DQF[0].file, "%s/O2/DATA/%s/DQ/%s/L1_cat0.txt",cwb_config_env,calibVer.Data(),calibType.Data());
101  sprintf(DQF[1].file, "%s/O2/DATA/%s/DQ/%s/H1_cat0.txt",cwb_config_env,calibVer.Data(),calibType.Data());
102  sprintf(DQF[2].file, "%s/O2/DATA/%s/DQ/%s/V1_cat0.txt",cwb_config_env,calibVer.Data(),calibType.Data());
103 
104  sprintf(DQF[3].file, "%s/O2/DATA/%s/DQ/%s/L1_cat1.txt",cwb_config_env,calibVer.Data(),calibType.Data());
105  sprintf(DQF[4].file, "%s/O2/DATA/%s/DQ/%s/H1_cat1.txt",cwb_config_env,calibVer.Data(),calibType.Data());
106  sprintf(DQF[5].file, "%s/O2/DATA/%s/DQ/%s/V1_cat1.txt",cwb_config_env,calibVer.Data(),calibType.Data());
107 
108  sprintf(DQF[6].file, "%s/O2/DATA/%s/DQ/%s/L1_cat2.txt",cwb_config_env,calibVer.Data(),calibType.Data());
109  sprintf(DQF[7].file, "%s/O2/DATA/%s/DQ/%s/H1_cat2.txt",cwb_config_env,calibVer.Data(),calibType.Data());
110 
111  sprintf(DQF[8].file, "%s/O2/DATA/%s/DQ/%s/L1_cat4.txt",cwb_config_env,calibVer.Data(),calibType.Data());
112  sprintf(DQF[9].file, "%s/O2/DATA/%s/DQ/%s/H1_cat4.txt",cwb_config_env,calibVer.Data(),calibType.Data());
113 
114 #ifdef EXECUTE
115  char ofile[1024];
116  sprintf(ofile,"%s/%s/%s/slagSizeMax.lst",slags_dir.Data(),calibVer.Data(),calibType.Data());
117  cout << ofile << endl;
118  ofstream out;
119  out.open(ofile);
120  if (!out.good()) {cout << "Error Opening File : " << ofile << endl;exit(1);}
121  out << "# chunk slagSize" << endl << endl;
122 #endif
123  cout << "# chunk slagSize" << endl << endl;
124 
125  for(int k=17;k<nChunks;k++) {
126 
127  sprintf(DQF[10].file, "%s/O2/CHUNKS/K%02d.period",cwb_config_env,chunk[k]);
128  sprintf(DQF[11].file, "%s/O2/CHUNKS/K%02d.period",cwb_config_env,chunk[k]);
129  sprintf(DQF[12].file, "%s/O2/CHUNKS/K%02d.period",cwb_config_env,chunk[k]);
130 
131  vector<waveSegment> cat1List=TB.readSegList(nDQF, DQF, CWB_CAT1);
132 
133  int slagMax=TB.getSlagJobList(cat1List, segLen).size();
134 
135  char string[64]; sprintf(string,"K%02d\t%d",chunk[k],2*slagMax+1);
136  cout << "slagSize = \t" << string << endl;
137 
138  Create_SlagRndFile(slags_dir, chunk[k], slagMax, cwb_config_env, (char*)calibVer.Data(), (char*)calibType.Data());
139 
140 #ifdef EXECUTE
141  out << string << endl;
142 #endif
143 
144  }
145 
146 #ifdef EXECUTE
147  out.close();
148 #endif
149 
150  exit(0);
151 }
152 
153 void Create_SlagRndFile(TString slags_dir, int chunkID, int slagMax, char* cwb_config_env, char* calibVer, char* calibType) {
154 
155  std::vector<int> RND_A(2*slagMax);
156  std::vector<int> RND_B(2*slagMax);
157  for(int n=0; n<slagMax; n++) {
158  RND_A[2*n+0]=+(n+1);
159  RND_A[2*n+1]=-(n+1);
160 
161  RND_B[2*n+0]=-(n+1);
162  RND_B[2*n+1]=+(n+1);
163  }
164 
165  shuffle(RND_A,SEED); // shuffle data RND_A
166  shuffle(RND_B,SEED); // shuffle data RND_B
167 
168  // check RND_A
169  for(int n=0; n<slagMax; n++) {
170  int A = +(n+1);
171  int B = -(n+1);
172  int nA=0;
173  int nB=0;
174  for(int n=0; n<2*slagMax; n++) {
175  if(RND_A[n]==A) nA++;
176  if(RND_A[n]==B) nB++;
177  }
178  if(nA!=1 && nB!=1) {
179  cout << "ERROR !!!" << endl;
180  exit(1);
181  }
182  }
183 
184  // check RND_B
185  for(int n=0; n<slagMax; n++) {
186  int A = +(n+1);
187  int B = -(n+1);
188  int nA=0;
189  int nB=0;
190  for(int n=0; n<2*slagMax; n++) {
191  if(RND_B[n]==A) nA++;
192  if(RND_B[n]==B) nB++;
193  }
194  if(nA!=1 && nB!=1) {
195  cout << "ERROR !!!" << endl;
196  exit(1);
197  }
198  }
199 
200  //for(int n=0; n<2*slagMax; n++) cout << n << "\t" << RND_A[n] << endl;;
201  //for(int n=0; n<2*slagMax; n++) cout << n << "\t" << RND_B[n] << endl;;
202 
203  char ofile[1024];
204  sprintf(ofile,"%s/%s/%s/K%02d.slags",slags_dir.Data(),calibVer,calibType,chunkID);
205  cout << ofile << endl;
206 
207 #ifdef EXECUTE
208  ofstream out;
209  out.open(ofile);
210  if (!out.good()) {cout << "Error Opening File : " << ofile << endl;exit(1);}
211  out << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << endl;
212  for(int n=0; n<2*slagMax; n++) {
213  out << n+1 << "\t" << 0 << "\t" << RND_A[n] << "\t" << RND_B[n] << endl;
214  }
215  out.close();
216 #endif
217 
218  return;
219 }
220 
221 void shuffle(std::vector<int>& vector, int seed) {
222 
223  TRandom3 rnd3(seed);
224 
225  size_t size = vector.size();
226 
227  if(size > 1) {
228  size_t i;
229  for(size_t i=0; i<size; i++) {
230  size_t j = int(rnd3.Uniform(0,size));
231  int t = vector[j];
232  vector[j] = vector[i];
233  vector[i] = t;
234  }
235  }
236 }
#define CHUNK_FILE_LIST
void Create_O2_LHV_ChunkSlagRndFiles(TString slags_dir, TString calibVer, TString calibType)
#define CHUNK_MAX_SIZE
void shuffle(std::vector< int > &vector, int seed=150914)
void Create_SlagRndFile(TString slags_dir, int chunkID, int slagMax, char *cwb_config_env, char *calibVer, char *calibType)
slagMin
slagMax
slagOff
nDQF
segLen
slagFile
nIFO
strcpy(analysis,"2G")
TString calibVer
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
list ifos
Definition: cWB_conf.py:23