Index: trunk/MagicSoft/Mars/scripts/preparemc
===================================================================
--- trunk/MagicSoft/Mars/scripts/preparemc	(revision 8227)
+++ trunk/MagicSoft/Mars/scripts/preparemc	(revision 8626)
@@ -1,4 +1,3 @@
 #!/bin/sh
-#
 # ========================================================================
 #
@@ -20,5 +19,5 @@
 #   Author(s): Daniela Dorner  05/2006 <mailto:dorner@astro.uni-wuerzburg.de>
 #
-#   Copyright: MAGIC Software Development, 2000-2006
+#   Copyright: MAGIC Software Development, 2000-2007
 #
 #
@@ -33,10 +32,7 @@
 #
 # variables, that have to be set by the user:
-# - dir          directory, where the mc sequence and dataset files are stored 
+# - path         directory, where the mc sequence and dataset files are stored 
 #                 be careful: don't move the sequence files afterwards, as the 
 #                 paths are stored in the datasetfiles
-# - mars         directory, where your Mars version is stored
-#                 only needed, if you want to create a rf-root-file for the 
-#                 energy estimation 
 # - zdmin        minimum zenith distance
 # - zdmax        maximum zenith distance
@@ -48,59 +44,48 @@
 # - numruns      num of runs, that are in the sequence file, which are used 
 #                 for training (SequencesOn in $mcdataset)
-# - trainenergy  if set to 'yes', the rf for energy estimation is trained
+# 
+# Remark: For the training of the RF for the energy estimation you need the 
+# macro trainengery.C in the path $path/macros in a modified version, i.e. the
+# inputfile (mcdataset) and the outputfile (rf-root file) are given as
+# options: $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$rffile\""\) 
 #
+# Remark: You have to run the script in your Mars directory.
 # 
 ##############################################################################
 
 
+path=/home/dorner/final_analysis
+mcoutpath=$path/mc
+macrospath=$path/macros
+mcdataset=$mcoutpath/mcdataset.txt
+mcdataset2=$mcoutpath/mcdataset2.txt
 
-#to be set by the user 
-dir=/home/dorner/crabspectrum 
-mars=/home/dorner/mars.cvs 
-zdmin=5
+zdmin=17
 zdmax=35
 psf=14
-modes=( "02" "04" ) # e.g. nowobble
-numruns=5
-# set here if you want to train a rf-engery-estimator
-#trainenergy=
-trainenergy="yes"
+modes=( "02" ) # nowobble
+numruns=3
 
+# be careful with $date, when path changes
+mcpath=/magic/montecarlo 
 
-# begin of script
-datasetdir=$dir/datasets
-sequencedir=$dir/sequences
-setupdir=$dir/setup
-mcdir=/magic/montecarlo
-mcrawdir=$mcdir/rawfiles
-mcstardir=$mcdir/star
-mcdataset=$datasetdir/mcdataset-test-train.txt
-mcdataset2=$datasetdir/mcdataset-for-sponde.txt
-
-# make directories 
-mkdir -pv $dir
-mkdir -v $sequencedir
-mkdir -v $datasetdir
-
-#calculation of the zbin
 zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
 zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
+
 zbinmin=`echo $zbinmin | cut -d. -f1`
 zbinmax=`echo $zbinmax | cut -d. -f1`
-echo "zd: min: $zbinmin max: $zbinmax"
-echo "numruns: $numruns"
+
+echo "zd:   min: $zdmin max: $zdmax"
+echo "zbin: min: $zbinmin max: $zbinmax"
+echo "$numruns runs are classified as test the rest as train"
 
 j=0
-for mode in ${modes[@]}
+for mode in $modes
 do 
-   echo "mode: "$mode
    for (( i=$zbinmin ; i < $zbinmax ; i++ ))
    do 
       zbin=`printf %02d $i`
-      echo "zbin: $zbin"
-      path=$mcrawdir/19$zbin/$mode/$psf
-      runsforfirst=
-
-      runs=(`ls $path 2>/dev/null | grep Gamma | cut -d_ -f2 | sed -e 's/^0//g' -e 's/^0//g' -e 's/^0//g' -e 's/^0//g' | tr "\n" " "`)
+      path=$mcpath/rawfiles/19$zbin/$mode/$psf
+      runs=(`ls $path | grep Gamma | cut -d_ -f2 | sed -e 's/^0//g' -e 's/^0//g' -e 's/^0//g' -e 's/^0//g' -e 's/^0//g' -e 's/^0//g' | tr "\n" " "`)
       if [ "$runs" = "" ]
       then
@@ -108,5 +93,7 @@
          continue
       fi
+      echo "found ${#runs[@]} Gamma MC files in path "$path
 
