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