Logo ROOT   6.10/09
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 "TIterator.h"
25 #include "RooStats/ModelConfig.h"
26 #include "RooProdPdf.h"
27 #include "RooDataSet.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 
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
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: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)
returns one-sided significance corresponding to a p-value
Definition: RooStatsUtils.h:44
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:58
Basic string class.
Definition: TString.h:129
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
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...
#define NULL
Definition: RtypesCore.h:88
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)
returns p-value corresponding to a 1-sided significance
Definition: RooStatsUtils.h:49
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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)
Definition: RooStatsUtils.h:99
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:82
bool IsNLLOffset()
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:62
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
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
A TTree object has a header with a name and a title.
Definition: TTree.h:78
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: RtypesCore.h:91
RooLinkedListIter is the TIterator implementation for RooLinkedList.
Bool_t isConstant() const
Definition: RooAbsArg.h:266