Home | News | Documentation | Download

How do I produce multiple canvas from a macro?

Please read tips for efficient and successful posting and posting code

_ROOT Version:_6.22/00
Platform: Ubuntu WSL2
Compiler: gedit, nano.

how do I produce two or more canvas from a macro?
My data is loaded from a .root file, see below.

#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TH1F.h"
#include <iostream>

using namespace std;

void energyandposition(){

	TFile * f = new TFile("File1.root");
	TTree *T = (TTree *) f->Get("out_DATA");
	TH1 * myh = static_cast<TH1*>(gPad->GetPrimitive("htemp"));
	myh->SetTitle("The kinetic energy as a function of position x");
	myh->GetXaxis()->SetTitle("Position x (m)");
	myh->GetYaxis()->SetTitle("Kinetic energy ");	


void gravitational_energy_vs_position_z(){

	TFile * f = new TFile("File2.root");
	TTree *T = (TTree *) f->Get("output_DATA");
	TH1 * myh = static_cast<TH1*>(gPad->GetPrimitive("htemp"));
	myh->SetTitle("The gravitational energy as a function of position z");
	myh->GetXaxis()->SetTitle("Position z ");
	myh->GetYaxis()->SetTitle("Gravitational energy ");


void Macro(){



First gravitational_energy_vs_position_x() is creating a canvas then the next function is overwriting it creating the next canvas over it.

Before each “Draw”, add: new TCanvas();

Thanks, it worked