source: tags/Mars-V1.1/scripts/preparemc

Last change on this file was 8227, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 6.6 KB
Line 
1#!/bin/sh
2#
3# ========================================================================
4#
5# *
6# * This file is part of MARS, the MAGIC Analysis and Reconstruction
7# * Software. It is distributed to you in the hope that it can be a useful
8# * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9# * It is distributed WITHOUT ANY WARRANTY.
10# *
11# * Permission to use, copy, modify and distribute this software and its
12# * documentation for any purpose is hereby granted without fee,
13# * provided that the above copyright notice appear in all copies and
14# * that both that copyright notice and this permission notice appear
15# * in supporting documentation. It is provided "as is" without express
16# * or implied warranty.
17# *
18#
19#
20# Author(s): Daniela Dorner 05/2006 <mailto:dorner@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2006
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# - dir 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# - mars directory, where your Mars version is stored
39# only needed, if you want to create a rf-root-file for the
40# energy estimation
41# - zdmin minimum zenith distance
42# - zdmax maximum zenith distance
43# - psf psf
44# at the moment mc with psf 14 and 20 is available
45# - modes observation mode
46# the explanation for the modes can be found in
47# /montecarlo/rawfiles/README.txt
48# - numruns num of runs, that are in the sequence file, which are used
49# for training (SequencesOn in $mcdataset)
50# - trainenergy if set to 'yes', the rf for energy estimation is trained
51#
52#
53##############################################################################
54
55
56
57#to be set by the user
58dir=/home/dorner/crabspectrum
59mars=/home/dorner/mars.cvs
60zdmin=5
61zdmax=35
62psf=14
63modes=( "02" "04" ) # e.g. nowobble
64numruns=5
65# set here if you want to train a rf-engery-estimator
66#trainenergy=
67trainenergy="yes"
68
69
70# begin of script
71datasetdir=$dir/datasets
72sequencedir=$dir/sequences
73setupdir=$dir/setup
74mcdir=/magic/montecarlo
75mcrawdir=$mcdir/rawfiles
76mcstardir=$mcdir/star
77mcdataset=$datasetdir/mcdataset-test-train.txt
78mcdataset2=$datasetdir/mcdataset-for-sponde.txt
79
80# make directories
81mkdir -pv $dir
82mkdir -v $sequencedir
83mkdir -v $datasetdir
84
85#calculation of the zbin
86zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
87zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
88zbinmin=`echo $zbinmin | cut -d. -f1`
89zbinmax=`echo $zbinmax | cut -d. -f1`
90echo "zd: min: $zbinmin max: $zbinmax"
91echo "numruns: $numruns"
92
93j=0
94for mode in ${modes[@]}
95do
96 echo "mode: "$mode
97 for (( i=$zbinmin ; i < $zbinmax ; i++ ))
98 do
99 zbin=`printf %02d $i`
100 echo "zbin: $zbin"
101 path=$mcrawdir/19$zbin/$mode/$psf
102 runsforfirst=
103
104 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" " "`)
105 if [ "$runs" = "" ]
106 then
107 echo " no runs found for zbin $i "
108 continue
109 fi
110
111 firstrun=${runs[0]}
112 secondrun=${runs[${numruns}]}
113 firstrunno=`printf %08d $firstrun`
114 secondrunno=`printf %08d $secondrun`
115 unset runs[0]
116 for (( k=1 ; k < $numruns ; k++ ))
117 do
118 runsforfirst=$runsforfirst" ${runs[$k]}"
119 unset runs[$k]
120 done
121 mcrawdir2=`echo $mcrawdir | sed -e 's/\//\\\\\//g'`
122 date=`echo $path | sed -e "s/$mcrawdir2\///" -e 's/\//-/g'`
123# date=`echo $path | cut -c 22-31 | sed -e 's/\//-/g'`
124
125 trainsequfile=$sequencedir/sequence$firstrunno.txt
126 trainsequences[$j]=$firstrunno
127 echo " writing train-sequfile "$trainsequfile
128 echo "Sequence: $firstrun" > $trainsequfile
129 echo "Night: $date" >> $trainsequfile
130 echo "" >> $trainsequfile
131 echo "CalRuns: 1" >> $trainsequfile
132 echo "PedRuns: 2" >> $trainsequfile
133 echo "DatRuns: $firstrun$runsforfirst" >> $trainsequfile
134 echo "" >> $trainsequfile
135
136 testsequfile=$sequencedir/sequence$secondrunno.txt
137 testsequences[$j]=$secondrunno
138 echo " writing test-sequfile "$testsequfile
139 echo "Sequence: $secondrun" > $testsequfile
140 echo "Night: $date" >> $testsequfile
141 echo "" >> $testsequfile
142 echo "CalRuns: 1" >> $testsequfile
143 echo "PedRuns: 2" >> $testsequfile
144 echo "DatRuns: ${runs[@]}" >> $testsequfile
145 echo "" >> $testsequfile
146
147 j=$j+1
148 done
149done
150
151
152echo "# test sequences: ${#testsequences[@]}"
153echo "# train sequences: ${#trainsequences[@]}"
154
155echo "writing dataset files $mcdataset and $mcdataset2"
156
157echo "AnalysisNumber: 1 " > $mcdataset
158echo "" >> $mcdataset
159echo "SequencesOn: ${trainsequences[@]}" >> $mcdataset
160echo "" >> $mcdataset
161echo "SequencesOff: ${testsequences[@]}" >> $mcdataset
162echo "" >> $mcdataset
163echo "" >> $mcdataset
164
165echo "AnalysisNumber: 1 " > $mcdataset2
166echo "" >> $mcdataset2
167echo "SequencesOn: ${testsequences[@]}" >> $mcdataset2
168echo "" >> $mcdataset2
169echo "" >> $mcdataset2
170
171for (( i=0 ; i < ${#testsequences[@]} ; i++ ))
172do
173 numtrain=${trainsequences[$i]}
174 notrain=`echo $numtrain | cut -c 0-4`
175 echo "Sequence$numtrain.File: $sequencedir/sequence$numtrain.txt" >> $mcdataset
176 echo "Sequence$numtrain.Dir: $mcstardir/$notrain/$numtrain" >> $mcdataset
177 echo "Sequence$numtrain.File: $sequencedir/sequence$numtrain.txt" >> $mcdataset2
178 echo "Sequence$numtrain.Dir: $mcstardir/$notrain/$numtrain" >> $mcdataset2
179
180 numtest=${testsequences[$i]}
181 notest=`echo $numtest | cut -c 0-4`
182 echo "Sequence$numtest.File: $sequencedir/sequence$numtest.txt" >> $mcdataset
183 echo "Sequence$numtest.Dir: $mcstardir/$notrain/$numtrain" >> $mcdataset
184 echo "Sequence$numtest.File: $sequencedir/sequence$numtest.txt" >> $mcdataset2
185 echo "Sequence$numtest.Dir: $mcstardir/$notrain/$numtrain" >> $mcdataset2
186done
187
188
189if [ "$trainenergy" == "yes" ]
190then
191 echo "creating rf-root-file for energy-estimation..."
192 cd $mars
193 logfile=$setupdir/trainenergy.log
194
195 root -q -b $mars/datacenter/macros/trainenergy.C+\("\"$mcdataset\""\,"\"$setupdir/\""\) | tee $logfile
196fi
Note: See TracBrowser for help on using the repository browser.