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