Logo ROOT   6.18/05
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"
24#include "TIterator.h"
26#include "RooProdPdf.h"
27#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 {
41
42
43 /// returns one-sided significance corresponding to a p-value
46 }
47
48 /// returns p-value corresponding to a 1-sided significance
51 }
52
53 /// Compute the Asimov Median significance for a Poisson process
54 /// with s = expected number of signal events, b = expected numner of background events
55 /// and optionally sigma_b = expected uncertainty of backgorund events
57
58 inline void SetParameters(const RooArgSet* desiredVals, RooArgSet* paramsToChange){
59 *paramsToChange=*desiredVals ;
60 }
61
63 RooArgSet constSet;
64 RooLinkedListIter it = set->iterator();
65 RooRealVar *myarg;
66 while ((myarg = (RooRealVar *)it.Next())) {
67 if(myarg->isConstant()) constSet.add(*myarg);
68 }
69 set->remove(constSet);
70 }
71
73 RooArgSet constSet;
74 RooLinkedListIter it = set.iterator();
75 RooRealVar *myarg;
76 while ((myarg = (RooRealVar *)it.Next())) {
77 if(myarg->isConstant()) constSet.add(*myarg);
78 }
79 set.remove(constSet);
80 }
81
82 inline bool SetAllConstant(const RooAbsCollection &coll, bool constant = true) {
83 // utility function to set all variable constant in a collection
84 // (from G. Petrucciani)
85 bool changed = false;
86 RooLinkedListIter iter = coll.iterator();
87 for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
88 RooRealVar *v = dynamic_cast<RooRealVar *>(a);
89 if (v && (v->isConstant() != constant)) {
90 changed = true;
91 v->setConstant(constant);
92 }
93 }
94 return changed;
95 }
96
97
98 // assuming all values in set are RooRealVars, randomize their values
100 Bool_t randomizeConstants = kTRUE)
101 {
102 RooLinkedListIter it = set.iterator();
103 RooRealVar* var;
104
105 // repeat loop to avoid calling isConstant for nothing
106 if (randomizeConstants) {
107 while ((var = (RooRealVar*)it.Next()) != NULL)
108 var->randomize();
109 }
110 else {
111 // exclude constants variables
112 while ((var = (RooRealVar*)it.Next()) != NULL)
113 if (!var->isConstant() )
114 var->randomize();
115 }
116
117
118 }
119
120 void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
121
122 void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
123
124 // extract constraint terms from pdf
125 RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name);
126 RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, const char *name);
127 // remove constraints from pdf and return the unconstrained pdf
128 RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name = NULL);
129 RooAbsPdf * MakeUnconstrainedPdf(const RooStats::ModelConfig &model, const char *name = NULL);
130
131 // 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.
132 TTree* GetAsTTree(TString name, TString desc, const RooDataSet& data);
133
134 // useful function to print in one line the content of a set with their values
135 void PrintListContent(const RooArgList & l, std::ostream & os = std::cout);
136
137 // function to set a global flag in RooStats to use NLL offset when performing nll computations
138 // Note that not all ROoStats tools implement this capabilities
139 void UseNLLOffset(bool on);
140
141 // function returning if the flag to check if the flag to use NLLOffset is set
142 bool IsNLLOffset();
143
144
145
146}
147
148
149#endif
SVector< double, 2 > v
Definition: Dict.h:5
#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:70
Bool_t isConstant() const
Definition: RooAbsArg.h:311
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 fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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:71
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:82
TTree * GetAsTTree(TString name, TString desc, const RooDataSet &data)
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:58
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:62
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)
void RandomizeCollection(RooAbsCollection &set, Bool_t randomizeConstants=kTRUE)
Definition: RooStatsUtils.h:99
Double_t PValueToSignificance(Double_t pvalue)
returns one-sided significance corresponding to a p-value
Definition: RooStatsUtils.h:44
void UseNLLOffset(bool on)
bool IsNLLOffset()
Double_t SignificanceToPValue(Double_t Z)
returns p-value corresponding to a 1-sided significance
Definition: RooStatsUtils.h:49
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
static constexpr double s
auto * l
Definition: textangle.C:4
auto * a
Definition: textangle.C:12