source: releases/Mars.2014.05.26/datacenter/scripts/runcorsika@ 20115

Last change on this file since 20115 was 10041, checked in by Daniela Dorner, 14 years ago
lock in db instead of lockfile
  • Property svn:executable set to *
File size: 9.1 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 run # and file #
147numchanged=0
148while (( 0 < 21 ))
149do
150 if ! [ $numchanged -eq 1 ]
151 then
152 if ! [ "$run" = "" ] && ! [ "$file" = "" ]
153 then
154 printprocesslog "INFO $program for run $run and file $file is already running => request new number "
155 fi
156 gettodo "1"
157 run=${primaries[0]}
158 file=${primaries[1]}
159 if [ "$run" = "" ] || [ "$file" = "" ]
160 then
161 printprocesslog "INFO nothing to do for $program "
162 fi
163 else
164 printprocesslog "INFO starting $program for run $run and file $file"
165 break
166 fi
167 setstatus "start"
168done
169
170# running corsika
171printprocesslog "INFO run $program for run $run and file $file"
172printprocesslog "INFO create input card for run $run and file $file"
173
174# get values for inputcard
175query="SELECT fParticleTypeKEY FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
176primparticle=`sendquery`
177query="SELECT fEnergyMin, fEnergyMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
178erange=`sendquery`
179query="SELECT fNumEvents FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
180numevts=`sendquery`
181query="SELECT fEnergySlope FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
182slope=`sendquery`
183query="SELECT fZenithDistanceMin, fZenithDistanceMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
184zdrange=`sendquery`
185# Change from the MARS definition (Az=90 -> East) to Corsika (Az=90 -> West)
186query="SELECT 180-fAzimuthMin, 180-fAzimuthMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
187azrange=`sendquery`
188query="SELECT fCorsikaSeed1 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
189seed1=`sendquery`
190query="SELECT fCorsikaSeed2 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
191seed2=`sendquery`
192query="SELECT fCorsikaSeed3 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
193seed3=`sendquery`
194query="SELECT fImpactMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
195impactmax=`sendquery`
196query="SELECT fViewConeMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
197viewconemax=`sendquery`
198query="SELECT fStartingAltitude FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
199startalt=`sendquery`
200query="SELECT fMirrorDiameter FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
201diameter=`sendquery`
202query="SELECT fAtmosphericModelKEY FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
203atm=`sendquery`
204query="SELECT fObsLevel FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
205obslev=`sendquery`
206query="SELECT fMagnetBX, fMagnetBZ FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
207magnet=`sendquery`
208query="SELECT fMagnetRotation FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
209magnetrot=`sendquery`
210query="SELECT fWavelengthMin, fWavelengthMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
211wavelengths=`sendquery`
212query="SELECT fNumReUseShowers FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
213numreuse=`sendquery`
214
215outpath=$mcpath"/"$program"/"`printf %08d $run | cut -c 1-4`/`printf %08d $run | cut -c 5-8`
216makedir $outpath
217logfile=$outpath/cer000`printf %06d $file | cut -c 4-6`".log"
218
219cd $corsikapath
220
221printprocesslog "INFO executing 'printinputcard | ./cc6501p-linux >| $logfile 2>&1' in directory $corsikapath "
222printinputcard | ./cc6501p-linux >| $logfile 2>&1
223
224check1=$?
225case $check1 in
226 0) printprocesslog "INFO $program finished successfully for run $run file $file (return code $check1)"
227 if [ $file -gt 999 ]
228 then
229 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`
230 corsikafileold=$mcpath/$program/`printf %08d $run | cut -c 1-4`/`printf %08d $run | cut -c 5-8`/cer`printf %06d $file`
231 if ! mv $corsikafileold $corsikafilenew
232 then
233 printprocesslog "ERROR could not mv $corsikafileold to $corsikafilenew"
234 check=2
235 fi
236 fi
237 if ! grep 'END OF RUN' $logfile
238 then
239 printprocesslog "ERROR could not find 'END OF RUN' in $logfile => unknown error for run $run file $file "
240 check=2
241 fi
242 ;;
243 *) printprocesslog "ERROR $program failed for run $run file $file (return code $check1)"
244 check=$check1
245 ;;
246esac
247
248# removing empty datnnnnnn file
249rm -f $outpath/dat`printf %06d $file`
250
251setstatus "stop"
252
253finish
254
Note: See TracBrowser for help on using the repository browser.