Index: trunk/MagicSoft/Mars/scripts/dospectrum
===================================================================
--- trunk/MagicSoft/Mars/scripts/dospectrum	(revision 8482)
+++ trunk/MagicSoft/Mars/scripts/dospectrum	(revision 8626)
@@ -1,4 +1,4 @@
 #!/bin/sh
-#
+# 
 # ========================================================================
 #
@@ -18,154 +18,216 @@
 #
 #
-#   Author(s): Daniela Dorner  05/2006 <mailto:dorner@astro.uni-wuerzburg.de>
-#
-#   Copyright: MAGIC Software Development, 2000-2006
+#   Author(s): Daniela Dorner  06/2007 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2007
 #
 #
 # ========================================================================
 #
-#
-#
 ##############################################################################
 #
-# This script creates the ganymed.rc files with different parameter sets (the 
-# parameters 1 and 3 are changed in steps). Then the script runs ganymed and 
-# sponde for this different parameter sets. 
-#
-# variables, that have to be set by the user:
-#
-# - path          directory, where the files are stored 
-# - mars          directory, where your Mars version is stored
-# - dataset       dataset file, which shall be used (filename without path)
-#                  the file has to be stored in the dataset directory in the 
-#                  path
-# - par*step      step width for changing the parameter * 
-# - par*numminus  number of steps going to smaller values of the parameter * 
-# - par*num       number of steps for changing the parameter * 
-# - spondenum     number of sponde rc file (also of the root and log file)
-# - ganymednum    number of ganymed root file
-#
-# Please make sure, that you provide the following files:
-# - $path/setup/ganymed$ganymednum.rc
-# - $path/setup/sponde$spondenum.rc
-# - $path/datasets/mcdataset-for-sponde.txt (if you use the script preparemc, 
-#    this file is produced automatically)
-# - $path/datasets/$datasetfilename (you give the datasetfilename below, but 
-#    you have to make sure, that it is in the directory $path/datasets
-#
-# To re-run ganymed (e.g. with new Software-Version), you have to delete 
-# the ganymed*.root files or set a new ganymednum. 
-# 
+# This script is: 
+# - writing rc-files with different sets of cuts 
+#   the set of cuts can be steered with the variables 
+#   $par3step, $par3numminus, $par3num and
+#   $par1step, $par1numminus, $par1num
+#     par*step     step width for changing the parameter * 
+#                  (suggested value: 0.005)
+#     par*numminus number of steps going to smaller values of the parameter * 
+#                  (starting value in your ganymed.rc file) 
+#     par*num      number of steps for changing the parameter * 
+#     par3: Cut1.Param3 from the ganymed.rc file 
+#     par1: Cut1.Param1 from the ganymed.rc file 
+# - writing a condor dag file for spectrum study
+#   With submitting this dag file with condor_submit_dag to condor from your
+#   Mars directroy you are running ganymed and sponde for all different rc 
+#   files. The condor dag man is taking care of the order of the jobs, 
+#   i.e. that sponde is started just when ganymed has been finished.
+# 
+# To start several spondes please set the arrays $spondes.
+# It is also possible to start new spondes without rerunning 
+# ganymed and/or the other spondes. To do so, please set the 
+# variables $doganymed and $spondedones accordingly
+#
+# Remark: You have to submit the condor dag file from your Mars directory.
+# 
+# For more detailed information read the comments directly before
+# each variable.
+#
 ##############################################################################
-
-
-# to be set by the user
-path=/home/dorner/crabspectrum
-mars=/home/dorner/mars.cvs
-datasetfilename=datasetcrab2005-2.txt
-spondenum=0
-ganymednum=1
-# settings for parameter 3
+#
+
+#
+# instructions and setup of the script
+# please set the variables according to your analysis
+#
+
+# path for you analysis
+path=/home/dorner/final_analysis
+# path where your condor dagfile is stored and where you need
+# the files processds.submit and processsponde.submit
+condorpath=$path/condor
+# path to store your resourcefiles
+# you should have there the ganymed.rc, which you want to use 
+# and your sponde.rc files 
+rcpath=$path/resources
+ganymedrc=$rcpath/ganymed_onoff.rc
+# outpath for your spectrum results
+# a directory for each set of cuts will be created there and
+# the ganymed and sponde output will be stored in these directories
+specpath=/results/spectrumSet2
+# name of your dataset
+# it has to be stored as dataset$dataset.txt in the directory
+# $path/datasets
+dataset="20060002"
+# this is the name of the condor-dag file, which you have to submit 
+# with condor_submit_dag from your Mars directory
+dagfile=$condorpath/set2spectrum.dag3
+# here you define whether ganymed still has to be done
+# if yes, set the variable $doganymed to "yes"
+#doganymed="yes"
+doganymed="no"
+# sponde.rc files have to be in the directory $rcpath 
+# they need to have the naming sponde1.rc, sponde2.rc, sponde3.rc 
+# (numbers in the following array)
+# the sponde.root files will be named in the same way (sponde(num).root)
+spondes=( 1 2 )
+# in this array you define whether the sponde is already done
+spondedones=( "done" "" )
+
+# this is the mc dataset, which has been created with the script
+# preparemc
+mcdataset=$path/mc/mcdataset2.txt
+
+# values for par3
 par3step=0.005
 par3numminus=10
 par3num=13
