Rerunning a macro error and recommendation for a bug-free ROOT version

Hi, it seems like this question has been asked multiple times, but I have one additional question. I was learning about histograms in ROOT, and wrote a simple macro that generates a gaussian histogram by randomly sampling a number of points.

It runs fine when I run it for the first time, but shows error when on second time. I do not know if this issue has been fully fixed. I am using ROOT 6.10, and I was wondering if there is an older version of ROOT that does not have this issue.

Thank you.


Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.10
Platform: Linux
_Compiler:_Emacs
___histogram1.C (148 Bytes)

What is the error message?

Note: you should be able to use:

root [0] .x histogram1.C
root [1] histogram1();

Thank you for your prompt reply. Do you know if there is a root version for ubuntu where this is not an issue? I am kind of confused if I should switch to, for example, some version of root 5, but I wonder if there is some functionalities that I will be missing out on.

Also the

root [0] .x histogram1.C
root [1] histogram1();

does not seem to work, cause I get the error right away when I execute the first line.

Post your macro here for inspection.

Based on what I read from a number of people, macro re-running is not allowed in ROOT version 6, so I switched to version 5, and it works fine now (with the same macro).

You should not be forced to go back to version 5. Post your macro here.

1 Like

Hi @couet, I just did. Thank you. I tried it in Root 6, and I just could not re-run this macro. It works very fine in Root 5. Thanks again.

humm … What kind of error are you getting when you execute the ‘first’ line (ie. the .x histogram1.C)? It should work the same as before.

Until v6.20 (about to be released), reloading unnamed macro was not working properly and since reloading is the only way to execute an unnamed macro twice, this is a problem.

With v6.20, doing

root [0] .x histogram1.C
root [1] .x histogram1.C

works fine (except that the gROOT->Reset() is uneffectice/useless)

With older release you need to update your code:

void histogram1() {
  TH1D *h1 = new TH1D("hist1","Histogram from a gaussian", 100,-3,3);
  // h1.GetBinWidth(0);
  h1->FillRandom("gaus",1000);
  h1->Draw();  // Or keep the histogram on the stack and use h1->DrawClone()
}

and then

root [0] .x histogram1.C
root [1] histogram1();

should work.

Hi @pcanal, the error is the one I have attached in one of my comments above. Let me be clear on the issue at hand:
When I open root from the terminal and run the macro for the first time, it works. Then, I close the program (without quitting root) and run .x histogram1.C, it does not work and gives me the error I was talking about. Then, the only option I have is to quit root and run root again and then do .x histogram1.C and it works fine again (but then it does not work on the second attempt) and so on. I was using root 6.10 for that, and someone recommended that I switch to root version 5, and i did, and that problem was gone. Is root 6.20 out yet for linux? Have you tried this on 6.20 and it works?

Thanks a lot for your help.

I got confused because you said

but you also said:

Those two statements don’t seem to be consistent.

From your description and from your screenshot, it is (as I expect), the second line that fails.

Oh … re-reading, I think my confusion comes from: close the program (without quitting root) which is confusing me because for me ‘the program’ is ‘root’ and thus if you close the program you also (using my definition) quit root. What you are calling close the program, I would probably call close the window.

Is root 6.20 out yet for linux?

No, not yet (but you could build it yourself)

Have you tried this on 6.20 and it works?

Yes.

I was using root 6.10 for that, and someone recommended that I switch to root version 5, …

You can also (if you do not need to modify the script between execution) applies the work-around I recommend and use any v6 version.

@pcanal, that was my bad getting you confused. Yes, I meant the window that pops up once I execute the code in my terminal.

No, not yet (but you could build it yourself)

Since I am very new to root, what does building root mean?

You can also (if you do not need to modify the script between execution) applies the work-around I recommend and use any v6 version.

I might need to modify the script between each execution cause I often tend to play a lot with it to figure out stuffs. However, let me again stress that in my version of root 6.10, I had the error even when I did not make any changes in the script.

I might need to modify the script between each execution

So the work-around won’t help you then. Your option are indeed using v5 or using v6.18 or lower and restart the root session each time or build a beta version of v6.20.

Since I am very new to root, what does building root mean?

See Building ROOT from source - ROOT

Cheers,
Philippe.

1 Like