Fit a histogram to ROOT::Math::crystalball_function with 4 free parameters

Hi every body,
I try to fit crystal ball function to my data. I used ROOT::Math::crystalball_function. but it just give me a line! I don’t know how I could get correct fit. Any help is appreciated.
this is my root file
eantie.root (242.2 KB)

this is my code:

TH1F* createHist(TString fileName, TString branchName);
Double_t CrystalBall(Double_t *x, Double_t *par);
Double_t m_mean;
void detectorResponse_2() {
TCanvas *convas = new TCanvas(“convas”, “etac mass in Gev”, 800, 1000);
gStyle->SetOptFit(1111);
TH1F *eantieHist = createHist(“eantie.root”,“gamma_recoil_mass”);
eantieHist->SetLineColor(kBlue);
eantieHist->SetOption(“E1”);
m_mean = eantieHist->GetMean();

TF1 *fitFunction = new TF1(“fitFunction”, CrystalBall, 2.7, 3.2, 4);
eantieHist->Fit(“fitFunction”);
}

TH1F* createHist(TString fileName, TString branchName) {

TFile *file = new TFile(fileName);
TTree fit4c = (TTree)file->Get(“photon”);
Double_t metac;
fit4c->SetBranchAddress(branchName,&metac);

//create one histogram
TH1F *hist = new TH1F(“gamma recoil mass”,“gamma recoil mass”,100,2.7,3.2);

Int_t nentries = (Int_t)fit4c->GetEntries();
for (Int_t i=0;i<nentries;i++) {
fit4c->GetEntry(i);
//fill the histogram with the destep entry
hist->Fill(metac);
}
return (hist);
}

Double_t CrystalBall(Double_t *x, Double_t *par) {
return ROOT::Math::crystalball_function(x[0], par[0], par[1], par[2], par[3]);
}


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


HI,

You need to set meaningful initial parameters for the function, otherwise by default will be zero.
For example do:

fitFunction->SetParameters(1,2,1,1,0)

For the parameter definition see

Lorenzo

1 Like

Hi,
thanks a lot Moneta. I got it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.