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"
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
51 inline double PValueToSignificance(double pvalue){
53 }
54
55 /// returns p-value corresponding to a 1-sided significance
56 inline double SignificanceToPValue(double Z){
58 }
59
60 /// Compute the Asimov Median significance for a Poisson process
61 /// with s = expected number of signal events, b = expected number of background events
62 /// and optionally sigma_b = expected uncertainty of backgorund events
63 double AsimovSignificance(double s, double b, double sigma_b = 0.0 );
64
65 inline void SetParameters(const RooArgSet* desiredVals, RooArgSet* paramsToChange){
66 paramsToChange->assign(*desiredVals) ;
67 }
68
70 RooArgSet constSet;
71 for (auto const *myarg : static_range_cast<RooRealVar *>(*set)) {
72 if(myarg->isConstant()) constSet.add(*myarg);
73 }
74 set->remove(constSet);
75 }
76
78 RooArgSet constSet;
79 for (auto const *myarg : static_range_cast<RooRealVar *>(set)) {
80 if(myarg->isConstant()) constSet.add(*myarg);
81 }
82 set.remove(constSet);
83 }
84
85 /// utility function to set all variable constant in a collection
86 /// (from G. Petrucciani)
87 inline bool SetAllConstant(const RooAbsCollection &coll, bool constant = true) {
88 bool changed = false;
89 for (auto *v : dynamic_range_cast<RooRealVar *>(coll)) {
90 if (v && (v->isConstant() != constant)) {
91 changed = true;
92 v->setConstant(constant);
93 }
94 }
95 return changed;
96 }
97
98
99 /// assuming all values in set are RooRealVars, randomize their values
101 bool randomizeConstants = true)
102 {
103
104 // repeat loop to avoid calling isConstant for nothing
105 if (randomizeConstants) {
106 for (auto *var : static_range_cast<RooRealVar *>(set))
107 var->randomize();
108 }
109 else {
110 // exclude constants variables
111 for (auto *var : static_range_cast<RooRealVar *>(set))
112 if (!var->isConstant() )
113 var->randomize();
114 }
115
116 }
117
118 void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
119
120 void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
121
122 /// extract constraint terms from pdf
123 RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name);
124 RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, const char *name);
125 /// remove constraints from pdf and return the unconstrained pdf
126 RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name = NULL);
127 RooAbsPdf * MakeUnconstrainedPdf(const RooStats::ModelConfig &model, const char *name = NULL);
128
129 /// Create a TTree with the given name and description. All RooRealVars in the RooDataSet are represented as branches that contain values of type double.
131
132 /// useful function to print in one line the content of a set with their values
133 void PrintListContent(const RooArgList & l, std::ostream & os = std::cout);
134
135 /// function to set a global flag in RooStats to use NLL offset when performing nll computations
136 /// Note that not all ROoStats tools implement this capabilities
137 void UseNLLOffset(bool on);
138
139 /// function returning if the flag to check if the flag to use NLLOffset is set
140 bool IsNLLOffset();
141
142 /// function that clones a workspace, copying all needed components and discarding all others
143 RooWorkspace* MakeCleanWorkspace(RooWorkspace *oldWS, const char *newName, bool copySnapshots,
144 const char *mcname, const char *newmcname);
145
146}
147
148
149#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:57
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:87
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:65
double PValueToSignificance(double pvalue)
returns one-sided significance corresponding to a p-value
Definition: RooStatsUtils.h:51
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:69
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)
remove constraints from pdf and return the unconstrained pdf
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
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...
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:56
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:43
bool useLikelihoodOffset
Offset the likelihood by passing RooFit::Offset to fitTo().
Definition: RooStatsUtils.h:42
auto * l
Definition: textangle.C:4