How to load AtlasStyle in PyRoot

Hello,

I’m trying to load AtlasStyle in my python code, but nothing seems to work.I run the code on the lxplus, this means it is ROOT version 6.10 (and this means gROOT.SetStyle("ATLAS") is not working).

The last thing I tried was

from ROOT import * gROOT.LoadMacro("AtlasStyle.C") 

because in another thread in this forum this was working for somebody. But it isn’t for me. I get the error:

    from ROOT import * gROOT.LoadMacro("AtlasStyle.C") 
                           ^
SyntaxError: invalid syntax

If it helps I have got the atlasstyle-00-04-02 folder, which I used for my c++ makros (include “atlasstyle-00-04-02/AtlasStyle.h” and than in root: .L atlasstyle-00-04-02/AtlasStyle.C works fine)

I guess you meant:

from ROOT import *
gROOT.LoadMacro("AtlasStyle.C")

right ? :slight_smile:

actually, make it:

import ROOT
ROOT.gROOT.LoadMacro("AtlasStyle.C")

or:

from ROOT import gROOT
gROOT.LoadMacro("AtlasStyle.C")

(from foo import * is frown upon in python, like using namespace std; is (or should be) in C++)

Thank you for your answer.
I tried it like you said, but now the error I get is

Error in <TROOT::LoadMacro>: macro AtlasStyle.C not found in path .:/usr/share/root/macros:

In my usr/share dorectory is no root folder? I don’t have it installed at the moment, because the time I treid to install it, it failed and hence I can use the lxplus, I didn’t tried it again. Is there any other chance? If not, I will try to install ROOT tomorrow again.

LoadMacro will look into some $LD_LIBRARY_PATH-like path.
You can query that value like so:

>>> from ROOT import gROOT
>>> gROOT.GetMacroPath()
'.:/usr/share/root/macros'

and modify it like so:

>>> import os
>>> gROOT.SetMacroPath(os.pathsep.join([gROOT.GetMacroPath(), "/some/other/path"]))
>>> gROOT.GetMacroPath()
'.:/usr/share/root/macros:/some/other/path'

Thank you! I will try that if my new try to install ROOT on my laptop fails tomorrow .

But if I try this: /some/other/path should be exactly what path? I don’t know where it is on lxplus or so…

that would be:

>>> import os
>>> gROOT.SetMacroPath(os.pathsep.join([gROOT.GetMacroPath(), "/path/to/atlasstyle-00-04-02"]))
>>> gROOT.GetMacroPath()
'.:/usr/share/root/macros:/path/to/atlasstyle-00-04-02'
1 Like

Huge Thank you! It seems to work now. There’s no error.

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