Log scale does not work


ROOT Version: 6.26/02
Platform: Windows
Compiler: MSVC 19.31.31104.0


Hi,

I can’t get it done to plot an axis logarithmically. The code is:

	Double_t partEdep;	
	tree = myFile->Get<TTree>("depE_sum");
	tree->SetBranchAddress("fdepEnergy_sum", &partEdep);
	auto HdepEnergy = new TH1F("HdepEnergy", "Histo_depE", 10000, 0.0001, 1.);  
	for (int iEntry = 0; iEntry < tree->GetEntriesFast(); ++iEntry)
	{
		tree->GetEntry(iEntry);
		HdepEnergy->Fill(partEdep);
	}

	TCanvas* c2 = new TCanvas("c2", "", 20, 20, 1000, 500);
	c2->Divide(1,4);

	c2->cd(1);
	c2->SetLogx();
	HdepEnergy->Draw("EHIST");
	HdepEnergy->SetFillColor(kCyan-2);
	HdepEnergy->SetLineColor(kOrange-3);
	HdepEnergy->GetXaxis()->SetTitle("[keV]");
	c2->SetLogx();

It’ll always plot regularly. Could you please tell me what I am doing wrongly?
Thanks in advance!

gPad->SetLogx();

1 Like

You can also change:

c2->cd(1);
c2->SetLogx();

to:

c2->cd(1)->SetLogx();

and remove c2->SetLogx();

1 Like

Thank you, this worked! But why? Respectively why does this work and not the other way around?

You have several pads. You need to set the log scale on the right pad. It was not the case in your initial code.

1 Like