3333## \date July 2024
3434## \author Robin Syring
3535
36- import ROOT
3736import numpy as np
37+ import ROOT
3838from sklearn .neural_network import MLPClassifier
3939
4040# The samples used for training the classifier in this tutorial / rescale for more accuracy
4545
4646
4747# Morphing as a baseline
48- def morphing (setting ):
49-
48+ def morphing (setting , workspace ):
5049 # Define binning for morphing
5150 grid = ROOT .RooMomentMorphFuncND .Grid (ROOT .RooBinning (4 , 0.0 , 4.0 ))
5251 x_var .setBins (50 )
@@ -199,7 +198,7 @@ def learned_likelihood_ratio(x, mu):
199198ROOT .SetOwnership (nllr_learned , True )
200199
201200# Compute the morphed nll
202- morphing (ROOT .RooMomentMorphFuncND .Linear )
201+ morphing (ROOT .RooMomentMorphFuncND .Linear , workspace )
203202nll_morph = workspace ["morph" ].createNLL (obs_data )
204203ROOT .SetOwnership (nll_morph , True )
205204
@@ -228,8 +227,8 @@ def learned_likelihood_ratio(x, mu):
228227frame1 .Draw ()
229228
230229legend1 = ROOT .TLegend (0.43 , 0.63 , 0.8 , 0.87 )
231- legend1 .SetFillColor (" kWhite" )
232- legend1 .SetLineColor (" kWhite" )
230+ legend1 .SetFillColor (ROOT . kWhite )
231+ legend1 .SetLineColor (ROOT . kWhite )
233232legend1 .SetTextSize (0.04 )
234233legend1 .AddEntry ("learned" , "learned (SBI)" , "L" )
235234legend1 .AddEntry ("gauss" , "true NLL" , "L" )
@@ -247,8 +246,8 @@ def learned_likelihood_ratio(x, mu):
247246frame2 .Draw ()
248247
249248legend2 = ROOT .TLegend (0.53 , 0.73 , 0.87 , 0.87 )
250- legend2 .SetFillColor (" kWhite" )
251- legend2 .SetLineColor (" kWhite" )
249+ legend2 .SetFillColor (ROOT . kWhite )
250+ legend2 .SetLineColor (ROOT . kWhite )
252251legend2 .SetTextSize (0.04 )
253252legend2 .AddEntry ("learned_ratio" , "learned (SBI)" , "L" )
254253legend2 .AddEntry ("exact" , "true ratio" , "L" )
0 commit comments