diff --git a/bin/Powheg/runcmsgrid.sh b/bin/Powheg/runcmsgrid.sh new file mode 100755 index 000000000000..78a95ceaa23b --- /dev/null +++ b/bin/Powheg/runcmsgrid.sh @@ -0,0 +1,263 @@ +#!/bin/bash + +fail_exit() { echo "$@"; exit 1; } + +# #set -o verbose +# EXPECTED_ARGS=3 + +# if [ $# -ne $EXPECTED_ARGS ] +# then + # echo "Usage: `basename $0` Nevents RandomSeed cpu" + # echo "Example: `basename $0` 1000 1212 cpu" + # exit 1 +# fi + +echo " ______________________________________ " +echo " Running Powheg " +echo " ______________________________________ " + +nevt=${1} +echo "%MSG-POWHEG number of events requested = $nevt" + +rnum=${2} +echo "%MSG-POWHEG random seed used for the run = $rnum" + +ncpu=${3} +echo "%MSG-POWHEG number of cputs for the run = $ncpu" + +LHEWORKDIR=`pwd` + +use_gridpack_env=true +if [ -n "$4" ] + then + use_gridpack_env=$4 +fi + +if [ "$use_gridpack_env" = true ] + then + if [ -n "$5" ] + then + scram_arch_version=${5} + else + scram_arch_version=slc7_amd64_gcc10 + fi + echo "%MSG-POWHEG SCRAM_ARCH version = $scram_arch_version" + + if [ -n "$6" ] + then + cmssw_version=${6} + else + cmssw_version=CMSSW_12_6_5 + fi + echo "%MSG-POWHEG CMSSW version = $cmssw_version" + export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch + source $VO_CMS_SW_DIR/cmsset_default.sh + export SCRAM_ARCH=${scram_arch_version} + scramv1 project CMSSW ${cmssw_version} + cd ${cmssw_version}/src + eval `scramv1 runtime -sh` +fi +cd $LHEWORKDIR + +seed=$rnum +file="cmsgrid" + +process="ggHZ" + +# Release to be used to define the environment and the compiler needed +export WORKDIR=`pwd` + +# LHAPDF setup +LHAPDFCONFIG=`echo "$LHAPDF_DATA_PATH/../../bin/lhapdf-config"` +#if lhapdf6 external is available then above points to lhapdf5 and needs to be overridden +LHAPDF6TOOLFILE=$CMSSW_BASE/config/toolbox/$SCRAM_ARCH/tools/available/lhapdf6.xml +if [ -e $LHAPDF6TOOLFILE ]; then + LHAPDFCONFIG=`cat $LHAPDF6TOOLFILE | grep " powheg.input + +# Check if the powheg.input file contains the proper settings to calculate weights + +produceWeights="false" + +grep -q "storeinfo_rwgt 1" powheg.input ; test $? -eq 0 || produceWeights="false" +grep -q "pdfreweight 1" powheg.input ; test $? -eq 0 || produceWeights="false" +grep -q "first runx" powheg.input ; test $? -ne 0 || produceWeights="true" + +cat powheg.input +../pwhg_main &> log_${process}_${seed}.txt; test $? -eq 0 || fail_exit "pwhg_main error: exit code not 0" + +if [ "${process}" == "X0jj" ]; then + # now run reweighting for X0jj process + # also need to modify powheg.input inbetween these calls + cp powheg.input powheg.input.noweight + sed -nir '/compute_rwgt/!p;$acompute_rwgt 1' powheg.input + + # sm weight + sed -nir '/lhrwgt_id/!p;$alhrwgt_id '\''sm_weight'\''' powheg.input + sed -nir '/MGcosa/!p;$aMGcosa 1d0' powheg.input + ../pwhg_main 2>&1 | tee logrew_${process}_${seed}_sm.txt; test $? -eq 0 || fail_exit "pwhg_main error: exit code not 0" + mv pwgevents-rwgt.lhe pwgevents.lhe + + # ps weight + sed -nir '/lhrwgt_id/!p;$alhrwgt_id '\''ps_weight'\''' powheg.input + sed -nir '/MGcosa/!p;$aMGcosa 0d0' powheg.input + ../pwhg_main 2>&1 | tee logrew_${process}_${seed}_ps.txt; test $? -eq 0 || fail_exit "pwhg_main error: exit code not 0" + mv pwgevents-rwgt.lhe pwgevents.lhe + + # mm weight + sed -nir '/lhrwgt_id/!p;$alhrwgt_id '\''mm_weight'\''' powheg.input + sed -nir '/MGcosa/!p;$aMGcosa -0.707107d0' powheg.input + ../pwhg_main 2>&1 | tee logrew_${process}_${seed}_mm.txt; test $? -eq 0 || fail_exit "pwhg_main error: exit code not 0" + mv pwgevents-rwgt.lhe pwgevents.lhe +fi + +if [ "$produceWeightsNNLO" == "true" ]; then + echo -e "\ncomputing weights for NNLOPS\n" + mv pwgevents.lhe fornnlops + cp ../nnlopsreweighter.input . + cp ../HNNLO-11.top . + cp ../HNNLO-22.top . + cp ../HNNLO-0505.top . + ../nnlopsreweighter + mv fornnlops.nnlo pwgevents.lhe +fi + +sed -e "/#new weight/d" -e "//d" -e "//d" pwgevents.lhe > pwgevents.lhe.tmp +mv pwgevents.lhe.tmp pwgevents.lhe +cp powheg.input powheg.input.noweight + +if [ "$produceWeights" == "true" ]; then + + echo " ______________________________________ " + echo " Running HV_ew reweight " + echo " ______________________________________ " + + cp pwgfullgrid-reg-00*.dat pwgfullgrid-reg.dat + echo "rwl_add 1" >> powheg.input + echo "rwl_group_events 2000" >> powheg.input + echo "lhapdf6maxsets 50" >> powheg.input + echo "rwl_file 'pwg-rwl.dat'" >> powheg.input + echo "rwl_format_rwgt 1" >> powheg.input + sed -i -e "s#select_EW#\#select_EW#g" powheg.input + echo "select_EW_virt 1" >> powheg.input + + ../pwhg_main &> logrew_${process}_${seed}.txt; test $? -eq 0 || fail_exit "pwhg_main error: exit code not 0" + cat pwgevents-rwgt.lhe | grep -v "Random number generator exit values" > ${file}_final.lhe +else + cat pwgevents.lhe | grep -v "Random number generator exit values" > ${file}_final.lhe +fi + +rm -rf powheg.input* + +echo -e "\n finished computing weights ..\n" + +xmllint --stream --noout ${file}_final.lhe > /dev/null 2>&1; test $? -eq 0 || fail_exit "xmllint integrity check failed on pwgevents.lhe" + +grep "> NaN" ${file}_final.lhe; test $? -ne 0 || fail_exit "Weights equal to NaN found, there must be a problem in the reweighting" + +# uncomment to avoid problems in production as whole job would fail and problem traced back to neg. PDFs +# grep ">0.00000E+00" ${file}_final.lhe; test $? -ne 0 || fail_exit "Weights equal to 0 found, there must be a problem in the reweighting" + +ls -l ${file}_final.lhe +sed -i 's/Input file powheg.input contained:/Process: '$process'\nInput file powheg.input contained:/g' ${file}_final.lhe +pwd +cp ${file}_final.lhe ${WORKDIR}/${file}_tmp.lhe +cd ${WORKDIR} +partialcommand=`cat JHUGen.input` +jhugencommand="./JHUGen $partialcommand ReadLHE=${file}_tmp.lhe DataFile=${file}_final Seed=${seed}" +######################## +#backwards compatibility +jhugencommand=$(echo $jhugencommand | sed "s/Seed=SEED//g") +######################## +echo ${jhugencommand} +${jhugencommand} + +if [ -s pwgstat.dat ]; then + mv pwgstat.dat pwg-stat.dat +fi + +if [ -s pwg-stat.dat ]; then + if [ "$process" = "b_bbar_4l" ] || [ "$process" = "HWJ_ew" ] || [ "$process" = "HW_ew" ] || [ "$process" = "HZJ_ew" ] || [ "$process" = "HZ_ew" ] || [ "$process" = "WWJ" ]; then + XSECTION=`tac pwg-stat.dat | grep total\ total | awk '{ print $(NF-2) }'` + XSECUNC=` tac pwg-stat.dat | grep total\ total | awk '{ print $(NF) }'` + else + XSECTION=`tac pwg-stat.dat | grep -m1 in\ pb | awk '{ print $(NF-2) }'` + XSECUNC=` tac pwg-stat.dat | grep -m1 in\ pb | awk '{ print $(NF) }'` + fi + head=`cat cmsgrid_final.lhe | grep -in "" | sed "s@:@ @g" | awk '{print $1+1}' | tail -1` + tail=`wc -l cmsgrid_final.lhe | awk -v tmp="$head" '{print $1-2-tmp}'` + tail -${tail} cmsgrid_final.lhe > cmsgrid_final.lhe_tail + head -${head} cmsgrid_final.lhe > cmsgrid_final.lhe_F + proclin=`expr $head + 1` + proc=`sed -n -e ${proclin}p cmsgrid_final.lhe | awk '{print $4}'` + echo " "$XSECTION" "$XSECUNC" 1.00000000000E-00 "$proc >> cmsgrid_final.lhe_F + echo "" >> cmsgrid_final.lhe_F + cat cmsgrid_final.lhe_tail >> cmsgrid_final.lhe_F + mv cmsgrid_final.lhe_F cmsgrid_final.lhe +fi +#Replace the negative so pythia will work +sed "s@-1000021@ 1000022@g" cmsgrid_final.lhe > cmsgrid_final.lhe_F1 +sed "s@1000021@1000022@g" cmsgrid_final.lhe_F1 > cmsgrid_final.lhe +cp ${file}_final.lhe ${WORKDIR}/. + +echo "Output ready with ${file}_final.lhe at $WORKDIR" +echo "End of job on " `date` +exit 0;