source: trunk/Mars/datacenter/scripts/insertmc@ 10012

Last change on this file since 10012 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: 9.3 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 08/2010 <mailto:daniela.dorner@unige.ch>
21#
22# Copyright: MAGIC Software Development, 2000-2010
23#
24#
25# ========================================================================
26#
27# script used to insert MC to the DB TestFACTSetup
28# also inserts sequence information
29#
30
31
32#
33# setup
34# to be filled by the user:
35#
36
37# to really insert information set insert="yes"
38insert="yes"
39insert=
40
41
42# give array of ceres keys
43# remark: in case you insert new ceres keys:
44# make sure that the information on the setup (i.e. table CeresSetup)
45# has been inserted before
46cereskeys=( 7 )
47cereskeys=( 1 2 3 4 5 6 7 8 9 10 11 12 )
48
49
50# give run number range which you want to process with the new setup
51# if one of these values is empty a new run is inserted with the setup given below
52# 423-960 corresponds to the range of runs used for the sensitivity curve
53# gammas: files 1300-1999 i.e. runs 423-630
54# muons: files 2400-2999 i.e. runs 753-930
55# protons: files 2000-2399 i.e. runs 633-750
56# protons: files 3000-3099 i.e. runs 933-960
57# protons: new runs 1040-1070
58runmin=423
59runmax=960
60runmin=1040
61runmax=1070
62runmin=
63runmax=
64
65
66#
67# setup for a new run
68#
69
70# number of events per file
71numevents=10000 # 250000
72# number of files per run
73numfile=1 # 10
74
75numreuse=1
76numreuse=20
77
78# particle type
79#particle=1 # gamma
80particle=14 # proton
81#particle=6 # muon
82#particle=3 # electron
83#particle=402 # helium
84#particle=5626 # iron
85
86
87# zenith range
88zdmin=30
89zdmax=30
90# azimuth range
91azmin=180
92azmax=180
93
94# energy (in GeV)
95emin=10 # 20
96emax=10 # 200000
97slope=-2.0 # for gammas, depends on source spectrum, or for test
98#slope=-2.78 # for protons and muons and irons
99
100# impact
101impactmax=80000 # for protons (and irons ?)
102#impactmax=42500 # for gammas
103#impactmax=20000 # for muons
104
105# view cone
106viewconemax=5.0 # for protons and irons
107#viewconemax=4.5 # for muons
108#viewconemax=0 # for gammas
109
110# starting altitude
111startalt=0 # for gammas and protons and irons
112#startalt=280 # for muons
113
114# mirror diameter
115mirrordia=1800
116mirrordia=900
117
118# wavelength range
119wavelengthmin=290
120wavelengthmax=900
121
122# observatory key
123obskey=1 # LP
124
125#
126# script - do not edit below
127#
128source `dirname $0`/sourcefile
129
130
131function sendquery2()
132{
133 if [ "$insert" = "yes" ]
134 then
135 sendquery >/dev/null
136 else
137 echo "Q: "$query
138 fi
139}
140
141# atmospheric model (at the moment only 11 to be used)
142# will be moved to user settings later
143atm=11
144
145# switches for insert
146newrun=
147newceres=
148
149# get ceres setup name
150query="SELECT fCeresSetupName FROM CeresSetup WHERE fCeresSetupKEY in ("`echo ${cereskeys[@]} | sed -e 's/\ /,/g'`")"
151echo $query
152ceresnames=( `sendquery` )
153if [ ${#ceresnames[@]} -lt ${#cereskeys[@]} ]
154then
155 echo "Please insert first the information on all new ceres setups (keys: "${cereskeys[@]}") into the database."
156 echo "EXIT."
157 exit
158fi
159
160if [ "$runmin" == "" ] || [ "$runmax" == "" ]
161then
162 newrun="yes"
163 # get next run number
164 query="SELECT Max(fRunNumber)+1 FROM CorsikaStatus"
165 prun=`sendquery`
166 crun=`echo " $prun + 1 " | bc -l`
167 drun=`echo " $prun + 2 " | bc -l`
168 runs=( $drun )
169
170 # get particle type name
171 query="SELECT fParticleTypeName FROM ParticleType WHERE fParticleTypeKEY="$particle
172 pname=`sendquery`
173
174 # get observatory name
175 query="SELECT fObservatoryName FROM Observatory WHERE fObservatoryKEY="$obskey
176 obsname=`sendquery`
177
178 echo "Do you really want to insert the following run(s)?"
179 echo " D-Run: "$drun" ("$numfile" file(s))"
180 echo " P-Run: "$prun
181 echo " C-Run: "$crun
182 echo " Particle: "$particle" ("$pname")"
183 echo " Number of events: "$numevents
184 echo " Energy: "$emin" GeV - "$emax" GeV "
185 echo " Slope: "$slope
186 echo " Maximum Impact: "$impactmax" m "
187 echo " Maximum View Cone: "$viewconemax" deg "
188 echo " Starting Altitude: "$startalt
189 echo " Mirror Diameter: "$mirrordia" cm "
190 echo " Zenith Distance: "$zdmin" deg - "$zdmax" deg "
191 echo " Azimuth: "$azmin" deg - "$azmax" deg "
192 echo " Wavelength: "$wavelengthmin" nm - "$wavelengthmax" nm "
193 echo " Observatory: "$obskey" ("$obsname")"
194else
195 newceres="yes"
196 echo "Do you really want to insert the following cereskey(s)?"
197 echo " run number range: "$runmin" - "$runmax
198 query="SELECT fRunNumber FROM CorsikaInfo WHERE fRunNumber BETWEEN "$runmin" AND "$runmax" GROUP BY fRunNumber"
199 runs=( `sendquery` )
200 echo " i.e. the following runs: "${runs[@]}
201fi
202echo " Ceres Setups: "${cereskeys[@]}" ("${ceresnames[@]}") "
203echo ""
204if [ "$insert" = "yes" ]
205then
206 echo "You are NOT executing the script in dummy mode => the runs will be inserted. "
207else
208 echo "You are executing the script in dummy mode => nothing will be inserted. "
209fi
210
211echo "Please insert y, if you want to continue"
212echo " n, if you want to exit the script"
213
214answer=`head -n 1`
215echo "Your answer: "$answer
216
217case $answer in
218 y) ;;
219 n) echo "EXIT"
220 exit
221 ;;
222 *) echo "Your answer is not clear -> EXIT"
223 exit
224 ;;
225esac
226
227
228
229if [ "$newrun" = "yes" ]
230then
231 echo "inserting new run "$drun" and according C-run, P-run and sequence information..."
232 #
233 # corsika information
234 #
235 for (( i=1 ; i<=$numfile ; i++ ))
236 do
237 seed1=`echo " $drun * 1000 + $i " | bc -l`
238 seed2=`echo " $drun * 1000 + $i + 1 " | bc -l`
239 seed3=`echo " $drun * 1000 + $i + 2 " | bc -l`
240
241 query="INSERT CorsikaStatus SET fRunNumber="$drun", fFileNumber="$i", fPriority="$drun
242 sendquery2
243 query="INSERT CorsikaInfo SET fRunNumber="$drun", fFileNumber="$i
244 query=$query", fAtmosphericModelKEY="$atm", fParticleTypeKEY="$particle
245 query=$query", fCorsikaSeed1="$seed1", fCorsikaSeed2="$seed2", fCorsikaSeed3="$seed3
246 query=$query", fZenithDistanceMin="$zdmin", fZenithDistanceMax="$zdmax
247 query=$query", fAzimuthMin="$azmin", fAzimuthMax="$azmax", fNumEvents="$numevents
248 query=$query", fEnergyMin="$emin", fEnergyMax="$emax", fEnergySlope="$slope
249 query=$query", fImpactMax="$impactmax", fViewConeMax="$viewconemax
250 query=$query", fStartingAltitude="$startalt", fMirrorDiameter="$mirrordia
251 query=$query", fObservatoryKEY="$obskey", fNumReUseShowers="$numreuse
252 query=$query", fWavelengthMin="$wavelengthmin", fWavelengthMax="$wavelengthmax
253 sendquery2
254 done
255
256 query="INSERT CorsikaStatus SET fRunNumber="$prun", fFileNumber=1, fStartTime='1970-01-01 00:00:00', fStopTime='1970-01-01 00:00:00' "", fPriority="$prun
257 sendquery2
258 query="INSERT CorsikaStatus SET fRunNumber="$crun", fFileNumber=1, fStartTime='1970-01-01 00:00:00', fStopTime='1970-01-01 00:00:00' "", fPriority="$crun
259 sendquery2
260
261 # sequence file
262 # does not need ceres key as well
263 query="INSERT SequenceFileStatus SET fSequenceNumber="$drun", fPriority="$drun
264 sendquery2
265fi
266
267#
268# further tables: CeresInfo, CeresStatus, Callisto, Calibration, Star, StarStatus, SequenceInfo
269#
270for run in ${runs[@]}
271do
272 drun=$run
273 crun=`echo " $drun - 1 " | bc -l`
274 prun=`echo " $drun - 2 " | bc -l`
275
276 for cereskey in ${cereskeys[@]}
277 do
278 query="SELECT fFileNumber FROM CorsikaInfo WHERE fRunNumber="$drun
279 files=`sendquery`
280 for file in ${files[@]}
281 do
282 query="INSERT CeresInfo SET fSequenceNumber="$drun", fRunNumber="$drun", fFileNumber="$file", fCeresSetupKEY="$cereskey", fRunTypeKEY=2"
283 sendquery2
284 done
285
286 query="INSERT CeresInfo SET fSequenceNumber="$drun", fRunNumber="$prun", fFileNumber=1, fCeresSetupKEY="$cereskey", fRunTypeKEY=3"
287 sendquery2
288 query="INSERT CeresInfo SET fSequenceNumber="$drun", fRunNumber="$crun", fFileNumber=1, fCeresSetupKEY="$cereskey", fRunTypeKEY=4"
289 sendquery2
290 query="INSERT CeresStatus SET fRunNumber="$drun", fCeresSetupKEY="$cereskey", fPriority="$drun
291 sendquery2
292 query="INSERT CeresStatus SET fRunNumber="$prun", fCeresSetupKEY="$cereskey", fPriority="$prun
293 sendquery2
294 query="INSERT CeresStatus SET fRunNumber="$crun", fCeresSetupKEY="$cereskey", fPriority="$crun
295 sendquery2
296 query="INSERT Star SET fSequenceNumber="$drun", fCeresSetupKEY="$cereskey
297 sendquery2
298 query="INSERT StarStatus SET fSequenceNumber="$drun", fCeresSetupKEY="$cereskey", fPriority="$drun
299 sendquery2
300 query="INSERT CallistoStatus SET fSequenceNumber="$drun", fCeresSetupKEY="$cereskey", fPriority="$drun
301 sendquery2
302 query="INSERT Calibration SET fSequenceNumber="$drun", fCeresSetupKEY="$cereskey
303 sendquery2
304 query="INSERT SequenceInfo SET fSequenceNumber="$drun", fCeresSetupKEY="$cereskey
305 sendquery2
306 done
307done
308
309
310
311
Note: See TracBrowser for help on using the repository browser.