| 1 | #!/bin/sh
|
|---|
| 2 | # ========================================================================
|
|---|
| 3 | #
|
|---|
| 4 | # *
|
|---|
| 5 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 6 | # * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 7 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 8 | # * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 9 | # *
|
|---|
| 10 | # * Permission to use, copy, modify and distribute this software and its
|
|---|
| 11 | # * documentation for any purpose is hereby granted without fee,
|
|---|
| 12 | # * provided that the above copyright notice appear in all copies and
|
|---|
| 13 | # * that both that copyright notice and this permission notice appear
|
|---|
| 14 | # * in supporting documentation. It is provided "as is" without express
|
|---|
| 15 | # * or implied warranty.
|
|---|
| 16 | # *
|
|---|
| 17 | #
|
|---|
| 18 | #
|
|---|
| 19 | # Author(s): Daniela Dorner 05/2006 <mailto:dorner@astro.uni-wuerzburg.de>
|
|---|
| 20 | #
|
|---|
| 21 | # Copyright: MAGIC Software Development, 2000-2007
|
|---|
| 22 | #
|
|---|
| 23 | #
|
|---|
| 24 | # ========================================================================
|
|---|
| 25 | #
|
|---|
| 26 | #
|
|---|
| 27 | #
|
|---|
| 28 | ##############################################################################
|
|---|
| 29 | #
|
|---|
| 30 | # This script creates mc sequences and datasets for a psf, observation mode
|
|---|
| 31 | # and zenith range chosen by the user.
|
|---|
| 32 | #
|
|---|
| 33 | # variables, that have to be set by the user:
|
|---|
| 34 | # - path directory, where the mc sequence and dataset files are stored
|
|---|
| 35 | # be careful: don't move the sequence files afterwards, as the
|
|---|
| 36 | # paths are stored in the datasetfiles
|
|---|
| 37 | # - zdmin minimum zenith distance
|
|---|
| 38 | # - zdmax maximum zenith distance
|
|---|
| 39 | # - psf psf (at the moment mc with psf 14 and 20 is available)
|
|---|
| 40 | # - modes observation mode
|
|---|
| 41 | # the explanation for the modes can be found in
|
|---|
| 42 | # /magic/montecarlo/rawfiles/README.txt
|
|---|
| 43 | # - numruns number of runs, that are in the sequence file, which are used
|
|---|
| 44 | # for training (SequencesOn in $mcdataset)
|
|---|
| 45 | #
|
|---|
| 46 | # Remark: For the training of the RF for the energy estimation you need the
|
|---|
| 47 | # macro trainengery.C in the path $path/macros in a modified version,
|
|---|
| 48 | # i.e. the inputfile (mcdataset) and the outputfile (rf-root file)
|
|---|
| 49 | # are given as options:
|
|---|
| 50 | # $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$rffile\""\)
|
|---|
| 51 | #
|
|---|
| 52 | # Remark: You have to run the script in your Mars directory.
|
|---|
| 53 | #
|
|---|
| 54 | ##############################################################################
|
|---|
| 55 |
|
|---|
| 56 | # to be set by the user
|
|---|
| 57 | path=/home/dorner/final_analysis
|
|---|
| 58 | # path where your mc sequence and dataset files are stored
|
|---|
| 59 | mcoutpath=$path/mc
|
|---|
| 60 | # path where you have your modified version of trainenergy.C
|
|---|
| 61 | macrospath=$path/macros
|
|---|
| 62 |
|
|---|
| 63 | # zenith range of your data
|
|---|
| 64 | zdmin=17
|
|---|
| 65 | zdmax=36
|
|---|
| 66 | # point spread function of your data
|
|---|
| 67 | psf=14
|
|---|
| 68 | # observation mode of your data
|
|---|
| 69 | # for explanations see /magic/montecarlo/rawfiles/README.txt
|
|---|
| 70 | modes=( "02" )
|
|---|
| 71 | # number of runs which are in the sequence files used for training
|
|---|
| 72 | # please adjust this number such, that you use about 30000 Events for training
|
|---|
| 73 | numruns=1
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | # some checks
|
|---|
| 79 | # checking if the given files and paths are existing
|
|---|
| 80 | if ! [ -e $mcoutpath ]
|
|---|
| 81 | then
|
|---|
| 82 | echo "Your outpath for the mc $mcoutpathdoes not exist."
|
|---|
| 83 | exit
|
|---|
| 84 | fi
|
|---|
| 85 | if ! [ -e $macrospath ]
|
|---|
| 86 | then
|
|---|
| 87 | echo "Your macros path $macrospath does not exist."
|
|---|
| 88 | exit
|
|---|
| 89 | fi
|
|---|
| 90 | if ! [ -e $macrospath/trainenergy.C ]
|
|---|
| 91 | then
|
|---|
| 92 | echo "Your trainenergy.C does not exist in path $macrospath."
|
|---|
| 93 | exit
|
|---|
| 94 | fi
|
|---|
| 95 |
|
|---|
| 96 | mcdatasettrain=$mcoutpath/mcdataset-for-training.txt
|
|---|
| 97 | mcdatasetsponde=$mcoutpath/mcdataset-for-sponde.txt
|
|---|
| 98 |
|
|---|
| 99 | # be careful with $date, when path changes
|
|---|
| 100 | mcpath=/magic/montecarlo
|
|---|
| 101 |
|
|---|
| 102 | zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
|
|---|
| 103 | zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
|
|---|
| 104 |
|
|---|
| 105 | zbinmin=`echo $zbinmin | cut -d. -f1`
|
|---|
| 106 | zbinmax=`echo $zbinmax | cut -d. -f1`
|
|---|
| 107 |
|
|---|
| 108 | echo "zd: min: $zdmin max: $zdmax"
|
|---|
| 109 | echo "zbin: min: $zbinmin max: $zbinmax"
|
|---|
| 110 | echo "$numruns runs are classified as test the rest as train"
|
|---|
| 111 |
|
|---|
| 112 | j=0
|
|---|
| 113 | for mode in $modes
|
|---|
| 114 | do
|
|---|
| 115 | for (( i=$zbinmin ; i < $zbinmax ; i++ ))
|
|---|
| 116 | do
|
|---|
| 117 | zbin=`printf %02d $i`
|
|---|
| 118 | path=$mcpath/rawfiles/19$zbin/$mode/$psf
|
|---|
| 119 | 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" " "`)
|
|---|
| 120 | if [ "$runs" = "" ]
|
|---|
| 121 | then
|
|---|
| 122 | echo " No runs for zbin $i found. Please try to find some MC with zbin $i!"
|
|---|
| 123 | continue
|
|---|
| 124 | fi
|
|---|
| 125 | echo "found ${#runs[@]} Gamma MC files in path "$path
|
|---|
| 126 |
|
|---|
| 127 | runsforfirst=""
|
|---|
| 128 | firstrun=${runs[0]}
|
|---|
| 129 | secondrun=${runs[${numruns}]}
|
|---|
| 130 | firstrunno=`printf %08d $firstrun`
|
|---|
| 131 | secondrunno=`printf %08d $secondrun`
|
|---|
| 132 | unset runs[0]
|
|---|
| 133 | for (( k=1 ; k < $numruns ; k++ ))
|
|---|
| 134 | do
|
|---|
| 135 | runsforfirst=$runsforfirst" ${runs[$k]}"
|
|---|
| 136 | unset runs[$k]
|
|---|
| 137 | done
|
|---|
| 138 | date=`echo $path | cut -d/ -f5-7 | sed -e 's/\//-/g'`
|
|---|
| 139 |
|
|---|
| 140 | trainsequfile=$mcoutpath/sequence$firstrunno.txt
|
|---|
| 141 | trainsequences[$j]=$firstrunno
|
|---|
| 142 | # echo " writing train-sequfile "$trainsequfile
|
|---|
| 143 | echo "Sequence: $firstrun" > $trainsequfile
|
|---|
| 144 | echo "Night: $date" >> $trainsequfile
|
|---|
| 145 | echo "" >> $trainsequfile
|
|---|
| 146 | echo "CalRuns: 1" >> $trainsequfile
|
|---|
| 147 | echo "PedRuns: 2" >> $trainsequfile
|
|---|
| 148 | echo "DatRuns: $firstrun$runsforfirst" >> $trainsequfile
|
|---|
| 149 | echo "" >> $trainsequfile
|
|---|
| 150 | echo "MonteCarlo: Yes" >> $trainsequfile
|
|---|
| 151 | echo "" >> $trainsequfile
|
|---|
| 152 |
|
|---|
| 153 | testsequfile=$mcoutpath/sequence$secondrunno.txt
|
|---|
| 154 | testsequences[$j]=$secondrunno
|
|---|
| 155 | # echo "writing test-sequfile "$testsequfile
|
|---|
| 156 | echo "Sequence: $secondrun" > $testsequfile
|
|---|
| 157 | echo "Night: $date" >> $testsequfile
|
|---|
| 158 | echo "" >> $testsequfile
|
|---|
| 159 | echo "CalRuns: 1" >> $testsequfile
|
|---|
| 160 | echo "PedRuns: 2" >> $testsequfile
|
|---|
| 161 | echo "DatRuns: ${runs[@]}" >> $testsequfile
|
|---|
| 162 | echo "" >> $testsequfile
|
|---|
| 163 | echo "MonteCarlo: Yes" >> $testsequfile
|
|---|
| 164 | echo "" >> $testsequfile
|
|---|
| 165 |
|
|---|
| 166 | j=$j+1
|
|---|
| 167 | done
|
|---|
| 168 | done
|
|---|
| 169 |
|
|---|
| 170 | echo "# test sequences: ${#testsequences[@]}"
|
|---|
| 171 | echo "# train sequences: ${#trainsequences[@]}"
|
|---|
| 172 |
|
|---|
| 173 | echo "AnalysisNumber: 1 " > $mcdatasettrain
|
|---|
| 174 | echo "" >> $mcdatasettrain
|
|---|
| 175 | echo "SequencesOn: ${trainsequences[@]}" >> $mcdatasettrain
|
|---|
| 176 | echo "" >> $mcdatasettrain
|
|---|
| 177 | echo "SequencesOff: ${testsequences[@]}" >> $mcdatasettrain
|
|---|
| 178 | echo "" >> $mcdatasettrain
|
|---|
| 179 | echo "" >> $mcdatasettrain
|
|---|
| 180 |
|
|---|
| 181 | echo "AnalysisNumber: 1 " > $mcdatasetsponde
|
|---|
| 182 | echo "" >> $mcdatasetsponde
|
|---|
| 183 | echo "SequencesOn: ${testsequences[@]}" >> $mcdatasetsponde
|
|---|
| 184 | echo "" >> $mcdatasetsponde
|
|---|
| 185 | echo "" >> $mcdatasetsponde
|
|---|
| 186 |
|
|---|
| 187 | for (( i=0 ; i < ${#testsequences[@]} ; i++ ))
|
|---|
| 188 | do
|
|---|
| 189 | numtrain=${trainsequences[$i]}
|
|---|
| 190 | notrain=`echo $numtrain | cut -c 0-4`
|
|---|
| 191 | echo "Sequence$numtrain.File: $mcoutpath/sequence$numtrain.txt" >> $mcdatasettrain
|
|---|
| 192 | echo "Sequence$numtrain.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasettrain
|
|---|
| 193 |
|
|---|
| 194 | numtest=${testsequences[$i]}
|
|---|
| 195 | notest=`echo $numtest | cut -c 0-4`
|
|---|
| 196 | echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdatasettrain
|
|---|
| 197 | echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasettrain
|
|---|
| 198 | echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdatasetsponde
|
|---|
| 199 | echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasetsponde
|
|---|
| 200 | done
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 | # train the rf for energy estimation
|
|---|
| 204 | logfile=$mcoutpath/trainenergy.log
|
|---|
| 205 | rffile=$mcoutpath/rf-energy.root
|
|---|
| 206 |
|
|---|
| 207 | echo "Your mcdataset for training: $mcdatasettrain"
|
|---|
| 208 | echo "Your rffile: $rffile"
|
|---|
| 209 | echo ""
|
|---|
| 210 | echo "Training the RF..."
|
|---|
| 211 | root -q -b $macrospath/trainenergy.C+\("\"$mcdatasettrain\""\,"\"$rffile\""\) | tee $logfile
|
|---|
| 212 |
|
|---|
| 213 | echo ""
|
|---|
| 214 | echo "Please use rf-file $rffile in your sponde.rc, in case you want to use the RF energy estimator there. "
|
|---|