+      runsforfirst=""
       firstrun=${runs[0]}
       secondrun=${runs[${numruns}]}
@@ -119,9 +106,7 @@
          unset runs[$k]
       done
-      mcrawdir2=`echo $mcrawdir | sed -e 's/\//\\\\\//g'` 
-      date=`echo $path | sed -e "s/$mcrawdir2\///" -e 's/\//-/g'` 
-#      date=`echo $path | cut -c 22-31 | sed -e 's/\//-/g'`
+      date=`echo $path | cut -d/ -f5-7 | sed -e 's/\//-/g'`
       
-      trainsequfile=$sequencedir/sequence$firstrunno.txt
+      trainsequfile=$mcoutpath/sequence$firstrunno.txt
       trainsequences[$j]=$firstrunno
       echo "  writing train-sequfile "$trainsequfile 
@@ -133,8 +118,10 @@
       echo "DatRuns:         $firstrun$runsforfirst" >> $trainsequfile
       echo "" >> $trainsequfile
+      echo "MonteCarlo: Yes" >> $trainsequfile
+      echo "" >> $trainsequfile
 
-      testsequfile=$sequencedir/sequence$secondrunno.txt
+      testsequfile=$mcoutpath/sequence$secondrunno.txt
       testsequences[$j]=$secondrunno
-      echo "  writing test-sequfile "$testsequfile 
+#      echo "writing test-sequfile "$testsequfile 
       echo "Sequence:        $secondrun" > $testsequfile
       echo "Night:           $date" >> $testsequfile
@@ -144,4 +131,6 @@
       echo "DatRuns:         ${runs[@]}" >> $testsequfile
       echo "" >> $testsequfile
+      echo "MonteCarlo: Yes" >> $testsequfile
+      echo "" >> $testsequfile
       
       j=$j+1
@@ -149,9 +138,6 @@
 done
 
-
 echo "# test sequences: ${#testsequences[@]}"
 echo "# train sequences: ${#trainsequences[@]}"
-
-echo "writing dataset files $mcdataset and $mcdataset2"
 
 echo "AnalysisNumber: 1 " > $mcdataset
@@ -173,24 +159,24 @@
    numtrain=${trainsequences[$i]}
    notrain=`echo $numtrain | cut -c 0-4`
-   echo "Sequence$numtrain.File: $sequencedir/sequence$numtrain.txt" >> $mcdataset
-   echo "Sequence$numtrain.Dir:  $mcstardir/$notrain/$numtrain" >> $mcdataset
-   echo "Sequence$numtrain.File: $sequencedir/sequence$numtrain.txt" >> $mcdataset2
-   echo "Sequence$numtrain.Dir:  $mcstardir/$notrain/$numtrain" >> $mcdataset2
+   echo "Sequence$numtrain.File: $mcoutpath/sequence$numtrain.txt" >> $mcdataset
+   echo "Sequence$numtrain.Dir:  $mcpath/star/$notrain/$numtrain" >> $mcdataset
+   echo "Sequence$numtrain.File: $mcoutpath/sequence$numtrain.txt" >> $mcdataset2
+   echo "Sequence$numtrain.Dir:  $mcpath/star/$notrain/$numtrain" >> $mcdataset2
 
    numtest=${testsequences[$i]}
    notest=`echo $numtest | cut -c 0-4`
-   echo "Sequence$numtest.File: $sequencedir/sequence$numtest.txt" >> $mcdataset
-   echo "Sequence$numtest.Dir:  $mcstardir/$notrain/$numtrain" >> $mcdataset
-   echo "Sequence$numtest.File: $sequencedir/sequence$numtest.txt" >> $mcdataset2
-   echo "Sequence$numtest.Dir:  $mcstardir/$notrain/$numtrain" >> $mcdataset2
+   echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdataset
+   echo "Sequence$numtest.Dir:  $mcpath/star/$notrain/$numtrain" >> $mcdataset
+   echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdataset2
+   echo "Sequence$numtest.Dir:  $mcpath/star/$notrain/$numtrain" >> $mcdataset2
 done
 
 
-if [ "$trainenergy" == "yes" ]
-then 
-   echo "creating rf-root-file for energy-estimation..."
-   cd $mars
-   logfile=$setupdir/trainenergy.log
+logfile=$mcoutpath/trainenergy.log
+rffile=$mcoutpath/rf-energy.root
 
-   root -q -b $mars/datacenter/macros/trainenergy.C+\("\"$mcdataset\""\,"\"$setupdir/\""\) | tee $logfile
-fi
+echo "mcdataset: $mcdataset"
+echo "rffile: $rffile"
+echo "macrospath: $macrospath"
+root -q -b $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$rffile\""\) | tee $logfile
+
