| 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 | #
|
|---|
| 22 | # Copyright: MAGIC Software Development, 2000-2007
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 | # ========================================================================
|
|---|
| 26 | #
|
|---|
| 27 | # This script is an intermediate solution to process the montecarlo files.
|
|---|
| 28 | # As soon as the montecarlo database is running, this script shall be
|
|---|
| 29 | # exchanged.
|
|---|
| 30 | #
|
|---|
| 31 | # The script is building one sequence per directory. As the files are
|
|---|
| 32 | # structured by condition, the files in one directory and such in one
|
|---|
| 33 | # sequence have the same observation mode, psf, zbin, ...
|
|---|
| 34 | #
|
|---|
| 35 |
|
|---|
| 36 | source `dirname $0`/sourcefile
|
|---|
| 37 | printprocesslog "INFO starting $0"
|
|---|
| 38 | program=mcsequences
|
|---|
| 39 |
|
|---|
| 40 | set -C
|
|---|
| 41 |
|
|---|
| 42 | scriptlog=$runlogpath/$program-$datetime.log
|
|---|
| 43 | date >> $scriptlog 2>&1
|
|---|
| 44 |
|
|---|
| 45 | # check if script is already running
|
|---|
| 46 | lockfile=$lockpath/lock-$program.txt
|
|---|
| 47 | checklock >> $scriptlog 2>&1
|
|---|
| 48 |
|
|---|
| 49 | # find montecarlo directories, build one sequence per directory and write sequence file
|
|---|
| 50 | printprocesslog "INFO building one sequence per mcdirectory and epoch"
|
|---|
| 51 |
|
|---|
| 52 | user="test"
|
|---|
| 53 | db="TestMonteCarlo"
|
|---|
| 54 | pw="Ics+eaTD"
|
|---|
| 55 |
|
|---|
| 56 | dirs=`find $mcrawpath -type d`
|
|---|
| 57 | for dir in ${dirs[@]}
|
|---|
| 58 | do
|
|---|
| 59 | cont=`echo $dir | cut -d/ -f6`
|
|---|
| 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-70`
|
|---|
| 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 | firstrun=`echo $datruns | cut -c 0-8`
|
|---|
| 84 | date=`echo $dir | cut -c 28-37 | sed -e 's/\//-/g'`
|
|---|
| 85 | #date=`echo $dir | cut -c 57-66 | sed -e 's/\//-/g'`
|
|---|
| 86 | zbin=`echo $date | cut -c 3,4`
|
|---|
| 87 |
|
|---|
| 88 | for datrun in ${datruns[@]}
|
|---|
| 89 | do
|
|---|
| 90 | update=" update MCRunData set fSequenceFirst=\"$firstrun\" where fRunNumber=\"$datrun\" "
|
|---|
| 91 | mysql -ss -u $user --password=$pw --host=vela $db -e " $update "
|
|---|
| 92 | done
|
|---|
| 93 |
|
|---|
| 94 | query=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY from MCRunData where fRunNumber=\"$firstrun\" "
|
|---|
| 95 | values=`mysql -ss -u $user --password=$pw --host=vela $db -e " $query "`
|
|---|
| 96 | spec=`echo $values | cut -d" " -f1`
|
|---|
| 97 | psf=`echo $values | cut -d" " -f2`
|
|---|
| 98 | amplfadc=`echo $values | cut -d" " -f3`
|
|---|
| 99 | atmo=`echo $values | cut -d" " -f4`
|
|---|
| 100 | obs=`echo $values | cut -d" " -f5`
|
|---|
| 101 | part=`echo $values | cut -d" " -f6`
|
|---|
| 102 | refl=`echo $values | cut -d" " -f7`
|
|---|
| 103 | cors=`echo $values | cut -d" " -f8`
|
|---|
| 104 | cam=`echo $values | cut -d" " -f9`
|
|---|
| 105 | view=`echo $values | cut -d" " -f10`
|
|---|
| 106 | query1=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstrun\" "
|
|---|
| 107 | query2=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstrun\" "
|
|---|
| 108 | check1=`mysql -ss -u $user --password=$pw --host=vela $db -e " $query1 "`
|
|---|
| 109 | check2=`mysql -ss -u $user --password=$pw --host=vela $db -e " $query2 "`
|
|---|
| 110 | insert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstrun\", fSequenceFileWritten=Now() "
|
|---|
| 111 | insert2=" insert MCSequences set fSequenceFirst=\"$firstrun\", fRunStart=\"$date\", fZBin=\"$zbin\", fSpectrumKEY=\"$spec\", fPSFKEY=\"$psf\", fAmplFadcKEY=\"$amplfadc\", fAtmosphericModelKEY=\"$atmo\", fObservationModeKEY=\"$obs\", fMCParticleKEY=\"$part\", fReflectorVersionKEY=\"$refl\", fCorsikaVersionKEY=\"$cors\", fCameraVersionKEY=\"$cam\", fViewConeAngleOKEY=\"$view\" "
|
|---|
| 112 | update2=" update MCSequences set fRunStart=\"$date\", fZBin=\"$zbin\", fSpectrumKEY=\"$spec\", fPSFKEY=\"$psf\", fAmplFadcKEY=\"$amplfadc\", fAtmosphericModelKEY=\"$atmo\", fObservationModeKEY=\"$obs\", fMCParticleKEY=\"$part\", fReflectorVersionKEY=\"$refl\", fCorsikaVersionKEY=\"$cors\", fCameraVersionKEY=\"$cam\", fViewConeAngleOKEY=\"$view\" where fSequenceFirst=\"$firstrun\" "
|
|---|
| 113 | if [ "$check1" == "" ]
|
|---|
| 114 | then
|
|---|
| 115 | mysql -ss -u $user --password=$pw --host=vela $db -e " $insert1 "
|
|---|
| 116 | fi
|
|---|
| 117 | if [ "$check2" == "" ]
|
|---|
| 118 | then
|
|---|
| 119 | mysql -ss -u $user --password=$pw --host=vela $db -e " $insert2 "
|
|---|
| 120 | else
|
|---|
| 121 | mysql -ss -u $user --password=$pw --host=vela $db -e " $update2 "
|
|---|
| 122 | fi
|
|---|
| 123 |
|
|---|
| 124 | no=`echo $firstrun | cut -c 0-4`
|
|---|
| 125 | sequpath=$mcsequpath/$no
|
|---|
| 126 | makedir $sequpath >> $scriptlog 2>&1
|
|---|
| 127 | sequfile=$sequpath/sequence$firstrun.txt
|
|---|
| 128 | echo "writing sequfile "$sequfile >> $scriptlog 2>&1
|
|---|
| 129 | printprocesslog "INFO writing sequencefile $sequfile"
|
|---|
| 130 |
|
|---|
| 131 | echo "Sequence: $firstrun" >| $sequfile
|
|---|
| 132 | echo "Night: $date" >> $sequfile
|
|---|
| 133 | echo "Epoch: $epoch" >> $sequfile
|
|---|
| 134 | echo "Mode: $mode" >> $sequfile
|
|---|
| 135 | echo "" >> $sequfile
|
|---|
| 136 | echo "CalRuns: $calrun" >> $sequfile
|
|---|
| 137 | echo "PedRuns: $pedrun" >> $sequfile
|
|---|
| 138 | echo "DatRuns: $datruns" >> $sequfile
|
|---|
| 139 | echo "" >> $sequfile
|
|---|
| 140 | echo "MonteCarlo: Yes" >> $sequfile
|
|---|
| 141 | echo "" >> $sequfile
|
|---|
| 142 | fi
|
|---|
| 143 | done
|
|---|
| 144 | done
|
|---|
| 145 | done
|
|---|
| 146 |
|
|---|
| 147 | finish >> $scriptlog 2>&1
|
|---|
| 148 |
|
|---|