1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
2 | // Eric Aubourg
|
---|
3 | // Christophe Magneville
|
---|
4 | // Reza Ansari
|
---|
5 |
|
---|
6 | /* Traitement simple des donnees Archeops KS1-3 - Reza Juin 2002
|
---|
7 |
|
---|
8 | ---------------- Exemple d'appel ---------------------
|
---|
9 | csh> aksj02 -start 104385384 -end 104399964 -range -500,500 \
|
---|
10 | -intoi boloMuV_26 -wtoi 8192 -wclean 512,5 \
|
---|
11 | inputbolo.fits filt.fits xx.ppf
|
---|
12 | */
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 | #include "machdefs.h"
|
---|
17 | #include <math.h>
|
---|
18 | #include <unistd.h>
|
---|
19 |
|
---|
20 | #include "toimanager.h"
|
---|
21 | #include "cgt.h"
|
---|
22 | #include "fitstoirdr.h"
|
---|
23 | #include "fitstoiwtr.h"
|
---|
24 | #include "simtoipr.h"
|
---|
25 | #include "simoffset.h"
|
---|
26 | #include "simcleaner.h"
|
---|
27 | #include "nooppr.h"
|
---|
28 | #include "timing.h"
|
---|
29 | #include "histinit.h"
|
---|
30 | #include "psighand.h"
|
---|
31 | #include <stdexcept>
|
---|
32 |
|
---|
33 | void Usage(bool fgerr)
|
---|
34 | {
|
---|
35 | cout << endl;
|
---|
36 | if (fgerr) {
|
---|
37 | cout << " aksj02 : Argument Error ! aksj02 -h for usage " << endl;
|
---|
38 | exit(1);
|
---|
39 | }
|
---|
40 | else {
|
---|
41 | cout << "\n Usage : aksj02 [-intoi toiname] [-start snb] [-end sne] \n"
|
---|
42 | << " [-dbg] [-wtoi sz] [-wclean wsz,nbw] [-range min,max] \n"
|
---|
43 | << " [-soff wsz,nptfit,degpol] [-soffnt PPFName] \n"
|
---|
44 | << " [-bgalcut bmin,bmax] [-bgal toiname] [-bgalfile pointFitsName] \n"
|
---|
45 | << " [-soff2 wsz,nptfit,degpol] [-soff2nt PPFName] \n"
|
---|
46 | << " [-bgal2cut bmin,bmax] \n"
|
---|
47 | << " [-gfilt wsz,sigma] \n"
|
---|
48 | << " [-nooutflg] [-wrtms] [-wrtifo] [-prstat] [-useseqbuff] \n"
|
---|
49 | << " inFitsName outFitsName \n"
|
---|
50 | << " -dbg : sets TOISeqBuffered debug level to 1 \n"
|
---|
51 | << " -start snb : sets the start sample num \n"
|
---|
52 | << " -end sne : sets the end sample num \n"
|
---|
53 | << " -range min,max : sets the acceptable range for intoi \n"
|
---|
54 | << " default= -16000,16000\n"
|
---|
55 | << " -intoi toiName : select input TOI name (def bolo)\n"
|
---|
56 | << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
|
---|
57 | << " -wclean wsz,nbw : sets cleaner window parameters (256,5) \n"
|
---|
58 | << " -soff wsz,nptfit,degpol : set SimpleOffsetEstimator parameters\n"
|
---|
59 | << " -soffnt PPFName : Writes out SimpleOffsetEstimator NTuple \n"
|
---|
60 | << " -bgalcut bmin,bmax: Galactic latitude cut (in degree) for SimpleOffsetEstimator\n"
|
---|
61 | << " -bgal toiname: Galactic latitude toiname \n"
|
---|
62 | << " -bgalfile pointFitsName: Pointing FITS file name (for gal. latitude) \n"
|
---|
63 | << " -soff2 wsz,nptfit,degpol : set SimpleOffsetEstimator_2 parameters\n"
|
---|
64 | << " -soff2nt PPFName : Writes out SimpleOffsetEstimator_2 NTuple \n"
|
---|
65 | << " -bgal2cut bmin,bmax: Galactic latitude cut (in degree) for SimpleOffsetEstimator_2\n"
|
---|
66 | << " -gfilt wsz,sigma : Activate gaussian filter (par= window size, sigma) \n"
|
---|
67 | // << " -wfft sz : Activate Fourier filter and sets its width \n"
|
---|
68 | // << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
|
---|
69 | // << " -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
|
---|
70 | // << " with a gaussian with width=sigf \n"
|
---|
71 | << " -nooutflg : Don't write flags to output FITS \n"
|
---|
72 | << " -wrtms : Write mean/sigma TOI's from cleaner \n"
|
---|
73 | << " -wrtifo : Write incopie flagged TOI's from cleaner/ offset from SimpleOffsetEstimator \n"
|
---|
74 | << " -prstat : PrintStat with ProcSampleCounter \n"
|
---|
75 | << " -useseqbuff : Use TOISeqBuffered TOI's (default: TOISegmented) \n"
|
---|
76 | << endl;
|
---|
77 | }
|
---|
78 | if (fgerr) exit(1);
|
---|
79 | }
|
---|
80 |
|
---|
81 | int main(int narg, char** arg) {
|
---|
82 |
|
---|
83 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
|
---|
84 |
|
---|
85 | cout << "aksj02 starting - Decoding arguments " << " narg=" << narg << endl;
|
---|
86 |
|
---|
87 | bool fgdbg = false;
|
---|
88 | bool fgsetstart = false;
|
---|
89 |
|
---|
90 | bool fgprstat = false;
|
---|
91 | bool fgsegmented = true;
|
---|
92 |
|
---|
93 | int dbglev = 0;
|
---|
94 |
|
---|
95 | int wtoi = 8192;
|
---|
96 | int wdegli = 512;
|
---|
97 |
|
---|
98 | int wfft = 4096;
|
---|
99 | int keepfft = 0;
|
---|
100 | int nmax = 10;
|
---|
101 | int istart = 0;
|
---|
102 | int iend = 0;
|
---|
103 |
|
---|
104 | double range_min = -16000;
|
---|
105 | double range_max = 16000.;
|
---|
106 |
|
---|
107 | // cleaner parameters
|
---|
108 | double clean_wsz = 256;
|
---|
109 | double clean_nbw = 5;
|
---|
110 |
|
---|
111 | // SimpleOffsetEstimator parameters
|
---|
112 | int soff_mwsz = 256;
|
---|
113 | int soff_nptfit = 5;
|
---|
114 | int soff_degpol = 2;
|
---|
115 | bool soff_nt = false;
|
---|
116 | string soff_nt_ppfname = "";
|
---|
117 |
|
---|
118 | // SimpleOffsetEstimator (2) parameters
|
---|
119 | bool soff2_dofg = false;
|
---|
120 | int soff2_mwsz = 256;
|
---|
121 | int soff2_nptfit = 5;
|
---|
122 | int soff2_degpol = 2;
|
---|
123 | bool soff2_nt = false;
|
---|
124 | string soff2_nt_ppfname = "";
|
---|
125 |
|
---|
126 | // Gaussian filter parameters
|
---|
127 | bool gfilt_fg = false;
|
---|
128 | int gfilt_wsz = 16;
|
---|
129 | double gfilt_sigma = 2.;
|
---|
130 |
|
---|
131 | // Coordinate file for galactic cut
|
---|
132 | string pointfile = "pointgal.fits";
|
---|
133 | double bmin = -10;
|
---|
134 | double bmax = 10.;
|
---|
135 | bool bgalcut = false;
|
---|
136 | string bgaltoi = "bgal";
|
---|
137 | bool bgalfile = false;
|
---|
138 | double bmin2 = -10;
|
---|
139 | double bmax2 = 10.;
|
---|
140 | bool bgal2cut = false;
|
---|
141 |
|
---|
142 | // File names
|
---|
143 | string infile;
|
---|
144 | string outfile;
|
---|
145 | string outppfname;
|
---|
146 | string intoi = "bolo";
|
---|
147 |
|
---|
148 | bool fg_wrtflag = true;
|
---|
149 | bool fg_wrtms = false;
|
---|
150 | bool fg_wrtifo = false;
|
---|
151 |
|
---|
152 |
|
---|
153 | bool fg_f_filt = false;
|
---|
154 | bool fg_killfreq = false;
|
---|
155 | int bf_killfreq = 1;
|
---|
156 | int nharm_killfreq = 1;
|
---|
157 | double sigf_killfreq = 1.;
|
---|
158 |
|
---|
159 | if (narg < 4) Usage(true);
|
---|
160 | int ko=1;
|
---|
161 | // decoding arguments
|
---|
162 | for(int ia=1; ia<narg; ia++) {
|
---|
163 | if (strcmp(arg[ia],"-start") == 0) {
|
---|
164 | if (ia == narg-1) Usage(true); // -start est suivi d'un argument
|
---|
165 | istart = atoi(arg[ia+1]); ia++;
|
---|
166 | fgsetstart = true;
|
---|
167 | }
|
---|
168 | else if (strcmp(arg[ia],"-end") == 0) {
|
---|
169 | if (ia == narg-1) Usage(true);
|
---|
170 | iend = atoi(arg[ia+1]); ia++;
|
---|
171 | }
|
---|
172 | else if (strcmp(arg[ia],"-wtoi") == 0) {
|
---|
173 | if (ia == narg-1) Usage(true);
|
---|
174 | wtoi = atoi(arg[ia+1]); ia++;
|
---|
175 | }
|
---|
176 | else if (strcmp(arg[ia],"-wclean") == 0) {
|
---|
177 | if (ia == narg-1) Usage(true);
|
---|
178 | wdegli = atoi(arg[ia+1]); ia++;
|
---|
179 | sscanf(arg[ia+1],"%d,%d", &clean_wsz, &clean_nbw);
|
---|
180 | }
|
---|
181 | else if (strcmp(arg[ia],"-soff") == 0) {
|
---|
182 | if (ia == narg-1) Usage(true);
|
---|
183 | sscanf(arg[ia+1],"%d,%d,%d", &soff_mwsz, &soff_nptfit, &soff_degpol);
|
---|
184 | ia++;
|
---|
185 | }
|
---|
186 | else if (strcmp(arg[ia],"-soffnt") == 0) {
|
---|
187 | soff_nt = true;
|
---|
188 | soff_nt_ppfname = arg[ia+1]; ia++;
|
---|
189 | }
|
---|
190 | else if (strcmp(arg[ia],"-soff2") == 0) {
|
---|
191 | if (ia == narg-1) Usage(true);
|
---|
192 | soff2_dofg = true;
|
---|
193 | sscanf(arg[ia+1],"%d,%d,%d", &soff2_mwsz, &soff2_nptfit, &soff2_degpol);
|
---|
194 | ia++;
|
---|
195 | }
|
---|
196 | else if (strcmp(arg[ia],"-soff2nt") == 0) {
|
---|
197 | soff2_nt = true;
|
---|
198 | soff2_nt_ppfname = arg[ia+1]; ia++;
|
---|
199 | }
|
---|
200 | else if (strcmp(arg[ia],"-gfilt") == 0) {
|
---|
201 | if (ia == narg-1) Usage(true);
|
---|
202 | sscanf(arg[ia+1],"%d,%lf", &gfilt_wsz, &gfilt_sigma);
|
---|
203 | gfilt_fg = true;
|
---|
204 | ia++;
|
---|
205 | }
|
---|
206 | else if (strcmp(arg[ia],"-bgalcut") == 0) {
|
---|
207 | if (ia == narg-1) Usage(true);
|
---|
208 | sscanf(arg[ia+1],"%lf,%lf", &bmin, &bmax);
|
---|
209 | bgalcut = true;
|
---|
210 | ia++;
|
---|
211 | }
|
---|
212 | else if (strcmp(arg[ia],"-bgal2cut") == 0) {
|
---|
213 | if (ia == narg-1) Usage(true);
|
---|
214 | sscanf(arg[ia+1],"%lf,%lf", &bmin2, &bmax2);
|
---|
215 | bgal2cut = true;
|
---|
216 | ia++;
|
---|
217 | }
|
---|
218 | else if (strcmp(arg[ia],"-bgalfile") == 0) {
|
---|
219 | if (ia == narg-1) Usage(true);
|
---|
220 | pointfile = arg[ia+1];
|
---|
221 | bgalfile = true;
|
---|
222 | ia++;
|
---|
223 | }
|
---|
224 | else if (strcmp(arg[ia],"-bgal") == 0) {
|
---|
225 | if (ia == narg-1) Usage(true);
|
---|
226 | bgaltoi = arg[ia+1];
|
---|
227 | ia++;
|
---|
228 | }
|
---|
229 | else if (strcmp(arg[ia],"-range") == 0) {
|
---|
230 | if (ia == narg-1) Usage(true);
|
---|
231 | sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
|
---|
232 | ia++;
|
---|
233 | }
|
---|
234 | else if (strcmp(arg[ia],"-intoi") == 0) {
|
---|
235 | if (ia == narg-1) Usage(true);
|
---|
236 | intoi = arg[ia+1]; ia++;
|
---|
237 | }
|
---|
238 | else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
|
---|
239 | else if (strcmp(arg[ia],"-nooutflg") == 0) fg_wrtflag = false;
|
---|
240 | else if (strcmp(arg[ia],"-wrtms") == 0) fg_wrtms = true;
|
---|
241 | else if (strcmp(arg[ia],"-wrtifo") == 0) fg_wrtifo = true;
|
---|
242 |
|
---|
243 | else if (strcmp(arg[ia],"-prstat") == 0) fgprstat = true;
|
---|
244 | else if (strcmp(arg[ia],"-useseqbuff") == 0) fgsegmented = false;
|
---|
245 |
|
---|
246 | else { ko = ia; break; } // Debut des noms
|
---|
247 | }
|
---|
248 |
|
---|
249 | if (iend < istart) iend = istart+wtoi*(nmax+5);
|
---|
250 | if ((narg-ko) < 2) Usage(true);
|
---|
251 | infile = arg[ko];
|
---|
252 | outfile = arg[ko+1];
|
---|
253 | // outppfname = arg[ko+2];
|
---|
254 |
|
---|
255 | cout << " Initializing SOPHYA ... " << endl;
|
---|
256 | SophyaInit();
|
---|
257 | SophyaConfigureSignalhandling(true);
|
---|
258 |
|
---|
259 | InitTim();
|
---|
260 | if ((soff2_dofg == true) && (wtoi < 32768)) wtoi = 32768;
|
---|
261 | if (!bgalfile) bgalcut = bgal2cut = false;
|
---|
262 |
|
---|
263 | cout << ">>>> aksj02: Infile= " << infile << " outFile="
|
---|
264 | << outfile << endl;
|
---|
265 | cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
|
---|
266 | << " iStart= " << istart << " iEnd= " << iend << endl;
|
---|
267 | cout << ">>>> InTOIName= " << intoi << endl;
|
---|
268 |
|
---|
269 | try {
|
---|
270 | TOIManager* mgr = TOIManager::getManager();
|
---|
271 |
|
---|
272 | // mgr->setRequestedSample(11680920,11710584);
|
---|
273 | // mgr->setRequestedSample(104121000, 104946120);
|
---|
274 | if (fgsetstart)
|
---|
275 | mgr->setRequestedSample(istart, iend);
|
---|
276 |
|
---|
277 | cout << "> Creating FITSTOIReader object - InFile=" << infile << endl;
|
---|
278 | FITSTOIReader r(infile);
|
---|
279 |
|
---|
280 | cout << "> Creating SimpleCleaner() " << endl;
|
---|
281 | SimpleCleaner cleaner(clean_wsz, clean_nbw);
|
---|
282 | cout << " Setting Range for cleaner: " << range_min
|
---|
283 | << " - " << range_max << endl;
|
---|
284 | cleaner.SetRange(range_min, range_max);
|
---|
285 |
|
---|
286 | cout << "> Creating SimpleOffsetEstimator(" << soff_mwsz << "," << soff_nptfit
|
---|
287 | << "," << soff_degpol << ")" << endl;
|
---|
288 | SimpleOffsetEstimator offes(soff_mwsz, soff_nptfit, soff_degpol);
|
---|
289 | offes.SavePolyNTuple(soff_nt, soff_nt_ppfname);
|
---|
290 |
|
---|
291 | SimpleOffsetEstimator* offes2 = NULL;
|
---|
292 | if (soff2_dofg) {
|
---|
293 | cout << "> Creating 2nd SimpleOffsetEstimator(" << soff2_mwsz << "," << soff2_nptfit
|
---|
294 | << "," << soff2_degpol << ")" << endl;
|
---|
295 | offes2 = new SimpleOffsetEstimator(soff2_mwsz, soff2_nptfit, soff2_degpol);
|
---|
296 | offes2->SavePolyNTuple(soff2_nt, soff2_nt_ppfname);
|
---|
297 | }
|
---|
298 |
|
---|
299 | SimpleFilter *filt = NULL;
|
---|
300 | if (gfilt_fg) {
|
---|
301 | cout << "> Creating a GaussianFilter SimpleFilter Object " << endl;
|
---|
302 | double G_sigma = gfilt_sigma;
|
---|
303 | double G_a = 1./(G_sigma*sqrt(M_PI*2.));
|
---|
304 | filt = new SimpleFilter(gfilt_wsz, SimpleFilter::GaussFilter, G_a, G_sigma);
|
---|
305 | }
|
---|
306 |
|
---|
307 | FITSTOIReader* rbgal = NULL;
|
---|
308 | if (bgalfile) { // if Galactic cut
|
---|
309 | cout << "> Creating bgal FITSTOIReader object - InFile=" << pointfile
|
---|
310 | << " bgaltoiname= " << bgaltoi << endl;
|
---|
311 | rbgal = new FITSTOIReader(pointfile);
|
---|
312 | }
|
---|
313 |
|
---|
314 | if (bgalfile && bgalcut) {
|
---|
315 | cout << " offes.SetBGalCut( " << bmin << "," << bmax << ")" << endl;
|
---|
316 | offes.SetBGalCut(bmin, bmax);
|
---|
317 | }
|
---|
318 | if (soff2_dofg && bgalfile && bgal2cut) {
|
---|
319 | cout << " offes2.SetBGalCut( " << bmin2 << "," << bmax2 << ")" << endl;
|
---|
320 | offes2->SetBGalCut(bmin, bmax);
|
---|
321 | }
|
---|
322 |
|
---|
323 | cout << "> Creating FITSTOIWriter OutFitsName= " << outfile << endl;
|
---|
324 | FITSTOIWriter w(outfile);
|
---|
325 |
|
---|
326 | CGT plombier(fgsegmented, wtoi);
|
---|
327 | plombier.SetDebugLevel(dbglev);
|
---|
328 |
|
---|
329 | cout << "> Connecting Processors through plombier ... " << endl;
|
---|
330 | string inname = "in";
|
---|
331 | string outname = "out";
|
---|
332 | plombier.Connect(r, intoi, cleaner, inname);
|
---|
333 | plombier.Connect(cleaner, "out", offes, "in");
|
---|
334 |
|
---|
335 | if (soff2_dofg && bgalcut && bgal2cut ) {
|
---|
336 | inname = "bgal";
|
---|
337 | outname = "bgalcopie";
|
---|
338 | plombier.Connect(*rbgal, bgaltoi, offes, inname);
|
---|
339 | plombier.Connect(offes, outname, *offes2, inname);
|
---|
340 | }
|
---|
341 | else if (soff2_dofg && bgal2cut) {
|
---|
342 | inname = "bgal";
|
---|
343 | plombier.Connect(*rbgal, bgaltoi, *offes2, inname);
|
---|
344 | }
|
---|
345 | else if (bgalcut) {
|
---|
346 | inname = "bgal";
|
---|
347 | plombier.Connect(*rbgal, bgaltoi, offes, inname);
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (soff2_dofg) {
|
---|
351 | inname = "in";
|
---|
352 | outname = "out";
|
---|
353 | plombier.Connect(offes, outname, *offes2, inname);
|
---|
354 | }
|
---|
355 |
|
---|
356 | if (gfilt_fg) {
|
---|
357 | if (soff2_dofg)
|
---|
358 | plombier.Connect(*offes2, "out", *filt, "in");
|
---|
359 | else
|
---|
360 | plombier.Connect(offes, "out", *filt, "in");
|
---|
361 | plombier.Connect(*filt, "out", w, "outfcln", "", 0, fg_wrtflag);
|
---|
362 | }
|
---|
363 | else {
|
---|
364 | if (soff2_dofg)
|
---|
365 | plombier.Connect(*offes2, "out", w, "outcln", "", 0, fg_wrtflag);
|
---|
366 | else
|
---|
367 | plombier.Connect(offes, "out", w, "outcln", "", 0, fg_wrtflag);
|
---|
368 | }
|
---|
369 |
|
---|
370 | if (fg_wrtifo) {
|
---|
371 | plombier.Connect(offes, "incopie", w, "inflg", "", 1.5*wtoi, fg_wrtflag);
|
---|
372 | plombier.Connect(offes, "offset", w, "offset", "", 1.5*wtoi);
|
---|
373 | if (soff2_dofg)
|
---|
374 | plombier.Connect(*offes2, "offset", w, "offset2", "", 2*wtoi);
|
---|
375 | }
|
---|
376 | if (fg_wrtms) {
|
---|
377 | plombier.Connect(cleaner, "mean", w, "mean", "", 3*wtoi);
|
---|
378 | plombier.Connect(cleaner, "sigma", w, "sigma", "", 3*wtoi);
|
---|
379 | }
|
---|
380 |
|
---|
381 | cout << "> Plombier status before start" << endl;
|
---|
382 | cout << plombier ;
|
---|
383 |
|
---|
384 | cout << cleaner;
|
---|
385 | cout << offes;
|
---|
386 | if (soff2_dofg) cout << *offes2;
|
---|
387 | cout << w;
|
---|
388 |
|
---|
389 | PrtTim("starting processors");
|
---|
390 | plombier.Start();
|
---|
391 |
|
---|
392 |
|
---|
393 | // ------------------- Impression continu de stat ------------------------
|
---|
394 | if (fgprstat) {
|
---|
395 | ProcSampleCounter<SimpleOffsetEstimator> stats(offes);
|
---|
396 | stats.InfoMessage() = "aksj02/Info";
|
---|
397 | stats.PrintStats();
|
---|
398 | }
|
---|
399 | // -----------------------------------------------------------------------
|
---|
400 |
|
---|
401 | cout << cleaner;
|
---|
402 | cout << offes;
|
---|
403 | if (soff2_dofg) cout << *offes2;
|
---|
404 | if (gfilt_fg) cout << *filt;
|
---|
405 | cout << w;
|
---|
406 |
|
---|
407 | mgr->joinAll();
|
---|
408 | PrtTim("End threads");
|
---|
409 | if (bgalcut) delete rbgal;
|
---|
410 | if (gfilt_fg) delete filt;
|
---|
411 | if (soff2_dofg) delete offes2;
|
---|
412 | }
|
---|
413 | catch (PThrowable & exc) {
|
---|
414 | cerr << "\n aksj02: Catched Exception \n" << (string)typeid(exc).name()
|
---|
415 | << " - Msg= " << exc.Msg() << endl;
|
---|
416 | }
|
---|
417 | catch (const std::exception & sex) {
|
---|
418 | cerr << "\n aksj02: Catched std::exception \n"
|
---|
419 | << (string)typeid(sex).name() << endl;
|
---|
420 | }
|
---|
421 | catch (...) {
|
---|
422 | cerr << "\n aksj02: some other exception was caught ! " << endl;
|
---|
423 | }
|
---|
424 |
|
---|
425 | return(0);
|
---|
426 | }
|
---|