TH1::FIT (Fitting a user defined function)

Hi.

based on the myfit.C tutorial, in order to fit an “experimental” histogram to a pretty complicated model (12 parameters), i have written the attached code.

the fit function, pBSim, needs the objects and variables which are defined between the “<<< START HERE” and the “<<< STOP HERE” comment lines. However, these definitions are needlessly performed each and every time the function is called. Basically, they can be defined in the void pBfit() function, but then i pBSim couldn’t access them…
Im not only new to ROOT but also to C++. :blush:

My Question Is: how do i make these definitions outside the function so that the objects will “live” also in the scope of the function? (or any other idea is welcome).

Thanks in advance, :slight_smile:
Moshe (PSI, Switzerland)
pBfit.C (2.49 KB)

I do not understand what you try to do with your pBsim function and Graphmuonprofile. Anyway, you can recode your example as shown in the attachement

Rene
pBfit.C (2.57 KB)

pBsim is the probability that (in a muSR experiment) the muon will stop in the sample at a field B.

Graphmuonprofile is just the implantation profile of the muons in the sample (low energy muons).

your code is indeed the programmatic solution to the problem. i forgot that one can declare variables and classes for “future use”. However, since pBsim has statistical nature (it is a simulation), minunit won’t converge. i have since tried a different approach and it worked.

Thanks a lot.