How to define a function to work with TF1 and Fit

Hi I’m using the latest root version integrated in anaconda as I want to use PyROOT. I have a problem when I try to generate a TF1 function from a python defined function.

First of all I define my function in python (gaussian function with linear background):

def gauss_lbg(x, par, gBinW=1): #we assume that bin width is 1 by default
    # par[0]	background constant
    # par[1]	background slope
    # par[2]	gauss width
    # par[3]	gauss constant
    # par[4]	gauss mean
    sqrt2pi , sqrt2 = np.sqrt(2*np.pi) , np.sqrt(2)
    if par[2] == 0: par[2]=1
    arg = (x[0] - par[4])/(sqrt2*par[2])
    return par[0] + x[0]*par[1] + gBinW/(sqrt2pi*par[2]) * par[3] * np.exp(-arg*arg)

After that I generate another python function to make my fits that involves a TF1 ROOT function, but when I run my code it gives me an error just in that line of the code

...
gauss_linbg_fit = ROOT.TF1('gauss_linear_background', gauss_lbg(), peak_left_min_bin, peak_right_min_bin, 5)
...

TypeError: gauss_lbg() missing 2 required positional arguments: ‘x’ and ‘par’

It seems that ROOT.TF1 don’t work with python defined functions, can you help me to solve that? I also have the same function defined in C++, but I don’t know how to integrate it in my python code.

Thanks for your help!

Hello,

You need to pass the Python callable gauss_lbg as argument of the TF1 constructor (right now you are calling it with no arguments, hence the error related to the arguments):

gauss_linbg_fit = ROOT.TF1('gauss_linear_background', gauss_lbg, peak_left_min_bin, peak_right_min_bin, 5)

Here there are some examples:

Thanks for your answer @etejedor. I’m sorry but I don’t know very well how to fix that with those examples, could you explain it a bit more please?

In the other hand, if I pass the python callable gauss_lbg without parenthesis like you write before the example, I get: *** Break *** segmentation violation, a lot of errors and python crash.

Hello,

This is the closest example to what you are doing:

See how it passes the function below to the TF1 constructor:

