Skip to content

Commit

Permalink
?
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Jan 16, 2025
1 parent 320898e commit e4d84f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
31 changes: 21 additions & 10 deletions ostap/fitting/roostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@
## allowed types for parameters
par_types = ROOT.RooAbsReal,
# ==============================================================================
if ( 6 , 28 ) <= root_info : # =================================================
# ==========================================================================
def make_set ( source ) : return ROOT.RooArgSet ( source )
# ==========================================================================
else : # =======================================================================
# ==========================================================================
def make_set ( source ) :
result = ROOT.RooArgSet()
for item in source : result.add ( item )
return result
# ==============================================================================
## @class ModelConfig
# Helper class to create `RooStats::ModelConfig`
# @see RooStats::ModelConfig
Expand Down Expand Up @@ -192,8 +203,7 @@ def __init__ ( self ,
constraints = cnts

## Inform ModelConfig on the constraints
if ( 6 , 28 ) <= root_info :
self.__mc.SetExternalConstraints ( constraints )
if ( 6 , 28 ) <= root_info : self.__mc.SetExternalConstraints ( constraints )
self.__external_constraints = constraints

self.__raw_pdf = raw_pdf
Expand All @@ -218,31 +228,32 @@ def __init__ ( self ,
assert all ( v in final_pdf for v in observables ), \
"Specified observables are not consistent with PDF"

observables = ROOT.RooArgSet ( self.pdf_observable ( o , dataset ) for o in observables )


observables = make_set ( self.pdf_observable ( o , dataset ) for o in observables )

## (6) set observables
self.__mc.SetObservables ( observables )
self.__observables = observables

## (7) get parameters of interess
poi = ROOT.RooArgSet ( self.pdf_param ( p , dataset ) for p in poi )
poi = make_set ( self.pdf_param ( p , dataset ) for p in poi )
mc.SetParametersOfInterest ( poi )
self.__poi = poi

## (8) global observables
assert all ( self.pdf_param ( p , dataset ) for p in global_observables )
if global_observables :
global_observables = ROOT.RooArgSet ( v for v in global_observables )
if global_observables :
global_observables = make_set ( v for v in global_observables )
assert all ( any ( o in c for c in constraints ) for o in global_observables ) , \
"Global observables are inconsisent with external constraints!"
mc.SetGlobalObservables ( global_observables )
self.__global_observables = global_observables

## nuisancee = all_parameters - poi - global_observables
nuisance = final_pdf.getParameters ( dataset ) - poi - global_observables
if nuisance : ROOT.RooStats.RemoveConstantParameters ( nuisance )
## (9) Nuisance parameters
if nuisance : ROOT.RooStats.RemoveConstantParameters ( nuisance )

## (9) Nuisance parameters
mc.SetNuisanceParameters ( nuisance )
self.__nuisance = nuisance

Expand All @@ -256,7 +267,7 @@ def __init__ ( self ,
## (11) constrained parameters (not used by RooStats!
assert all ( self.pdf_param ( p , dataset ) for p in constrained )
if constrained :
constrained = ROOT.RooArgSet ( v for v in conditional )
constrained = make_set ( v for v in conditional )
mc.SetConstraintParametrs ( constrained )
self.__constrained = constrained

Expand Down
2 changes: 1 addition & 1 deletion ostap/fitting/tests/test_fitting_roostats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def test_point_limit_hc () :
# - Profile Likelihoood Calculator is used
def test_point_limit_pl () :
""" Get the upper limit at given point for small signal at fixed mass
- resoltuion is fixed
- resolution is fixed
- Profile-Likelihood Calculator is used
"""

Expand Down
2 changes: 1 addition & 1 deletion ostap/fitting/tests/test_fitting_roostats5.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
model_sim.fitTo ( dataset , quiet = True )


err = 0.1
err = 0.3
reff = ROOT.RooRealVar ( 'reff' , 'ratio of efficiencies' , 1.0 , 0 , 10 )
ceff1 = model2.soft_constraint ( reff , VE ( 1.0, err**2 ) )

Expand Down

0 comments on commit e4d84f2

Please sign in to comment.