Index: /BAORadio/AmasNancay/trunk/etude_mergeAna.pic
===================================================================
--- /BAORadio/AmasNancay/trunk/etude_mergeAna.pic	(revision 590)
+++ /BAORadio/AmasNancay/trunk/etude_mergeAna.pic	(revision 591)
@@ -18,5 +18,4 @@
 
 echo $nbins1420
-
 
 
@@ -26,4 +25,5 @@
 clearscript IntAt1420
 clearscript sigmaRaw1420Side
+clearscript sigmaRaw1400a1420
 ############################################################################
 defscript evolAtCalibFreq
@@ -150,8 +150,6 @@
 
 
-
-
-#col 13 = onoffRaw01420side
-#col 14 = onoffRaw11420side
+#col 13 = onoffRaw01420side   Ch 0
+#col 14 = onoffRaw11420side   Ch 1
 
 ntcol2var onoffevol 13 linCh0All
@@ -161,5 +159,5 @@
 line2vec vecCh1All $linCh1All
 
-
+#packing values only valid for 500 cycles...
 set packVal "1 10 25 50 100"
 set sigmaCh0 ""
@@ -188,5 +186,5 @@
   mean1 = ${outvec.sum}/${outvec.size}
   sigma1 = sqrt(${outvec.sumsq}/${outvec.size}-${mean1}*${mean1})
-  errsig1 = ${sigma0}/sqrt(2*${outvec.size})	
+  errsig1 = ${sigma1}/sqrt(2*${outvec.size})	
   set sigmaCh1 "${sigmaCh1} ${sigma1}"	
   set errsigCh1 "${errsigCh1} ${errsig1}"
@@ -222,5 +220,83 @@
 
 endscript
