# Mixing interactive an batch modes

**URL:** <https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672>\
**Category:** ROOT\
**Created:** [February 5, 2017, 8:08pm UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672 "2017-02-05T20:08:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![andalenavals](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/andalenavals/32/16185_2.png) [@andalenavals](https://root-forum.cern.ch/u/andalenavals)\
**Post date:** [February 5, 2017, 8:08pm UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/1 "2017-02-05T20:08:29Z")

</div>

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.

```auto
    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

> [@Draw canvases produced in batch mode](https://root-forum.cern.ch/t/draw-canvases-produced-in-batch-mode/19893/1):
>
> I need to produce many canvases in batch in my application. What I do is something like this: gROOT-\>SetBatch(kTRUE); std::vector\<TCanvas\*\> canvases; for(int i = 0; int \< nCanvases; i++){ TCanvas \*c = new TCanvas; TH1F \*h1 = new TH1F(...); TH1F \*h2 = new TH1F(...); // Fill h1 and h2 and then: h1-\>Draw(); h2-\>Draw("SAME"); canvases.push\_back(c); } gROOT-\>SetBatch(kFALSE); At the end I have a vector of TCanvas. At this point the user may ask the GUI to show a certain canvas, so I need to d…

and it seems like a open discussion.

Thanks in advance  
Regards,

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 6, 2017, 8:23am UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/2 "2017-02-06T08:23:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andalenavals](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/andalenavals/32/16185_2.png) [@andalenavals](https://root-forum.cern.ch/u/andalenavals)\
**Post date:** [February 6, 2017, 4:36pm UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/3 "2017-02-06T16:36:24Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 6, 2017, 4:44pm UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/4 "2017-02-06T16:44:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andalenavals](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/andalenavals/32/16185_2.png) [@andalenavals](https://root-forum.cern.ch/u/andalenavals)\
**Post date:** [February 6, 2017, 4:57pm UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/5 "2017-02-06T16:57:14Z")

</div>

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

```auto
#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;

 }
```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 6, 2017, 5:02pm UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/6 "2017-02-06T17:02:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andalenavals](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/andalenavals/32/16185_2.png) [@andalenavals](https://root-forum.cern.ch/u/andalenavals)\
**Post date:** [February 6, 2017, 6:16pm UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/7 "2017-02-06T18:16:37Z")

</div>

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

```auto
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?

```auto
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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 7, 2017, 9:16am UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/8 "2017-02-07T09:16:55Z")

</div>

Your are missing:

```auto
   TApplication theApp("App", &argc, argv);
```

```auto
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;
}
```

---

<div class="post-metadata">

**Author:** ![andalenavals](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/andalenavals/32/16185_2.png) [@andalenavals](https://root-forum.cern.ch/u/andalenavals)\
**Post date:** [February 8, 2017, 10:31pm UTC](https://root-forum.cern.ch/t/mixing-interactive-an-batch-modes/23672/9 "2017-02-08T22:31:49Z")

</div>

Thank you, it works properly.
