[RF] Wrong integral value, possibly problems with some global caching
- [x] Checked for duplicates It might be somehow associated with #7182
Describe the bug
In the attached archive there is a macro test.C showing the problem.
The problem is that even though all user-created objects die when functions Integral() and Plot() finish, the integral value is different if Plot() is invoked before the second call to Integral(). Both removing the call to Plot() or using the same value of delta in Integral() and Plot() make the test pass. Looks like ws.pdf("signal")->plotOn(frame); creates some global cache of the integral which is used with newly created objects.
Expected behavior
The integral value should not depend on the Plot() step - be equal before and after the Plot().
To Reproduce
Unpack the attached archive and run root -b -l -q test.C in the unpacked directory.
Setup
The test passes for ROOT versions up to 6.22.00, fails in 6.22.06 and later (I didn't check between). It doesn't depend on the operating system nor machine. In the archive there is also a script test.sh that can be run on lxplus.cern.ch selecting different root versions.
Additional context
While the current behaviour is clearly a bug and needs to be fixed, I would also appreciate a workaround that I could use right now. Maybe there is some function/static method to call to clean up the global caches (if that is indeed a problem of caching).
Hi! I think the global caches are a bad idea, I'm still thinking of how to get rid of them without losing cache efficiency.
For now, the workaround is to clear the global cache with:
RooExpensiveObjectCache::instance().clearAll();
Another solution is to use the RooWorkspace factory pattern to create your model, because then it uses a model local cache in the workspace that gets cleared when the workspace goes out of scope.
Hope that helps for now!
edit 1: corrected "mode local" to "model local"
Thank you very much for the workaround. It works for me.
Do you understand why it happens with plotOn and if the problem can happen in other scenarios? I am thinking where to put the workaround in my actual code (as opposed to the short example attached to this issue).
Can you point me to some docs/tutorial on how to use RooWorkspace factory pattern to create my model? Is it possible to achieve somehow the same effect regarding the cache when I am importing into the workspace?
By "mode local" did you mean "model local"?