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

Last change on this file since 8626 was 8626, checked in by Daniela Dorner, 17 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 6.4 KB
Line 
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
40# at the moment mc with psf 14 and 20 is available
41# - modes observation mode
42# the explanation for the modes can be found in
43# /montecarlo/rawfiles/README.txt
44# - numruns num 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, i.e. the
49# inputfile (mcdataset) and the outputfile (rf-root file) are given as
50# options: $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$rffile\""\)
51#
52# Remark: You have to run the script in your Mars directory.
53#
54##############################################################################
55
56
57path=/home/dorner/final_analysis
58mcoutpath=$path/mc
59macrospath=$path/macros
60mcdataset=$mcoutpath/mcdataset.txt
61mcdataset2=$mcoutpath/mcdataset2.txt
62
63zdmin=17
64zdmax=35
65psf=14
66modes=( "02" ) # nowobble
67numruns=3
68
69# be careful with $date, when path changes
70mcpath=/magic/montecarlo
71
72zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
73zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
74
75zbinmin=`echo $zbinmin | cut -d. -f1`
76zbinmax=`echo $zbinmax | cut -d. -f1`
77
78echo "zd: min: $zdmin max: $zdmax"
79echo "zbin: min: $zbinmin max: $zbinmax"
80echo "$numruns runs are classified as test the rest as train"
81
82j=0
83for mode in $modes
84do
85 for (( i=$zbinmin ; i < $zbinmax ; i++ ))
86 do
87 zbin=`printf %02d $i`
88 path=$mcpath/rawfiles/19$zbin/$mode/$psf
89 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" " "`)
90 if [ "$runs" = "" ]
91 then
92 echo " no runs found for zbin $i "
93 continue
94 fi
95 echo "found ${#runs[@]} Gamma MC files in path "$path
96
97 runsforfirst=""
98 firstrun=${runs[0]}
99 secondrun=${runs[${numruns}]}
100 firstrunno=`printf %08d $firstrun`
101 secondrunno=`printf %08d $secondrun`
102 unset runs[0]
103 for (( k=1 ; k < $numruns ; k++ ))
104 do
105 runsforfirst=$runsforfirst" ${runs[$k]}"
106 unset runs[$k]
107 done
108 date=`echo $path | cut -d/ -f5-7 | sed -e 's/\//-/g'`
109
110 trainsequfile=$mcoutpath/sequence$firstrunno.txt
111 trainsequences[$j]=$firstrunno
112 echo " writing train-sequfile "$trainsequfile
113 echo "Sequence: $firstrun" > $trainsequfile
114 echo "Night: $date" >> $trainsequfile
115 echo "" >> $trainsequfile
116 echo "CalRuns: 1" >> $trainsequfile
117 echo "PedRuns: 2" >> $trainsequfile
118 echo "DatRuns: $firstrun$runsforfirst" >> $trainsequfile
119 echo "" >> $trainsequfile
120 echo "MonteCarlo: Yes" >> $trainsequfile
121 echo "" >> $trainsequfile
122
123 testsequfile=$mcoutpath/sequence$secondrunno.txt
124 testsequences[$j]=$secondrunno
125# echo "writing test-sequfile "$testsequfile
126 echo "Sequence: $secondrun" > $testsequfile
127 echo "Night: $date" >> $testsequfile
128 echo "" >> $testsequfile
129 echo "CalRuns: 1" >> $testsequfile
130 echo "PedRuns: 2" >> $testsequfile
131 echo "DatRuns: ${runs[@]}" >> $testsequfile
132 echo "" >> $testsequfile
133 echo "MonteCarlo: Yes" >> $testsequfile
134 echo "" >> $testsequfile
135
136 j=$j+1
137 done
138done
139
140echo "# test sequences: ${#testsequences[@]}"
141echo "# train sequences: ${#trainsequences[@]}"
142
143echo "AnalysisNumber: 1 " > $mcdataset
144echo "" >> $mcdataset
145echo "SequencesOn: ${trainsequences[@]}" >> $mcdataset
146echo "" >> $mcdataset
147echo "SequencesOff: ${testsequences[@]}" >> $mcdataset
148echo "" >> $mcdataset
149echo "" >> $mcdataset
150
151echo "AnalysisNumber: 1 " > $mcdataset2
152echo "" >> $mcdataset2
153echo "SequencesOn: ${testsequences[@]}" >> $mcdataset2
154echo "" >> $mcdataset2
155echo "" >> $mcdataset2
156
157for (( i=0 ; i < ${#testsequences[@]} ; i++ ))
158do
159 numtrain=${trainsequences[$i]}
160 notrain=`echo $numtrain | cut -c 0-4`
161 echo "Sequence$numtrain.File: $mcoutpath/sequence$numtrain.txt" >> $mcdataset
162 echo "Sequence$numtrain.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdataset
163 echo "Sequence$numtrain.File: $mcoutpath/sequence$numtrain.txt" >> $mcdataset2
164 echo "Sequence$numtrain.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdataset2
165
166 numtest=${testsequences[$i]}
167 notest=`echo $numtest | cut -c 0-4`
168 echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdataset
169 echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdataset
170 echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdataset2
171 echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdataset2
172done
173
174
175logfile=$mcoutpath/trainenergy.log
176rffile=$mcoutpath/rf-energy.root
177
178echo "mcdataset: $mcdataset"
179echo "rffile: $rffile"
180echo "macrospath: $macrospath"
181root -q -b $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$rffile\""\) | tee $logfile
182
Note: See TracBrowser for help on using the repository browser.