5 echo "$0 -i <result> -j <file2> -o <result>"
9 function addToPartialResult {
10 IN1=$2 #merged file for previous jobs
12 RESULT=$6 #output merged file
14 test -f ${IN1} && test -f ${IN2} || usage
18 # check if all 3 text files have the same number of lines
19 nblines=`cat ${IN1} | wc -l`
20 nb2=`cat ${IN2} | wc -l`
21 nb3=`cat ${RESULT} | wc -l`
23 if [ $nblines -ne $nb2 ] || [ $nblines -ne $nb3 ]; then
24 echo "Files does not have the same size"
28 # Find the number of primaries for this job (the same for all line and different of 0)
29 # Get the number of primaries from edep and square_edep to determine the std.
31 for i in $(seq 2 $nblines); do
33 file2=`sed -n "${i}p" < ${IN2}`
35 edep2=$(echo ${file2} | cut -f3 -d' ')
36 stdEdep2=$(echo ${file2} | cut -f4 -d' ')
37 sqEdep2=$(echo ${file2} | cut -f5 -d' ')
38 nbPrimary=$(python <<EOP
39 if ($edep2 == 0 or $sqEdep2 == 0):
42 temp=pow($edep2,2)*(pow($stdEdep2,2)-1)/(pow($stdEdep2*$edep2,2)-$sqEdep2)
43 print(int(round(temp)))
46 if [ $nbPrimary -ne 0 ]; then
50 dose2=$(echo ${file2} | cut -f6 -d' ')
51 stdDose2=$(echo ${file2} | cut -f7 -d' ')
52 sqDose2=$(echo ${file2} | cut -f8 -d' ')
53 nbPrimary=$(python <<EOP
54 if ($dose2 == 0 or $sqDose2 == 0):
57 temp=pow($dose2,2)*(pow($stdDose2,2)-1)/(pow($stdDose2*$dose2,2)-$sqDose2)
58 print(int(round(temp)))
61 if [ $nbPrimary -ne 0 ]; then
66 #Copy the 1st line in output
67 line1=`sed -n "1p" < ${RESULT}`
68 echo "${line1}" >> ${TMP}
69 # for all lines (except the 1st), split according tab
70 # sum the some elements (dose, edep) ...
71 for i in $(seq 2 $nblines); do
73 file1=`sed -n "${i}p" < ${IN1}`
74 file2=`sed -n "${i}p" < ${IN2}`
75 file3=`sed -n "${i}p" < ${RESULT}`
77 # sum edep: get the 2 values, sum them and replace it in the file3
78 # The /#./0. is important to add 0 for decimal value between 0 and 1
79 edep1=$(echo ${file1} | cut -f3 -d' ')
80 edep2=$(echo ${file2} | cut -f3 -d' ')
81 edep3=$(python -c "print($edep1+$edep2)")
83 file3=$(echo $file3 |awk -v r=${edep3} '{$3=r}1')
85 # sum square_edep: get the 2 values, sum them and replace it in the file3
86 sqEdep1=$(echo ${file1} | cut -f5 -d' ')
87 sqEdep2=$(echo ${file2} | cut -f5 -d' ')
88 sqEdep3=$(python -c "print($sqEdep1+$sqEdep2)")
89 sqEdep3=${sqEdep3/#./0.}
90 file3=$(echo $file3 |awk -v r=${sqEdep3} '{$5=r}1')
92 # Get the number of primaries from edep and square_edep to determine the std.
93 # Sum the number of primaries with the latter ones
94 nbPrimaryEdep1=$(echo ${file1} | cut -f4 -d' ')
95 nbPrimaryEdep3=$(python <<EOP
96 print($nbPrimary+$nbPrimaryEdep1)
99 nbPrimaryEdep3=${nbPrimaryEdep3/#./0.}
100 file3=$(echo $file3 |awk -v r=${nbPrimaryEdep3} '{$4=r}1')
102 # sum dose: get the 2 values, sum them and replace it in the file3
103 dose1=$(echo ${file1} | cut -f6 -d' ')
104 dose2=$(echo ${file2} | cut -f6 -d' ')
105 dose3=$(python -c "print($dose1+$dose2)")
107 file3=$(echo $file3 |awk -v r=${dose3} '{$6=r}1')
109 # sum square_dose: get the 2 values, sum them and replace it in the file3
110 sqDose1=$(echo ${file1} | cut -f8 -d' ')
111 sqDose2=$(echo ${file2} | cut -f8 -d' ')
112 sqDose3=$(python -c "print($sqDose1+$sqDose2)")
113 sqDose3=${sqDose3/#./0.}
114 file3=$(echo $file3 |awk -v r=${sqDose3} '{$8=r}1')
116 # Get the number of primaries from dose and square_dose to determine the std.
117 # Sum the number of primaries with the latter ones
118 nbPrimaryDose1=$(echo ${file1} | cut -f7 -d' ')
119 stdDose2=$(echo ${file2} | cut -f7 -d' ')
120 nbPrimaryDose3=$(python <<EOP
121 print($nbPrimary+$nbPrimaryDose1)
124 nbPrimaryDose3=${nbPrimaryDose3/#./0.}
125 file3=$(echo $file3 |awk -v r=${nbPrimaryDose3} '{$7=r}1')
127 # sum n_hits: get the 2 values, sum them and replace it in the file3
128 hit1=$(echo ${file1} | cut -f9 -d' ')
129 hit2=$(echo ${file2} | cut -f9 -d' ')
130 hit3=$(python -c "print($hit1+$hit2)")
131 file3=$(echo $file3 |awk -v r=${hit3} '{$9=r}1')
133 # sum n_event_hits: get the 2 values, sum them and replace it in the file3
134 event1=$(echo ${file1} | cut -f10 -d' ')
135 event2=$(echo ${file2} | cut -f10 -d' ')
136 event3=$(python -c "print($event1+$event2)")
137 file3=$(echo $file3 |awk -v r=${event3} '{$10=r}1')
140 echo "${file3}" >> ${TMP}
142 mv -f ${TMP} ${RESULT}
145 function copyFirstPartialResult {
151 # check if all 2 text files have the same number of lines
152 nblines=`cat ${IN1} | wc -l`
153 nb3=`cat ${RESULT} | wc -l`
155 if [ $nblines -ne $nb3 ]; then
156 echo "Files does not have the same size"
159 # Find the number of primaries for this job (the same for all line and different of 0)
160 # Get the number of primaries from edep and square_edep to determine the std.
162 for i in $(seq 2 $nblines); do
164 file2=`sed -n "${i}p" < ${IN1}`
166 edep2=$(echo ${file2} | cut -f3 -d' ')
167 stdEdep2=$(echo ${file2} | cut -f4 -d' ')
168 sqEdep2=$(echo ${file2} | cut -f5 -d' ')
169 nbPrimary=$(python <<EOP
170 if ($edep2 == 0 or $sqEdep2 == 0):
173 temp=pow($edep2,2)*(pow($stdEdep2,2)-1)/(pow($stdEdep2*$edep2,2)-$sqEdep2)
174 print(int(round(temp)))
177 if [ $nbPrimary -ne 0 ]; then
181 dose2=$(echo ${file2} | cut -f6 -d' ')
182 stdDose2=$(echo ${file2} | cut -f7 -d' ')
183 sqDose2=$(echo ${file2} | cut -f8 -d' ')
184 nbPrimary=$(python <<EOP
185 if ($dose2 == 0 or $sqDose2 == 0):
188 temp=pow($dose2,2)*(pow($stdDose2,2)-1)/(pow($stdDose2*$dose2,2)-$sqDose2)
189 print(int(round(temp)))
192 if [ $nbPrimary -ne 0 ]; then
197 #Copy the 1st line in output
198 line1=`sed -n "1p" < ${RESULT}`
199 echo "${line1}" >> ${TMP}
200 # for all lines (except the 1st), split according tab
201 # write the number of primaries
202 for i in $(seq 2 $nblines); do
204 file3=`sed -n "${i}p" < ${RESULT}`
206 file3=$(echo $file3 |awk -v r=${nbPrimary} '{$4=r}1')
207 file3=$(echo $file3 |awk -v r=${nbPrimary} '{$7=r}1')
210 echo "${file3}" >> ${TMP}
212 mv -f ${TMP} ${RESULT}
215 function divideUncertaintyResult {
221 # check if all 2 text files have the same number of lines
222 nblines=`cat ${IN1} | wc -l`
223 nb3=`cat ${RESULT} | wc -l`
225 if [ $nblines -ne $nb3 ]; then
226 echo "Files does not have the same size"
230 #Copy the 1st line in output
231 line1=`sed -n "1p" < ${RESULT}`
232 echo "${line1}" >> ${TMP}
233 # for all lines (except the 1st), split according tab
234 # sum the some elements (dose, edep) ...
235 for i in $(seq 2 $nblines); do
237 file1=`sed -n "${i}p" < ${IN1}`
238 file3=`sed -n "${i}p" < ${RESULT}`
240 # Divide uncertainty and replace it in the file3
241 edep1=$(echo ${file1} | cut -f3 -d' ')
242 nbPrimaryEdep1=$(echo ${file1} | cut -f4 -d' ')
243 sqEdep1=$(echo ${file1} | cut -f5 -d' ')
244 stdEdep3=$(python <<EOP
246 if ($edep1 == 0 or $sqEdep1 == 0):
249 temp=math.sqrt(($sqEdep1/$nbPrimaryEdep1-pow($edep1/$nbPrimaryEdep1, 2))/($nbPrimaryEdep1-1))/($edep1/$nbPrimaryEdep1)
253 stdEdep3=${stdEdep3/#./0.}
254 file3=$(echo $file3 |awk -v r=${stdEdep3} '{$4=r}1')
256 # Divide uncertainty and replace it in the file3
257 dose1=$(echo ${file1} | cut -f6 -d' ')
258 nbPrimaryDose1=$(echo ${file1} | cut -f7 -d' ')
259 sqDose1=$(echo ${file1} | cut -f8 -d' ')
260 stdDose3=$(python <<EOP
262 if ($edep1 == 0 or $sqEdep1 == 0):
265 temp=math.sqrt(($sqDose1/$nbPrimaryDose1-pow($dose1/$nbPrimaryDose1, 2))/($nbPrimaryDose1-1))/($dose1/$nbPrimaryDose1)
269 stdDose3=${stdDose3/#./0.}
270 file3=$(echo $file3 |awk -v r=${stdDose3} '{$7=r}1')
273 echo "${file3}" >> ${TMP}
275 mv -f ${TMP} ${RESULT}