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

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