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

Last change on this file since 9312 was 9225, checked in by hoehne, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 13.4 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-Moench 01/2009 <mailto:hoehne@astro.uni-wuerzburg.de>
22#
23# Copyright: MAGIC Software Development, 2000-2009
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" "GammaSUM" "GammaW1SUM" "GammaW2SUM" "GammaFWSUM" "GammaDiffSUM" "GammaHESUM" "GammaHEW1SUM" "GammaHEW2SUM" "GammaHEFWSUM" "GammaHEDiffSUM" "ProtonDiffSUM" "ProtonHEDiffSUM" "MuonDiffSUM" "MuonHEDiffSUM")
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, fTriggerFlagKEY from MCRunData where fRunNumber=\"$firstruntrain\" "
104 trainquery2=" select sum(fNumEvents), sum(fNumTriggers), sum(fNumSumTriggers) 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 traintrig=`echo $trainvalues | cut -d" " -f12`
119 trainevents=`echo $trainvalues2 | cut -d" " -f1`
120 traintriggers=`echo $trainvalues2 | cut -d" " -f2`
121 trainsumtriggers=`echo $trainvalues2 | cut -d" " -f3`
122 trainquery3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstruntrain\" "
123 trainquery4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstruntrain\" "
124 traincheck3=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainquery3 "`
125 traincheck4=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainquery4 "`
126 traininsert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstruntrain\", fSequenceFileWritten=Now() "
127 traininsert2=" insert MCSequences set fSequenceFirst=\"$firstruntrain\", fPriority=\"$firstruntrain\", fRunStart=\"$date\", fNumEvents=\"$trainevents\", fNumTriggers=\"$traintriggers\", fNumSumTriggers=\"$trainsumtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$trainspec\", fPSFKEY=\"$trainpsf\", fAddSpotSizeKEY=\"$trainass\", fAmplFadcKEY=\"$trainamplfadc\", fAtmosphericModelKEY=\"$trainatmo\", fObservationModeKEY=\"$trainobs\", fMCParticleKEY=\"$trainpart\", fReflectorVersionKEY=\"$trainrefl\", fCorsikaVersionKEY=\"$traincors\", fCameraVersionKEY=\"$traincam\", fViewConeAngleOKEY=\"$trainview\", fTriggerFlagKEY=\"$traintrig\", fTestTrainKEY=2 "
128 trainupdate2=" update MCSequences set fRunStart=\"$date\", fNumEvents=\"$trainevents\", fNumTriggers=\"$traintriggers\", fNumSumTriggers=\"$trainsumtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$trainspec\", fPSFKEY=\"$trainpsf\", fAddSpotSizeKEY=\"$trainass\", fAmplFadcKEY=\"$trainamplfadc\", fAtmosphericModelKEY=\"$trainatmo\", fObservationModeKEY=\"$trainobs\", fMCParticleKEY=\"$trainpart\", fReflectorVersionKEY=\"$trainrefl\", fCorsikaVersionKEY=\"$traincors\", fCameraVersionKEY=\"$traincam\", fViewConeAngleOKEY=\"$trainview\", fTriggerFlagKEY=\"$traintrig\", fTestTrainKEY=2 where fSequenceFirst=\"$firstruntrain\" "
129 if [ "$traincheck3" == "" ]
130 then
131 mysql -ss -u $user --password=$pw --host=$ho $db -e " $traininsert1 "
132 fi
133 if [ "$traincheck4" == "" ]
134 then
135 mysql -ss -u $user --password=$pw --host=$ho $db -e " $traininsert2 "
136 else
137 mysql -ss -u $user --password=$pw --host=$ho $db -e " $trainupdate2 "
138 fi
139
140 trainno=`echo $firstruntrain | cut -c 0-4`
141 trainsequpath=$mcsequpath/$trainno
142 makedir $trainsequpath >> $scriptlog 2>&1
143 trainsequfile=$trainsequpath/sequence$firstruntrain.txt
144 echo "writing train sequfile "$trainsequfile >> $scriptlog 2>&1
145 printprocesslog "INFO writing train sequencefile $trainsequfile"
146
147 echo "Sequence: $firstruntrain" >| $trainsequfile
148 echo "Night: $date" >> $trainsequfile
149 echo "Epoch: $epoch" >> $trainsequfile
150 echo "Mode: $mode" >> $trainsequfile
151 echo "" >> $trainsequfile
152 echo "CalRuns: $calrun" >> $trainsequfile
153 echo "PedRuns: $pedrun" >> $trainsequfile
154 echo "DatRuns: $trainruns" >> $trainsequfile
155 echo "" >> $trainsequfile
156 echo "MonteCarlo: Yes" >> $trainsequfile
157 echo "Training sequence" >> $trainsequfile
158 echo "" >> $trainsequfile
159
160
161 #test runs
162 for testrun in ${testruns[@]}
163 do
164 testupdate=" update MCRunData set fSequenceFirst=\"$firstruntest\" where fRunNumber=\"$testrun\" "
165 mysql -ss -u $user --password=$pw --host=$ho $db -e " $testupdate "
166 done
167
168 testquery1=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY, fAddSpotSizeKEY, fTriggerFlagKEY from MCRunData where fRunNumber=\"$firstruntest\" "
169 testquery2=" select sum(fNumEvents), sum(fNumTriggers), sum(fNumSumTriggers) from MCRunData where fRunNumber in ($testruns2) "
170 testvalues=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $testquery1 "`
171 testvalues2=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $testquery2 "`
172 testspec=`echo $testvalues | cut -d" " -f1`
173 testpsf=`echo $testvalues | cut -d" " -f2`
174 testamplfadc=`echo $testvalues | cut -d" " -f3`
175 testatmo=`echo $testvalues | cut -d" " -f4`
176 testobs=`echo $testvalues | cut -d" " -f5`
177 testpart=`echo $testvalues | cut -d" " -f6`
178 testrefl=`echo $testvalues | cut -d" " -f7`
179 testcors=`echo $testvalues | cut -d" " -f8`
180 testcam=`echo $testvalues | cut -d" " -f9`
181 testview=`echo $testvalues | cut -d" " -f10`
182 testass=`echo $testvalues | cut -d" " -f11`
183 testtrig=`echo $testvalues | cut -d" " -f12`
184 testevents=`echo $testvalues2 | cut -d" " -f1`
185 testtriggers=`echo $testvalues2 | cut -d" " -f2`
186 testsumtriggers=`echo $testvalues2 | cut -d" " -f3`
187 testquery3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstruntest\" "
188 testquery4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstruntest\" "
189 testcheck3=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $testquery3 "`
190 testcheck4=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $testquery4 "`
191 testinsert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstruntest\", fSequenceFileWritten=Now() "
192 testinsert2=" insert MCSequences set fSequenceFirst=\"$firstruntest\", fPriority=\"$firstruntest\", fRunStart=\"$date\", fNumEvents=\"$testevents\", fNumTriggers=\"$testtriggers\", fNumSumTriggers=\"$testsumtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$testspec\", fPSFKEY=\"$testpsf\", fAddSpotSizeKEY=\"$testass\", fAmplFadcKEY=\"$testamplfadc\", fAtmosphericModelKEY=\"$testatmo\", fObservationModeKEY=\"$testobs\", fMCParticleKEY=\"$testpart\", fReflectorVersionKEY=\"$testrefl\", fCorsikaVersionKEY=\"$testcors\", fCameraVersionKEY=\"$testcam\", fViewConeAngleOKEY=\"$testview\", fTriggerFlagKEY=\"$testtrig\", fTestTrainKEY=3 "
193 testupdate2=" update MCSequences set fRunStart=\"$date\", fNumEvents=\"$testevents\", fNumTriggers=\"$testtriggers\", fNumSumTriggers=\"$testsumtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$testspec\", fPSFKEY=\"$testpsf\", fAddSpotSizeKEY=\"$testass\", fAmplFadcKEY=\"$testamplfadc\", fAtmosphericModelKEY=\"$testatmo\", fObservationModeKEY=\"$testobs\", fMCParticleKEY=\"$testpart\", fReflectorVersionKEY=\"$testrefl\", fCorsikaVersionKEY=\"$testcors\", fCameraVersionKEY=\"$testcam\", fViewConeAngleOKEY=\"$testview\", fTriggerFlagKEY=\"$testtrig\", fTestTrainKEY=3 where fSequenceFirst=\"$firstruntest\" "
194 if [ "$testcheck3" == "" ]
195 then
196 mysql -ss -u $user --password=$pw --host=$ho $db -e " $testinsert1 "
197 fi
198 if [ "$testcheck4" == "" ]
199 then
200 mysql -ss -u $user --password=$pw --host=$ho $db -e " $testinsert2 "
201 else
202 mysql -ss -u $user --password=$pw --host=$ho $db -e " $testupdate2 "
203 fi
204
205 testno=`echo $firstruntest | cut -c 0-4`
206 testsequpath=$mcsequpath/$testno
207 makedir $testsequpath >> $scriptlog 2>&1
208 testsequfile=$testsequpath/sequence$firstruntest.txt
209 echo "writing test sequfile "$testsequfile >> $scriptlog 2>&1
210 printprocesslog "INFO writing test sequencefile $testsequfile"
211
212 echo "Sequence: $firstruntest" >| $testsequfile
213 echo "Night: $date" >> $testsequfile
214 echo "Epoch: $epoch" >> $testsequfile
215 echo "Mode: $mode" >> $testsequfile
216 echo "" >> $testsequfile
217 echo "CalRuns: $calrun" >> $testsequfile
218 echo "PedRuns: $pedrun" >> $testsequfile
219 echo "DatRuns: $testruns" >> $testsequfile
220 echo "" >> $testsequfile
221 echo "MonteCarlo: Yes" >> $testsequfile
222 echo "Test sequence" >> $testsequfile
223 echo "" >> $testsequfile
224 fi
225 done
226 done
227done
228
229finish >> $scriptlog 2>&1
230
Note: See TracBrowser for help on using the repository browser.