Logo ROOT  
Reference Guide
rf514_RooCustomizer.C File Reference

Detailed Description

View in nbviewer Open in SWAN

Using the RooCustomizer to create multiple PDFs that share a lot of properties, but have unique parameters for each category. As an extra complication, some of the new parameters need to be functions of a mass parameter.

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
The proto model before customisation:
0x7ffc93a811f0 RooAddPdf::model = 750.5 [Auto,Dirty]
0x7ffc93a829c8/V- RooGaussian::gauss = 0 [Auto,Dirty]
0x7ffc93a836b0/V- RooRealVar::Energy = 1500
0x7ffc93a832d0/V- RooRealVar::meanG = 100
0x7ffc93a82ee0/V- RooRealVar::sigmaG = 3
0x7ffc93a81c90/V- RooRealVar::yieldSig = 1
0x7ffc93a820e8/V- RooPolynomial::linear = 1501 [Auto,Dirty]
0x7ffc93a836b0/V- RooRealVar::Energy = 1500
0x7ffc93a825e8/V- RooRealVar::pol1 = 1
0x7ffc93a818b0/V- RooRealVar::yieldBkg = 1
PDF 1 with a yield depending on M:
0x55bb78a96cd0 RooAddPdf::model_Sample1 = 1156.8 [Auto,Dirty]
0x7ffc93a820e8/V- RooPolynomial::linear = 1501 [Auto,Dirty]
0x7ffc93a836b0/V- RooRealVar::Energy = 1500
0x7ffc93a825e8/V- RooRealVar::pol1 = 1
0x7ffc93a818b0/V- RooRealVar::yieldBkg = 1
0x55bb78a1af10/V- RooGaussian::gauss_Sample1 = 0 [Auto,Dirty]
0x7ffc93a836b0/V- RooRealVar::Energy = 1500
0x7ffc93a82ee0/V- RooRealVar::sigmaG = 3
0x55bb78a96710/V- RooRealVar::meanG_Sample1 = 100
0x7ffc93a800f0/V- RooFormulaVar::yieldSig_Sample1 = 0.29755 [Auto,Clean]
0x7ffc93a804e8/V- RooRealVar::M = 1
PDF 2 with a yield depending on M:
0x55bb78aa2740 RooAddPdf::model_Sample2 = 1000.67 [Auto,Dirty]
0x7ffc93a820e8/V- RooPolynomial::linear = 1501 [Auto,Dirty]
0x7ffc93a836b0/V- RooRealVar::Energy = 1500
0x7ffc93a825e8/V- RooRealVar::pol1 = 1
0x7ffc93a818b0/V- RooRealVar::yieldBkg = 1
0x55bb787849c0/V- RooGaussian::gauss_Sample2 = 0 [Auto,Dirty]
0x7ffc93a836b0/V- RooRealVar::Energy = 1500
0x7ffc93a82ee0/V- RooRealVar::sigmaG = 3
0x55bb78954ce0/V- RooRealVar::meanG_Sample2 = 100
0x7ffc93a7fc80/V- RooFormulaVar::yieldSig_Sample2 = 0.5 [Auto,Clean]
0x7ffc93a804e8/V- RooRealVar::M = 1
PDF 3 with a free yield:
0x55bb78a939b0 RooAddPdf::model_Sample3 = 750.5 [Auto,Dirty]
0x7ffc93a820e8/V- RooPolynomial::linear = 1501 [Auto,Dirty]
0x7ffc93a836b0/V- RooRealVar::Energy = 1500
0x7ffc93a825e8/V- RooRealVar::pol1 = 1
0x7ffc93a818b0/V- RooRealVar::yieldBkg = 1
0x55bb78a95100/V- RooGaussian::gauss_Sample3 = 0 [Auto,Dirty]
0x7ffc93a836b0/V- RooRealVar::Energy = 1500
0x7ffc93a82ee0/V- RooRealVar::sigmaG = 3
0x55bb78a98280/V- RooRealVar::meanG_Sample3 = 100
0x55bb78785940/V- RooRealVar::yieldSig_Sample3 = 1
The following leafs have been created automatically while customising:
1) RooRealVar:: meanG_Sample1 = 100
2) RooRealVar:: meanG_Sample2 = 100
3) RooRealVar:: meanG_Sample3 = 100
4) RooRealVar:: yieldSig_Sample3 = 1
The following leafs have been used while customising
(partial overlap with the set of automatically created leaves.
a new customiser for a different PDF could reuse them if necessary.):
1) RooFormulaVar:: yieldSig_Sample1 = 0.29755
2) RooFormulaVar:: yieldSig_Sample2 = 0.5
3) RooRealVar:: meanG_Sample1 = 200
4) RooRealVar:: meanG_Sample2 = 300
5) RooRealVar:: meanG_Sample3 = 100
6) RooRealVar:: yieldSig_Sample3 = 1
#include "RooRealVar.h"
#include "RooGaussian.h"
#include "RooPolynomial.h"
#include "RooAddPdf.h"
#include "RooCustomizer.h"
#include "RooCategory.h"
#include "RooFormulaVar.h"
#include <iostream>
void rf514_RooCustomizer() {
// Define a proto model that will be used as the template for each category
// ---------------------------------------------------------------------------
RooRealVar E("Energy","Energy",0,3000);
RooRealVar meanG("meanG","meanG", 100., 0., 3000.);
RooRealVar sigmaG("sigmaG","sigmaG", 3.);
RooGaussian gauss("gauss", "gauss", E, meanG, sigmaG);
RooRealVar pol1("pol1", "Constant of the polynomial", 1, -10, 10);
RooPolynomial linear("linear", "linear", E, pol1);
RooRealVar yieldSig("yieldSig", "yieldSig", 1, 0, 1.E4);
RooRealVar yieldBkg("yieldBkg", "yieldBkg", 1, 0, 1.E4);
RooAddPdf model("model", "S + B model",
RooArgList(gauss,linear),
RooArgList(yieldSig, yieldBkg));
std::cout << "The proto model before customisation:" << std::endl;
model.Print("T"); // "T" prints the model as a tree
// Build the categories
RooCategory sample("sample","sample");
sample["Sample1"] = 1;
sample["Sample2"] = 2;
sample["Sample3"] = 3;
// Start to customise the proto model that was defined above.
// ---------------------------------------------------------------------------
// We need two sets for bookkeeping of PDF nodes:
RooArgSet newLeafs; // This set collects leafs that are created in the process.
RooArgSet allCustomiserNodes; // This set lists leafs that have been used in a replacement operation.
// 1. Each sample should have its own mean for the gaussian
// The customiser will make copies of `meanG` for each category.
// These will all appear in the set `newLeafs`, which will own the new nodes.
RooCustomizer cust(model, sample, newLeafs, &allCustomiserNodes);
cust.splitArg(meanG, sample);
// 2. Each sample should have its own signal yield, but there is an extra complication:
// We need the yields 1 and 2 to be a function of the variable "mass".
// For this, we pre-define nodes with exacly the names that the customiser would have created automatically,
// that is, "<nodeName>_<categoryName>", and we register them in the set of customiser nodes.
// The customiser will pick them up instead of creating new ones.
// If we don't provide one (e.g. for "yieldSig_Sample3"), it will be created automatically by cloning `yieldSig`.
RooRealVar mass("M", "M", 1, 0, 12000);
RooFormulaVar yield1("yieldSig_Sample1", "Signal yield in the first sample", "M/3.360779", mass);
RooFormulaVar yield2("yieldSig_Sample2", "Signal yield in the second sample", "M/2", mass);
allCustomiserNodes.add(yield1);
allCustomiserNodes.add(yield2);
// Instruct the customiser to replace all yieldSig nodes for each sample:
cust.splitArg(yieldSig, sample);
// Now we can start building the PDFs for all categories:
auto pdf1 = cust.build("Sample1");
auto pdf2 = cust.build("Sample2");
auto pdf3 = cust.build("Sample3");
// And we inspect the two PDFs
std::cout << "\nPDF 1 with a yield depending on M:" << std::endl;
pdf1->Print("T");
std::cout << "\nPDF 2 with a yield depending on M:" << std::endl;
pdf2->Print("T");
std::cout << "\nPDF 3 with a free yield:" << std::endl;
pdf3->Print("T");
std::cout << "\nThe following leafs have been created automatically while customising:" << std::endl;
newLeafs.Print("V");
// If we needed to set reasonable values for the means of the gaussians, this could be done as follows:
auto& meanG1 = static_cast<RooRealVar&>(allCustomiserNodes["meanG_Sample1"]);
meanG1.setVal(200);
auto& meanG2 = static_cast<RooRealVar&>(allCustomiserNodes["meanG_Sample2"]);
meanG2.setVal(300);
std::cout << "\nThe following leafs have been used while customising"
<< "\n\t(partial overlap with the set of automatically created leaves."
<< "\n\ta new customiser for a different PDF could reuse them if necessary.):" << std::endl;
allCustomiserNodes.Print("V");
}
Author
Stephan Hageboeck, CERN

Definition in file rf514_RooCustomizer.C.

RooFormulaVar.h
RooRealVar::setVal
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:226
RooAddPdf
Definition: RooAddPdf.h:32
RooCustomizer
Definition: RooCustomizer.h:35
RooArgList
Definition: RooArgList.h:21
RooGaussian.h
RooGaussian
Definition: RooGaussian.h:25
RooAddPdf.h
RooArgSet::add
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooPolynomial.h
RooFormulaVar
Definition: RooFormulaVar.h:30
RooCustomizer.h
TGeant4Unit::gauss
static constexpr double gauss
Definition: TGeant4SystemOfUnits.h:269
RooPolynomial
Definition: RooPolynomial.h:28
RooCategory.h
RooRealVar.h
RooCategory
Definition: RooCategory.h:27
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooAbsCollection::Print
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
Definition: RooAbsCollection.h:199
RooRealVar
Definition: RooRealVar.h:35
TMath::E
constexpr Double_t E()
Base of natural log:
Definition: TMath.h:102
RooArgSet
Definition: RooArgSet.h:28