Logo ROOT   6.18/05
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 the parameters of interest in the interval
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 virtual void SetParametersOfInterest(const RooArgSet& set) {
100 if (!SetHasOnlyParameters(set,"ModelConfig::SetParametersOfInterest")) return ;
101 SetParameters(set);
102 }
103 /// specify the parameters of interest
104 /// through a list of comma-separated arguments already in the workspace
105 virtual void SetParameters(const char *argList) {
106 if(!GetWS()) return;
107 SetParameters(GetWS()->argSet(argList));
108 }
109 virtual void SetParametersOfInterest(const char *argList) {
110 SetParameters(argList);
111 }
112
113 /// specify the nuisance parameters (e.g. the rest of the parameters)
114 virtual void SetNuisanceParameters(const RooArgSet& set) {
115 if (!SetHasOnlyParameters(set,"ModelConfig::SetNuisanceParameters")) return ;
116 fNuisParamsName=std::string(GetName()) + "_NuisParams";
117 DefineSetInWS(fNuisParamsName.c_str(), set);
118 }
119 /// specify the nuisance parameters
120 /// through a list of comma-separated arguments already in the workspace
121 virtual void SetNuisanceParameters(const char *argList) {
122 if(!GetWS()) return;
123 SetNuisanceParameters(GetWS()->argSet(argList));
124 }
125
126 /// specify the constraint parameters
127 virtual void SetConstraintParameters(const RooArgSet& set) {
128 if (!SetHasOnlyParameters(set,"ModelConfig::SetConstainedParameters")) return ;
129 fConstrParamsName=std::string(GetName()) + "_ConstrainedParams";
130 DefineSetInWS(fConstrParamsName.c_str(), set);
131 }
132 /// specify the constraint parameters
133 /// through a list of comma-separated arguments already in the workspace
134 virtual void SetConstraintParameters(const char *argList) {
135 if(!GetWS()) return;
136 SetConstraintParameters(GetWS()->argSet(argList));
137 }
138
139 /// specify the observables
140 virtual void SetObservables(const RooArgSet& set) {
141 if (!SetHasOnlyParameters(set,"ModelConfig::SetObservables")) return ;
142 fObservablesName=std::string(GetName()) + "_Observables";
143 DefineSetInWS(fObservablesName.c_str(), set);
144 }
145 /// specify the observables
146 /// through a list of comma-separated arguments already in the workspace
147 virtual void SetObservables(const char *argList) {
148 if(!GetWS()) return;
149 SetObservables(GetWS()->argSet(argList));
150 }
151
152 /// specify the conditional observables
153 virtual void SetConditionalObservables(const RooArgSet& set) {
154 if (!SetHasOnlyParameters(set,"ModelConfig::SetConditionalObservables")) return ;
155 fConditionalObsName=std::string(GetName()) + "_ConditionalObservables";
157 }
158 /// specify the conditional observables
159 /// through a list of comma-separated arguments already in the workspace
160 virtual void SetConditionalObservables(const char *argList) {
161 if(!GetWS()) return;
162 SetConditionalObservables(GetWS()->argSet(argList));
163 }
164
165 /// specify the global observables
166 virtual void SetGlobalObservables(const RooArgSet& set) {
167
168 if (!SetHasOnlyParameters(set,"ModelConfig::SetGlobalObservables")) return ;
169
170 // make global observables constant
171 RooFIter iter = set.fwdIterator();
172 RooAbsArg *arg = iter.next();
173 while(arg != NULL) {
174 arg->setAttribute("Constant", kTRUE);
175 arg = iter.next();
176 }
177
178 fGlobalObsName=std::string(GetName()) + "_GlobalObservables";
179 DefineSetInWS(fGlobalObsName.c_str(), set);
180 }
181 /// specify the global observables
182 /// through a list of comma-separated arguments already in the workspace
183 virtual void SetGlobalObservables(const char *argList) {
184 if(!GetWS()) return;
185 SetGlobalObservables(GetWS()->argSet(argList));
186 }
187
188 /// set parameter values for a particular hypothesis if using a common PDF
189 /// by saving a snapshot in the workspace
190 virtual void SetSnapshot(const RooArgSet& set);
191
192 /// specify the name of the PDF in the workspace to be used
193 virtual void SetPdf(const char* name) {
194 if (! GetWS() ) return;
195
196 if(GetWS()->pdf(name))
197 fPdfName = name;
198 else
199 coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<std::endl;
200 }
201
202 /// specify the name of the PDF in the workspace to be used
203 virtual void SetPriorPdf(const char* name) {
204 if (! GetWS() ) return;
205
206 if(GetWS()->pdf(name))
208 else
209 coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<std::endl;
210 }
211
212
213 /// specify the name of the dataset in the workspace to be used
214 virtual void SetProtoData(const char* name){
215 if (! GetWS() ) return;
216
217 if(GetWS()->data(name))
219 else
220 coutE(ObjectHandling) << "dataset "<<name<< " does not exist in workspace"<<std::endl;
221 }
222
223
224 /* getter methods */
225
226
227 /// get model PDF (return NULL if pdf has not been specified or does not exist)
228 RooAbsPdf * GetPdf() const { return (GetWS()) ? GetWS()->pdf(fPdfName.c_str()) : 0; }
229
230 /// get RooArgSet containing the parameter of interest (return NULL if not existing)
231 const RooArgSet * GetParametersOfInterest() const { return (GetWS()) ? GetWS()->set(fPOIName.c_str()) : 0; }
232
233 /// get RooArgSet containing the nuisance parameters (return NULL if not existing)
234 const RooArgSet * GetNuisanceParameters() const { return (GetWS()) ? GetWS()->set(fNuisParamsName.c_str()) : 0; }
235
236 /// get RooArgSet containing the constraint parameters (return NULL if not existing)
237 const RooArgSet * GetConstraintParameters() const { return (GetWS()) ? GetWS()->set(fConstrParamsName.c_str()) : 0; }
238
239 /// get parameters prior pdf (return NULL if not existing)
240 RooAbsPdf * GetPriorPdf() const { return (GetWS()) ? GetWS()->pdf(fPriorPdfName.c_str()) : 0; }
241
242 /// get RooArgSet for observables (return NULL if not existing)
243 const RooArgSet * GetObservables() const { return (GetWS()) ? GetWS()->set(fObservablesName.c_str()) : 0; }
244
245 /// get RooArgSet for conditional observables (return NULL if not existing)
246 const RooArgSet * GetConditionalObservables() const { return (GetWS()) ? GetWS()->set(fConditionalObsName.c_str()) : 0; }
247
248 /// get RooArgSet for global observables (return NULL if not existing)
249 const RooArgSet * GetGlobalObservables() const { return (GetWS()) ? GetWS()->set(fGlobalObsName.c_str()) : 0; }
250
251 /// get Proto data set (return NULL if not existing)
252 RooAbsData * GetProtoData() const { return (GetWS()) ? GetWS()->data(fProtoDataName.c_str()) : 0; }
253
254 /// get RooArgSet for parameters for a particular hypothesis (return NULL if not existing)
255 const RooArgSet * GetSnapshot() const;
256
257 void LoadSnapshot() const;
258
259 RooWorkspace * GetWS() const override;
260 /// alias for GetWS()
261 RooWorkspace * GetWorkspace() const { return GetWS(); }
262
263 /// guesses Observables and ParametersOfInterest if not already set
264 void GuessObsAndNuisance(const RooAbsData& data);
265
266 /// overload the print method
267 virtual void Print(Option_t* option = "") const override;
268
269protected:
270
271 /// helper function to check that content of a given set is exclusively parameters
272 Bool_t SetHasOnlyParameters(const RooArgSet& set, const char* errorMsgPrefix=0) ;
273
274 /// helper functions to define a set in the WS
275 void DefineSetInWS(const char* name, const RooArgSet& set);
276
277 /// internal function to import Pdf in WS
278 void ImportPdfInWS(const RooAbsPdf & pdf);
279
280 /// internal function to import data in WS
281 void ImportDataInWS(RooAbsData & data);
282
283 TRef fRefWS; /// WS reference used in the file
284
285 std::string fWSName; /// name of the WS
286
287 std::string fPdfName; /// name of PDF in workspace
288 std::string fDataName; /// name of data set in workspace
289 std::string fPOIName; /// name for RooArgSet specifying parameters of interest
290
291 std::string fNuisParamsName; /// name for RooArgSet specifying nuisance parameters
292 std::string fConstrParamsName; /// name for RooArgSet specifying constrained parameters
293 std::string fPriorPdfName; /// name for RooAbsPdf specifying a prior on the parameters
294
295 std::string fConditionalObsName; /// name for RooArgSet specifying conditional observables
296 std::string fGlobalObsName; /// name for RooArgSet specifying global observables
297 std::string fProtoDataName; /// name for RooArgSet specifying dataset that should be used as proto-data
298
299 std::string fSnapshotName; /// name for RooArgSet that specifies a particular hypothesis
300
301 std::string fObservablesName; /// name for RooArgSet specifying observable parameters.
302
303 ClassDefOverride(ModelConfig,5) /// A class that holds configuration information for a model using a workspace as a store
304
305};
306
307} // end namespace RooStats
308
309
310#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:70
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:256
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:37
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:140
std::string fSnapshotName
name for RooArgSet specifying dataset that should be used as proto-data
Definition: ModelConfig.h:299
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:291
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 list of comma-separated arguments already in the workspace
Definition: ModelConfig.h:147
RooAbsData * GetProtoData() const
get Proto data set (return NULL if not existing)
Definition: ModelConfig.h:252
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 through a list of comma-separated arguments already in the workspace
Definition: ModelConfig.h:121
std::string fWSName
WS reference used in the file.
Definition: ModelConfig.h:285
std::string fPriorPdfName
name for RooArgSet specifying constrained parameters
Definition: ModelConfig.h:293
std::string fDataName
name of PDF in workspace
Definition: ModelConfig.h:288
virtual void SetWorkspace(RooWorkspace &ws)
Definition: ModelConfig.h:66
RooWorkspace * GetWorkspace() const
alias for GetWS()
Definition: ModelConfig.h:261
const RooArgSet * GetConditionalObservables() const
get RooArgSet for conditional observables (return NULL if not existing)
Definition: ModelConfig.h:246
virtual void SetProtoData(const char *name)
specify the name of the dataset in the workspace to be used
Definition: ModelConfig.h:214
std::string fConditionalObsName
name for RooAbsPdf specifying a prior on the parameters
Definition: ModelConfig.h:295
const RooArgSet * GetGlobalObservables() const
get RooArgSet for global observables (return NULL if not existing)
Definition: ModelConfig.h:249
virtual void SetParametersOfInterest(const RooArgSet &set)
Definition: ModelConfig.h:99
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:231
std::string fPdfName
name of the WS
Definition: ModelConfig.h:287
std::string fObservablesName
name for RooArgSet that specifies a particular hypothesis
Definition: ModelConfig.h:301
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
Definition: ModelConfig.h:234
virtual void SetGlobalObservables(const RooArgSet &set)
specify the global observables
Definition: ModelConfig.h:166
virtual void SetConstraintParameters(const char *argList)
specify the constraint parameters through a list of comma-separated arguments already in the workspac...
Definition: ModelConfig.h:134
ModelConfig(RooWorkspace *ws=0)
Definition: ModelConfig.h:34
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:105
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:292
virtual void Print(Option_t *option="") const override
overload the print method
std::string fGlobalObsName
name for RooArgSet specifying conditional observables
Definition: ModelConfig.h:296
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:289
virtual void SetParametersOfInterest(const char *argList)
Definition: ModelConfig.h:109
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
Definition: ModelConfig.h:243
virtual void SetConditionalObservables(const char *argList)
specify the conditional observables through a list of comma-separated arguments already in the worksp...
Definition: ModelConfig.h:160
virtual void SetGlobalObservables(const char *argList)
specify the global observables through a list of comma-separated arguments already in the workspace
Definition: ModelConfig.h:183
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:237
virtual void SetParameters(const RooArgSet &set)
specify the parameters of interest in the interval
Definition: ModelConfig.h:93
void GuessObsAndNuisance(const RooAbsData &data)
guesses Observables and ParametersOfInterest if not already set
Definition: ModelConfig.cxx:50
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:203
std::string fProtoDataName
name for RooArgSet specifying global observables
Definition: ModelConfig.h:297
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
Definition: ModelConfig.h:228
virtual void SetNuisanceParameters(const RooArgSet &set)
specify the nuisance parameters (e.g. the rest of the parameters)
Definition: ModelConfig.h:114
virtual void SetConstraintParameters(const RooArgSet &set)
specify the constraint parameters
Definition: ModelConfig.h:127
virtual void SetPdf(const char *name)
specify the name of the PDF in the workspace to be used
Definition: ModelConfig.h:193
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:153
RooAbsPdf * GetPriorPdf() const
get parameters prior pdf (return NULL if not existing)
Definition: ModelConfig.h:240
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:58
Namespace for the RooStats classes.
Definition: Asimov.h:20
void ws()
Definition: ws.C:66