#include#include void simpleCanvas(){ //create canvas TCanvas *c1 = new TCanvas("c1","Simple Canvas",600,400); //create histogram TH1F *hist = new TH1F("hist","Example histogram",100,-5,5); //fill histogram randomly hist->FillRandom("gaus",1000); //draw histogram on canvas hist->Draw(); }
#includeIn this example, we create a new TCanvas and divide it into a 2x2 grid. We then create four new TH1F histograms with different probability distributions and fill them randomly. Finally, we draw each histogram on a separate cell of the canvas. Package: ROOT - A modular scientific software toolkit.#include void multiCanvas(){ //create canvas TCanvas *c1 = new TCanvas("c1","Simple Canvas",600,400); //divide canvas into 2x2 grid c1->Divide(2,2); //create histograms TH1F *hist1 = new TH1F("hist1","Histogram 1",100,-5,5); TH1F *hist2 = new TH1F("hist2","Histogram 2",100,-5,5); TH1F *hist3 = new TH1F("hist3","Histogram 3",100,-5,5); TH1F *hist4 = new TH1F("hist4","Histogram 4",100,-5,5); //fill histograms randomly hist1->FillRandom("gaus",1000); hist2->FillRandom("landau",1000); hist3->FillRandom("expo",1000); hist4->FillRandom("gaus",1000); //draw histograms on canvas c1->cd(1); hist1->Draw(); c1->cd(2); hist2->Draw(); c1->cd(3); hist3->Draw(); c1->cd(4); hist4->Draw(); }