What(): RooAbsCollection::addOwned could not add the argument to the collection! The ownership would not be well defined if we ignore this

Dear experts,
I am trying to implement systematics in my model. I am doing it following the example in Include Shape systematics. My code is slightly different since I am using unbinned datasets so I use continuous pdfs instead of Histograms as in the example.

Anyway I define my model as described in the example above (from 3 RooAddPdf and a RooRealVar i construct a PiecewiseInterpolation function) and I get this warning:

 WARNING:Eval -- Evaluating RooAddPdf "model_name" without a defined normalization set. This can lead to ambiguous coefficients definition and incorrect results. Use RooAddPdf::fixCoefNormalization(nset) to provide a normalization set for defining uniquely RooAddPdf coefficients!

so I fix my normalization set using my observable in x axis for all my RooAddPdf and I get an error that terminates my code

[#0] ERROR:InputArguments -- RooArgSet::checkForDup: ERROR argument with name "model name"_conditional is already in this set
terminate called after throwing an instance of 'std::runtime_error'
  what():  RooAbsCollection::addOwned could not add the argument to the collection! The ownership would not be well defined if we ignore this.

The warning and the error is not triggered if I use RooRealSumPdf instead of RooAddPdf, but in this case the shapes of my pdfs changes (thing that I can manually fix doing something like this Difference between RoorealSum and RooAddPdf but it is a quite nasty given my model)

So I was wondering if it is possible to do with RooAddPdf adjusting something or I must use RooRealSumPdf.

Thanks,
Elia

in the file attached is part of the code where I create my model
question.C (13.9 KB)

Hello @Elia_Giulio_Grandoni,

thank you for your question, let me tag our Roofit expert @jonas.

Have a nice day,
cheers,
Marta

Hi @Elia_Giulio_Grandoni!

I don’t see anything wrong with the code that you shared, but also the error you pointed out must come from a different part of the code, and not the one you shared. It mentions a model with the name "model name", which is not to be found in the attached code.

Could it be that in the full code, you’re accidentally giving two different RooFit object the same name? In this case "model name"?

Cheers,
Jonas

Hi @jonas,

doing some debugging it seems that the code fails when I call the fit

 RooFitResult *res = model.fitTo(*toydata, Strategy(1), Save(), Constrain(sys_alpha), GlobalObservables(nominal_sys_mean, nominal_sys_var));
 res->Print("v");

:frowning:

A follow up:

If I try to draw the pdfs and the data (before the fit) I get

The first three are what I expect, although the last one no; it should be the sum of the three pdfs.

RooRealSumPdf temp_model("temp sig + bkg model", "temp sig + bkg model",
                                    RooArgList(ALP_sys_model, RMD_sys_model, ACC_sys_model), RooArgList(nSig, nRmd, nAcc), true);
// model with costraint
RooProdPdf model("sig + bkg model", "sig + bkg model", RooArgList(temp_model, gaus_sys));

Also if I skip the fit and I make the workspace where I save the “model” function the set of pdfs saved is just the central one. I don’t get to see the ones with systematic variations.

Found the problem, for some reason the print (Form(“…”, …)) did not work, so I had several variables with the same name.

Still have trobles with the shape of the model, but I guess it is due to the normalization of the systematic models and the RooRealSumPdf class.

Cheers,
Elia

Hi @Elia_Giulio_Grandoni, sorry for the late follow-up!

Glad you found the solution to the problem with the names to fix the crash!

Still have trobles with the shape of the model, but I guess it is due to the normalization of the systematic models and the RooRealSumPdf class.

Yes, this is indeed because of the normalization of the RooRealSumPdf components.

The RooRealSumPdf is not normalizing the components before adding them, because it doesn’t propagate the normalization set information to the components. I think this is a design mistake of the RooRealSumPdf that we might eventually fix.

So you need to use RooAddPdf, it handles these cases better. But RooAddPdf only takes RooAbsPdfs objects in the input list, which is not the case for your PiecewiseInterpolations, which are just regular functions (RooAbsReal).

But since you know that you interpolations are normalized (they are the linear sum of normalized pdfs), you can just wrap them in a RooWrapperPdf where you skip a redundant numeric normalization step with the selfNormalized=true argument to the constructor. These wrapper pdfs can then be used in a final RooAddPdf, and you should be all good. In other words: avoid the RooRealSumPdf because is doesn’t define the normalization of it’s components.

I hope this helps!

Cheers,
Jonas

Hi @jonas,

thanks for the reply. Your comment definetively helped. I also did the exercise to do it with RooRealSumPdf normalizing by hand each pdf before summing them as in this forum question. Anyway with RooWrapperPdf with the self normalization its more straightfoward. I used it after every PiecewiseInterpolation and now the model has the right shape.

Cheers,
Elia

A follow up question for @jonas .

To draw the fitted distributions I have to specify to the model the fitted “fractions” of each value. And put the sys_alpha value to zero, if not the shapes do not make any sense…any reason why?

Here is the model and the fit

//Using the wrapper I can construct the RooAddPdfModel 
RooAddPdf temp_model("temp sig + bkg model", "temp sig + bkg model",
                    RooArgList(ALP_sys_model, RMD_sys_model, ACC_sys_model), RooArgList(nSig, nRmd, nAcc));
// model with costraint
RooProdPdf model("sig + bkg model", "sig + bkg model", RooArgList(temp_model, gaus_sys));

RooAbsData *toydata = model.generate(RooArgSet(minv), Extended());

RooFitResult *res = model.fitTo(*toydata, Strategy(2), Save(), Constrain(sys_alpha), GlobalObservables(nominal_sys_mean, nominal_sys_var));

If I put in the drawing

nSig.setVal(nSig.getVal()*10000); 
nRmd.setVal(nRmd.getVal());
nAcc.setVal(nAcc.getVal()); 
sys_alpha.setVal(0);

I get the right shapes (model before (left) and after fit (right))

immagine

if I use

sys_alpha.setVal(sys_alpha.getVal());

no… (model before (left) and after fit (right))

immagine

What is your model for sys_alpha.getVal() there? Are all your piecewise interpolations positive definite for this value? If they are not, they would again not be normalized correctly and cause problems when using as pdfs. I mean for some large value of alpha (positive or negative, depending on the shape variations), the linear extrapolation will inevitably become negative. Did you make sure that the range of your alpha variable is defined such that this can’t happen?

Hi @jonas,

for sys_alpha I use a gaussian constrain defined as

//sys par + costraint
RooRealVar sys_alpha("sys_alpha", "sys_alpha", 0, -5, 5);
// remember that nominal_sys_mean e nominal_sys_var will be a global observable!!!
RooRealVar nominal_sys_mean("nominal_sys_mean", "nominal_sys_mean", 0, -1, 1);
nominal_sys_mean.setVal(0);
nominal_sys_mean.setConstant();
RooRealVar nominal_sys_var("nominal_sys_var", "nominal_sys_var", 1, 0.1, 2);
nominal_sys_var.setVal(1);
nominal_sys_var.setConstant();
// cosrtaint model that fuctuates on alpha
RooGaussian gaus_sys("gaus_sys", "gaus_sys", sys_alpha, nominal_sys_mean, nominal_sys_var);

The shapes of two of the three functions are ok for all the sys_alpha values.

The one that behaves strangely is the ACC_sys_model (the green one in the previous relply).

on the left the three nominal values used for the interpolation (almost superimposed). On the right the sys_model drawn for different alpha values (from 1 to 5 bottom to top curve). With the normalization something strange is happening, the integral is growing with the value of alpha.

The three central models are RooLandau pdfs and they are joined using

// create an linear interpolating model usign sys_alpha
PiecewiseInterpolation ACC_sys_model_temp("ACC_sys_model_temp", "ACC_sys_model_temp", model_ACC, model_ACC_m1S, model_ACC_p1S, sys_alpha);
// wrap pdfs to make a rooabspdf!!
RooWrapperPdf ACC_sys_model("ACC_sys_model", "ACC_sys_model", ACC_sys_model_temp, true);

I can not see the problem in my script…

I have found a solution that I am sure is not the optimal one. The difference between the ACC_sys_model and the other two is that the other two are defined as a RooAddPdf for which I fix the normalization coefficient using “fixCoefNormalization”. So also for the ACC_model I created a “dummy” RooAddPdf fixing the coefficient and it works (I summed two pdfs with fractions fixed to be 0 and 1).

If you have a better solution I will be happy to hear it :slight_smile:

Thanks for the support,
Elia

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