Skip to content

Instantly share code, notes, and snippets.

@henryiii
Created July 9, 2019 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryiii/921e2423f61c4e45ffc198ba0c4dda20 to your computer and use it in GitHub Desktop.
Save henryiii/921e2423f61c4e45ffc198ba0c4dda20 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make a workspace with PDFs and variables"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1mRooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby\u001b[0m \n",
" Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University\n",
" All rights reserved, please read http://roofit.sourceforge.net/license.txt\n",
"\n"
]
}
],
"source": [
"RooRealVar M(\"M\",\"mes\",5.24,5.30);"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"RooRealVar Mean(\"Mean\",\"Mean mbc\",5.28,5.275,5.285);\n",
"RooRealVar Sigma1(\"Sigma1\",\"Width of Gaussian Btag\",0.004,0,.008);\n",
"\n",
"RooGaussian sig1(\"sig1\",\"The signal fitting function Gaussian PDF\",M,Mean,Sigma1);"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"RooRealVar cutoff(\"cutoff\",\"argus cutoff\",5.29);\n",
"RooRealVar argparc(\"argparc\",\"argus shape parameter c\",-50,-100,-1);\n",
"RooRealVar argparp(\"argparp\",\"argus shape parameter p\", 0.4);\n",
"\n",
"RooArgusBG Argus(\"Argus\", \"Argus PDF\", M,cutoff,argparc,argparp);"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"RooRealVar Nsig1(\"Nsig1\",\"number of signal events\",300,0,600);\n",
"RooRealVar Nbg(\"Nbg\",\"Background number\",3000,0,4000);//third argument will be large if large bkd; once we have a data sample, we need Ns scaled automatically. If \"even\" number of Nbg on plot, scale larger (indicates hit a threshhold) (...,...,guess,lower bound, upper bound)\n",
"\n",
"RooAddPdf model(\"model\",\"combined signal and background\",RooArgList(sig1,Argus),RooArgList(Nsig1,Nbg));"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ROOT's use of capital letters should keep this from conflicting with Python keywords... No, wait, RooFit uses lowercase 60% of the time, including `import`. I guess I'm glad I didn't use Python here..."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooAddPdf::model\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooGaussian::sig1\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooRealVar::M\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooRealVar::Mean\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooRealVar::Sigma1\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooRealVar::Nsig1\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooArgusBG::Argus\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooRealVar::cutoff\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooRealVar::argparc\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooRealVar::argparp\n",
"[#1] INFO:ObjectHandling -- RooWorkspace::import(work) importing RooRealVar::Nbg\n"
]
}
],
"source": [
"RooWorkspace work(\"work\");\n",
"work.import(model);"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"RooWorkspace(work) work contents\n",
"\n",
"variables\n",
"---------\n",
"(M,Mean,Nbg,Nsig1,Sigma1,argparc,argparp,cutoff)\n",
"\n",
"p.d.f.s\n",
"-------\n",
"RooArgusBG::Argus[ m=M m0=cutoff c=argparc p=argparp ] = 0.511728\n",
"RooAddPdf::model[ Nsig1 * sig1 + Nbg * Argus ] = 0.469202\n",
"RooGaussian::sig1[ x=M mean=Mean sigma=Sigma1 ] = 0.0439369\n",
"\n"
]
}
],
"source": [
"work.Print()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you think this doesn't look like saving a ROOT file, you are right. RooFit is not very ROOTish."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"work.writeToFile(\"workspace.root\");"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment