Logo ROOT  
Reference Guide
rf508_listsetmanip.C File Reference

Detailed Description

View in nbviewer Open in SWAN Organization and simultaneous fits: RooArgSet and RooArgList tools and tricks

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
[#0] WARNING:InputArguments -- The parameter 'b' with range [-10, 10] of the RooGaussian 'g' exceeds the safe range of (0, inf). Advise to limit its range.
sclone = (a,b,c,d,e,g)
RooArgSet::sclone = (a,b,c,d,e,g)
1) RooRealVar:: a = 1
2) RooRealVar:: b = 2
3) RooRealVar:: c = 3 +/- 0.5
4) RooRealVar:: d = 4
5) RooCategory:: e = sig(idx = 0)
6) RooGaussian:: g = 0.882497
1) 0x55d8cc669df0 RooRealVar:: a = 1 C L(-10 - 10) "a"
2) 0x55d8cbf85340 RooRealVar:: b = 2 C L(-10 - 10) "b"
3) 0x55d8cc3f7780 RooRealVar:: c = 3 +/- 0.5 L(-10 - 10) "c"
4) 0x55d8cc4df520 RooRealVar:: d = 4 L(-10 - 10) "d"
5) 0x55d8cc1264d0 RooCategory:: e = sig(idx = 0)
"e"
6) 0x55d8cc4dfbe0 RooGaussian:: g[ x=x mean=a sigma=b ] = 0.882497 "g"
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "RooArgSet.h"
#include "RooArgList.h"
#include "RooCategory.h"
using namespace RooFit;
void rf508_listsetmanip()
{
// C r e a t e d u m m y o b j e c t s
// ---------------------------------------
// Create some variables
RooRealVar a("a", "a", 1, -10, 10);
RooRealVar b("b", "b", 2, -10, 10);
RooRealVar c("c", "c", 3, -10, 10);
RooRealVar d("d", "d", 4, -10, 10);
RooRealVar x("x", "x", 0, -10, 10);
c.setError(0.5);
a.setConstant();
b.setConstant();
// Create a category
RooCategory e("e", "e");
e.defineType("sig");
e.defineType("bkg");
// Create a pdf
RooGaussian g("g", "g", x, a, b);
// C r e a t i n g , f i l l i n g R o o A r g S e t s
// -------------------------------------------------------
// A RooArgSet is a set of RooAbsArg objects. Each object in the set must have
// a unique name
// Set constructors exists with up to 9 initial arguments
// At any time objects can be added with add()
s.add(e);
// Add up to 9 additional arguments in one call
s.add(RooArgSet(c, d));
// Sets can contain any type of RooAbsArg, also pdf and functions
s.add(g);
// Remove element d
s.remove(d);
// A c c e s s i n g R o o A r g S e t c o n t e n t s
// -------------------------------------------------------
// You can look up objects by name
RooAbsArg *aptr = s.find("a");
// Construct a subset by name
RooArgSet *subset1 = (RooArgSet *)s.selectByName("a,b,c");
// Construct asubset by attribute
RooArgSet *subset2 = (RooArgSet *)s.selectByAttrib("Constant", kTRUE);
// Construct the subset of overlapping contents with another set
RooArgSet s2(c, d, e);
RooArgSet *subset3 = (RooArgSet *)s1.selectCommon(s2);
// O w n i n g R o o A r g S e t s
// ---------------------------------
// Create a RooArgSet that owns its components
// A set either owns all of its components or none,
// so once addOwned() is used, add() can no longer be
// used and will result in an error message
RooRealVar *ac = (RooRealVar *)a.clone("a");
RooRealVar *bc = (RooRealVar *)b.clone("b");
RooRealVar *cc = (RooRealVar *)c.clone("c");
s3.addOwned(RooArgSet(*ac, *bc, *cc));
// Another possibility is to add an owned clone
// of an object instead of the original
// A clone of a owning set is non-owning and its
// contents is owned by the originating owning set
RooArgSet *sclone = (RooArgSet *)s3.Clone("sclone");
// To make a clone of a set and its contents use
// the snapshot method
RooArgSet *sclone2 = (RooArgSet *)s3.snapshot();
// If a set contains function objects, only the head node
// is cloned in a snapshot. To make a snapshot of all
// servers of a function object do as follows. The result
// of a RooArgSet snapshot with deepCloning option is a set
// of cloned objects, and all their clone (recursive) server
// dependencies, that together form a self-consistent
// set that is free of external dependencies
RooArgSet *sclone3 = (RooArgSet *)s3.snapshot(kTRUE);
// S e t p r i n t i n g
// ------------------------
// Inline printing only show list of names of contained objects
cout << "sclone = " << (*sclone) << endl;
// Plain print shows the same, prefixed by name of the set
sclone->Print();
// Standard printing shows one line for each item with the items name, class name and value
sclone->Print("s");
// Verbose printing adds each items arguments, address and 'extras' as defined by the object
sclone->Print("v");
// U s i n g R o o A r g L i s t s
// ---------------------------------
// List constructors exists with up to 9 initial arguments
RooArgList l(a, b, c, d);
// Lists have an explicit order and allow multiple arguments with the same name
l.add(RooArgList(a, b, c, d));
// Access by index is provided
RooAbsArg *arg4 = l.at(4);
}
Date
July 2008
Author
Wouter Verkerke

Definition in file rf508_listsetmanip.C.

c
#define c(i)
Definition: RSha256.hxx:101
l
auto * l
Definition: textangle.C:4
RooArgSet::addOwned
Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to an owning set.
Definition: RooArgSet.cxx:274
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
e
#define e(i)
Definition: RSha256.hxx:103
RooArgSet::addClone
RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add clone of specified element to an owning set.
Definition: RooArgSet.cxx:288
RooArgSet.h
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooGaussian.h
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
TCanvas.h
RooDataSet.h
b
#define b(i)
Definition: RSha256.hxx:100
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:126
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
a
auto * a
Definition: textangle.C:12
s1
#define s1(x)
Definition: RSha256.hxx:91
RooPlot.h
RooCategory.h
RooRealVar.h
RooConstVar.h
RooCategory
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:27
TAxis.h
RooAbsCollection::Clone
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsCollection.h:42
d
#define d(i)
Definition: RSha256.hxx:102
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
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:200
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooArgList.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
g
#define g(i)
Definition: RSha256.hxx:105