# "Custom" likelihood definition

Dear all,

I’m trying to find out a way to add “relations” between the coefficients of a RooAddPdf.
(Probably my question is wrong in terms of RooFit, but let me explain my issue, maybe it’s clear what I mean).

Currently I’m performing an unbinned EML in 2D with 3 PDFs, yielding 3 event counts.
Here’s a stripped down version of what I’m doing:

``````RooRealVar nElectronsWithCorrectCharge("nElectronsWithCorrectCharge", ...);
RooRealVar nPositronsWithCorrectCharge("nPositronsWithCorrectCharge", ...);
RooRealVar nElectronsWithWrongCharge("nElectronsWithWrongCharge", ...);

RooArgList(*electronPdf, *positronPdf, *ccElectronPdf),
RooArgList(nElectronsWithCorrectCharge, nPositronsWithCorrectCharge, nElectronsWithWrongCharge));``````

What I really want to know is the “number of electrons” nElectrons, and the “number of positrons” nPositrons.
Currently I have to extract them like this (including error propagation)

``````double nElectrons = nElectronsWithCorrectCharge + nElectronsWithWrongCharge;
double nPositrons = nPositronsWithCorrectCharge;``````

What I’d prefer to have is to fit the number of electrons and positrons directly and a probability of misidentifying an electron as a positron (and vice versa), called fChargeConfusionProbability.

``````  double nElectronsWithCorrectCharge = nElectrons  * (1 - fChargeConfusionProbability);
double nElectronsWithWrongCharge   = nElectrons * fChargeConfusionProbability;
double nPositronsWithCorrectCharge = nPositrons  * (1 - fChargeConfusionProbability);
double nPositronsWithWrongCharge   = nPositrons  * fChargeConfusionProbability;``````

I wonder if it’s possible to encode this type of fit in RooFit. I had success with this approach by manually defining a likelihood function and fitting ‘nElectrons’ / ‘nPositrons’ / ‘fChargeConfusionProbability’ in a binned likelihood fit using ROOT + TMinuit directly, but I prefer to work out this problem in terms of RooFit.

I hope I can get some advise on how to solve this problem.