Overwriting object in RooWorkspace


I would like to be able to overwrite an object in a RooWorkspace (just like the way it is done when overwriting and object in a TFile (i.e TFile::Write(0,TObject::kOverwrite)). How do you set up the RooWorkspace::import conflict resolution such that it replaces the current object in the workspace with the object you pass to import?



Hi Matt,

You can’t. Workspaces are designed to work like SVN, you can’t touch anything that is already in there.
If you want to modify a component of a pdf, you can trivially make a new version. Assuming you have a ‘RooAbsArg& node’ that is intended to replace a RooAbsArg with name "node"
in the workspace, you can do

// Import the replacement with name "newNode"
w.import(node,Rename(“newNode”)) ;

// Construct a copy of the pdf “model” that uses “node” that uses “newNode” instread
w.factory(“EDIT::newModel(model,node=newNode)”) ;


Hi Wouter,

I’d like to do something similar. The use case is similar to what you describe but i’d like to write some code that’s generic to any RooAbsReal. I think I could do it in a generic way with RooWorkspace::factory but it would quickly get messy with lots of copies of things and I would need another, likely complicated, system to carefully keep track of all the renamed objects in the RooWorkspace, and their dependencies, and which should be used in the fit etc.

e.g. I might want to change a parameter of a pdf, that is part of a RooAddPdf, that is part of another RooAddPdf, that represents one slice of a RooSimultaneous pdf. And I might want to do this several times…

I have tried something like what is in the snippet attached. This seems to almost work…
example.cpp (1.81 KB)
I have a new object in the workspace which is the ‘newvar’. When a fit is performed using the pdfs that depend on ‘newvar’, ‘newvar’ is fit for and not ‘var’, as expected.

However, when I print out the RooWorkspace it indicates that actually the pdfs still depend on ‘var’ and not ‘newvar’, this seems to contradict the fact that ‘newvar’ was used in the fit.

Also when I try and plot the results of the fit and I come to plotting the affected components I get error messages like this:

ERROR:LinkStateMgmt – RooAbsArg::redirectServers(Bd_signal_g0): ERROR, some proxies could not be adjusted.

Which I think is happening here: root.cern.ch/root/html/src/RooAb … .html#1003 . It appears that the proxyList of the RooAbsArg is not updated when I try and replace an old server with a new one. However, I’m not really sure what the RooArgProxy class does and why all RooAbsArgs have lists of their ‘proxies’.

Could you offer any insight on this? Does the proxyList get updated during RooAbsArg::replaceServer? If not, is there an explanation for this? And is this even the problem?

Also I would greatly appreciate it if you could take a look at the attached code and tell me why it doesn’t quite work and whether anything like it is likely to serve the purpose I would like it to?

Please let me know if you would like any more details.

Many thanks,