source: branches/removing_cpp11_features/scripts/preparemc@ 19796

Last change on this file since 19796 was 8828, checked in by hoehne, 17 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.0 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# Author(s): Daniel Hoehne 11/2007 <mailto:hoehne@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2007
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# - path 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# - zdmin minimum zenith distance
39# - zdmax maximum zenith distance
40# - psf add. spot size before camera
41# - mode production mode of the mcs
42# the explanation for the modes can be found in the text and in
43# /magic/montecarlo/rawfiles/README.txt
44# - numruns number 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,
49# i.e. the inputfile (mcdataset) and the outputfile (rf-root file)
50# are given as options:
51# $macrospath/trainenergy.C+\("\"$mcdataset\""\,"\"$rffile\""\)
52#
53# Remark: You have to run the script in your Mars directory.
54#
55##############################################################################
56
57# to be set by the user
58path=~
59# path where your mc sequence and dataset files are stored
60mcoutpath=$path/mc
61# path where you have your modified version of trainenergy.C
62macrospath=$path/macros
63
64# zenith range of your data
65zdmin=7
66zdmax=25
67# additional spotsize (before camera) for the mcs. You can calculate it with Sqrt(psf(real data)*psf(real data) - 25)
68psf=15
69# production mode of your data
70# available observation modes: On (please leave modes empty: ""), Wobble ("W1", "W2"), Fake Wobble ("FW"), Diffuse ("Diff")
71# you can combine these with: high energy (harder spectrum: "HE")
72# particle type: "Muon", "Gamma" or "Proton"
73# remark: first the particle, then the spectrum and the observation mode at the end: Examples mode="GammaHEFW" or "ProtonDiff" or "GammaW1"
74# please have also a look into /magic/montecarlo/rawfiles/README.txt
75# you can also use asterisks, e.g.: "GammaW*" for W1 and W2
76mode="GammaW1"
77# epoch for which the mc were produced
78# available epochs: MC_old MC_April_May06 MC_post_June06 MC_MuxFADCs MCMuxFADCs_NEW (last one is for Mux data with reduced fadc slices number)
79epos=( "MC_Old" )
80# number of runs which are in the sequence files used for training
81# please adjust this number such, that you use about 30000 Events for training
82numruns=2
83
84
85
86
87# some checks
88# checking if the given files and paths are existing
89if ! [ -e $mcoutpath ]
90then
91 echo "Your outpath for the mc $mcoutpath does not exist."
92 exit
93fi
94if ! [ -e $macrospath ]
95then
96 echo "Your macros path $macrospath does not exist."
97 exit
98fi
99if ! [ -e $macrospath/trainenergy.C ]
100then
101 echo "Your trainenergy.C does not exist in path $macrospath."
102 exit
103fi
104
105mcdatasettrain=$mcoutpath/mcdataset-for-training.txt
106mcdatasetsponde=$mcoutpath/mcdataset-for-sponde.txt
107
108# be careful with $date, when path changes
109mcpath=/magic/montecarlo
110
111
112zbinmin=`echo "scale=2 ; 100*(1 - c($zdmin*3.14/180))+1" | bc -l`
113zbinmax=`echo "scale=2 ; 100*(1 - c($zdmax*3.14/180))+1" | bc -l`
114
115zbinmin=`echo $zbinmin | cut -d. -f1`
116zbinmax=`echo $zbinmax | cut -d. -f1`
117
118echo "zd: min: $zdmin max: $zdmax"
119echo "zbin: min: $zbinmin max: $zbinmax"
120echo "$numruns runs are classified as test, the rest as train"
121
122j=0
123for epo in $epos
124do
125 for (( i=$zbinmin ; i < $zbinmax ; i++ ))
126 do
127 #depending on the epoch you need different P and C runs and time codes
128 case "$epo" in
129
130 "MC_up_to_April06")
131 prun=272
132 crun=273
133 time="03"
134 ;;
135 "MC_old")
136 prun=4223
137 crun=4224
138 time="03"
139 ;;
140 "MC_April_May06")
141 prun=272
142 crun=273
143 time="02"
144 ;;
145 "MC_post_June06")
146 prun=1048
147 crun=1049
148 time="02"
149 ;;
150 "MC_MuxFADCs")
151 prun=3919
152 crun=3920
153 time="01"
154 ;;
155 "MC_MuxFADCs_NEW")
156 prun=270
157 crun=271
158 time="01"
159 ;;
160 *)
161 echo "Wrong epoch $epo , please specify a valid epoch"
162 continue
163 ;;
164 esac
165
166 zbin=`printf %02d $i`
167 path=$mcpath/rawfiles/19$zbin/$time/$psf
168 runs=(`ls $path | grep $mode | 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' -e 's/^0//g' | tr "\n" " "`)
169 if [ "$runs" = "" ]
170 then
171 echo " No runs for zbin $i found. Please try to find some MC with zbin $i!"
172 continue
173 fi
174 echo "found ${#runs[@]} Gamma MC files in path "$path
175
176 runsforfirst=""
177 firstrun=${runs[0]}
178 secondrun=${runs[${numruns}]}
179 firstrunno=`printf %08d $firstrun`
180 secondrunno=`printf %08d $secondrun`
181 unset runs[0]
182 for (( k=1 ; k < $numruns ; k++ ))
183 do
184 runsforfirst=$runsforfirst" ${runs[$k]}"
185 unset runs[$k]
186 done
187 date=`echo $path | cut -d/ -f5-7 | sed -e 's/\//-/g'`
188
189 trainsequfile=$mcoutpath/sequence$firstrunno.txt
190 trainsequences[$j]=$firstrunno
191# echo " writing train-sequfile "$trainsequfile
192 echo "Sequence: $firstrun" > $trainsequfile
193 echo "Night: $date" >> $trainsequfile
194 echo "" >> $trainsequfile
195 echo "CalRuns: 1" >> $trainsequfile
196 echo "PedRuns: 2" >> $trainsequfile
197 echo "DatRuns: $firstrun$runsforfirst" >> $trainsequfile
198 echo "" >> $trainsequfile
199 echo "MonteCarlo: Yes" >> $trainsequfile
200 echo "" >> $trainsequfile
201
202 testsequfile=$mcoutpath/sequence$secondrunno.txt
203 testsequences[$j]=$secondrunno
204# echo "writing test-sequfile "$testsequfile
205 echo "Sequence: $secondrun" > $testsequfile
206 echo "Night: $date" >> $testsequfile
207 echo "" >> $testsequfile
208 echo "CalRuns: 1" >> $testsequfile
209 echo "PedRuns: 2" >> $testsequfile
210 echo "DatRuns: ${runs[@]}" >> $testsequfile
211 echo "" >> $testsequfile
212 echo "MonteCarlo: Yes" >> $testsequfile
213 echo "" >> $testsequfile
214
215 j=$j+1
216 done
217done
218
219echo "# test sequences: ${#testsequences[@]}"
220echo "# train sequences: ${#trainsequences[@]}"
221
222echo "AnalysisNumber: 1 " > $mcdatasettrain
223echo "" >> $mcdatasettrain
224echo "SequencesOn: ${trainsequences[@]}" >> $mcdatasettrain
225echo "" >> $mcdatasettrain
226echo "SequencesOff: ${testsequences[@]}" >> $mcdatasettrain
227echo "" >> $mcdatasettrain
228echo "" >> $mcdatasettrain
229
230echo "AnalysisNumber: 1 " > $mcdatasetsponde
231echo "" >> $mcdatasetsponde
232echo "SequencesOn: ${testsequences[@]}" >> $mcdatasetsponde
233echo "" >> $mcdatasetsponde
234echo "" >> $mcdatasetsponde
235
236for (( i=0 ; i < ${#testsequences[@]} ; i++ ))
237do
238 numtrain=${trainsequences[$i]}
239 notrain=`echo $numtrain | cut -c 0-4`
240 echo "Sequence$numtrain.File: $mcoutpath/sequence$numtrain.txt" >> $mcdatasettrain
241 echo "Sequence$numtrain.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasettrain
242
243 numtest=${testsequences[$i]}
244 notest=`echo $numtest | cut -c 0-4`
245 echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdatasettrain
246 echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasettrain
247 echo "Sequence$numtest.File: $mcoutpath/sequence$numtest.txt" >> $mcdatasetsponde
248 echo "Sequence$numtest.Dir: $mcpath/star/$notrain/$numtrain" >> $mcdatasetsponde
249done
250
251
252# train the rf for energy estimation
253logfile=$mcoutpath/trainenergy.log
254rffile=$mcoutpath/rf-energy.root
255
256echo "Your mcdataset for training: $mcdatasettrain"
257echo "Your rffile: $rffile"
258echo ""
259echo "Training the RF..."
260root -q -b $macrospath/trainenergy.C+\("\"$mcdatasettrain\""\,"\"$rffile\""\) | tee $logfile
261
262echo ""
263echo "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.