Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:49

0001 #!/bin/bash
0002 
0003 set -o verbose
0004 
0005 echo "   ______________________________________     "
0006 echo "         Running Madgraph5....                "
0007 echo "   ______________________________________     "
0008 
0009 repo=${1}
0010 echo "%MSG-MG5 repository = $repo"
0011 
0012 name=${2} 
0013 echo "%MSG-MG5 gridpack = $name"
0014 
0015 decay=${3}
0016 echo "%MSG-MG5 run decay = $decay"
0017 
0018 replace=${4}
0019 echo "%MSG-MG5 replace = $replace"
0020 
0021 process=${5}
0022 echo "%MSG-MG5 process = $process"
0023 
0024 maxjetflavor=${6}
0025 echo "%MSG-MG5 maxjetflavor = $maxjetflavor"
0026 
0027 qcut=${7}
0028 echo "%MSG-MG5 qcut = $qcut"
0029 
0030 minmax_jet=${8}
0031 echo "%MSG-MG5 minmax_jet = $minmax_jet"
0032 
0033 min_jets=${9}
0034 max_jets=${10}
0035 echo "%MSG-MG5 min/max jet multiplicity = $min_jets / $max_jets"
0036 
0037 nevt=${11}
0038 echo "%MSG-MG5 number of events requested = $nevt"
0039 
0040 rnum=${12}
0041 echo "%MSG-MG5 random seed used for the run = $rnum"
0042 
0043 ncpu=${13}
0044 echo "%MSG-MG5 thread count requested = $ncpu (ignored)"
0045 
0046 # retrieve the wanted gridpack from the official repository 
0047 fn-fileget -c `cmsGetFnConnect frontier://smallfiles` ${repo}/${name}_gridpack.tar.gz 
0048 
0049 # force the f77 compiler to be the CMS defined one
0050 
0051 ln -sf `which gfortran` f77
0052 ln -sf `which gfortran` g77
0053 PATH=`pwd`:${PATH}
0054 
0055 tar xzf ${name}_gridpack.tar.gz ; rm -f ${name}_gridpack.tar.gz ; cd madevent
0056 ## rename addmasses.py to addmasses.py.no
0057 
0058 find . -name addmasses.py -exec mv {} {}.no \;
0059 
0060 
0061 ########### BEGIN - REPLACE process ################
0062 # REPLACE script is runned automatically by run.sh if REPLACE dir is found ###
0063 # REPLACE will replace el with el/mu/taus by default, if you need something else you need to edit the replace_card1.dat
0064 if [ ${replace} == true ] ; then
0065     cd ..
0066     mkdir REPLACE
0067     cat > replace_card1.dat <<EOF
0068 # Enter here any particles you want replaced in the event file after ME run
0069 # In the syntax PID : PID1 PID2 PID3 ...
0070 # End with "done" or <newline>
0071 11:11 13 15
0072 -12: -12 -14 -16
0073 -11:-11 -13 -15
0074 12: 12 14 16
0075 done
0076 EOF
0077     cp  ./madevent/bin/replace.pl  ./replace_card1.dat  ./REPLACE/
0078     cd -
0079 fi      
0080 ########## END - REPLACE #########################
0081 
0082 
0083 ###### BEGIN - DECAY process #################
0084 # Decay is runned automatically by run.sh if DECAY dir is found
0085 # To avoid compilation problem DECAY dir has been created and compiled when gridpack is created
0086 # if not needed DECAY dir is deleted
0087 
0088 if [ "${decay}" != true ] ; then
0089     rm -rf DECAY
0090 fi
0091 
0092 ######END - DECAY #####
0093 
0094 
0095 # run the production stage
0096 ./run.sh ${nevt} ${rnum}
0097 
0098 ls -al
0099 
0100 file="events"
0101 
0102 if [ ! -f ${file}.lhe.gz ]; then
0103         echo "%MSG-MG5 events.lhe.gz file is not in the same folder with run.sh script, abort  !!! "
0104         exit
0105 
0106 fi
0107 
0108 cp ${file}.lhe.gz ${file}_orig.lhe.gz
0109 gzip -d ${file}.lhe.gz
0110 
0111 #_______________________________________________________________________________________
0112 # check the seed number in LHE file.
0113 
0114 echo "   ______________________________________     "
0115 echo "         post processing started              "
0116 echo "   ______________________________________     "
0117 
0118 echo 
0119 if [ -f ${file}.lhe ] ; then
0120         seed=`awk 'BEGIN{FS=" = gseed  "}/gseed/{print $1}' ${file}.lhe`
0121         number_event=`grep -c "</event>" ${file}.lhe`
0122 fi
0123 
0124 if [ $seed -eq $rnum ] ;then
0125                 echo "GSEED  :$seed"
0126                 if [ $number_event -eq $nevt ] ;then
0127                         echo "NEVENT :  $nevt "
0128                 else
0129                         echo "%MSG-MG5 Error: The are less events ( $number_event ) Post Production is cancelled."
0130                         # TO-DO You might want to save the events in case of inspection the events.
0131                         exit 1
0132                 fi
0133 else
0134         echo "%MSG-MG5 Error: Seed numbers doesnt match ( $seed )"
0135         exit 1
0136 fi
0137 
0138 #_______________________________________________________________________________________
0139 # post-process the LHE file.
0140 
0141 
0142 #__________________________________________
0143 # wjets/zjets
0144 
0145 if [[ ${process} == wjets || ${process} == zjets ]] ; then
0146         echo "%MSG-MG5 process V+jets"
0147         python madevent/bin/mgPostProcv2.py -o ${file}_qcut${qcut}_mgPostv2.lhe -m -w -j ${maxjetflavor} -q ${qcut} -e 5 -s ${file}.lhe
0148 fi
0149 
0150 # qcd 
0151 if [ ${process} == qcd ] ; then
0152         echo "%MSG-MG5 process QCD"
0153         python madevent/bin/mgPostProcv2.py -o ${file}_qcut${qcut}_mgPostv2.lhe -q ${qcut} -j ${maxjetflavor} -e 5 -s ${file}.lhe
0154 fi
0155 
0156 # ttbar
0157 if [ ${process} == ttbar ] ; then
0158         echo "%MSG-MG5 process ttbar"
0159         python madevent/bin/mgPostProcv2.py -o ${file}_qcut${qcut}_mgPostv2.lhe  -m -w -t -j ${maxjetflavor} -q ${qcut} -e 5 -s ${file}.lhe
0160         sed -i -e '/Rnd seed/d'  -e '/MC partial width/d' -e '/Number of Events/d' -e '/Max wgt/d' -e '/Average wgt/d'   -e '/Integrated weight/d' ${file}_qcut${qcut}_mgPostv2.lhe
0161 fi
0162 
0163 #__________________________________________
0164 # If you have HT binned samples min/max jets might be different from file to file. 
0165 # So you can override the min/max jets decision and put by hand these from the command line 
0166 
0167 if [ $minmax_jet == true ] ;then
0168 
0169         sed -i "s/ [0-9]* = minjets    ! Smallest number of additional light flavour jets/ $min_jets = minjets    ! Smallest number of additional light flavour jets/g" \
0170         ${file}_qcut${qcut}_mgPostv2.lhe 
0171         sed -i "s/ [0-9]* = maxjets    ! Largest number (inclusive ktMLM matching multipl.)/ $max_jets = maxjets    ! Largest number  (inclusive ktMLM matching multipl.)/g" \
0172         ${file}_qcut${qcut}_mgPostv2.lhe 
0173 fi
0174 
0175 mv ${file}_qcut${qcut}_mgPostv2.lhe ${name}_final.lhe 
0176 
0177 ls -l
0178 echo
0179 
0180 exit 0