source: trunk/MagicSoft/Mars/datacenter/scripts/mcsequences@ 9217

Last change on this file since 9217 was 9217, checked in by hoehne, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 12.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 12/2005 <mailto:dorner@astro.uni-wuerzburg.de>
21# Author(s): Daniel Hoehne 06/2008 <mailto:hoehne@astro.uni-wuerzburg.de>
22#
23# Copyright: MAGIC Software Development, 2000-2008
24#
25#
26# ========================================================================
27#
28# The script is building two sequences per directory and epoch. One for
29# training and one for testing. The relevant parameters are taken from
30# the MC database.
31#
32
33source `dirname $0`/sourcefile
34printprocesslog "INFO starting $0"
35program=mcsequences
36
37set -C
38
39scriptlog=$runlogpath/$program-$datetime.log
40date >> $scriptlog 2>&1
41
42# check if script is already running
43lockfile=$lockpath/lock-$program.txt
44checklock >> $scriptlog 2>&1
45
46# find montecarlo directories, build two sequences per directory and write sequence files
47printprocesslog "INFO building two sequences per mcdirectory and epoch, one for training and one for testing"
48
49getdbsetup
50
51dirs=`find $mcrawpath -type d`
52for dir in ${dirs[@]}
53do
54 cont=`echo $dir | cut -d/ -f7`
55 #cont=`echo $dir | cut -d/ -f10`
56 if [ "$cont" == "" ]
57 then
58 continue
59 fi
60 echo $dir >> $scriptlog 2>&1
61
62 epochs=`ls -l $mcpath/camera | cut -c 52-80`
63 for epoch in ${epochs[@]}
64 do
65 echo $epoch >> $scriptlog 2>&1
66 calfile=`find $dir -lname *${epoch}/*.root | grep "_C_"`
67 pedfile=`find $dir -lname *${epoch}/*.root | grep "_P_"`
68
69 calrun=`echo $calfile | cut -d_ -f2`
70 pedrun=`echo $pedfile | cut -d_ -f2`
71
72 modes=("Gamma" "GammaW1" "GammaW2" "GammaFW" "GammaDiff" "GammaHE" "GammaHEW1" "GammaHEW2" "GammaHEFW" "GammaHEDiff" "ProtonDiff" "ProtonHEDiff" "MuonDiff" "MuonHEDiff")
73 for mode in ${modes[@]}
74 do
75 datruns=`find $dir -lname *${epoch}/*.root | grep ${mode}_ | grep "_D_" | cut -d_ -f2 | tr "\n" " "`
76 if [ "$datruns" != "" ]
77 then
78 num=`echo $datruns | wc -w`
79 train=`expr $num / 5`
80 test=`expr $num - $train`
81 last=`expr $num \* 9`
82 train2=`expr $train \* 9`
83 firstrun=`echo $datruns | cut -c 0-8`
84 trainruns=`echo $datruns | cut -c 0-$train2`
85 trainruns2=`echo $trainruns | sed -e 's/ /,/g'`
86 testruns=`echo $datruns | cut -c $train2-$last`
87 testruns2=`echo $testruns | sed -e 's/ /,/g'`
88 firstruntrain=`echo $trainruns | cut -c 0-8`
89 firstruntest=`echo $testruns | cut -c 0-8`
90
91 date=`echo $dir | cut -c 28-37 | sed -e 's/\//-/g'`
92 #date=`echo $dir | cut -c 57-66 | sed -e 's/\//-/g'`
93 zbin=`echo $date | cut -c 3,4`
94
95
96 #training runs
97 for trainrun in ${trainruns[@]}
98 do
99 trainupdate=" update MCRunData set fSequenceFirst=\"$firstruntrain\" where fRunNumber=\"$trainrun\" "
100 mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainupdate "
101 done
102
103 trainquery1=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY, fAddSpotSizeKEY from MCRunData where fRunNumber=\"$firstruntrain\" "
104 trainquery2=" select sum(fNumEvents), sum(fNumtriggers) from MCRunData where fRunNumber in ($trainruns2) "
105 trainvalues=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainquery1 "`
106 trainvalues2=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainquery2 "`
107 trainspec=`echo $trainvalues | cut -d" " -f1`
108 trainpsf=`echo $trainvalues | cut -d" " -f2`
109 trainamplfadc=`echo $trainvalues | cut -d" " -f3`
110 traintrainatmo=`echo $trainvalues | cut -d" " -f4`
111 trainobs=`echo $trainvalues | cut -d" " -f5`
112 trainpart=`echo $trainvalues | cut -d" " -f6`
113 trainrefl=`echo $trainvalues | cut -d" " -f7`
114 traincors=`echo $trainvalues | cut -d" " -f8`
115 traincam=`echo $trainvalues | cut -d" " -f9`
116 trainview=`echo $trainvalues | cut -d" " -f10`
117 trainass=`echo $trainvalues | cut -d" " -f11`
118 trainevents=`echo $trainvalues2 | cut -d" " -f1`
119 traintriggers=`echo $trainvalues2 | cut -d" " -f2`
120 trainquery3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstruntrain\" "
121 trainquery4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstruntrain\" "
122 traincheck3=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainquery3 "`
123 traincheck4=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainquery4 "`
124 traininsert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstruntrain\", fSequenceFileWritten=Now() "
125 traininsert2=" insert MCSequences set fSequenceFirst=\"$firstruntrain\", fRunStart=\"$date\", fNumEvents=\"$trainevents\", fNumTriggers=\"$traintriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$trainspec\", fPSFKEY=\"$trainpsf\", fAddSpotSizeKEY=\"$trainass\", fAmplFadcKEY=\"$trainamplfadc\", fAtmosphericModelKEY=\"$trainatmo\", fObservationModeKEY=\"$trainobs\", fMCParticleKEY=\"$trainpart\", fReflectorVersionKEY=\"$trainrefl\", fCorsikaVersionKEY=\"$traincors\", fCameraVersionKEY=\"$traincam\", fViewConeAngleOKEY=\"$trainview\", fTestTrainKEY=2 "
126 trainupdate2=" update MCSequences set fRunStart=\"$date\", fNumEvents=\"$trainevents\", fNumTriggers=\"$traintriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$trainspec\", fPSFKEY=\"$trainpsf\", fAddSpotSizeKEY=\"$trainass\", fAmplFadcKEY=\"$trainamplfadc\", fAtmosphericModelKEY=\"$trainatmo\", fObservationModeKEY=\"$trainobs\", fMCParticleKEY=\"$trainpart\", fReflectorVersionKEY=\"$trainrefl\", fCorsikaVersionKEY=\"$traincors\", fCameraVersionKEY=\"$traincam\", fViewConeAngleOKEY=\"$trainview\", fTestTrainKEY=2 where fSequenceFirst=\"$firstruntrain\" "
127 if [ "$traincheck3" == "" ]
128 then
129 mysql -ss -u $user --password=$pw --host=$ho $db -e " $traininsert1 "
130 fi
131 if [ "$traincheck4" == "" ]
132 then
133 mysql -ss -u $user --password=$pw --host=$ho $db -e " $traininsert2 "
134 else
135 mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainupdate2 "
136 fi
137
138 trainno=`echo $firstruntrain | cut -c 0-4`
139 trainsequpath=$mcsequpath/$trainno
140 makedir $trainsequpath >> $scriptlog 2>&1
141 trainsequfile=$trainsequpath/sequence$firstruntrain.txt
142 echo "writing train sequfile "$trainsequfile >> $scriptlog 2>&1
143 printprocesslog "INFO writing train sequencefile $trainsequfile"
144
145 echo "Sequence: $firstruntrain" >| $trainsequfile
146 echo "Night: $date" >> $trainsequfile
147 echo "Epoch: $epoch" >> $trainsequfile
148 echo "Mode: $mode" >> $trainsequfile
149 echo "" >> $trainsequfile
150 echo "CalRuns: $calrun" >> $trainsequfile
151 echo "PedRuns: $pedrun" >> $trainsequfile
152 echo "DatRuns: $trainruns" >> $trainsequfile
153 echo "" >> $trainsequfile
154 echo "MonteCarlo: Yes" >> $trainsequfile
155 echo "Training sequence" >> $trainsequfile
156 echo "" >> $trainsequfile
157
158
159 #test runs
160 for testrun in ${testruns[@]}
161 do
162 testupdate=" update MCRunData set fSequenceFirst=\"$firstruntest\" where fRunNumber=\"$testrun\" "
163 mysql -ss -u $user --password=$pw --host=$ho $db -e " $testupdate "
164 done
165
166 testquery1=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY, fAddSpotSizeKEY from MCRunData where fRunNumber=\"$firstruntest\" "
167 testquery2=" select sum(fNumEvents), sum(fNumtriggers) from MCRunData where fRunNumber in ($testruns2) "
168 testvalues=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $testquery1 "`
169 testvalues2=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $testquery2 "`
170 testspec=`echo $testvalues | cut -d" " -f1`
171 testpsf=`echo $testvalues | cut -d" " -f2`
172 testamplfadc=`echo $testvalues | cut -d" " -f3`
173 testatmo=`echo $testvalues | cut -d" " -f4`
174 testobs=`echo $testvalues | cut -d" " -f5`
175 testpart=`echo $testvalues | cut -d" " -f6`
176 testrefl=`echo $testvalues | cut -d" " -f7`
177 testcors=`echo $testvalues | cut -d" " -f8`
178 testcam=`echo $testvalues | cut -d" " -f9`
179 testview=`echo $testvalues | cut -d" " -f10`
180 testass=`echo $testvalues | cut -d" " -f11`
181 testevents=`echo $testvalues2 | cut -d" " -f1`
182 testtriggers=`echo $testvalues2 | cut -d" " -f2`
183 testquery3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstruntest\" "
184 testquery4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstruntest\" "
185 testcheck3=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $testquery3 "`
186 testcheck4=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $testquery4 "`
187 testinsert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstruntest\", fSequenceFileWritten=Now() "
188 testinsert2=" insert MCSequences set fSequenceFirst=\"$firstruntest\", fRunStart=\"$date\", fNumEvents=\"$testevents\", fNumTriggers=\"$testtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$testspec\", fPSFKEY=\"$testpsf\", fAddSpotSizeKEY=\"$testass\", fAmplFadcKEY=\"$testamplfadc\", fAtmosphericModelKEY=\"$testatmo\", fObservationModeKEY=\"$testobs\", fMCParticleKEY=\"$testpart\", fReflectorVersionKEY=\"$testrefl\", fCorsikaVersionKEY=\"$testcors\", fCameraVersionKEY=\"$testcam\", fViewConeAngleOKEY=\"$testview\", fTestTrainKEY=3 "
189 testupdate2=" update MCSequences set fRunStart=\"$date\", fNumEvents=\"$testevents\", fNumTriggers=\"$testtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$testspec\", fPSFKEY=\"$testpsf\", fAddSpotSizeKEY=\"$testass\", fAmplFadcKEY=\"$testamplfadc\", fAtmosphericModelKEY=\"$testatmo\", fObservationModeKEY=\"$testobs\", fMCParticleKEY=\"$testpart\", fReflectorVersionKEY=\"$testrefl\", fCorsikaVersionKEY=\"$testcors\", fCameraVersionKEY=\"$testcam\", fViewConeAngleOKEY=\"$testview\", fTestTrainKEY=3 where fSequenceFirst=\"$firstruntest\" "
190 if [ "$testcheck3" == "" ]
191 then
192 mysql -ss -u $user --password=$pw --host=$ho $db -e " $testinsert1 "
193 fi
194 if [ "$testcheck4" == "" ]
195 then
196 mysql -ss -u $user --password=$pw --host=$ho $db -e " $testinsert2 "
197 else
198 mysql -ss -u $user --password=$pw --host=$ho $db -e " $testupdate2 "
199 fi
200
201 testno=`echo $firstruntest | cut -c 0-4`
202 testsequpath=$mcsequpath/$testno
203 makedir $testsequpath >> $scriptlog 2>&1
204 testsequfile=$testsequpath/sequence$firstruntest.txt
205 echo "writing test sequfile "$testsequfile >> $scriptlog 2>&1
206 printprocesslog "INFO writing test sequencefile $testsequfile"
207
208 echo "Sequence: $firstruntest" >| $testsequfile
209 echo "Night: $date" >> $testsequfile
210 echo "Epoch: $epoch" >> $testsequfile
211 echo "Mode: $mode" >> $testsequfile
212 echo "" >> $testsequfile
213 echo "CalRuns: $calrun" >> $testsequfile
214 echo "PedRuns: $pedrun" >> $testsequfile
215 echo "DatRuns: $testruns" >> $testsequfile
216 echo "" >> $testsequfile
217 echo "MonteCarlo: Yes" >> $testsequfile
218 echo "Test sequence" >> $testsequfile
219 echo "" >> $testsequfile
220 fi
221 done
222 done
223done
224
225finish >> $scriptlog 2>&1
226
Note: See TracBrowser for help on using the repository browser.