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

Last change on this file since 8709 was 8637, checked in by Daniela Dorner, 17 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.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 (at the moment mc with psf 14 and 20 is available)
40# - modes observation mode
41# the explanation for the modes can be found in
42# /magic/montecarlo/rawfiles/README.txt
43# - numruns number of runs, that are in the sequence file, which are used
44# for training (SequencesOn in $mcdataset)
45#
46# Remark: For the training of the RF for the energy estimation you need the
47# macro trainengery.C in the path $path/macros in a modified version,
48# i.e. the inputfile (mcdataset) and the outputfile (rf-root file)
49# are given as options:
50# $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$rffile\""\)
51#
52# Remark: You have to run the script in your Mars directory.
53#
54##############################################################################
55
56# to be set by the user
57path=/home/dorner/final_analysis
58# path where your mc sequence and dataset files are stored
59mcoutpath=$path/mc
60# path where you have your modified version of trainenergy.C
61macrospath=$path/macros
62
63# zenith range of your data
64zdmin=17
65zdmax=36
66# point spread function of your data
67psf=14
68# observation mode of your data
69# for explanations see /magic/montecarlo/rawfiles/README.txt
70modes=( "02" )
71# number of runs which are in the sequence files used for training
72# please adjust this number such, that you use about 30000 Events for training
73numruns=1
74
75
76
77
78# some checks
79# checking if the given files and paths are existing
80if ! [ -e $mcoutpath ]
81then
82 echo "Your outpath for the mc $mcoutpathdoes not exist."
83 exit
84fi
85if ! [ -e $macrospath ]
86then
87 echo "Your macros path $macrospath does not exist."
88 exit
89fi
90if ! [ -e $macrospath/trainenergy.C ]
91then
92 echo "Your trainenergy.C does not exist in path $macrospath."
93 exit
94fi
95
96mcdatasettrain=$mcoutpath/mcdataset-for-training.txt
97mcdatasetsponde=$mcoutpath/mcdataset-for-sponde.txt
98
99# be careful with $date, when path changes
100mcpath=/magic/montecarlo
101
102zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
103zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
104
105zbinmin=`echo $zbinmin | cut -d. -f1`
106zbinmax=`echo $zbinmax | cut -d. -f1`
107
108echo "zd: min: $zdmin max: $zdmax"
109echo "zbin: min: $zbinmin max: $zbinmax"
110echo "$numruns runs are classified as test the rest as train"
111
112j=0
113for mode in $modes
114do
115 for (( i=$zbinmin ; i < $zbinmax ; i++ ))
116 do
117 zbin=`printf %02d $i`
118 path=$mcpath/rawfiles/19$zbin/$mode/$psf
119 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" " "`)
120 if [ "$runs" = "" ]
121 then
122 echo " No runs for zbin $i found. Please try to find some MC with zbin $i!"
123 continue
124 fi
125 echo "found ${#runs[@]} Gamma MC files in path "$path
126
127 runsforfirst=""
128 firstrun=${runs[0]}
129 secondrun=${runs[${numruns}]}
130 firstrunno=`printf %08d $firstrun`
131 secondrunno=`printf %08d $secondrun`
132 unset runs[0]
133 for (( k=1 ; k < $numruns ; k++ ))
134 do
135 runsforfirst=$runsforfirst" ${runs[$k]}"
136 unset runs[$k]
137 done
138 date=`echo $path | cut -d/ -f5-7 | sed -e 's/\//-/g'`
139
140 trainsequfile=$mcoutpath/sequence$firstrunno.txt
141 trainsequences[$j]=$firstrunno
142# echo " writing train-sequfile "$trainsequfile
143 echo "Sequence: $firstrun" > $trainsequfile
144 echo "Night: $date" >> $trainsequfile
145 echo "" >> $trainsequfile
146 echo "CalRuns: 1" >> $trainsequfile
147 echo "PedRuns: 2" >> $trainsequfile
148 echo "DatRuns: $firstrun$runsforfirst" >> $trainsequfile
149 echo "" >> $trainsequfile
150 echo "MonteCarlo: Yes" >> $trainsequfile
151 echo "" >> $trainsequfile
152
153 testsequfile=$mcoutpath/sequence$secondrunno.txt
154 testsequences[$j]=$secondrunno
155# echo "writing test-sequfile "$testsequfile
156 echo "Sequence: $secondrun" > $testsequfile
157 echo "Night: $date" >> $testsequfile
158 echo "" >> $testsequfile
159 echo "CalRuns: 1" >> $testsequfile
160 echo "PedRuns: 2" >> $testsequfile
161 echo "DatRuns: ${runs[@]}" >> $testsequfile
162 echo "" >> $testsequfile
163 echo "MonteCarlo: Yes" >> $testsequfile
164 echo "" >> $testsequfile
165
166 j=$j+1
167 done
168done
169
170echo "# test sequences: ${#testsequences[@]}"
171echo "# train sequences: ${#trainsequences[@]}"
172
173echo "AnalysisNumber: 1 " > $mcdatasettrain
174echo "" >> $mcdatasettrain
175echo "SequencesOn: ${trainsequences[@]}" >> $mcdatasettrain
176echo "" >> $mcdatasettrain
177echo "SequencesOff: ${testsequences[@]}" >> $mcdatasettrain
178echo "" >> $mcdatasettrain
179echo "" >> $mcdatasettrain
180
181echo "AnalysisNumber: 1 " > $mcdatasetsponde
182echo "" >> $mcdatasetsponde
183echo "SequencesOn: ${testsequences[@]}" >> $mcdatasetsponde
184echo "" >> $mcdatasetsponde
185echo "" >> $mcdatasetsponde
186
187for (( i=0 ; i < ${#testsequences[@]} ; i++ ))
188do
189 numtrain=${trainsequences[$i]}
190 notrain=`echo $numtrain | cut -c 0-4`
191 echo "Sequence$numtrain.File: $mcoutpath/sequence$numtrain.txt" >> $mcdatasettrain
192 echo "Sequence$numtrain.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasettrain
193
194 numtest=${testsequences[$i]}
195 notest=`echo $numtest | cut -c 0-4`
196 echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdatasettrain
197 echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasettrain
198 echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdatasetsponde
199 echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasetsponde
200done
201
202
203# train the rf for energy estimation
204logfile=$mcoutpath/trainenergy.log
205rffile=$mcoutpath/rf-energy.root
206
207echo "Your mcdataset for training: $mcdatasettrain"
208echo "Your rffile: $rffile"
209echo ""
210echo "Training the RF..."
211root -q -b $macrospath/trainenergy.C+\("\"$mcdatasettrain\""\,"\"$rffile\""\) | tee $logfile
212
213echo ""
214echo "Please use rf-file $rffile in your sponde.rc, in case you want to use the RF energy estimator there. "
Note: See TracBrowser for help on using the repository browser.