Index: /BAORadio/AmasNancay/trunk/plotRawDiffOnOff.pic
===================================================================
--- /BAORadio/AmasNancay/trunk/plotRawDiffOnOff.pic	(revision 630)
+++ /BAORadio/AmasNancay/trunk/plotRawDiffOnOff.pic	(revision 631)
@@ -1,5 +1,8 @@
 #source should be in minuscule letters
+# gain = 1 if on,off have been divided by gain
+
 set source $1
 set ncycles $2
+set gain $3
 
 #c++compile meanSigSum
@@ -15,12 +18,55 @@
 setaxesatt "$axedefatt"
 
-
-set f1420low 1420.2
-set f1420high 1420.6
-nbins1420 = floor((${f1420high}-${f1420low})/250*8192)
-
+set path "/sps/baoradio/AmasNancay/AST"
+if ( $gain == "0" ) then
+  openppf ${path}/rawOnOffDiffNoGain_${source}-${ncycles}Cycles.ppf
+  echo "Opening file  ${path}/rawOnOffDiffNoGain_${source}-${ncycles}Cycles.ppf"
+else
+  openppf ${path}/rawOnOffDiff_${source}-${ncycles}Cycles.ppf
+  echo "Opening file  ${path}/rawOnOffDiff_${source}-${ncycles}Cycles.ppf"
+endif
+
+# Abell 85, 500 cycles
+if ( ${source} == "abell85" ) then
+  set f1420low 1420.2
+  set f1420high 1420.6
+  set packVal "1 10 25 50 100"
+endif
+
+<<<<<<< .mine
+# Abell 1205, 600, 750 cycles
+if ( ${source} == "abell1205" ) then
+  set f1420low 1420.1
+  set f1420high 1420.6
+  if ( $ncycles == 600 ) then
+    set packVal "1 10 25 50 100 120"
+  else
+    set packVal "1 10 15 50 75 125 150"
+  endif
+endif
+=======
 set path "/sps/baoradio/AmasNancay/JEC"
 openppf ${path}/rawOnOffDiff_${source}-${ncycles}Cycles.ppf
-
+>>>>>>> .r630
+
+# Abell 2440, 210 cycles
+if ( ${source} == "abell2440" ) then
+  set f1420low 1420.4
+  set f1420high 1420.7
+  set packVal "1 10 25 42"
+endif
+
+# All clusters, 1549 cycles
+if ( ${source} == "abell85-abell2440-abell1205" ) then
+  set f1420low 1420.1
+  set f1420high 1420.7
+  set packVal "1 10 25 50 100 260"
+endif
+
+echo "f1420low=${f1420low}, f1420high=${f1420high}"
+echo "Packing values="${packVal}
+
+nbins1420 = floor((${f1420high}-${f1420low})/250*8192)
+#echo $nbins1420
 
 clearscript evolAt1420Freq
@@ -29,4 +75,5 @@
 clearscript sigmaRaw1420Side
 clearscript sigmaRaw1410a1415
+clearscript sigmaRawBand
 clearscript IntAt1420
 clearscript diffOnOff
@@ -64,5 +111,4 @@
 c++compile rebining
 c++link rebining.so dorebin
-
 
 #col 3 = onoffRaw01420side   Ch 0
@@ -81,5 +127,4 @@
 set sigmaCh1 ""
 set errsigCh1 ""
-
 
 foreach ipack ( $packVal )
@@ -210,4 +255,227 @@
 endscript
 ###########################################
