Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rs601_HLFactoryexample.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roostats
3## \notebook -js
4## High Level Factory: creation of a simple model
5##
6## \macro_image
7## \macro_output
8## \macro_code
9##
10## \date July 2022
11## \authors Artem Busorgin, Danilo Piparo (C++ version)
12
13import ROOT
14
15# --- Build the datacard and dump to file---
16card_name = "HLFavtoryexample.rs"
17with open(card_name, "w") as f:
18 f.write("// The simplest card\n\n")
19 f.write("gauss = Gaussian(mes[5.20,5.30],mean[5.28,5.2,5.3],width[0.0027,0.001,1]);\n")
20 f.write("argus = ArgusBG(mes,5.291,argpar[-20,-100,-1]);\n")
21 f.write("sum = SUM(nsig[200,0,10000]*gauss,nbkg[800,0,10000]*argus);\n\n")
22
23hlf = ROOT.RooStats.HLFactory("HLFavtoryexample", card_name, False)
24
25# --- Take elements out of the internal workspace ---
26w = hlf.GetWs()
27
28mes = w.arg("mes")
29sumpdf = w["sum"]
30argus = w["argus"]
31
32# --- Generate a toyMC sample from composite PDF ---
33data = sumpdf.generate(mes, 2000)
34
35# --- Perform extended ML fit of composite PDF to toy data ---
36sumpdf.fitTo(data)
37
38# --- Plot toy data and composite PDF overlaid ---
39mesframe = mes.frame()
40data.plotOn(mesframe)
41sumpdf.plotOn(mesframe)
42sumpdf.plotOn(mesframe, Components=argus, LineStyle="--")
43
44ROOT.gROOT.SetStyle("Plain")
45
46c = ROOT.TCanvas()
47mesframe.Draw()
48
49c.SaveAs("rs601_HLFactoryexample.png")