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;
}