Executing external script

Hi,

I have many root scripts containing data array and each plots a graph. Now, I want to plot all the graphs in different pad in one canvas. Here is an example:

I have scripts: script1.C, script2.C, script3.C and script4.C. When I execute each script separately, each will draw graph for the data array in that script, for example graph1 by script1.C, graph2 by script2.C, graph3 by script3.C, and graph4 by script4.C. Now I want to do:

TCanvas *c = new TCanvas("c", "c", 800, 650);
c->Divide(2,2);

c->cd(1);
execute  script1.C and plot graph1 in this pad.

c->cd(2);
execute  script2.C and plot graph2 in this pad.

............
............

I tried this but it plots in separate canvas:

c->cd(1);
gSystem->Exec("root -l script1.C");

I want to keep each script so that I can still run them separately. How can I do this.

Any suggestion will be helpful.
Thanks.

Problem solved. Thanks.

Could you tell us how do you solve your problem? It could be helpful for the users who will have this problem.

Yes, in fact it was simple, somehow I was missing it.

I included those script in my main program and call those functions from main program, that’s all. Here is an example.

Let us say my scripts are script1.C, script2.C, script3.C. Each of them plot a graph when they are executed separately. script1.C plots graph1, script2.C plots graph2 and script3.C plots graph3. My script1.C looks like this:

void script1()
{
      double x[] = {1, 2, 3, 4};
      double y[] = {2, 4, 6, 8};
      
      TGraph *graph1 = new TGraph(4, x, y);
      graph1->SetName("graph1");
      graph1->SetTitle("graph1"); 
      graph1->Draw("AP");
}

Now, I want to plot all these graphs in different pads of a canvas. Here is my main program:

#include "script1.C"
#include "script2.C"
#include "script3.C"

void plot()
{
    TCanvas *c = new TCanvas("c", "c", 800, 650);
     c->Divide(2, 2);

     c->cd(1);
     script1();

     c->cd(2);
     script2();

     c->cd(3);
     script3();

     c->Draw();
}

Hope it helps. Thanks.