source: trunk/Mars/datacenter/scripts/runcorsika@ 10038

Last change on this file since 10038 was 10006, checked in by Daniela Dorner, 14 years ago
implemented fNumReUseShowers (parameter how often a shower is reused in Corsika)
  • Property svn:executable set to *
File size: 8.7 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/2007 <mailto:daniela.dorner@unige.ch>
21#
22# Copyright: MAGIC Software Development, 2000-2010
23#
24#
25# ========================================================================
26#
27# This script runs corsika.
28#
29
30if [ "$SOURCEFILEPATH" = "" ]
31then
32 source `dirname $0`/sourcefile
33else
34 source $SOURCEFILEPATH/sourcefile
35fi
36printprocesslog "INFO starting $0"
37program=corsika
38step=Corsika
39
40set -C
41
42export FLUPRO=$corsikapath'/fluka2008_3'
43
44# printing input card to stdout
45function printinputcard()
46{
47 # Run number
48 echo "RUNNR "$file
49 # Starting event number
50 echo "EVTNR 1"
51 # Number of simulated events
52 echo "NSHOW "$numevts
53 # Seed values for simulation
54 echo "SEED "$seed1" 0 0 "
55 echo "SEED "$seed2" 0 0 "
56 echo "SEED "$seed3" 0 0 "
57 # Primary particle
58 echo "PRMPAR "$primparticle
59 echo "ERANGE "$erange
60 echo "ESLOPE "$slope
61 # Simulation range (theta, phi, view cone, starting altitude)
62 echo "THETAP "$zdrange
63 echo "PHIP "$azrange
64 echo "VIEWCONE 0. "$viewconemax
65 echo "FIXCHI "$startalt
66 # Observation level, magnetic field, atmosphere
67 echo "OBSLEV "$obslev".E2"
68 # From www.noaa.gov/geomagmodels roughly for January 2009. (was 29.5 and 23.0)
69 # MAGNET BX BZ (BX is the horizontal component (muT) to the x-direction of
70 # the detector, BZ is the vertical component (muT) downwards)
71 echo "MAGNET "$magnet
72 # Rotation angle between array x-direction and magnetic north direction
73 # positive if array x-direction points to the west
74 echo "ARRANG "$magnetrot
75 # Atmosphere (model, true/false for atmospheric refraction of cer-photons)
76 # Atmosphere read from atmprof11.dat
77 # My current understanding is that only refraction (bending of light
78 # but no absorption of photons is taken into account) setting T.
79 echo "ATMOSPHERE "$atm" T"
80
81 # Current boundaries in reflector program
82 # echo "ATMLAY 400000 1000000 4000000 10000000"
83
84 # Boundaries as determined by CORSIKA
85 # Until we can read the result from the corsika fit we fix the
86 # values which come out of the fit. This is not ideal but forces
87 # things to be consistent. Be careful is using a different model -
88 # the fit might not be ideal.
89 echo "ATMLAY 775000 1650000 5000000 10500000"
90
91 # Other parameters
92 echo "RADNKG 200.E2"
93 echo "ECUTS 0.3 0.3 0.02 0.02"
94 echo "ECTMAP 1.E4"
95 # Don't add muon particle data to output
96 echo "MUADDI F"
97 # Enable muon multiple scattering
98 echo "MUMULT T"
99 # Wavelength range (was originally 600)
100 echo "CWAVLG "$wavelengths
101 # MMCS
102 echo "CSCAT "$numreuse" 0. "$impactmax
103 # CORSIKA
104 # echo "CSCAT "$numreuse" "$impactmax" 0."
105 echo "CERSIZ 1."
106 # Write Cherenkov photons to cer-file
107 echo "CERFIL T"
108 # Number of telescopes
109 echo "CERTEL 1"
110 # MMCS
111 echo " 0. 0. 0. 0. 0. "$diameter" "$diameter
112 # CORSIKA (x, y, z, r)
113 # echo "TELESCOPE 0. 0. 0. "$diameter
114 # This keyword has no relevance but allows to store the
115 # maximum simulated impact parameter. The "magic" is that
116 # ceres interpretes the third and fourth argument as
117 # maximum simulated impact if they are identical and
118 # the other four arguments are 1
119 # echo "CERARY 1 1 "$diameter" "$diameter" 1 1"
120 # How the longitudinal shower development is sampled
121 # echo "LONGI T 10. T F"
122 echo "LONGI F 20 0 F F"
123 # Maximum number of detailed particles to print
124 echo "MAXPRT 0"
125 # Suppress file with partciles reaching ground (DATnnnnnn)
126 # FIXME: Should we make this switchable by the database?
127 echo "PAROUT F F"
128 # Don't write a database file
129 echo "DATBAS F"
130 # Switch off all debugging output
131 echo "DEBUG F 6 F 1000000"
132 # Output path
133 echo "DIRECT "$outpath
134 # DIRECT /dev/null
135 # TELFIL filename
136 # TELFIL | gzip
137 # TELESCOPE X Y Z R
138 # User and host (for convenience)
139 echo "USER "`whoami`
140 echo "HOST "`hostname`
141 # End of input card
142 echo "EXIT"
143}
144
145
146# get sequence #
147gettodo "1"
148run=${primaries[0]}
149file=${primaries[1]}
150
151# lock sequ
152lockfile=$lockpath/lock-$step-$run.$file.txt
153checklock
154
155printprocesslog "INFO starting $program for run $run and file $file"
156
157setstatus "start"
158
159printprocesslog "INFO run $program for run $run and file $file"
160printprocesslog "INFO create input card for run $run and file $file"
161
162# get values for inputcard
163query="SELECT fParticleTypeKEY FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
164primparticle=`sendquery`
165query="SELECT fEnergyMin, fEnergyMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
166erange=`sendquery`
167query="SELECT fNumEvents FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
168numevts=`sendquery`
169query="SELECT fEnergySlope FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
170slope=`sendquery`
171query="SELECT fZenithDistanceMin, fZenithDistanceMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
172zdrange=`sendquery`
173# Change from the MARS definition (Az=90 -> East) to Corsika (Az=90 -> West)
174query="SELECT 180-fAzimuthMin, 180-fAzimuthMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
175azrange=`sendquery`
176query="SELECT fCorsikaSeed1 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
177seed1=`sendquery`
178query="SELECT fCorsikaSeed2 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
179seed2=`sendquery`
180query="SELECT fCorsikaSeed3 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
181seed3=`sendquery`
182query="SELECT fImpactMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
183impactmax=`sendquery`
184query="SELECT fViewConeMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
185viewconemax=`sendquery`
186query="SELECT fStartingAltitude FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
187startalt=`sendquery`
188query="SELECT fMirrorDiameter FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
189diameter=`sendquery`
190query="SELECT fAtmosphericModelKEY FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
191atm=`sendquery`
192query="SELECT fObsLevel FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
193obslev=`sendquery`
194query="SELECT fMagnetBX, fMagnetBZ FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
195magnet=`sendquery`
196query="SELECT fMagnetRotation FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
197magnetrot=`sendquery`
198query="SELECT fWavelengthMin, fWavelengthMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
199wavelengths=`sendquery`
200query="SELECT fNumReUseShowers FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
201numreuse=`sendquery`
202
203outpath=$mcpath"/"$program"/"`printf %08d $run | cut -c 1-4`/`printf %08d $run | cut -c 5-8`
204makedir $outpath
205logfile=$outpath/cer000`printf %06d $file | cut -c 4-6`".log"
206
207cd $corsikapath
208
209printprocesslog "INFO executing 'printinputcard | ./cc6501p-linux >| $logfile 2>&1' in directory $corsikapath "
210printinputcard | ./cc6501p-linux >| $logfile 2>&1
211
212check1=$?
213case $check1 in
214 0) printprocesslog "INFO $program finished successfully for run $run file $file (return code $check1)"
215 if [ $file -gt 999 ]
216 then
217 corsikafilenew=$mcpath/$program/`printf %08d $run | cut -c 1-4`/`printf %08d $run | cut -c 5-8`/cer000`printf %06d $file | cut -c 4-6`
218 corsikafileold=$mcpath/$program/`printf %08d $run | cut -c 1-4`/`printf %08d $run | cut -c 5-8`/cer`printf %06d $file`
219 if ! mv $corsikafileold $corsikafilenew
220 then
221 printprocesslog "ERROR could not mv $corsikafileold to $corsikafilenew"
222 check=2
223 fi
224 fi
225 if ! grep 'END OF RUN' $logfile
226 then
227 printprocesslog "ERROR could not find 'END OF RUN' in $logfile => unknown error for run $run file $file "
228 check=2
229 fi
230 ;;
231 *) printprocesslog "ERROR $program failed for run $run file $file (return code $check1)"
232 check=$check1
233 ;;
234esac
235
236# removing empty datnnnnnn file
237rm -f $outpath/dat`printf %06d $file`
238
239setstatus "stop"
240
241finish
242
Note: See TracBrowser for help on using the repository browser.