Logo ROOT  
Reference Guide
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"
27
28
29/** \namespace RooStats
30 \ingroup Roostats
31
32Namespace for the RooStats classes
33
34All the classes of the %RooStats package are in the RooStats namespace.
35In addition the namespace contain a set of utility functions.
36
37*/
38
39namespace RooStats {
41 bool useLikelihoodOffset{false}; /// Offset the likelihood by passing RooFit::Offset to fitTo().
42 bool useEvalErrorWall{true}; /// Use the error wall RooFit::EvalErrorWall to drive the fitter away from disallowed parameter values.
43 };
44
45 /// Retrieve the config object which can be used to set flags for things like offsetting the likelihood
46 /// or using the error wall for the minimiser.
47 RooStatsConfig& GetGlobalRooStatsConfig();
48
49 /// returns one-sided significance corresponding to a p-value
52 }
53
54 /// returns p-value corresponding to a 1-sided significance
57 }
58
59 /// Compute the Asimov Median significance for a Poisson process
60 /// with s = expected number of signal events, b = expected numner of background events
61 /// and optionally sigma_b = expected uncertainty of backgorund events
63
64 inline void SetParameters(const RooArgSet* desiredVals, RooArgSet* paramsToChange){
65 *paramsToChange=*desiredVals ;
66 }
67
69 RooArgSet constSet;
70 RooLinkedListIter it = set->iterator();
71 RooRealVar *myarg;
72 while ((myarg = (RooRealVar *)it.Next())) {
73 if(myarg->isConstant()) constSet.add(*myarg);
74 }
75 set->remove(constSet);
76 }
77
79 RooArgSet constSet;
80 RooLinkedListIter it = set.iterator();
81 RooRealVar *myarg;
82 while ((myarg = (RooRealVar *)it.Next())) {
83 if(myarg->isConstant()) constSet.add(*myarg);
84 }
85 set.remove(constSet);
86 }
87
88 inline bool SetAllConstant(const RooAbsCollection &coll, bool constant = true) {
89 // utility function to set all variable constant in a collection
90 // (from G. Petrucciani)
91 bool changed = false;
92 RooLinkedListIter iter = coll.iterator();
93 for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
94 RooRealVar *v = dynamic_cast<RooRealVar *>(a);
95 if (v && (v->isConstant() != constant)) {
96 changed = true;
97 v->setConstant(constant);
98 }
99 }
100 return changed;
101 }
102
103
104 // assuming all values in set are RooRealVars, randomize their values
106 Bool_t randomizeConstants = kTRUE)
107 {
108 RooLinkedListIter it = set.iterator();
109 RooRealVar* var;
110
111 // repeat loop to avoid calling isConstant for nothing
112 if (randomizeConstants) {
113 while ((var = (RooRealVar*)it.Next()) != NULL)
114 var->randomize();
115 }
116 else {
117 // exclude constants variables
118 while ((var = (RooRealVar*)it.Next()) != NULL)
119 if (!var->isConstant() )
120 var->randomize();
121 }
122
123
124 }
125
126 void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
127
128 void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
129
130 // extract constraint terms from pdf
131 RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name);
132 RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, const char *name);
133 // remove constraints from pdf and return the unconstrained pdf
134 RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name = NULL);
135 RooAbsPdf * MakeUnconstrainedPdf(const RooStats::ModelConfig &model, const char *name = NULL);
136
137 // 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.
138 TTree* GetAsTTree(TString name, TString desc, const RooDataSet& data);
139
140 // useful function to print in one line the content of a set with their values
141 void PrintListContent(const RooArgList & l, std::ostream & os = std::cout);
142
143 // function to set a global flag in RooStats to use NLL offset when performing nll computations
144 // Note that not all ROoStats tools implement this capabilities
145 void UseNLLOffset(bool on);
146
147 // function returning if the flag to check if the flag to use NLLOffset is set
148 bool IsNLLOffset();
149
150
151
152}
153
154
155#endif
#define b(i)
Definition: RSha256.hxx:100
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
char name[80]
Definition: TGX11.cxx:109
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
Bool_t isConstant() const
Definition: RooAbsArg.h:320
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooLinkedListIter iterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
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:28
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
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
A wrapper around TIterator derivatives.
TObject * Next() override
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
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:131
A TTree represents a columnar dataset.
Definition: TTree.h:72
double normal_cdf_c(double x, double sigma=1, double x0=0)
Complement of the cumulative distribution function of the normal (Gaussian) distribution (upper tail)...
double normal_quantile_c(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the upper tail of the normal (Gaussian) distri...
Namespace for the RooStats classes.
Definition: Asimov.h:20
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)
Definition: RooStatsUtils.h:88
TTree * GetAsTTree(TString name, TString desc, const RooDataSet &data)
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:64
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:68
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
Definition: RooStatsUtils.h:50
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
Definition: RooStatsUtils.h:55
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
static constexpr double s
bool useEvalErrorWall
Offset the likelihood by passing RooFit::Offset to fitTo().
Definition: RooStatsUtils.h:42
auto * l
Definition: textangle.C:4
auto * a
Definition: textangle.C:12