2 ##########################################################################
6 # This file is part of rootpwa
8 # rootpwa is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # rootpwa is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
21 ##########################################################################
22 #-------------------------------------------------------------------------
23 # File and Version Information:
24 # $Rev:: $: revision of last commit
25 # $Author:: $: author of last commit
26 # $Date:: $: date of last commit
29 # calculates amplitudes for a single mass bin specified by
30 # (1-based) index MASS_BIN_INDEX
32 # runs locally as well as on a batch system
34 # job arguments may be passed via command line or environment
37 # a typical command line to run this script locally looks like this:
38 # for i in $(seq 1 50);\
39 # do calcAmplitudesForMassBin.sh ${i} &> ${ROOTPWA_LOGS_DIR}/calcAmplitudes.${i}.log;\
42 # uses ROOTPWA environment variables
50 # Boris Grube TUM (original author)
53 #-------------------------------------------------------------------------
56 # file layout parameters
57 # subdirectory names for amplitudes
61 # extensions of event data files; naming scheme is <mass bin><extension>
63 PS_FILE_EXT=.genbod.evt
65 PSACC_FILE_EXT=.acc.evt
68 #PSACC_FILE_EXT=.acc.root
69 # amplitude file format
73 INT_FILE_NAME=norm.int
74 #INT_FILE_NAME=norm.root
78 # if SGE is used as batch system, job arrays can be conveniently used
79 # to run this script; MASS_BIN_INDEX is set to SGE_TASK_ID
81 ##$ -l medium=TRUE,h_vmem=200M
82 # path for stdout files
83 ##$ -o /afs/e18.ph.tum.de/user/bgrube/compass/pwa/4PionMuoProdPwa/logs
84 # merge sterr into stdout
86 # send mail when job is aborted, rescheduled, or suspended
89 # enable path aliasing
91 # export all environment variables to job
95 echo ">>> info: called ${0} ${*}"
100 usage: $(basename ${0}) [OPTIONS]... [MASS
BIN INDEX]
102 creates amplitude and
integral files
for real data, phase-space MC,
103 and accepted phase-space MC in
mass bin directory given by 1-based
104 index [MASS
BIN INDEX] by running
'calcAmplitudes' and
'calcIntegrals'
107 -${KEY_PATTERN_OPT}
'<PATTERN>' glob pattern that defines
set of key files to be processed
108 -${MASS_BINS_DIR_OPT} <DIR> path to directory with
mass bins
109 -${PDG_TABLE_OPT} <
FILE> path to PDG table file
110 -${HELP_OPT} display
this help and
exit
114 if [[
"${#}" -eq 1 ]]
126 glob pattern that defines
set of key files ... -${KEY_PATTERN_OPT}
'${KEY_PATTERN}'
127 path to directory with
mass bins ............. -${MASS_BINS_DIR_OPT}
'${MASS_BINS_DIR}'
128 path to PDG table file ....................... -${PDG_TABLE_OPT}
'${PDG_TABLE}'
130 mass bin index ............................... ${MASS_BIN_INDEX}
135 function runCalcAmplitudes {
136 local _DT_FILE=
"${1}"
137 local _AMP_DIR=
"${2}"
138 local _NMB_OF_KEYS=$(eval ls -1 ${KEY_PATTERN} | wc -l)
139 # process all key files
140 declare -
i _COUNT_KEY=0
141 for _KEY_FILE in ${KEY_PATTERN}
143 local _KEY_NAME=$(basename ${_KEY_FILE})
144 local _AMP_FILE=${_AMP_DIR}/${_KEY_NAME/.key/${AMP_FILE_EXT}}
147 echo ">>> info: generating amplitudes for '${_KEY_NAME}' [${_COUNT_KEY}/${_NMB_OF_KEYS}]"
148 # don't overwrite existing files
149 if [[ -s
"${_AMP_FILE}" ]]
151 echo "??? warning: file '${_AMP_FILE}' already exists. skipping."
153 local _CMD=
"${ROOTPWA_BIN}/calcAmplitudes -k ${_KEY_FILE} -p ${PDG_TABLE} -o ${_AMP_FILE} ${_DT_FILE}"
162 local _AMP_DIR=
"${1}"
164 echo ">>> info: generating integrals for '${_AMP_DIR}'"
165 local _CURRENT_DIR=$(pwd)
166 # avoid problems with full path names in pwa2000
168 local _CMD=
"${ROOTPWA_BIN}/int *.amp > ${INT_FILE_NAME}" # works only with .amp and .
int files
175 function runCalcIntegrals {
176 local _AMP_DIR=
"${1}"
178 echo ">>> info: generating integrals for '${_AMP_DIR}'"
179 local _CMD=
"${ROOTPWA_BIN}/calcIntegrals -o ${_AMP_DIR}/${INT_FILE_NAME} ${_AMP_DIR}/*${AMP_FILE_EXT}"
185 function runPhaseSpaceGen {
186 local _NMB_EVENTS=50000
187 local _SEED=1234567890
188 local _PS_FILE=
"${1}"
189 local _MASS_BIN_NAME=$(basename
"${_PS_FILE}" "${PS_FILE_EXT}")
190 local _BIN_M_MIN=${_MASS_BIN_NAME%.*}
191 local _BIN_M_MAX=${_MASS_BIN_NAME#*.}
193 echo ">>> info: generating ${_NMB_EVENTS} phase space events for mass bin [${_BIN_M_MIN}, ${_BIN_M_MAX}] MeV/c^2"
194 local _CMD=
"root -b -q -l \"runPhaseSpaceGen.C(${_NMB_EVENTS}, \\\"${_PS_FILE}\\\", ${_BIN_M_MIN}, ${_BIN_M_MAX}, ${_SEED})\""
200 # take arguments either from command line, environment, or use default
201 # (in this order of priority)
204 MASS_BINS_DIR_OPT=
"m"
207 # use default values, if variables are not defined in environment
208 if [[ -z
"${KEY_PATTERN}" && ! -z
"${ROOTPWA_KEYS_DIR}" ]]
210 KEY_PATTERN=
"${ROOTPWA_KEYS_DIR}/*.key"
212 if [[ -z
"${MASS_BIN_INDEX}" ]]
216 # override MASS_BIN_INDEX with SGE_TASK_ID
217 if [[ -
n "${SGE_TASK_ID}" ]]
219 MASS_BIN_INDEX=
"${SGE_TASK_ID}"
221 if [[ -z
"${MASS_BINS_DIR}" ]]
223 MASS_BINS_DIR=
"${ROOTPWA_DATA_DIR}"
225 if [[ -z
"${PDG_TABLE}" ]]
227 PDG_TABLE=
"${ROOTPWA}/amplitude/particleDataTable.txt"
229 # parse command line options
230 while getopts
"${KEY_PATTERN_OPT}:${MASS_BINS_DIR_OPT}:${PDG_TABLE_OPT}:${HELP_OPT}" OPTION
233 ${KEY_PATTERN_OPT}) KEY_PATTERN=${OPTARG};;
234 ${MASS_BINS_DIR_OPT}) MASS_BINS_DIR=${OPTARG};;
235 ${PDG_TABLE_OPT}) PDG_TABLE=${OPTARG};;
236 ${HELP_OPT})
usage 0;;
239 shift $((${OPTIND} - 1))
# just leave remaining arguments in $*
242 MASS_BIN_INDEX=
"${1}"
244 if [[ -z
"${KEY_PATTERN}" || -z
"${MASS_BINS_DIR}" || -z
"${PDG_TABLE}" || -z
"${MASS_BIN_INDEX}" ]]
248 if [[
"${ROOTPWA_ENV_SET}" !=
"true" ]]
250 echo "!!! error: ROOTPWA environment is not setup. please source the ROOTPWA setup script first."
255 # convert all input paths to absolute paths
256 KEY_PATTERN=$(readlink --canonicalize-missing
"${KEY_PATTERN}")
257 MASS_BINS_DIR=$(readlink --canonicalize-missing
"${MASS_BINS_DIR}")
258 PDG_TABLE=$(readlink --canonicalize-missing
"${PDG_TABLE}")
261 echo ">>> info: ${0} started on $(date)"
265 # construct array of
mass bins in ascending order
266 MASS_BINS=( $(find ${MASS_BINS_DIR} -type
d -regex
'.*/[0-9]+.[0-9]+' -printf
'%f\n' | sort -
n) )
267 if [[ -z
"${MASS_BINS}" ]]
269 echo "!!! error: cannot find any mass bins in '${MASS_BINS_DIR}'"
272 # find right mass bin
273 MASS_BIN_DIR=${MASS_BINS[$(expr ${MASS_BIN_INDEX} - 1)]}
274 if [[ -z
"${MASS_BIN_DIR}" ]]
276 echo "!!! error: cannot find mass bin with index ${MASS_BIN_INDEX}"
279 MASS_BIN_DIR=${MASS_BINS_DIR}/${MASS_BIN_DIR}
280 if [[ ! -
d "${MASS_BIN_DIR}" ]]
282 echo "!!! error: mass bin directory '${MASS_BIN_DIR}' does not exist"
287 # define mass bin file structure
289 MASS_BIN_NAME=$(basename ${MASS_BIN_DIR})
290 # directory
for amplitude files from real data
291 DT_AMP_DIR=${MASS_BIN_DIR}/${DT_AMP_DIR_NAME}
292 # path of real data file
293 DT_FILE=${MASS_BIN_DIR}/${MASS_BIN_NAME}${DT_FILE_EXT}
294 if [[ ! -e
"${DT_FILE}" ]]
296 echo "!!! error: data file '${DT_FILE}' does not exist. exiting."
299 # directory for amplitude files from Monte-Carlo
300 PS_AMP_DIR=${MASS_BIN_DIR}/${PS_AMP_DIR_NAME}
301 # path of Monte-Carlo data file
302 PS_FILE=${MASS_BIN_DIR}/${MASS_BIN_NAME}${PS_FILE_EXT}
303 # directory for amplitude files from Monte-Carlo
304 PSACC_AMP_DIR=${MASS_BIN_DIR}/${PSACC_AMP_DIR_NAME}
305 # path of Monte-Carlo data file
306 PSACC_FILE=${MASS_BIN_DIR}/${MASS_BIN_NAME}${PSACC_FILE_EXT}
309 # check whether necessary file and directories are there
310 if [[
"$(eval ls -1 ${KEY_PATTERN} | wc -l)" ==
"0" ]]
312 echo "!!! error: no key files match glob pattern '${KEY_PATTERN}'. exiting."
315 if [[ ! -s
"${PDG_TABLE}" ]]
317 echo "!!! error: PDG table file '${PDG_TABLE}' does not exist. exiting."
322 # calculate amplitudes
323 echo ">>> info: starting amplitude calculation for mass bin ${MASS_BIN_INDEX} in '${MASS_BIN_DIR}' using waveset(s) '${KEY_PATTERN}'"
324 echo ">>> info: $(eval ls -1 ${KEY_PATTERN} | wc -l) key files:"
325 eval ls -l ${KEY_PATTERN}
327 echo ">>> info: ${0} started on $(date)"
330 echo "------------------------------------------------------------"
331 echo ">>> info: processing real data for mass bin '${MASS_BIN_DIR}'"
332 # create directory if necessary
333 if [[ ! -
d "${DT_AMP_DIR}" ]]
335 mkdir --parents --verbose
"${DT_AMP_DIR}"
337 # generate amplitude files for real data
338 runCalcAmplitudes
"${DT_FILE}" "${DT_AMP_DIR}"
342 echo "------------------------------------------------------------"
343 echo ">>> info: processing phase-space Monte Carlo data for mass bin '${MASS_BIN_DIR}'"
344 # generate amplitude files for phase-space Monte Carlo data
345 if [[ ! -s
"${PS_FILE}" ]]
347 echo "??? warning: phase-space MC data file '${PS_FILE}' does not exist"
348 # generate phase space for normalization integral
349 #runPhaseSpaceGen "${PS_FILE}"
351 # create directory if necessary
352 if [[ ! -
d "${PS_AMP_DIR}" ]]
354 mkdir --parents --verbose
"${PS_AMP_DIR}"
356 # generate amplitude files for phase-space MC data
357 runCalcAmplitudes
"${PS_FILE}" "${PS_AMP_DIR}"
358 # perform integration for phase-space MC data
359 #runInt "${PS_AMP_DIR}"
360 runCalcIntegrals
"${PS_AMP_DIR}"
364 echo "------------------------------------------------------------"
365 echo ">>> info: processing accepted phase-space Monte-Carlo data for mass bin '${MASS_BIN_DIR}'"
366 # generate amplitude files for accepted phase-space Monte-Carlo data
367 if [[ ! -s
"${PSACC_FILE}" ]]
369 echo "??? warning: accepted phase-space MC data file '${PSACC_FILE}' does not exist"
371 # create directory if necessary
372 if [[ ! -
d "${PSACC_AMP_DIR}" ]]
374 mkdir --parents --verbose
"${PSACC_AMP_DIR}"
376 # generate amplitude files for accepted phase-space MC data
377 runCalcAmplitudes
"${PSACC_FILE}" "${PSACC_AMP_DIR}"
378 # perform integration for accepted phase-space MC data
379 #runInt "${PSACC_AMP_DIR}"
380 runCalcIntegrals
"${PSACC_AMP_DIR}"
385 echo ">>> info: ${0} successfully finished on $(date)"