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

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