source: BAORadio/AmasNancay/trunk/analyse.cc@ 565

Last change on this file since 565 was 556, checked in by campagne, 14 years ago

generalise the process to download the files for final analysis (jec)

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