| 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  10/2006 <mailto:dorner@astro.uni-wuerzburg.de> | 
|---|
| 21 | # | 
|---|
| 22 | #   Copyright: MAGIC Software Development, 2000-2006 | 
|---|
| 23 | # | 
|---|
| 24 | # | 
|---|
| 25 | # ======================================================================== | 
|---|
| 26 | # | 
|---|
| 27 | ############################################################################## | 
|---|
| 28 | # | 
|---|
| 29 | # This script runs callisto with the -movie option and the corresponding | 
|---|
| 30 | # rc files for a given sequence. | 
|---|
| 31 | # The following movies are produced: | 
|---|
| 32 | # - movieSequenceNumber[mc]-withoutcut.mpg (all events) | 
|---|
| 33 | # - movieSequenceNumber[mc]-qualcut.mpg    (events after quality cuts) | 
|---|
| 34 | # - movieSequenceNumber[mc]-areacut.mpg    (events after area cut) | 
|---|
| 35 | # - movieSequenceNumber[mc]-thetacut.mpg   (events after theta^2 cut) | 
|---|
| 36 | # | 
|---|
| 37 | # If no outpath is given, the movies are stored in the directory movies. | 
|---|
| 38 | # | 
|---|
| 39 | # The script has to be executed in the Mars directory. | 
|---|
| 40 | # | 
|---|
| 41 | ############################################################################## | 
|---|
| 42 |  | 
|---|
| 43 | #to be set by the user (if you don't use the command-line options) | 
|---|
| 44 | #give either sequence number or sequence file (including path) | 
|---|
| 45 | sequence= | 
|---|
| 46 | sequfile="" | 
|---|
| 47 |  | 
|---|
| 48 | #path of your output directory | 
|---|
| 49 | outpath=movies | 
|---|
| 50 | #define values for callisto.rc files | 
|---|
| 51 | TargetLength=5 | 
|---|
| 52 | NumEvents=500 | 
|---|
| 53 | Threshold=3 | 
|---|
| 54 |  | 
|---|
| 55 | function usage() | 
|---|
| 56 | { | 
|---|
| 57 | echo "Usage: $0 [options]" | 
|---|
| 58 | echo "options:" | 
|---|
| 59 | echo -n "  --sequ sequence#        " | 
|---|
| 60 | echo " giving number of sequence which shall be processed " | 
|---|
| 61 | echo -n "  --out outpath           " | 
|---|
| 62 | echo " giving the path where all outputfiles are stored " | 
|---|
| 63 | echo -n "  --target-length seconds " | 
|---|
| 64 | echo " giving the length of one event in seconds " | 
|---|
| 65 | echo -n "  --num-events #events    " | 
|---|
| 66 | echo " giving the number of events in the movie " | 
|---|
| 67 | echo -n "  -wobble                 " | 
|---|
| 68 | echo " give this option for processing a wobble sequence " | 
|---|
| 69 | echo -n "  -mc                     " | 
|---|
| 70 | echo " give this option for processing a montecarlo sequence " | 
|---|
| 71 | echo "" | 
|---|
| 72 | echo "Remarks: " | 
|---|
| 73 | echo    " - you can set the needed variables also in the script " | 
|---|
| 74 | echo    " - you have to set the outpath and either the sequence number or the sequence file" | 
|---|
| 75 | echo    "    (if both is set, the sequence given by the sequencefile is processed)" | 
|---|
| 76 | echo    " - you have to execute the script from your mars directory" | 
|---|
| 77 | echo    " - some options for the movie can be set in the script" | 
|---|
| 78 | echo    " - if you don't set the outpath, the default 'movies' is used" | 
|---|
| 79 | echo "" | 
|---|
| 80 | exit | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | alias mymysql='mysql -u MAGIC --password=d99swMT! --host=vela MyMagic -s -e' | 
|---|
| 84 |  | 
|---|
| 85 |  | 
|---|
| 86 | while [ "$1" ] | 
|---|
| 87 | do | 
|---|
| 88 | case $1 in | 
|---|
| 89 | --sequ)  shift | 
|---|
| 90 | sequence=$1 | 
|---|
| 91 | ;; | 
|---|
| 92 | --out)  shift | 
|---|
| 93 | outpath=$1 | 
|---|
| 94 | ;; | 
|---|
| 95 | --target-length)  shift | 
|---|
| 96 | TargetLength=$1 | 
|---|
| 97 | ;; | 
|---|
| 98 | --num-events)  shift | 
|---|
| 99 | NumEvents=$1 | 
|---|
| 100 | ;; | 
|---|
| 101 | -wobble)  wobble='yes' | 
|---|
| 102 | ;; | 
|---|
| 103 | -mc)  mc='mc' | 
|---|
| 104 | ;; | 
|---|
| 105 | -h)  usage | 
|---|
| 106 | ;; | 
|---|
| 107 | *)      echo "unknown option $1 " | 
|---|
| 108 | usage | 
|---|
| 109 | exit | 
|---|
| 110 | ;; | 
|---|
| 111 | esac | 
|---|
| 112 | shift | 
|---|
| 113 | done | 
|---|
| 114 |  | 
|---|
| 115 | if [ "$sequence" = "" ] | 
|---|
| 116 | then | 
|---|
| 117 | echo "WARNING sequ has not been set" | 
|---|
| 118 | echo "" | 
|---|
| 119 | usage | 
|---|
| 120 | fi | 
|---|
| 121 |  | 
|---|
| 122 | # get variables | 
|---|
| 123 | if ! n8=`printf %08d $sequence` | 
|---|
| 124 | then | 
|---|
| 125 | echo "your sequence number is not valid" | 
|---|
| 126 | usage | 
|---|
| 127 | fi | 
|---|
| 128 | no=`echo $n8 | cut -c 1-4` | 
|---|
| 129 | if [ "$mc" == "mc" ] | 
|---|
| 130 | then | 
|---|
| 131 | sequfile="/magic/montecarlo/sequences/"$no"/sequence$n8.txt" | 
|---|
| 132 | calpath="/magic/montecarlo/callisto/"$no"/"$n8 | 
|---|
| 133 | else | 
|---|
| 134 | sequfile="/magic/sequences/"$no"/sequence$n8.txt" | 
|---|
| 135 | calpath="/magic/data/callisto/"$no"/"$n8 | 
|---|
| 136 | fi | 
|---|
| 137 | outpath2=$outpath"/temp" | 
|---|
| 138 | datasetfile=$outpath2"/dataset"$n8".txt" | 
|---|
| 139 | ganymedfile=$outpath2"/ganymed"$n8".root" | 
|---|
| 140 | ganymedsumfile=$outpath2"/ganymed"$n8"-summary.root" | 
|---|
| 141 | mkdir -pv $outpath2 | 
|---|
| 142 |  | 
|---|
| 143 | if ! ls $sequfile >/dev/null | 
|---|
| 144 | then | 
|---|
| 145 | echo $sequfile" doesn't exist." | 
|---|
| 146 | usage | 
|---|
| 147 | fi | 
|---|
| 148 |  | 
|---|
| 149 | echo "" | 
|---|
| 150 | echo "Variables and paths from your input: " | 
|---|
| 151 | echo " outpath:      "$outpath | 
|---|
| 152 | echo " sequence:     "$sequence | 
|---|
| 153 | echo " sequfile:     "$sequfile | 
|---|
| 154 | echo " datasetfile:  "$datasetfile | 
|---|
| 155 | echo " ganymedfiles: "$ganymedfile", "$ganymedsumfile | 
|---|
| 156 | echo " inputpaths:   "$calpath | 
|---|
| 157 | echo "" | 
|---|
| 158 |  | 
|---|
| 159 |  | 
|---|
| 160 | # write datasetfile | 
|---|
| 161 | echo "AnalysisNumber: "$sequence > $datasetfile | 
|---|
| 162 | echo "" >> $datasetfile | 
|---|
| 163 | echo "SequencesOn: "$sequence >> $datasetfile | 
|---|
| 164 | echo "" >> $datasetfile | 
|---|
| 165 | if [ "$mc" == "mc" ] | 
|---|
| 166 | then | 
|---|
| 167 | echo "MonteCarlo: Yes " >> $datasetfile | 
|---|
| 168 | else | 
|---|
| 169 | # get source name | 
|---|
| 170 | query="SELECT fSourceName FROM Source LEFT JOIN Sequences ON Sequences.fSourceKEY=Source.fSourceKEY WHERE fSequenceFirst="$sequence | 
|---|
| 171 | source=`mymysql "$query"` | 
|---|
| 172 | echo "SourceName: "$source >> $datasetfile | 
|---|
| 173 | echo "Catalog: /magic/datacenter/setup/magic_favorites_dc.edb" >> $datasetfile | 
|---|
| 174 | fi | 
|---|
| 175 | if [ "$wobble" == "yes" ] | 
|---|
| 176 | then | 
|---|
| 177 | echo "WobbleMode: On " >> $datasetfile | 
|---|
| 178 | fi | 
|---|
| 179 | echo "" >> $datasetfile | 
|---|
| 180 |  | 
|---|
| 181 |  | 
|---|
| 182 | # choose callisto.rc | 
|---|
| 183 | if [ $sequence -gt 200000 ] | 
|---|
| 184 | then | 
|---|
| 185 | rc="callisto_mux.rc" | 
|---|
| 186 | else | 
|---|
| 187 | rc="callisto.rc" | 
|---|
| 188 | fi | 
|---|
| 189 |  | 
|---|
| 190 | # write callisto.rc files | 
|---|
| 191 | names=( "withoutcut" "qualcut" "areacut" "thetacut" ) | 
|---|
| 192 | for (( i=0 ; i < 4 ; i++ )) | 
|---|
| 193 | do | 
|---|
| 194 | calrc=$outpath2"/callisto_"$n8$mc"-"${names[$i]}".rc" | 
|---|
| 195 | echo "creating "$calrc | 
|---|
| 196 | grep -v MMoveWrite $rc > $calrc | 
|---|
| 197 | echo "MMovieWrite.FileName: "$outpath"/movie"$n8$mc"-"${names[$i]}".mpg" >> $calrc | 
|---|
| 198 | echo "MMovieWrite.TargetLength: "$TargetLength >> $calrc | 
|---|
| 199 | echo "MMovieWrite.NumEvents: "$NumEvents >> $calrc | 
|---|
| 200 | echo "MMovieWrite.Threshold: "$Threshold >> $calrc | 
|---|
| 201 | if [ $i -eq 1 ] | 
|---|
| 202 | then | 
|---|
| 203 | echo "MFEvtNumber.FileName: "$ganymedsumfile >> $calrc | 
|---|
| 204 | fi | 
|---|
| 205 | if [ $i -gt 1 ] | 
|---|
| 206 | then | 
|---|
| 207 | echo "MFEvtNumber.FileName: "$ganymedfile >> $calrc | 
|---|
| 208 | fi | 
|---|
| 209 | if [ $i -gt 2 ] | 
|---|
| 210 | then | 
|---|
| 211 | echo "MFEvtNumber.Selector: ThetaSquared.fVal<0.04 && DataType.fVal>0.5" >> $calrc | 
|---|
| 212 | fi | 
|---|
| 213 | done | 
|---|
| 214 |  | 
|---|
| 215 | # define options for callisto | 
|---|
| 216 | opts=" -f -v5 -b --movie " | 
|---|
| 217 | if [ "$mc" == "mc" ] | 
|---|
| 218 | then | 
|---|
| 219 | opts=$opts" -mc " | 
|---|
| 220 | fi | 
|---|
| 221 | opts=$opts" -y --iny=$calpath $sequence " | 
|---|
| 222 |  | 
|---|
| 223 | # produce movie without cuts | 
|---|
| 224 | command="./callisto $opts --config=$outpath2/callisto_$n8$mc-${names[0]}.rc " | 
|---|
| 225 | echo "submitting: "$command | 
|---|
| 226 | condor_run $command & | 
|---|
| 227 |  | 
|---|
| 228 | # run ganymed and produce summary file | 
|---|
| 229 | gopts="-v5 -f -b " | 
|---|
| 230 | if [ "$wobble" == "yes" ] | 
|---|
| 231 | then | 
|---|
| 232 | gopts=$gopts" --config=ganymed_wobble.rc " | 
|---|
| 233 | fi | 
|---|
| 234 | command="./ganymed $gopts --sum --out=$outpath2 $datasetfile" | 
|---|
| 235 | echo "executing: "$command | 
|---|
| 236 | if ! $command | 
|---|
| 237 | then | 
|---|
| 238 | echo "execution failed." | 
|---|
| 239 | exit | 
|---|
| 240 | fi | 
|---|
| 241 |  | 
|---|
| 242 | # produce movies with cuts | 
|---|
| 243 | for (( i=1 ; i < 4 ; i++ )) | 
|---|
| 244 | do | 
|---|
| 245 | command="./callisto $opts --config=$outpath2/callisto_$n8$mc-${names[$i]}.rc " | 
|---|
| 246 | echo "submitting: "$command | 
|---|
| 247 | condor_run $command & | 
|---|
| 248 | done | 
|---|
| 249 |  | 
|---|