+##################################################
+defscript sigmaRaw1400a1420
+
+c++compile rebining
+c++link rebining.so dorebin
+
+
+#col 19 = onoffRaw0f14001420   Ch 0
+#col 20 = onoffRaw1f14001420  Ch 1
+
+ntcol2var onoffevol 19 linCh0All
+line2vec vecCh0All $linCh0All
+
+ntcol2var onoffevol 20 linCh1All
+line2vec vecCh1All $linCh1All
+
+#packing values only valid for 500 cycles...
+set packVal "1 10 25 50 100"
+set sigmaCh0 ""
+set errsigCh0 ""
+set sigmaCh1 ""
+set errsigCh1 ""
+
+
+foreach ipack ( $packVal )
+
+#Packing per ipack
+  del invec 
+  del outvec
+  cp vecCh0All invec
+  call dorebin $ipack
+  mean0 = ${outvec.sum}/${outvec.size}
+  sigma0 = sqrt(${outvec.sumsq}/${outvec.size}-${mean0}*${mean0})
+  errsig0 = ${sigma0}/sqrt(2*${outvec.size})	
+  set sigmaCh0 "${sigmaCh0} ${sigma0}"	
+  set errsigCh0 "${errsigCh0} ${errsig0}"	
+#
+  del invec
+  del outvec
+  cp vecCh1All invec
+  call dorebin $ipack
+  mean1 = ${outvec.sum}/${outvec.size}
+  sigma1 = sqrt(${outvec.sumsq}/${outvec.size}-${mean1}*${mean1})
+  errsig1 = ${sigma1}/sqrt(2*${outvec.size})	
+  set sigmaCh1 "${sigmaCh1} ${sigma1}"	
+  set errsigCh1 "${errsigCh1} ${errsig1}"
+end
+
+
+newnt nt0 x y ey
+newnt nt1 x y ey
+
+set x0 ( $packVal )
+set y0 ( $sigmaCh0 )
+set ey0 ( $errsigCh0 )
+
+set x1 ( $packVal )
+set y1 ( $sigmaCh1 )
+set ey1 ( $errsigCh1 )
+	
+for i 0:$#x0
+ line2nt nt0 $x0[i] $y0[i] $ey0[i]
+ line2nt nt1 $x1[i] $y1[i] $ey1[i]
+end
+
+
+newwin 1 1
+plot2de nt0 x y 0 ey 1 "blue marker=fcircle,9 notit nsta"     
+plot2de nt1 x y 0 ey 1 "same red  marker=fcircle,9 notit nsta"
+n = ${#x0}-1
+func $y0[0]/sqrt(x) $x0[0] $x0[n]  100 "same"
+settitle "Sigma [1400,1420]MHz ${source} Ch 0 (blue) Ch 1 (red)" ' ' $defatt
+setaxelabels "num of cycles" "Sigma (a.u)" $axedefatt
+
+
+
+endscript
 ###########################################
+
 defscript evolAt1420SideFreq
 
@@ -361,4 +437,14 @@
 # Calibration coeff. per cycles
 #
+
+graphicatt "xylimits=1250,1500,-0.01,0.01"
+del sonoffovoff0 sonoffovoff1
+objaoper meanOvOffNoCalib row 0 sonoffovoff0
+objaoper meanOvOffNoCalib row 1 sonoffovoff1
+newwin 1 1
+plot2d sonoffovoff0 (n/8192)*250+1250 val n>0 "blue cpts notit nsta"
+plot2d sonoffovoff1 (n/8192)*250+1250 val n>0 "red same cpts notit nsta"
+settitle "Raw (ON-OFF)/OFF  ${source} Ch 0 (blue) Ch 1 (red) ${ncycles}cycles" ' ' $defatt
+setaxelabels "Freq. (MHz)" "I (a.u)" $axedefatt
 
 
Index: /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc
===================================================================
--- /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc	(revision 590)
+++ /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc	(revision 591)
@@ -111,4 +111,29 @@
 
 //-------------
+//JEC 25/10/11 Perform a median filtering with a sliding window of "halfwidth" half width
+//             It takes care of the edges and is based on the median function (above) 
+void medianFiltering(const TMatrix<r_4> mtx, 
+		     sa_size_t halfwidth,
+		     TMatrix<r_4>& vec) {
+  
+  sa_size_t nr = mtx.NRows();
+  sa_size_t nc = mtx.NCols();
+  sa_size_t chMin = 0;
+  sa_size_t chMax = nc-1;
+  
+  for (sa_size_t ir=0; ir<nr; ir++){
+    for (sa_size_t ic=0; ic<nc; ic++) {
+      sa_size_t chLow = ic-halfwidth;
+      chLow = (chLow >= chMin) ? chLow : chMin;
+      sa_size_t chHigh = ic+halfwidth;
+      chHigh = ( chHigh <= chMax ) ? chHigh : chMax;
+      TVector<r_4> tmp(mtx(Range(ir),Range(chLow,chHigh)),false);
+      vector<r_4> val;
+      tmp.FillTo(val);
+      vec(ir,ic) = median(val.begin(),val.end());
+    }
+  }
+}
+//-------------
 void split(const string& str, const string& delimiters , vector<string>& tokens) {
     // Skip delimiters at beginning.
@@ -264,18 +289,20 @@
 
   //mean ON-OFF over the list of cycles
+  TMatrix<r_4> meanDiffONOFFovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);          //set to 0 
   TMatrix<r_4> meanDiffONOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);          //set to 0 
   TMatrix<r_4> meanDiffONOFF_perRunCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);      //set to 0
   TMatrix<r_4> meanDiffONOFF_perCycleCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);    //set to 0
