Mixing interactive an batch modes

I again rooters.
I know that you can go from interactive to batch, however is it possible to work in the other direction?
Let me show and example to be clear.
I’ve written a code in batch mode that saves 20 ascii files in TGraphs, it prints they and save the canvas in a pdf file, however some times is hard to define the position of a TLegend in batch mode, so I think will be more practical to define that graphically.

    W[0]->Draw("AP");
    for (int i = 1; i <= 19; i++)
    {
      W[i]->Draw("same p");
    }
  leg->Draw();
  c2->Print("plot4.eps");

So, how can I print the canvas in the interactive mode? I’ve been reading this post

and it seems like a open discussion.

Thanks in advance
Regards,

If you run your macro in interactive mode you should see the result on screen and be able to edit it. What is problem? it should be fine.

The problem is that I’m running in batch mode. I just want to see my canvas in interactive, Otherwise I would have to translate my script

int main(int argc, char** argv ){
  
  TString sleg [24];
    
  sleg [0]= "#lambda = 587.57(23) [nm]"; 
  sleg [1]= "#lambda = 667.84(23) [nm]";  
  sleg [2]= "#lambda = 705.79(23) [nm]"; 
  
  int numfiles = argc -1; 
  TLegend *leg= new TLegend( 0.18,0.6,0.5,0.8);
  
  TGraphErrors * W[numfiles];
  for (int i = 0; i < numfiles ; i++)
    {
      W[i]= new TGraphErrors(argv[i+1]);
      leg->AddEntry(W[i] , argv[i+1] , "P");
      //leg->AddEntry(W[i] , sleg[i] , "P");
    }
  W[0]->Draw("AP");
  for (int i = 1; i < numfiles; i++)
    {
      W[i]->Draw("same p");
    }
  //leg->Draw();


  //FIT 
  TF1 * f = new TF1("GauS","[0]*TMath::Gaus(x, [1], [2])+[3]*TMath::Sin([4]*x) ", 0, 4000);
  R.DefinirTF1(f, 3, 10, kRed);
  f->SetParName(0, "Amplitud Gausiana");
  f->SetParName(1, "Media");
  f->SetParName(2, "Sigma");
  f->SetParName(3, "Amplitud Sin");
  f->SetParName(4, "frecuencia");
  //f->SetParameter(0 , 1);
  f->SetParameters(0.45 , 2507 , 560, 0.05, 3);
  f->SetParLimits(0, 0, 1);
  f->SetParLimits(1, 0, 4000);
  f->SetParLimits(2, 0, 4000);
  f->FixParameter(3, 0.05);
  f->FixParameter(4, 0.2);
  //f->Draw("same");
  W[0]->Fit("GauS", "", " ", 1000, 4000);
  c2->Print("plot4.eps");
  return 0;

 }

and I think it is not practical and it has running disadvantages.

You print the canvas “c2” … but where it is defined ?

Sorry, I did not add the rigth code. This is the one

#include "inc/Procesador.h"
#include "inc/RootImprove.h"

using namespace std;

int main(int argc, char** argv ){

  RootImprove R;
  R.DefinirEstilo();
  TCanvas *c2 = new TCanvas ("c2","",800,600);
  R.DefinirCanvas(c2);
  c2->cd();
  
  TString sleg [24];
  
  sleg [0]= "#lambda = 587.57(23) [nm]"; 
  sleg [1]= "#lambda = 667.84(23) [nm]";  
  sleg [2]= "#lambda = 705.79(23) [nm]"; 
  
  int numfiles = argc -1; 
  TLegend *leg= new TLegend( 0.18,0.6,0.5,0.8);//sup-izq
  
  //Formato x y dx dy
  TGraphErrors * W[numfiles];
  for (int i = 0; i < numfiles ; i++)
    {
      W[i]= new TGraphErrors(argv[i+1]);
      R.DefinirTGraph(W[i], R.MarkerStyle(i) , 0.5 , R.Color(i), R.Color(i));
      leg->AddEntry(W[i] , argv[i+1] , "P");
      //leg->AddEntry(W[i] , sleg[i] , "P");
    }
  
  R.DefinirTitulos(W[0],"Intensidad vs tiempo de adquisicion", "Tiempo de adquisicion [ms]", "Intensidad [u.a]" );
  R.DefinirEjes(W[0], 0 , 4000 , 0 , 0.6 ); 
  W[0]->Draw("AP");
  for (int i = 1; i < numfiles; i++)
    {
      W[i]->Draw("same p");
    }
  //leg->Draw();


  //FIT
  // W[0]->Fit("pol1","", "", 3000, 3500); //po+p1x
  // W[0]->Fit("pol2","", "", 1000, 4000); //po+p1x+p2x*x
  // W[0]->Fit("expo", "", "", 1000, 4000); //exp(po+p1x)
  // W[0]->Fit("gaus", "", " ", 1000, 4000);
  // W[0]->Fit("gausn", "", " ", 1000, 4000);

  
  TF1 * f = new TF1("GauS","[0]*TMath::Gaus(x, [1], [2])+[3]*TMath::Sin([4]*x) ", 0, 4000);
  R.DefinirTF1(f, 3, 10, kRed);
  f->SetParName(0, "Amplitud Gausiana");
  f->SetParName(1, "Media");
  f->SetParName(2, "Sigma");
  f->SetParName(3, "Amplitud Sin");
  f->SetParName(4, "frecuencia");
  //f->SetParameter(0 , 1);
  f->SetParameters(0.45 , 2507 , 560, 0.05, 3);
  f->SetParLimits(0, 0, 1);
  f->SetParLimits(1, 0, 4000);
  f->SetParLimits(2, 0, 4000);
  f->FixParameter(3, 0.05);
  f->FixParameter(4, 0.2);
  //f->Draw("same");
  W[0]->Fit("GauS", "", " ", 1000, 4000);
  R.DibujarAjuste(500, 0.55, "#lambda = 0.2300(4)Pixeles + 173.8(8)");

  
  c2->Print("plot4.eps");
  return 0;

 }

I suppose that somewhere you have something like gROOT->SetBatch(kTRUE);
To see the canvas in interactive mode you should do gROOT->SetBatch(kFALSE);

Could you show me how to do it? I’ve tried this

int main(int argc, char** argv ){
  gROOT->SetBatch(kTRUE);
  TCanvas *c2 = new TCanvas ("c2","",800,600);
  c2->cd();
  TGraph *g = new TGraph(1);
  int dots = 100;

  for(int i=1; i<dots ; i++){
    g->SetPoint(i-1, i, sin(i));
  }
  gROOT->SetBatch(kFALSE);
  g->Draw("APC");
  c2->Print("plot.eps");
  
  return 0;
 }

but the interactive mode doesn’t appears, and I don’t get nor compiling neither running mistakes.
Shall I compile in another way?

Target = cint
ROOTFLAGS = $(shell root-config --cflags) 
ROOTLIBS =  $(shell root-config --libs)

all: $(Target)
cint: cint.cpp
	g++ -o $@ cint.cpp $(ROOTFLAGS) $(ROOTLIBS)
clean: 
	rm -f $(Target)

Is this root version depended? I’m running 5.34 version.

Your are missing:

   TApplication theApp("App", &argc, argv);
int main(int argc, char **argv){
  TApplication theApp("tapp", &argc, argv);
  
   TH1F *h = new TH1F("h","h",100,-3,3);
   h->FillRandom("gaus",1000);
   TCanvas *c1=new TCanvas("c1");
   h->Draw();
   c1->Update();
  
   theApp.Run();
   
   return 0;
}

Thank you, it works properly.