This tool has now been superseded by RooSimWSTool
RooSimPdfBuilder
is a powerful tool to build RooSimultaneous
PDFs that are defined in terms component PDFs that are identical in structure, but have different parameters.
The following example demonstrates the essence of RooSimPdfBuilder
: Given a dataset D with a RooRealVar X
and a RooCategory C
that has state C1 and C2.
X
with a Gaussian+ArgusBG PDF, D(C==C1)
and D(C==C2)
separately and simultaneously. Coding this example directly with RooFit classes gives (we assume dataset D and variables C and X have been declared previously)
RooRealVar m("m","mean of gaussian",-10,10) ; RooRealVar s_C1("s_C1","sigma of gaussian C1",0,20) ; RooRealVar s_C2("s_C2","sigma of gaussian C2",0,20) ; RooGaussian gauss_C1("gauss_C1","gaussian C1",X,m,s_C1) ; RooGaussian gauss_C2("gauss_C2","gaussian C2",X,m,s_C2) ; RooRealVar k_C1("k_C1","ArgusBG kappa parameter C1",-50,0) ; RooRealVar k_C2("k_C2","ArgusBG kappa parameter C2",-50,0) ; RooRealVar xm("xm","ArgusBG cutoff point",5.29) ; RooArgusBG argus_C1("argus_C1","argus background C1",X,k_C1,xm) ; RooArgusBG argus_C2("argus_C2","argus background C2",X,k_C2,xm) ; RooRealVar gfrac("gfrac","fraction of gaussian",0.,1.) ; RooAddPdf pdf_C1("pdf_C1","gauss+argus_C1",RooArgList(gauss_C1,argus_C1),gfrac) ; RooAddPdf pdf_C2("pdf_C2","gauss+argus_C2",RooArgList(gauss_C2,argus_C2),gfrac) ; RooSimultaneous simPdf("simPdf","simPdf",C) ; simPdf.addPdf(pdf_C1,"C1") ; simPdf.addPdf(pdf_C2,"C2") ;
Coding this example with RooSimPdfBuilder gives
RooRealVar m("m","mean of gaussian",-10,10) ; RooRealVar s("s","sigma of gaussian",0,20) ; RooGaussian gauss("gauss","gaussian",X,m,s) ; RooRealVar k("k","ArgusBG kappa parameter",-50,0) ; RooRealVar xm("xm","ArgusBG cutoff point",5.29) ; RooArgusBG argus("argus","argus background",X,k,xm) ; RooRealVar gfrac("gfrac","fraction of gaussian",0.,1.) ; RooAddPdf pdf("pdf","gauss+argus",RooArgList(gauss,argus),gfrac) ; RooSimPdfBuilder builder(pdf) ; RooArgSet* cfg = builder.createProtoBuildConfig() ; dynamic_cast<RooStringVar&>((*cfg)["physModels"]) = "pdf" ; /// Name of the PDF we are going to work with dynamic_cast<RooStringVar&>((*cfg)["splitCats"]) = "C" ; /// Category used to differentiate sub-datasets dynamic_cast<RooStringVar&>((*cfg)["pdf"]) = "C : k,s" ; /// Prescription to taylor PDF parameters k and s /// for each data subset designated by C states RooSimultaneous* simPdf = builder.buildPdf(*cfg,&D) ;
The above snippet of code demonstrates the concept of RooSimPdfBuilder
: the user defines a single 'prototype' PDF that defines the structure of all PDF components of the RooSimultaneous
PDF to be built. RooSimPdfBuilder
then takes this prototype and replicates it as a component PDF for each state of the C index category.
In the above example RooSimPdfBuilder
will first replicate k
and s
into k_C1,k_C2
and s_C1,s_C2
, as prescribed in the configuration. Then it will recursively replicate all PDF nodes that depend on the 'split' parameter nodes: gauss
into gauss_C1,C2
, argus
into argus_C1,C2
and finally pdf
into pdf_C1,pdf_C2
. When PDFs for all states of C have been replicated they are assembled into a RooSimultaneous
PDF, which is returned by the buildPdf()
method.
Although in this very simple example the use of RooSimPdfBuilder
doesn't reduce the amount of code much, it is already easier to read and maintain because there is no duplicate code. As the complexity of the RooSimultaneous
to be built increases, the advantages of RooSimPdfBuilder
will become more and more apparent.
Each builder configuration needs at minumum two lines, physModels
and splitCats
, which identify the ingredients of the build. In this section we only explain the building rules for builds from a single prototype PDF. In that case the physModels
line always reads
physModels = {pdfName}
The second line, splitCats
, indicates which categories are going to be used to differentiate the various subsets of the 'master' input data set. You can enter a single category here, or multiple if necessary:
splitCats = {catName} [{catName} ...]
All listed splitcats must be RooCategories
that appear in the dataset provided to RooSimPdfBuilder::buildPdf()
The parameter splitting prescriptions, the essence of each build configuration can be supplied in a third line carrying the name of the pdf listed in physModels
pdfName = {splitCat} : {parameter} [,{parameter},....]
Each pdf can have only one line with splitting rules, but multiple rules can be supplied in each line, e.g.
pdfName = {splitCat} : {parameter} [,{parameter},....] {splitCat} : {parameter} [,{parameter},....]
Conversely, each parameter can only have one splitting prescription, but it may be split by multiple categories, e.g.
pdfName = {splitCat1},{splitCat2} : {parameter}
instructs RooSimPdfBuilder
to build a RooSuperCategory
of {splitCat1}
and {splitCat2}
and split {parameter}
with that RooSuperCategory
Here is an example of a builder configuration that uses several of the options discussed above:
physModels = pdf splitCats = tagCat runBlock pdf = tagCat : signalRes,bkgRes runBlock : fudgeFactor tagCat,runBlock : kludgeParam
The prototype builder configuration returned by RooSimPdfBuilder::createProtoBuildConfig()
is a pointer to a RooArgSet
filled with initially blank RooStringVars
named physModels,splitCats
and one additional for each PDF supplied to the RooSimPdfBuilders
constructor (with the same name)
In macro code, the easiest way to assign new values to these RooStringVars
is to use RooArgSet
s array operator and the RooStringVar
s assignment operator, e.g.
(*config)["physModels"] = "Blah" ;
To enter multiple splitting rules simply separate consecutive rules by whitespace (not newlines), e.g.
(*config)["physModels"] = "Blah " /// << note trailing space here "Blah 2" ;
In this example, the C++ compiler will concatenate the two string literals (without inserting any whitespace), so the extra space after 'Blah' is important here.
Alternatively, you can read the configuration from an ASCII file, as you can for any RooArgSet
using RooArgSet::readFromFile()
. In that case the ASCII file can follow the syntax of the examples above and the '\
' line continuation sequence can be used to fold a long splitting rule over multiple lines.
RooArgSet* config = builder.createProtoBuildConfig() ; config->readFromFile("config.txt") ; --- config.txt ---------------- physModels = pdf splitCats = tagCat pdf = tagCat : bogusPar -------------------------------
It is also possible to build a RooSimultaneous
PDF from multiple PDF prototypes. This is appropriate for cases where the input prototype PDF would otherwise be a RooSimultaneous
PDF by itself. In such cases we don't feed a single RooSimultaneous
PDF into RooSimPdfBuilder
, instead we feed it its ingredients and add a prescription to the builder configuration that corresponds to the PDF-category state mapping of the prototype RooSimultaneous
.
The constructor of the RooSimPdfBuilder
will look as follows:
RooSimPdfBuilder builder(RooArgSet(pdfA,pdfB,...)) ;
The physModels
line is now expanded to carry the pdf->state mapping information that the prototype RooSimultaneous
would have. I.e.
physModels = mode : pdfA=modeA pdfB=modeB
is equivalent to a prototype RooSimultaneous
constructed as
RooSimultanous simPdf("simPdf","simPdf",mode); simPdf.addPdf(pdfA,"modeA") ; simPdf.addPdf(pdfB,"modeB") ;
The rest of the builder configuration works the same, except that each prototype PDF now has its own set of splitting rules, e.g.
physModels = mode : pdfA=modeA pdfB=modeB splitCats = tagCat pdfA = tagCat : bogusPar pdfB = tagCat : fudgeFactor
Please note that
The master index category ('mode' above) doesn't have to be listed in splitCats
, this is implicit.
In the following case: /p>
physModels = mode : pdfA=modeA pdfB=modeB pdfA=modeC pdfB=modeD
there are still only 2 sets of splitting rules: one for pdfA
and one for pdfB
. However, you can differentiate between modeA
and modeC
in the above example. The technique is to use mode
as splitting category, e.g.
physModels = mode : pdfA=modeA pdfB=modeB pdfA=modeC pdfB=modeD splitCats = tagCat pdfA = tagCat : bogusPar mode : funnyPar pdfB = mode : kludgeFactor
will result in an individual set of funnyPar
parameters for modeA
and modeC
labeled funnyPar_modeA
and funnyPar_modeB
and an individual set of kludgeFactor parameters for pdfB
, kludgeFactor_modeB
and kludgeFactor_modeD
. Please note that for splits in the master index category (mode) only the applicable states are built (A,C for pdfA
, B,D for pdfB
)
You can request to limit the list of states of each splitCat that will be considered in the build. This limitation is requested in the each build as follows:
splitCats = tagCat(Lep,Kao) RunBlock(Run1)
In this example the splitting of tagCat
is limited to states Lep,Kao
and the splitting of runBlock
is limited to Run1
. The splits apply globally to each build, i.e. every parameter split requested in this build will be limited according to these specifications.
NB: Partial builds have no pdf associated with the unbuilt states of the limited splits. Running such a pdf on a dataset that contains data with unbuilt states will result in this data being ignored completely.
It is possible to make non-trivial parameter splits with RooSimPdfBuilder
. Trivial splits are considered simple splits in one (fundamental) category in the dataset or a split in a RooSuperCategory
'product' of multiple fundamental categories in the dataset. Non-trivial splits can be performed using an intermediate 'category function' (RooMappedCategory, RooGenericCategory,RooThresholdCategory
etc), i.e. any RooAbsCategory
derived objects that calculates its output as function of one or more input RooRealVars
and/or RooCategories
.
Such 'function categories' objects must be constructed by the user prior to building the PDF. In the RooSimPdfBuilder::buildPdf()
function these objects can be passed in an optional RooArgSet
called 'auxiliary categories':
const RooSimultaneous
* buildPdf(const RooArgSet& buildConfig, const RooAbsData* dataSet,
const RooArgSet& auxSplitCats, bool verbose=false) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Objects passed in this argset can subsequently be used in the build configuration, e.g.
RooMappedCategory tagMap("tagMap","Mapped tagging category",tagCat,"CutBased") ; tagMap.map("Lep","CutBased") ; tagMap.map("Kao","CutBased") ; tagMap.map("NT*","NeuralNet") ; ... builder.buildPdf(config,D,tagMap) ; ^^^^^^ Contents of config> physModels = pdf splitCats = tagCat runBlock pdf = tagCat : signalRes tagMap : fudgeFactor ^^^^^^
In the above example signalRes
will be split in signalRes_Kao,signalRes_Lep, signalRes_NT1,signalRes_NT2
, while fudgeFactor
will be split in fudgeFactor_CutBased
and fudgeFactor_NeuralNet
.
Category functions passed in the auxSplitCats RooArgSet
can be used regularly in the splitting configuration. They should not be listed in splitCats
, but must be able to be expressed completely in terms of the splitCats
that are listed.
Sometimes you want to build multiple PDFs for independent consecutive fits that share some of their parameters. For example, we have two prototype PDFs pdfA(x;p,q)
and pdfB(x;p,r)
that have a common parameter p
. We want to build a RooSimultaneous
for both pdfA
and B
, which involves a split of parameter p
and we would like to build the simultaneous pdfs simA
and simB
such that still share their (now split) parameters p_XXX
. This is accomplished by letting a single instance of RooSimPdfBuilder
handle the builds of both pdfA
and pdfB
, as illustrated in this example:
RooSimPdfBuilder builder(RooArgSet(pdfA,pdfB)) ; RooArgSet* configA = builder.createProtoBuildConfig() ; (*configA)["physModels"] = "pdfA" ; (*configA)["splitCats"] = "C" ; (*configA)["pdf"] = "C : p" ; RooSimultaneous* simA = builder.buildPdf(*configA,&D) ; RooArgSet* configB = builder.createProtoBuildConfig() ; (*configA)["physModels"] = "pdfB" ; (*configA)["splitCats"] = "C" ; (*configA)["pdf"] = "C : p" ; RooSimultaneous* simB = builder.buildPdf(*configB,&D) ;
The RooSimPdfBuilder
instance owns all the objects it creates, including the top-level RooSimultaneous
returned by buildPdf()
. Therefore the builder instance should exist as long as the constructed PDFs needs to exist.
Definition at line 32 of file RooSimPdfBuilder.h.
Public Member Functions | |
RooSimPdfBuilder (const RooArgSet &pdfProtoList) | |
~RooSimPdfBuilder () | |
void | addSpecializations (const RooArgSet &specSet) |
RooSimultaneous * | buildPdf (const RooArgSet &buildConfig, const RooAbsData *dataSet, const RooArgSet &auxSplitCats, bool verbose=false) |
RooSimultaneous * | buildPdf (const RooArgSet &buildConfig, const RooAbsData *dataSet, const RooArgSet *auxSplitCats=0, bool verbose=false) |
RooSimultaneous * | buildPdf (const RooArgSet &buildConfig, const RooArgSet &dependents, const RooArgSet &auxSplitCats, bool verbose=false) |
RooSimultaneous * | buildPdf (const RooArgSet &buildConfig, const RooArgSet &dependents, const RooArgSet *auxSplitCats=0, bool verbose=false) |
Initialize needed components. | |
RooArgSet * | createProtoBuildConfig () |
Make RooArgSet of configuration objects. | |
const RooArgSet & | splitLeafList () |
Public Member Functions inherited from TObject | |
TObject () | |
TObject constructor. | |
TObject (const TObject &object) | |
TObject copy ctor. | |
virtual | ~TObject () |
TObject destructor. | |
void | AbstractMethod (const char *method) const |
Use this method to implement an "abstract" method that you don't want to leave purely abstract. | |
virtual void | AppendPad (Option_t *option="") |
Append graphics object to current pad. | |
virtual void | Browse (TBrowser *b) |
Browse object. May be overridden for another default action. | |
ULong_t | CheckedHash () |
Check and record whether this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object. | |
virtual const char * | ClassName () const |
Returns name of class to which the object belongs. | |
virtual void | Clear (Option_t *="") |
virtual TObject * | Clone (const char *newname="") const |
Make a clone of an object using the Streamer facility. | |
virtual Int_t | Compare (const TObject *obj) const |
Compare abstract method. | |
virtual void | Copy (TObject &object) const |
Copy this to obj. | |
virtual void | Delete (Option_t *option="") |
Delete this object. | |
virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
Computes distance from point (px,py) to the object. | |
virtual void | Draw (Option_t *option="") |
Default Draw method for all objects. | |
virtual void | DrawClass () const |
Draw class inheritance tree of the class to which this object belongs. | |
virtual TObject * | DrawClone (Option_t *option="") const |
Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad) . | |
virtual void | Dump () const |
Dump contents of object on stdout. | |
virtual void | Error (const char *method, const char *msgfmt,...) const |
Issue error message. | |
virtual void | Execute (const char *method, const char *params, Int_t *error=0) |
Execute method on this object with the given parameter string, e.g. | |
virtual void | Execute (TMethod *method, TObjArray *params, Int_t *error=0) |
Execute method on this object with parameters stored in the TObjArray. | |
virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
Execute action corresponding to an event at (px,py). | |
virtual void | Fatal (const char *method, const char *msgfmt,...) const |
Issue fatal error message. | |
virtual TObject * | FindObject (const char *name) const |
Must be redefined in derived classes. | |
virtual TObject * | FindObject (const TObject *obj) const |
Must be redefined in derived classes. | |
virtual Option_t * | GetDrawOption () const |
Get option used by the graphics system to draw this object. | |
virtual const char * | GetIconName () const |
Returns mime type name of object. | |
virtual const char * | GetName () const |
Returns name of object. | |
virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
Returns string containing info about the object at position (px,py). | |
virtual Option_t * | GetOption () const |
virtual const char * | GetTitle () const |
Returns title of object. | |
virtual UInt_t | GetUniqueID () const |
Return the unique object id. | |
virtual Bool_t | HandleTimer (TTimer *timer) |
Execute action in response of a timer timing out. | |
virtual ULong_t | Hash () const |
Return hash value for this object. | |
Bool_t | HasInconsistentHash () const |
Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e. | |
virtual void | Info (const char *method, const char *msgfmt,...) const |
Issue info message. | |
virtual Bool_t | InheritsFrom (const char *classname) const |
Returns kTRUE if object inherits from class "classname". | |
virtual Bool_t | InheritsFrom (const TClass *cl) const |
Returns kTRUE if object inherits from TClass cl. | |
virtual void | Inspect () const |
Dump contents of this object in a graphics canvas. | |
void | InvertBit (UInt_t f) |
Bool_t | IsDestructed () const |
IsDestructed. | |
virtual Bool_t | IsEqual (const TObject *obj) const |
Default equal comparison (objects are equal if they have the same address in memory). | |
virtual Bool_t | IsFolder () const |
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects). | |
R__ALWAYS_INLINE Bool_t | IsOnHeap () const |
virtual Bool_t | IsSortable () const |
R__ALWAYS_INLINE Bool_t | IsZombie () const |
virtual void | ls (Option_t *option="") const |
The ls function lists the contents of a class on stdout. | |
void | MayNotUse (const char *method) const |
Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary). | |
virtual Bool_t | Notify () |
This method must be overridden to handle object notification. | |
void | Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const |
Use this method to declare a method obsolete. | |
void | operator delete (void *ptr) |
Operator delete. | |
void | operator delete[] (void *ptr) |
Operator delete []. | |
void * | operator new (size_t sz) |
void * | operator new (size_t sz, void *vp) |
void * | operator new[] (size_t sz) |
void * | operator new[] (size_t sz, void *vp) |
TObject & | operator= (const TObject &rhs) |
TObject assignment operator. | |
virtual void | Paint (Option_t *option="") |
This method must be overridden if a class wants to paint itself. | |
virtual void | Pop () |
Pop on object drawn in a pad to the top of the display list. | |
virtual void | Print (Option_t *option="") const |
This method must be overridden when a class wants to print itself. | |
virtual Int_t | Read (const char *name) |
Read contents of object with specified name from the current directory. | |
virtual void | RecursiveRemove (TObject *obj) |
Recursively remove this object from a list. | |
void | ResetBit (UInt_t f) |
virtual void | SaveAs (const char *filename="", Option_t *option="") const |
Save this object in the file specified by filename. | |
virtual void | SavePrimitive (std::ostream &out, Option_t *option="") |
Save a primitive as a C++ statement(s) on output stream "out". | |
void | SetBit (UInt_t f) |
void | SetBit (UInt_t f, Bool_t set) |
Set or unset the user status bits as specified in f. | |
virtual void | SetDrawOption (Option_t *option="") |
Set drawing option for object. | |
virtual void | SetUniqueID (UInt_t uid) |
Set the unique object id. | |
virtual void | SysError (const char *method, const char *msgfmt,...) const |
Issue system error message. | |
R__ALWAYS_INLINE Bool_t | TestBit (UInt_t f) const |
Int_t | TestBits (UInt_t f) const |
virtual void | UseCurrentStyle () |
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked. | |
virtual void | Warning (const char *method, const char *msgfmt,...) const |
Issue warning message. | |
virtual Int_t | Write (const char *name=0, Int_t option=0, Int_t bufsize=0) |
Write this object to the current directory. | |
virtual Int_t | Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const |
Write this object to the current directory. | |
Protected Attributes | |
RooArgSet | _compSplitCatSet |
std::list< RooSuperCategory * > | _fitCatList |
RooArgSet | _protoPdfSet |
TList | _retiredCustomizerList |
std::list< RooSimultaneous * > | _simPdfList |
RooArgSet | _splitNodeList |
RooArgSet | _splitNodeListOwned |
Private Member Functions | |
RooSimPdfBuilder (const RooSimPdfBuilder &) | |
Additional Inherited Members | |
Public Types inherited from TObject | |
enum | { kIsOnHeap = 0x01000000 , kNotDeleted = 0x02000000 , kZombie = 0x04000000 , kInconsistent = 0x08000000 , kBitMask = 0x00ffffff } |
enum | { kSingleKey = BIT(0) , kOverwrite = BIT(1) , kWriteDelete = BIT(2) } |
enum | EDeprecatedStatusBits { kObjInCanvas = BIT(3) } |
enum | EStatusBits { kCanDelete = BIT(0) , kMustCleanup = BIT(3) , kIsReferenced = BIT(4) , kHasUUID = BIT(5) , kCannotPick = BIT(6) , kNoContextMenu = BIT(8) , kInvalidObject = BIT(13) } |
Static Public Member Functions inherited from TObject | |
static Longptr_t | GetDtorOnly () |
Return destructor only flag. | |
static Bool_t | GetObjectStat () |
Get status of object stat flag. | |
static void | SetDtorOnly (void *obj) |
Set destructor only flag. | |
static void | SetObjectStat (Bool_t stat) |
Turn on/off tracking of objects in the TObjectTable. | |
Protected Types inherited from TObject | |
enum | { kOnlyPrepStep = BIT(3) } |
Protected Member Functions inherited from TObject | |
virtual void | DoError (int level, const char *location, const char *fmt, va_list va) const |
Interface to ErrorHandler (protected). | |
void | MakeZombie () |
#include <RooSimPdfBuilder.h>
RooSimPdfBuilder::RooSimPdfBuilder | ( | const RooArgSet & | pdfProtoList | ) |
Definition at line 466 of file RooSimPdfBuilder.cxx.
RooSimPdfBuilder::~RooSimPdfBuilder | ( | ) |
Definition at line 1029 of file RooSimPdfBuilder.cxx.
|
private |
Definition at line 497 of file RooSimPdfBuilder.cxx.
|
inline |
Definition at line 43 of file RooSimPdfBuilder.h.
|
inline |
Definition at line 53 of file RooSimPdfBuilder.h.
|
inline |
Definition at line 48 of file RooSimPdfBuilder.h.
RooSimultaneous * RooSimPdfBuilder::buildPdf | ( | const RooArgSet & | buildConfig, |
const RooArgSet & | dependents, | ||
const RooArgSet * | auxSplitCats = 0 , |
||
bool | verbose = false |
||
) |
Initialize needed components.
Definition at line 507 of file RooSimPdfBuilder.cxx.
RooArgSet * RooSimPdfBuilder::createProtoBuildConfig | ( | ) |
Make RooArgSet of configuration objects.
Definition at line 480 of file RooSimPdfBuilder.cxx.
|
inline |
Definition at line 58 of file RooSimPdfBuilder.h.
|
protected |
Definition at line 66 of file RooSimPdfBuilder.h.
|
protected |
Definition at line 72 of file RooSimPdfBuilder.h.
|
protected |
Definition at line 64 of file RooSimPdfBuilder.h.
|
protected |
Definition at line 69 of file RooSimPdfBuilder.h.
|
protected |
Definition at line 71 of file RooSimPdfBuilder.h.
|
protected |
Definition at line 68 of file RooSimPdfBuilder.h.
|
protected |
Definition at line 67 of file RooSimPdfBuilder.h.