source: tags/Mars-V1.1/datacenter/scripts/linkmc

Last change on this file was 8433, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.2 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 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
174done
175
176printprocesslog "INFO linking cal and ped files"
177echo "linking cal and ped file" >> $scriptlog 2>&1
178#get files
179pedfile=`find $mccampath/Cal_and_Ped -name *_P_*.root`
180calfile=`find $mccampath/Cal_and_Ped -name *_C_*.root`
181echo "calfile"$calfile >> $scriptlog 2>&1
182echo "pedfile"$pedfile >> $scriptlog 2>&1
183#check number of files
184numfiles=`echo $pedfile $calfile | wc -w`
185if [ "$numfiles" != "2" ]
186then
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
190fi
191
192#get all directories in the linked structure
193dirs=`find $mcrawpath -type d`
194
195for dir in ${dirs[@]}
196do
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
219done
220
221finish >> $scriptlog 2>&1
222
Note: See TracBrowser for help on using the repository browser.