# Why Landau fitting not working

I am trying Landau fit but the location of the fitting peak shifted towards right. And change of the fitted function range also not working . When I change the fitting range I always getting same mean value 6.61.
I am getting chisq/dof: 3.7104 for this fitting.
Here is my code :
void LandauFit()
{
// Open the ROOT file
TFile *file = TFile::Open(“output0.root”);

``````// Access the "Photons" tree
TTree *tree = (TTree*)file->Get("Photons");

// Create a histogram to hold the data from the "fT" branch
TH1F *histogram = new TH1F("histogram", "fT Branch", 103, -3, 100);

// Fill the histogram with data from the "fT" branch
tree->Draw("fT >> histogram");

// Create a Landau function
TF1 *landauFunc = new TF1("landauFunc", "landau", -5, 100);
landauFunc->SetParameter(1, 20); // Adjust the initial peak position

// Fit the histogram with the Landau function
histogram->Fit("landauFunc");

// Get the mean value from the fit
Double_t mean = landauFunc->GetParameter(1);

// Get the chi-square value
``````

Double_t chiSquare = landauFunc->GetChisquare();

// Get the degrees of freedom (number of data points minus the number of fit parameters)
Int_t dof = landauFunc->GetNDF();

// Calculate chisq/dof
Double_t chisqOverDof = chiSquare / dof;

// Print chisq/dof
cout << "chisq/dof: " << chisqOverDof << endl;

``````// Print the mean
cout << "Mean: " << mean << endl;
``````

}

Hi @iamaanand; maybe @jonas and/or @moneta can help here.

Cheers,
J.

Hi,

Your underlined distribution for your histogram does not look to me to be a Landau, your are missing the negative part (i.e. the part before the Landau peak). It is probably a different distribution, maybe a Gamma distribution?

Lorenzo

1 Like

Ok. @moneta I want to fit it with best possible distribution function. Yes, it also look like Gamma distribution. Can you tell me how to fit this distribution. What function I must define?

Hi,
For the Gamma you can use `ROOT::Math::gamma_pdf`.
You can then create a TF1 for fitting as following:

``````auto f1 = new TF1("f1","*ROOT::Math::gamma_pdf(x,,,)",0,100);
f1->SetParameters(100,2,10,0);
f2->Draw();
``````

Lorenzo

2 Likes