+# Old function sigmaRaw1400a1420
+defscript sigmaRawBand
+# flow,fhigh = frequency limits for integration band
+# offFilt = 1 we divide on-off by filtered Off
+
+set flow $1
+set fhigh $2
+set offFilt $3
+set nclusters $4
+graphicatt ""
+
+if ( $nclusters == 1 ) then
+## Individual clusters (update of mergeAnaFiles.cc on 09/01/2012)
+## mergeAnaFiles.cc -> meanRawDiffOnOffCycles -> rawOnOffDiff_[source]-[n]Cycles.ppf
+## Frequency bands [1405,1415], [1405,1410], [1410,1415] MHz
+## [1405,1415]: col 11,12 = onoffRaw[0,1]f14051415 Ch[0,1] (ON-OFF)/OFF_filt
+## [1405,1410]: col 13,14 = onoffRaw[0,1]f14051410 Ch[0,1]
+## [1410,1415]: col  5, 6 = onoffRaw[0,1]f14101415 Ch[0,1]
+## [1405,1415]: col 15,16 = diffonoffRaw[0,1]f14051415 Ch[0,1] (ON-OFF)
+## [1405,1410]: col 17,18 = diffonoffRaw[0,1]f14051410 Ch[0,1]
+## [1410,1415]: col 19,20 = diffonoffRaw[0,1]f14101415 Ch[0,1]
+  if ( $flow == 1405 ) then
+    if ( $fhigh == 1415 ) then
+      if ( $offFilt == 1 ) then
+        set col0 11
+        set col1 12
+      else
+        set col0 15
+        set col1 16
+      endif
+    endif
+    if ( $fhigh == 1410 ) then
+      if ( $offFilt == 1 ) then
+        set col0 13
+        set col1 14
+      else
+        set col0 17
+        set col1 18
+      endif
+    endif
+  endif
+  if ( $flow == 1410 ) then
+    if ( $fhigh == 1415 ) then
+      if ( $offFilt == 1 ) then
+        set col0 5
+        set col1 6
+      else
+        set col0 19
+        set col1 20
+      endif
+    endif
+  endif
+
+  ntcol2var onoffevol $col0 linCh0All
+  line2vec vecCh0All $linCh0All
+  ntcol2var onoffevol $col1 linCh1All
+  line2vec vecCh1All $linCh1All
+else
+  ## Execute if analysing All Clusters abell85-abell2440-abell1205
+  ## mergeAnaFiles.cc -> MeanRawDiffOnOffAllClusters -> rawOnOffDiff_[sources]-[n]Cycles.ppf
+  ## Shifts the distribution of each cluster to mean~0, to avoid 
+  ## offset problems when regrouping values
+  ##   col 5,6  = onoffRaw0f14101415   Ch 0,1 [1410,1415]MHz
+  ##   col 7,8  = onoffRaw1f141014125  Ch 0,1 [1410,1412.5]MHz
+  ##   col 9,10 = onoffRaw1f14101411   Ch 0,1 [1410,1411]MHz
+
+  if ( $flow == 1410 ) then
+    if ( $fhigh == 1415 ) then
+      set col0 5
+      set col1 6
+    endif
+    if ( $fhigh == 14125 ) then
+      set col0 7
+      set col1 8
+    endif
+    if ( $fhigh == 1411 ) then
+      set col0 9
+      set col1 10
+    endif
+  endif
+  echo Analysing ntuple columns $col0, $col1
+
+  ntcol2var onoffevol $col0 linCh0All
+  line2vec invecCh0All $linCh0All
+  ntcol2var onoffevol $col1 linCh1All
+  line2vec invecCh1All $linCh1All
+
+  del v85 v2440 v1205
+  exptovec v85 onoffevol cycletot-1 srcID==85
+  set v85_first ${v85.min}
+  set v85_last ${v85.max}
+  exptovec v2440 onoffevol cycletot-1 srcID==2440
+  set v2440_first ${v2440.min}
+  set v2440_last ${v2440.max}
+  exptovec v1205 onoffevol cycletot-1 srcID==1205
+  set v1205_first ${v1205.min}
+  set v1205_last ${v1205.max}
+
+  del vecCh085 vecCh02440 vecCh01205 vecCh185 vecCh12440 vecCh11205 vecCh0All vecCh1All
+  h/copy invecCh0All vecCh085 ${v85_first}:${v85_last}
+  h/copy invecCh0All vecCh02440 $v2440_first:$v2440_last
+  h/copy invecCh0All vecCh01205 $v1205_first:$v1205_last
+  h/copy invecCh1All vecCh185 $v85_first:$v85_last
+  h/copy invecCh1All vecCh12440 $v2440_first:$v2440_last
+  h/copy invecCh1All vecCh11205 $v1205_first:$v1205_last
+
+  c++exec double m,s; int l=-1; \
+	  MeanSigma(vecCh085,m,s)  ; vecCh085   -= m;\
+  	  MeanSigma(vecCh02440,m,s); vecCh02440 -= m;\
+	  MeanSigma(vecCh01205,m,s); vecCh01205 -= m;\
+	  MeanSigma(vecCh185,m,s)  ; vecCh185   -= m;\
+	  MeanSigma(vecCh12440,m,s); vecCh12440 -= m;\
+	  MeanSigma(vecCh11205,m,s); vecCh11205 -= m;\
+	  TVector<r_8> vecCh0All(invecCh0All.NElts()); KeepObj(vecCh0All); \
+	  TVector<r_8> vecCh1All(invecCh1All.NElts()); KeepObj(vecCh1All); \
+	  for (int i=0;i<vecCh085.NElts();i++){l++;vecCh0All(l)=vecCh085(i);vecCh1All(l)=vecCh185(i);}\
+	  for (int j=0;j<vecCh02440.NElts();j++){l++;vecCh0All(l)=vecCh02440(j);vecCh1All(l)=vecCh12440(j);}\
+	  for (int k=0;k<vecCh01205.NElts();k++){l++;vecCh0All(l)=vecCh01205(k);vecCh1All(l)=vecCh11205(k);}
+  ## End All Clusters
+endif
+ 
+set sigmaCh0 ""
+set errsigCh0 ""
+set sigmaCh1 ""
+set errsigCh1 ""
+
+c++compile rebining
+c++link rebining.so dorebin
+
+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 [$flow,$fhigh]MHz ${source} Ch 0 (blue) Ch 1 (red)" ' ' $defatt
+setaxelabels "num of cycles" "Sigma (a.u)" $axedefatt
+
+del h0 h1
+set xmin -0.01
+set xmax 0.01
+newh1d h0 $xmin $xmax 200
+newh1d h1 $xmin $xmax 200
+if ( $offFilt == 0 ) then
+  if ( $gain == 0 ) then
+    del h0 h1
+    newh1d h0 -0.0001 0.0001 200
+    newh1d h1 -0.0001 0.0001 200
+  endif
+  newwin 1 1
+  n/proj h0 onoffevol.diffonoffRaw0f$flow$fhigh ! ! ! "blue notit"
+  n/proj h1 onoffevol.diffonoffRaw1f$flow$fhigh ! ! ! "same red notit"
+  settitle "diffonoffRaw [$flow,$fhigh]MHz ${source} Ch 0 (blue) Ch 1 (red)" ' ' $defatt
+  newwin 1 1
+  n/pl onoffevol.diffonoffRaw1f$flow$fhigh%cycle ! ! "cpts red notit"
+  n/pl onoffevol.diffonoffRaw0f$flow$fhigh%cycle ! ! "cpts same blue notit"
+  settitle "diffonoffRaw [$flow,$fhigh]MHz ${source} Ch 0 (blue) Ch 1 (red)" ' ' $defatt
+else
+  newwin 1 1
+  n/proj h0 onoffevol.onoffRaw0f$flow$fhigh ! ! ! "cpts blue notit"
+  n/proj h1 onoffevol.onoffRaw1f$flow$fhigh ! ! ! "cpts same red notit"
+  settitle "onoffRaw [$flow,$fhigh]MHz ${source} Ch 0 (blue) Ch 1 (red)" ' ' $defatt
+  newwin 1 1
+  n/pl onoffevol.onoffRaw0f$flow$fhigh%cycle ! ! "cpts blue notit"
+  n/pl onoffevol.onoffRaw1f$flow$fhigh%cycle ! ! "cpts same red notit"
+  settitle "onoffRaw [$flow,$fhigh]MHz ${source} Ch 0 (blue) Ch 1 (red)" ' ' $defatt
+endif
+
+endscript
+##########################################
+defscript evolAt1400a1415OffOn
+
+graphicatt "xylimits=0,${ncycles},0.99,1.02"
+
+newwin 1 1
+n/pl onoffevol.offRaw0f14001415%cycle ! ! "blue cpts notit nsta"
+n/pl onoffevol.offRaw1f14001415%cycle ! ! "same red cpts notit nsta"
+n/pl onoffevol.onRaw0f14001415%cycle ! ! "same cyan cpts notit nsta"
+n/pl onoffevol.onRaw1f14001415%cycle ! ! "same orange cpts notit nsta"
+settitle "Raw OFF and ON  ${source} Ch 0 (blue/cyan) Ch 1 (red/orange) ${ncycles}cycles " ' ' $defatt
+setaxelabels "cycle" "I[1400,1415]MHz Raw (a.u)" $axedefatt
+
+endscript
+##########################################
 defscript evolAt1410a1415OffOn
 
