High Level Factory: creation of a simple model
Author: Artem Busorgin, Danilo Piparo (C++ version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, March 19, 2024 at 07:18 PM.
import ROOT
--- Build the datacard and dump to file---
card_name = "HLFavtoryexample.rs"
with open(card_name, "w") as f:
f.write("// The simplest card\n\n")
f.write("gauss = Gaussian(mes[5.20,5.30],mean[5.28,5.2,5.3],width[0.0027,0.001,1]);\n")
f.write("argus = ArgusBG(mes,5.291,argpar[-20,-100,-1]);\n")
f.write("sum = SUM(nsig[200,0,10000]*gauss,nbkg[800,0,10000]*argus);\n\n")
hlf = ROOT.RooStats.HLFactory("HLFavtoryexample", card_name, False)
--- Take elements out of the internal workspace ---
w = hlf.GetWs()
mes = w.arg("mes")
sumpdf = w["sum"]
argus = w["argus"]
--- Generate a toyMC sample from composite PDF ---
data = sumpdf.generate(mes, 2000)
--- Perform extended ML fit of composite PDF to toy data ---
sumpdf.fitTo(data)
<cppyy.gbl.RooFitResult object at 0x(nil)>
[#1] INFO:Minimization -- p.d.f. provides expected number of events, including extended term in likelihood. [#1] INFO:Fitting -- RooAbsPdf::fitTo(sum) fixing normalization set for coefficient determination to observables in data [#1] INFO:Fitting -- using CPU computation library compiled with -mavx2 [#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_sum_sumData) Summation contains a RooNLLVar, using its error level [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization Minuit2Minimizer: Minimize with max-calls 2500 convergence for edm < 1 strategy 1 Minuit2Minimizer : Valid minimum - status = 0 FVAL = -18178.1839194288186 Edm = 7.6129471840253625e-05 Nfcn = 112 argpar = -22.9054 +/- 3.42143 (limited) mean = 5.27987 +/- 0.000215769 (limited) nbkg = 1612.74 +/- 44.6723 (limited) nsig = 387.37 +/- 27.7674 (limited) width = 0.00300965 +/- 0.000199023 (limited) [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
Info in <Minuit2>: MnSeedGenerator Computing seed using NumericalGradient calculator Info in <Minuit2>: MnSeedGenerator Initial state: FCN = -17788.81972 Edm = 387.8769988 NCalls = 23 Info in <Minuit2>: MnSeedGenerator Initial state Minimum value : -17788.81972 Edm : 387.8769988 Internal parameters: [ 0.6638599611 0.6435011088 -0.9972832224 -1.287002218 -1.488269535] Internal gradient : [ 14.82946743 126.275939 -2757.194664 -1308.655031 -596.9436515] Internal covariance matrix: [[ 0.012706854 0 0 0 0] [ 0 4.9189718e-05 0 0 0] [ 0 0 0.00015334155 0 0] [ 0 0 0 0.00021750069 0] [ 0 0 0 0 2.7280305e-05]]] Info in <Minuit2>: VariableMetricBuilder Start iterating until Edm is < 0.001 with call limit = 2500 Info in <Minuit2>: VariableMetricBuilder 0 - FCN = -17788.81972 Edm = 387.8769988 NCalls = 23 Info in <Minuit2>: VariableMetricBuilder 1 - FCN = -18169.69569 Edm = 6.384645825 NCalls = 34 Info in <Minuit2>: VariableMetricBuilder 2 - FCN = -18176.80971 Edm = 0.5318821738 NCalls = 45 Info in <Minuit2>: VariableMetricBuilder 3 - FCN = -18177.90366 Edm = 0.1830792573 NCalls = 57 Info in <Minuit2>: VariableMetricBuilder 4 - FCN = -18178.17357 Edm = 0.009596744002 NCalls = 69 Info in <Minuit2>: VariableMetricBuilder 5 - FCN = -18178.18392 Edm = 8.460513492e-05 NCalls = 81 Info in <Minuit2>: VariableMetricBuilder After Hessian Info in <Minuit2>: VariableMetricBuilder 6 - FCN = -18178.18392 Edm = 7.612947184e-05 NCalls = 112 Info in <Minuit2>: Minuit2Minimizer::Hesse Using max-calls 2500 Info in <Minuit2>: Minuit2Minimizer::Hesse Hesse is valid - matrix is accurate
--- Plot toy data and composite PDF overlaid ---
mesframe = mes.frame()
data.plotOn(mesframe)
sumpdf.plotOn(mesframe)
sumpdf.plotOn(mesframe, Components=argus, LineStyle="--")
ROOT.gROOT.SetStyle("Plain")
c = ROOT.TCanvas()
mesframe.Draw()
c.SaveAs("rs601_HLFactoryexample.png")
[#1] INFO:Plotting -- RooAbsPdf::plotOn(sum) directly selected PDF components: (argus) [#1] INFO:Plotting -- RooAbsPdf::plotOn(sum) indirectly selected PDF components: ()
Info in <TCanvas::Print>: png file rs601_HLFactoryexample.png has been created
Draw all canvases
%jsroot on
from ROOT import gROOT
gROOT.GetListOfCanvases().Draw()