What is exactly the reproducer code that causes the error? If I just run what you posted (with the modification of not calling gauss_lbg, I don’t see any crash.

Hello and thanks for your reply @etejedor , I’ll attach a piece of the code and a small piece of the data but is enough to reproduce the crash.

Calib_201123_131528_histos.root (1.4 MB)
multifit_test.py (13.6 KB)

You can ignore all de code above line 203, which is data processing and the peak finder, below line 203 starts the gaussian fitting code. In 209 I define my gaussian function, then in 221 I define my peakfit function, TF1 is defined in line 240.

To reproduce the crash, just put both files in the same folder, run: python -i multifit_test.py let the program do the stuff for some seconds and when it finish just call the FitSinglePeak function like this (for example):

FitSinglePeak(DSSD1_H[1], Gd_peak[1][1][0][0])

I get a break segmentation violation when I do that.

Just to let you know, if I define my function like this:

gauss_linbg_fit = ROOT.TF1('gauss_linear_background', 
                                '[0] + x*[1] + 1/(TMath::Sqrt(2*TMath::Pi())*[2]) * [3] * TMath::Exp(-((x - [4])/(TMath::Sqrt(2.)*[2]))*((x - [4])/(TMath::Sqrt(2.)*[2])))',
                                peak_left_min_bin, peak_right_min_bin)

My code run perfectly, and FitSinglePeak function works well and I get this plot:

This works, but I really need that python defined functions work because It’s much easier for me to define more complex function in that way.

Thank you again for your time and help!

Hello,

I ran your code but I can’t reproduce the crash, everything seems fine:

$ python3 -i multifit_test.py 
Program started at: 13:35:36
File readed

 Creating empty histograms: 
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 32/32 [00:00<00:00, 748.67it/s]
OK Empty histograms created

 Getting histograms from histos.root
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 32/32 [00:01<00:00, 25.13it/s]
OK  New histos get from histos.root 

Finding peaks on each histogram
  0%|                                                                                                                                                                                | 0/32 [00:00<?, ?it/s]Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
  3%|█████▎                                                                                                                                                                  | 1/32 [00:00<00:12,  2.47it/s]TSpectrum::SearchHighRes:0: RuntimeWarning: Peak buffer full
 16%|██████████████████████████▎                                                                                                                                             | 5/32 [00:01<00:07,  3.57it/s]TSpectrum::SearchHighRes:0: RuntimeWarning: Peak buffer full
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 32/32 [00:04<00:00,  6.44it/s]

 OK All peaks have been found
>>> FitSinglePeak(DSSD1_H[1], Gd_peak[1][1][0][0])


	 Chi Square: 86.972830 
	 FWHM: 25.304986 +- 0.691178 
	 Position: 1056.879644 +- 0.311120 
	 Area: 3040.410168 +- 96.879836 
	 Sigma: 10.746038 +- 0.293516 


(1056.8796441685383, <cppyy.gbl.TF1 object at 0x9981e70>, <cppyy.gbl.TF1 object at 0x99b67a0>)

I also get the exact same plot you posted.

What ROOT version are you using? I tried with current master, but you can also try with ROOT 6.22/06 . We released new PyROOT bindings in 6.22 that fix a number of issues.

Thats exactly the output I want! T.T
I’m using M1 Mac with mambaforge installed and root as conda-forge package. Here you have the versions of root that I get from conda list:


I’m running it in python 3.9.1 shell.

This is the error I have when I run exactly the same script that I uploaded before:

Program started at: 14:13:38
File readed

 Creating empty histograms: 
100%|███████████████████████████████████████████████████████████████| 32/32 [00:00<00:00, 3939.35it/s]
OK Empty histograms created

 Getting histograms from histos.root
100%|█████████████████████████████████████████████████████████████████| 32/32 [00:00<00:00, 94.78it/s]
OK  New histos get from histos.root 

Finding peaks on each histogram
  0%|                                                                          | 0/32 [00:00<?, ?it/s]Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
  3%|██                                                                | 1/32 [00:00<00:12,  2.40it/s]TSpectrum::SearchHighRes:0: RuntimeWarning: Peak buffer full
 12%|████████▎                                                         | 4/32 [00:00<00:08,  3.31it/s]TSpectrum::SearchHighRes:0: RuntimeWarning: Peak buffer full
100%|█████████████████████████████████████████████████████████████████| 32/32 [00:01<00:00, 30.23it/s]

 OK All peaks have been found
Calculating peaks positions with gaussian fitting
  0%|                                                                           | 0/8 [00:00<?, ?it/s] *** Break *** segmentation violation
[/Users/vicentegt/mambaforge/lib/libCore.6.22.06.so] TUnixSystem::DispatchSignals(ESignals) (no debug info)
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::RuntimeDyldMachOAArch64::processRelocationRef(unsigned int, llvm::object::content_iterator<llvm::object::RelocationRef>, llvm::object::ObjectFile const&, std::__1::map<llvm::object::SectionRef, unsigned int, std::__1::less<llvm::object::SectionRef>, std::__1::allocator<std::__1::pair<llvm::object::SectionRef const, unsigned int> > >&, std::__1::map<llvm::RelocationValueRef, unsigned long, std::__1::less<llvm::RelocationValueRef>, std::__1::allocator<std::__1::pair<llvm::RelocationValueRef const, unsigned long> > >&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::RuntimeDyldImpl::loadObjectImpl(llvm::object::ObjectFile const&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::RuntimeDyldMachO::loadObject(llvm::object::ObjectFile const&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::RuntimeDyld::loadObject(llvm::object::ObjectFile const&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::orc::RTDyldObjectLinkingLayer::ConcreteLinkedObject<std::__1::shared_ptr<llvm::RuntimeDyld::MemoryManager>, std::__1::shared_ptr<llvm::JITSymbolResolver>, llvm::orc::RTDyldObjectLinkingLayer::addObject(std::__1::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile> >, std::__1::shared_ptr<llvm::JITSymbolResolver>)::'lambda'(std::__1::__list_iterator<std::__1::unique_ptr<llvm::orc::RTDyldObjectLinkingLayerBase::LinkedObject, std::__1::default_delete<llvm::orc::RTDyldObjectLinkingLayerBase::LinkedObject> >, void*>, llvm::RuntimeDyld&, std::__1::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile> > const&, std::__1::function<void ()>)>::finalize() (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::orc::RTDyldObjectLinkingLayer::ConcreteLinkedObject<std::__1::shared_ptr<llvm::RuntimeDyld::MemoryManager>, std::__1::shared_ptr<llvm::JITSymbolResolver>, llvm::orc::RTDyldObjectLinkingLayer::addObject(std::__1::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile> >, std::__1::shared_ptr<llvm::JITSymbolResolver>)::'lambda'(std::__1::__list_iterator<std::__1::unique_ptr<llvm::orc::RTDyldObjectLinkingLayerBase::LinkedObject, std::__1::default_delete<llvm::orc::RTDyldObjectLinkingLayerBase::LinkedObject> >, void*>, llvm::RuntimeDyld&, std::__1::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile> > const&, std::__1::function<void ()>)>::getSymbolMaterializer(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'()::operator()() const (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::orc::LazyEmittingLayer<llvm::orc::IRCompileLayer<cling::IncrementalJIT::RemovableObjectLinkingLayer, llvm::orc::SimpleCompiler> >::EmissionDeferredModule::find(llvm::StringRef, bool, llvm::orc::IRCompileLayer<cling::IncrementalJIT::RemovableObjectLinkingLayer, llvm::orc::SimpleCompiler>&)::'lambda'()::operator()() const (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] cling::IncrementalJIT::getSymbolAddress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] cling::IncrementalExecutor::getAddressOfGlobal(llvm::StringRef, bool*) const (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] PyFunction_AsCPointer(_object*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::(anonymous namespace)::FunctionPointerConverter::SetArg(_object*, CPyCppyy::Parameter&, CPyCppyy::CallContext*) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPMethod::ConvertAndSetArgs(_object*, CPyCppyy::CallContext*) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPConstructor::Call(CPyCppyy::CPPInstance*&, _object*, _object*, CPyCppyy::CallContext*) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::(anonymous namespace)::mp_call(CPyCppyy::CPPOverload*, _object*, _object*) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::tpp_call(CPyCppyy::TemplateProxy*, _object*, _object*) (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyObject_Call (no debug info)
[/Users/vicentegt/mambaforge/bin/python] slot_tp_init (no debug info)
[/Users/vicentegt/mambaforge/bin/python] type_call (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyObject_MakeTpCall (no debug info)
[/Users/vicentegt/mambaforge/bin/python] call_function (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyEval_EvalCode (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyFunction_Vectorcall (no debug info)
[/Users/vicentegt/mambaforge/bin/python] call_function (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyEval_EvalCode (no debug info)
[/Users/vicentegt/mambaforge/bin/python] PyRun_FileExFlags (no debug info)
[/Users/vicentegt/mambaforge/bin/python] PyRun_SimpleFileExFlags (no debug info)
[/Users/vicentegt/mambaforge/bin/python] Py_RunMain (no debug info)
[/Users/vicentegt/mambaforge/bin/python] pymain_main (no debug info)
[/Users/vicentegt/mambaforge/bin/python] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
 *** Break *** segmentation violation
[/Users/vicentegt/mambaforge/lib/libCore.6.22.06.so] TUnixSystem::DispatchSignals(ESignals) (no debug info)
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::RuntimeDyldMachOAArch64::processRelocationRef(unsigned int, llvm::object::content_iterator<llvm::object::RelocationRef>, llvm::object::ObjectFile const&, std::__1::map<llvm::object::SectionRef, unsigned int, std::__1::less<llvm::object::SectionRef>, std::__1::allocator<std::__1::pair<llvm::object::SectionRef const, unsigned int> > >&, std::__1::map<llvm::RelocationValueRef, unsigned long, std::__1::less<llvm::RelocationValueRef>, std::__1::allocator<std::__1::pair<llvm::RelocationValueRef const, unsigned long> > >&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::RuntimeDyldImpl::loadObjectImpl(llvm::object::ObjectFile const&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::RuntimeDyldMachO::loadObject(llvm::object::ObjectFile const&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::RuntimeDyld::loadObject(llvm::object::ObjectFile const&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::orc::RTDyldObjectLinkingLayer::ConcreteLinkedObject<std::__1::shared_ptr<llvm::RuntimeDyld::MemoryManager>, std::__1::shared_ptr<llvm::JITSymbolResolver>, llvm::orc::RTDyldObjectLinkingLayer::addObject(std::__1::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile> >, std::__1::shared_ptr<llvm::JITSymbolResolver>)::'lambda'(std::__1::__list_iterator<std::__1::unique_ptr<llvm::orc::RTDyldObjectLinkingLayerBase::LinkedObject, std::__1::default_delete<llvm::orc::RTDyldObjectLinkingLayerBase::LinkedObject> >, void*>, llvm::RuntimeDyld&, std::__1::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile> > const&, std::__1::function<void ()>)>::finalize() (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::orc::RTDyldObjectLinkingLayer::ConcreteLinkedObject<std::__1::shared_ptr<llvm::RuntimeDyld::MemoryManager>, std::__1::shared_ptr<llvm::JITSymbolResolver>, llvm::orc::RTDyldObjectLinkingLayer::addObject(std::__1::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile> >, std::__1::shared_ptr<llvm::JITSymbolResolver>)::'lambda'(std::__1::__list_iterator<std::__1::unique_ptr<llvm::orc::RTDyldObjectLinkingLayerBase::LinkedObject, std::__1::default_delete<llvm::orc::RTDyldObjectLinkingLayerBase::LinkedObject> >, void*>, llvm::RuntimeDyld&, std::__1::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile> > const&, std::__1::function<void ()>)>::getSymbolMaterializer(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'()::operator()() const (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] llvm::orc::LazyEmittingLayer<llvm::orc::IRCompileLayer<cling::IncrementalJIT::RemovableObjectLinkingLayer, llvm::orc::SimpleCompiler> >::EmissionDeferredModule::find(llvm::StringRef, bool, llvm::orc::IRCompileLayer<cling::IncrementalJIT::RemovableObjectLinkingLayer, llvm::orc::SimpleCompiler>&)::'lambda'()::operator()() const (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] cling::IncrementalJIT::getSymbolAddress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) (no debug info)
[/Users/vicentegt/mambaforge/lib/libCling.6.22.06.so] cling::IncrementalExecutor::getAddressOfGlobal(llvm::StringRef, bool*) const (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] PyFunction_AsCPointer(_object*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::(anonymous namespace)::FunctionPointerConverter::SetArg(_object*, CPyCppyy::Parameter&, CPyCppyy::CallContext*) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPMethod::ConvertAndSetArgs(_object*, CPyCppyy::CallContext*) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPConstructor::Call(CPyCppyy::CPPInstance*&, _object*, _object*, CPyCppyy::CallContext*) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::(anonymous namespace)::mp_call(CPyCppyy::CPPOverload*, _object*, _object*) (no debug info)
[/Users/vicentegt/mambaforge/lib/libcppyy3_9.6.22.06.so] CPyCppyy::tpp_call(CPyCppyy::TemplateProxy*, _object*, _object*) (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyObject_Call (no debug info)
[/Users/vicentegt/mambaforge/bin/python] slot_tp_init (no debug info)
[/Users/vicentegt/mambaforge/bin/python] type_call (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyObject_MakeTpCall (no debug info)
[/Users/vicentegt/mambaforge/bin/python] call_function (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyEval_EvalCode (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyFunction_Vectorcall (no debug info)
[/Users/vicentegt/mambaforge/bin/python] call_function (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/vicentegt/mambaforge/bin/python] _PyEval_EvalCode (no debug info)
[/Users/vicentegt/mambaforge/bin/python] PyRun_FileExFlags (no debug info)
[/Users/vicentegt/mambaforge/bin/python] PyRun_SimpleFileExFlags (no debug info)
[/Users/vicentegt/mambaforge/bin/python] Py_RunMain (no debug info)
[/Users/vicentegt/mambaforge/bin/python] pymain_main (no debug info)
[/Users/vicentegt/mambaforge/bin/python] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
(base) vicentegt@arm64-apple-darwin20:~/Downloads% /Users/vicentegt/mambaforge/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

You are using a recent ROOT then, perhaps it’s an issue with Python3.9?

Also, this message:

Calculating peaks positions with gaussian fitting

I don’t see it in my output, and it seems to come right before the crash. Wasn’t this line:

>>> FitSinglePeak(DSSD1_H[1], Gd_peak[1][1][0][0])

the one that causes the crash? I don’t see that you ran it in the crash output you just showed.

This is because I just added 2 final lanes to the script that I uploaded before.

print('Calculating peaks positions with gaussian fitting')
FitSinglePeak(DSSD1_H[1], Gd_peak[1][1][0][0])

Just to not write the same commands all time in shell.

Which python version did you used when you tested my script? That could be the point.

I’m pretty sure now that it isn’t code problem, as you could run the script without problems, but I’m not sure what could we do to fix it.

It’s kind of embarrassing (:sweat_smile:) taking a lot of your time to help me to solve that. I’m sorry.

No problem at all! We are here for that.

So I tried to replicate your same environment. I created a conda environment with ROOT 6.22.6 as you did. I tried again your code, it still succeeds. The only difference at this point is that I’m using Python3.8.6 and you are using Python3.9. Can you try creating a conda environment with Python3.8.6 and ROOT 6.22.6?

Yes of course, but it probably take me a while. Are you testing in arm too? I have other pc with linux with python 3.9.1, I can also test my script there. I’ll give you my feedback as soon as test both.

Thank you very much!

You MUST use EXACTLY the same python version (and the same compiler) that your ROOT binaries were built for (otherwise, expect mysterious crashes anywhere, anytime):

root-config --python-version # C/C++ calling python
root-config --python2-version # python 2 calling C/C++
root-config --python3-version # python 3 calling C/C++

BTW. Do also remember that the “conda-forge” and “defaults” channels are not 100% compatible (expect errors when the install environment is mixing packages from multiple channels).

If you installed ROOT via conda, you should also use the conda Python (which ROOT was built with).

It shouldn’t take you much time, just do:

conda create -c conda-forge --name root_622 root

and run your script (I think you’ll need to install pandas and tqdm too in the env - conda install tqdm pandas)

Hi, sorry for the delay I just had a meeting. Well I could do some test all with the same script that I uploaded some messages ago using root 6.22.6.

  1. Linux pc with intel processor in anaconda environment with python 3.8.6 → :white_check_mark: Everything works
  2. Linux pc with intel processor in anaconda environment with python 3.9.1 → :white_check_mark: Everything works
  3. MacBook Pro with M1 processor (ARM) using mambaforge (instead of anaconda) which is arm compatible with python 3.9.1 → :x: I get the error that I posted before.
  4. MacBook Pro with M1 processor (ARM) using mambaforge with python 3.8.6 → :x: I get the error that I posted before.

So It seems that it’s because mambaforge or maybe ARM architecture. I’m not sure if miniconda works on arm macbooks, I could test it using miniconda instead mambaforge. What do you recommend me? Could you test my script with an arm macbook? If it works, which configuration do you have? (miniconda, anaconda, mambaforge, miniforge…¿? )

Thank you for your help, it seems new macbooks still have some compatibility issues. But this concrete issue seems very strange for me.

Hello,

I tried on a MacOS (Intel processor) and everything runs fine, but I do see the same LLVM failure you reported in one of our build nodes that is Mac11 ARM (@Axel can perhaps comment).

For the moment, if you also have a Linux Intel machine, I would suggest you use that.

The point is that my Intel pc with Linux is like 10 years old, so I can’t really work fine with it. Anyway if I change the way I define my function from this:

def gauss_lbg(x, par): #we assume that bin width is 1 by default
    # par[0]	background constant
    # par[1]	background slope
    # par[2]	gauss width
    # par[3]	gauss constant
    # par[4]	gauss mean
    sqrt2pi , sqrt2 = np.sqrt(2*np.pi) , np.sqrt(2)
    if par[2] == 0: par[2]=1
    arg = (x[0] - par[4])/(sqrt2*par[2])
    return par[0] + x[0]*par[1] + 1/(sqrt2pi*par[2]) * par[3] * np.exp(-arg*arg)

gauss_linbg_fit = ROOT.TF1('gauss_linear_background', gauss_lbg, peak_left_min_bin, peak_right_min_bin, 5)

To that:

gauss_linbg_fit = ROOT.TF1('gauss_linear_background', 
                                '[0] + x*[1] + 1/(TMath::Sqrt(2*TMath::Pi())*[2]) * [3] * TMath::Exp(-((x - [4])/(TMath::Sqrt(2.)*[2]))*((x - [4])/(TMath::Sqrt(2.)*[2])))',
                                peak_left_min_bin, peak_right_min_bin)

Everything works function fits and plot with same accuracy, the point is that maybe solve that issue will help me and other users if we try more complex functions.

At least we identified the problem, which is any issue related to arm o mac11OS, I’m actually using BigSur 11.1. Anything I could help to fix this please tell me :smile:

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