Error while attempting to write output of Integral() to text file in a bash script


ROOT Version: 6.28/06
Platform: WSL Ubuntu
Compiler: Not Provided


Hi, relatively new to root and I’m currently attempting to use a bash script to complete a task, and within the code is:

	root B4.root <<-EOF		#opens the output in root then takes the integral of the data and saves it to a text file (currently throwing an error)
	Eabs->Integral() >> ../FullOut.txt
	.q	
	EOF
	cd ..

The error given when attempting to run this is:

ROOT_prompt_1:1:21: error: expected expression
Eabs->Integral() >> ../FullOut.txt
                    ^

My best guess is that giving a directory is trying to use regular shell commands inside of root?? However I have not found any way to fix this from looking online. What am I doing wrong? Thanks

You should put the ROOT code inside a ROOT macro (read the Primer for examples) and call the macro from the bash script like this:

 root -l -b -q yourmacro.C

if your macro doesn’t take arguments. You can redirect the output from the macro with, .e.g.

 root -l -b -q yourmacro.C > yourlogfile.txt

Or you could save directly to a log file from inside your macro (e.g. with ofstream).
(Do root --help in the linux terminal to see what the -l -b -q mean).
To see how to open and work with root files in a macro, read the “File I/O” section of the primer I linked above.

Thanks for the help! Upon reading root --help I discovered that since I only wanted to run one command I could simply use

root B4.root -l -b -q -e 'Eabs->Integral()' >> ../FullOut.txt
1 Like