Passing arguments to a macro

Hi! Is there a way to pass arguments to a macro started from command line ?
something like :
adrian@nthez145: ~ $root .x macro.C (arg1 , arg2)
Thank you !

see several examples at page 10 of the Users Guide


:blush: thanks :blush:
sorry :frowning:

…I’ve search the user’s guide under parameter and argv.

I came upon this old post while looking for a parameter passing method that would apply to the simplest macro style from with root:

[code]For example:
some code


root [0] .x quickplot_4ch.C(3)
Error: can not open file ‘/…/rootfiles/./quickplot_4ch.C(3)’

(aka synax error)
and then another try to see if argc was visible

root [1] .x quickplot_4ch.C
Error: Symbol argc is not defined in current scope quickplot_4ch.C:2:
*** Interpreter error recovered ***

So does the macro require a “main” call to pass a parameter?



The chapter you are looking for is “CINT the C++ Interpreter” at In particular the discussion on Named Scripts.

In short do:

// File quickplot_4ch.C void quickplot_4ch.C(int val) { // some code }
and useroot 'quickplot_4ch.C(3)'


1 Like

In a bash shell I’d like to do the following:

root ‘quickplot_4ch.C+(BINW)’

Error: Symbol BINW is not defined in current scope :0:

After reviewing other posts and ch2…
So it seems that if I know the value to pass, everything works fine (as in previous helps), but trying to pass it through an enclosing shell script won’t get the values paste the single quotes?



cplager, thanks for the attempt…but…

[code]root [0]
Processing compRates.C+($BINW,$RATE1,$RATE2)…

RooFit v2.50 – Developed by Wouter Verkerke and David Kirkby
Copyright © 2000-2008 NIKHEF, University of California & Stanford University
All rights reserved, please read

Error: Symbol BINW is not defined in current scope :0:
Error: Symbol RATE1 is not defined in current scope :0:
Error: Symbol RATE2 is not defined in current scope :0:[/code]

I suspected…when $3,$4,$5 didn’t work, but I gave it a try anyway.


Traffic sure was slow in the forum this week.

This isn’t really a Root question anymore, but…

Use double quotes " " not single quotes ’ '.

Either will work within the script:

root -l “compRates.C+($BINW,$RATE1,$RATE2)”

root -l ‘compRates.C+(’$BINW,$RATE1,$RATE2’)’

also, args on the script’s command line must be separated by blank spaces (not commas)

Sorry for digging this old thread, but it may be worth noting that ROOT options “-b” and “-q” may be in some cases preferable than “-l” and that in case BINW is a string, for instance, the following will work :

I do this frequently, and my macro takes string and non-string arguments. Here is an example with fixed arguments:

If I needed to pass shell variables as arguments, I have to carefully escape some quotes. Here is a complicated example where I use printf to format a string argument. Note the change of the outermost quotes to backticks and double-quotes to allow the shell variable expansion.

for run in {535,536,537}
  root -b -q -l `printf "standard_analysis.C+(\"../rootfiles/Outputs/Run%04d\",\"./out\",\"iif\",12000,125,-0.00015)" "${run}"`

Non-string arguments are easier:

for t in {120,125,130}
  root -b -q -l "standard_analysis.C+(\"../rootfiles/Outputs/Run0535\",\"./out\",\"iif\",12000,${myvar},-0.00015)"

Note: my way of doing it might not be the most straightforward, but seems to work.

1 Like

Hello Brun,
Please I need a help. I am trying to run root macros but I am getting this error TApplication::ExecuteFile: macro macros not found in path .:/Users/gideonbentum/root_src/obj/macros. Please how do I solve this problem?

ROOT didn’t find the file called “macros”. Check how you spelled it / from which directory you try to execute it.

Let’s, however, not warm up a thread that’s more than 7 years old. If you need further help, you can create a new topic where we deal with your case in detail.

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