Logo ROOT   6.08/07
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 #ifndef ROOT_TMath
16 #include "TMath.h"
17 #endif
18 
19 #ifndef ROOT_TTree
20 #include "TTree.h"
21 #endif
22 
23 #ifndef ROOT_Math_DistFuncMathCore
25 #endif
26 
27 #include "RooArgSet.h"
28 #include "RooRealVar.h"
29 #include "RooAbsCollection.h"
30 #include "TIterator.h"
31 #include "RooStats/ModelConfig.h"
32 #include "RooProdPdf.h"
33 #include "RooDataSet.h"
34 
35 
36 /**
37 
38 \defgroup Roostats RooStats
39 
40 %RooStats is a package containing statistical tools built on top of %RooFit.
41 See the %RooStats (Twiki Page)[https://twiki.cern.ch/twiki/bin/view/RooStats/WebHome] for more information.
42 */
43 
44 /**
45 
46 \namespace RooStats Namespace for the RooStats classes
47 
48 All the classes of the %RooStats package are in the RooStats namespace.
49 In addition the namespace contain a set of utility functions.
50 
51 \ingroup Roostats
52 
53  */
54 
55 namespace RooStats {
56 
57 
58  // returns one-sided significance corresponding to a p-value
61  }
62 
63  // returns p-value corresponding to a 1-sided significance
66  }
67 
68 
69  inline void SetParameters(const RooArgSet* desiredVals, RooArgSet* paramsToChange){
70  *paramsToChange=*desiredVals ;
71  }
72 
74  RooArgSet constSet;
75  RooLinkedListIter it = set->iterator();
76  RooRealVar *myarg;
77  while ((myarg = (RooRealVar *)it.Next())) {
78  if(myarg->isConstant()) constSet.add(*myarg);
79  }
80  set->remove(constSet);
81  }
82 
84  RooArgSet constSet;
85  RooLinkedListIter it = set.iterator();
86  RooRealVar *myarg;
87  while ((myarg = (RooRealVar *)it.Next())) {
88  if(myarg->isConstant()) constSet.add(*myarg);
89  }
90  set.remove(constSet);
91  }
92 
93  inline bool SetAllConstant(const RooAbsCollection &coll, bool constant = true) {
94  // utility function to set all variable constant in a collection
95  // (from G. Petrucciani)
96  bool changed = false;
97  RooLinkedListIter iter = coll.iterator();
98  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
99  RooRealVar *v = dynamic_cast<RooRealVar *>(a);
100  if (v && (v->isConstant() != constant)) {
101  changed = true;
102  v->setConstant(constant);
103  }
104  }
105  return changed;
106  }
107 
108 
109  // assuming all values in set are RooRealVars, randomize their values
111  Bool_t randomizeConstants = kTRUE)
112  {
113  RooLinkedListIter it = set.iterator();
114  RooRealVar* var;
115 
116  // repeat loop tpo avoid calling isConstant for nothing
117  if (randomizeConstants) {
118  while ((var = (RooRealVar*)it.Next()) != NULL)
119  var->randomize();
120  }
121  else {
122  // exclude constants variables
123  while ((var = (RooRealVar*)it.Next()) != NULL)
124  if (!var->isConstant() )
125  var->randomize();
126  }
127 
128 
129  }
130 
131  void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
132 
133  void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints);
134 
135  // extract constraint terms from pdf
136  RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name);
137  RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, const char *name);
138  // remove constraints from pdf and return the unconstrained pdf
139  RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name = NULL);
140  RooAbsPdf * MakeUnconstrainedPdf(const RooStats::ModelConfig &model, const char *name = NULL);
141 
142  // 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.
143  TTree* GetAsTTree(TString name, TString desc, const RooDataSet& data);
144 
145  // useful function to print in one line the content of a set with their values
146  void PrintListContent(const RooArgList & l, std::ostream & os = std::cout);
147 
148  // function to set a global flag in RooStats to use NLL offset when performing nll computations
149  // Note that not all ROoStats tools implement this capabilities
150  void UseNLLOffset(bool on);
151 
152  // function returning if the flag to check if the flag to use NLLOffset is set
153  bool IsNLLOffset();
154 
155 
156 
157 }
158 
159 
160 #endif
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:52
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:86
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...
Double_t PValueToSignificance(Double_t pvalue)
Definition: RooStatsUtils.h:59
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:69
Basic string class.
Definition: TString.h:137
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
TTree * GetAsTTree(TString name, TString desc, const RooDataSet &data)
void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints)
virtual TObject * Next()
Double_t SignificanceToPValue(Double_t Z)
Definition: RooStatsUtils.h:64
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)
SVector< double, 2 > v
Definition: Dict.h:5
void setConstant(Bool_t value=kTRUE)
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
TLine * l
Definition: textangle.C:4
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
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)
Namespace for the RooStats classes.
Definition: Asimov.h:20
double Double_t
Definition: RtypesCore.h:55
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
Definition: RooStatsUtils.h:93
bool IsNLLOffset()
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:73
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooLinkedListIter iterator(Bool_t dir=kIterForward) const
#define NULL
Definition: Rtypes.h:82
A TTree object has a header with a name and a title.
Definition: TTree.h:98
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
RooLinkedListIter is the TIterator implementation for RooLinkedList.
char name[80]
Definition: TGX11.cxx:109
Bool_t isConstant() const
Definition: RooAbsArg.h:266