Derive my own RooChi2Var

Dear Roofit users!
I would like to ask for your help, just to sketch the solution of the following problem.
I have to make a simultaneous fit of two data objects: RooDataHist and RooDataHist with two model objects: RooAddPdf and some derived class fromRooAbsReal (see attached picture for illustration). How do I make this? RooSimultaneous allows only AddPdf method.
Probably I have to define a sum of chi-2 for the first and second functions as a separate class. What should this class be derived from? If this is RooChi2Var, I still don’t understand what function(s) should I overload in there.
Any your thoughts and drafts are greatly appreciated.
Thank you.


It seems that the following code does work as expected:

   RooAbsReal* chi21 = model1.createChi2(*data1);
   RooAbsReal* chi22 = model2.createChi2(*data2);
   RooAddition chisum("chisum","",RooArgSet(*chi21,*chi22));
   RooMinuit* m = new RooMinuit(chisum);
   m->migrad();