Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooStatsUtils.h
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer 28/07/2008
3
4/*************************************************************************
5 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOSTATS_RooStatsUtils
13#define ROOSTATS_RooStatsUtils
14
15#include "TMath.h"
16
17#include "TTree.h"
18
20
21#include "RooArgSet.h"
22#include "RooRealVar.h"
23#include "RooAbsCollection.h"
25#include "RooProdPdf.h"
26#include "RooDataSet.h"
28
29
30/** \namespace RooStats
31 \ingroup Roostats
32
33Namespace for the RooStats classes
34
35All the classes of the %RooStats package are in the RooStats namespace.
36In addition the namespace contain a set of utility functions.
37
38*/
39
40namespace RooStats {
42 bool useLikelihoodOffset{false}; /// Offset the likelihood by passing RooFit::Offset to fitTo().
43 bool useEvalErrorWall{true}; /// Use the error wall RooFit::EvalErrorWall to drive the fitter away from disallowed parameter values.
44 };
45
46 /// Retrieve the config object which can be used to set flags for things like offsetting the likelihood
47 /// or using the error wall for the minimiser.
48 RooStatsConfig& GetGlobalRooStatsConfig();
49
50 /// returns one-sided significance corresponding to a p-value
52 return ::ROOT::Math::normal_quantile_c(pvalue,1);
53 }
54
55 /// returns p-value corresponding to a 1-sided significance
57 return ::ROOT::Math::normal_cdf_c(Z);
58 }
59
60 /// Compute the Asimov Median significance for a Poisson process
61 /// with s = expected number of signal events, b = expected numner of background events
62 /// and optionally sigma_b = expected uncertainty of backgorund events
64
65 inline void SetParameters(const RooArgSet* desiredVals, RooArgSet* paramsToChange){
66 *paramsToChange=*desiredVals ;
67 }
68
70 RooArgSet constSet;
71 RooLinkedListIter it = set->iterator();
72 RooRealVar *myarg;
73 while ((myarg = (RooRealVar *)it.Next())) {
74 if(myarg->isConstant()) constSet.add(*myarg);
75 }
76 set->remove(constSet);
77 }
78
80 RooArgSet constSet;
81 RooLinkedListIter it = set.iterator();
82 RooRealVar *myarg;
83 while ((myarg = (RooRealVar *)it.Next())) {
84 if(myarg->isConstant()) constSet.add(*myarg);
85 }
86 set.remove(constSet);
87 }
88
89 inline bool SetAllConstant(const RooAbsCollection &coll, bool constant = true) {
90 // utility function to set all variable constant in a collection
91 // (from G. Petrucciani)
92 bool changed = false;
93 RooLinkedListIter iter = coll.iterator();
94 for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
95 RooRealVar *v = dynamic_cast<RooRealVar *>(a);
96 if (v && (v->isConstant() != constant)) {
97 changed = true;
98 v->setConstant(constant);
99 }
100 }
101 return changed;
102 }
103
104
105 // assuming all values in set are RooRealVars, randomize their values
107 Bool_t randomizeConstants = kTRUE)
108 {
109 RooLinkedListIter it = set.iterator();
110 RooRealVar* var;
111
112 // repeat loop to avoid calling isConstant for nothing
113 if (randomizeConstants) {
114 while ((var = (RooRealVar*)it.Next()) != NULL)
115 var->randomize();
116 }
117 else {
118 // exclude constants variables
119 while ((var = (RooRealVar*)it.Next()) != NULL)
120 if (!var->isConstant() )
121 var->randomize();
122 }
123
124
125 }
126
127 void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
128
129 void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
130
131 // extract constraint terms from pdf
132 RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name);
133 RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, const char *name);
134 // remove constraints from pdf and return the unconstrained pdf
135 RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name = NULL);
136 RooAbsPdf * MakeUnconstrainedPdf(const RooStats::ModelConfig &model, const char *name = NULL);
137
138 // Create a TTree with the given name and description. All RooRealVars in the RooDataSet are represented as branches that contain values of type Double_t.
139 TTree* GetAsTTree(TString name, TString desc, const RooDataSet& data);
140
141 // useful function to print in one line the content of a set with their values
142 void PrintListContent(const RooArgList & l, std::ostream & os = std::cout);
143
144 // function to set a global flag in RooStats to use NLL offset when performing nll computations
145 // Note that not all ROoStats tools implement this capabilities
146 void UseNLLOffset(bool on);
147
148 // function returning if the flag to check if the flag to use NLLOffset is set
149 bool IsNLLOffset();
150
151
152
153}
154
155
156#endif
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
char name[80]
Definition TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
Bool_t isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:380
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooLinkedListIter iterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
virtual void randomize(const char *rangeName=0)
Set a new value sampled from a uniform distribution over the fit range.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:33
A wrapper around TIterator derivatives.
TObject * Next() override
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition ModelConfig.h:30
Basic string class.
Definition TString.h:136
A TTree represents a columnar dataset.
Definition TTree.h:79
Namespace for the RooStats classes.
Definition Asimov.h:19
Double_t AsimovSignificance(Double_t s, Double_t b, Double_t sigma_b=0.0)
Compute the Asimov Median significance for a Poisson process with s = expected number of signal event...
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
TTree * GetAsTTree(TString name, TString desc, const RooDataSet &data)
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
void RemoveConstantParameters(RooArgSet *set)
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints)
RooStatsConfig & GetGlobalRooStatsConfig()
Retrieve the config object which can be used to set flags for things like offsetting the likelihood o...
void RandomizeCollection(RooAbsCollection &set, Bool_t randomizeConstants=kTRUE)
Double_t PValueToSignificance(Double_t pvalue)
returns one-sided significance corresponding to a p-value
void UseNLLOffset(bool on)
Use an offset in NLL calculations.
bool IsNLLOffset()
Test of RooStats should by default offset NLL calculations.
Double_t SignificanceToPValue(Double_t Z)
returns p-value corresponding to a 1-sided significance
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
bool useEvalErrorWall
Offset the likelihood by passing RooFit::Offset to fitTo().
auto * l
Definition textangle.C:4