-  static const int NINFO=19;
+  static const int NINFO=21;
   char* onffTupleName[NINFO]={"cycle"
-			  ,"onoffRaw0","onoffRaw1"
-			  ,"onoffRun0","onoffRun1"
-			  ,"onoffCycle0","onoffCycle1"
-			  ,"onoffRaw01420","onoffRaw11420"
-			  ,"onoffRun01420","onoffRun11420"
-			  ,"onoffCycle01420","onoffCycle11420"
-			  ,"onoffRaw01420side","onoffRaw11420side"
-			  ,"onoffRun01420side","onoffRun11420side"
-			  ,"onoffCycle01420side","onoffCycle11420side"
+			      ,"onoffRaw0","onoffRaw1"
+			      ,"onoffRun0","onoffRun1"
+			      ,"onoffCycle0","onoffCycle1"
+			      ,"onoffRaw01420","onoffRaw11420"
+			      ,"onoffRun01420","onoffRun11420"
+			      ,"onoffCycle01420","onoffCycle11420"
+			      ,"onoffRaw01420side","onoffRaw11420side"
+			      ,"onoffRun01420side","onoffRun11420side"
+			      ,"onoffCycle01420side","onoffCycle11420side"
+			      ,"onoffRaw0f14001420","onoffRaw1f14001420"
   };
   NTuple onoffevolution(NINFO,onffTupleName);
@@ -294,5 +321,8 @@
   sa_size_t ch1420bLow  = freqToChan(1422);
   sa_size_t ch1420bHigh = freqToChan(1423);
-
+  
+  //25/10/11 follow 1400-1420Mhz
+  sa_size_t ch1420 = freqToChan(1420);
+  sa_size_t ch1400 = freqToChan(1400);
 
   if (para.debuglev_>0){
@@ -631,4 +661,13 @@
       meanDiffONOFF_noCalib += diffOnOff_noCalib;
       
+      //JEC 29/10/11 add ON-OFF/OFF
+      TMatrix<r_4> diffOnOffOvOff_noCalib(diffOnOff_noCalib,false); //do not share data
+      TMatrix<r_4> aSpecOffFitltered(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
+      sa_size_t halfWidth = 35; //number of freq. bin for the 1/2 width of the filtering window
+      medianFiltering(aSpecOff,halfWidth,aSpecOffFitltered);
+      
+      diffOnOffOvOff_noCalib.Div(aSpecOffFitltered); //division in place
+      meanDiffONOFFovOFF_noCalib += diffOnOffOvOff_noCalib;
+
       TMatrix<r_4> diffOnOff_perRunCalib = aSpecOn_BAOCalibRun - aSpecOff_BAOCalibRun;
       meanDiffONOFF_perRunCalib += diffOnOff_perRunCalib;
@@ -703,4 +742,12 @@
       xnt[18] = (meanInRange_1420aFreq_perCycle(1) + meanInRange_1420bFreq_perCycle(1))/2.;
 
+
+      //JEC 25/10/11 follow 1400-1420 MHz bande protege et n'inclue pas le 1420.4Mhz de la Galaxie
+      TVector<r_4> meanInRange_1400a1420Freq_noCalib(NUMBER_OF_CHANNELS);
+      meanInRange(diffOnOff_noCalib,ch1400,ch1420,meanInRange_1400a1420Freq_noCalib);
+      xnt[19] = meanInRange_1400a1420Freq_noCalib(0);
+      xnt[20] = meanInRange_1400a1420Freq_noCalib(1);
+      
+
       
       //store infos to Ntuple
@@ -717,4 +764,6 @@
   //Normalisation
   if(totalNumberCycles > 0){
+    //JEC 29/10 add ON-OFF/OFF
+    meanDiffONOFFovOFF_noCalib  /= (r_4)totalNumberCycles;
     meanDiffONOFF_noCalib       /= (r_4)totalNumberCycles;
     meanDiffONOFF_perRunCalib   /= (r_4)totalNumberCycles;
@@ -745,4 +794,9 @@
     string tag = "meanNoCalib";
     fos << PPFNameTag(tag) << meanDiffONOFF_noCalib;
+    
+    //JEC 29/10/11
+    tag = "meanOvOffNoCalib";
+    fos << PPFNameTag(tag) << meanDiffONOFFovOFF_noCalib;
+
     tag = "meanPerRunCalib";
     fos << PPFNameTag(tag) << meanDiffONOFF_perRunCalib;
