Logo coherent WaveBurst  
Config Reference Guide
Logo
Create_O1_LH_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_O1_LH_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/O1/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 = 2;
57 
58  char ifo[NIFO_MAX][8];
59  strcpy(ifo[0],"L1");
60  strcpy(ifo[1],"H1");
61 
62  vector<TString> ifos(nIFO);
63  for(int n=0;n<nIFO;n++) ifos[n]=ifo[n];
64 
65  int slagMin = 0; // if slagMax=0 -> slagMin must be < slagMax
66  int slagOff = 0;
67  size_t* slagSite = NULL; // site index starting with 0
68  char* slagFile = NULL; // slag file list
69 
70  //jobs
71  int segLen = 1200;
72 
73  // dq file list
74  // {ifo, dqcat_file, dqcat[0/1/2], shift[sec], inverse[false/true], 4columns[true/false]}
75  int nDQF=10;
76  dqfile DQF[10]={
77 
78  {"L1" ,"", CWB_CAT0, 0., false, false},
79  {"H1" ,"", CWB_CAT0, 0., false, false},
80 
81  {"L1" ,"", CWB_CAT1, 0., true, false},
82  {"H1" ,"", CWB_CAT1, 0., true, false},
83 
84  {"L1" ,"", CWB_CAT2, 0., true, false},
85  {"H1" ,"", CWB_CAT2, 0., true, false},
86 
87  {"L1" ,"", CWB_CAT1, 0., true, false},
88  {"H1" ,"", CWB_CAT1, 0., true, false},
89 
90  {"L1" ,"", CWB_CAT0, 0., false, false},
91  {"H1" ,"", CWB_CAT0, 0., false, false}
92 
93  };
94 
95  sprintf(DQF[0].file, "%s/O1/DATA/%s/DQ/%s/L1_cat0.txt",cwb_config_env,calibVer.Data(),calibType.Data());
96  sprintf(DQF[1].file, "%s/O1/DATA/%s/DQ/%s/H1_cat0.txt",cwb_config_env,calibVer.Data(),calibType.Data());
97 
98  sprintf(DQF[2].file, "%s/O1/DATA/%s/DQ/%s/L1_cat1.txt",cwb_config_env,calibVer.Data(),calibType.Data());
99  sprintf(DQF[3].file, "%s/O1/DATA/%s/DQ/%s/H1_cat1.txt",cwb_config_env,calibVer.Data(),calibType.Data());
100 
101  sprintf(DQF[4].file, "%s/O1/DATA/%s/DQ/%s/L1_cat2.txt",cwb_config_env,calibVer.Data(),calibType.Data());
102  sprintf(DQF[5].file, "%s/O1/DATA/%s/DQ/%s/H1_cat2.txt",cwb_config_env,calibVer.Data(),calibType.Data());
103 
104  sprintf(DQF[6].file, "%s/O1/DATA/%s/DQ/%s/L1_cat4.txt",cwb_config_env,calibVer.Data(),calibType.Data());
105  sprintf(DQF[7].file, "%s/O1/DATA/%s/DQ/%s/H1_cat4.txt",cwb_config_env,calibVer.Data(),calibType.Data());
106 
107 #ifdef EXECUTE
108  char ofile[1024];
109  sprintf(ofile,"%s/%s/%s/slagSizeMax.lst",slags_dir.Data(),calibVer.Data(),calibType.Data());
110  cout << ofile << endl;
111  ofstream out;
112  out.open(ofile);
113  if (!out.good()) {cout << "Error Opening File : " << ofile << endl;exit(1);}
114  out << "# chunk slagSize" << endl << endl;
115 #endif
116  cout << "# chunk slagSize" << endl << endl;
117 
118  for(int k=0;k<nChunks;k++) {
119 
120  sprintf(DQF[8].file, "%s/O1/CHUNKS/K%02d.period",cwb_config_env,chunk[k]);
121  sprintf(DQF[9].file, "%s/O1/CHUNKS/K%02d.period",cwb_config_env,chunk[k]);
122 
123  vector<waveSegment> cat1List=TB.readSegList(nDQF, DQF, CWB_CAT1);
124 
125  int slagMax=TB.getSlagJobList(cat1List, segLen).size();
126 
127  char string[64]; sprintf(string,"K%02d\t%d",chunk[k],2*slagMax+1);
128  cout << "slagSize = \t" << string << endl;
129 
130  Create_SlagRndFile(slags_dir, chunk[k], slagMax, cwb_config_env, (char*)calibVer.Data(), (char*)calibType.Data());
131 
132 #ifdef EXECUTE
133  out << string << endl;
134 #endif
135 
136  }
137 
138 #ifdef EXECUTE
139  out.close();
140 #endif
141 
142  exit(0);
143 }
144 
145 void Create_SlagRndFile(TString slags_dir, int chunkID, int slagMax, char* cwb_config_env, char* calibVer, char* calibType) {
146 
147  std::vector<int> RND(2*slagMax);
148  for(int n=0; n<slagMax; n++) {
149  RND[2*n+0]=+(n+1);
150  RND[2*n+1]=-(n+1);
151  }
152 
153  shuffle(RND,SEED); // shuffle data
154 
155  // check
156  for(int n=0; n<slagMax; n++) {
157  int A = +(n+1);
158  int B = -(n+1);
159  int nA=0;
160  int nB=0;
161  for(int n=0; n<2*slagMax; n++) {
162  if(RND[n]==A) nA++;
163  if(RND[n]==B) nB++;
164  }
165  if(nA!=1 && nB!=1) {
166  cout << "ERROR !!!" << endl;
167  exit(1);
168  }
169  }
170 
171  //for(int n=0; n<2*slagMax; n++) cout << n << "\t" << RND[n] << endl;;
172 
173  char ofile[1024];
174  sprintf(ofile,"%s/%s/%s/K%02d.slags",slags_dir.Data(),calibVer,calibType,chunkID);
175  cout << ofile << endl;
176 
177 #ifdef EXECUTE
178  ofstream out;
179  out.open(ofile);
180  if (!out.good()) {cout << "Error Opening File : " << ofile << endl;exit(1);}
181  out << 0 << "\t" << 0 << "\t" << 0 << endl;
182  for(int n=0; n<2*slagMax; n++) {
183  out << n+1 << "\t" << 0 << "\t" << RND[n] << endl;
184  }
185  out.close();
186 #endif
187 
188  return;
189 }
190 
191 void shuffle(std::vector<int>& vector, int seed) {
192 
193  TRandom3 rnd3(seed);
194 
195  size_t size = vector.size();
196 
197  if(size > 1) {
198  size_t i;
199  for(size_t i=0; i<size; i++) {
200  size_t j = int(rnd3.Uniform(0,size));
201  int t = vector[j];
202  vector[j] = vector[i];
203  vector[i] = t;
204  }
205  }
206 }
void Create_O1_LH_ChunkSlagRndFiles(TString slags_dir, TString calibVer, TString calibType)
#define CHUNK_FILE_LIST
#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