Logo ROOT   6.10/09
Reference Guide
ModelConfig.h
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke, Sven Kreiss
3 /*************************************************************************
4  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 #ifndef ROOSTATS_ModelConfig
12 #define ROOSTATS_ModelConfig
13 
14 
15 #include "RooAbsPdf.h"
16 
17 #include "RooAbsData.h"
18 
19 #include "RooArgSet.h"
20 
21 #include "RooWorkspace.h"
22 
23 #include "TRef.h"
24 
25 #include <string>
26 
27 
28 namespace RooStats {
29 
30 class ModelConfig : public TNamed {
31 
32 public:
33 
35  TNamed()
36  {
37  if(ws) SetWS(*ws);
38  }
39 
40  ModelConfig(const char* name, RooWorkspace *ws = 0) :
41  TNamed(name, name)
42  {
43  if(ws) SetWS(*ws);
44  }
45 
46  ModelConfig(const char* name, const char* title, RooWorkspace *ws = 0) :
47  TNamed(name, title)
48  {
49  if(ws) SetWS(*ws);
50  }
51 
52 
53  /// clone
54  virtual ModelConfig * Clone(const char * name = "") const {
55  ModelConfig * mc = new ModelConfig(*this);
56  if(strcmp(name,"")==0)
57  mc->SetName(this->GetName());
58  else
59  mc->SetName(name);
60  return mc;
61  }
62 
63  /// set a workspace that owns all the necessary components for the analysis
64  virtual void SetWS(RooWorkspace & ws);
65  //// alias for SetWS(...)
66  virtual void SetWorkspace(RooWorkspace & ws) { SetWS(ws); }
67 
68  /// Set the proto DataSet, add to the the workspace if not already there
69  virtual void SetProtoData(RooAbsData & data) {
70  ImportDataInWS(data);
71  SetProtoData( data.GetName() );
72  }
73 
74  /// Set the Pdf, add to the the workspace if not already there
75  virtual void SetPdf(const RooAbsPdf& pdf) {
76  ImportPdfInWS(pdf);
77  SetPdf( pdf.GetName() );
78  }
79 
80  /// Set the Prior Pdf, add to the the workspace if not already there
81  virtual void SetPriorPdf(const RooAbsPdf& pdf) {
82  ImportPdfInWS(pdf);
83  SetPriorPdf( pdf.GetName() );
84  }
85 
86  /// specify the parameters of interest in the interval
87  virtual void SetParameters(const RooArgSet& set) {
88  if (!SetHasOnlyParameters(set,"ModelConfig::SetParameters")) return ;
89  fPOIName=std::string(GetName()) + "_POI";
90  DefineSetInWS(fPOIName.c_str(), set);
91  }
92 
93  virtual void SetParametersOfInterest(const RooArgSet& set) {
94  if (!SetHasOnlyParameters(set,"ModelConfig::SetParametersOfInterest")) return ;
95  SetParameters(set);
96  }
97  /// specify the parameters of interest
98  /// through a list of comma-separated arguments already in the workspace
99  virtual void SetParameters(const char *argList) {
100  if(!GetWS()) return;
101  SetParameters(GetWS()->argSet(argList));
102  }
103  virtual void SetParametersOfInterest(const char *argList) {
104  SetParameters(argList);
105  }
106 
107  /// specify the nuisance parameters (e.g. the rest of the parameters)
108  virtual void SetNuisanceParameters(const RooArgSet& set) {
109  if (!SetHasOnlyParameters(set,"ModelConfig::SetNuisanceParameters")) return ;
110  fNuisParamsName=std::string(GetName()) + "_NuisParams";
111  DefineSetInWS(fNuisParamsName.c_str(), set);
112  }
113  /// specify the nuisance parameters
114  /// through a list of comma-separated arguments already in the workspace
115  virtual void SetNuisanceParameters(const char *argList) {
116  if(!GetWS()) return;
117  SetNuisanceParameters(GetWS()->argSet(argList));
118  }
119 
120  /// specify the constraint parameters
121  virtual void SetConstraintParameters(const RooArgSet& set) {
122  if (!SetHasOnlyParameters(set,"ModelConfig::SetConstainedParameters")) return ;
123  fConstrParamsName=std::string(GetName()) + "_ConstrainedParams";
124  DefineSetInWS(fConstrParamsName.c_str(), set);
125  }
126  /// specify the constraint parameters
127  /// through a list of comma-separated arguments already in the workspace
128  virtual void SetConstraintParameters(const char *argList) {
129  if(!GetWS()) return;
130  SetConstraintParameters(GetWS()->argSet(argList));
131  }
132 
133  /// specify the observables
134  virtual void SetObservables(const RooArgSet& set) {
135  if (!SetHasOnlyParameters(set,"ModelConfig::SetObservables")) return ;
136  fObservablesName=std::string(GetName()) + "_Observables";
137  DefineSetInWS(fObservablesName.c_str(), set);
138  }
139  /// specify the observables
140  /// through a list of comma-separated arguments already in the workspace
141  virtual void SetObservables(const char *argList) {
142  if(!GetWS()) return;
143  SetObservables(GetWS()->argSet(argList));
144  }
145 
146  /// specify the conditional observables
147  virtual void SetConditionalObservables(const RooArgSet& set) {
148  if (!SetHasOnlyParameters(set,"ModelConfig::SetConditionalObservables")) return ;
149  fConditionalObsName=std::string(GetName()) + "_ConditionalObservables";
150  DefineSetInWS(fConditionalObsName.c_str(), set);
151  }
152  /// specify the conditional observables
153  /// through a list of comma-separated arguments already in the workspace
154  virtual void SetConditionalObservables(const char *argList) {
155  if(!GetWS()) return;
156  SetConditionalObservables(GetWS()->argSet(argList));
157  }
158 
159  /// specify the global observables
160  virtual void SetGlobalObservables(const RooArgSet& set) {
161 
162  if (!SetHasOnlyParameters(set,"ModelConfig::SetGlobalObservables")) return ;
163 
164  // make global observables constant
165  RooFIter iter = set.fwdIterator();
166  RooAbsArg *arg = iter.next();
167  while(arg != NULL) {
168  arg->setAttribute("Constant", kTRUE);
169  arg = iter.next();
170  }
171 
172  fGlobalObsName=std::string(GetName()) + "_GlobalObservables";
173  DefineSetInWS(fGlobalObsName.c_str(), set);
174  }
175  /// specify the global observables
176  /// through a list of comma-separated arguments already in the workspace
177  virtual void SetGlobalObservables(const char *argList) {
178  if(!GetWS()) return;
179  SetGlobalObservables(GetWS()->argSet(argList));
180  }
181 
182  /// set parameter values for a particular hypothesis if using a common PDF
183  /// by saving a snapshot in the workspace
184  virtual void SetSnapshot(const RooArgSet& set);
185 
186  /// specify the name of the PDF in the workspace to be used
187  virtual void SetPdf(const char* name) {
188  if (! GetWS() ) return;
189 
190  if(GetWS()->pdf(name))
191  fPdfName = name;
192  else
193  coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<std::endl;
194  }
195 
196  /// specify the name of the PDF in the workspace to be used
197  virtual void SetPriorPdf(const char* name) {
198  if (! GetWS() ) return;
199 
200  if(GetWS()->pdf(name))
202  else
203  coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<std::endl;
204  }
205 
206 
207  /// specify the name of the dataset in the workspace to be used
208  virtual void SetProtoData(const char* name){
209  if (! GetWS() ) return;
210 
211  if(GetWS()->data(name))
213  else
214  coutE(ObjectHandling) << "dataset "<<name<< " does not exist in workspace"<<std::endl;
215  }
216 
217 
218  /* getter methods */
219 
220 
221  /// get model PDF (return NULL if pdf has not been specified or does not exist)
222  RooAbsPdf * GetPdf() const { return (GetWS()) ? GetWS()->pdf(fPdfName.c_str()) : 0; }
223 
224  /// get RooArgSet containing the parameter of interest (return NULL if not existing)
225  const RooArgSet * GetParametersOfInterest() const { return (GetWS()) ? GetWS()->set(fPOIName.c_str()) : 0; }
226 
227  /// get RooArgSet containing the nuisance parameters (return NULL if not existing)
228  const RooArgSet * GetNuisanceParameters() const { return (GetWS()) ? GetWS()->set(fNuisParamsName.c_str()) : 0; }
229 
230  /// get RooArgSet containing the constraint parameters (return NULL if not existing)
231  const RooArgSet * GetConstraintParameters() const { return (GetWS()) ? GetWS()->set(fConstrParamsName.c_str()) : 0; }
232 
233  /// get parameters prior pdf (return NULL if not existing)
234  RooAbsPdf * GetPriorPdf() const { return (GetWS()) ? GetWS()->pdf(fPriorPdfName.c_str()) : 0; }
235 
236  /// get RooArgSet for observables (return NULL if not existing)
237  const RooArgSet * GetObservables() const { return (GetWS()) ? GetWS()->set(fObservablesName.c_str()) : 0; }
238 
239  /// get RooArgSet for conditional observables (return NULL if not existing)
240  const RooArgSet * GetConditionalObservables() const { return (GetWS()) ? GetWS()->set(fConditionalObsName.c_str()) : 0; }
241 
242  /// get RooArgSet for global observables (return NULL if not existing)
243  const RooArgSet * GetGlobalObservables() const { return (GetWS()) ? GetWS()->set(fGlobalObsName.c_str()) : 0; }
244 
245  /// get Proto data set (return NULL if not existing)
246  RooAbsData * GetProtoData() const { return (GetWS()) ? GetWS()->data(fProtoDataName.c_str()) : 0; }
247 
248  /// get RooArgSet for parameters for a particular hypothesis (return NULL if not existing)
249  const RooArgSet * GetSnapshot() const;
250 
251  void LoadSnapshot() const;
252 
253  RooWorkspace * GetWS() const;
254  /// alias for GetWS()
255  RooWorkspace * GetWorkspace() const { return GetWS(); }
256 
257  /// guesses Observables and ParametersOfInterest if not already set
258  void GuessObsAndNuisance(const RooAbsData& data);
259 
260  /// overload the print method
261  virtual void Print(Option_t* option = "") const;
262 
263 protected:
264 
265  /// helper function to check that content of a given set is exclusively parameters
266  Bool_t SetHasOnlyParameters(const RooArgSet& set, const char* errorMsgPrefix=0) ;
267 
268  /// helper functions to define a set in the WS
269  void DefineSetInWS(const char* name, const RooArgSet& set);
270 
271  /// internal function to import Pdf in WS
272  void ImportPdfInWS(const RooAbsPdf & pdf);
273 
274  /// internal function to import data in WS
275  void ImportDataInWS(RooAbsData & data);
276 
277  TRef fRefWS; /// WS reference used in the file
278 
279  std::string fWSName; /// name of the WS
280 
281  std::string fPdfName; /// name of PDF in workspace
282  std::string fDataName; /// name of data set in workspace
283  std::string fPOIName; /// name for RooArgSet specifying parameters of interest
284 
285  std::string fNuisParamsName; /// name for RooArgSet specifying nuisance parameters
286  std::string fConstrParamsName; /// name for RooArgSet specifying constrained parameters
287  std::string fPriorPdfName; /// name for RooAbsPdf specifying a prior on the parameters
288 
289  std::string fConditionalObsName; /// name for RooArgSet specifying conditional observables
290  std::string fGlobalObsName; /// name for RooArgSet specifying global observables
291  std::string fProtoDataName; /// name for RooArgSet specifying dataset that should be used as proto-data
292 
293  std::string fSnapshotName; /// name for RooArgSet that specifies a particular hypothesis
294 
295  std::string fObservablesName; /// name for RooArgSet specifying observable parameters.
296 
297  ClassDef(ModelConfig,4) /// A class that holds configuration information for a model using a workspace as a store
298 
299 };
300 
301 } // end namespace RooStats
302 
303 
304 #endif
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:266
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
#define coutE(a)
Definition: RooMsgService.h:34
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
virtual void SetProtoData(const char *name)
specify the name of the dataset in the workspace to be used
Definition: ModelConfig.h:208
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
Definition: ModelConfig.h:237
virtual void SetPdf(const char *name)
specify the name of the PDF in the workspace to be used
Definition: ModelConfig.h:187
void LoadSnapshot() const
load the snapshot from ws if it exists
virtual void SetWorkspace(RooWorkspace &ws)
Definition: ModelConfig.h:66
const char Option_t
Definition: RtypesCore.h:62
void GuessObsAndNuisance(const RooAbsData &data)
guesses Observables and ParametersOfInterest if not already set
Definition: ModelConfig.cxx:50
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
std::string fNuisParamsName
name for RooArgSet specifying parameters of interest
Definition: ModelConfig.h:285
bool Bool_t
Definition: RtypesCore.h:59
#define NULL
Definition: RtypesCore.h:88
std::string fGlobalObsName
name for RooArgSet specifying conditional observables
Definition: ModelConfig.h:290
void ImportDataInWS(RooAbsData &data)
internal function to import data in WS
virtual void SetObservables(const RooArgSet &set)
specify the observables
Definition: ModelConfig.h:134
virtual ModelConfig * Clone(const char *name="") const
clone
Definition: ModelConfig.h:54
std::string fPdfName
name of the WS
Definition: ModelConfig.h:281
virtual void SetGlobalObservables(const char *argList)
specify the global observables through a list of comma-separated arguments already in the workspace ...
Definition: ModelConfig.h:177
std::string fSnapshotName
name for RooArgSet specifying dataset that should be used as proto-data
Definition: ModelConfig.h:293
Persistent Reference link to a TObject A TRef is a lightweight object pointing to any TObject...
Definition: TRef.h:32
#define ClassDef(name, id)
Definition: Rtypes.h:297
ModelConfig(const char *name, const char *title, RooWorkspace *ws=0)
Definition: ModelConfig.h:46
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetObservables(const char *argList)
specify the observables through a list of comma-separated arguments already in the workspace ...
Definition: ModelConfig.h:141
virtual void SetPdf(const RooAbsPdf &pdf)
Set the Pdf, add to the the workspace if not already there.
Definition: ModelConfig.h:75
std::string fConstrParamsName
name for RooArgSet specifying nuisance parameters
Definition: ModelConfig.h:286
std::string fPriorPdfName
name for RooArgSet specifying constrained parameters
Definition: ModelConfig.h:287
std::string fWSName
WS reference used in the file.
Definition: ModelConfig.h:279
std::string fConditionalObsName
name for RooAbsPdf specifying a prior on the parameters
Definition: ModelConfig.h:289
ModelConfig(const char *name, RooWorkspace *ws=0)
Definition: ModelConfig.h:40
RooWorkspace * GetWorkspace() const
alias for GetWS()
Definition: ModelConfig.h:255
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found...
RooAbsPdf * GetPriorPdf() const
get parameters prior pdf (return NULL if not existing)
Definition: ModelConfig.h:234
std::string fObservablesName
name for RooArgSet that specifies a particular hypothesis
Definition: ModelConfig.h:295
const RooArgSet * GetConditionalObservables() const
get RooArgSet for conditional observables (return NULL if not existing)
Definition: ModelConfig.h:240
std::string fPOIName
name of data set in workspace
Definition: ModelConfig.h:283
virtual void Print(Option_t *option="") const
overload the print method
RooWorkspace * GetWS() const
get from TRef
virtual void SetParameters(const RooArgSet &set)
specify the parameters of interest in the interval
Definition: ModelConfig.h:87
virtual void SetNuisanceParameters(const RooArgSet &set)
specify the nuisance parameters (e.g. the rest of the parameters)
Definition: ModelConfig.h:108
virtual void SetConstraintParameters(const RooArgSet &set)
specify the constraint parameters
Definition: ModelConfig.h:121
virtual void SetWS(RooWorkspace &ws)
set a workspace that owns all the necessary components for the analysis
virtual void SetConditionalObservables(const RooArgSet &set)
specify the conditional observables
Definition: ModelConfig.h:147
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
std::string fProtoDataName
name for RooArgSet specifying global observables
Definition: ModelConfig.h:291
virtual void SetPriorPdf(const char *name)
specify the name of the PDF in the workspace to be used
Definition: ModelConfig.h:197
virtual void SetProtoData(RooAbsData &data)
Set the proto DataSet, add to the the workspace if not already there.
Definition: ModelConfig.h:69
Bool_t SetHasOnlyParameters(const RooArgSet &set, const char *errorMsgPrefix=0)
helper function to check that content of a given set is exclusively parameters
RooAbsArg * next()
ModelConfig(RooWorkspace *ws=0)
Definition: ModelConfig.h:34
RooAbsData * GetProtoData() const
get Proto data set (return NULL if not existing)
Definition: ModelConfig.h:246
void ImportPdfInWS(const RooAbsPdf &pdf)
internal function to import Pdf in WS
Namespace for the RooStats classes.
Definition: Asimov.h:20
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
Definition: ModelConfig.h:222
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
Definition: ModelConfig.h:225
virtual void SetParameters(const char *argList)
specify the parameters of interest through a list of comma-separated arguments already in the workspa...
Definition: ModelConfig.h:99
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
const RooArgSet * GetConstraintParameters() const
get RooArgSet containing the constraint parameters (return NULL if not existing)
Definition: ModelConfig.h:231
virtual void SetNuisanceParameters(const char *argList)
specify the nuisance parameters through a list of comma-separated arguments already in the workspace ...
Definition: ModelConfig.h:115
virtual void SetPriorPdf(const RooAbsPdf &pdf)
Set the Prior Pdf, add to the the workspace if not already there.
Definition: ModelConfig.h:81
void DefineSetInWS(const char *name, const RooArgSet &set)
helper functions to define a set in the WS
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
const RooArgSet * GetGlobalObservables() const
get RooArgSet for global observables (return NULL if not existing)
Definition: ModelConfig.h:243
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
Definition: ModelConfig.h:228
const RooArgSet * set(const char *name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
virtual void SetParametersOfInterest(const RooArgSet &set)
Definition: ModelConfig.h:93
virtual void SetConditionalObservables(const char *argList)
specify the conditional observables through a list of comma-separated arguments already in the worksp...
Definition: ModelConfig.h:154
virtual void SetParametersOfInterest(const char *argList)
Definition: ModelConfig.h:103
const RooArgSet * GetSnapshot() const
get RooArgSet for parameters for a particular hypothesis (return NULL if not existing) ...
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
virtual void SetGlobalObservables(const RooArgSet &set)
specify the global observables
Definition: ModelConfig.h:160
virtual void SetSnapshot(const RooArgSet &set)
set parameter values for a particular hypothesis if using a common PDF by saving a snapshot in the wo...
const Bool_t kTRUE
Definition: RtypesCore.h:91
std::string fDataName
name of PDF in workspace
Definition: ModelConfig.h:282
virtual void SetConstraintParameters(const char *argList)
specify the constraint parameters through a list of comma-separated arguments already in the workspac...
Definition: ModelConfig.h:128
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42