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 
19 #include "Math/DistFuncMathCore.h"
20 
21 #include "RooArgSet.h"
22 #include "RooRealVar.h"
23 #include "RooAbsCollection.h"
24 #include "RooStats/ModelConfig.h"
25 #include "RooProdPdf.h"
26 #include "RooDataSet.h"
27 #include "RooAbsCategoryLValue.h"
28 
29 
30 /** \namespace RooStats
31  \ingroup Roostats
32 
33 Namespace for the RooStats classes
34 
35 All the classes of the %RooStats package are in the RooStats namespace.
36 In addition the namespace contain a set of utility functions.
37 
38 */
39 
40 namespace RooStats {
41  struct RooStatsConfig {
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
53  }
54 
55  /// returns p-value corresponding to a 1-sided significance
58  }
59 
60  /// Compute the Asimov Median significance for a Poisson process
61  /// with s = expected number of signal events, b = expected numner of background events
62  /// and optionally sigma_b = expected uncertainty of backgorund events
64 
65  inline void SetParameters(const RooArgSet* desiredVals, RooArgSet* paramsToChange){
66  *paramsToChange=*desiredVals ;
67  }
68 
70  RooArgSet constSet;
71  RooLinkedListIter it = set->iterator();
72  RooRealVar *myarg;
73  while ((myarg = (RooRealVar *)it.Next())) {
74  if(myarg->isConstant()) constSet.add(*myarg);
75  }
76  set->remove(constSet);
77  }
78 
80  RooArgSet constSet;
81  RooLinkedListIter it = set.iterator();
82  RooRealVar *myarg;
83  while ((myarg = (RooRealVar *)it.Next())) {
84  if(myarg->isConstant()) constSet.add(*myarg);
85  }
86  set.remove(constSet);
87  }
88 
89  inline bool SetAllConstant(const RooAbsCollection &coll, bool constant = true) {
90  // utility function to set all variable constant in a collection
91  // (from G. Petrucciani)
92  bool changed = false;
93  RooLinkedListIter iter = coll.iterator();
94  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
95  RooRealVar *v = dynamic_cast<RooRealVar *>(a);
96  if (v && (v->isConstant() != constant)) {
97  changed = true;
98  v->setConstant(constant);
99  }
100  }
101  return changed;
102  }
103 
104 
105  // assuming all values in set are RooRealVars, randomize their values
107  Bool_t randomizeConstants = kTRUE)
108  {
109  RooLinkedListIter it = set.iterator();
110  RooRealVar* var;
111 
112  // repeat loop to avoid calling isConstant for nothing
113  if (randomizeConstants) {
114  while ((var = (RooRealVar*)it.Next()) != NULL)
115  var->randomize();
116  }
117  else {
118  // exclude constants variables
119  while ((var = (RooRealVar*)it.Next()) != NULL)
120  if (!var->isConstant() )
121  var->randomize();
122  }
123 
124 
125  }
126 
127  void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
128 
129  void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
130 
131  // extract constraint terms from pdf
132  RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name);
134  // remove constraints from pdf and return the unconstrained pdf
135  RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name = NULL);
136  RooAbsPdf * MakeUnconstrainedPdf(const RooStats::ModelConfig &model, const char *name = NULL);
137 
138  // 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.
139  TTree* GetAsTTree(TString name, TString desc, const RooDataSet& data);
140 
141  // useful function to print in one line the content of a set with their values
142  void PrintListContent(const RooArgList & l, std::ostream & os = std::cout);
143 
144  // function to set a global flag in RooStats to use NLL offset when performing nll computations
145  // Note that not all ROoStats tools implement this capabilities
146  void UseNLLOffset(bool on);
147 
148  // function returning if the flag to check if the flag to use NLLOffset is set
149  bool IsNLLOffset();
150 
151 
152 
153 }
154 
155 
156 #endif
RooStats::AsimovSignificance
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...
Definition: RooStatsUtils.cxx:38
l
auto * l
Definition: textangle.C:4
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooStats::IsNLLOffset
bool IsNLLOffset()
Test of RooStats should by default offset NLL calculations.
Definition: RooStatsUtils.cxx:66
RooArgSet.h
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
RooAbsCollection::remove
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
Definition: RooAbsCollection.cxx:584
TTree.h
TString
Basic string class.
Definition: TString.h:136
v
@ v
Definition: rootcling_impl.cxx:3635
RooDataSet.h
b
#define b(i)
Definition: RSha256.hxx:100
RooStats::RooStatsConfig::useEvalErrorWall
bool useEvalErrorWall
Offset the likelihood by passing RooFit::Offset to fitTo().
Definition: RooStatsUtils.h:43
RooStats::SetAllConstant
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
Definition: RooStatsUtils.h:89
RooLinkedListIter::Next
TObject * Next() override
Definition: RooLinkedListIter.h:220
bool
RooAbsCollection::iterator
RooLinkedListIter iterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
Definition: RooAbsCollection.h:127
RooAbsCollection.h
RooStats::GetAsTTree
TTree * GetAsTTree(TString name, TString desc, const RooDataSet &data)
Definition: RooStatsUtils.cxx:309
RooStats::PValueToSignificance
Double_t PValueToSignificance(Double_t pvalue)
returns one-sided significance corresponding to a p-value
Definition: RooStatsUtils.h:51
RooLinkedListIter
A wrapper around TIterator derivatives.
Definition: RooLinkedListIter.h:204
RooStats::RooStatsConfig::useLikelihoodOffset
bool useLikelihoodOffset
Definition: RooStatsUtils.h:42
RooProdPdf.h
ModelConfig.h
a
auto * a
Definition: textangle.C:12
RooArgSet::add
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
Definition: RooArgSet.cxx:261
RooStats::UseNLLOffset
void UseNLLOffset(bool on)
Use an offset in NLL calculations.
Definition: RooStatsUtils.cxx:61
DistFuncMathCore.h
RooStats::PrintListContent
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
Definition: RooStatsUtils.cxx:317
RooAbsCollection
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Definition: RooAbsCollection.h:31
RooRealVar.h
RooStats::RooStatsConfig
Definition: RooStatsUtils.h:41
ROOT::Math::normal_cdf_c
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)...
Definition: ProbFuncMathCore.cxx:226
RooStats::RandomizeCollection
void RandomizeCollection(RooAbsCollection &set, Bool_t randomizeConstants=kTRUE)
Definition: RooStatsUtils.h:106
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAbsCategoryLValue.h
RooStats
Namespace for the RooStats classes.
Definition: Asimov.h:19
RooStats::SetParameters
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:65
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::normal_quantile_c
double normal_quantile_c(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the upper tail of the normal (Gaussian) distri...
Definition: QuantFuncMathCore.cxx:126
RooStats::RemoveConstantParameters
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:69
RooAbsRealLValue::randomize
virtual void randomize(const char *rangeName=0)
Set a new value sampled from a uniform distribution over the fit range.
Definition: RooAbsRealLValue.cxx:413
RooDataSet
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
RooStats::FactorizePdf
void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints)
Definition: RooStatsUtils.cxx:70
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooAbsPdf
Definition: RooAbsPdf.h:43
RooStats::GetGlobalRooStatsConfig
RooStatsConfig & GetGlobalRooStatsConfig()
Retrieve the config object which can be used to set flags for things like offsetting the likelihood o...
Definition: RooStatsUtils.cxx:33
RooStats::SignificanceToPValue
Double_t SignificanceToPValue(Double_t Z)
returns p-value corresponding to a 1-sided significance
Definition: RooStatsUtils.h:56
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooStats::MakeUnconstrainedPdf
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)
Definition: RooStatsUtils.cxx:199
RooStats::ModelConfig
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
RooAbsArg::isConstant
Bool_t isConstant() const
Check if the "Constant" attribute is set.
Definition: RooAbsArg.h:360
TMath.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
RooStats::MakeNuisancePdf
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
Definition: RooStatsUtils.cxx:118