[quote=“azou191”]Hmm, yeah, I do simply type .x test2.C. I execute the code from the ROOT prompt, yes.
And I have some executable code outside of the root macro because I have several ‘functions’ within the script that I call from the ‘main’ macro. I had to put them outside any macro as I need to access them in several functions.
If it’s easier, I can post my whole code so that you can have an idea of what I’m doing if that’s easier?[/quote]
No, please, do some work and send us the smallest working code sample reproducing exactly your problem.
In general it’s not a good idea to use global variables, but this has nothing to do with ROOT and solutions can be different. Of course, a macro can contain global variables, after all if you have to solve your problem at any price … why not.
Now, back to your original macro. The simplest way to fix it:
TCanvas *canvas = new TCanvas("canvas", "results", 50, 10, 1000, 600);
TPad *LHSPad = new TPad("LHSPad", "LHSPad", 0.02, 0.02, 0.79, 0.98);
TPad *RHSPad = new TPad("RHSPad", "RHSPad", 0.81, 0.02, 0.98, 0.98);
TH1F * hist = new TH1F("a", "b", 10, -2., 2.);