source: trunk/MagicSoft/Mars/datacenter/scripts/linkmc@ 7982

Last change on this file since 7982 was 7982, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.5 KB
Line 
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
44source `dirname $0`/sourcefile
45printprocesslog "INFO starting $0"
46program=linkmc
47
48set -C
49
50scriptlog=$runlogpath/$progam-`date +%F`.log
51date >> $scriptlog 2>&1
52
53# check if script is already running
54lockfile=$lockpath/lock-$program.txt
55checklock >> $scriptlog 2>&1
56
57mccampath=$mcpath/camera
58next=$mcrawpath/.next #in .next the next runno is stored
59processed=$mcrawpath/.processed #in .processed the linked files are stored
60readme=$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
63if ! ls $next >> $scriptlog 2>&1
64then
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
68fi
69
70
71# observation modes
72modes=("" "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
77date >| $readme 2>&1
78echo "" >> $readme 2>&1
79echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
80echo "--------------------------------------------------------------" >> $readme 2>&1
81echo "" >> $readme 2>&1
82echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
83echo "YYYY represents 19zbin" >> $readme 2>&1
84echo "MM represents the mode" >> $readme 2>&1
85echo "DD represents the psf in mm" >> $readme 2>&1
86echo "" >> $readme 2>&1
87echo "explanation of the modes" >> $readme 2>&1
88echo "modes: "${modes[@]} >> $readme 2>&1
89echo "" >> $readme 2>&1
90for (( i=1 ; i <= 12 ; i++ ))
91do
92 if [ "${modes[i]}" != "" ]
93 then
94 numofmode=`printf %02d $i`
95 echo "mode (MM) = $numofmode means ${modes[$i]}" >> $readme 2>&1
96 fi
97done
98echo "" >> $readme 2>&1
99echo "the mode is indicating " >> $readme 2>&1
100echo " - the particle type" >> $readme 2>&1
101echo " - wobble/nowobble" >> $readme 2>&1
102echo " - HE" >> $readme 2>&1
103echo " - w+/w0 (as +/0)" >> $readme 2>&1
104echo " a combination of w0 and wobble means 'fake wobble'" >> $readme 2>&1
105echo " (normal mc shifted by 0.4 deg -> abberation not taken into account)" >> $readme 2>&1
106echo "" >> $readme 2>&1
107
108
109#get runnumber
110runno=`cat $next`
111
112#get files, which have to be linked
113camfiles=`find $mccampath -type f | grep -v Cal_and_Ped`
114
115printprocesslog "INFO linking new camerafiles starting with runno $runno"
116for camfile in ${camfiles[@]}
117do
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# workaround due to 5digit runnumber for data with runnumber < 35487
128 no2=`printf %05d $runno`
129 zbin=`echo $file | cut -d_ -f2 | cut -c 5-6` #zbin from filename
130 zbin=`printf %02d $zbin` #2digit
131 wobble=`echo $file | cut -d_ -f6 | cut -c 2` #mode from filename
132 particle=`echo $file | cut -d_ -f1` #particle type from filename
133 psf=`echo $camfile | cut -d/ -f5 | cut -c 6,8` #psf from path
134
135 particledir=`echo $camfile | cut -d/ -f4` #particletype from path
136 wobbledir=`echo $camfile | cut -d/ -f6` #mode from path
137
138 #build mode name
139 testmode=$particle$wobbledir$wobble
140
141 #get mode extension for filename
142 case $wobble in
143 0) wobblemode="";;
144 +) wobblemode="W1";;
145 -) wobblemode="W2";;
146 *) echo "couldn't find any indication for mode (wobble)" >> $scriptlog 2>&1
147 ;;
148 esac
149
150 #get no of mode from array $modes
151 for (( i=1 ; i <= 12 ; i++ ))
152 do
153 if [ "${modes[$i]}" == "$testmode" ]
154 then
155 totalmode=$i
156 break
157 fi
158 done
159
160 totalmode=`printf %02d $totalmode` #2 digits
161
162 project=${particle}${zbin}${wobblemode} #build project name
163 #create new filename
164 newfile="$mcrawpath/19$zbin/$totalmode/$psf/19${zbin}${totalmode}${psf}_${no2}_D_${project}_E.root"
165 newdir=`dirname $newfile`
166 makedir $newdir >> $scriptlog 2>&1
167
168 runno=`expr $runno + 1` #next runnumber
169 echo $runno >| $next
170
171 #link file
172 ln -sv $camfile $newfile >> $scriptlog 2>&1
173 #add filename to processed file
174 echo $camfile >> $processed
175
176done
177
178printprocesslog "INFO linking cal and ped files"
179echo "linking cal and ped file" >> $scriptlog 2>&1
180#get files
181pedfile=`find $mccampath/Cal_and_Ped -name *_P_*.root`
182calfile=`find $mccampath/Cal_and_Ped -name *_C_*.root`
183echo "calfile"$calfile >> $scriptlog 2>&1
184echo "pedfile"$pedfile >> $scriptlog 2>&1
185#check number of files
186numfiles=`echo $pedfile $calfile | wc -w`
187if [ "$numfiles" != "2" ]
188then
189 "too many files in the directory $mccampath/Cal_and_Ped -> exit" >> $scriptlog 2>&1
190 printprocesslog "ERROR too many ped and cal files found in $mccampath/Cal_and_Ped"
191 finish >> $scriptlog 2>&1
192fi
193
194#get all directories in the linked structure
195dirs=`find $mcrawpath -type d`
196
197for dir in ${dirs[@]}
198do
199 #continue, if directory has already linked C and P run
200 cont=`ls $dir/*_0000[12]_[CP]_MonteCarlo_E.root 2>/dev/null | wc -w`
201 if [ "$cont" == "2" ] >> $scriptlog 2>&1
202 then
203 continue
204 fi
205
206 #continue, if directory is not at the lowest level of the structure
207 cont=`echo $dir | cut -d/ -f6`
208 if [ "$cont" == "" ]
209 then
210 continue
211 fi
212
213 #get date for filename from directory name
214 date=`echo $dir | cut -c 22-25,27,28,30,31`
215
216 #create new filenames and link files
217# workaround due to 5digit runnumber for data with runnumber < 35487
218# newcalfile="${dir}/${date}_00000002_C_MonteCarlo_E.root"
219 newcalfile="${dir}/${date}_00002_C_MonteCarlo_E.root"
220 ln -sv $calfile $newcalfile >> $scriptlog 2>&1
221# workaround due to 5digit runnumber for data with runnumber < 35487
222# newpedfile="${dir}/${date}_00000001_P_MonteCarlo_E.root"
223 newpedfile="${dir}/${date}_00001_P_MonteCarlo_E.root"
224 ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
225done
226
227finish >> $scriptlog 2>&1
228
Note: See TracBrowser for help on using the repository browser.