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

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