# Simultaneous hist fit; ROOT::Math::IMultiGenFunction trouble

**URL:** <https://root-forum.cern.ch/t/simultaneous-hist-fit-root-math-imultigenfunction-trouble/14668>\
**Category:** Roofit and RooStats\
**Created:** [July 30, 2012, 2:43pm UTC](https://root-forum.cern.ch/t/simultaneous-hist-fit-root-math-imultigenfunction-trouble/14668 "2012-07-30T14:43:45Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pibion](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pibion/32/11745_2.png) [@pibion](https://root-forum.cern.ch/u/pibion)\
**Post date:** [July 30, 2012, 2:43pm UTC](https://root-forum.cern.ch/t/simultaneous-hist-fit-root-math-imultigenfunction-trouble/14668/1 "2012-07-30T14:43:45Z")

</div>

Hello ROOTers,

I am trying to fit several histograms simultaneously, and originally used code directly adapted from the example at [http://root.cern.ch/root/html/tutorials/fit/combinedFit.C.html](http://root.cern.ch/root/html/tutorials/fit/combinedFit.C.html).

Now I need to use quite a few more histograms and functions, and I’d really like to avoid passing each function by hand. I’ve tried to adapt the code so that I pass the GlobalChi2 struct a container of pointers to ROOT::Math::IMultiGenFunction objects instead of passing each ROOT::Math::IMultiGenFunction explicitly, but I’m running into problems.

In the orignal code, objects of type ROOT::Fit::Chi2Function were created in the main body of the function and passed by reference to a struct calling for ROOT::Math::IMultiGenFunction objects. But when I pass by reference a container of ROOT::Fit::Chi2Function \* to a struct expecting a container of ROOT::Math::IMultiGenFunction \*, I get an error:

[quote]error: no matching function for call to ‘GlobalChi2::GlobalChi2(std::vector\<ROOT::Fit::Chi2Function\*, std::allocatorROOT::Fit::Chi2Function\* \>&)’  
/afs/crc.nd.edu/user/a/arobert4/neutwall.git/3He26Mg\_analysis/fit/combinedFit\_vec.C:37: note: candidates are: GlobalChi2::GlobalChi2(std::vector\<ROOT::Math::IMultiGenFunction\*, std::allocatorROOT::Math::IMultiGenFunction\* \>&)[/quote]

I’m not sure how to fix this. Making containers of the objects themselves fails because ROOT::Fit::Chi2Function doesn’t have an assignment operator. As far as I can tell, I need to make a container of pointers.

My understanding is that these two different types are necessary - the ROOT::Fit::Chi2Function can accept data and a function, while the ROOT::Math::IMultiGenFunction allows me to define the () operator, necessary for the fitter.

I’ve also explored fixing this by passing the fitter a vector of structs, where each struct takes a function. But I’m really not sure how to make this work with the call to the ROOT::Fit::Fitter; I can’t seem to match the function call the original code is making with anything in the documentation.

The version of ROOT I’m using is 5.30, running on linux with x86\_64 architecture.

Many thanks for your time!  
[combinedFit\_vec\_simple.C](https://root-forum.cern.ch/uploads/default/original/2X/5/545c154bc36c872bb985c7c51484dcff69bd88c2.C) (2.76 KB)

---

_[View the full topic](https://root-forum.cern.ch/t/simultaneous-hist-fit-root-math-imultigenfunction-trouble/14668)._
