How to Write histo in root file with log and colz option

How to Write Histogram in Root file with colz and log option:
This is how i’m trying
but my root file does not have the histo in colz and log option
it is just a simple 2D histogram

void point()
{
TString file = “out.root”;
TFile myfile = TFile::Open(file.Data());
TFile
ou = new TFile(“qahist.root”,“recreate”);
ou->cd();
myfile->ls();
TH2F *f=(TH2F *)myfile->Get(“hNBTOFvsGRM”);
TCanvas *c1= new TCanvas();
c1->cd();
c1->SetLogz();
f->GetXaxis()->SetRange(0,200);
f->GetYaxis()->SetRange(0,400);
f->Draw(“colz”);
f->Write();
ou->Close();
}

Cheers


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Maybe you want: c1->Write(); // save the drawn canvas

Thanks Wile, it worked.

is there any option to save directly the histo in log and colz option rather than the canvas?

I guess, you could encode “colz” using: f->SetOption("COLZ");
However, “log” is a canvas option (not a histogram).

1 Like

The drawing option is not part of the histogram. If you have a histogram h2 in a ROOT file and you want to draw it with the option col you need to Draw it with:

h2->Draw("col");

@couet Try: h2->SetOption("COLZ"); h2->Draw();