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-2006
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This script is linking the montecarlo files from the original structure
|
---|
28 | # to a structure from which the files can be processed more easily with the
|
---|
29 | # automatic analysis.
|
---|
30 | # This script is not yet running automatically.
|
---|
31 | #
|
---|
32 | # original structure:
|
---|
33 | # /magic/montecarlo/camera/
|
---|
34 | #
|
---|
35 | # new structure:
|
---|
36 | # /magic/montecarlo/rawfiles/YYYY/MM/DD/file.root
|
---|
37 | # more explanation concerning the file structure can be found in the file
|
---|
38 | # /magic/montecarlo/rawfiles/README.txt
|
---|
39 | #
|
---|
40 | # First the data files are linked and then in each new directory also the
|
---|
41 | # pedestal and calibration file is linked.
|
---|
42 | #
|
---|
43 |
|
---|
44 | source `dirname $0`/sourcefile
|
---|
45 | printprocesslog "INFO starting $0"
|
---|
46 | program=linkmc
|
---|
47 |
|
---|
48 | set -C
|
---|
49 |
|
---|
50 | scriptlog=$runlogpath/$progam-`date +%F`.log
|
---|
51 | date >> $scriptlog 2>&1
|
---|
52 |
|
---|
53 | # check if script is already running
|
---|
54 | lockfile=$lockpath/lock-$program.txt
|
---|
55 | checklock >> $scriptlog 2>&1
|
---|
56 |
|
---|
57 | mccampath=$mcpath/camera
|
---|
58 | next=$mcrawpath/.next #in .next the next runno is stored
|
---|
59 | processed=$mcrawpath/.processed #in .processed the linked files are stored
|
---|
60 | readme=$mcrawpath/README.txt #file in which the information about the modes is redirected to have always an updated explanation
|
---|
61 |
|
---|
62 | # check if file with next runnumber is available
|
---|
63 | if ! ls $next >> $scriptlog 2>&1
|
---|
64 | then
|
---|
65 | echo "file $next not found -> no start-runno -> exit" >> $scriptlog 2>&1
|
---|
66 | printprocesslog "ERROR file $next (last runno) not found"
|
---|
67 | finish >> $scriptlog 2>&1
|
---|
68 | fi
|
---|
69 |
|
---|
70 |
|
---|
71 | # observation modes
|
---|
72 | modes=("" "Gammawobble+" "Gammanowobble0" "GammawobbleHE+" "GammanowobbleHE0" "Gammawobble0" "GammawobbleHE0" "Gammadiffuse0" "Protonnowobble0" )
|
---|
73 | #be carful:
|
---|
74 | # w- not yet foreseen in this script
|
---|
75 |
|
---|
76 | # print information and explanation of structure into README.txt
|
---|
77 | date >| $readme 2>&1
|
---|
78 | echo "" >> $readme 2>&1
|
---|
79 | echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
|
---|
80 | echo "--------------------------------------------------------------" >> $readme 2>&1
|
---|
81 | echo "" >> $readme 2>&1
|
---|
82 | echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
|
---|
83 | echo "YYYY represents 19zbin" >> $readme 2>&1
|
---|
84 | echo "MM represents the mode" >> $readme 2>&1
|
---|
85 | echo "DD represents the psf in mm" >> $readme 2>&1
|
---|
86 | echo "" >> $readme 2>&1
|
---|
87 | echo "explanation of the modes" >> $readme 2>&1
|
---|
88 | echo "modes: "${modes[@]} >> $readme 2>&1
|
---|
89 | echo "" >> $readme 2>&1
|
---|
90 | for (( i=1 ; i <= 12 ; i++ ))
|
---|
91 | do
|
---|
92 | if [ "${modes[i]}" != "" ]
|
---|
93 | then
|
---|
94 | numofmode=`printf %02d $i`
|
---|
95 | echo "mode (MM) = $numofmode means ${modes[$i]}" >> $readme 2>&1
|
---|
96 | fi
|
---|
97 | done
|
---|
98 | echo "" >> $readme 2>&1
|
---|
99 | echo "the mode is indicating " >> $readme 2>&1
|
---|
100 | echo " - the particle type" >> $readme 2>&1
|
---|
101 | echo " - wobble/nowobble" >> $readme 2>&1
|
---|
102 | echo " - HE" >> $readme 2>&1
|
---|
103 | echo " - w+/w0 (as +/0)" >> $readme 2>&1
|
---|
104 | echo " a combination of w0 and wobble means 'fake wobble'" >> $readme 2>&1
|
---|
105 | echo " (normal mc shifted by 0.4 deg -> abberation not taken into account)" >> $readme 2>&1
|
---|
106 | echo "" >> $readme 2>&1
|
---|
107 |
|
---|
108 |
|
---|
109 | #get runnumber
|
---|
110 | runno=`cat $next`
|
---|
111 |
|
---|
112 | #get files, which have to be linked
|
---|
113 | camfiles=`find $mccampath -type f | grep -v Cal_and_Ped`
|
---|
114 |
|
---|
115 | printprocesslog "INFO linking new camerafiles starting with runno $runno"
|
---|
116 | for camfile in ${camfiles[@]}
|
---|
117 | do
|
---|
118 | #continue, if file is already linked
|
---|
119 | if grep $camfile $processed >> $scriptlog 2>&1
|
---|
120 | then
|
---|
121 | continue
|
---|
122 | fi
|
---|
123 | printprocesslog "INFO linking $file"
|
---|
124 | file=`basename $camfile` #filename
|
---|
125 | no=`printf %08d $runno | cut -c 0-5` #first 5 digits of a 8digit runno -> for path
|
---|
126 | no2=`printf %08d $runno` #runno with 8 digits
|
---|
127 | zbin=`echo $file | cut -d_ -f2 | cut -c 5-6` #zbin from filename
|
---|
128 | zbin=`printf %02d $zbin` #2digit
|
---|
129 | wobble=`echo $file | cut -d_ -f6 | cut -c 2` #mode from filename
|
---|
130 | particle=`echo $file | cut -d_ -f1` #particle type from filename
|
---|
131 | psf=`echo $camfile | cut -d/ -f5 | cut -c 6,8` #psf from path
|
---|
132 |
|
---|
133 | particledir=`echo $camfile | cut -d/ -f4` #particletype from path
|
---|
134 | wobbledir=`echo $camfile | cut -d/ -f6` #mode from path
|
---|
135 |
|
---|
136 | #build mode name
|
---|
137 | testmode=$particle$wobbledir$wobble
|
---|
138 |
|
---|
139 | #get mode extension for filename
|
---|
140 | case $wobble in
|
---|
141 | 0) wobblemode="";;
|
---|
142 | +) wobblemode="W1";;
|
---|
143 | -) wobblemode="W2";;
|
---|
144 | *) echo "couldn't find any indication for mode (wobble)" >> $scriptlog 2>&1
|
---|
145 | ;;
|
---|
146 | esac
|
---|
147 |
|
---|
148 | #get no of mode from array $modes
|
---|
149 | for (( i=1 ; i <= 12 ; i++ ))
|
---|
150 | do
|
---|
151 | if [ "${modes[$i]}" == "$testmode" ]
|
---|
152 | then
|
---|
153 | totalmode=$i
|
---|
154 | break
|
---|
155 | fi
|
---|
156 | done
|
---|
157 |
|
---|
158 | totalmode=`printf %02d $totalmode` #2 digits
|
---|
159 |
|
---|
160 | project=${particle}${zbin}${wobblemode} #build project name
|
---|
161 | #create new filename
|
---|
162 | newfile="$mcrawpath/19$zbin/$totalmode/$psf/19${zbin}${totalmode}${psf}_${no2}_D_${project}_E.root"
|
---|
163 | newdir=`dirname $newfile`
|
---|
164 | makedir $newdir >> $scriptlog 2>&1
|
---|
165 |
|
---|
166 | runno=`expr $runno + 1` #next runnumber
|
---|
167 | echo $runno >| $next
|
---|
168 |
|
---|
169 | #link file
|
---|
170 | ln -sv $camfile $newfile >> $scriptlog 2>&1
|
---|
171 | #add filename to processed file
|
---|
172 | echo $camfile >> $processed
|
---|
173 |
|
---|
174 | done
|
---|
175 |
|
---|
176 | printprocesslog "INFO linking cal and ped files"
|
---|
177 | echo "linking cal and ped file" >> $scriptlog 2>&1
|
---|
178 | #get files
|
---|
179 | pedfile=`find $mccampath/Cal_and_Ped -name *_P_*.root`
|
---|
180 | calfile=`find $mccampath/Cal_and_Ped -name *_C_*.root`
|
---|
181 | echo "calfile"$calfile >> $scriptlog 2>&1
|
---|
182 | echo "pedfile"$pedfile >> $scriptlog 2>&1
|
---|
183 | #check number of files
|
---|
184 | numfiles=`echo $pedfile $calfile | wc -w`
|
---|
185 | if [ "$numfiles" != "2" ]
|
---|
186 | then
|
---|
187 | "too many files in the directory $mccampath/Cal_and_Ped -> exit" >> $scriptlog 2>&1
|
---|
188 | printprocesslog "ERROR too many ped and cal files found in $mccampath/Cal_and_Ped"
|
---|
189 | finish >> $scriptlog 2>&1
|
---|
190 | fi
|
---|
191 |
|
---|
192 | #get all directories in the linked structure
|
---|
193 | dirs=`find $mcrawpath -type d`
|
---|
194 |
|
---|
195 | for dir in ${dirs[@]}
|
---|
196 | do
|
---|
197 | #continue, if directory has already linked C and P run
|
---|
198 | cont=`ls $dir/*_0000[12]_[CP]_MonteCarlo_E.root 2>/dev/null | wc -w`
|
---|
199 | if [ "$cont" == "2" ] >> $scriptlog 2>&1
|
---|
200 | then
|
---|
201 | continue
|
---|
202 | fi
|
---|
203 |
|
---|
204 | #continue, if directory is not at the lowest level of the structure
|
---|
205 | cont=`echo $dir | cut -d/ -f6`
|
---|
206 | if [ "$cont" == "" ]
|
---|
207 | then
|
---|
208 | continue
|
---|
209 | fi
|
---|
210 |
|
---|
211 | #get date for filename from directory name
|
---|
212 | date=`echo $dir | cut -c 22-25,27,28,30,31`
|
---|
213 |
|
---|
214 | #create new filenames and link files
|
---|
215 | newcalfile="${dir}/${date}_00000002_C_MonteCarlo_E.root"
|
---|
216 | ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
217 | newpedfile="${dir}/${date}_00000001_P_MonteCarlo_E.root"
|
---|
218 | ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
219 | done
|
---|
220 |
|
---|
221 | finish >> $scriptlog 2>&1
|
---|
222 |
|
---|