RooFit model.Print("v" ) segfault in simple example

Dear experts

I was trying to setup a fit with ROOT 6.26/00 (currently checking if the segfault goes away in latest ROOT (6.28)

Here a minimal example

import ROOT as r

massVariable = r.RooRealVar("m","m",1200)
bComb1   = r.RooRealVar('bcomb1', 'bcomb1', -1E-3, -1E-2, 1E-2)
nComb1   = r.RooRealVar("nComb1","nComb1", 200)
pdf1     = r.RooExtendPdf( "combo1_ext","combo1_ext", r.RooExponential(f"combo1",   f"combo1", massVariable , bComb1), nComb1)
pdf1.Print("v")

bComb2   = r.RooRealVar('bcomb2', 'bcomb2', -1E-3, -1E-2, 1E-2)
nComb2   = r.RooRealVar("nComb2","nComb2", 200)
pdf2     = r.RooExtendPdf( "combo2_ext","combo2_ext", r.RooExponential(f"combo2",   f"combo2", massVariable , bComb2), nComb2)
pdf2.Print("v")

model = r.RooAddPdf("model","model", r.RooArgList(pdf1,pdf2))
model.Print("v")

Basically the Print(“v”) segfault with :

--- RooAbsArg ---
  Value State: DIRTY
  Shape State: DIRTY
  Attributes:  [ServerDied,ServerDied:combo1(55d19d2c1b00)] 
  Address: 0x55d19d51d4d0
  Clients: 
  Servers: 
    (0x55d19d2ee670,V-) RooRealVar::nComb1 "nComb1"
  Proxies: 
    pdf ->  *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================

Thread 2 (Thread 0x7f9e57636700 (LWP 5327)):
#0  0x00007f9e837e0de2 in pthread_cond_timedwait

GLIBC_2.3.2 () from /lib64/libpthread.so.0

seems like the Printing is not protected if it has some nullptr not associated tot the pdf?

Thanks
Renato

Hi!

The crashes happen because you are defining the RooExponentials as temporaries. They get out of scope and destructed after your calls to the RooExtendPdf constructors, leaving the extended pdfs with invalid pointers. Remember: RooFit objects don’t own each other, they are just connected by pointers.

If you assign the exponentials to separate variables that Python keeps alive, then all goes well:

import ROOT as r

massVariable = r.RooRealVar("m","m",1200)

bComb1   = r.RooRealVar('bcomb1', 'bcomb1', -1E-3, -1E-2, 1E-2)
nComb1   = r.RooRealVar("nComb1","nComb1", 200)
expo1    = r.RooExponential(f"combo1",   f"combo1", massVariable , bComb1)
pdf1     = r.RooExtendPdf( "combo1_ext","combo1_ext", expo1, nComb1)
pdf1.Print("v")

bComb2   = r.RooRealVar('bcomb2', 'bcomb2', -1E-3, -1E-2, 1E-2)
nComb2   = r.RooRealVar("nComb2","nComb2", 200)
expo2    = r.RooExponential(f"combo2",   f"combo2", massVariable , bComb2)
pdf2     = r.RooExtendPdf( "combo2_ext","combo2_ext", expo2, nComb2)
pdf2.Print("v")

model = r.RooAddPdf("model","model", r.RooArgList(pdf1,pdf2))
model.Print("v")
1 Like

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