Logo ROOT  
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 "RooWorkspaceHandle.h"
22
23#include "TRef.h"
24
25#include <string>
26
27
28namespace RooStats {
29
30class ModelConfig final : public TNamed, public RooWorkspaceHandle {
31
32public:
33
35 TNamed()
36 {
37 if(ws) SetWS(*ws);
38 }
39
40 ModelConfig(const char* name, RooWorkspace *ws = 0) :
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 override {
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) override;
65 //// alias for SetWS(...)
66 virtual void SetWorkspace(RooWorkspace & ws) { SetWS(ws); }
67
68 /// Remove the existing reference to a workspace and replace it with this new one.
69 virtual void ReplaceWS(RooWorkspace *ws) override {
70 fRefWS = nullptr;
71 SetWS(*ws);
72 }
73
74 /// Set the proto DataSet, add to the the workspace if not already there
75 virtual void SetProtoData(RooAbsData & data) {
76 ImportDataInWS(data);
77 SetProtoData( data.GetName() );
78 }
79
80 /// Set the Pdf, add to the the workspace if not already there
81 virtual void SetPdf(const RooAbsPdf& pdf) {
82 ImportPdfInWS(pdf);
83 SetPdf( pdf.GetName() );
84 }
85
86 /// Set the Prior Pdf, add to the the workspace if not already there
87 virtual void SetPriorPdf(const RooAbsPdf& pdf) {
88 ImportPdfInWS(pdf);
89 SetPriorPdf( pdf.GetName() );
90 }
91
92 /// Specify parameters of the PDF.
93 virtual void SetParameters(const RooArgSet& set) {
94 if (!SetHasOnlyParameters(set,"ModelConfig::SetParameters")) return ;
95 fPOIName=std::string(GetName()) + "_POI";
96 DefineSetInWS(fPOIName.c_str(), set);
97 }
98
99 /// Specify parameters of interest.
100 virtual void SetParametersOfInterest(const RooArgSet& set) {
101 if (!SetHasOnlyParameters(set,"ModelConfig::SetParametersOfInterest")) return ;
102 SetParameters(set);
103 }
104
105 /// Specify parameters
106 /// using a list of comma-separated list of arguments already in the workspace.
107 virtual void SetParameters(const char *argList) {
108 if(!GetWS()) return;
109 SetParameters(GetWS()->argSet(argList));
110 }
111
112 /// Specify parameters of interest
113 /// using a comma-separated list of arguments already in the workspace.
114 virtual void SetParametersOfInterest(const char *argList) {
115 SetParameters(argList);
116 }
117
118 /// Specify the nuisance parameters (parameters that are not POI).
119 virtual void SetNuisanceParameters(const RooArgSet& set) {
120 if (!SetHasOnlyParameters(set,"ModelConfig::SetNuisanceParameters")) return ;
121 fNuisParamsName=std::string(GetName()) + "_NuisParams";
122 DefineSetInWS(fNuisParamsName.c_str(), set);
123 }
124
125 /// Specify the nuisance parameters
126 /// using a comma-separated list of arguments already in the workspace.
127 virtual void SetNuisanceParameters(const char *argList) {
128 if(!GetWS()) return;
129 SetNuisanceParameters(GetWS()->argSet(argList));
130 }
131
132 /// Specify the constraint parameters
133 virtual void SetConstraintParameters(const RooArgSet& set) {
134 if (!SetHasOnlyParameters(set,"ModelConfig::SetConstainedParameters")) return ;
135 fConstrParamsName=std::string(GetName()) + "_ConstrainedParams";
136 DefineSetInWS(fConstrParamsName.c_str(), set);
137 }
138 /// Specify the constraint parameters
139 /// through a comma-separated list of arguments already in the workspace.
140 virtual void SetConstraintParameters(const char *argList) {
141 if(!GetWS()) return;
142 SetConstraintParameters(GetWS()->argSet(argList));
143 }
144
145 /// Specify the observables.
146 virtual void SetObservables(const RooArgSet& set) {
147 if (!SetHasOnlyParameters(set,"ModelConfig::SetObservables")) return ;
148 fObservablesName=std::string(GetName()) + "_Observables";
149 DefineSetInWS(fObservablesName.c_str(), set);
150 }
151 /// specify the observables
152 /// through a comma-separated list of arguments already in the workspace.
153 virtual void SetObservables(const char *argList) {
154 if(!GetWS()) return;
155 SetObservables(GetWS()->argSet(argList));
156 }
157
158 /// Specify the conditional observables.
159 virtual void SetConditionalObservables(const RooArgSet& set) {
160 if (!SetHasOnlyParameters(set,"ModelConfig::SetConditionalObservables")) return ;
161 fConditionalObsName=std::string(GetName()) + "_ConditionalObservables";
163 }
164 /// Specify the conditional observables
165 /// through a comma-separated list of arguments already in the workspace.
166 virtual void SetConditionalObservables(const char *argList) {
167 if(!GetWS()) return;
168 SetConditionalObservables(GetWS()->argSet(argList));
169 }
170
171 /// Specify the global observables.
172 virtual void SetGlobalObservables(const RooArgSet& set) {
173
174 if (!SetHasOnlyParameters(set,"ModelConfig::SetGlobalObservables")) return ;
175
176 // make global observables constant
177 RooFIter iter = set.fwdIterator();
178 RooAbsArg *arg = iter.next();
179 while(arg != NULL) {
180 arg->setAttribute("Constant", kTRUE);
181 arg = iter.next();
182 }
183
184 fGlobalObsName=std::string(GetName()) + "_GlobalObservables";
185 DefineSetInWS(fGlobalObsName.c_str(), set);
186 }
187 /// Specify the global observables
188 /// through a comma-separated list of arguments already in the workspace.
189 virtual void SetGlobalObservables(const char *argList) {
190 if(!GetWS()) return;
191 SetGlobalObservables(GetWS()->argSet(argList));
192 }
193
194 /// Set parameter values for a particular hypothesis if using a common PDF
195 /// by saving a snapshot in the workspace.
196 virtual void SetSnapshot(const RooArgSet& set);
197
198 /// Specify the name of the PDF in the workspace to be used.
199 virtual void SetPdf(const char* name) {
200 if (! GetWS() ) return;
201
202 if(GetWS()->pdf(name))
203 fPdfName = name;
204 else
205 coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<std::endl;
206 }
207
208 /// Specify the name of the PDF in the workspace to be used.
209 virtual void SetPriorPdf(const char* name) {
210 if (! GetWS() ) return;
211
212 if(GetWS()->pdf(name))
214 else
215 coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<std::endl;
216 }
217
218
219 /// Specify the name of the dataset in the workspace to be used.
220 virtual void SetProtoData(const char* name){
221 if (! GetWS() ) return;
222
223 if(GetWS()->data(name))
225 else
226 coutE(ObjectHandling) << "dataset "<<name<< " does not exist in workspace"<<std::endl;
227 }
228
229
230 /* getter methods */
231
232
233 /// get model PDF (return NULL if pdf has not been specified or does not exist)
234 RooAbsPdf * GetPdf() const { return (GetWS()) ? GetWS()->pdf(fPdfName.c_str()) : 0; }
235
236 /// get RooArgSet containing the parameter of interest (return NULL if not existing)
237 const RooArgSet * GetParametersOfInterest() const { return (GetWS()) ? GetWS()->set(fPOIName.c_str()) : 0; }
238
239 /// get RooArgSet containing the nuisance parameters (return NULL if not existing)
240 const RooArgSet * GetNuisanceParameters() const { return (GetWS()) ? GetWS()->set(fNuisParamsName.c_str()) : 0; }
241
242 /// get RooArgSet containing the constraint parameters (return NULL if not existing)
243 const RooArgSet * GetConstraintParameters() const { return (GetWS()) ? GetWS()->set(fConstrParamsName.c_str()) : 0; }
244
245 /// get parameters prior pdf (return NULL if not existing)
246 RooAbsPdf * GetPriorPdf() const { return (GetWS()) ? GetWS()->pdf(fPriorPdfName.c_str()) : 0; }
247
248 /// get RooArgSet for observables (return NULL if not existing)
249 const RooArgSet * GetObservables() const { return (GetWS()) ? GetWS()->set(fObservablesName.c_str()) : 0; }
250
251 /// get RooArgSet for conditional observables (return NULL if not existing)
252 const RooArgSet * GetConditionalObservables() const { return (GetWS()) ? GetWS()->set(fConditionalObsName.c_str()) : 0; }
253
254 /// get RooArgSet for global observables (return NULL if not existing)
255 const RooArgSet * GetGlobalObservables() const { return (GetWS()) ? GetWS()->set(fGlobalObsName.c_str()) : 0; }
256
257 /// get Proto data set (return NULL if not existing)
258 RooAbsData * GetProtoData() const { return (GetWS()) ? GetWS()->data(fProtoDataName.c_str()) : 0; }
259
260 /// get RooArgSet for parameters for a particular hypothesis (return NULL if not existing)
261 const RooArgSet * GetSnapshot() const;
262
263 void LoadSnapshot() const;
264
265 RooWorkspace * GetWS() const override;
266 /// alias for GetWS()
267 RooWorkspace * GetWorkspace() const { return GetWS(); }
268
269 void GuessObsAndNuisance(const RooAbsData& data);
270
271 /// overload the print method
272 virtual void Print(Option_t* option = "") const override;
273
274protected:
275
276 /// helper function to check that content of a given set is exclusively parameters
277 Bool_t SetHasOnlyParameters(const RooArgSet& set, const char* errorMsgPrefix=0) ;
278
279 /// helper functions to define a set in the WS
280 void DefineSetInWS(const char* name, const RooArgSet& set);
281
282 /// internal function to import Pdf in WS
283 void ImportPdfInWS(const RooAbsPdf & pdf);
284
285 /// internal function to import data in WS
286 void ImportDataInWS(RooAbsData & data);
287
288 TRef fRefWS; /// WS reference used in the file
289
290 std::string fWSName; /// name of the WS
291
292 std::string fPdfName; /// name of PDF in workspace
293 std::string fDataName; /// name of data set in workspace
294 std::string fPOIName; /// name for RooArgSet specifying parameters of interest
295
296 std::string fNuisParamsName; /// name for RooArgSet specifying nuisance parameters
297 std::string fConstrParamsName; /// name for RooArgSet specifying constrained parameters
298 std::string fPriorPdfName; /// name for RooAbsPdf specifying a prior on the parameters
299
300 std::string fConditionalObsName; /// name for RooArgSet specifying conditional observables
301 std::string fGlobalObsName; /// name for RooArgSet specifying global observables
302 std::string fProtoDataName; /// name for RooArgSet specifying dataset that should be used as proto-data
303
304 std::string fSnapshotName; /// name for RooArgSet that specifies a particular hypothesis
305
306 std::string fObservablesName; /// name for RooArgSet specifying observable parameters.
307
308 ClassDefOverride(ModelConfig,5) /// A class that holds configuration information for a model using a workspace as a store
309
310};
311
312} // end namespace RooStats
313
314
315#endif
#define coutE(a)
Definition: RooMsgService.h:34
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDefOverride(name, id)
Definition: Rtypes.h:330
char name[80]
Definition: TGX11.cxx:109
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:261
RooFIter fwdIterator() const R__SUGGEST_ALTERNATIVE("begin()
One-time forward iterator.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:39
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooAbsArg * next()
Return next element or nullptr if at end.
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
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...
virtual void SetObservables(const RooArgSet &set)
Specify the observables.
Definition: ModelConfig.h:146
std::string fSnapshotName
name for RooArgSet specifying dataset that should be used as proto-data
Definition: ModelConfig.h:304
void ImportPdfInWS(const RooAbsPdf &pdf)
internal function to import Pdf in WS
std::string fNuisParamsName
name for RooArgSet specifying parameters of interest
Definition: ModelConfig.h:296
virtual void SetPriorPdf(const RooAbsPdf &pdf)
Set the Prior Pdf, add to the the workspace if not already there.
Definition: ModelConfig.h:87
virtual ModelConfig * Clone(const char *name="") const override
clone
Definition: ModelConfig.h:54
virtual void SetObservables(const char *argList)
specify the observables through a comma-separated list of arguments already in the workspace.
Definition: ModelConfig.h:153
RooAbsData * GetProtoData() const
get Proto data set (return NULL if not existing)
Definition: ModelConfig.h:258
void DefineSetInWS(const char *name, const RooArgSet &set)
helper functions to define a set in the WS
virtual void SetNuisanceParameters(const char *argList)
Specify the nuisance parameters using a comma-separated list of arguments already in the workspace.
Definition: ModelConfig.h:127
std::string fWSName
WS reference used in the file.
Definition: ModelConfig.h:290
std::string fPriorPdfName
name for RooArgSet specifying constrained parameters
Definition: ModelConfig.h:298
std::string fDataName
name of PDF in workspace
Definition: ModelConfig.h:293
virtual void SetWorkspace(RooWorkspace &ws)
Definition: ModelConfig.h:66
RooWorkspace * GetWorkspace() const
alias for GetWS()
Definition: ModelConfig.h:267
const RooArgSet * GetConditionalObservables() const
get RooArgSet for conditional observables (return NULL if not existing)
Definition: ModelConfig.h:252
virtual void SetProtoData(const char *name)
Specify the name of the dataset in the workspace to be used.
Definition: ModelConfig.h:220
std::string fConditionalObsName
name for RooAbsPdf specifying a prior on the parameters
Definition: ModelConfig.h:300
const RooArgSet * GetGlobalObservables() const
get RooArgSet for global observables (return NULL if not existing)
Definition: ModelConfig.h:255
virtual void SetParametersOfInterest(const RooArgSet &set)
Specify parameters of interest.
Definition: ModelConfig.h:100
virtual void ReplaceWS(RooWorkspace *ws) override
Remove the existing reference to a workspace and replace it with this new one.
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
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
Definition: ModelConfig.h:237
std::string fPdfName
name of the WS
Definition: ModelConfig.h:292
std::string fObservablesName
name for RooArgSet that specifies a particular hypothesis
Definition: ModelConfig.h:306
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
Definition: ModelConfig.h:240
virtual void SetGlobalObservables(const RooArgSet &set)
Specify the global observables.
Definition: ModelConfig.h:172
virtual void SetConstraintParameters(const char *argList)
Specify the constraint parameters through a comma-separated list of arguments already in the workspac...
Definition: ModelConfig.h:140
ModelConfig(RooWorkspace *ws=0)
Definition: ModelConfig.h:34
virtual void SetParameters(const char *argList)
Specify parameters using a list of comma-separated list of arguments already in the workspace.
Definition: ModelConfig.h:107
ModelConfig(const char *name, RooWorkspace *ws=0)
Definition: ModelConfig.h:40
void LoadSnapshot() const
load the snapshot from ws if it exists
std::string fConstrParamsName
name for RooArgSet specifying nuisance parameters
Definition: ModelConfig.h:297
virtual void Print(Option_t *option="") const override
overload the print method
std::string fGlobalObsName
name for RooArgSet specifying conditional observables
Definition: ModelConfig.h:301
void ImportDataInWS(RooAbsData &data)
internal function to import data in WS
virtual void SetWS(RooWorkspace &ws) override
Set a workspace that owns all the necessary components for the analysis.
std::string fPOIName
name of data set in workspace
Definition: ModelConfig.h:294
virtual void SetParametersOfInterest(const char *argList)
Specify parameters of interest using a comma-separated list of arguments already in the workspace.
Definition: ModelConfig.h:114
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
Definition: ModelConfig.h:249
virtual void SetConditionalObservables(const char *argList)
Specify the conditional observables through a comma-separated list of arguments already in the worksp...
Definition: ModelConfig.h:166
virtual void SetGlobalObservables(const char *argList)
Specify the global observables through a comma-separated list of arguments already in the workspace.
Definition: ModelConfig.h:189
const RooArgSet * GetSnapshot() const
get RooArgSet for parameters for a particular hypothesis (return NULL if not existing)
const RooArgSet * GetConstraintParameters() const
get RooArgSet containing the constraint parameters (return NULL if not existing)
Definition: ModelConfig.h:243
virtual void SetParameters(const RooArgSet &set)
Specify parameters of the PDF.
Definition: ModelConfig.h:93
void GuessObsAndNuisance(const RooAbsData &data)
Makes sensible guesses of observables, parameters of interest and nuisance parameters if one or multi...
Definition: ModelConfig.cxx:68
RooWorkspace * GetWS() const override
get from TRef
ModelConfig(const char *name, const char *title, RooWorkspace *ws=0)
Definition: ModelConfig.h:46
virtual void SetPriorPdf(const char *name)
Specify the name of the PDF in the workspace to be used.
Definition: ModelConfig.h:209
std::string fProtoDataName
name for RooArgSet specifying global observables
Definition: ModelConfig.h:302
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
Definition: ModelConfig.h:234
virtual void SetNuisanceParameters(const RooArgSet &set)
Specify the nuisance parameters (parameters that are not POI).
Definition: ModelConfig.h:119
virtual void SetConstraintParameters(const RooArgSet &set)
Specify the constraint parameters.
Definition: ModelConfig.h:133
virtual void SetPdf(const char *name)
Specify the name of the PDF in the workspace to be used.
Definition: ModelConfig.h:199
virtual void SetProtoData(RooAbsData &data)
Set the proto DataSet, add to the the workspace if not already there.
Definition: ModelConfig.h:75
virtual void SetConditionalObservables(const RooArgSet &set)
Specify the conditional observables.
Definition: ModelConfig.h:159
RooAbsPdf * GetPriorPdf() const
get parameters prior pdf (return NULL if not existing)
Definition: ModelConfig.h:246
virtual void SetPdf(const RooAbsPdf &pdf)
Set the Pdf, add to the the workspace if not already there.
Definition: ModelConfig.h:81
An interface to set and retrieve a workspace.
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
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...
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Persistent Reference link to a TObject A TRef is a lightweight object pointing to any TObject.
Definition: TRef.h:32
@ ObjectHandling
Definition: RooGlobalFunc.h:68
Namespace for the RooStats classes.
Definition: Asimov.h:20
void ws()
Definition: ws.C:66