Problem with root Landau fitting macro

Hi

This is my macro:

#include <TMath.h>

Double_t fitf(Double_t *v, Double_t par) {
Double_t arg = 0;
if (par[2] != 0) arg = (v[0] - par[1])/par[2];
Double_t fitval = par[0]TMath::Landau(-0.5arg
arg));
return fitval;
}

void land1() {

  TFile *f = new TFile("tot2z.root");
  TH1F *h1001 = (TH1F*)f->Get("h1001");
  TF1 *func = new TF1("fit",fitf,3,3,3);
  
  func->SetParameters(500,h1001->GetMean(),h1001->GetRMS());
  func->SetParNames("Constant","Mean_value","Sigma");
  h1001->Fit("fit");

}

and all I see is my data points and a function ruining on 0. Can someone point out my mistakes ?

greetings

Jacek

Hi,

Your macro seems fine, it could be that the initial parameter are too far away from the solution or the function is not the right one for fitting your data.
Why are you doing the transformation x -> 0.5*[(x-m)/s]**2 ? You can use also the location and the scale parameter of TMath::Landau(x,m,s).
To help you more, I would need your root file with the histogram,

Regards
Lorenzo

thank you!

I solved the problem, the new macro looks like this:

Double_t par[3],chisquare;
//TH2F *h3001;

void land2() {

  TFile *f = new TFile("tot2z.root");
  TH1F *h1001 = (TH1F*)f->Get("h1001");
  land = new TF1("land", "landau(0)",200,800);
  land->GetParameters(&par[0]);
  //land->GetParameters(&par[1]);
  //land->GetParameters(&par[2]); 

  land->SetParameters(500,h1001->GetMean(),h1001->GetRMS());
  //land>SetParNames("Constant","Mean_value","Sigma");

  h1001->Fit("land");

}

greetings

Jacek