Numeric algorithm tuning: caching of slow numeric integrals and parameterizations of slow numeric integrals 
 
  
import sys
import ROOT
 
 
def getWorkspace(mode):
    
    
    
    
    
    
 
    w = ROOT.RooWorkspace()
 
    if mode != 2:
        
        w = ROOT.RooWorkspace("w", 1)
 
        
        
        w.factory(
            "EXPR::model('1/((x-a)*(x-a)+0.01)+1/((y-a)*(y-a)+0.01)+1/((z-a)*(z-a)+0.01)',x[-1,1],y[-1,1],z[-1,1],a[-5,5])"
        )
 
    if mode == 1:
        
        
        
        
        
 
        
        model = w["model"]
        model.setStringAttribute("CACHEPARMINT", "x:y:z")
 
        
        normSet = {w["x"], w["y"], w["z"]}
        model.getVal(normSet)
        w.writeToFile("rf903_numintcache.root")
 
    if mode == 2:
        
        f = ROOT.TFile("rf903_numintcache.root")
        w = f.Get("w")
 
    
    return w
 
 
mode = 0
 
 
w = getWorkspace(mode)
if mode == 1:
    
    w.Print()
 
    
    hhcache = w.expensiveObjectCache().getObj(1)
    if hhcache:
        ROOT.TCanvas("rf903_numintcache", "rf903_numintcache", 600, 600)
        hhcache.createHistogram(
"a").
Draw()
 
    else:
        ROOT.RooFit.Error("rf903_numintcache", "Cached histogram is not existing in workspace")
        sys.exit()
 
 
model = w["model"]
d = model.generate({w["x"], w["y"], w["z"]}, 1000)
 
model.fitTo(d, Verbose=True, Timer=True, PrintLevel=-1)
 
framex = w["x"].frame(Title="Projection of 3D model on X")
d.plotOn(framex)
model.plotOn(framex)
 
c = ROOT.TCanvas("rf903_numintcache", "rf903_numintcache", 600, 600)
framex.Draw()
 
c.SaveAs("rf903_numintcache.png")
 
ROOT.gDirectory.Add(w)
  [#1] INFO:NumericIntegration -- RooRealIntegral::init(model_Int[x,y,z]) using numeric integrator RooAdaptiveIntegratorND to calculate Int(x,y,z)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for a: using 1
 
prevFCN = 1659.930708  a=0.02003, [#1] INFO:NumericIntegration -- RooRealIntegral::init(model_Int[x,y,z]) using numeric integrator RooAdaptiveIntegratorND to calculate Int(x,y,z)
 
prevFCN = 1668.090831  a=-0.02003, 
prevFCN = 1666.341378  a=0.002003, 
prevFCN = 1660.094465  a=-0.002003, 
prevFCN = 1659.913535  a=-0.001236, 
prevFCN = 1659.902781  a=-0.001036, 
prevFCN = 1659.903514  a=-0.001437, 
prevFCN = 1659.903515  a=-0.001089, 
prevFCN = 1659.903177  a=-0.001383, 
prevFCN = 1659.903178  a=-0.001236, 
prevFCN = 1659.902781  a=-0.001089, 
prevFCN = 1659.903177  a=-0.001383, 
prevFCN = 1659.903178  a=-0.001207, 
prevFCN = 1659.902797  a=-0.001266, 
prevFCN = 1659.902797  [#1] INFO:Minimization -- Command timer: Real time 0:00:02, CP time 2.740
[#1] INFO:Minimization -- Session timer: Real time 0:00:02, CP time 2.740
a=-0.001236, 
prevFCN = 1659.902781  a=-0.001207, 
prevFCN = 1659.902797  a=-0.001266, 
prevFCN = 1659.902797  a=-0.00123, 
prevFCN = 1659.902782  a=-0.001242, 
prevFCN = 1659.902782  [#1] INFO:Minimization -- Command timer: Real time 0:00:00, CP time 0.950
[#1] INFO:Minimization -- Session timer: Real time 0:00:03, CP time 3.690, 2 slices
a=-0.001236, [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#0] WARNING:NumericIntegration -- RooAdaptiveIntegratorND::dtor(model) WARNING: Number of suppressed warningings about integral evaluations where target precision was not reached is 20
[#1] INFO:Plotting -- RooAbsReal::plotOn(model) plot on x integrates over variables (y,z)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_Int[y,z]_Norm[x,y,z]) using numeric integrator RooAdaptiveIntegratorND to calculate Int(y,z)
- Date
 - February 2018 
 
- Authors
 - Clemens Lange, Wouter Verkerke (C++ version) 
 
Definition in file rf903_numintcache.py.