ROOT commands from bash script

Hi, I want to write a bash script that runs some root commands. The script is


for i in `seq 1 235`;
        root -b -q 
        .x masses_wrong_ratio_opt.C("/home/george/Desktop/wrong_weights/output/benchmark_ttH_1.dat.out")                # runs the macro script that creates the root files
        .q                                                                                                              # exits root    
        mv ratio_wrng.root ratio_wrng_$i.root                                                                           # changes the name of the root files

but it doesn’t seem to work. the output is

./ line 6: syntax error near unexpected token `('
./ line 6: `	.x masses_wrong_ratio_opt_C("/home/george/Desktop/wrong_weights/output/benchmark_ttH_'$i'.dat.out")		# runs the macro script that creates the root files'

Anyone knows how to fix it?


1 Like

The script below should print ROOT’s help. You can modify it to do what you want.


root -l <<-EOF

Basically, you need to use <<-EOF for the next lines to be used as input to ROOT, and then EOF when you are finished with ROOT commands.

You don’t need .x, just use:

for i in {1..235}; do # in bash, you dont need to call seq
  root -b -q masses_wrong_ratio_opt.C'("/home/george/Desktop/wrong_weights/output/benchmark_ttH_1.dat.out")'

The trick is to quote the parentheses and the double quotes as well. Easiest done using single quotes :slight_smile:

It gets a bit messy if you want to use i instead of 1 in the filename:
root -b -q masses_wrong_ratio_opt.C'("/home/george/Desktop/wrong_weights/output/benchmark_ttH_'${i}'.dat.out")'

Complely untested :slight_smile:

Also, consider using root -b -q masses_wrong_ratio_opt.C+'("/home/geo ... to compile the code.

But how will the argument of the macro change if I don’t use i? I want each time to be "/home/george/Desktop/wrong_weights/output/benchmark_ttH_ΝUMBER.dat.out"
where NUMBER to span from 1 to 235… and then to exit root…

Thank you

you can use with the escaping of " and ( :
root.exe -l -b -q EmcalJetCDF.C\(\"local\",\"test\",\"data.txt\"\)

if you want to start more similar processes is better to have separate subdirs in which you will have the input,
a generic named symlink to input data and the output file
if the output file is root you can do hadd of the results at the end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.