Skip to content

Instantly share code, notes, and snippets.

@kunathj
Last active January 14, 2022 20:47
Show Gist options
  • Save kunathj/76f21ea4ea92bf3b2b0f9f7916ec38dc to your computer and use it in GitHub Desktop.
Save kunathj/76f21ea4ea92bf3b2b0f9f7916ec38dc to your computer and use it in GitHub Desktop.
Wrapper for SiW-ECAL eventbuilding in SiWECAL-TB-analysis repository
#!/bin/bash
# 1. Choose the software version.
source /cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc10-opt/setup.sh # python3, faster.
# source /cvmfs/ilc.desy.de/sw/x86_64_gcc82_centos7/v02-02-03/init_ilcsoft.sh # python2, standard calice software stack.
CALIB_TAG="3GeVMIPscan"
TB_FOLDER="/eos/project-s/siw-ecal/TB2021-11"
OUT_FOLDER="/afs/cern.ch/work/j/jokunath/public/buildfiles"
ROOT_PATH=$1
# 2. Choose the rootfile and extract the run name (for mask and output name)
if [ "$ROOT_PATH" == "" ]; then
ROOT_FOLDER="${TB_FOLDER}/beamData/rootfiles"
ROOT_PATH="${ROOT_FOLDER}/3GeV_22degrees/3GeV_22degrees_run_050126_merged.root"
echo "Use default run:" ${ROOT_PATH}
fi
if ! [ -f ${ROOT_PATH} ]; then
echo "ERROR: Rootfile does not exist! ${ROOT_PATH}"; exit
fi
ROOT_FILE_NAME=$(basename ${ROOT_PATH})
RUN=${ROOT_FILE_NAME/%_merged.root}
# 3. Run event building
OLD_PWD=${PWD}
cd $(dirname $BASH_SOURCE)/eventbuilding;
./build_events.py ${ROOT_PATH}\
--w_config 0\
--cob_positions_string "" \
--out_file_name ${OUT_FOLDER}/${RUN}_build3.root\
--pedestals_file "${TB_FOLDER}/calibration/pedestals/Pedestal_${CALIB_TAG}_highgain.txt" \
--mip_calibration_file "${TB_FOLDER}/calibration/mip_calib/MIP_${CALIB_TAG}_highgain.txt" \
--pedestals_lg_file "${TB_FOLDER}/calibration/pedestals/Pedestal_${CALIB_TAG}_lowgain.txt" \
--mip_calibration_lg_file "${TB_FOLDER}/calibration/mip_calib/MIP_${CALIB_TAG}_lowgain.txt" \
--masked_file "${TB_FOLDER}/calibration/masked/masked_channels_${RUN}.txt" \
--max_entries -1
cd ${OLD_PWD}
#!/bin/bash
OLD_PWD=${PWD}
# 1. Confirm inputs.
RUN="/eos/project-s/siw-ecal/TB2021-11/beamData/rootfiles/3GeVMIPscan_run_050093/"
if [ "${RUN}" == "" ]; then
echo "ERROR: A data folder must be provided as first argument to the script"; exit
fi
# Sometimes it might be easier to give the full path, for autocompletion.
RUN=$(basename ${RUN})
IN_FOLDER="/eos/project-s/siw-ecal/TB2021-11/beamData/rootfiles/${RUN}"
if ! [ -e ${IN_FOLDER} ]; then
echo "ERROR: ${IN_FOLDER} does not exist!"; exit
fi
# 2. Prepare the output
OUT_FOLDER="/afs/cern.ch/work/j/jokunath/public/${RUN}"
source /cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc10-opt/setup.sh
# source /cvmfs/ilc.desy.de/sw/x86_64_gcc82_centos7/v02-02-02/init_ilcsoft.sh
which python
mkdir ${OUT_FOLDER}
CONVERTED_SINGLE_FILE=${OUT_FOLDER}/${RUN}_converted.root
if ! [ -e ${CONVERTED_SINGLE_FILE} ]; then
hadd ${CONVERTED_SINGLE_FILE} ${IN_FOLDER}/*.root
fi
# 3. Create the masked file, if necessary
MASKED_FILE=${OUT_FOLDER}/masked.txt
if ! [ -e ${MASKED_FILE} ]; then
echo "Create the masked file."
cp /eos/project-s/siw-ecal/TB2021-11/beamData/ascii/3GeVMIPscan_run_050093/Run_Settings.txt $(dirname $BASH_SOURCE)/SLBcommissioning/Run_Settings_week2.txt
cd $(dirname $BASH_SOURCE)/SLBcommissioning;
root -l -q -b test_read_masked_channels_summary.C\(\"Run_Settings_week2\"\)
rm Run_Settings_week2.txt
mv Run_Settings_week2_masked.txt ${MASKED_FILE}
cd ${OLD_PWD}
fi
# 4. Run event building
CALIB_TAG="3GeVMIPscan_run_merged"
cd $(dirname $BASH_SOURCE)/eventbuilding;
python -m cProfile -o output_v11.pstats build_events.py ${CONVERTED_SINGLE_FILE} \
--w_config 0 \
--cob_positions_string "" \
--out_file_name py_test.root\
--pedestals_file "/eos/project-s/siw-ecal/TB2021-11/beamData/calibration/Pedestal_${CALIB_TAG}.txt" \
--mip_calibration_file "/eos/project-s/siw-ecal/TB2021-11/beamData/calibration/MIPs_${CALIB_TAG}.txt" \
--masked_file ${MASKED_FILE} \
--max_entries 2000
cd ${OLD_PWD}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment