Index: /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc
===================================================================
--- /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc	(revision 560)
+++ /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc	(revision 561)
@@ -53,4 +53,5 @@
   int nSliceInFreq_;  //used by reduceSpectra() fnc
   string typeOfCalib_;//type of calibration to be done
+  string calibFreq_;  //freq. value used for calibration
 } para;
 //--------------------------------------------------------------
@@ -61,5 +62,5 @@
 }
 //---------
-  class median_of_empty_list_exception:public std::exception{
+class median_of_empty_list_exception:public std::exception{
     virtual const char* what() const throw() {
     return "Attempt to take the median of an empty list of numbers.  "
@@ -86,4 +87,21 @@
   }
 
+//-------------
+void split(const string& str, const string& delimiters , vector<string>& tokens) {
+    // Skip delimiters at beginning.
+    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+    // Find first "non-delimiter".
+    string::size_type pos     = str.find_first_of(delimiters, lastPos);
+
+    while (string::npos != pos || string::npos != lastPos)
+    {
+        // Found a token, add it to the vector.
+        tokens.push_back(str.substr(lastPos, pos - lastPos));
+        // Skip delimiters.  Note the "not_of"
+        lastPos = str.find_first_not_of(delimiters, pos);
+        // Find next "non-delimiter"
+        pos = str.find_first_of(delimiters, lastPos);
+    }
+}
 //--------------------------------------------------------------
 char *regexp (const char *string, const char *patrn, int *begin, int *end) {    
@@ -211,4 +229,121 @@
 //Used like: 
 //
+// void meanCalibBAODiffOnOffCycles() throw(string) {
+
+//   list<string> listOfFiles;
+//   string directoryName;
+//   directoryName = para.inPath_ + "/" + para.sourceName_;
+
+//   //Make the listing of the directory
+//   listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
+  
+//   list<string>::const_iterator iFile, iFileEnd, iSpecOff, iSpecOffEnd, iSpecOn, iSpecOnEnd;
+//   iFileEnd = listOfFiles.end();
+  
+
+//   //Loop on files
+//   uint_4 nRuns=0;
+//   TArray<r_4> tableOfSpectra(NUMBER_OF_FREQ,NUMBER_OF_CHANNELS,TOTAL_NUM_CYCLES); //TOTAL_NUM_CYCLES should be large enough...
+
+
+//   for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
+//     if (para.debuglev_>90){
+//       cout << "load file <" << *iFile << ">" << endl;
+//     }
+
+//     vector<string> tokens;
+//     split(*File,"_",tokens);
+//     string dateOfRun = tokens[1];
+//     string srcLower = tokens[2];
+//     if (para.debuglev_>90){
+//       cout << "date <" << dateOfRun << ">" << endl;
+//     }
+    
+//     PInPersist fin(*iFile);
+//     vector<string> vec = fin.GetNameTags();
+
+//     if (para.typeOfCalib_ == "perRun") {
+//       ///////////////////
+//       //make the calibration of the mean of all Off and On of the run and perform the difference
+
+//       vector<string> modeList;
+//       modeList.push_back("On");
+//       modeList.push_back("Off");
+//       vector<string>::const_iterator iMode;
+//       map<string, TMatrix<r_4> > spectreModeCollect;
+
+//       for (iMode = modeList.begin(); iMode!=modeList.end(); ++iMode) {
+// 	///////////////////
+// 	//
+// 	//Compute the mean of the mode
+// 	//
+// 	list<string> listOfSpectra;
+// 	//Keep only required PPF objects
+// 	string matchstr = "specRaw"+(*iMode)+"[0-9]+"; 
+// 	std::remove_copy_if(
+// 			    vec.begin(), vec.end(), back_inserter(listOfSpectra),
+// 			    not1(StringMatch(matchstr))
+// 			    );
+	
+// 	listOfSpectra.sort(stringCompare);
+// 	iSpecEnd = listOfSpectra.end();
+// 	TMatrix<r_4> meanOfSpectra(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
+// 	uint_4 nSpectra=0;
+// 	//Loop of spectra matrix
+// 	for (iSpec = listOfSpectra.begin(); iSpec!=iSpecEnd;  ++iSpec){
+// 	  if (para.debuglev_>90){
+// 	    cout << " spactra <" << *iSpec << ">" << endl;
+// 	  }
+// 	  TMatrix<r_4> aSpec(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
+// 	  fin.GetObject(aSpec,*iSpec);
+// 	  //How to see if the GetObject is ok?? Ask Reza
+// 	  nSpectra++;
+// 	  meanOfSpectra+=aSpec;
+// 	}//end loop Off
+// 	//Mean
+// 	if(nSpectra>0)meanOfSpectra=(r_4)(nSpectra);
+
+// 	//BAO Calibrator
+// 	string calibFileName = directoryName + "/" 
+// 	  + "calib_" + dateOfRun + "_" + srcLower + "_"+(*iMode)+"_" 
+// 	  + para.calibFreq_ +"MHz-All.txt";
+// 	if(debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
+// 	ifstream ifs(calibFileName.c_str());
+// 	if ( ! ifs.is_open() ) {
+// 	  rc = 999;
+// 	  throw calibFileName + " cannot be opened...";
+// 	}	
+// 	TVector<r_4> calibBAOfactors;
+// 	sa_size_t nr,nc; //values read 
+// 	calibBAOfactorsOff.ReadASCII(ifs,nr,nc);
+// 	if(debuglev_>9){
+// 	  cout << "(nr,nc): "<< nr << "," << nc << endl;
+// 	  calibBAOfactors.Print(cout);
+// 	}
+	
+// 	for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
+// 	  meanOfSpectra(Range(iCh), Range::all()) /=calibBAOfactors(iCh);
+// 	}
+// 	//storage
+// 	spectreModeCollect.insert(pair<string, TMatrix<r_4> >(*iMode,TMatrix<r_4>(meanOfSpectra,false))); //do not share data (cf. SOPHYA) 
+//       }//end of mode
+
+//       //Take the difference ON-OFF in current run
+//       TMatrix<r_4>diffOnOff = spectreModeCollect["On"]-spectreModeCollect["Off"];
+
+
+//     } else if (para.typeOfCalib_ == "perCycle") {
+//       //perform the calibration of the OFF and ON per cycle, then make the mean and take the diff
+//     } else {
+//       string msg="FATAL (meanCalibBAODiffOnOffCycles); unknown calibration mode " 
+// 	+ para.typeOfCalib_ ;
+//       throw(msg);
+//     }  
+
+
+//     nRuns++;
+    
+//   }//eo loop on spectra in a file
+// }
 void meanCalibBAODiffOnOffCycles() throw(string) {
 
@@ -220,91 +355,306 @@
   listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
   
-  list<string>::const_iterator iFile, iFileEnd, iSpecOff, iSpecOffEnd, iSpecOn, iSpecOnEnd;
+  list<string>::const_iterator iFile, iFileEnd, iSpec, iSpecEnd;
   iFileEnd = listOfFiles.end();
-  
-  //Loop on files
+
+  //Loop on files/run
+  uint_4 totalNumberCycles=0; //total number of cycles for normalisation
   for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
     if (para.debuglev_>90){
       cout << "load file <" << *iFile << ">" << endl;
     }
+
+    vector<string> tokens;
+    split(*iFile,"_",tokens);
+    string dateOfRun = tokens[1];
+    if (para.debuglev_>90){
+      cout << "date <" << dateOfRun << ">" << endl;
+    }
+    vector<string> tokens2;
+    split(tokens[2],".",tokens2);
+    string srcLower = tokens2[0];
+
+
+    
     PInPersist fin(*iFile);
     vector<string> vec = fin.GetNameTags();
 
-    if (para.typeOfCalib_ == "perRun") {
-      ///////////////////
-      //make the calibration of the mean of all Off and On of the run and perform the difference
-      ///////////////////
-      //
-      //Compute the mean of the Off
-      //
-      list<string> listOfSpectraOff;
+    vector<string> modeList;
+    modeList.push_back("On");
+    modeList.push_back("Off");
+    vector<string>::const_iterator iMode;
+    
+    map<string, list<int> > cycleModeCollect;
+    
+    for (iMode = modeList.begin(); iMode!=modeList.end(); ++iMode) {
+      list<string> listOfSpectra;
       //Keep only required PPF objects
+      string matchstr = "specRaw"+(*iMode)+"[0-9]+"; 
       std::remove_copy_if(
 			  vec.begin(), vec.end(), back_inserter(listOfSpectra),
-			  not1(match)
+			  not1(StringMatch(matchstr))
 			  );
       
-      listOfSpectraOff.sort(stringCompare);
-      iSpecOffEnd = listOfSpectraOff.end();
-      TMatrix<r_4> meanOfSpectraOff(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
-      uint_4 nSpectraOff=0;
+      listOfSpectra.sort(stringCompare);
+      iSpecEnd = listOfSpectra.end();
+      
+      matchstr = "[0-9]+";
       //Loop of spectra matrix
-      for (iSpecOff = listOfSpectraOff.begin(); iSpecOff !=iSpecOffEnd;  ++iSpecOff){
+      list<int> listOfCycles;
+      for (iSpec = listOfSpectra.begin(); iSpec!=iSpecEnd;  ++iSpec){
+	int b,e;
+	regexp(iSpec->c_str(),matchstr.c_str(),&b,&e);
 	if (para.debuglev_>90){
-	  cout << " spactra <" << *iSpecOff << ">" << endl;
+	  cout << " spactra <" << *iSpec << ">" << endl;
+	  cout << " cycle " << iSpec->substr(b) << endl;
 	}
-	TMatrix<r_4> aSpec(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
-	fin.GetObject(aSpec,*iSpecOff);
-	//How to see if the GetObject is ok?? Ask Reza
-	nSpectraOff++;
-	meanOfSpectraOff+=aSpec;
-      }//end loop Off
-      //Normalisation
-      if(nSpectraOff>0)meanOfSpectraOff/=(r_4)(nSpectraOff);
-      //
-      //Compute the mean of the On
-      //
-      list<string> listOfSpectraOn;
-      //Keep only required PPF objects
-      std::remove_copy_if(
-			  vec.begin(), vec.end(), back_inserter(listOfSpectra),
-			  not1(match)
-			  );
+	listOfCycles.push_back(atoi((iSpec->substr(b)).c_str()));
+      }//end loop spectra
+      cycleModeCollect[*iMode] = listOfCycles;
+    }//end of mode    
+
+    //Take the Intersection of the list Of cycles in mode Off and On    
+    list<int> commonCycles;
+    set_intersection(cycleModeCollect["On"].begin(),
+		     cycleModeCollect["On"].end(),
+		     cycleModeCollect["Off"].begin(),
+		     cycleModeCollect["Off"].end(),
+		     back_inserter(commonCycles)
+		     );
+    
+    if (para.debuglev_>90){
+      cout << "Liste of cycles common to On & Off: <";
+      for (list<int>::iterator i=commonCycles.begin(); i!=commonCycles.end(); ++i){
+	cout << *i << " ";
+      }
+      cout << ">" << endl;
+    }
+    
+    //
+    //Load BAO Calibration factors "per Cycle and Channels"
+    //Compute the mean per Cycle to 
+    //  fill factors "per Run and Channels" with the same cycle list
+    //
+    //
+    //TODO improve the code....
+
+    TMatrix<r_4> calibBAOfactors_Off_Cycle_Ch0;
+    TMatrix<r_4> calibBAOfactors_Off_Cycle_Ch1;
+    TMatrix<r_4> calibBAOfactors_On_Cycle_Ch0;
+    TMatrix<r_4> calibBAOfactors_On_Cycle_Ch1;
+    
+    string calibFileName;
+    ifstream ifs;
+    sa_size_t nr,nc; //values read 
+
+    //OFF Cycle per Channel
+    calibFileName = directoryName + "/" 
+      + "calib_" + dateOfRun + "_" + srcLower + "_Off_" 
+      + para.calibFreq_ +"MHz-Ch0Cycles.txt";
+    if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
+    ifs.open(calibFileName.c_str());
+    if ( ! ifs.is_open() ) {
+
+      throw calibFileName + " cannot be opened...";
+    }	
+    calibBAOfactors_Off_Cycle_Ch0.ReadASCII(ifs,nr,nc);
+    if(para.debuglev_>9){
+      cout << "(nr,nc): "<< nr << "," << nc << endl;
+      calibBAOfactors_Off_Cycle_Ch0.Print(cout);
+    }
+
+    TMatrix<r_4> calibBAOfactors_Off_Run_Ch0(nr,nc);
+    calibBAOfactors_Off_Run_Ch0.Column(0) = calibBAOfactors_Off_Cycle_Ch0.Column(0);
+    {//Compute the mean
+      TVector<r_4> coef(calibBAOfactors_Off_Cycle_Ch0(Range::all(),Range::last()),false);
+      double mean,sigma;
+      MeanSigma(coef,mean,sigma);
+      cout << "Mean: " << mean << " sigma " << sigma << endl;
+      calibBAOfactors_Off_Run_Ch0.Column(1).SetCst(mean);
+    }
+    if(para.debuglev_>9){
+      cout << "Fill calib. with mean value " << endl; 
+      calibBAOfactors_Off_Run_Ch0.Print(cout);
+    }
+    ifs.close();
+
+    //
+    calibFileName = directoryName + "/" 
+      + "calib_" + dateOfRun + "_" + srcLower + "_Off_" 
+      + para.calibFreq_ +"MHz-Ch1Cycles.txt";
+    if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
+    ifs.open(calibFileName.c_str());
+    if ( ! ifs.is_open() ) {
+
+      throw calibFileName + " cannot be opened...";
+    }	
+    calibBAOfactors_Off_Cycle_Ch1.ReadASCII(ifs,nr,nc);
+    if(para.debuglev_>9){
+      cout << "(nr,nc): "<< nr << "," << nc << endl;
+      calibBAOfactors_Off_Cycle_Ch1.Print(cout);
+    }
+    TMatrix<r_4> calibBAOfactors_Off_Run_Ch1(nr,nc);
+    calibBAOfactors_Off_Run_Ch1.Column(0) = calibBAOfactors_Off_Cycle_Ch1.Column(0);
+    {//Compute the mean
+      TVector<r_4> coef(calibBAOfactors_Off_Cycle_Ch1(Range::all(),Range::last()),false);
+      double mean,sigma;
+      MeanSigma(coef,mean,sigma);
+      cout << "Mean: " << mean << " sigma " << sigma << endl;
+      calibBAOfactors_Off_Run_Ch1.Column(1).SetCst(mean);
+    }
+    if(para.debuglev_>9){
+      cout << "Fill calib. with mean value " << endl; 
+      calibBAOfactors_Off_Run_Ch1.Print(cout);
+    }
+    ifs.close();
+
+    //ON Cycle per Channel
+    calibFileName = directoryName + "/" 
+      + "calib_" + dateOfRun + "_" + srcLower + "_On_" 
+      + para.calibFreq_ +"MHz-Ch0Cycles.txt";
+    if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
+    ifs.open(calibFileName.c_str());
+    if ( ! ifs.is_open() ) {
+
+      throw calibFileName + " cannot be opened...";
+    }	
+    calibBAOfactors_On_Cycle_Ch0.ReadASCII(ifs,nr,nc);
+    if(para.debuglev_>9){
+      cout << "(nr,nc): "<< nr << "," << nc << endl;
+      calibBAOfactors_On_Cycle_Ch0.Print(cout);
+	
+    }
+
+    TMatrix<r_4> calibBAOfactors_On_Run_Ch0(nr,nc);
+    calibBAOfactors_On_Run_Ch0.Column(0) = calibBAOfactors_On_Cycle_Ch0.Column(0);
+    {//Compute the mean
+      TVector<r_4> coef(calibBAOfactors_On_Cycle_Ch0(Range::all(),Range::last()),false);
+      double mean,sigma;
+      MeanSigma(coef,mean,sigma);
+      cout << "Mean: " << mean << " sigma " << sigma << endl;
+      calibBAOfactors_On_Run_Ch0.Column(1).SetCst(mean);
+    }
+    if(para.debuglev_>9){
+      cout << "Fill calib. with mean value " << endl; 
+      calibBAOfactors_On_Run_Ch0.Print(cout);
+    }
+    ifs.close();
+
+    
+    calibFileName = directoryName + "/" 
+      + "calib_" + dateOfRun + "_" + srcLower + "_On_" 
+      + para.calibFreq_ +"MHz-Ch1Cycles.txt";
+    if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
+    ifs.open(calibFileName.c_str());
+    if ( ! ifs.is_open() ) {
+      throw calibFileName + " cannot be opened...";
+    }	
+    calibBAOfactors_On_Cycle_Ch1.ReadASCII(ifs,nr,nc);
+    if(para.debuglev_>9){
+      cout << "(nr,nc): "<< nr << "," << nc << endl;
+      calibBAOfactors_On_Cycle_Ch1.Print(cout);
+    }
+    TMatrix<r_4> calibBAOfactors_On_Run_Ch1(nr,nc);
+    calibBAOfactors_On_Run_Ch1.Column(0) = calibBAOfactors_On_Cycle_Ch1.Column(0);
+    {//Compute the mean
+      TVector<r_4> coef(calibBAOfactors_On_Cycle_Ch1(Range::all(),Range::last()),false);
+      double mean,sigma;
+      MeanSigma(coef,mean,sigma);
+      cout << "Mean: " << mean << " sigma " << sigma << endl;
+      calibBAOfactors_On_Run_Ch1.Column(1).SetCst(mean);
+    }
+    if(para.debuglev_>9){
+      cout << "Fill calib. with mean value " << endl; 
+      calibBAOfactors_On_Run_Ch1.Print(cout);
+    }
+
+    ifs.close();
+    
+    //link <cycle> - <calibration coefficient>
+    map<int,r_4> calibBAO_Off_Ch0;
+    map<int,r_4> calibBAO_Off_Ch1;
+    map<int,r_4> calibBAO_On_Ch0;
+    map<int,r_4> calibBAO_On_Ch1;
+    if (para.typeOfCalib_ == "perRun") {
+      sa_size_t nr = calibBAOfactors_Off_Run_Ch0.NRows();
+      for (sa_size_t ir=0; ir<nr; ++ir){
+	calibBAO_Off_Ch0[(int)calibBAOfactors_Off_Run_Ch0(0,ir)]
+	  = calibBAOfactors_Off_Run_Ch0(1,ir);
+      }
+      nr = calibBAOfactors_Off_Run_Ch1.NRows();
+      for (sa_size_t ir=0; ir<nr; ++ir){
+	calibBAO_Off_Ch1[(int)calibBAOfactors_Off_Run_Ch1(0,ir)]
+	  = calibBAOfactors_Off_Run_Ch1(1,ir);
+      }
+
+      nr = calibBAOfactors_On_Run_Ch0.NRows();
+      for (sa_size_t ir=0; ir<nr; ++ir){
+	calibBAO_On_Ch0[(int)calibBAOfactors_On_Run_Ch0(0,ir)]
+	  = calibBAOfactors_On_Run_Ch0(1,ir);
+      }
+      nr = calibBAOfactors_On_Run_Ch1.NRows();
+      for (sa_size_t ir=0; ir<nr; ++ir){
+	calibBAO_On_Ch1[(int)calibBAOfactors_On_Run_Ch1(0,ir)]
+	  = calibBAOfactors_On_Run_Ch1(1,ir);
+      }
       
-      listOfSpectraOn.sort(stringCompare);
-      iSpecOnEnd = listOfSpectraOn.end();
-      TMatrix<r_4> meanOfSpectraOn(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
-      uint_4 nSpectraOn=0;
-      //Loop of spectra matrix
-      for (iSpecOn = listOfSpectraOn.begin(); iSpecOn !=iSpecOnEnd;  ++iSpecOn){
-	if (para.debuglev_>90){
-	  cout << " spactra <" << *iSpecOn << ">" << endl;
-	}
-	TMatrix<r_4> aSpec(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
-	fin.GetObject(aSpec,*iSpecOn);
-	//How to see if the GetObject is ok?? Ask Reza
-	nSpectraOn++;
-	meanOfSpectraOn+=aSpec;
-      }//end loop On
-      //Normalisation
-      if(nSpectraOn>0)meanOfSpectraOn/=(r_4)(nSpectraOn);
-      //
-      //Get the calibration file
-      //
+    } else if (para.typeOfCalib_ == "perCycle") {
+
+      sa_size_t nr = calibBAOfactors_Off_Cycle_Ch0.NRows();
+      for (sa_size_t ir=0; ir<nr; ++ir){
+	calibBAO_Off_Ch0[(int)calibBAOfactors_Off_Cycle_Ch0(0,ir)]
+	  = calibBAOfactors_Off_Cycle_Ch0(1,ir);
+      }
+      nr = calibBAOfactors_Off_Cycle_Ch1.NRows();
+      for (sa_size_t ir=0; ir<nr; ++ir){
+	calibBAO_Off_Ch1[(int)calibBAOfactors_Off_Cycle_Ch1(0,ir)]
+	  = calibBAOfactors_Off_Cycle_Ch1(1,ir);
+      }
+
+      nr = calibBAOfactors_On_Cycle_Ch0.NRows();
+      for (sa_size_t ir=0; ir<nr; ++ir){
+	calibBAO_On_Ch0[(int)calibBAOfactors_On_Cycle_Ch0(0,ir)]
+	  = calibBAOfactors_On_Cycle_Ch0(1,ir);
+      }
+      nr = calibBAOfactors_On_Cycle_Ch1.NRows();
+      for (sa_size_t ir=0; ir<nr; ++ir){
+	calibBAO_On_Ch1[(int)calibBAOfactors_On_Cycle_Ch1(0,ir)]
+	  = calibBAOfactors_On_Cycle_Ch1(1,ir);
+      }
+
+    } else {
+      throw "Unknow calibration type: " + para.typeOfCalib_;
+    }
+
+
+    
+// 	for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
+// 	  meanOfSpectra(Range(iCh), Range::all()) /=calibBAOfactors(iCh);
+// 	}
+
+    //Loop on cyles
+    for (list<int>::iterator ic=commonCycles.begin(); ic!=commonCycles.end(); ++ic){
+      string ppftag;
+      //load ON phase
+      stringstream cycle;
+      cycle << *ic;
       
-
-
-    } else if {para.typeOfCalib_ == "perCycle") {
-      //perform the calibration of the OFF and ON per cycle, then make the mean and take the diff
-    } else {
-      string msg="FATAL (meanCalibBAODiffOnOffCycles); unknown calibration mode " 
-	+ para.typeOfCalib_ ;
-      throw(msg);
-    }
-
-    
-    }//eo loop on spectra in a file
-  }//eo loop on files
-  
+      ppftag = "specRawOn"+cycle.str();
+      TMatrix<r_4> aSpecON(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
+      fin.GetObject(aSpecON,ppftag);
+
+      
+
+
+
+      ppftag = "specRawOff"+cycle.str();
+      TMatrix<r_4> aSpecOFF(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
+      fin.GetObject(aSpecOFF,ppftag);
+      
+      totalNumberCycles++;
+	
+    }//eo loop on cycles
+
+  }//eo loop on spectra in a file
 }
 //-------------------------------------------------------
@@ -545,4 +895,5 @@
   string nSliceInFreq = "32";
   string typeOfCalib="perRun";
+  string calibFreq = "1346";
   
   //  bool okarg=false;
@@ -551,10 +902,11 @@
     if (strcmp(arg[ka],"-h")==0) {
       cout << "Usage:  -act [meanRawDiffOnOff]|medianRawDiffOnOff|meanCalibBAODiffOnOff\n"
-	   << " -calibopt [perRun]|perCcyle (cf. in case of calibration to be done)"
+	   << " -calibopt [perRun]|perCcyle (cf. in case of calibration to be done)\n"
+	   << " -calibfreq <number> (cf. freq. used by calibration operation)\n"
 	   << " -src [Abell85]\n -inPath [.]|<top_root_dir of the ppf file>\n" 
 	   << " (ex. /sps/baoradio/AmasNancay/JEC/\n " 
 	   << " -outPath [.]|<dir of the output> \n"
 	   << " -nSliceInFreq [32]|<number of bin in freq. to cumulate>\n"
-	   << " -ppfFile <generic name of the input ppf files> (ex. diffOnOffRaw)"
+	   << " -ppfFile <generic name of the input ppf files> (ex. diffOnOffRaw)\n"
 	   << " -debug <level> "
 	   << endl;
@@ -571,4 +923,8 @@
     else if (strcmp(arg[ka],"-calibopt")==0) {
       typeOfCalib=arg[ka+1];
+      ka+=2;
+    }    
+    else if (strcmp(arg[ka],"-calibfreq")==0) {
+      calibFreq=arg[ka+1];
       ka+=2;
     }    
@@ -602,4 +958,6 @@
   para.ppfFile_    = ppfFile;
   para.nSliceInFreq_ = atoi(nSliceInFreq.c_str());
+  para.typeOfCalib_ = typeOfCalib;
+  para.calibFreq_   = calibFreq;
 
   cout << "Dump Initial parameters ............" << endl;
@@ -610,4 +968,6 @@
        << " ppfFile = " <<  para.ppfFile_ << "\n"
        << " nSliceInFreq = " << para.nSliceInFreq_  << "\n"
+       << " typeOfCalib = " << para.typeOfCalib_ << "\n"
+       << " calibFreq = " <<  para.calibFreq_ << "\n"
        << " debuglev = "  << para.debuglev_   << "\n";
   cout << "...................................." << endl;
