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

Last change on this file since 7876 was 7735, 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
79sourcefile=$mars/datacenter/scripts/sourcefile
80zdmin=9
81zdmax=51
82psf=14
83modes=( "02" "04" ) # e.g. nowobble
84numruns=5
85
86
87makedir $dir
88
89#needed if not set in .bashrc or when script is e.g. executed in cronjob
90export ROOTSYS=/opt/root_v4.04.02g
91export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
92export PATH=$PATH:$ROOTSYS/bin
93
94mcdir=/montecarlo/rawfiles
95mcdataset=$dir/mcdataset-test-train.txt
96mcdataset2=$dir/mcdataset-for-ganymed.txt
97
98#calculation of the zbin
99zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
100zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
101zbinmin=`echo $zbinmin | cut -d. -f1`
102zbinmax=`echo $zbinmax | cut -d. -f1`
103echo "zd: min: $zbinmin max: $zbinmax"
104echo "numruns: $numruns"
105
106j=0
107for mode in ${modes[@]}
108do
109 echo "mode: "$mode
110 for (( i=$zbinmin ; i < $zbinmax ; i++ ))
111 do
112 zbin=`printf %02d $i`
113 echo "zbin: $zbin"
114 path=$mcdir/19$zbin/$mode/$psf
115 runsforfirst=
116
117 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" " "`)
118 if [ "$runs" = "" ]
119 then
120 echo " no runs found for zbin $i "
121 continue
122 fi
123
124 firstrun=${runs[0]}
125 secondrun=${runs[${numruns}]}
126 firstrunno=`printf %08d $firstrun`
127 secondrunno=`printf %08d $secondrun`
128 unset runs[0]
129 for (( k=1 ; k < $numruns ; k++ ))
130 do
131 runsforfirst=$runsforfirst" ${runs[$k]}"
132 unset runs[$k]
133 done
134 date=`echo $path | cut -c 22-31 | sed -e 's/\//-/g'`
135
136 trainsequfile=$dir/sequence$firstrunno.txt
137 trainsequences[$j]=$firstrunno
138 echo " writing train-sequfile "$trainsequfile
139 echo "Sequence: $firstrun" > $trainsequfile
140 echo "Night: $date" >> $trainsequfile
141 echo "" >> $trainsequfile
142 echo "CalRuns: 1" >> $trainsequfile
143 echo "PedRuns: 2" >> $trainsequfile
144 echo "DatRuns: $firstrun$runsforfirst" >> $trainsequfile
145 echo "" >> $trainsequfile
146
147 testsequfile=$dir/sequence$secondrunno.txt
148 testsequences[$j]=$secondrunno
149 echo " writing test-sequfile "$testsequfile
150 echo "Sequence: $secondrun" > $testsequfile
151 echo "Night: $date" >> $testsequfile
152 echo "" >> $testsequfile
153 echo "CalRuns: 1" >> $testsequfile
154 echo "PedRuns: 2" >> $testsequfile
155 echo "DatRuns: ${runs[@]}" >> $testsequfile
156 echo "" >> $testsequfile
157
158 j=$j+1
159 done
160done
161
162echo "# test sequences: ${#testsequences[@]}"
163echo "# train sequences: ${#trainsequences[@]}"
164
165echo "writing dataset files $mcdataset and $mcdataset2"
166
167echo "AnalysisNumber: 1 " > $mcdataset
168echo "" >> $mcdataset
169echo "SequencesOn: ${trainsequences[@]}" >> $mcdataset
170echo "" >> $mcdataset
171echo "SequencesOff: ${testsequences[@]}" >> $mcdataset
172echo "" >> $mcdataset
173echo "" >> $mcdataset
174
175echo "AnalysisNumber: 1 " > $mcdataset2
176echo "" >> $mcdataset2
177echo "SequencesOn: ${testsequences[@]}" >> $mcdataset2
178echo "" >> $mcdataset2
179echo "" >> $mcdataset2
180
181for (( i=0 ; i < ${#testsequences[@]} ; i++ ))
182do
183 numtrain=${trainsequences[$i]}
184 notrain=`echo $numtrain | cut -c 0-4`
185 echo "Sequence$numtrain.File: $dir/sequence$numtrain.txt" >> $mcdataset
186 echo "Sequence$numtrain.Dir: /montecarlo/star/$notrain/$numtrain" >> $mcdataset
187 echo "Sequence$numtrain.File: $dir/sequence$numtrain.txt" >> $mcdataset2
188 echo "Sequence$numtrain.Dir: /montecarlo/star/$notrain/$numtrain" >> $mcdataset2
189
190 numtest=${testsequences[$i]}
191 notest=`echo $numtest | cut -c 0-4`
192 echo "Sequence$numtest.File: $dir/sequence$numtest.txt" >> $mcdataset
193 echo "Sequence$numtest.Dir: /montecarlo/star/$notrain/$numtrain" >> $mcdataset
194 echo "Sequence$numtest.File: $dir/sequence$numtest.txt" >> $mcdataset2
195 echo "Sequence$numtest.Dir: /montecarlo/star/$notrain/$numtrain" >> $mcdataset2
196done
197
198# put # before the 'exit' to create rf-root-file for energy-estimation
199exit
200
201echo "creating rf-root-file for energy-estimation..."
202source $sourcefile
203cd $mars
204logfile=$dir/trainenergy.log
205
206root -q -b $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$dir/\""\) | tee $logfile
207
Note: See TracBrowser for help on using the repository browser.