#ifndef ROOSTATS_ModelConfig
#define ROOSTATS_ModelConfig
#ifndef ROO_ABS_PDF
#include "RooAbsPdf.h"
#endif
#ifndef ROO_ABS_DATA
#include "RooAbsData.h"
#endif
#ifndef ROO_ARG_SET
#include "RooArgSet.h"
#endif
#ifndef ROO_WORKSPACE
#include "RooWorkspace.h"
#endif
#ifndef ROOT_TRef
#include "TRef.h"
#endif
#include <string>
namespace RooStats {
class ModelConfig : public TNamed {
public:
ModelConfig(RooWorkspace * ws = 0) :
TNamed()
{
if(ws) SetWS(*ws);
}
ModelConfig(const char* name, RooWorkspace *ws = 0) :
TNamed(name, name)
{
if(ws) SetWS(*ws);
}
ModelConfig(const char* name, const char* title, RooWorkspace *ws = 0) :
TNamed(name, title)
{
if(ws) SetWS(*ws);
}
virtual ModelConfig * Clone(const char * name = "") const {
ModelConfig * mc = new ModelConfig(*this);
if(strcmp(name,"")==0)
mc->SetName(this->GetName());
else
mc->SetName(name);
return mc;
}
virtual void SetWS(RooWorkspace & ws);
virtual void SetWorkspace(RooWorkspace & ws) { SetWS(ws); }
virtual void SetProtoData(RooAbsData & data) {
ImportDataInWS(data);
SetProtoData( data.GetName() );
}
virtual void SetPdf(const RooAbsPdf& pdf) {
ImportPdfInWS(pdf);
SetPdf( pdf.GetName() );
}
virtual void SetPriorPdf(const RooAbsPdf& pdf) {
ImportPdfInWS(pdf);
SetPriorPdf( pdf.GetName() );
}
virtual void SetParameters(const RooArgSet& set) {
fPOIName=std::string(GetName()) + "_POI";
DefineSetInWS(fPOIName.c_str(), set);
}
virtual void SetParametersOfInterest(const RooArgSet& set) {
SetParameters(set);
}
virtual void SetNuisanceParameters(const RooArgSet& set) {
fNuisParamsName=std::string(GetName()) + "_NuisParams";
DefineSetInWS(fNuisParamsName.c_str(), set);
}
virtual void SetConstraintParameters(const RooArgSet& set) {
fConstrParamsName=std::string(GetName()) + "_ConstrainedParams";
DefineSetInWS(fConstrParamsName.c_str(), set);
}
virtual void SetObservables(const RooArgSet& set) {
fObservablesName=std::string(GetName()) + "_Observables";
DefineSetInWS(fObservablesName.c_str(), set);
}
virtual void SetConditionalObservables(const RooArgSet& set) {
fConditionalObsName=std::string(GetName()) + "_ConditionalObservables";
DefineSetInWS(fConditionalObsName.c_str(), set);
}
virtual void SetGlobalObservables(const RooArgSet& set) {
fGlobalObsName=std::string(GetName()) + "_GlobalObservables";
DefineSetInWS(fGlobalObsName.c_str(), set);
}
virtual void SetSnapshot(const RooArgSet& set);
virtual void SetPdf(const char* name) {
if (! GetWS() ) return;
if(GetWS()->pdf(name))
fPdfName = name;
else
coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<endl;
}
virtual void SetPriorPdf(const char* name) {
if (! GetWS() ) return;
if(GetWS()->pdf(name))
fPriorPdfName = name;
else
coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<endl;
}
virtual void SetProtoData(const char* name){
if (! GetWS() ) return;
if(GetWS()->data(name))
fProtoDataName = name;
else
coutE(ObjectHandling) << "dataset "<<name<< " does not exist in workspace"<<endl;
}
RooAbsPdf * GetPdf() const { return (GetWS()) ? GetWS()->pdf(fPdfName.c_str()) : 0; }
const RooArgSet * GetParametersOfInterest() const { return (GetWS()) ? GetWS()->set(fPOIName.c_str()) : 0; }
const RooArgSet * GetNuisanceParameters() const { return (GetWS()) ? GetWS()->set(fNuisParamsName.c_str()) : 0; }
const RooArgSet * GetConstraintParameters() const { return (GetWS()) ? GetWS()->set(fConstrParamsName.c_str()) : 0; }
RooAbsPdf * GetPriorPdf() const { return (GetWS()) ? GetWS()->pdf(fPriorPdfName.c_str()) : 0; }
const RooArgSet * GetObservables() const { return (GetWS()) ? GetWS()->set(fObservablesName.c_str()) : 0; }
const RooArgSet * GetConditionalObservables() const { return (GetWS()) ? GetWS()->set(fConditionalObsName.c_str()) : 0; }
const RooArgSet * GetGlobalObservables() const { return (GetWS()) ? GetWS()->set(fGlobalObsName.c_str()) : 0; }
RooAbsData * GetProtoData() const { return (GetWS()) ? GetWS()->data(fProtoDataName.c_str()) : 0; }
const RooArgSet * GetSnapshot() const;
void LoadSnapshot() const;
RooWorkspace * GetWS() const;
RooWorkspace * GetWorkspace() const { return GetWS(); }
void GuessObsAndNuisance(const RooAbsData& data);
virtual void Print(Option_t* option = "") const;
protected:
void DefineSetInWS(const char* name, const RooArgSet& set);
void ImportPdfInWS(const RooAbsPdf & pdf);
void ImportDataInWS(RooAbsData & data);
TRef fRefWS;
std::string fWSName;
std::string fPdfName;
std::string fDataName;
std::string fPOIName;
std::string fNuisParamsName;
std::string fConstrParamsName;
std::string fPriorPdfName;
std::string fConditionalObsName;
std::string fGlobalObsName;
std::string fProtoDataName;
std::string fSnapshotName;
std::string fObservablesName;
ClassDef(ModelConfig,4)
};
}
#endif