1 | //
|
---|
2 | // Analyse of Amas@Nancay runs by J.E Campagne (LAL)
|
---|
3 | // Version 0: 1/6/2011
|
---|
4 | //-----------------------------
|
---|
5 |
|
---|
6 | // Utilisation de SOPHYA pour faciliter les tests ...
|
---|
7 | #include "sopnamsp.h"
|
---|
8 | #include "machdefs.h"
|
---|
9 |
|
---|
10 | #include <stdlib.h>
|
---|
11 | #include <dirent.h>
|
---|
12 | #include <matharr.h>
|
---|
13 |
|
---|
14 | // include standard c/c++
|
---|
15 | #include <iostream>
|
---|
16 | #include <fstream>
|
---|
17 | #include <string>
|
---|
18 | #include <vector>
|
---|
19 | #include <map>
|
---|
20 | #include <functional>
|
---|
21 | #include <algorithm>
|
---|
22 | #include <numeric>
|
---|
23 | #include <list>
|
---|
24 | #include <exception>
|
---|
25 |
|
---|
26 | // include sophya mesure ressource CPU/memoire ...
|
---|
27 | #include "resusage.h"
|
---|
28 | #include "ctimer.h"
|
---|
29 | #include "timing.h"
|
---|
30 | #include "timestamp.h"
|
---|
31 | #include "strutilxx.h"
|
---|
32 | #include "ntuple.h"
|
---|
33 | #include "fioarr.h"
|
---|
34 | #include "tarrinit.h"
|
---|
35 | #include "histinit.h"
|
---|
36 | #include "fitsioserver.h"
|
---|
37 | #include "fiosinit.h"
|
---|
38 | #include "ppersist.h"
|
---|
39 |
|
---|
40 |
|
---|
41 | const sa_size_t NUMBER_OF_CHANNELS = 2;
|
---|
42 | const sa_size_t NUMBER_OF_FREQ = 8192;
|
---|
43 | const r_4 LOWER_FREQUENCY = 1250.0; //MHz
|
---|
44 | const r_4 TOTAL_BANDWIDTH = 250.0; //MHz
|
---|
45 |
|
---|
46 | //decalration of non class members functions
|
---|
47 | extern "C" {
|
---|
48 | int Usage(bool);
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | //----------------------------------------------------------
|
---|
53 | //Utility fonctions
|
---|
54 | // Function for deleting pointers in map.
|
---|
55 | template<class A, class B>
|
---|
56 | struct DeleteMapFntor
|
---|
57 | {
|
---|
58 | // Overloaded () operator.
|
---|
59 | // This will be called by for_each() function.
|
---|
60 | bool operator()(pair<A,B> x) const
|
---|
61 | {
|
---|
62 | // Assuming the second item of map is to be
|
---|
63 | // deleted. Change as you wish.
|
---|
64 | delete x.second;
|
---|
65 | return true;
|
---|
66 | }
|
---|
67 | };
|
---|
68 | //-----
|
---|
69 | bool compare(const pair<string,r_4>& i, const pair<string,r_4>& j) {
|
---|
70 | return i.second < j.second;
|
---|
71 | }
|
---|
72 | //-----
|
---|
73 | sa_size_t round_sa(r_4 r) {
|
---|
74 | return static_cast<sa_size_t>((r > 0.0) ? (r + 0.5) : (r - 0.5));
|
---|
75 | }
|
---|
76 | //-----
|
---|
77 | string StringToLower(string strToConvert){
|
---|
78 | //change each element of the string to lower case
|
---|
79 | for(unsigned int i=0;i<strToConvert.length();i++) {
|
---|
80 | strToConvert[i] = tolower(strToConvert[i]);
|
---|
81 | }
|
---|
82 | return strToConvert;//return the converted string
|
---|
83 | }
|
---|
84 | //-----
|
---|
85 | //JEC 22/9/11 comparison, not case sensitive to sort File liste START
|
---|
86 | bool stringCompare( const string &left, const string &right ){
|
---|
87 | if( left.size() < right.size() )
|
---|
88 | return true;
|
---|
89 | ////////////POSSIBLY A BUG return false;
|
---|
90 | for( string::const_iterator lit = left.begin(), rit = right.begin(); lit != left.end() && rit != right.end(); ++lit, ++rit )
|
---|
91 | if( tolower( *lit ) < tolower( *rit ) )
|
---|
92 | return true;
|
---|
93 | else if( tolower( *lit ) > tolower( *rit ) )
|
---|
94 | return false;
|
---|
95 | return false; ///////TO BE FIXED
|
---|
96 | }//JEC 22/9/11 comparison, not case sensitive to sort File liste END
|
---|
97 | //-----
|
---|
98 | list<string> ListOfFileInDir(string dir, string filePettern) throw(string) {
|
---|
99 | list<string> theList;
|
---|
100 |
|
---|
101 |
|
---|
102 | DIR *dip;
|
---|
103 | struct dirent *dit;
|
---|
104 | string msg; string fileName;
|
---|
105 | string fullFileName;
|
---|
106 | size_t found;
|
---|
107 |
|
---|
108 | if ((dip=opendir(dir.c_str())) == NULL ) {
|
---|
109 | msg = "opendir failed on directory "+dir;
|
---|
110 | throw msg;
|
---|
111 | }
|
---|
112 | while ( (dit = readdir(dip)) != NULL ) {
|
---|
113 | fileName = dit->d_name;
|
---|
114 | found=fileName.find(filePettern);
|
---|
115 | if (found != string::npos) {
|
---|
116 | fullFileName = dir + "/";
|
---|
117 | fullFileName += fileName;
|
---|
118 | theList.push_back(fullFileName);
|
---|
119 | }
|
---|
120 | }//eo while
|
---|
121 | if (closedir(dip) == -1) {
|
---|
122 | msg = "closedir failed on directory "+dir;
|
---|
123 | throw msg;
|
---|
124 | }
|
---|
125 |
|
---|
126 | //JEC 22/9/11 START
|
---|
127 | theList.sort(stringCompare);
|
---|
128 | //JEC 22/9/11 END
|
---|
129 |
|
---|
130 | return theList;
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | //Declaration of local classes
|
---|
135 | //----------------------------------------------
|
---|
136 | //Process Interface
|
---|
137 | class IProcess {
|
---|
138 | public:
|
---|
139 | IProcess() {}
|
---|
140 | virtual ~IProcess() {}
|
---|
141 | virtual int processCmd() throw(string) =0;
|
---|
142 | };
|
---|
143 | //------------
|
---|
144 | //Common Process
|
---|
145 | class ProcessBase : public IProcess {
|
---|
146 | public:
|
---|
147 | ProcessBase();
|
---|
148 | virtual ~ProcessBase();
|
---|
149 | void SetInputPath(const string& inputPath) {inputPath_ = inputPath;}
|
---|
150 | void SetOutputPath(const string& outputPath) {outputPath_ = outputPath;}
|
---|
151 | void SetSourceName(const string& sourceName) {sourceName_ = sourceName;}
|
---|
152 | void SetDateOfRun(const string& dateOfRun) {dateOfRun_ = dateOfRun;}
|
---|
153 | void SetSpectraDirectory(const string& spectraDirectory) {spectraDirectory_ = spectraDirectory;}
|
---|
154 | void SetTypeOfFile(const string& typeOfFile) { typeOfFile_ = typeOfFile; }
|
---|
155 | void SetNumCycle(const string& numcycle) {numcycle_ = numcycle; }
|
---|
156 | void SetScaFileName(const string& scaFileName) { scaFileName_ =scaFileName; }
|
---|
157 |
|
---|
158 | void SetDebugLevel(const string& debuglev) {
|
---|
159 | debuglev_ = atoi(debuglev.c_str());
|
---|
160 | }
|
---|
161 |
|
---|
162 | virtual int processCmd() throw(string);
|
---|
163 |
|
---|
164 | protected:
|
---|
165 | string inputPath_;
|
---|
166 | string outputPath_;
|
---|
167 | string sourceName_;
|
---|
168 | string dateOfRun_;
|
---|
169 | string spectraDirectory_;
|
---|
170 | string typeOfFile_;
|
---|
171 |
|
---|
172 | string numcycle_; //cycle numbers format="first,last"
|
---|
173 | sa_size_t ifirstCycle_;
|
---|
174 | sa_size_t ilastCycle_;
|
---|
175 |
|
---|
176 |
|
---|
177 | uint_4 debuglev_;
|
---|
178 | string scaFileName_;
|
---|
179 | NTuple* scaTuple_;
|
---|
180 | map<sa_size_t,sa_size_t> idCycleInTuple_;
|
---|
181 | };
|
---|
182 | ProcessBase::ProcessBase() {
|
---|
183 | scaTuple_ = 0;
|
---|
184 | }
|
---|
185 | ProcessBase::~ProcessBase() {
|
---|
186 | if (scaTuple_) delete scaTuple_;
|
---|
187 | scaTuple_ = 0;
|
---|
188 | }
|
---|
189 | //------------
|
---|
190 | //Process ON/OFF data
|
---|
191 | //------------
|
---|
192 | class ProcessONOFFData : public ProcessBase {
|
---|
193 | protected:
|
---|
194 | string freqBAOCalibration_;//string MHz
|
---|
195 | public:
|
---|
196 | ProcessONOFFData(){}
|
---|
197 | virtual ~ProcessONOFFData(){}
|
---|
198 |
|
---|
199 | void SetFreqBAOCalibration(const string& freqBAOCalibration) {
|
---|
200 | freqBAOCalibration_ = freqBAOCalibration;
|
---|
201 | }
|
---|
202 |
|
---|
203 | virtual int processCmd() throw(string);
|
---|
204 | };
|
---|
205 |
|
---|
206 | //JEC 22/9/11 Make ON-OFF analysis WO any calibration START
|
---|
207 | //------------
|
---|
208 | //Process ON/OFF Raw data
|
---|
209 | //------------
|
---|
210 | class ProcessONOFFRawData : public ProcessBase {
|
---|
211 |
|
---|
212 | public:
|
---|
213 | ProcessONOFFRawData(){}
|
---|
214 | virtual ~ProcessONOFFRawData(){}
|
---|
215 |
|
---|
216 | virtual int processCmd() throw(string);
|
---|
217 | };
|
---|
218 | //JEC 22/9/11 Make ON-OFF analysis WO any calibration END
|
---|
219 |
|
---|
220 | //------------
|
---|
221 | //Process Gain
|
---|
222 | //------------
|
---|
223 | class ProcessGain : public ProcessBase {
|
---|
224 | protected:
|
---|
225 | string mode_; //mode of data taken for gain computation On || Off
|
---|
226 | public:
|
---|
227 | ProcessGain(){}
|
---|
228 | virtual ~ProcessGain(){}
|
---|
229 |
|
---|
230 | void SetMode(const string& mode) {mode_ = mode;}
|
---|
231 |
|
---|
232 | virtual int processCmd() throw(string);
|
---|
233 | };
|
---|
234 | //------------
|
---|
235 | //Process Calibration
|
---|
236 | //------------
|
---|
237 | class ProcessCalibration : public ProcessBase {
|
---|
238 | protected:
|
---|
239 | string option_; //option of calibration procedure
|
---|
240 | string freqBAOCalibration_;//string MHz
|
---|
241 | r_4 valfreqBAOCalibration_; //value MHz
|
---|
242 | string bandWidthBAOCalibration_;//string MHz
|
---|
243 | r_4 valbandWidthBAOCalibration_;//value MHz
|
---|
244 |
|
---|
245 | sa_size_t lowerFreqBin_;
|
---|
246 | sa_size_t upperFreqBin_;
|
---|
247 |
|
---|
248 | public:
|
---|
249 | ProcessCalibration() {}
|
---|
250 | virtual ~ProcessCalibration(){}
|
---|
251 |
|
---|
252 | void SetOption(const string& option) {option_ = option;}
|
---|
253 | void SetFreqBAOCalibration(const string& freqBAOCalibration) {
|
---|
254 | freqBAOCalibration_ = freqBAOCalibration;
|
---|
255 | valfreqBAOCalibration_ = atof(freqBAOCalibration_.c_str());
|
---|
256 | }
|
---|
257 | void SetBandWidthBAOCalibration(const string& bandWidthBAOCalibration) {
|
---|
258 | bandWidthBAOCalibration_ = bandWidthBAOCalibration;
|
---|
259 | valbandWidthBAOCalibration_ = atof(bandWidthBAOCalibration_.c_str());
|
---|
260 | }
|
---|
261 |
|
---|
262 | void ComputeLowerUpperFreqBin();
|
---|
263 |
|
---|
264 | virtual int processCmd() throw(string);
|
---|
265 | };
|
---|
266 | void ProcessCalibration::ComputeLowerUpperFreqBin() {
|
---|
267 | sa_size_t c0 = round_sa(NUMBER_OF_FREQ*(valfreqBAOCalibration_-LOWER_FREQUENCY)/TOTAL_BANDWIDTH);
|
---|
268 | sa_size_t dc = round_sa(NUMBER_OF_FREQ*valbandWidthBAOCalibration_/TOTAL_BANDWIDTH);
|
---|
269 | lowerFreqBin_ = c0-dc/2;
|
---|
270 | upperFreqBin_ = c0+dc/2;
|
---|
271 | }
|
---|
272 |
|
---|
273 |
|
---|
274 | //----------------------------------------------------
|
---|
275 | //----------------------------------------------------
|
---|
276 | int main(int narg, char* arg[])
|
---|
277 | {
|
---|
278 |
|
---|
279 | //Init process types
|
---|
280 | map<string,IProcess*> process;
|
---|
281 | //JEC 22/9/11 Make ON-OFF analysis WO any calibration START
|
---|
282 | process["rawOnOff"] = new ProcessONOFFRawData();
|
---|
283 | //JEC 22/9/11 Make ON-OFF analysis WO any calibration END
|
---|
284 | process["dataOnOff"] = new ProcessONOFFData();
|
---|
285 | process["gain"] = new ProcessGain();
|
---|
286 | process["calib"] = new ProcessCalibration();
|
---|
287 |
|
---|
288 | //Init Sophya related modules
|
---|
289 | // SophyaInit();
|
---|
290 | TArrayInitiator _inia; //nneded for TArray persistancy
|
---|
291 | FitsIOServerInit(); //needed for input file
|
---|
292 |
|
---|
293 | //message used in Exceptions
|
---|
294 | string msg;
|
---|
295 |
|
---|
296 | //Return code
|
---|
297 | int rc = 0;
|
---|
298 |
|
---|
299 | //Arguments managements
|
---|
300 | if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false);
|
---|
301 | if (narg<11) return Usage(true);
|
---|
302 |
|
---|
303 | string action;
|
---|
304 | string inputPath = ".";
|
---|
305 | string outputPath = ".";
|
---|
306 | string sourceName;
|
---|
307 | string scaFile;
|
---|
308 | string dateOfRun;
|
---|
309 | string spectraDirectory;
|
---|
310 | string freqBAOCalib = "";
|
---|
311 | string bandWidthBAOCalib = "";
|
---|
312 | string debuglev = "0";
|
---|
313 | string mode = "";
|
---|
314 | string numcycle;
|
---|
315 | string calibrationOpt = "";
|
---|
316 |
|
---|
317 | string typeOfFile="medfiltmtx";
|
---|
318 |
|
---|
319 |
|
---|
320 | // bool okarg=false;
|
---|
321 | int ka=1;
|
---|
322 | while (ka<(narg-1)) {
|
---|
323 | cout << "Debug arglist: <" << arg[ka] <<">" << endl;
|
---|
324 | if (strcmp(arg[ka],"-debug")==0) {
|
---|
325 | debuglev=arg[ka+1];
|
---|
326 | ka+=2;
|
---|
327 | }
|
---|
328 | else if (strcmp(arg[ka],"-act")==0) {
|
---|
329 | action=arg[ka+1];
|
---|
330 | ka+=2;
|
---|
331 | }
|
---|
332 | else if (strcmp(arg[ka],"-inPath")==0) {
|
---|
333 | inputPath=arg[ka+1];
|
---|
334 | ka+=2;
|
---|
335 | }
|
---|
336 | else if (strcmp(arg[ka],"-outPath")==0) {
|
---|
337 | outputPath=arg[ka+1];
|
---|
338 | ka+=2;
|
---|
339 | }
|
---|
340 | else if (strcmp(arg[ka],"-source")==0) {
|
---|
341 | sourceName=arg[ka+1];
|
---|
342 | ka+=2;
|
---|
343 | }
|
---|
344 | else if (strcmp(arg[ka],"-sca")==0) {
|
---|
345 | scaFile=arg[ka+1];
|
---|
346 | ka+=2;
|
---|
347 | }
|
---|
348 | else if (strcmp(arg[ka],"-date")==0) {
|
---|
349 | dateOfRun=arg[ka+1];
|
---|
350 | ka+=2;
|
---|
351 | }
|
---|
352 | else if (strcmp(arg[ka],"-specdir")==0) {
|
---|
353 | spectraDirectory=arg[ka+1];
|
---|
354 | ka+=2;
|
---|
355 | }
|
---|
356 | else if (strcmp(arg[ka],"-specname")==0) {
|
---|
357 | typeOfFile=arg[ka+1];
|
---|
358 | ka+=2;
|
---|
359 | }
|
---|
360 | else if (strcmp(arg[ka],"-freqBAOCalib")==0) {
|
---|
361 | freqBAOCalib = arg[ka+1];
|
---|
362 | ka+=2;
|
---|
363 | }
|
---|
364 | else if (strcmp(arg[ka],"-bwBAOCalib")==0) {
|
---|
365 | bandWidthBAOCalib = arg[ka+1];
|
---|
366 | ka+=2;
|
---|
367 | }
|
---|
368 | else if (strcmp(arg[ka],"-mode")==0) {
|
---|
369 | mode =arg[ka+1];
|
---|
370 | ka+=2;
|
---|
371 | }
|
---|
372 | else if (strcmp(arg[ka],"-numcycle")==0) {
|
---|
373 | numcycle =arg[ka+1];
|
---|
374 | ka+=2;
|
---|
375 | }
|
---|
376 | else if (strcmp(arg[ka],"-calibopt")==0) {
|
---|
377 | calibrationOpt =arg[ka+1];
|
---|
378 | ka+=2;
|
---|
379 | }
|
---|
380 | else ka++;
|
---|
381 | }//eo while
|
---|
382 |
|
---|
383 |
|
---|
384 | //JEC 21/9/11 Give the input parameters START
|
---|
385 | cout << "Dump Iiitial parameters ............" << endl;
|
---|
386 | cout << " action = " << action << "\n"
|
---|
387 | << " inputPath = " << inputPath << "\n"
|
---|
388 | << " outputPath = " << outputPath << "\n"
|
---|
389 | << " sourceName = " << sourceName << "\n"
|
---|
390 | << " scaFile = " << scaFile << "\n"
|
---|
391 | << " dateOfRun = " << dateOfRun << "\n"
|
---|
392 | << " spectraDirectory = " << spectraDirectory << "\n"
|
---|
393 | << " freqBAOCalib = " << freqBAOCalib << "\n"
|
---|
394 | << " bandWidthBAOCalib = " << bandWidthBAOCalib << "\n"
|
---|
395 | << " debuglev = " << debuglev << "\n"
|
---|
396 | << " mode = " << mode << "\n"
|
---|
397 | << " numcycle = " << numcycle << "\n"
|
---|
398 | << " calibrationOpt = " << calibrationOpt << endl;
|
---|
399 | cout << "...................................." << endl;
|
---|
400 | //JEC 21/9/11 Give the input parameters END
|
---|
401 |
|
---|
402 |
|
---|
403 | try {
|
---|
404 | //verification of action
|
---|
405 | if(process.find(action) == process.end()) {
|
---|
406 | msg = "action ";
|
---|
407 | msg += action + " not valid... FATAL";
|
---|
408 | rc = 999;
|
---|
409 | throw msg;
|
---|
410 | }
|
---|
411 |
|
---|
412 |
|
---|
413 | //
|
---|
414 | //Process initialisation...
|
---|
415 | //
|
---|
416 | try {
|
---|
417 | ProcessBase* procbase = dynamic_cast<ProcessBase*>(process[action]);
|
---|
418 | if (procbase == 0) {
|
---|
419 | msg= "action ";
|
---|
420 | msg += action + "Not a <process base> type...FATAL";
|
---|
421 | rc = 999;
|
---|
422 | throw msg;
|
---|
423 | }
|
---|
424 | procbase->SetInputPath(inputPath);
|
---|
425 | procbase->SetOutputPath(outputPath);
|
---|
426 |
|
---|
427 | if ("" == sourceName) {
|
---|
428 | msg = "(FATAL) missingsourceName for action " + action;
|
---|
429 | Usage(true);
|
---|
430 | throw msg;
|
---|
431 | }
|
---|
432 | procbase->SetSourceName(sourceName);
|
---|
433 |
|
---|
434 | if ("" == dateOfRun) {
|
---|
435 | msg = "(FATAL) missing dateOfRun for action " + action;
|
---|
436 | Usage(true);
|
---|
437 | throw msg;
|
---|
438 | }
|
---|
439 | procbase->SetDateOfRun(dateOfRun);
|
---|
440 |
|
---|
441 |
|
---|
442 | if ("" == spectraDirectory) {
|
---|
443 | msg = "(FATAL) missing spectraDirectory for action " + action;
|
---|
444 | Usage(true);
|
---|
445 | throw msg;
|
---|
446 | }
|
---|
447 | procbase->SetSpectraDirectory(spectraDirectory);
|
---|
448 |
|
---|
449 | if ("" == scaFile) {
|
---|
450 | msg = "(FATAL) missing scaFile for action " + action;
|
---|
451 | Usage(true);
|
---|
452 | throw msg;
|
---|
453 | }
|
---|
454 | procbase->SetScaFileName(scaFile);
|
---|
455 |
|
---|
456 | if ("" == numcycle) {
|
---|
457 | msg = "(FATAL) missing cycle number for action " + action;
|
---|
458 | Usage(true);
|
---|
459 | throw msg;
|
---|
460 | }
|
---|
461 | procbase->SetNumCycle(numcycle);
|
---|
462 |
|
---|
463 |
|
---|
464 | procbase->SetTypeOfFile(typeOfFile);
|
---|
465 |
|
---|
466 | procbase->SetDebugLevel(debuglev);
|
---|
467 | }
|
---|
468 | catch(exception& e){
|
---|
469 | throw e.what();
|
---|
470 | }
|
---|
471 |
|
---|
472 | //JEC 22/9/11 Make ON-OFF analysis WO any calibration START
|
---|
473 | // try {
|
---|
474 | // ProcessONOFFRawData* procRawdata = dynamic_cast<ProcessONOFFRawData*>(process[action]);
|
---|
475 | // }
|
---|
476 | // catch(exception& e){
|
---|
477 | // throw e.what();
|
---|
478 | // }
|
---|
479 | //JEC 22/9/11 Make ON-OFF analysis WO any calibration END
|
---|
480 |
|
---|
481 |
|
---|
482 | try {
|
---|
483 | ProcessONOFFData* procdata = dynamic_cast<ProcessONOFFData*>(process[action]);
|
---|
484 | if (procdata) {
|
---|
485 | if (freqBAOCalib == "") {
|
---|
486 | msg = "(FATAL) missing calibration BAO frequency for action " + action;
|
---|
487 | Usage(true);
|
---|
488 | throw msg;
|
---|
489 | }
|
---|
490 | procdata->SetFreqBAOCalibration(freqBAOCalib);
|
---|
491 | }
|
---|
492 | }
|
---|
493 | catch(exception& e){
|
---|
494 | throw e.what();
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | try {
|
---|
499 | ProcessGain* procgain = dynamic_cast<ProcessGain*>(process[action]);
|
---|
500 | if(procgain) {
|
---|
501 | if (mode == "") {
|
---|
502 | msg = "(FATAL) missing mode-type for action " + action;
|
---|
503 | Usage(true);
|
---|
504 | throw msg;
|
---|
505 | }
|
---|
506 | procgain->SetMode(mode);
|
---|
507 | }
|
---|
508 | }
|
---|
509 | catch(exception& e){
|
---|
510 | throw e.what();
|
---|
511 | }
|
---|
512 |
|
---|
513 | try {
|
---|
514 | ProcessCalibration* proccalib = dynamic_cast<ProcessCalibration*>(process[action]);
|
---|
515 | if(proccalib) {
|
---|
516 | if (calibrationOpt == "") {
|
---|
517 | msg = "(FATAL) missing calibration option";
|
---|
518 | Usage(true);
|
---|
519 | throw msg;
|
---|
520 | }
|
---|
521 | if (freqBAOCalib == "") {
|
---|
522 | msg = "(FATAL) missing calibration BAO frequency for action " + action;
|
---|
523 | Usage(true);
|
---|
524 | throw msg;
|
---|
525 | }
|
---|
526 | if (bandWidthBAOCalib == "") {
|
---|
527 | msg = "(FATAL) missing calibration BAO frequency band width for action " + action;
|
---|
528 | Usage(true);
|
---|
529 | throw msg;
|
---|
530 | }
|
---|
531 | proccalib->SetOption(calibrationOpt);
|
---|
532 | proccalib->SetFreqBAOCalibration(freqBAOCalib);
|
---|
533 | proccalib->SetBandWidthBAOCalibration(bandWidthBAOCalib);
|
---|
534 | proccalib->ComputeLowerUpperFreqBin();
|
---|
535 | }
|
---|
536 | }
|
---|
537 | catch(exception& e){
|
---|
538 | throw e.what();
|
---|
539 | }
|
---|
540 |
|
---|
541 | //
|
---|
542 | //execute command
|
---|
543 | //
|
---|
544 | rc = process[action]->processCmd();
|
---|
545 |
|
---|
546 | }
|
---|
547 | catch (std::exception& sex) {
|
---|
548 | cerr << "\n analyse.cc std::exception :" << (string)typeid(sex).name()
|
---|
549 | << "\n msg= " << sex.what() << endl;
|
---|
550 | rc = 78;
|
---|
551 | }
|
---|
552 | catch ( string str ) {
|
---|
553 | cerr << "analyse.cc Exception raised: " << str << endl;
|
---|
554 | }
|
---|
555 | catch (...) {
|
---|
556 | cerr << " analyse.cc catched unknown (...) exception " << endl;
|
---|
557 | rc = 79;
|
---|
558 | }
|
---|
559 |
|
---|
560 |
|
---|
561 |
|
---|
562 |
|
---|
563 | cout << ">>>> analyse.cc ------- END ----------- RC=" << rc << endl;
|
---|
564 |
|
---|
565 | //Delete processes
|
---|
566 | for_each(process.begin(),process.end(), DeleteMapFntor<string,IProcess*>());
|
---|
567 |
|
---|
568 | return rc;
|
---|
569 | }
|
---|
570 |
|
---|
571 | //---------------------------------------------------
|
---|
572 | int Usage(bool flag) {
|
---|
573 | cout << "Analyse.cc usage...." << endl;
|
---|
574 | cout << "analyse -act <action_type>: dataOnOff, rawOnOff, gain, calib\n"
|
---|
575 | << " -inPath <path for input files: default='.'>\n"
|
---|
576 | << " -outPath <path for output files: default='.'>\n"
|
---|
577 | << " -source <source name> \n"
|
---|
578 | << " -date <YYYYMMDD>\n"
|
---|
579 | << " -sca <file name scaXYZ.sum.trans>\n"
|
---|
580 | << " -specdir <generic directory name of spectra fits files>\n"
|
---|
581 | << " -specname <generic name of spectra fits files>\n"
|
---|
582 | << " -freqBAOCalib <freq in MHZ> freq. of calibration BAO\n"
|
---|
583 | << " valid for act=dataOnOff\n"
|
---|
584 | << " -bwBAOCalib <band width MHz> band width arround central freq. for calibration BAO\n"
|
---|
585 | << " valid for act=calib\n"
|
---|
586 | << " -mode <mode_type>:\n"
|
---|
587 | << " valid for act=gain, mode_type: On, Off\n"
|
---|
588 | << " -numcycle <number>,<number>:\n"
|
---|
589 | << " valid for all actions"
|
---|
590 | << " -calibopt <option>:\n"
|
---|
591 | << " valid for act=calib: indiv OR mean (NOT USED)"
|
---|
592 | << " -debuglev <number> [0=default]\n"
|
---|
593 | << " 1: normal print\n"
|
---|
594 | << " 2: save intermediate spectra\n"
|
---|
595 | << endl;
|
---|
596 | if (flag) {
|
---|
597 | cout << "use <path>/analyse -h for detailed instructions" << endl;
|
---|
598 | return 5;
|
---|
599 | }
|
---|
600 | return 1;
|
---|
601 | }
|
---|
602 |
|
---|
603 | int ProcessBase::processCmd() throw(string) {
|
---|
604 | int rc =0;
|
---|
605 | string msg;
|
---|
606 | if(debuglev_>0)cout << "Process Base" << endl;
|
---|
607 | //------------------------
|
---|
608 | //Use the sca file informations
|
---|
609 | //------------------------
|
---|
610 | // string scaFullPathName = "./";
|
---|
611 | //TOBE FIXED scaFullPathName += sourceName_+"/"+dateOfRun_ + StringToLower(sourceName_)+"/";
|
---|
612 | string scaFullPathName = inputPath_ + "/"
|
---|
613 | + sourceName_+ "/" +dateOfRun_ + StringToLower(sourceName_)+ "/" + scaFileName_;
|
---|
614 | char* scaTupleColumnName[9] = {"cycle","stcalOn","spcalOn","stOn","spOn","stcalOff","spcalOff","stOff","spOff"};
|
---|
615 | scaTuple_ = new NTuple(9,scaTupleColumnName);
|
---|
616 | int n = scaTuple_->FillFromASCIIFile(scaFullPathName);
|
---|
617 | if(n<0){ //Error
|
---|
618 | msg = "(FATAL) NTuple error loading "+ scaFullPathName;
|
---|
619 | rc = 999;
|
---|
620 | throw msg;
|
---|
621 | }
|
---|
622 |
|
---|
623 | if(debuglev_>1){
|
---|
624 | cout << "ProcessBase::processCmd: dump tuple in " << scaFullPathName << endl;
|
---|
625 | scaTuple_->Show(cout);
|
---|
626 | }
|
---|
627 |
|
---|
628 |
|
---|
629 | //Get the cycles (here consider consecutive cycles)
|
---|
630 | //The SCA file cannot be used as the DAQ can miss some cycles...
|
---|
631 | // r_8 firstCycle, lastCycle;
|
---|
632 | // scaTuple_->GetMinMax("cycle",firstCycle,lastCycle);
|
---|
633 | // ifirstCycle_ = (sa_size_t)firstCycle;
|
---|
634 | // ilastCycle_ = (sa_size_t)lastCycle;
|
---|
635 | //Analyse the string given by -numcycle command line
|
---|
636 | int ai1=0,ai2=0;
|
---|
637 | sscanf(numcycle_.c_str(),"%d,%d",&ai1,&ai2);
|
---|
638 | ifirstCycle_ = (sa_size_t)ai1;
|
---|
639 | ilastCycle_ = (sa_size_t)ai2;
|
---|
640 |
|
---|
641 |
|
---|
642 | //associate cycle number to index line in tuple
|
---|
643 | sa_size_t nLines = scaTuple_->NbLines();
|
---|
644 | for(sa_size_t iL=0; iL<nLines; ++iL){
|
---|
645 | idCycleInTuple_[(sa_size_t)scaTuple_->GetCell(iL,"cycle")]=iL;
|
---|
646 | }
|
---|
647 |
|
---|
648 |
|
---|
649 | return rc;
|
---|
650 | }
|
---|
651 | //JEC 22/9/11 Make ON-OFF analysis WO any calibration START
|
---|
652 | //----------------------------------------------
|
---|
653 | int ProcessONOFFRawData::processCmd() throw(string) {
|
---|
654 | int rc = 0;
|
---|
655 | try {
|
---|
656 | rc = ProcessBase::processCmd();
|
---|
657 | }
|
---|
658 | catch (string s) {
|
---|
659 | throw s;
|
---|
660 | }
|
---|
661 | if(debuglev_>0)cout << "Process Raw Data ON OFF" << endl;
|
---|
662 | vector<string> modeList;
|
---|
663 | modeList.push_back("On");
|
---|
664 | modeList.push_back("Off");
|
---|
665 | vector<string>::const_iterator iMode;
|
---|
666 |
|
---|
667 | uint_4 id;
|
---|
668 | string tag;
|
---|
669 |
|
---|
670 | //
|
---|
671 | //Process to get sucessively
|
---|
672 | //Raw Spectra,
|
---|
673 | //The pocesses are separated to allow intermediate save of results
|
---|
674 |
|
---|
675 | map< pair<string, sa_size_t>, TMatrix<r_4> > spectreCollect;
|
---|
676 | map< pair<string, sa_size_t>, TMatrix<r_4> >::iterator iSpectre, iSpectreEnd;
|
---|
677 |
|
---|
678 | for (iMode = modeList.begin(); iMode != modeList.end(); ++iMode) {
|
---|
679 | string mode = *iMode;
|
---|
680 | if(debuglev_>0)cout << "Process RAW Mode " << mode << endl;
|
---|
681 |
|
---|
682 | //------------------------------------------
|
---|
683 | //Produce Raw spectra per cycle
|
---|
684 | //------------------------------------------
|
---|
685 |
|
---|
686 | string directoryName;
|
---|
687 | list<string> listOfSpecFiles;
|
---|
688 | list<string>::const_iterator iFile, iFileEnd;
|
---|
689 |
|
---|
690 |
|
---|
691 | //
|
---|
692 | //loop on cycles
|
---|
693 | //
|
---|
694 | for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
|
---|
695 | directoryName = "./" + mode + "/";
|
---|
696 | stringstream sicycle;
|
---|
697 | sicycle << icycle;
|
---|
698 | directoryName += spectraDirectory_ + sicycle.str() + "/";
|
---|
699 |
|
---|
700 | //read directory
|
---|
701 | listOfSpecFiles = ListOfFileInDir(directoryName,typeOfFile_);
|
---|
702 |
|
---|
703 |
|
---|
704 | //compute mean of spectra created in a cycle
|
---|
705 | if(debuglev_>0)cout << "compute mean for cycle " << icycle << endl;
|
---|
706 | TMatrix<r_4> spectreMean(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //implicit init to 0
|
---|
707 | iFileEnd = listOfSpecFiles.end();
|
---|
708 | r_4 nSpectres = 0;
|
---|
709 | for (iFile = listOfSpecFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
710 | FitsInOutFile aSpectrum(*iFile,FitsInOutFile::Fits_RO);
|
---|
711 | TMatrix<r_4> spectre(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
712 | aSpectrum >> spectre;
|
---|
713 | spectreMean += spectre;
|
---|
714 | nSpectres++;
|
---|
715 | }// end of for files
|
---|
716 | if(nSpectres>0) spectreMean /= nSpectres;
|
---|
717 |
|
---|
718 | //save mean spectrum
|
---|
719 | spectreCollect.insert( pair< pair<string,sa_size_t>, TMatrix<r_4> >(make_pair(mode,icycle),TMatrix<r_4>(spectreMean,false) ));
|
---|
720 | }//end of for cycles
|
---|
721 | }//end loop on mode for raw preocess
|
---|
722 |
|
---|
723 | //JEC 23/9/11 DO IT
|
---|
724 | // if(debuglev_>1) {//save mean spectra on file
|
---|
725 | cout << "Save mean raw spectra" << endl;
|
---|
726 | string fileName;
|
---|
727 | fileName = "./dataRaw_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
|
---|
728 |
|
---|
729 | POutPersist fos(fileName);
|
---|
730 | id=0;
|
---|
731 | iSpectreEnd = spectreCollect.end();
|
---|
732 | for (iSpectre = spectreCollect.begin();
|
---|
733 | iSpectre != iSpectreEnd ; ++iSpectre, ++id) {
|
---|
734 | tag = "specRaw";
|
---|
735 | tag += (iSpectre->first).first;
|
---|
736 | stringstream sid;
|
---|
737 | sid << (iSpectre->first).second;
|
---|
738 | tag += sid.str();
|
---|
739 | if(debuglev_>9) {
|
---|
740 | cout << "save tag<" << tag << ">" << endl;
|
---|
741 | }
|
---|
742 | fos << PPFNameTag(tag) << iSpectre->second;
|
---|
743 | }
|
---|
744 | // }//end of save fits
|
---|
745 |
|
---|
746 |
|
---|
747 | //------------------------------------------
|
---|
748 | // Perform ON-OFF
|
---|
749 | //------------------------------------------
|
---|
750 |
|
---|
751 | map< sa_size_t, TMatrix<r_4> > diffCollect;
|
---|
752 | map< sa_size_t, TMatrix<r_4> >::iterator iDiff, iDiffEnd;
|
---|
753 |
|
---|
754 | TMatrix<r_4> diffMeanOnOff(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //init zero
|
---|
755 | r_4 nCycles = 0;
|
---|
756 | for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
|
---|
757 | nCycles++;
|
---|
758 | TMatrix<r_4> specmtxOn(spectreCollect[make_pair(modeList[0],icycle)],false); //clone the memory
|
---|
759 | TMatrix<r_4> specmtxOff(spectreCollect[make_pair(modeList[1],icycle)],false); //clone the memory
|
---|
760 | TMatrix<r_4> diffOnOff = specmtxOn - specmtxOff;
|
---|
761 | diffCollect.insert(pair< sa_size_t,TMatrix<r_4> >(icycle,TMatrix<r_4>(diffOnOff,false) ));
|
---|
762 | diffMeanOnOff += diffOnOff;
|
---|
763 | }//end loop on cycle
|
---|
764 | if(nCycles>0) diffMeanOnOff/=nCycles;
|
---|
765 |
|
---|
766 | //exctract channels and do the mean
|
---|
767 | TVector<r_4> meanOfChan(NUMBER_OF_FREQ); //implicitly init to 0
|
---|
768 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh) {
|
---|
769 | meanOfChan += diffMeanOnOff.Row(iCh).Transpose();
|
---|
770 | }
|
---|
771 | meanOfChan /= (r_4)NUMBER_OF_CHANNELS;
|
---|
772 |
|
---|
773 |
|
---|
774 |
|
---|
775 | {//save diff ON-OFF on Raw data
|
---|
776 | if(debuglev_>0)cout << "save ON-OFF RAW spectra" << endl;
|
---|
777 | string fileName;
|
---|
778 | fileName = "./diffOnOffRaw_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
|
---|
779 | POutPersist fos(fileName);
|
---|
780 | iDiffEnd = diffCollect.end();
|
---|
781 | id = 0;
|
---|
782 |
|
---|
783 | //JEC 22/9/11 Mean & Sigma in 32-bins size START
|
---|
784 | sa_size_t nSliceFreq = 32; //TODO: put as an input parameter option ?
|
---|
785 | sa_size_t deltaFreq = NUMBER_OF_FREQ/nSliceFreq;
|
---|
786 | //JEC 22/9/11 Mean & Sigma in 32-bins size END
|
---|
787 |
|
---|
788 | for (iDiff = diffCollect.begin();iDiff != iDiffEnd ; ++iDiff, id++) {
|
---|
789 | tag = "specONOFFRaw";
|
---|
790 | stringstream sid;
|
---|
791 | sid << iDiff->first;
|
---|
792 | tag += sid.str();
|
---|
793 | fos << PPFNameTag(tag) << iDiff->second;
|
---|
794 |
|
---|
795 | //JEC 22/9/11 Mean & Sigma in 32-bins size START
|
---|
796 | if (debuglev_>9) {
|
---|
797 | cout << "Debug slicing: slice/delta " << nSliceFreq << " " << deltaFreq << endl;
|
---|
798 | }
|
---|
799 | TMatrix<r_4> reducedMeanDiffOnOff(NUMBER_OF_CHANNELS,nSliceFreq); //init 0 by default
|
---|
800 | TMatrix<r_4> reducedSigmaDiffOnOff(NUMBER_OF_CHANNELS,nSliceFreq); //init 0 by default
|
---|
801 | for (sa_size_t iSlice=0; iSlice<nSliceFreq; iSlice++){
|
---|
802 | sa_size_t freqLow= iSlice*deltaFreq;
|
---|
803 | sa_size_t freqHigh= freqLow + deltaFreq -1;
|
---|
804 | if (debuglev_>9) {
|
---|
805 | cout << "Debug .......... slicing ["<< iSlice << "]: low/high freq" << freqLow << "/" << freqHigh << endl;
|
---|
806 | }
|
---|
807 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh){
|
---|
808 | if (debuglev_>9) {
|
---|
809 | cout << "Debug .......... Channel " << iCh;
|
---|
810 | }
|
---|
811 | TVector<r_4> reducedRow;
|
---|
812 | reducedRow = (iDiff->second).SubMatrix(Range(iCh),Range(freqLow,freqHigh)).CompactAllDimensions();
|
---|
813 | double mean;
|
---|
814 | double sigma;
|
---|
815 | MeanSigma(reducedRow,mean,sigma);
|
---|
816 | if (debuglev_>9) {
|
---|
817 | cout << "mean/signa " << mean << "/" << sigma << endl;
|
---|
818 | }
|
---|
819 | reducedMeanDiffOnOff(iCh,iSlice) = mean;
|
---|
820 | reducedSigmaDiffOnOff(iCh,iSlice) = sigma;
|
---|
821 | }//loop on Channel
|
---|
822 | }//loop on Freq. slice
|
---|
823 | tag = "redMeanONOFFRaw";
|
---|
824 | tag += sid.str();
|
---|
825 | fos << PPFNameTag(tag) << reducedMeanDiffOnOff;
|
---|
826 | tag = "redSigmaONOFFRaw";
|
---|
827 | tag += sid.str();
|
---|
828 | fos << PPFNameTag(tag) << reducedSigmaDiffOnOff;
|
---|
829 | //JEC 22/9/11 END
|
---|
830 |
|
---|
831 | }//loop on ON-OFF spectre
|
---|
832 | //save the mean also
|
---|
833 | fos << PPFNameTag("specONOFFRawMean") << diffMeanOnOff;
|
---|
834 |
|
---|
835 | //JEC 22/9/11 START
|
---|
836 | TMatrix<r_4> reducedMeanDiffOnOffAll(NUMBER_OF_CHANNELS,nSliceFreq); //init 0 by default
|
---|
837 | TMatrix<r_4> reducedSigmaDiffOnOffAll(NUMBER_OF_CHANNELS,nSliceFreq); //init 0 by default
|
---|
838 | for (sa_size_t iSlice=0; iSlice<nSliceFreq; iSlice++){
|
---|
839 | sa_size_t freqLow= iSlice*deltaFreq;
|
---|
840 | sa_size_t freqHigh= freqLow + deltaFreq -1;
|
---|
841 | if (debuglev_>9) {
|
---|
842 | cout << "Debug .......... slicing ["<< iSlice << "]: low/high freq" << freqLow << "/" << freqHigh << endl;
|
---|
843 | }
|
---|
844 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh){
|
---|
845 | if (debuglev_>9) {
|
---|
846 | cout << "Debug .......... Channel " << iCh;
|
---|
847 | }
|
---|
848 | TVector<r_4> reducedRow;
|
---|
849 | reducedRow = diffMeanOnOff.SubMatrix(Range(iCh),Range(freqLow,freqHigh)).CompactAllDimensions();
|
---|
850 | double mean;
|
---|
851 | double sigma;
|
---|
852 | MeanSigma(reducedRow,mean,sigma);
|
---|
853 | if (debuglev_>9) {
|
---|
854 | cout << "mean/signa " << mean << "/" << sigma << endl;
|
---|
855 | }
|
---|
856 | reducedMeanDiffOnOffAll(iCh,iSlice) = mean;
|
---|
857 | reducedSigmaDiffOnOffAll(iCh,iSlice) = sigma;
|
---|
858 | }//loop on Channel
|
---|
859 | }//loop on Freq. slice
|
---|
860 | tag = "redMeanONOFFRawAll";
|
---|
861 | fos << PPFNameTag(tag) << reducedMeanDiffOnOffAll;
|
---|
862 | tag = "redSigmaONOFFRawAll";
|
---|
863 | fos << PPFNameTag(tag) << reducedSigmaDiffOnOffAll;
|
---|
864 | //JEC 22/9/11 END
|
---|
865 |
|
---|
866 |
|
---|
867 |
|
---|
868 | fos << PPFNameTag("specONOFFRaw2ChanMean") << meanOfChan;
|
---|
869 | }//end of save fits
|
---|
870 |
|
---|
871 |
|
---|
872 | cout << "OK rawOnOff finished" <<endl;
|
---|
873 | return rc;
|
---|
874 | } //ProcessONOFFRawData::processCmd
|
---|
875 |
|
---|
876 | //JEC 22/9/11 Make ON-OFF analysis WO any calibration END
|
---|
877 | //----------------------------------------------
|
---|
878 | int ProcessONOFFData::processCmd() throw(string) {
|
---|
879 | int rc = 0;
|
---|
880 | try {
|
---|
881 | rc = ProcessBase::processCmd();
|
---|
882 | }
|
---|
883 | catch (string s) {
|
---|
884 | throw s;
|
---|
885 | }
|
---|
886 | if(debuglev_>0)cout << "Process Data" << endl;
|
---|
887 | vector<string> modeList;
|
---|
888 | modeList.push_back("On");
|
---|
889 | modeList.push_back("Off");
|
---|
890 | vector<string>::const_iterator iMode;
|
---|
891 |
|
---|
892 | uint_4 id;
|
---|
893 | string tag;
|
---|
894 |
|
---|
895 | //
|
---|
896 | //Process to get sucessively
|
---|
897 | //Raw Spectra,
|
---|
898 | //BAO Calibrated Spectra
|
---|
899 | //and RT Calibrated Spectra
|
---|
900 | //The pocesses are separated to allow intermediate save of results
|
---|
901 |
|
---|
902 | map< pair<string, sa_size_t>, TMatrix<r_4> > spectreCollect;
|
---|
903 | map< pair<string, sa_size_t>, TMatrix<r_4> >::iterator iSpectre, iSpectreEnd;
|
---|
904 |
|
---|
905 | for (iMode = modeList.begin(); iMode != modeList.end(); ++iMode) {
|
---|
906 | string mode = *iMode;
|
---|
907 | if(debuglev_>0)cout << "Process RAW Mode " << mode << endl;
|
---|
908 |
|
---|
909 | //------------------------------------------
|
---|
910 | //Produce Raw spectra per cycle
|
---|
911 | //------------------------------------------
|
---|
912 |
|
---|
913 | string directoryName;
|
---|
914 | list<string> listOfSpecFiles;
|
---|
915 | list<string>::const_iterator iFile, iFileEnd;
|
---|
916 |
|
---|
917 |
|
---|
918 | //
|
---|
919 | //loop on cycles
|
---|
920 | //
|
---|
921 | for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
|
---|
922 | //TOBE FIXED directoryName = "./" + sourceName_ + "/"+ dateOfRun_ + StringToLower(sourceName_) + "/" +mode + "/";
|
---|
923 | directoryName = "./" + mode + "/";
|
---|
924 | stringstream sicycle;
|
---|
925 | sicycle << icycle;
|
---|
926 | directoryName += spectraDirectory_ + sicycle.str() + "/";
|
---|
927 |
|
---|
928 | //read directory
|
---|
929 | listOfSpecFiles = ListOfFileInDir(directoryName,typeOfFile_);
|
---|
930 |
|
---|
931 |
|
---|
932 | //compute mean of spectra created in a cycle
|
---|
933 | if(debuglev_>0)cout << "compute mean for cycle " << icycle << endl;
|
---|
934 | TMatrix<r_4> spectreMean(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //implicit init to 0
|
---|
935 | iFileEnd = listOfSpecFiles.end();
|
---|
936 | r_4 nSpectres = 0;
|
---|
937 | for (iFile = listOfSpecFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
938 | FitsInOutFile aSpectrum(*iFile,FitsInOutFile::Fits_RO);
|
---|
939 | TMatrix<r_4> spectre(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
940 | aSpectrum >> spectre;
|
---|
941 | spectreMean += spectre;
|
---|
942 | nSpectres++;
|
---|
943 | }// end of for files
|
---|
944 | if(nSpectres>0) spectreMean /= nSpectres;
|
---|
945 |
|
---|
946 | //save mean spectrum
|
---|
947 | spectreCollect.insert( pair< pair<string,sa_size_t>, TMatrix<r_4> >(make_pair(mode,icycle),TMatrix<r_4>(spectreMean,false) ));
|
---|
948 | }//end of for cycles
|
---|
949 | }//end loop on mode for raw preocess
|
---|
950 |
|
---|
951 | if(debuglev_>1) {//save mean spectra on file
|
---|
952 | cout << "Save mean raw spectra" << endl;
|
---|
953 | string fileName;
|
---|
954 | //TOBE FIXED fileName = "./" + sourceName_ + "/" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_" + "dataRaw" + ".ppf";
|
---|
955 | fileName = "./dataRaw_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
|
---|
956 |
|
---|
957 | POutPersist fos(fileName);
|
---|
958 | id=0;
|
---|
959 | iSpectreEnd = spectreCollect.end();
|
---|
960 | for (iSpectre = spectreCollect.begin();
|
---|
961 | iSpectre != iSpectreEnd ; ++iSpectre, ++id) {
|
---|
962 | tag = "specRaw";
|
---|
963 |
|
---|
964 | //JEC 20/9/11 modif tag to take into account Mode and Cycle number START
|
---|
965 | // stringstream sid;
|
---|
966 | // sid << id;
|
---|
967 | // tag += sid.str();
|
---|
968 | tag += (iSpectre->first).first;
|
---|
969 | stringstream sid;
|
---|
970 | sid << (iSpectre->first).second;
|
---|
971 | tag += sid.str();
|
---|
972 | if(debuglev_>9) {
|
---|
973 | cout << "save tag<" << tag << ">" << endl;
|
---|
974 | }
|
---|
975 | //JEC 20/9/11 modif tag to take into account Mode and Cycle number END
|
---|
976 |
|
---|
977 | fos << PPFNameTag(tag) << iSpectre->second;
|
---|
978 | }
|
---|
979 | }//end of save fits
|
---|
980 |
|
---|
981 |
|
---|
982 |
|
---|
983 | for (iMode = modeList.begin(); iMode != modeList.end(); ++iMode) {
|
---|
984 | string mode = *iMode;
|
---|
985 | if(debuglev_>0)cout << "Process CALIB BAO Mode " << mode << endl;
|
---|
986 | //------------------------------------------
|
---|
987 | // Correct Raw spectra for BAO calibration
|
---|
988 | //------------------------------------------
|
---|
989 | //Read BAO calibration files
|
---|
990 | sa_size_t nr,nc; //values read
|
---|
991 |
|
---|
992 | //JEC 20/9/11 use mean calibration coeff upon all cycles START
|
---|
993 | string calibFileName = inputPath_+ "/"
|
---|
994 | + sourceName_ + "/" + dateOfRun_ + StringToLower(sourceName_)
|
---|
995 | + "/calib_" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_"
|
---|
996 | + mode + "_" + freqBAOCalibration_ + "MHz-All.txt";
|
---|
997 |
|
---|
998 | if(debuglev_>0) cout << "Read file " << calibFileName << endl;
|
---|
999 | ifstream ifs(calibFileName.c_str());
|
---|
1000 | if ( ! ifs.is_open() ) {
|
---|
1001 | rc = 999;
|
---|
1002 | throw calibFileName + " cannot be opened...";
|
---|
1003 | }
|
---|
1004 | TVector<r_4> calibBAOfactors;
|
---|
1005 | if(debuglev_>9) cout << "Debug 1" << endl;
|
---|
1006 | calibBAOfactors.ReadASCII(ifs,nr,nc);
|
---|
1007 | if(debuglev_>9){
|
---|
1008 | cout << "Debug 2: (nr,nc): "<< nr << "," << nc << endl;
|
---|
1009 | calibBAOfactors.Print(cout);
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | //JEC 20/9/11 use mean calibration coeff upon all cycles END
|
---|
1013 |
|
---|
1014 | //
|
---|
1015 | //spectra corrected by BAO calibration factor
|
---|
1016 | //-----make it different on Channels and Cycles (1/06/2011) OBSOLETE
|
---|
1017 | //use mean calibration coeff upon all cycles (20/6/11)
|
---|
1018 | //warning cycles are numbered from 1,...,N
|
---|
1019 | //
|
---|
1020 | if(debuglev_>0)cout << "do calibration..." << endl;
|
---|
1021 | for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
|
---|
1022 | TMatrix<r_4> specmtx(spectreCollect[make_pair(mode,icycle)],true); //share the memory
|
---|
1023 |
|
---|
1024 | for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
|
---|
1025 | //JEC 20/9/11 use mean calibration coeff upon all cycles START
|
---|
1026 |
|
---|
1027 | // specmtx( Range(iCh), Range::all() ) /= calibBAOfactors(iCh,icycle-1);
|
---|
1028 | specmtx( Range(iCh), Range::all() ) /= calibBAOfactors(iCh);
|
---|
1029 | //JEC 20/9/11 use mean calibration coeff upon all cycles END
|
---|
1030 | }
|
---|
1031 | }
|
---|
1032 | } //end loop mode for BAO calib
|
---|
1033 |
|
---|
1034 | cout << "save calibrated BAO spectra" << endl;
|
---|
1035 | string fileName;
|
---|
1036 | //TO BE FIXED fileName = "./" + sourceName_ + "/" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_" + "dataBAOCalib" + ".ppf";
|
---|
1037 | fileName = "./dataBAOCalib_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
|
---|
1038 |
|
---|
1039 | POutPersist fos(fileName);
|
---|
1040 | iSpectreEnd = spectreCollect.end();
|
---|
1041 | id=0;
|
---|
1042 | for (iSpectre = spectreCollect.begin();iSpectre != iSpectreEnd ; ++iSpectre, ++id) {
|
---|
1043 |
|
---|
1044 | tag = "specBAOCalib";
|
---|
1045 | //JEC 20/9/11 modif tag to take into account Mode and Cycle number START
|
---|
1046 | // stringstream sid;
|
---|
1047 | // sid << id;
|
---|
1048 | // tag += sid.str();
|
---|
1049 | tag += (iSpectre->first).first;
|
---|
1050 | stringstream sid;
|
---|
1051 | sid << (iSpectre->first).second;
|
---|
1052 | tag += sid.str();
|
---|
1053 | if(debuglev_>9) {
|
---|
1054 | cout << "save tag<" << tag << ">" << endl;
|
---|
1055 | }
|
---|
1056 | //JEC 20/9/11 modif tag to take into account Mode and Cycle number END
|
---|
1057 |
|
---|
1058 | fos << PPFNameTag(tag) << iSpectre->second;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | for (iMode = modeList.begin(); iMode != modeList.end(); ++iMode) {
|
---|
1062 | string mode = *iMode;
|
---|
1063 | if(debuglev_>0)cout << "Process CALIB RT Mode " << mode << endl;
|
---|
1064 | //------------------------------------------
|
---|
1065 | // Correct BAO calib spectra for RT calibration
|
---|
1066 | //------------------------------------------
|
---|
1067 | //Very Preliminary May-June 11
|
---|
1068 | //coef RT @ 1346MHz Ouest - Est associees a Ch 0 et 1
|
---|
1069 | r_4 calibRT[NUMBER_OF_CHANNELS] = {27.724, 22.543};
|
---|
1070 | for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
|
---|
1071 | TMatrix<r_4> specmtx(spectreCollect[make_pair(mode,icycle)],true); //share the memory
|
---|
1072 | for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
|
---|
1073 | specmtx( Range(iCh), Range::all() ) *= calibRT[iCh];
|
---|
1074 | }
|
---|
1075 | }
|
---|
1076 | }//end loop on mode RT calib
|
---|
1077 |
|
---|
1078 | {//save mean spectra BAO & RT calibrated on file
|
---|
1079 | if(debuglev_>0)cout << "save calibrated BAO & RT spectra" << endl;
|
---|
1080 | string fileName;
|
---|
1081 | //TO BE FIXED fileName = "./" + sourceName_ + "/" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_" + "dataBAORTCalib" + ".ppf";
|
---|
1082 | fileName = "./dataBAORTCalib_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
|
---|
1083 | POutPersist fos(fileName);
|
---|
1084 | iSpectreEnd = spectreCollect.end();
|
---|
1085 | id = 0;
|
---|
1086 | for (iSpectre = spectreCollect.begin();iSpectre != iSpectreEnd ; ++iSpectre, ++id) {
|
---|
1087 | tag = "specBAORTCalib";
|
---|
1088 | //JEC 20/9/11 modif tag to take into account Mode and Cycle number START
|
---|
1089 | // stringstream sid;
|
---|
1090 | // sid << id;
|
---|
1091 | // tag += sid.str();
|
---|
1092 | tag += (iSpectre->first).first;
|
---|
1093 | stringstream sid;
|
---|
1094 | sid << (iSpectre->first).second;
|
---|
1095 | tag += sid.str();
|
---|
1096 | if(debuglev_>9) {
|
---|
1097 | cout << "save tag<" << tag << ">" << endl;
|
---|
1098 | }
|
---|
1099 | //JEC 20/9/11 modif tag to take into account Mode and Cycle number END
|
---|
1100 | fos << PPFNameTag(tag) << iSpectre->second;
|
---|
1101 | }
|
---|
1102 | }//end of save fits
|
---|
1103 |
|
---|
1104 | //------------------------------------------
|
---|
1105 | // Perform ON-OFF
|
---|
1106 | //------------------------------------------
|
---|
1107 |
|
---|
1108 | map< sa_size_t, TMatrix<r_4> > diffCollect;
|
---|
1109 | map< sa_size_t, TMatrix<r_4> >::iterator iDiff, iDiffEnd;
|
---|
1110 |
|
---|
1111 | TMatrix<r_4> diffMeanOnOff(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //init zero
|
---|
1112 | r_4 nCycles = 0;
|
---|
1113 | for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
|
---|
1114 | nCycles++;
|
---|
1115 | TMatrix<r_4> specmtxOn(spectreCollect[make_pair(modeList[0],icycle)],false); //clone the memory
|
---|
1116 | TMatrix<r_4> specmtxOff(spectreCollect[make_pair(modeList[1],icycle)],false); //clone the memory
|
---|
1117 | TMatrix<r_4> diffOnOff = specmtxOn - specmtxOff;
|
---|
1118 | diffCollect.insert(pair< sa_size_t,TMatrix<r_4> >(icycle,TMatrix<r_4>(diffOnOff,false) ));
|
---|
1119 | diffMeanOnOff += diffOnOff;
|
---|
1120 | }//end loop on cycle
|
---|
1121 | if(nCycles>0) diffMeanOnOff/=nCycles;
|
---|
1122 |
|
---|
1123 | //exctract channels and do the mean
|
---|
1124 | TVector<r_4> meanOfChan(NUMBER_OF_FREQ); //implicitly init to 0
|
---|
1125 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh) {
|
---|
1126 | meanOfChan += diffMeanOnOff.Row(iCh).Transpose();
|
---|
1127 | }
|
---|
1128 | meanOfChan /= (r_4)NUMBER_OF_CHANNELS;
|
---|
1129 |
|
---|
1130 |
|
---|
1131 |
|
---|
1132 | {//save diff ON-OFF BAO & RT calibrated
|
---|
1133 | if(debuglev_>0)cout << "save ON-OFF spectra" << endl;
|
---|
1134 | string fileName;
|
---|
1135 | //TO BE FIXED fileName = "./" + sourceName_ + "/" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_" + "diffOnOff" + ".ppf";
|
---|
1136 | fileName = "./diffOnOff_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
|
---|
1137 | POutPersist fos(fileName);
|
---|
1138 | iDiffEnd = diffCollect.end();
|
---|
1139 | id = 0;
|
---|
1140 | for (iDiff = diffCollect.begin();iDiff != iDiffEnd ; ++iDiff, id++) {
|
---|
1141 | tag = "specONOFF";
|
---|
1142 | stringstream sid;
|
---|
1143 | //JEC 20/9/11 sid << id;
|
---|
1144 | sid << iDiff->first;
|
---|
1145 | tag += sid.str();
|
---|
1146 | if(debuglev_>9) {
|
---|
1147 | cout << "save tag<" << tag << ">" << endl;
|
---|
1148 | }
|
---|
1149 | fos << PPFNameTag(tag) << iDiff->second;
|
---|
1150 | }
|
---|
1151 | //save the mean also
|
---|
1152 | fos << PPFNameTag("specONOFFMean") << diffMeanOnOff;
|
---|
1153 | fos << PPFNameTag("specONOFF2ChanMean") << meanOfChan;
|
---|
1154 | }//end of save fits
|
---|
1155 |
|
---|
1156 | cout << "OK dataOnOff finished";
|
---|
1157 |
|
---|
1158 | return rc;
|
---|
1159 | } //ProcessONOFFData::processCmd
|
---|
1160 | //
|
---|
1161 | //----------------------------------------------
|
---|
1162 | //
|
---|
1163 | int ProcessGain::processCmd() throw(string) {
|
---|
1164 | int rc = 0;
|
---|
1165 | string msg = "";
|
---|
1166 |
|
---|
1167 | try {
|
---|
1168 | rc = ProcessBase::processCmd();
|
---|
1169 | }
|
---|
1170 | catch (string s) {
|
---|
1171 | throw s;
|
---|
1172 | }
|
---|
1173 | if(debuglev_>0)cout << "Process Gain" << endl;
|
---|
1174 |
|
---|
1175 | string directoryName;
|
---|
1176 | //TOBE FIXED directoryName = "./" + sourceName_ + "/"+ dateOfRun_ + StringToLower(sourceName_) + "/" +mode_ + "/";
|
---|
1177 | //JEC 6/09/2011 numcycle_ repalced by ifirstCycle_ according to definition of numcycle_ and the fact that for GAIN 1 cycle is involved
|
---|
1178 | stringstream thegaincycle;
|
---|
1179 | thegaincycle << ifirstCycle_;
|
---|
1180 | directoryName = inputPath_ + "/"
|
---|
1181 | + sourceName_ + "/" + dateOfRun_ + StringToLower(sourceName_) + "/"
|
---|
1182 | + mode_ + "/" + spectraDirectory_ + thegaincycle.str() + "/";
|
---|
1183 |
|
---|
1184 | list<string> listOfSpecFiles;
|
---|
1185 | list<string>::const_iterator iFile, iFileEnd;
|
---|
1186 | //read directory
|
---|
1187 |
|
---|
1188 | listOfSpecFiles = ListOfFileInDir(directoryName,typeOfFile_);
|
---|
1189 |
|
---|
1190 | //Mean power computed over the N channels to select the spectra for gain computation
|
---|
1191 | //The threshold is computed "on-line" as 1% of the difference (max power -min power) over the
|
---|
1192 | // the min power.
|
---|
1193 | //A possible alternative is to set an absolute value...
|
---|
1194 | if(debuglev_>0)cout << "compute mean poser spectra for files in " << directoryName << endl;
|
---|
1195 | iFileEnd = listOfSpecFiles.end();
|
---|
1196 | map<string, r_4> meanpowerCollect;
|
---|
1197 | //JEC 21/9/11 add meanpower for each Channels START
|
---|
1198 | map<string, r_4> meanPowerPerChanCollect;
|
---|
1199 | //JEC 21/9/11 add meanpower for each Channels END
|
---|
1200 |
|
---|
1201 | map<string, r_4>::const_iterator iMeanPow, iMeanPowEnd;
|
---|
1202 |
|
---|
1203 | for (iFile = listOfSpecFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
1204 | FitsInOutFile aSpectrum(*iFile,FitsInOutFile::Fits_RO);
|
---|
1205 | TMatrix<r_4> spectre(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1206 | aSpectrum >> spectre;
|
---|
1207 | meanpowerCollect[*iFile] = spectre.Sum()/spectre.Size();
|
---|
1208 | //JEC 21/9/11 add meanpower for each Channels START
|
---|
1209 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh) {
|
---|
1210 | TVector<r_4> specChan(NUMBER_OF_FREQ);
|
---|
1211 | specChan = spectre.Row(iCh).Transpose();
|
---|
1212 | stringstream tmp;
|
---|
1213 | tmp << iCh;
|
---|
1214 | string tag = *iFile + "_" + tmp.str();
|
---|
1215 | meanPowerPerChanCollect[tag] = specChan.Sum()/specChan.Size();
|
---|
1216 | }
|
---|
1217 | //JEC 21/9/11 add meanpower for each Channels END
|
---|
1218 | }//end of for files
|
---|
1219 | pair<string, r_4> minelement = *min_element(meanpowerCollect.begin(),meanpowerCollect.end(),compare);
|
---|
1220 | pair<string, r_4> maxelement = *max_element(meanpowerCollect.begin(),meanpowerCollect.end(),compare);
|
---|
1221 | if(debuglev_>1){
|
---|
1222 | cout << "meanpowerCollect has " << meanpowerCollect.size() << " spectra registered" << endl;
|
---|
1223 | cout << "find min mean power "<<minelement.second << " for " << minelement.first << endl;
|
---|
1224 | cout << "find max mean power "<<maxelement.second << " for " << maxelement.first << endl;
|
---|
1225 | }
|
---|
1226 | r_4 threshold = minelement.second + 0.01*(maxelement.second-minelement.second);
|
---|
1227 | if(debuglev_>1){
|
---|
1228 | cout << "threshold found at " << threshold <<endl;
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | TMatrix<r_4> spectreMean(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //implicit init to 0
|
---|
1232 | r_4 nSpectres = 0;
|
---|
1233 | iMeanPowEnd = meanpowerCollect.end();
|
---|
1234 | for (iMeanPow = meanpowerCollect.begin(); iMeanPow != iMeanPowEnd; ++iMeanPow) {
|
---|
1235 | if ( iMeanPow->second <= threshold ) {
|
---|
1236 | //TODO avoid the reloading of the file may speed up
|
---|
1237 | FitsInOutFile aSpectrum(iMeanPow->first,FitsInOutFile::Fits_RO);
|
---|
1238 | TMatrix<r_4> spectre(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1239 | aSpectrum >> spectre;
|
---|
1240 | spectreMean += spectre;
|
---|
1241 | nSpectres++;
|
---|
1242 | }
|
---|
1243 | }
|
---|
1244 | if(debuglev_>1){
|
---|
1245 | cout << "Number of files selected for gain " << nSpectres <<endl;
|
---|
1246 | }
|
---|
1247 | if(nSpectres>0) {
|
---|
1248 | spectreMean /= nSpectres;
|
---|
1249 | } else {
|
---|
1250 | stringstream tmp;
|
---|
1251 | tmp << threshold;
|
---|
1252 | msg = "Gain: cannot find a spectra above threshold value =" + tmp.str() + " ... FATAL";
|
---|
1253 | throw msg;
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | //Save gain spectra
|
---|
1257 | {
|
---|
1258 | //use ! to override the file: special features of cfitsio library
|
---|
1259 | string fileName;
|
---|
1260 | //TOBE FIXED fileName = "!./" + sourceName_ + "/gain_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".fits";
|
---|
1261 | fileName = "!"+ outputPath_ + "/gain_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".fits";
|
---|
1262 | if(debuglev_>1){
|
---|
1263 | cout << "save gains in " << fileName << endl;
|
---|
1264 | }
|
---|
1265 | FitsInOutFile fos(fileName, FitsInOutFile::Fits_Create);
|
---|
1266 | fos << spectreMean;
|
---|
1267 | }
|
---|
1268 | //save mean power values
|
---|
1269 | {
|
---|
1270 | vector<r_4> tmp;
|
---|
1271 | //JEC 21/9/11 add meanpower for each Channels START
|
---|
1272 | vector<r_4> tmpCh0; //for Chan 0
|
---|
1273 | vector<r_4> tmpCh1; //for Chan 1
|
---|
1274 | //JEC 21/9/11 add meanpower for each Channels END
|
---|
1275 | for (iFile = listOfSpecFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
1276 | if (debuglev_>9) {
|
---|
1277 | cout << "Gain: save mean power of file: " << *iFile << endl;
|
---|
1278 | }
|
---|
1279 | tmp.push_back(meanpowerCollect[*iFile]);
|
---|
1280 | //JEC 21/9/11 add meanpower for each Channels START
|
---|
1281 | stringstream tmp0;
|
---|
1282 | tmp0 << (sa_size_t)0;
|
---|
1283 | string tag0 = *iFile + "_" + tmp0.str();
|
---|
1284 | tmpCh0.push_back(meanPowerPerChanCollect[tag0]);
|
---|
1285 | if (NUMBER_OF_CHANNELS>1){
|
---|
1286 | stringstream tmp1;
|
---|
1287 | tmp1 << (sa_size_t)1;
|
---|
1288 | string tag1 = *iFile + "_" + tmp1.str();
|
---|
1289 | tmpCh1.push_back(meanPowerPerChanCollect[tag1]);
|
---|
1290 | }
|
---|
1291 | //JEC 21/9/11 add meanpower for each Channels END
|
---|
1292 | }
|
---|
1293 | string fileName;
|
---|
1294 | //TOBE FIXED fileName = "./" + sourceName_ + "/gain_monitor_" + dateOfRun_
|
---|
1295 | fileName = outputPath_ + "/gain_monitor_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
|
---|
1296 | POutPersist fos(fileName);
|
---|
1297 | TVector<r_4> tvtmp(tmp);
|
---|
1298 | fos.PutObject(tvtmp,"gainmoni"); //Attention initialement le tag etait "monitor"...
|
---|
1299 | //JEC 21/9/11 add meanpower for each Channels START
|
---|
1300 | TVector<r_4> tvtmp0(tmpCh0);
|
---|
1301 | fos.PutObject(tvtmp0,"gainmoni0");
|
---|
1302 | if (NUMBER_OF_CHANNELS>1){
|
---|
1303 | TVector<r_4> tvtmp1(tmpCh1);
|
---|
1304 | fos.PutObject(tvtmp1,"gainmoni1");
|
---|
1305 | }
|
---|
1306 | //JEC 21/9/11 add meanpower for each Channels END
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | cout << "OK gain finished" <<endl;
|
---|
1310 | return rc;
|
---|
1311 | }//ProcessGain::processCmd
|
---|
1312 | //
|
---|
1313 | //----------------------------------------------
|
---|
1314 | //
|
---|
1315 | int ProcessCalibration::processCmd() throw(string) {
|
---|
1316 | int rc = 0;
|
---|
1317 | string msg = "";
|
---|
1318 |
|
---|
1319 | try {
|
---|
1320 | rc = ProcessBase::processCmd();
|
---|
1321 | }
|
---|
1322 | catch (string s) {
|
---|
1323 | throw s;
|
---|
1324 | }
|
---|
1325 | if(debuglev_>0)cout << "Process Calibration with option "<< option_ << endl;
|
---|
1326 |
|
---|
1327 | vector<string> modeList;
|
---|
1328 | modeList.push_back("On");
|
---|
1329 | modeList.push_back("Off");
|
---|
1330 |
|
---|
1331 | r_8 t0absolute = -1; //TIMEWIN of the first spectra used
|
---|
1332 | r_8 timeTag0 = -1; //MEANTT, mean TIME TAG of the first paquet window
|
---|
1333 | bool first = true; // for initialisation
|
---|
1334 |
|
---|
1335 | // Power Tuple
|
---|
1336 | // mode, cycle, time, {Ch0, ... ,ChN} mean poser in the range [f0-Bw/2, f0+Bw/2]
|
---|
1337 | vector<string> varPowerTupleName; //ntuple variable naming
|
---|
1338 | varPowerTupleName.push_back("mode");
|
---|
1339 | varPowerTupleName.push_back("cycle");
|
---|
1340 | varPowerTupleName.push_back("time");
|
---|
1341 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS;++iCh){
|
---|
1342 | stringstream tmp;
|
---|
1343 | tmp << iCh;
|
---|
1344 | varPowerTupleName.push_back("Ch"+tmp.str());
|
---|
1345 | }
|
---|
1346 | r_4 valPowerTuple[varPowerTupleName.size()];
|
---|
1347 | NTuple powerEvolution(varPowerTupleName);
|
---|
1348 |
|
---|
1349 |
|
---|
1350 | //-----------------
|
---|
1351 | //Start real process
|
---|
1352 | //------------------
|
---|
1353 | for (size_t iMode = 0; iMode < modeList.size(); ++iMode) {
|
---|
1354 | string mode = modeList[iMode];
|
---|
1355 | if(debuglev_>0)cout << "Process Calibration for Mode " << mode << endl;
|
---|
1356 |
|
---|
1357 | //initialize the start of each calibration procedure given by the RT SCA file
|
---|
1358 | //see ProcessBase::processCmd for the structure of the sca file
|
---|
1359 | string scaStartCalibName = "stcal"+mode;
|
---|
1360 | sa_size_t idStartCalib = scaTuple_->ColumnIndex(scaStartCalibName);
|
---|
1361 |
|
---|
1362 | string directoryName;
|
---|
1363 | list<string> listOfSpecFiles;
|
---|
1364 | list<string>::const_iterator iFile, iFileEnd;
|
---|
1365 | //
|
---|
1366 | //loop on cycles
|
---|
1367 | //
|
---|
1368 | for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
|
---|
1369 |
|
---|
1370 | directoryName = inputPath_ + "/"
|
---|
1371 | + sourceName_ + "/"+ dateOfRun_ + StringToLower(sourceName_) + "/" +mode + "/";
|
---|
1372 | stringstream sicycle;
|
---|
1373 | sicycle << icycle;
|
---|
1374 | directoryName += spectraDirectory_ + sicycle.str() + "/";
|
---|
1375 |
|
---|
1376 | //read directory
|
---|
1377 | listOfSpecFiles = ListOfFileInDir(directoryName,typeOfFile_);
|
---|
1378 |
|
---|
1379 | iFileEnd = listOfSpecFiles.end();
|
---|
1380 | DVList header;
|
---|
1381 | TMatrix<r_4> spectre(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //implicit init to 0
|
---|
1382 |
|
---|
1383 | for (iFile = listOfSpecFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
1384 | FitsInOutFile aSpectrum(*iFile,FitsInOutFile::Fits_RO);
|
---|
1385 | aSpectrum.GetHeaderRecords(header);
|
---|
1386 | aSpectrum >> spectre;
|
---|
1387 |
|
---|
1388 | if(first){//initialise the timer
|
---|
1389 | first = false;
|
---|
1390 | t0absolute = header.GetD("TIMEWIN")/1000.;
|
---|
1391 | timeTag0 = header.GetD("MEANTT");
|
---|
1392 | if (debuglev_>1){
|
---|
1393 | cout << "debug Header of " << *iFile << endl;
|
---|
1394 | cout << "TIMEWIN = " << setprecision(12) << t0absolute << " "
|
---|
1395 | << "MEANTT = " << setprecision(12) << timeTag0 << endl;
|
---|
1396 | }
|
---|
1397 | }//end init timer
|
---|
1398 |
|
---|
1399 | //Set time of current file
|
---|
1400 | //Add to the non-precise absolute origin an precise increment
|
---|
1401 | r_4 timeTag = t0absolute + (header.GetD("MEANTT") - timeTag0);
|
---|
1402 | int index=0;
|
---|
1403 | valPowerTuple[index++] = iMode;
|
---|
1404 | valPowerTuple[index++] = icycle;
|
---|
1405 | valPowerTuple[index++] = timeTag-scaTuple_->GetCell(idCycleInTuple_[icycle],idStartCalib); //take the RT time start as refernce
|
---|
1406 |
|
---|
1407 | //Compute the mean power of the two channel (separatly) in the range [f-bw/2, f+bw/2]
|
---|
1408 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS;++iCh){
|
---|
1409 | TMatrix<r_4> tmp(spectre(Range(iCh),Range(lowerFreqBin_,upperFreqBin_)),false);
|
---|
1410 | r_4 mean = tmp.Sum()/(r_4)tmp.Size();
|
---|
1411 | valPowerTuple[index++] = mean;
|
---|
1412 | }//end of channel loop
|
---|
1413 |
|
---|
1414 | //Fill Tuple
|
---|
1415 | powerEvolution.Fill(valPowerTuple);
|
---|
1416 | }//end of files loop
|
---|
1417 | }//end of cycles loop
|
---|
1418 | }//end of mode loop
|
---|
1419 |
|
---|
1420 | //store power evolution Tuple
|
---|
1421 | if(debuglev_>0){
|
---|
1422 | cout << "ProcessCalibration::processCmd: dump powerEvolution tuple" << endl;
|
---|
1423 | powerEvolution.Show(cout);
|
---|
1424 | }
|
---|
1425 | //
|
---|
1426 | //Compute Calibration Coefficients as function of mode/cycle/channels
|
---|
1427 | //
|
---|
1428 |
|
---|
1429 | //Tsys,Incremant Intensity... Tuple
|
---|
1430 | //mode mode cycle [(tsys0,dint0),...,(tsysN,dintN)]
|
---|
1431 | vector<string> varCalibTupleName;
|
---|
1432 | varCalibTupleName.push_back("mode");
|
---|
1433 | varCalibTupleName.push_back("cycle");
|
---|
1434 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS;++iCh){
|
---|
1435 | stringstream tmp;
|
---|
1436 | tmp << iCh;
|
---|
1437 | varCalibTupleName.push_back("tsys"+tmp.str());
|
---|
1438 | varCalibTupleName.push_back("dint"+tmp.str());
|
---|
1439 | }
|
---|
1440 | r_4 valCalibTuple[varCalibTupleName.size()];
|
---|
1441 | NTuple calibEvolution(varCalibTupleName);
|
---|
1442 |
|
---|
1443 | // select time E [twin0,twin1] U [twin2,twin3] for Tsys
|
---|
1444 | // time unit = second
|
---|
1445 | const r_4 twin0 = -3.;
|
---|
1446 | const r_4 twin1 = -1.;
|
---|
1447 | const r_4 twin2 = 6.;
|
---|
1448 | const r_4 twin3 = 8;
|
---|
1449 | const r_4 thresholdFactor = 0.20; //80% of the diff. Max-Min intensity
|
---|
1450 |
|
---|
1451 | sa_size_t inModeIdx = powerEvolution.ColumnIndex("mode");
|
---|
1452 | sa_size_t inCycleIdx= powerEvolution.ColumnIndex("cycle");
|
---|
1453 | sa_size_t inTimeIdx = powerEvolution.ColumnIndex("time");
|
---|
1454 | sa_size_t inOffsetCh0 = powerEvolution.ColumnIndex("Ch0"); //nb Ch0 position in the powerEvolution tuple
|
---|
1455 | if(debuglev_>1) cout << "DEBUG: in Idx: ("
|
---|
1456 | << inModeIdx << ", "
|
---|
1457 | << inCycleIdx << ", "
|
---|
1458 | << inTimeIdx << ", "
|
---|
1459 | << inOffsetCh0 << ")"
|
---|
1460 | << endl;
|
---|
1461 |
|
---|
1462 |
|
---|
1463 | size_t outModeIdx = calibEvolution.ColumnIndex("mode");
|
---|
1464 | size_t outCycleIdx= calibEvolution.ColumnIndex("cycle");
|
---|
1465 | size_t outOffsetCh0 = calibEvolution.ColumnIndex("tsys0"); //nb Ch0 position in the monitor tuple
|
---|
1466 | size_t outNDataPerCh= 2;
|
---|
1467 | if(debuglev_>1) cout << "DEBUG: out Idx: ("
|
---|
1468 | << outModeIdx << ", "
|
---|
1469 | << outCycleIdx << ", "
|
---|
1470 | << outOffsetCh0 << ")"
|
---|
1471 | << endl;
|
---|
1472 |
|
---|
1473 | sa_size_t nPowerEvolEntry = powerEvolution.NEntry();
|
---|
1474 | double minMode;
|
---|
1475 | double maxMode;
|
---|
1476 | powerEvolution.GetMinMax("mode",minMode,maxMode);
|
---|
1477 | double minCycleNum;
|
---|
1478 | double maxCycleNum;
|
---|
1479 | powerEvolution.GetMinMax("cycle",minCycleNum,maxCycleNum);
|
---|
1480 | if(debuglev_>1) cout << "DEBUG mode ("<<minMode<<","<<maxMode<<")\n"
|
---|
1481 | << "cycle ("<<minCycleNum<<","<<maxCycleNum<<")"
|
---|
1482 | << endl;
|
---|
1483 |
|
---|
1484 | r_4* aPowerEvolEntry; // a ligne of the powerEvolution tuple
|
---|
1485 | // r_4* aPowerEvolEntry = new r_4[powerEvolution.NbColumns()]; // a ligne of the powerEvolution tuple
|
---|
1486 |
|
---|
1487 | r_4 minMean;
|
---|
1488 | r_4 maxMean;
|
---|
1489 |
|
---|
1490 | for (size_t iMode = (size_t)minMode; iMode <= (size_t)maxMode; iMode++){
|
---|
1491 | for (size_t iCycle = (size_t)minCycleNum; iCycle <= (size_t)maxCycleNum; iCycle++ ){
|
---|
1492 | if(debuglev_>1) cout<<"DEBUG >>>>>>> mode/cycle: " << iMode << "/" << iCycle << endl;
|
---|
1493 |
|
---|
1494 | valCalibTuple[outModeIdx]=iMode;
|
---|
1495 | valCalibTuple[outCycleIdx]=iCycle;
|
---|
1496 | //
|
---|
1497 | //Compute the Min && Max value of each Ch<i> data
|
---|
1498 | if(debuglev_>1) cout<<"DEBUG compute Min and Max for each channels" << endl;
|
---|
1499 | //
|
---|
1500 | TVector<r_4> chMean[NUMBER_OF_CHANNELS];
|
---|
1501 | for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;iCh++){
|
---|
1502 | chMean[iCh].SetSize(nPowerEvolEntry);
|
---|
1503 | }
|
---|
1504 | for (sa_size_t ie=0; ie<nPowerEvolEntry; ie++){
|
---|
1505 | aPowerEvolEntry = powerEvolution.GetVec(ie);
|
---|
1506 | if ( (size_t)aPowerEvolEntry[inModeIdx] == iMode && (size_t)aPowerEvolEntry[inCycleIdx] == iCycle ){
|
---|
1507 | for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;iCh++){
|
---|
1508 | chMean[iCh](ie) = aPowerEvolEntry[iCh+inOffsetCh0];
|
---|
1509 | }//end cut
|
---|
1510 | }
|
---|
1511 | }//eo loop on tuple entries
|
---|
1512 | for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;iCh++){
|
---|
1513 | //
|
---|
1514 | //select values to compute background Tsys
|
---|
1515 | if(debuglev_>1) {
|
---|
1516 | cout<< "DEBUG >>>> Ch[" << iCh << "]" << endl;
|
---|
1517 | cout<< "DEBUG select values to compute background Tsys " << endl;
|
---|
1518 | }
|
---|
1519 | //
|
---|
1520 |
|
---|
1521 | std::vector<r_4> lowerInt;
|
---|
1522 | for (sa_size_t ie=0; ie<nPowerEvolEntry; ie++){
|
---|
1523 | aPowerEvolEntry = powerEvolution.GetVec(ie);
|
---|
1524 | if ( (size_t)aPowerEvolEntry[inModeIdx] == iMode && (size_t)aPowerEvolEntry[inCycleIdx] == iCycle ){
|
---|
1525 | r_4 time = aPowerEvolEntry[inTimeIdx];
|
---|
1526 | if ( (time >= twin0 && time <= twin1) ||
|
---|
1527 | (time >= twin2 && time <= twin3)
|
---|
1528 | ) lowerInt.push_back(aPowerEvolEntry[iCh+inOffsetCh0]);
|
---|
1529 | }//end cut
|
---|
1530 | } //end loop entries
|
---|
1531 | //
|
---|
1532 | //compute the Tsys
|
---|
1533 | if(debuglev_>1) cout <<"DEBUG compute Tsys" << endl;
|
---|
1534 | //
|
---|
1535 | std::nth_element(lowerInt.begin(),
|
---|
1536 | lowerInt.begin()+lowerInt.size()/2,
|
---|
1537 | lowerInt.end());
|
---|
1538 | r_4 tsys = *(lowerInt.begin()+lowerInt.size()/2);
|
---|
1539 | if(debuglev_>1) cout << "DEBUG tsys["<<iCh<<"] : " << tsys <<endl;
|
---|
1540 | //
|
---|
1541 | //set the threshold for DAB detection
|
---|
1542 | //
|
---|
1543 | chMean[iCh].MinMax(minMean,maxMean);
|
---|
1544 | minMean = (tsys > minMean) ? tsys : minMean; //pb of empty vector
|
---|
1545 | if(debuglev_>1) cout << "DEBUG min["<<iCh<<"] : " << minMean
|
---|
1546 | << " max["<<iCh<<"] : " << maxMean
|
---|
1547 | <<endl;
|
---|
1548 | r_4 deltathres = thresholdFactor * (maxMean-minMean);
|
---|
1549 | r_4 thres = tsys + deltathres;
|
---|
1550 | if(debuglev_>1) cout << "DEBUG thres["<<iCh<<"] : " << thres <<endl;
|
---|
1551 | //
|
---|
1552 | //collect upper part of the DAB
|
---|
1553 | if(debuglev_>1) cout <<"DEBUG collect upper part of the DAB" << endl;
|
---|
1554 | //
|
---|
1555 | std::vector<r_4> upperInt;
|
---|
1556 | for (sa_size_t ie=0; ie<nPowerEvolEntry; ie++){
|
---|
1557 | aPowerEvolEntry = powerEvolution.GetVec(ie);
|
---|
1558 | if ( (size_t)aPowerEvolEntry[inModeIdx] == iMode && (size_t)aPowerEvolEntry[inCycleIdx] == iCycle ){
|
---|
1559 | r_4 mean = aPowerEvolEntry[iCh+inOffsetCh0];
|
---|
1560 | if (mean >= thres) upperInt.push_back(mean);
|
---|
1561 | }//end cut
|
---|
1562 | }//eo loop on channels
|
---|
1563 | //
|
---|
1564 | //compute adjacent differences to detect the 2 DAB levels
|
---|
1565 | //
|
---|
1566 | if(debuglev_>1) cout << "(DEBUG )size upper [" << iCh << "]: " << upperInt.size() <<endl;
|
---|
1567 | std::vector<r_4> upperIntAdjDiff(upperInt.size());
|
---|
1568 | std::adjacent_difference(upperInt.begin(),
|
---|
1569 | upperInt.end(),
|
---|
1570 | upperIntAdjDiff.begin());
|
---|
1571 | //
|
---|
1572 | //Search the 2 DAB states
|
---|
1573 | if(debuglev_>1) cout<<"DEBUG Search the 2 DAB states" << endl;
|
---|
1574 | //
|
---|
1575 | std::vector<r_4> upIntState[2];
|
---|
1576 | int state=-1;
|
---|
1577 | for (size_t i=1;i<upperInt.size();i++) {//skip first value
|
---|
1578 | if (fabs(upperIntAdjDiff[i])<upperInt[i]*0.010) {
|
---|
1579 | if(state == -1) state=0;
|
---|
1580 | if(state == -2) state=1;
|
---|
1581 | upIntState[state].push_back(upperInt[i]);
|
---|
1582 | } else {
|
---|
1583 | if (state == 0) state=-2;
|
---|
1584 | }
|
---|
1585 | }
|
---|
1586 | //
|
---|
1587 | //Take the mean of the median values of each levels
|
---|
1588 | if(debuglev_>1)cout << "DEBUG mean of the median values of each levels" << endl;
|
---|
1589 | //
|
---|
1590 | r_4 meanUpper = 0;
|
---|
1591 | r_4 nval = 0;
|
---|
1592 | for (int i=0;i<2;i++) {
|
---|
1593 | if (!upIntState[i].empty()) {
|
---|
1594 | std::nth_element(upIntState[i].begin(),
|
---|
1595 | upIntState[i].begin()+upIntState[i].size()/2,
|
---|
1596 | upIntState[i].end());
|
---|
1597 | meanUpper += *(upIntState[i].begin()+upIntState[i].size()/2);
|
---|
1598 | nval++;
|
---|
1599 | }
|
---|
1600 | }
|
---|
1601 | meanUpper /= nval;
|
---|
1602 | //
|
---|
1603 | //Finaly the increase of power due to the DAB is:
|
---|
1604 | //
|
---|
1605 | r_4 deltaInt = meanUpper - tsys;
|
---|
1606 | if(debuglev_>1) cout << "DEBUG deltaInt["<<iCh<<"] : " << deltaInt <<endl;
|
---|
1607 | //
|
---|
1608 | //Save for monitoring and final calibration operations
|
---|
1609 | //
|
---|
1610 | valCalibTuple[outOffsetCh0+outNDataPerCh*iCh] = tsys;
|
---|
1611 | valCalibTuple[outOffsetCh0+outNDataPerCh*iCh+1] = deltaInt;
|
---|
1612 | }//end loop on channels
|
---|
1613 | if(debuglev_>1) cout<<"DEBUG Fill the calibEvolution tuple" << endl;
|
---|
1614 | calibEvolution.Fill(valCalibTuple);
|
---|
1615 | }//eo loop on Cycles
|
---|
1616 | }//eo loop on Modes
|
---|
1617 | //
|
---|
1618 | //store calibration evolution Tuple
|
---|
1619 | //
|
---|
1620 | if(debuglev_>0){
|
---|
1621 | cout << "ProcessCalibration::processCmd: dump calibEvolution tuple" << endl;
|
---|
1622 | calibEvolution.Show(cout);
|
---|
1623 | }
|
---|
1624 | //
|
---|
1625 | //Compute the means per channel of the calibration coefficients (deltaInt)
|
---|
1626 | //and save cycle based Calibration Ctes in file named as
|
---|
1627 | // <source>-<date>-<mode>-<fcalib>MHz-Ch<channel>Cycles.txt
|
---|
1628 | // format <cycle> <coef>
|
---|
1629 | //the means are stored in files
|
---|
1630 | // <source>-<date>-<mode>-<fcalib>MHz-All.txt
|
---|
1631 | // format <channel> <coef>
|
---|
1632 | //
|
---|
1633 | sa_size_t nModes = (sa_size_t)(maxMode - minMode) + 1;
|
---|
1634 | string calibCoefFileName;
|
---|
1635 | ofstream calibMeanCoefFile[nModes]; //Mean over cycles
|
---|
1636 | ofstream calibCoefFile[nModes][NUMBER_OF_CHANNELS]; //cycle per cycle
|
---|
1637 | for (sa_size_t iMode=0; iMode<nModes; iMode++){
|
---|
1638 | //The file for the Means Coeff.
|
---|
1639 | calibCoefFileName = outputPath_ + "/calib_"
|
---|
1640 | + dateOfRun_ + "_" + StringToLower(sourceName_) + "_"
|
---|
1641 | + modeList[iMode] + "_"
|
---|
1642 | + freqBAOCalibration_ + "MHz-All.txt";
|
---|
1643 | calibMeanCoefFile[iMode].open(calibCoefFileName.c_str());
|
---|
1644 | //The file for the cycle per cycle Coeff.
|
---|
1645 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; iCh++){
|
---|
1646 | stringstream chString;
|
---|
1647 | chString << iCh;
|
---|
1648 | calibCoefFileName = outputPath_ + "/calib_"
|
---|
1649 | + dateOfRun_ + "_" + StringToLower(sourceName_) + "_"
|
---|
1650 | + modeList[iMode] + "_"
|
---|
1651 | + freqBAOCalibration_ + "MHz-Ch" + chString.str() + "Cycles.txt";
|
---|
1652 | calibCoefFile[iMode][iCh].open(calibCoefFileName.c_str());
|
---|
1653 | }
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 | r_4* aCalibEvolEntry;
|
---|
1657 | sa_size_t nCalibEvolEntry = calibEvolution.NEntry();
|
---|
1658 |
|
---|
1659 | TMatrix<r_4> meanCalibCoef(nModes,NUMBER_OF_CHANNELS); //by default init to 0
|
---|
1660 | TMatrix<r_4> nData4Mean(nModes,NUMBER_OF_CHANNELS);
|
---|
1661 |
|
---|
1662 | //READ the calibration tuple, fill the array for mean and write to ascii file
|
---|
1663 | for (sa_size_t ie=0; ie<nCalibEvolEntry; ie++){
|
---|
1664 | aCalibEvolEntry = calibEvolution.GetVec(ie);
|
---|
1665 | if(debuglev_>1){
|
---|
1666 | cout << "DEBUG mode/cycle/Coef "
|
---|
1667 | << aCalibEvolEntry[outModeIdx] << " "
|
---|
1668 | << aCalibEvolEntry[outCycleIdx] << " ";
|
---|
1669 | }
|
---|
1670 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; iCh++){
|
---|
1671 | if(debuglev_>1) cout << aCalibEvolEntry[outOffsetCh0+outNDataPerCh*iCh+1] << " "; // for debug
|
---|
1672 | sa_size_t currentMode = (sa_size_t)(aCalibEvolEntry[outModeIdx] - minMode); //ok even if minMode <> 0
|
---|
1673 | nData4Mean(currentMode,iCh)++;
|
---|
1674 | meanCalibCoef(currentMode,iCh) += aCalibEvolEntry[outOffsetCh0+outNDataPerCh*iCh+1];
|
---|
1675 |
|
---|
1676 | calibCoefFile[currentMode][iCh] << aCalibEvolEntry[outCycleIdx] << " "
|
---|
1677 | << setprecision(12)
|
---|
1678 | << aCalibEvolEntry[outOffsetCh0+outNDataPerCh*iCh+1]
|
---|
1679 | << endl;
|
---|
1680 | }
|
---|
1681 | if(debuglev_>1) cout << endl; //for debug
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 | //Perform means: true means that div per 0 is treated (slower but safer)
|
---|
1685 | meanCalibCoef.Div(nData4Mean,true);
|
---|
1686 |
|
---|
1687 | if(debuglev_>0){
|
---|
1688 | cout << "DEBUG nData4Mean" << endl;
|
---|
1689 | nData4Mean.Print(cout);
|
---|
1690 | cout << "DEBUG meanCalibCoef (averaged)" << endl;
|
---|
1691 | meanCalibCoef.Print(cout);
|
---|
1692 | }
|
---|
1693 |
|
---|
1694 | //Save means Coef
|
---|
1695 | for (sa_size_t iMode=0; iMode<nModes; iMode++){
|
---|
1696 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; iCh++){
|
---|
1697 | calibMeanCoefFile[iMode] << setprecision(12)
|
---|
1698 | << meanCalibCoef(iMode,iCh)
|
---|
1699 | << endl;
|
---|
1700 | }
|
---|
1701 | }
|
---|
1702 |
|
---|
1703 | //Save Monitor File
|
---|
1704 | {
|
---|
1705 | string fileName = outputPath_ + "/calib_monitor_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
|
---|
1706 | POutPersist calibMonitorFile(fileName);
|
---|
1707 | calibMonitorFile << PPFNameTag("powermoni") << powerEvolution;
|
---|
1708 | calibMonitorFile << PPFNameTag("calibmoni") << calibEvolution;
|
---|
1709 | }
|
---|
1710 |
|
---|
1711 | //Clean & Return
|
---|
1712 | for (sa_size_t iMode=0; iMode<nModes; iMode++){
|
---|
1713 | calibMeanCoefFile[iMode].close();
|
---|
1714 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; iCh++){
|
---|
1715 | calibCoefFile[iMode][iCh].close();
|
---|
1716 | }
|
---|
1717 | }
|
---|
1718 |
|
---|
1719 | cout << "Ok calibration finished" << endl;
|
---|
1720 | return rc;
|
---|
1721 | }//ProcessCalibration::processCmd
|
---|
1722 |
|
---|