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
16
17#include "RooArgSet.h"
18#include "RooRealVar.h"
19#include "RooAbsCollection.h"
21#include "RooProdPdf.h"
22#include "RooDataSet.h"
24
25class TTree;
26
27
28/** \namespace RooStats
29 \ingroup Roostats
30
31Namespace for the RooStats classes
32
33All the classes of the %RooStats package are in the RooStats namespace.
34In addition the namespace contain a set of utility functions.
35
36*/
37
38namespace RooStats {
40 bool useLikelihoodOffset{false}; ///< Offset the likelihood by passing RooFit::Offset to fitTo().
41 bool useEvalErrorWall{true}; ///< Use the error wall RooFit::EvalErrorWall to drive the fitter away from disallowed parameter values.
42 };
43
44 /// Retrieve the config object which can be used to set flags for things like offsetting the likelihood
45 /// or using the error wall for the minimiser.
46 RooStatsConfig& GetGlobalRooStatsConfig();
47
48 /// returns one-sided significance corresponding to a p-value
49 inline double PValueToSignificance(double pvalue){
51 }
52
53 /// returns p-value corresponding to a 1-sided significance
54 inline double SignificanceToPValue(double Z){
56 }
57
58 /// Compute the Asimov Median significance for a Poisson process
59 /// with s = expected number of signal events, b = expected number of background events
60 /// and optionally sigma_b = expected uncertainty of backgorund events
61 double AsimovSignificance(double s, double b, double sigma_b = 0.0 );
62
63 inline void SetParameters(const RooArgSet* desiredVals, RooArgSet* paramsToChange){
64 paramsToChange->assign(*desiredVals) ;
65 }
66
68 RooArgSet constSet;
69 for (auto const *myarg : static_range_cast<RooRealVar *>(*set)) {
70 if(myarg->isConstant()) constSet.add(*myarg);
71 }
72 set->remove(constSet);
73 }
74
76 RooArgSet constSet;
77 for (auto const *myarg : static_range_cast<RooRealVar *>(set)) {
78 if(myarg->isConstant()) constSet.add(*myarg);
79 }
80 set.remove(constSet);
81 }
82
83 /// utility function to set all variable constant in a collection
84 /// (from G. Petrucciani)
85 inline bool SetAllConstant(const RooAbsCollection &coll, bool constant = true) {
86 bool changed = false;
87 for (auto *v : dynamic_range_cast<RooRealVar *>(coll)) {
88 if (v && (v->isConstant() != constant)) {
89 changed = true;
90 v->setConstant(constant);
91 }
92 }
93 return changed;
94 }
95
96
97 /// assuming all values in set are RooRealVars, randomize their values
99 bool randomizeConstants = true)
100 {
101
102 // repeat loop to avoid calling isConstant for nothing
103 if (randomizeConstants) {
104 for (auto *var : static_range_cast<RooRealVar *>(set))
105 var->randomize();
106 }
107 else {
108 // exclude constants variables
109 for (auto *var : static_range_cast<RooRealVar *>(set))
110 if (!var->isConstant() )
111 var->randomize();
112 }
113
114 }
115
116 void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
117
118 void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
119
120 /// extract constraint terms from pdf
121 RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name);
122 RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, const char *name);
123 /// remove constraints from pdf and return the unconstrained pdf
124 RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name = nullptr);
125 RooAbsPdf * MakeUnconstrainedPdf(const RooStats::ModelConfig &model, const char *name = nullptr);
126
127 /// Create a TTree with the given name and description. All RooRealVars in the RooDataSet are represented as branches that contain values of type double.
129
130 /// useful function to print in one line the content of a set with their values
131 void PrintListContent(const RooArgList & l, std::ostream & os = std::cout);
132
133 /// function to set a global flag in RooStats to use NLL offset when performing nll computations
134 /// Note that not all ROoStats tools implement this capabilities
135 void UseNLLOffset(bool on);
136
137 /// function returning if the flag to check if the flag to use NLLOffset is set
138 bool IsNLLOffset();
139
140 /// function that clones a workspace, copying all needed components and discarding all others
141 RooWorkspace* MakeCleanWorkspace(RooWorkspace *oldWS, const char *newName, bool copySnapshots,
142 const char *mcname, const char *newmcname);
143
144}
145
146
147#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Definition: TGX11.cxx:110
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
Basic string class.
Definition: TString.h:136
A TTree represents a columnar dataset.
Definition: TTree.h:79
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:19
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
utility function to set all variable constant in a collection (from G.
Definition: RooStatsUtils.h:85
TTree * GetAsTTree(TString name, TString desc, const RooDataSet &data)
Create a TTree with the given name and description. All RooRealVars in the RooDataSet are represented...
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:63
double PValueToSignificance(double pvalue)
returns one-sided significance corresponding to a p-value
Definition: RooStatsUtils.h:49
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:67
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
extract constraint terms from pdf
void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints)
void RandomizeCollection(RooAbsCollection &set, bool randomizeConstants=true)
assuming all values in set are RooRealVars, randomize their values
Definition: RooStatsUtils.h:98
RooStatsConfig & GetGlobalRooStatsConfig()
Retrieve the config object which can be used to set flags for things like offsetting the likelihood o...
double AsimovSignificance(double s, double b, double sigma_b=0.0)
Compute the Asimov Median significance for a Poisson process with s = expected number of signal event...
void UseNLLOffset(bool on)
function to set a global flag in RooStats to use NLL offset when performing nll computations Note tha...
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=nullptr)
remove constraints from pdf and return the unconstrained pdf
bool IsNLLOffset()
function returning if the flag to check if the flag to use NLLOffset is set
RooWorkspace * MakeCleanWorkspace(RooWorkspace *oldWS, const char *newName, bool copySnapshots, const char *mcname, const char *newmcname)
function that clones a workspace, copying all needed components and discarding all others
double SignificanceToPValue(double Z)
returns p-value corresponding to a 1-sided significance
Definition: RooStatsUtils.h:54
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
useful function to print in one line the content of a set with their values
static constexpr double s
bool useEvalErrorWall
Use the error wall RooFit::EvalErrorWall to drive the fitter away from disallowed parameter values.
Definition: RooStatsUtils.h:41
bool useLikelihoodOffset
Offset the likelihood by passing RooFit::Offset to fitTo().
Definition: RooStatsUtils.h:40
TLine l
Definition: textangle.C:4