-# settings for parameter 1
+# values for par1
 par1step=0.005
 par1numminus=1 
-par1num=7
-
-
-function printsetup()
-{
-   echo "you set the following parameters: "
-   echo " path:       $path "
-   echo " ganymedrc:  $ganymedrc"
-   echo " sponderc:   $sponderc"
-   echo " dataset:    $dataset"
-   echo " mcdataset:  $mcdataset"
-   echo " spondenum:  $spondenum"
-   echo " ganymednum: $ganymednum"
-   echo " par1:       -$par1numminus to $par1num in $par1step steps"
-   echo " par3:       -$par3numminus to $par3num in $par3step steps"
-}
-
-#general variables
-datasetpath=$path/datasets
-setuppath=$path/setup
-#resultpath=$path/ganyspec
-resultpath=$path/ganyspec`echo $datasetfilename | sed -e 's/[.]txt//'`
-dataset=$datasetpath/$datasetfilename
-mcdataset=$datasetpath/mcdataset-for-sponde.txt
-ganymedrc=$setuppath/ganymed$ganymednum.rc
-sponderc=$setuppath/sponde$spondenum.rc
-setuplog=$setuppath/setup`date +%F-%H-%M-%S`.log
-
-if ! ls $ganymedrc >/dev/null 2>&1
-then
-   echo "couldn't find $ganymedrc."
-   echo "please provide the file $ganymedrc and re-run the script"
-   exit
-fi
-
-if ! ls $sponderc >/dev/null 2>&1
-then
-   echo "couldn't find $sponderc."
-   echo "do you want to continue anyhow? (ganymed will be done)"
-   echo "please insert y, if you want continue"
-   echo "              n, if you want quit"
-
-   answer=`head -n 1`
-   case $answer in
-      y) echo "continue creating rc files and running ganymed"
-         ;;
-      n) echo "please provide the file $ganymedrc and re-run the script"
-         exit
-         ;;
-      *) echo "your answer is not clear -> exit"
-         exit
-         ;;
-   esac
-   
-fi
-
-#start of the script
-printsetup
-printsetup > $setuplog
-
-mkdir -pv $resultpath
-
-echo "generating the ganymed.rc files with different parameter sets"
-# generating the ganymed.rc files with different parameter sets
+par1num=7 
+
+#
+# end of setup
+# beginning of script
+# 
+
+# some checks
+# checking if the given files and paths are existing
+if ! [ -e $mcdataset ]
+then
+   echo "Your mc dataset file $mcdataset does not exist."
+   exit
+fi
+if ! [ -e $path$specpath ]
+then
+   echo "Your output path $path$specpath does not exist."
+   exit
+fi
+if ! [ -e $path/datasets/dataset$dataset.txt ]
+then
+   echo "Your dataset file $path/datasets/dataset$dataset.txt does not exist."
+   exit
+fi
+if ! [ -e $ganymedrc ]
+then
+   echo "Your ganymed rc file $ganymedrc does not exist."
+   exit
+fi
+for (( l=0 ; l < ${#spondes[@]} ; l++ ))
+do 
+   if ! [ -e $rcpath/sponde${spondes[$l]}.rc ]
+   then
+      echo "Your sponde rc file $rcpath/sponde${spondes[$l]}.rc does not exist."
+      exit
+   fi
+done
+
+# get the parameters
 par3=`cat $ganymedrc | grep 'Cut1.Param3' | cut -d: -f2`
 par1=`cat $ganymedrc | grep 'Cut1.Param1' | cut -d: -f2`
-
-echo "parameter: 3 $par3 ,  1 $par1"
-
+echo "parameters: "
+echo "  par3= $par3"
+echo "  par1= $par1"
+echo ""
+
+# calculate the parameters with which you start
 start3=`echo $par3 - \( $par3numminus*$par3step \) | bc `
 start1=`echo $par1 - \( $par1numminus*$par1step \) | bc `
-echo "start: 1: $start1 3: $start3"
-
+echo "start: "
+echo "  par1: $start1 "
+echo "  par3: $start3"
+echo ""
+
+
+# function to print the lines for ganymed to the dag file
+function printganydagentry()
+{
+   if [ "$doganymed" = "yes" ]
+   then
+      echo "JOB  gany$name $condorpath/processds.submit"
+   else
+      echo "JOB  gany$name $condorpath/processds.submit DONE"
+   fi
+   echo "VARS gany$name path=\"$path\""
+   echo "VARS gany$name out=\"$dir\""
+   echo "VARS gany$name ds=\"$dataset\""
+   echo "VARS gany$name num=\"$dataset\""
+   echo "VARS gany$name rc=\"$rcfile\""
+   echo ""
+}
+
+# function to print the lines for sponde to the dag file
+function printspecdagentry()
+{
+   sponderc=$rcpath/sponde$1.rc
+   if [ "$2" = "done" ]
+   then
+      echo "JOB  spec$1_$name $condorpath/processsponde.submit DONE"
+   else
+      echo "JOB  spec$1_$name $condorpath/processsponde.submit"
+   fi
+   echo "VARS spec$1_$name path=\"/home/dorner/final_analysis\""
+   echo "VARS spec$1_$name out=\"$outpath\""
+   echo "VARS spec$1_$name rc=\"$sponderc\""
+   echo "VARS spec$1_$name spondenum=\"$1\""
+   echo "VARS spec$1_$name mcds=\"$mcdataset\""
+   echo "VARS spec$1_$name num=\"$dataset\""
+   echo ""
+   echo "PARENT gany$name CHILD spec$1_$name "
+   echo ""
+}
+
+echo "writing dag file $dagfile for dataset $dataset"
+echo "# dag file for dataset $dataset" > $dagfile
+echo "" >> $dagfile
 val1=$start1
 val3=$start3
-
+count=0
 for (( i=0 ; i < $par3num ; i++ ))
 do 
    for (( j=0 ; j < $par1num ; j++ ))
    do 
-#      echo "i: $i - j: $j ------- par1: $val1 and par3: $val3"
-      dir=$resultpath/set${val1}_${val3}
-      if ! ls $dir >/dev/null 2>&1
+      name=${val1}_${val3}
+      dir=$specpath/ganyspec$name
+      outpath=$path$dir
+      rcfile=$outpath/ganymed_${name}_onoff.rc
+      if ! [ -d $outpath ]
       then 
-         mkdir -pv $dir
+         mkdir -v $outpath
       fi
-#      rcfile=$dir/ganymed_${val1}_${val3}_onoff.rc
-      rcfile=$dir/`basename $ganymedrc` 
-      if ! ls $rcfile >/dev/null 2>&1
-      then 
-         cat $ganymedrc | sed -e s/"${par1}"/"   ${val1}"/ -e s/"${par3}"/"  ${val3}"/ > $rcfile
-      else
-         echo "rcfile $rcfile already exists"
-      fi
+      cat $ganymedrc | sed -e s/"${par1}"/"   ${val1}"/ -e s/"${par3}"/"  ${val3}"/ > $rcfile
       val1=`echo $val1 + $par1step | bc`
+      echo " writing dag entry for set of cuts par1: $val1, par3: $val3"
+      echo "# ganymed and sponde for dataset $dataset with cuts $name" >> $dagfile
+      echo "" >> $dagfile
+      printganydagentry  >> $dagfile
+      for (( k=0 ; k < ${#spondes[@]} ; k++ ))
+      do 
+         printspecdagentry ${spondes[$k]} ${spondedones[$k]} >> $dagfile
+      done
+      echo "" >> $dagfile
+      count=`echo $count + 1 | bc`
    done
    val3=`echo $val3 + $par3step | bc`
@@ -173,62 +235,9 @@
 done
 
-
-# running ganymed and sponde for different parameter sets
-
-# function running ganymed and sponde for a set of cuts
-function dospec()
-{
-   cd $mars
-
-   name=$set/ganymed`printf %08d $ganymednum`
-   ganymedfile=$name.root
-   if ! ls $ganymedfile >/dev/null 2>&1
-   then 
-      cd $mars
-#      rc=`ls $set/ganymed_*onoff.rc`
-      ganymedlog=$name.log
-      echo "starting ganymed for set $set ..."
-      if ! condor_run ./ganymed -b -f --n=$ganymednum --log=$ganymedlog --out=$set --config=$set/`basename $ganymedrc` $dataset >/dev/null
-      then 
-         echo "condor is not working " 
-         return
-      fi
-   else
-      echo "ganymed for set $set already done => continue with sponde"
-   fi
-
-   if ! ls $sponderc >/dev/null 2>&1
-   then 
-      echo "ERROR: spondercfile $sponderc is missing"
-      return
-   fi
-   spondefile=$set/sponde$spondenum-g$ganymednum.root
-   spondelog=$set/sponde$spondenum-g$ganymednum.log
-   if ! ls $spondefile >/dev/null 2>&1
-   then
-      echo "starting sponde for set $set ..."
-      if ! condor_run ./sponde -b -f --log=$spondelog --config=$sponderc -f $ganymedfile $mcdataset $spondefile >/dev/null
-      then
-         echo "condor is not working " 
-         return
-      fi
-      echo "finished sponde for set $set ..."
-   else
-      echo "sponde $spondenum for set $set already done => please remove sponde files or give new spondenum"
-   fi
-}
-
-
-sets=`find $resultpath -type d`
-for set in ${sets[@]}
-do 
-#   echo "set: "$set
-   if [ "$set" == "$resultpath" ]
-   then
-      continue
-   fi
-   dospec &
-   sleep 3
-done
-
-
+echo ""
+echo "finished writing condor dag file "$dagfile
+echo "in total $count different sets of cuts are used"
+echo ""
+echo "you can submit it now with \"condor_submit_dag -f $dagfile\" from your Mars directory"
+echo ""
+
