Logo ROOT   master
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);
133  RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, 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
bool useEvalErrorWall
Offset the likelihood by passing RooFit::Offset to fitTo().
Definition: RooStatsUtils.h:43
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
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
virtual void randomize(const char *rangeName=0)
Set a new value sampled from a uniform distribution over the fit range.
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
double normal_quantile_c(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the upper tail of the normal (Gaussian) distri...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
Double_t PValueToSignificance(Double_t pvalue)
returns one-sided significance corresponding to a p-value
Definition: RooStatsUtils.h:51
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:65
Basic string class.
Definition: TString.h:131
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...
TTree * GetAsTTree(TString name, TString desc, const RooDataSet &data)
RooLinkedListIter iterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
TObject * Next() override
void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints)
static constexpr double s
Double_t SignificanceToPValue(Double_t Z)
returns p-value corresponding to a 1-sided significance
Definition: RooStatsUtils.h:56
RooRealVar represents a fundamental (non-derived) real-valued object.
Definition: RooRealVar.h:36
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)
auto * a
Definition: textangle.C:12
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
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)...
void RandomizeCollection(RooAbsCollection &set, Bool_t randomizeConstants=kTRUE)
void UseNLLOffset(bool on)
Use an offset in NLL calculations.
Namespace for the RooStats classes.
Definition: Asimov.h:19
double Double_t
Definition: RtypesCore.h:55
RooStatsConfig & GetGlobalRooStatsConfig()
Retrieve the config object which can be used to set flags for things like offsetting the likelihood o...
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
Definition: RooStatsUtils.h:89
bool IsNLLOffset()
Test of RooStats should by default offset NLL calculations.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:69
RooAbsPdf, the base class of all PDFs
Definition: RooAbsPdf.h:40
auto * l
Definition: textangle.C:4
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
A TTree represents a columnar dataset.
Definition: TTree.h:72
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:70
const Bool_t kTRUE
Definition: RtypesCore.h:87
A wrapper around TIterator derivatives.
char name[80]
Definition: TGX11.cxx:109
Bool_t isConstant() const
Definition: RooAbsArg.h:319