| 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 | # Author(s): Daniel Hoehne 11/2007 <mailto:hoehne@astro.uni-wuerzburg.de>
|
|---|
| 21 | #
|
|---|
| 22 | # Copyright: MAGIC Software Development, 2000-2007
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 | # ========================================================================
|
|---|
| 26 | #
|
|---|
| 27 | #
|
|---|
| 28 | #
|
|---|
| 29 | ##############################################################################
|
|---|
| 30 | #
|
|---|
| 31 | # This script creates mc sequences and datasets for a psf, observation mode
|
|---|
| 32 | # and zenith range chosen by the user.
|
|---|
| 33 | #
|
|---|
| 34 | # variables, that have to be set by the user:
|
|---|
| 35 | # - path directory, where the mc sequence and dataset files are stored
|
|---|
| 36 | # be careful: don't move the sequence files afterwards, as the
|
|---|
| 37 | # paths are stored in the datasetfiles
|
|---|
| 38 | # - zdmin minimum zenith distance
|
|---|
| 39 | # - zdmax maximum zenith distance
|
|---|
| 40 | # - psf add. spot size before camera
|
|---|
| 41 | # - mode production mode of the mcs
|
|---|
| 42 | # the explanation for the modes can be found in the text and in
|
|---|
| 43 | # /magic/montecarlo/rawfiles/README.txt
|
|---|
| 44 | # - numruns number of runs, that are in the sequence file, which are used
|
|---|
| 45 | # for training (SequencesOn in $mcdataset)
|
|---|
| 46 | #
|
|---|
| 47 | # Remark: For the training of the RF for the energy estimation you need the
|
|---|
| 48 | # macro trainengery.C in the path $path/macros in a modified version,
|
|---|
| 49 | # i.e. the inputfile (mcdataset) and the outputfile (rf-root file)
|
|---|
| 50 | # are given as options:
|
|---|
| 51 | # $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$rffile\""\)
|
|---|
| 52 | #
|
|---|
| 53 | # Remark: You have to run the script in your Mars directory.
|
|---|
| 54 | #
|
|---|
| 55 | ##############################################################################
|
|---|
| 56 |
|
|---|
| 57 | # to be set by the user
|
|---|
| 58 | path=~
|
|---|
| 59 | # path where your mc sequence and dataset files are stored
|
|---|
| 60 | mcoutpath=$path/mc
|
|---|
| 61 | # path where you have your modified version of trainenergy.C
|
|---|
| 62 | macrospath=$path/macros
|
|---|
| 63 |
|
|---|
| 64 | # zenith range of your data
|
|---|
| 65 | zdmin=7
|
|---|
| 66 | zdmax=25
|
|---|
| 67 | # additional spotsize (before camera) for the mcs. You can calculate it with Sqrt(psf(real data)*psf(real data) - 25)
|
|---|
| 68 | psf=15
|
|---|
| 69 | # production mode of your data
|
|---|
| 70 | # available observation modes: On (please leave modes empty: ""), Wobble ("W1", "W2"), Fake Wobble ("FW"), Diffuse ("Diff")
|
|---|
| 71 | # you can combine these with: high energy (harder spectrum: "HE")
|
|---|
| 72 | # particle type: "Muon", "Gamma" or "Proton"
|
|---|
| 73 | # remark: first the particle, then the spectrum and the observation mode at the end: Examples mode="GammaHEFW" or "ProtonDiff" or "GammaW1"
|
|---|
| 74 | # please have also a look into /magic/montecarlo/rawfiles/README.txt
|
|---|
| 75 | # you can also use asterisks, e.g.: "GammaW*" for W1 and W2
|
|---|
| 76 | mode="GammaW1"
|
|---|
| 77 | # epoch for which the mc were produced
|
|---|
| 78 | # available epochs: MC_old MC_April_May06 MC_post_June06 MC_MuxFADCs MCMuxFADCs_NEW (last one is for Mux data with reduced fadc slices number)
|
|---|
| 79 | epos=( "MC_Old" )
|
|---|
| 80 | # number of runs which are in the sequence files used for training
|
|---|
| 81 | # please adjust this number such, that you use about 30000 Events for training
|
|---|
| 82 | numruns=2
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | # some checks
|
|---|
| 88 | # checking if the given files and paths are existing
|
|---|
| 89 | if ! [ -e $mcoutpath ]
|
|---|
| 90 | then
|
|---|
| 91 | echo "Your outpath for the mc $mcoutpath does not exist."
|
|---|
| 92 | exit
|
|---|
| 93 | fi
|
|---|
| 94 | if ! [ -e $macrospath ]
|
|---|
| 95 | then
|
|---|
| 96 | echo "Your macros path $macrospath does not exist."
|
|---|
| 97 | exit
|
|---|
| 98 | fi
|
|---|
| 99 | if ! [ -e $macrospath/trainenergy.C ]
|
|---|
| 100 | then
|
|---|
| 101 | echo "Your trainenergy.C does not exist in path $macrospath."
|
|---|
| 102 | exit
|
|---|
| 103 | fi
|
|---|
| 104 |
|
|---|
| 105 | mcdatasettrain=$mcoutpath/mcdataset-for-training.txt
|
|---|
| 106 | mcdatasetsponde=$mcoutpath/mcdataset-for-sponde.txt
|
|---|
| 107 |
|
|---|
| 108 | # be careful with $date, when path changes
|
|---|
| 109 | mcpath=/magic/montecarlo
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
|
|---|
| 113 | zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
|
|---|
| 114 |
|
|---|
| 115 | zbinmin=`echo $zbinmin | cut -d. -f1`
|
|---|
| 116 | zbinmax=`echo $zbinmax | cut -d. -f1`
|
|---|
| 117 |
|
|---|
| 118 | echo "zd: min: $zdmin max: $zdmax"
|
|---|
| 119 | echo "zbin: min: $zbinmin max: $zbinmax"
|
|---|
| 120 | echo "$numruns runs are classified as test, the rest as train"
|
|---|
| 121 |
|
|---|
| 122 | j=0
|
|---|
| 123 | for epo in $epos
|
|---|
| 124 | do
|
|---|
| 125 | for (( i=$zbinmin ; i < $zbinmax ; i++ ))
|
|---|
| 126 | do
|
|---|
| 127 | #depending on the epoch you need different P and C runs and time codes
|
|---|
| 128 | case "$epo" in
|
|---|
| 129 |
|
|---|
| 130 | "MC_up_to_April06")
|
|---|
| 131 | prun=272
|
|---|
| 132 | crun=273
|
|---|
| 133 | time="03"
|
|---|
| 134 | ;;
|
|---|
| 135 | "MC_old")
|
|---|
| 136 | prun=4223
|
|---|
| 137 | crun=4224
|
|---|
| 138 | time="03"
|
|---|
| 139 | ;;
|
|---|
| 140 | "MC_April_May06")
|
|---|
| 141 | prun=272
|
|---|
| 142 | crun=273
|
|---|
| 143 | time="02"
|
|---|
| 144 | ;;
|
|---|
| 145 | "MC_post_June06")
|
|---|
| 146 | prun=1048
|
|---|
| 147 | crun=1049
|
|---|
| 148 | time="02"
|
|---|
| 149 | ;;
|
|---|
| 150 | "MC_MuxFADCs")
|
|---|
| 151 | prun=3919
|
|---|
| 152 | crun=3920
|
|---|
| 153 | time="01"
|
|---|
| 154 | ;;
|
|---|
| 155 | "MC_MuxFADCs_NEW")
|
|---|
| 156 | prun=270
|
|---|
| 157 | crun=271
|
|---|
| 158 | time="01"
|
|---|
| 159 | ;;
|
|---|
| 160 | *)
|
|---|
| 161 | echo "Wrong epoch $epo , please specify a valid epoch"
|
|---|
| 162 | continue
|
|---|
| 163 | ;;
|
|---|
| 164 | esac
|
|---|
| 165 |
|
|---|
| 166 | zbin=`printf %02d $i`
|
|---|
| 167 | path=$mcpath/rawfiles/19$zbin/$time/$psf
|
|---|
| 168 | runs=(`ls $path | grep $mode | 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' -e 's/^0//g' | tr "\n" " "`)
|
|---|
| 169 | if [ "$runs" = "" ]
|
|---|
| 170 | then
|
|---|
| 171 | echo " No runs for zbin $i found. Please try to find some MC with zbin $i!"
|
|---|
| 172 | continue
|
|---|
| 173 | fi
|
|---|
| 174 | echo "found ${#runs[@]} Gamma MC files in path "$path
|
|---|
| 175 |
|
|---|
| 176 | runsforfirst=""
|
|---|
| 177 | firstrun=${runs[0]}
|
|---|
| 178 | secondrun=${runs[${numruns}]}
|
|---|
| 179 | firstrunno=`printf %08d $firstrun`
|
|---|
| 180 | secondrunno=`printf %08d $secondrun`
|
|---|
| 181 | unset runs[0]
|
|---|
| 182 | for (( k=1 ; k < $numruns ; k++ ))
|
|---|
| 183 | do
|
|---|
| 184 | runsforfirst=$runsforfirst" ${runs[$k]}"
|
|---|
| 185 | unset runs[$k]
|
|---|
| 186 | done
|
|---|
| 187 | date=`echo $path | cut -d/ -f5-7 | sed -e 's/\//-/g'`
|
|---|
| 188 |
|
|---|
| 189 | trainsequfile=$mcoutpath/sequence$firstrunno.txt
|
|---|
| 190 | trainsequences[$j]=$firstrunno
|
|---|
| 191 | # echo " writing train-sequfile "$trainsequfile
|
|---|
| 192 | echo "Sequence: $firstrun" > $trainsequfile
|
|---|
| 193 | echo "Night: $date" >> $trainsequfile
|
|---|
| 194 | echo "" >> $trainsequfile
|
|---|
| 195 | echo "CalRuns: 1" >> $trainsequfile
|
|---|
| 196 | echo "PedRuns: 2" >> $trainsequfile
|
|---|
| 197 | echo "DatRuns: $firstrun$runsforfirst" >> $trainsequfile
|
|---|
| 198 | echo "" >> $trainsequfile
|
|---|
| 199 | echo "MonteCarlo: Yes" >> $trainsequfile
|
|---|
| 200 | echo "" >> $trainsequfile
|
|---|
| 201 |
|
|---|
| 202 | testsequfile=$mcoutpath/sequence$secondrunno.txt
|
|---|
| 203 | testsequences[$j]=$secondrunno
|
|---|
| 204 | # echo "writing test-sequfile "$testsequfile
|
|---|
| 205 | echo "Sequence: $secondrun" > $testsequfile
|
|---|
| 206 | echo "Night: $date" >> $testsequfile
|
|---|
| 207 | echo "" >> $testsequfile
|
|---|
| 208 | echo "CalRuns: 1" >> $testsequfile
|
|---|
| 209 | echo "PedRuns: 2" >> $testsequfile
|
|---|
| 210 | echo "DatRuns: ${runs[@]}" >> $testsequfile
|
|---|
| 211 | echo "" >> $testsequfile
|
|---|
| 212 | echo "MonteCarlo: Yes" >> $testsequfile
|
|---|
| 213 | echo "" >> $testsequfile
|
|---|
| 214 |
|
|---|
| 215 | j=$j+1
|
|---|
| 216 | done
|
|---|
| 217 | done
|
|---|
| 218 |
|
|---|
| 219 | echo "# test sequences: ${#testsequences[@]}"
|
|---|
| 220 | echo "# train sequences: ${#trainsequences[@]}"
|
|---|
| 221 |
|
|---|
| 222 | echo "AnalysisNumber: 1 " > $mcdatasettrain
|
|---|
| 223 | echo "" >> $mcdatasettrain
|
|---|
| 224 | echo "SequencesOn: ${trainsequences[@]}" >> $mcdatasettrain
|
|---|
| 225 | echo "" >> $mcdatasettrain
|
|---|
| 226 | echo "SequencesOff: ${testsequences[@]}" >> $mcdatasettrain
|
|---|
| 227 | echo "" >> $mcdatasettrain
|
|---|
| 228 | echo "" >> $mcdatasettrain
|
|---|
| 229 |
|
|---|
| 230 | echo "AnalysisNumber: 1 " > $mcdatasetsponde
|
|---|
| 231 | echo "" >> $mcdatasetsponde
|
|---|
| 232 | echo "SequencesOn: ${testsequences[@]}" >> $mcdatasetsponde
|
|---|
| 233 | echo "" >> $mcdatasetsponde
|
|---|
| 234 | echo "" >> $mcdatasetsponde
|
|---|
| 235 |
|
|---|
| 236 | for (( i=0 ; i < ${#testsequences[@]} ; i++ ))
|
|---|
| 237 | do
|
|---|
| 238 | numtrain=${trainsequences[$i]}
|
|---|
| 239 | notrain=`echo $numtrain | cut -c 0-4`
|
|---|
| 240 | echo "Sequence$numtrain.File: $mcoutpath/sequence$numtrain.txt" >> $mcdatasettrain
|
|---|
| 241 | echo "Sequence$numtrain.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasettrain
|
|---|
| 242 |
|
|---|
| 243 | numtest=${testsequences[$i]}
|
|---|
| 244 | notest=`echo $numtest | cut -c 0-4`
|
|---|
| 245 | echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdatasettrain
|
|---|
| 246 | echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasettrain
|
|---|
| 247 | echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdatasetsponde
|
|---|
| 248 | echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasetsponde
|
|---|
| 249 | done
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 | # train the rf for energy estimation
|
|---|
| 253 | logfile=$mcoutpath/trainenergy.log
|
|---|
| 254 | rffile=$mcoutpath/rf-energy.root
|
|---|
| 255 |
|
|---|
| 256 | echo "Your mcdataset for training: $mcdatasettrain"
|
|---|
| 257 | echo "Your rffile: $rffile"
|
|---|
| 258 | echo ""
|
|---|
| 259 | echo "Training the RF..."
|
|---|
| 260 | root -q -b $macrospath/trainenergy.C+\("\"$mcdatasettrain\""\,"\"$rffile\""\) | tee $logfile
|
|---|
| 261 |
|
|---|
| 262 | echo ""
|
|---|
| 263 | echo "Please use rf-file $rffile in your sponde.rc, in case you want to use the RF energy estimator there. "
|
|---|