HistFactory’s ShapeSys isn’t initializing the ConstraintType correctly and instead you just get random values in memory:
import ROOT
shapes = []
for i in xrange(100):
shapesys = ROOT.RooStats.HistFactory.ShapeSys()
shapes.append(shapesys)
print shapesys.GetConstraintType()
1766341178
1413102196
1413102196
1953721967
38578736
0
18446744073709551615
0
0
0
0
0
0
0
0
0
0
23800560
23801200
0
0
0
0
0
0
0
23800560
23801200
23826512
It would also be convenient to overload SetConstraintType to accept the string equivalent “Gaussian” or “Poisson” (not case sensitive, and also accept shortened Gauss and Pois).
Hi,
I have fixed this bug in both 5.34 patches and master of ROOT. Thank you for reporting it !
etConstraintType with a string, but what is the problem of using the enumeration, i.e. using ShapeSys::SetConstraintType(Constraint::Gaussian) ?
Best Regards
Lorenzo
Thanks for fixing this!
Yes it’s easy to use the enum in C++, but from Python the equivalent is to use
ROOT.RooStats.HistFactory.Constraint.Gaussian
It’s kind of deeply nested…
I know Gaussian is 0 and Poisson is 1 so I can just pass those values, although the code is then less readable.
It was trivial to improve rootpy ShapeSys subclass to handle both cases. I also fixed the ROOT bug in rootpy’s subclass so the constraint is initialized properly.
https://github.com/rootpy/rootpy/blob/master/rootpy/stats/histfactory/histfactory.py#L788
>>> from rootpy.stats.histfactory import ShapeSys, Constraint
>>> Constraint.Gaussian
0
>>> Constraint.Poisson
1
>>> s = ShapeSys('shape')
>>> s.constraint = 'gaussian'
>>> s.constraint
0L
>>> s.constraint = 'poisson'
>>> s.constraint
1L
>>> s.constraint = Constraint.Gaussian
>>> s.constraint
0L
>>> s.constraint = 'something'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "rootpy/stats/histfactory/histfactory.py", line 815, in constraint
self.SetConstraintType(value)
File "rootpy/stats/histfactory/histfactory.py", line 807, in SetConstraintType
"'{0}' is not a valid constraint".format(value))
ValueError: 'something' is not a valid constraint