Please read tips for efficient and successful posting and posting code
_ROOT Version:_6.22/00
Platform: Ubuntu WSL2
Compiler: gedit, nano.
Hello,
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");
T->Draw("kinetic_energy:position");
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");
T->Draw("gravitational_energy:position_z");
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(){
gravitational_energy_vs_position_x();
kinetic_energyandposition_z();
}
First gravitational_energy_vs_position_x() is creating a canvas then the next function is overwriting it creating the next canvas over it.