Running RooFit from script or from prompt

Hi all,

I have a very small roofit script

[code]from ROOT import *

ROOFit business

try:
_sc = RooFit
except NameError:
_roofitLoad = gSystem.Load(“libRooFit”)
if _roofitLoad == 0:
from ROOT import *

ws = RooWorkspace(“w”, 1)
ws.factory(“CBShape::sig(B_postcalib_M[4479,6079], mu[5000,5500], sigma[80,50,150], alpha[0.1,5], n[0,100])”)
[/code]

If I type the commands from the command prompt, everything is fine. Now, if I put this in a script and run it, I get the following errors and it fails:

Error in <TCint::AutoLoad>: failure loading dependent library libMathMore.so for class RooCBShape Error in <TCint::AutoLoad>: failure loading library libRooFit.so for class RooCBShape [#0] ERROR:ObjectHandling -- RooFactoryWSTool::createArg() ERROR in CINT constructor call to create object [#0] ERROR:ObjectHandling -- RooFactoryWSTool::processExpression() ERRORS detected, transaction to workspace aborted, no objects committed

I’m on Mac Mountain Lion, and I compiled root myself (5.34.03). I guess it’s my mistake somewhere, but I can’t find it.

Thanks,
Albert

Hi,

further investigations lead me to the simplified script

from ROOT import *
gSystem.Load("libRooFit")
from ROOT import *

ws = RooWorkspace("w", 1)
ws.factory("CBShape::sig(B_postcalib_M[4479,6079], mu[5000,5500], sigma[80,50,150], alpha[0.1,5], n[0,100])")

which give, only when running as script,

[code]RooFit v3.55 – Developed by Wouter Verkerke and David Kirkby
Copyright © 2000-2012 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt

[#1] INFO:ObjectHandling – RooWorkspace::exportToCint(w) INFO: references to all objects in this workspace will be created in CINT in 'namespace w’
Error in TClass::BuildRealData: Cannot find any ShowMembers function for G__CINT_ws!
[#0] ERROR:ObjectHandling – RooFactoryWSTool::createArg() ERROR in CINT constructor call to create object
[#0] ERROR:ObjectHandling – RooFactoryWSTool::processExpression() ERRORS detected, transaction to workspace aborted, no objects committed
[/code]

So in this way the mathmore problem disappears. Maybe this helps find a solution?

EDIT: Further investigation lead me to the fact that if I do

and then move from here, instead of the typical

it also works. I thought the recommended way was the second one, and that’s why I was using it. Am I wrong?

Hi,

“from ROOT import *” is definitely NOT recommended, as it is slower and less clear as to where objects come from. Case in point is your example. :slight_smile:

What’s going on, is that the python interpreter needs to check for the existence of “ws” before it can assign to it. The reason being that “ws” needs to have its reference count decreased by 1 if it does exist. That check tickles the lookup in ROOT, b/c of that “from ROOT import *”, and one of the funny things that happen with said lookup, is that if such a named variable exists on the C++ side, it will be created and then immediately deleted again by having its reference count decreased.

Now, as it happens, ws does exist:[code]root [0] gSystem->Load(“libRooFit”)

RooFit v3.55 – Developed by Wouter Verkerke and David Kirkby
Copyright © 2000-2012 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt

(int)0
root [1] ws
(class G__CINT_ws)12495072
root [2][/code]
So, simply use a different name, such as e.g. “myws” when using “from ROOT import *”.

Cheers,
Wim