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

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