Log axis

Hi,

I’ve a problem to plot an axis logarithmitically. Usually I just use something like “c3->SetLogy();” (when c3 is TCanvas) but it does not work right now.
Here’s my code:

[code]#include “Header.hxx”
#include
#include <stdio.h>
#include <stdlib.h>
#include
#include “Riostream.h”
#include “TText.h”
#include “TLatex.h”
#include “TLegend.h”
#include "TMath.h"
using namespace std;

Int_t fit_cosmics(const char inFile="…/testtree.root", Int_t gain=1, Int_t apd=2)
{
TFile
_file = new TFile(inFile);
if(_file==NULL)
{
printf(“No file “%s” found!\n”, inFile);
}

TDirectory* TD=(TDirectory*)_file->Get("Cosmics_added");			
TD->cd();
										
TH1F *his[25]; 
char name[200];
Char_t fitFile[200];

// if(gain==1)
{	
	sprintf(fitFile,"fitfiles/fitparameter_energyresolution_HG_%s.txt",inFile);
}
  
Double_t peak[25], peak_error[25];
Double_t sigma[25], sigma_error[25];	
ofstream textfile;
textfile.open (fitFile);
  
TCanvas *c3 = new TCanvas("c3","Landau Fits",1600,900);
c3->SetLogy();	
c3->Divide(5,5);										
Int_t mean,rms,c;
Double_t width;	

Int_t i=12;
for(Int_t i=0;i<25;i++)
{
	if(gain==0)
	{
		sprintf(name,"ENERGY_HG1_add_cosmics_cond%02d",i);
	}

	if(gain==1)
	{
		sprintf(name,"ENERGY_HG2_add_cosmics_cond%02d",i);
	}
	
	TH1F *his=(TH1F *) TD->Get(name);
	c3->cd(i+1);
	his->GetXaxis()->SetTitle("Energy / a.u.");
	his->GetYaxis()->SetTitle("Counts");
	cout<<his->GetEntries()<<endl;		 
	his->Rebin(40);  									//2
	his->GetXaxis()->SetRangeUser(500, 5000);

	his->Draw();		

	mean=his->GetMean();
	rms=his->GetRMS();		
	width=rms/2;
	TF1 *fit0=new TF1("fit0","landau",1200,3000);
	fit0->SetParameter(0,his->GetBinContent(mean));
	fit0->SetParameter(1,mean);
	fit0->SetParameter(2,width);
	his->Fit(fit0,"WW0q,REM");

	//output:
	textfile << i <<""<<fit->GetParameter(0)<<""<<fit->GetParameter(1)<<""<<fit->GetParameter(2)<<""<<fit->GetParameter(3)<<"\n";
	peak[i]=abs(fit->GetParameter(1));
	sigma[i]=abs(fit->GetParameter(2));
	peak_error[i]=abs(fit->GetParError(1));
	sigma_error[i]=abs(fit->GetParError(2)); 
}

textfile.close();
cout <<"Textfile "<<fitFile<<" with fitparameters created!"<<endl;
cout<<"Fit finished!"<<endl;

return 0;

}[/code]

Anybody an idea ? Thank you in advance!

you have sub-pads. You should set the log scale on the sub-pads not on the canvas.
On which sub-pad do you way to have a log scale ?

for instance replace:

c3->cd(i+1);

by:

c3->cd(i+1)->SetLogy();

and all the sub-pads will have a log scale along y.

Thank you very much!

I just wonder why it worked in previous programs where I did quite the same (where also a lot of sub-pads were present)… anyhow, thank you :exclamation:

Surely you did something a bit different … :slight_smile: