I am trying to write a shell script to run Madgraph 5 but after entering the madgraph interface my script is not working

Asked by Luqman Ali on 2015-10-02

# !/bin/bash

run=${1}
nevt=${2}
#rnum=${3}

# Now let shell know where to find madgraph executables
cd /home/Luqman/MadGraph/MG5_aMC_v2_0_1/bin
ls -l

rnum=`date +%s%N | cut -b11-18`
echo $rnum

# To run madgraph executable
./mg5

#Generate a process
./generate p p > t t~ , (t > w+ b , w+ > e+ ve),(t~ > w- b~ , w- > e- ve~)

#Make output
output test${run}

#replace the seed in the run card with ${rnum}
sed -i "s#[0-9]\+ *= *iseed# ${rnum} = iseed#g" test${run}/Cards/run_card.dat

#if [ ! -e test${run}/Cards/run_card.dat ]; then
# echo test${run}Cards/run_card.dat " does not exist!"
# exit 1;
#fi

#replace the number of events in the run_card
sed -i "s#[0-9]\+ *= *nevents# ${nevt} = nevents#g" test${run}/Cards/run_card.dat

launch test${run}

exit
~
I am using the above script to run madgraph but after ./mg5 command I get the madgraph interface and asks to do the other thing like generate, output, launch and other things by entering these command to the MG CLI. Idon't know how to include these commands to the shell script?

Question information

Language:
English Edit question
Status:
Solved
For:
MadGraph5_aMC@NLO Edit question
Assignee:
No assignee Edit question
Solved by:
Olivier Mattelaer
Solved:
2015-10-04
Last query:
2015-10-04
Last reply:
2015-10-03

This question was reopened

Olivier Mattelaer suggests this article as an answer to your question:
FAQ #2186: “How to script MG5 run?”.

Luqman Ali (luqmanali1584) said : #2

My script is ok upto the ./mg5 but after that I just get a mg5 CLI and the generate command is not working.
This is my first ever script in the shell scripting and I don't know how to write the generate process and the output commands in my script so that they may work in the mg5 interface. I couldn't find anything useful in the suggested article.

Well,

You really have all the information needed in the above link.
The idea is to write a file with all the madgraph command and then run on that input file with
 ./bin/mg5 PATH

The problem of your script is that you start an interactive session and that the code waits input in stdin (i.e. you typing in your keyboard). When you hit ctrl-c, then you go back to bash who tries to run ./generate which off course do not exists in a linux command.

you can write your command file on the flight with the "echo" command something like
# creation of the input file for madgraph
echo "generate p p > t t~ , (t > w+ b , w+ > e+ ve),(t~ > w- b~ , w- > e- ve~)" > mymcd
echo "output test${run}" >> mycmd
echo "launch test${run}" >> mycmd
echo "set iseed ${rnum}" >> mycmd
echo "set nevents ${nevt}" >> mycmd

Cheers,

Olivier

Luqman Ali (luqmanali1584) said : #5

Thanks Olivier Mattelaer, that solved my question.