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 |
|
---|
33 | source `dirname $0`/sourcefile
|
---|
34 | printprocesslog "INFO starting $0"
|
---|
35 | program=mcsequences
|
---|
36 |
|
---|
37 | set -C
|
---|
38 |
|
---|
39 | # check if script is already running
|
---|
40 | lockfile=$lockpath/lock-$program.txt
|
---|
41 | checklock
|
---|
42 |
|
---|
43 | # find montecarlo directories, build two sequences per directory and write sequence files
|
---|
44 | printprocesslog "INFO building two sequences per mcdirectory and epoch, one for training and one for testing"
|
---|
45 |
|
---|
46 | getdbsetup
|
---|
47 |
|
---|
48 | dirs=`find $mcrawpath -type d`
|
---|
49 | for dir in ${dirs[@]}
|
---|
50 | do
|
---|
51 | cont=`echo $dir | cut -d/ -f7`
|
---|
52 | #cont=`echo $dir | cut -d/ -f10`
|
---|
53 | if [ "$cont" == "" ]
|
---|
54 | then
|
---|
55 | continue
|
---|
56 | fi
|
---|
57 | printprocesslog "INFO dir: "$dir
|
---|
58 |
|
---|
59 | epochs=`ls -l $mcpath/camera | cut -c 52-80`
|
---|
60 | for epoch in ${epochs[@]}
|
---|
61 | do
|
---|
62 | printprocesslog "INFO epoch: "$epoch
|
---|
63 | calfile=`find $dir -lname *${epoch}/*.root | grep "_C_"`
|
---|
64 | pedfile=`find $dir -lname *${epoch}/*.root | grep "_P_"`
|
---|
65 |
|
---|
66 | calrun=`echo $calfile | cut -d_ -f2`
|
---|
67 | pedrun=`echo $pedfile | cut -d_ -f2`
|
---|
68 |
|
---|
69 | 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")
|
---|
70 | for mode in ${modes[@]}
|
---|
71 | do
|
---|
72 | datruns=`find $dir -lname *${epoch}/*.root | grep ${mode}_ | grep "_D_" | cut -d_ -f2 | tr "\n" " "`
|
---|
73 | if [ "$datruns" != "" ]
|
---|
74 | then
|
---|
75 | num=`echo $datruns | wc -w`
|
---|
76 | train=`expr $num / 5`
|
---|
77 | test=`expr $num - $train`
|
---|
78 | last=`expr $num \* 9`
|
---|
79 | train2=`expr $train \* 9`
|
---|
80 | firstrun=`echo $datruns | cut -c 0-8`
|
---|
81 | trainruns=`echo $datruns | cut -c 0-$train2`
|
---|
82 | trainruns2=`echo $trainruns | sed -e 's/ /,/g'`
|
---|
83 | testruns=`echo $datruns | cut -c $train2-$last`
|
---|
84 | testruns2=`echo $testruns | sed -e 's/ /,/g'`
|
---|
85 | firstruntrain=`echo $trainruns | cut -c 0-8`
|
---|
86 | firstruntest=`echo $testruns | cut -c 0-8`
|
---|
87 |
|
---|
88 | date=`echo $dir | cut -c 28-37 | sed -e 's/\//-/g'`
|
---|
89 | #date=`echo $dir | cut -c 57-66 | sed -e 's/\//-/g'`
|
---|
90 | zbin=`echo $date | cut -c 3,4`
|
---|
91 |
|
---|
92 |
|
---|
93 | #training runs
|
---|
94 | for trainrun in ${trainruns[@]}
|
---|
95 | do
|
---|
96 | trainupdate=" update MCRunData set fSequenceFirst=\"$firstruntrain\" where fRunNumber=\"$trainrun\" "
|
---|
97 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $trainupdate "
|
---|
98 | done
|
---|
99 |
|
---|
100 | trainquery1=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY, fAddSpotSizeKEY, fTriggerFlagKEY from MCRunData where fRunNumber=\"$firstruntrain\" "
|
---|
101 | trainquery2=" select sum(fNumEvents), sum(fNumTriggers), sum(fNumSumTriggers) from MCRunData where fRunNumber in ($trainruns2) "
|
---|
102 | trainvalues=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $trainquery1 "`
|
---|
103 | trainvalues2=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $trainquery2 "`
|
---|
104 | trainspec=`echo $trainvalues | cut -d" " -f1`
|
---|
105 | trainpsf=`echo $trainvalues | cut -d" " -f2`
|
---|
106 | trainamplfadc=`echo $trainvalues | cut -d" " -f3`
|
---|
107 | traintrainatmo=`echo $trainvalues | cut -d" " -f4`
|
---|
108 | trainobs=`echo $trainvalues | cut -d" " -f5`
|
---|
109 | trainpart=`echo $trainvalues | cut -d" " -f6`
|
---|
110 | trainrefl=`echo $trainvalues | cut -d" " -f7`
|
---|
111 | traincors=`echo $trainvalues | cut -d" " -f8`
|
---|
112 | traincam=`echo $trainvalues | cut -d" " -f9`
|
---|
113 | trainview=`echo $trainvalues | cut -d" " -f10`
|
---|
114 | trainass=`echo $trainvalues | cut -d" " -f11`
|
---|
115 | traintrig=`echo $trainvalues | cut -d" " -f12`
|
---|
116 | trainevents=`echo $trainvalues2 | cut -d" " -f1`
|
---|
117 | traintriggers=`echo $trainvalues2 | cut -d" " -f2`
|
---|
118 | trainsumtriggers=`echo $trainvalues2 | cut -d" " -f3`
|
---|
119 | trainquery3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstruntrain\" "
|
---|
120 | trainquery4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstruntrain\" "
|
---|
121 | traincheck3=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $trainquery3 "`
|
---|
122 | traincheck4=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $trainquery4 "`
|
---|
123 | traininsert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstruntrain\", fPriority=\"$firstruntrain\", fSequenceFileWritten=Now() "
|
---|
124 | traininsert2=" insert MCSequences set fSequenceFirst=\"$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 "
|
---|
125 | 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\" "
|
---|
126 | if [ "$traincheck3" == "" ]
|
---|
127 | then
|
---|
128 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $traininsert1 "
|
---|
129 | fi
|
---|
130 | if [ "$traincheck4" == "" ]
|
---|
131 | then
|
---|
132 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $traininsert2 "
|
---|
133 | else
|
---|
134 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $trainupdate2 "
|
---|
135 | fi
|
---|
136 |
|
---|
137 | trainno=`echo $firstruntrain | cut -c 0-4`
|
---|
138 | trainsequpath=$mcsequpath/$trainno
|
---|
139 | makedir $trainsequpath
|
---|
140 | trainsequfile=$trainsequpath/sequence$firstruntrain.txt
|
---|
141 | printprocesslog "INFO writing train sequencefile $trainsequfile"
|
---|
142 |
|
---|
143 | echo "Sequence: $firstruntrain" >| $trainsequfile
|
---|
144 | echo "Night: $date" >> $trainsequfile
|
---|
145 | echo "Epoch: $epoch" >> $trainsequfile
|
---|
146 | echo "Mode: $mode" >> $trainsequfile
|
---|
147 | echo "" >> $trainsequfile
|
---|
148 | echo "CalRuns: $calrun" >> $trainsequfile
|
---|
149 | echo "PedRuns: $pedrun" >> $trainsequfile
|
---|
150 | echo "DatRuns: $trainruns" >> $trainsequfile
|
---|
151 | echo "" >> $trainsequfile
|
---|
152 | echo "MonteCarlo: Yes" >> $trainsequfile
|
---|
153 | echo "Training sequence" >> $trainsequfile
|
---|
154 | echo "" >> $trainsequfile
|
---|
155 |
|
---|
156 |
|
---|
157 | #test runs
|
---|
158 | for testrun in ${testruns[@]}
|
---|
159 | do
|
---|
160 | testupdate=" update MCRunData set fSequenceFirst=\"$firstruntest\" where fRunNumber=\"$testrun\" "
|
---|
161 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $testupdate "
|
---|
162 | done
|
---|
163 |
|
---|
164 | testquery1=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY, fAddSpotSizeKEY, fTriggerFlagKEY from MCRunData where fRunNumber=\"$firstruntest\" "
|
---|
165 | testquery2=" select sum(fNumEvents), sum(fNumTriggers), sum(fNumSumTriggers) from MCRunData where fRunNumber in ($testruns2) "
|
---|
166 | testvalues=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $testquery1 "`
|
---|
167 | testvalues2=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $testquery2 "`
|
---|
168 | testspec=`echo $testvalues | cut -d" " -f1`
|
---|
169 | testpsf=`echo $testvalues | cut -d" " -f2`
|
---|
170 | testamplfadc=`echo $testvalues | cut -d" " -f3`
|
---|
171 | testatmo=`echo $testvalues | cut -d" " -f4`
|
---|
172 | testobs=`echo $testvalues | cut -d" " -f5`
|
---|
173 | testpart=`echo $testvalues | cut -d" " -f6`
|
---|
174 | testrefl=`echo $testvalues | cut -d" " -f7`
|
---|
175 | testcors=`echo $testvalues | cut -d" " -f8`
|
---|
176 | testcam=`echo $testvalues | cut -d" " -f9`
|
---|
177 | testview=`echo $testvalues | cut -d" " -f10`
|
---|
178 | testass=`echo $testvalues | cut -d" " -f11`
|
---|
179 | testtrig=`echo $testvalues | cut -d" " -f12`
|
---|
180 | testevents=`echo $testvalues2 | cut -d" " -f1`
|
---|
181 | testtriggers=`echo $testvalues2 | cut -d" " -f2`
|
---|
182 | testsumtriggers=`echo $testvalues2 | cut -d" " -f3`
|
---|
183 | testquery3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstruntest\" "
|
---|
184 | testquery4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstruntest\" "
|
---|
185 | testcheck3=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $testquery3 "`
|
---|
186 | testcheck4=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $testquery4 "`
|
---|
187 | testinsert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstruntest\", fPriority=\"$firstruntest\", fSequenceFileWritten=Now() "
|
---|
188 | testinsert2=" insert MCSequences set fSequenceFirst=\"$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 "
|
---|
189 | 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\" "
|
---|
190 | if [ "$testcheck3" == "" ]
|
---|
191 | then
|
---|
192 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $testinsert1 "
|
---|
193 | fi
|
---|
194 | if [ "$testcheck4" == "" ]
|
---|
195 | then
|
---|
196 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $testinsert2 "
|
---|
197 | else
|
---|
198 | mysql -ss -u $us --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
|
---|
204 | testsequfile=$testsequpath/sequence$firstruntest.txt
|
---|
205 | printprocesslog "INFO writing test sequencefile $testsequfile"
|
---|
206 |
|
---|
207 | echo "Sequence: $firstruntest" >| $testsequfile
|
---|
208 | echo "Night: $date" >> $testsequfile
|
---|
209 | echo "Epoch: $epoch" >> $testsequfile
|
---|
210 | echo "Mode: $mode" >> $testsequfile
|
---|
211 | echo "" >> $testsequfile
|
---|
212 | echo "CalRuns: $calrun" >> $testsequfile
|
---|
213 | echo "PedRuns: $pedrun" >> $testsequfile
|
---|
214 | echo "DatRuns: $testruns" >> $testsequfile
|
---|
215 | echo "" >> $testsequfile
|
---|
216 | echo "MonteCarlo: Yes" >> $testsequfile
|
---|
217 | echo "Test sequence" >> $testsequfile
|
---|
218 | echo "" >> $testsequfile
|
---|
219 | fi
|
---|
220 | done
|
---|
221 | done
|
---|
222 | done
|
---|
223 |
|
---|
224 | finish
|
---|
225 |
|
---|