source: trunk/MagicSoft/Mars/scripts/preparemc@ 8206

Last change on this file since 8206 was 8206, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 6.8 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# - sourcefile directory, where your Mars version is stored
42# only needed, if you want to create a rf-root-file for the
43# energy estimation
44# be careful, you also have to set the mars path in sourcefile
45# - zdmin minimum zenith distance
46# - zdmax maximum zenith distance
47# - psf psf
48# at the moment mc with psf 14 and 20 is available
49# - modes observation mode
50# the explanation for the modes can be found in
51# /montecarlo/rawfiles/README.txt
52# - numruns num of runs, that are in the sequence file, which are used for
53# training (SequencesOn in $mcdataset)
54#
55# If you want to create a rf-root-file for the energy estimation, you have to
56# comment out the 'exit' before the last lines of the script.
57#
58##############################################################################
59
60#function to create directory
61function makedir()
62{
63 if [ ! -d $@ ]
64 then
65 mkdir -pv $@
66 if [ ! -d $@ ]
67 then
68 echo "could not make dir "$@
69 exit
70 fi
71 fi
72}
73
74
75
76#to be set by the user
77dir=/home/operator/mc
78mars=/home/operator/Mars.cvs
79zdmin=9
80zdmax=51
81psf=14
82modes=( "02" "04" ) # e.g. nowobble
83numruns=5
84
85makedir $dir
86
87#needed if not set in .bashrc or when script is e.g. executed in cronjob
88export ROOTSYS=/opt/root_v5.12.00f
89export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
90export PATH=$PATH:$ROOTSYS/bin
91
92mcdir=/magic/montecarlo/rawfiles
93mcdataset=$dir/mcdataset-test-train.txt
94mcdataset2=$dir/mcdataset-for-ganymed.txt
95
96#calculation of the zbin
97zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
98zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
99zbinmin=`echo $zbinmin | cut -d. -f1`
100zbinmax=`echo $zbinmax | cut -d. -f1`
101echo "zd: min: $zbinmin max: $zbinmax"
102echo "numruns: $numruns"
103
104j=0
105for mode in ${modes[@]}
106do
107 echo "mode: "$mode
108 for (( i=$zbinmin ; i < $zbinmax ; i++ ))
109 do
110 zbin=`printf %02d $i`
111 echo "zbin: $zbin"
112 path=$mcdir/19$zbin/$mode/$psf
113 runsforfirst=
114
115 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" " "`)
116 if [ "$runs" = "" ]
117 then
118 echo " no runs found for zbin $i "
119 continue
120 fi
121
122 firstrun=${runs[0]}
123 secondrun=${runs[${numruns}]}
124 firstrunno=`printf %08d $firstrun`
125 secondrunno=`printf %08d $secondrun`
126 unset runs[0]
127 for (( k=1 ; k < $numruns ; k++ ))
128 do
129 runsforfirst=$runsforfirst" ${runs[$k]}"
130 unset runs[$k]
131 done
132 date=`echo $path | cut -c 22-31 | sed -e 's/\//-/g'`
133
134 trainsequfile=$dir/sequence$firstrunno.txt
135 trainsequences[$j]=$firstrunno
136 echo " writing train-sequfile "$trainsequfile
137 echo "Sequence: $firstrun" > $trainsequfile
138 echo "Night: $date" >> $trainsequfile
139 echo "" >> $trainsequfile
140 echo "CalRuns: 1" >> $trainsequfile
141 echo "PedRuns: 2" >> $trainsequfile
142 echo "DatRuns: $firstrun$runsforfirst" >> $trainsequfile
143 echo "" >> $trainsequfile
144
145 testsequfile=$dir/sequence$secondrunno.txt
146 testsequences[$j]=$secondrunno
147 echo " writing test-sequfile "$testsequfile
148 echo "Sequence: $secondrun" > $testsequfile
149 echo "Night: $date" >> $testsequfile
150 echo "" >> $testsequfile
151 echo "CalRuns: 1" >> $testsequfile
152 echo "PedRuns: 2" >> $testsequfile
153 echo "DatRuns: ${runs[@]}" >> $testsequfile
154 echo "" >> $testsequfile
155
156 j=$j+1
157 done
158done
159
160echo "# test sequences: ${#testsequences[@]}"
161echo "# train sequences: ${#trainsequences[@]}"
162
163echo "writing dataset files $mcdataset and $mcdataset2"
164
165echo "AnalysisNumber: 1 " > $mcdataset
166echo "" >> $mcdataset
167echo "SequencesOn: ${trainsequences[@]}" >> $mcdataset
168echo "" >> $mcdataset
169echo "SequencesOff: ${testsequences[@]}" >> $mcdataset
170echo "" >> $mcdataset
171echo "" >> $mcdataset
172
173echo "AnalysisNumber: 1 " > $mcdataset2
174echo "" >> $mcdataset2
175echo "SequencesOn: ${testsequences[@]}" >> $mcdataset2
176echo "" >> $mcdataset2
177echo "" >> $mcdataset2
178
179for (( i=0 ; i < ${#testsequences[@]} ; i++ ))
180do
181 numtrain=${trainsequences[$i]}
182 notrain=`echo $numtrain | cut -c 0-4`
183 echo "Sequence$numtrain.File: $dir/sequence$numtrain.txt" >> $mcdataset
184 echo "Sequence$numtrain.Dir: /montecarlo/star/$notrain/$numtrain" >> $mcdataset
185 echo "Sequence$numtrain.File: $dir/sequence$numtrain.txt" >> $mcdataset2
186 echo "Sequence$numtrain.Dir: /montecarlo/star/$notrain/$numtrain" >> $mcdataset2
187
188 numtest=${testsequences[$i]}
189 notest=`echo $numtest | cut -c 0-4`
190 echo "Sequence$numtest.File: $dir/sequence$numtest.txt" >> $mcdataset
191 echo "Sequence$numtest.Dir: /montecarlo/star/$notrain/$numtrain" >> $mcdataset
192 echo "Sequence$numtest.File: $dir/sequence$numtest.txt" >> $mcdataset2
193 echo "Sequence$numtest.Dir: /montecarlo/star/$notrain/$numtrain" >> $mcdataset2
194done
195
196# put # before the 'exit' to create rf-root-file for energy-estimation
197exit
198
199echo "creating rf-root-file for energy-estimation..."
200cd $mars
201logfile=$dir/trainenergy.log
202
203root -q -b $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$dir/\""\) | tee $logfile
204
Note: See TracBrowser for help on using the repository browser.