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:
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++
You can create many TCanvas objects but only one TApplication (e.g., right in your “main
” routine).
// $(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;
}
1 Like
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