Problem with the definition of a function for fitting

dear rooters,

I have a problem with this code. I don’t see any problem in it, but it doesn’t compile. I would like to try to fit my datas with a Crystal Ball function, as I have datas wich are negatively skewed; and I am looking for a distribution which has a significant negative skewness.

Thanks a lot, regards

Jean-Philippe
check_statistics.C (6.99 KB)

In order to find source code bugs, always try to precompile your code using ACLiC (even if you plan to use it as an interpreted macro) using something like:
root [0] .L check_statistics.C++

  1. “**” is not a proper C/C++ power operator, you should use std::pow or TMath::Power.
  2. “… TMath::(1+ …” make no sense
  3. you will need at least:
    #include “TH1.h”
    #include “TMath.h”
    #include “TCanvas.h”
    #include “TStyle.h”
    #include “TF1.h”
    #include “TRandom3.h”
    #include
    #include
    #include

thanks for your fast reply. I didn’t know that I need to specify the libraries as in a classic C++ code, because before, using in built-functions (Gaussians to be more precise) for the fitting, it worked perfectly. I know that ** is not a C/C++ operator but I thought that it is used in root like x**2 for Pow(x,2).
I will try to bring the modifications that you propose me.

I brought the modifications that you propose me, it compiles perfectly. However, I got a problem at the execution, it tells me :
"Warning in TCanvas::ResizePad: Inf/NaN propagated to the pad. Check drawn objects.
Warning in TCanvas::ResizePad: c1 height changed from 0 to 10

root [1] Warning in TCanvas::ResizePad: Inf/NaN propagated to the pad. Check drawn objects.
Warning in TCanvas::ResizePad: c1 height changed from 0 to 10

Warning in TCanvas::ResizePad: Inf/NaN propagated to the pad. Check drawn objects.
Warning in TCanvas::ResizePad: c1 height changed from 0 to 10"

Please find attached the code that I have now. If I remove the 4 (number of parameters of the function that I call) in the definition of the TF1 : " TF1* fit1 = new TF1(“crystal”,crystalballfunction,5,10,4); " ; it gives me a segmentation fault and crashes.

Is there something that I missed ?

Thanks in advance, regards

Jean-Philippe
check_statistics.C (7.2 KB)

I don’t have your data files, so I cannot try it.
I noticed one thing. You do not set initial values for functions’ parameters before you try to fit your histograms (after “f = new TF1” and before “h->Fit”, you need to “f->SetParameters”).

yes you are right, I can try to assign starting values, even though I have actually no idea of what starting values to choose. Here is one data file that I used, the one for which I try this complex function for fitting.

Thanks for your help,

Jean-Philippe
diskmasses1.txt (449 Bytes)

You probably do not need to care about “gaus” functions (ROOT will try to find appropriate initial parameters itself) but you definitely need to care about your “crystal” function.

Two notes about your histograms:

  1. the “names” of ROOT objects should be “simple identifiers” (the “titles” can be anything), so you should have something like:
    TH1D *h1 = new TH1D(“h1”, “Log(M_d) distribution first dataset;disk masses;# occurrences”, 50, 3. 10.);
  2. the peak in “diskmasses1.txt” is very sharp (possibly in another data files it’s the same) so I think you should add the “I” option to all fits