Fitting histo using crystalball

Hi everyone,
I realized that’s not work to fit histogram using crystalball function just by doing like that:

 TF1 *fit = new TF1("fit","crystalball_function");

even if this works for gaussian function.
So I was trying to do it by using roofit but didn’t have what I expected, here is my code for instance.

TFile* f0   = new TFile("nominal_signalDistributions_20170217.root");
 TH1F * chan_15GeV   = (TH1F*)f0->Get("chan_0_hist_150");
 // Declare observable x
 RooRealVar x("x","x",12,16.5) ;

   // Create a binned dataset that imports contents of TH1 and associates its contents to observable 'x'
  RooDataHist dh("dh","dh",x,Import(*chan_15GeV));
RooPlot* frame = x.frame(Title("Imported TH1 with internal errors")) ;

  // Fit a Gaussian p.d.f to the data
  RooRealVar cbmean("mean","mean",0,12,16.5);
  RooRealVar cbsigma("sigma","sigma",3,0.1,16.5);
  RooRealVar cbn("cb n","cb_n",3.6,0.1,100.);
  RooRealVar cbalpha("cb alpha","cb_alpha",1,0.1,16.5.);
  RooCBShape cb("cb","cb",x,cbmean,cbsigma,cbalpha,cbn) ;

and I got almost a horizontal blue line that’s nothing to do with the shape of the histogram, that I attached here.
Could someone tell me what I did wrong please.


It works in ROOT using
TF1 *fit = new TF1("fit","crystalball"); fit->SetParameters(p1,p2,p3,p4,p5); chan_15GeV->Fit(fit);

and you need to set reasonable initial parameter values (p1,…p5) depending on your histogram

Best Regards


Hi Lorenzo,
Thanks so much, I just saw your message.

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