# 2 canvas with 2 TApplication

**URL:** <https://root-forum.cern.ch/t/2-canvas-with-2-tapplication/48486>\
**Category:** Newbie\
**Created:** [January 21, 2022, 1:24pm UTC](https://root-forum.cern.ch/t/2-canvas-with-2-tapplication/48486 "2022-01-21T13:24:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MicheleScattola](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/michelescattola/32/27810_2.png) [@MicheleScattola](https://root-forum.cern.ch/u/MicheleScattola)\
**Post date:** [January 21, 2022, 1:24pm UTC](https://root-forum.cern.ch/t/2-canvas-with-2-tapplication/48486/1 "2022-01-21T13:24:27Z")

</div>

Good afternoon!  
I am writing a file main.cpp which reads data from files and creates ROOT plots.  
I am interested into having 2 different canvas for 2 types of Montecarlo integration. My implementation in main.cpp looks something like this:

```auto
void Histrogram1 {
TApplication app1("app1",0,0);
TCanvas * can1 = new TCanvas(...);
can1->Divide(3,2);
...
app1.Run();
}

void Histrogram2 {
TApplication app2("app2",0,0);
TCanvas * can2 = new TCanvas(...);
can2->Divide(3,2);
...
app2.Run();
}

int main(){
Histogram1();
Histogram2();

return 0;
}

```

I have created 2 different TApplications and different canvas, I don’t know why but when I execute the code it only creates the canvas of the 1st Histogram void function written in “int main” (in this case Histogram1)

_ROOT Version:_ 6.24/06  
\_Platform:\_Ubuntu 21.04  
_Compiler:_ g++

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 21, 2022, 1:39pm UTC](https://root-forum.cern.ch/t/2-canvas-with-2-tapplication/48486/2 "2022-01-21T13:39:58Z")

</div>

You can create many [TCanvas](https://root.cern/doc/master/classTCanvas.html) objects but only one [TApplication](https://root.cern/doc/master/classTApplication.html) (e.g., right in your “`main`” routine).

```cpp
// $(root-config --cxx --cflags) main.cpp $(root-config --libs) && ./a.out
#include "TApplication.h"
#include "TCanvas.h"
#include "TText.h"
void Histogram1() {
  TCanvas *c = new TCanvas("can1", "canvas 1");
  c->Divide(3, 2);
  c->cd(2);
  (new TText(0.5, 0.5, "PAD 2"))->Draw();
  c->cd(0);
}
void Histogram2() {
  TCanvas *c = new TCanvas("can2", "canvas 2");
  c->Divide(3, 2);
  c->cd(5);
  (new TText(0.5, 0.5, "PAD 5"))->Draw();
  c->cd(0);
}
int main() {
  TApplication a("app", 0, 0);
  Histogram1();
  Histogram2();
  a.Run(); // note: "File" -> "Quit ROOT" will NOT return here
  return 0;
}

```

---

<div class="post-metadata">

**Author:** ![MicheleScattola](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/michelescattola/32/27810_2.png) [@MicheleScattola](https://root-forum.cern.ch/u/MicheleScattola)\
**Post date:** [January 21, 2022, 4:34pm UTC](https://root-forum.cern.ch/t/2-canvas-with-2-tapplication/48486/4 "2022-01-21T16:34:01Z")

</div>

Cheers thank you!  
So if I want both plots to be shown I need to declare only 1 void function (with the TApplication inside of it)?  
Because if I add the TApplication and run it inside main it creates the canvas but they are blank
