Logo ROOT   6.08/07
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 #ifndef ROO_ABS_PDF
16 #include "RooAbsPdf.h"
17 #endif
18 
19 #ifndef ROO_ABS_DATA
20 #include "RooAbsData.h"
21 #endif
22 
23 #ifndef ROO_ARG_SET
24 #include "RooArgSet.h"
25 #endif
26 
27 #ifndef ROO_WORKSPACE
28 #include "RooWorkspace.h"
29 #endif
30 
31 #ifndef ROOT_TRef
32 #include "TRef.h"
33 #endif
34 
35 #include <string>
36 
37 
38 namespace RooStats {
39 
40 
41 /**
42 
43 ModelConfig is a simple class that holds configuration information specifying how a model
44 should be used in the context of various RooStats tools. A single model can be used
45 in different ways, and this class should carry all that is needed to specify how it should be used.
46 ModelConfig requires a workspace to be set.
47 
48 \ingroup Roostats
49 
50 */
51 
52 class ModelConfig : public TNamed {
53 
54 public:
55 
57  TNamed()
58  {
59  if(ws) SetWS(*ws);
60  }
61 
62  ModelConfig(const char* name, RooWorkspace *ws = 0) :
63  TNamed(name, name)
64  {
65  if(ws) SetWS(*ws);
66  }
67 
68  ModelConfig(const char* name, const char* title, RooWorkspace *ws = 0) :
69  TNamed(name, title)
70  {
71  if(ws) SetWS(*ws);
72  }
73 
74 
75  /// clone
76  virtual ModelConfig * Clone(const char * name = "") const {
77  ModelConfig * mc = new ModelConfig(*this);
78  if(strcmp(name,"")==0)
79  mc->SetName(this->GetName());
80  else
81  mc->SetName(name);
82  return mc;
83  }
84 
85  /// set a workspace that owns all the necessary components for the analysis
86  virtual void SetWS(RooWorkspace & ws);
87  //// alias for SetWS(...)
88  virtual void SetWorkspace(RooWorkspace & ws) { SetWS(ws); }
89 
90  /// Set the proto DataSet, add to the the workspace if not already there
91  virtual void SetProtoData(RooAbsData & data) {
92  ImportDataInWS(data);
93  SetProtoData( data.GetName() );
94  }
95 
96  /// Set the Pdf, add to the the workspace if not already there
97  virtual void SetPdf(const RooAbsPdf& pdf) {
98  ImportPdfInWS(pdf);
99  SetPdf( pdf.GetName() );
100  }
101 
102  /// Set the Prior Pdf, add to the the workspace if not already there
103  virtual void SetPriorPdf(const RooAbsPdf& pdf) {
104  ImportPdfInWS(pdf);
105  SetPriorPdf( pdf.GetName() );
106  }
107 
108  /// specify the parameters of interest in the interval
109  virtual void SetParameters(const RooArgSet& set) {
110  if (!SetHasOnlyParameters(set,"ModelConfig::SetParameters")) return ;
111  fPOIName=std::string(GetName()) + "_POI";
112  DefineSetInWS(fPOIName.c_str(), set);
113  }
114 
115  virtual void SetParametersOfInterest(const RooArgSet& set) {
116  if (!SetHasOnlyParameters(set,"ModelConfig::SetParametersOfInterest")) return ;
117  SetParameters(set);
118  }
119  /// specify the parameters of interest
120  /// through a list of comma-separated arguments already in the workspace
121  virtual void SetParameters(const char *argList) {
122  if(!GetWS()) return;
123  SetParameters(GetWS()->argSet(argList));
124  }
125  virtual void SetParametersOfInterest(const char *argList) {
126  SetParameters(argList);
127  }
128 
129  /// specify the nuisance parameters (e.g. the rest of the parameters)
130  virtual void SetNuisanceParameters(const RooArgSet& set) {
131  if (!SetHasOnlyParameters(set,"ModelConfig::SetNuisanceParameters")) return ;
132  fNuisParamsName=std::string(GetName()) + "_NuisParams";
133  DefineSetInWS(fNuisParamsName.c_str(), set);
134  }
135  /// specify the nuisance parameters
136  /// through a list of comma-separated arguments already in the workspace
137  virtual void SetNuisanceParameters(const char *argList) {
138  if(!GetWS()) return;
139  SetNuisanceParameters(GetWS()->argSet(argList));
140  }
141 
142  /// specify the constraint parameters
143  virtual void SetConstraintParameters(const RooArgSet& set) {
144  if (!SetHasOnlyParameters(set,"ModelConfig::SetConstainedParameters")) return ;
145  fConstrParamsName=std::string(GetName()) + "_ConstrainedParams";
146  DefineSetInWS(fConstrParamsName.c_str(), set);
147  }
148  /// specify the constraint parameters
149  /// through a list of comma-separated arguments already in the workspace
150  virtual void SetConstraintParameters(const char *argList) {
151  if(!GetWS()) return;
152  SetConstraintParameters(GetWS()->argSet(argList));
153  }
154 
155  /// specify the observables
156  virtual void SetObservables(const RooArgSet& set) {
157  if (!SetHasOnlyParameters(set,"ModelConfig::SetObservables")) return ;
158  fObservablesName=std::string(GetName()) + "_Observables";
159  DefineSetInWS(fObservablesName.c_str(), set);
160  }
161  /// specify the observables
162  /// through a list of comma-separated arguments already in the workspace
163  virtual void SetObservables(const char *argList) {
164  if(!GetWS()) return;
165  SetObservables(GetWS()->argSet(argList));
166  }
167 
168  /// specify the conditional observables
169  virtual void SetConditionalObservables(const RooArgSet& set) {
170  if (!SetHasOnlyParameters(set,"ModelConfig::SetConditionalObservables")) return ;
171  fConditionalObsName=std::string(GetName()) + "_ConditionalObservables";
172  DefineSetInWS(fConditionalObsName.c_str(), set);
173  }
174  /// specify the conditional observables
175  /// through a list of comma-separated arguments already in the workspace
176  virtual void SetConditionalObservables(const char *argList) {
177  if(!GetWS()) return;
178  SetConditionalObservables(GetWS()->argSet(argList));
179  }
180 
181  /// specify the global observables
182  virtual void SetGlobalObservables(const RooArgSet& set) {
183 
184  if (!SetHasOnlyParameters(set,"ModelConfig::SetGlobalObservables")) return ;
185 
186  // make global observables constant
187  RooFIter iter = set.fwdIterator();
188  RooAbsArg *arg = iter.next();
189  while(arg != NULL) {
190  arg->setAttribute("Constant", kTRUE);
191  arg = iter.next();
192  }
193 
194  fGlobalObsName=std::string(GetName()) + "_GlobalObservables";
195  DefineSetInWS(fGlobalObsName.c_str(), set);
196  }
197  /// specify the global observables
198  /// through a list of comma-separated arguments already in the workspace
199  virtual void SetGlobalObservables(const char *argList) {
200  if(!GetWS()) return;
201  SetGlobalObservables(GetWS()->argSet(argList));
202  }
203 
204  /// set parameter values for a particular hypothesis if using a common PDF
205  /// by saving a snapshot in the workspace
206  virtual void SetSnapshot(const RooArgSet& set);
207 
208  /// specify the name of the PDF in the workspace to be used
209  virtual void SetPdf(const char* name) {
210  if (! GetWS() ) return;
211 
212  if(GetWS()->pdf(name))
213  fPdfName = name;
214  else
215  coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<std::endl;
216  }
217 
218  /// specify the name of the PDF in the workspace to be used
219  virtual void SetPriorPdf(const char* name) {
220  if (! GetWS() ) return;
221 
222  if(GetWS()->pdf(name))
224  else
225  coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<std::endl;
226  }
227 
228 
229  /// specify the name of the dataset in the workspace to be used
230  virtual void SetProtoData(const char* name){
231  if (! GetWS() ) return;
232 
233  if(GetWS()->data(name))
235  else
236  coutE(ObjectHandling) << "dataset "<<name<< " does not exist in workspace"<<std::endl;
237  }
238 
239 
240  /* getter methods */
241 
242 
243  /// get model PDF (return NULL if pdf has not been specified or does not exist)
244  RooAbsPdf * GetPdf() const { return (GetWS()) ? GetWS()->pdf(fPdfName.c_str()) : 0; }
245 
246  /// get RooArgSet containing the parameter of interest (return NULL if not existing)
247  const RooArgSet * GetParametersOfInterest() const { return (GetWS()) ? GetWS()->set(fPOIName.c_str()) : 0; }
248 
249  /// get RooArgSet containing the nuisance parameters (return NULL if not existing)
250  const RooArgSet * GetNuisanceParameters() const { return (GetWS()) ? GetWS()->set(fNuisParamsName.c_str()) : 0; }
251 
252  /// get RooArgSet containing the constraint parameters (return NULL if not existing)
253  const RooArgSet * GetConstraintParameters() const { return (GetWS()) ? GetWS()->set(fConstrParamsName.c_str()) : 0; }
254 
255  /// get parameters prior pdf (return NULL if not existing)
256  RooAbsPdf * GetPriorPdf() const { return (GetWS()) ? GetWS()->pdf(fPriorPdfName.c_str()) : 0; }
257 
258  /// get RooArgSet for observables (return NULL if not existing)
259  const RooArgSet * GetObservables() const { return (GetWS()) ? GetWS()->set(fObservablesName.c_str()) : 0; }
260 
261  /// get RooArgSet for conditional observables (return NULL if not existing)
262  const RooArgSet * GetConditionalObservables() const { return (GetWS()) ? GetWS()->set(fConditionalObsName.c_str()) : 0; }
263 
264  /// get RooArgSet for global observables (return NULL if not existing)
265  const RooArgSet * GetGlobalObservables() const { return (GetWS()) ? GetWS()->set(fGlobalObsName.c_str()) : 0; }
266 
267  /// get Proto data set (return NULL if not existing)
268  RooAbsData * GetProtoData() const { return (GetWS()) ? GetWS()->data(fProtoDataName.c_str()) : 0; }
269 
270  /// get RooArgSet for parameters for a particular hypothesis (return NULL if not existing)
271  const RooArgSet * GetSnapshot() const;
272 
273  void LoadSnapshot() const;
274 
275  RooWorkspace * GetWS() const;
276  /// alias for GetWS()
277  RooWorkspace * GetWorkspace() const { return GetWS(); }
278 
279  /// guesses Observables and ParametersOfInterest if not already set
280  void GuessObsAndNuisance(const RooAbsData& data);
281 
282  /// overload the print method
283  virtual void Print(Option_t* option = "") const;
284 
285 protected:
286 
287  /// helper function to check that content of a given set is exclusively parameters
288  Bool_t SetHasOnlyParameters(const RooArgSet& set, const char* errorMsgPrefix=0) ;
289 
290  /// helper functions to define a set in the WS
291  void DefineSetInWS(const char* name, const RooArgSet& set);
292 
293  /// internal function to import Pdf in WS
294  void ImportPdfInWS(const RooAbsPdf & pdf);
295 
296  /// internal function to import data in WS
297  void ImportDataInWS(RooAbsData & data);
298 
299  TRef fRefWS; /// WS reference used in the file
300 
301  std::string fWSName; /// name of the WS
302 
303  std::string fPdfName; /// name of PDF in workspace
304  std::string fDataName; /// name of data set in workspace
305  std::string fPOIName; /// name for RooArgSet specifying parameters of interest
306 
307  std::string fNuisParamsName; /// name for RooArgSet specifying nuisance parameters
308  std::string fConstrParamsName; /// name for RooArgSet specifying constrained parameters
309  std::string fPriorPdfName; /// name for RooAbsPdf specifying a prior on the parameters
310 
311  std::string fConditionalObsName; /// name for RooArgSet specifying conditional observables
312  std::string fGlobalObsName; /// name for RooArgSet specifying global observables
313  std::string fProtoDataName; /// name for RooArgSet specifying dataset that should be used as protodata
314 
315  std::string fSnapshotName; /// name for RooArgSet that specifies a particular hypothesis
316 
317  std::string fObservablesName; /// name for RooArgSet specifying observable parameters.
318 
319  ClassDef(ModelConfig,4) /// A class that holds configuration information for a model using a workspace as a store
320 
321 };
322 
323 } // end namespace RooStats
324 
325 
326 #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:51
#define coutE(a)
Definition: RooMsgService.h:35
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:52
virtual void SetProtoData(const char *name)
specify the name of the dataset in the workspace to be used
Definition: ModelConfig.h:230
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
Definition: ModelConfig.h:259
virtual void SetPdf(const char *name)
specify the name of the PDF in the workspace to be used
Definition: ModelConfig.h:209
void LoadSnapshot() const
virtual void SetWorkspace(RooWorkspace &ws)
Definition: ModelConfig.h:88
const char Option_t
Definition: RtypesCore.h:62
void GuessObsAndNuisance(const RooAbsData &data)
guesses Observables and ParametersOfInterest if not already set
Definition: ModelConfig.cxx:32
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:307
bool Bool_t
Definition: RtypesCore.h:59
std::string fGlobalObsName
name for RooArgSet specifying conditional observables
Definition: ModelConfig.h:312
void ImportDataInWS(RooAbsData &data)
internal function to import data in WS
virtual void SetObservables(const RooArgSet &set)
specify the observables
Definition: ModelConfig.h:156
virtual ModelConfig * Clone(const char *name="") const
clone
Definition: ModelConfig.h:76
std::string fPdfName
name of the WS
Definition: ModelConfig.h:303
virtual void SetGlobalObservables(const char *argList)
specify the global observables through a list of comma-separated arguments already in the workspace ...
Definition: ModelConfig.h:199
std::string fSnapshotName
name for RooArgSet specifying dataset that should be used as protodata
Definition: ModelConfig.h:315
Persistent Reference link to a TObject A TRef is a lightweight object pointing to any TObject...
Definition: TRef.h:34
#define ClassDef(name, id)
Definition: Rtypes.h:254
ModelConfig(const char *name, const char *title, RooWorkspace *ws=0)
Definition: ModelConfig.h:68
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual void SetObservables(const char *argList)
specify the observables through a list of comma-separated arguments already in the workspace ...
Definition: ModelConfig.h:163
virtual void SetPdf(const RooAbsPdf &pdf)
Set the Pdf, add to the the workspace if not already there.
Definition: ModelConfig.h:97
std::string fConstrParamsName
name for RooArgSet specifying nuisance parameters
Definition: ModelConfig.h:308
std::string fPriorPdfName
name for RooArgSet specifying constrained parameters
Definition: ModelConfig.h:309
std::string fWSName
WS reference used in the file.
Definition: ModelConfig.h:301
std::string fConditionalObsName
name for RooAbsPdf specifying a prior on the parameters
Definition: ModelConfig.h:311
ModelConfig(const char *name, RooWorkspace *ws=0)
Definition: ModelConfig.h:62
RooWorkspace * GetWorkspace() const
alias for GetWS()
Definition: ModelConfig.h:277
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:256
std::string fObservablesName
name for RooArgSet that specifies a particular hypothesis
Definition: ModelConfig.h:317
const RooArgSet * GetConditionalObservables() const
get RooArgSet for conditional observables (return NULL if not existing)
Definition: ModelConfig.h:262
std::string fPOIName
name of data set in workspace
Definition: ModelConfig.h:305
virtual void Print(Option_t *option="") const
overload the print method
Definition: ModelConfig.cxx:90
RooWorkspace * GetWS() const
virtual void SetParameters(const RooArgSet &set)
specify the parameters of interest in the interval
Definition: ModelConfig.h:109
virtual void SetNuisanceParameters(const RooArgSet &set)
specify the nuisance parameters (e.g. the rest of the parameters)
Definition: ModelConfig.h:130
virtual void SetConstraintParameters(const RooArgSet &set)
specify the constraint parameters
Definition: ModelConfig.h:143
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:169
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:313
virtual void SetPriorPdf(const char *name)
specify the name of the PDF in the workspace to be used
Definition: ModelConfig.h:219
virtual void SetProtoData(RooAbsData &data)
Set the proto DataSet, add to the the workspace if not already there.
Definition: ModelConfig.h:91
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:56
RooAbsData * GetProtoData() const
get Proto data set (return NULL if not existing)
Definition: ModelConfig.h:268
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:244
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
Definition: ModelConfig.h:247
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:121
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:253
virtual void SetNuisanceParameters(const char *argList)
specify the nuisance parameters through a list of comma-separated arguments already in the workspace ...
Definition: ModelConfig.h:137
virtual void SetPriorPdf(const RooAbsPdf &pdf)
Set the Prior Pdf, add to the the workspace if not already there.
Definition: ModelConfig.h:103
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:265
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
Definition: ModelConfig.h:250
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...
#define NULL
Definition: Rtypes.h:82
virtual void SetParametersOfInterest(const RooArgSet &set)
Definition: ModelConfig.h:115
virtual void SetConditionalObservables(const char *argList)
specify the conditional observables through a list of comma-separated arguments already in the worksp...
Definition: ModelConfig.h:176
virtual void SetParametersOfInterest(const char *argList)
Definition: ModelConfig.h:125
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:182
const Bool_t kTRUE
Definition: Rtypes.h:91
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...
return
Definition: HLFactory.cxx:514
std::string fDataName
name of PDF in workspace
Definition: ModelConfig.h:304
virtual void SetConstraintParameters(const char *argList)
specify the constraint parameters through a list of comma-separated arguments already in the workspac...
Definition: ModelConfig.h:150
char name[80]
Definition: TGX11.cxx:109
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42