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
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){
50 return ::ROOT::Math::normal_quantile_c(pvalue,1);
51 }
52
53 /// returns p-value corresponding to a 1-sided significance
54 inline double SignificanceToPValue(double Z){
55 return ::ROOT::Math::normal_cdf_c(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 background 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
117 void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
118
119 void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
120
121 /// extract constraint terms from pdf
122 RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name);
123 RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, const char *name);
124 /// remove constraints from pdf and return the unconstrained pdf
125 RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name = nullptr);
126 RooAbsPdf * MakeUnconstrainedPdf(const RooStats::ModelConfig &model, const char *name = nullptr);
127
128 /// Create a TTree with the given name and description. All RooRealVars in the RooDataSet are represented as branches that contain values of type double.
130
131 /// useful function to print in one line the content of a set with their values
132 void PrintListContent(const RooArgList & l, std::ostream & os = std::cout);
133
134 /// function to set a global flag in RooStats to use NLL offset when performing nll computations
135 /// Note that not all ROoStats tools implement this capabilities
136 void UseNLLOffset(bool on);
137
138 /// function returning if the flag to check if the flag to use NLLOffset is set
139 bool IsNLLOffset();
140
141 /// function that clones a workspace, copying all needed components and discarding all others
142 RooWorkspace* MakeReducedWorkspace(RooWorkspace *oldWS, const char *newName, bool copySnapshots,
143 const char *mcname, const char *newmcname, bool copyData=true);
144
145}
146
147
148#endif
#define b(i)
Definition RSha256.hxx:100
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 on
char name[80]
Definition TGX11.cxx:110
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...
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
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:24
Container class to hold unbinned data.
Definition RooDataSet.h:34
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition ModelConfig.h:35
Persistable container for RooFit projects.
Basic string class.
Definition TString.h:139
A TTree represents a columnar dataset.
Definition TTree.h:79
Namespace for the RooStats classes.
Definition CodegenImpl.h:58
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
utility function to set all variable constant in a collection (from G.
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)
double PValueToSignificance(double pvalue)
returns one-sided significance corresponding to a p-value
void RemoveConstantParameters(RooArgSet *set)
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...
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
double SignificanceToPValue(double Z)
returns p-value corresponding to a 1-sided significance
RooWorkspace * MakeReducedWorkspace(RooWorkspace *oldWS, const char *newName, bool copySnapshots, const char *mcname, const char *newmcname, bool copyData=true)
function that clones a workspace, copying all needed components and discarding all others
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
bool useEvalErrorWall
Use the error wall RooFit::EvalErrorWall to drive the fitter away from disallowed parameter values.
bool useLikelihoodOffset
Offset the likelihood by passing RooFit::Offset to fitTo().
TLine l
Definition textangle.C:4