ModelConfig.h

Go to the documentation of this file.
00001 // @(#)root/roostats:$Id: ModelConfig.h 37084 2010-11-29 21:37:13Z moneta $
00002 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke, Sven Kreiss
00003 /*************************************************************************
00004  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00009  *************************************************************************/
00010 
00011 #ifndef ROOSTATS_ModelConfig
00012 #define ROOSTATS_ModelConfig
00013 
00014 
00015 #ifndef ROO_ABS_PDF
00016 #include "RooAbsPdf.h"
00017 #endif
00018 
00019 #ifndef ROO_ABS_DATA
00020 #include "RooAbsData.h"
00021 #endif
00022 
00023 #ifndef ROO_ARG_SET
00024 #include "RooArgSet.h"
00025 #endif
00026 
00027 #ifndef ROO_WORKSPACE
00028 #include "RooWorkspace.h"
00029 #endif
00030 
00031 #ifndef ROOT_TRef
00032 #include "TRef.h"
00033 #endif
00034 
00035 #include <string>
00036 
00037 //_________________________________________________
00038 /*
00039 BEGIN_HTML
00040 <p>
00041 ModelConfig is a simple class that holds configuration information specifying how a model
00042 should be used in the context of various RooStats tools.  A single model can be used
00043 in different ways, and this class should carry all that is needed to specify how it should be used.
00044 ModelConfig requires a workspace to be set.
00045 </p>
00046 END_HTML
00047 */
00048 //
00049 
00050 
00051 namespace RooStats {
00052 
00053 class ModelConfig : public TNamed {
00054 
00055 public:
00056 
00057    ModelConfig(RooWorkspace * ws = 0) : 
00058       TNamed()
00059    {
00060       if(ws) SetWS(*ws);
00061    }
00062     
00063    ModelConfig(const char* name, RooWorkspace *ws = 0) : 
00064       TNamed(name, name)
00065    {
00066       if(ws) SetWS(*ws);
00067    }
00068     
00069    ModelConfig(const char* name, const char* title, RooWorkspace *ws = 0) : 
00070       TNamed(name, title)
00071    {
00072       if(ws) SetWS(*ws);
00073    }
00074 
00075     
00076    // clone
00077    virtual ModelConfig * Clone(const char * name = "") const {
00078       ModelConfig * mc =  new ModelConfig(*this);
00079       if(strcmp(name,"")==0)
00080         mc->SetName(this->GetName());
00081       else
00082         mc->SetName(name); 
00083       return mc; 
00084    }
00085 
00086    // set a workspace that owns all the necessary components for the analysis
00087    virtual void SetWS(RooWorkspace & ws);
00088    /// alias for SetWS(...)
00089    virtual void SetWorkspace(RooWorkspace & ws) { SetWS(ws); }
00090 
00091    // Set the proto DataSet, add to the the workspace if not already there
00092    virtual void SetProtoData(RooAbsData & data) {      
00093       ImportDataInWS(data); 
00094       SetProtoData( data.GetName() );
00095    }
00096     
00097    // Set the Pdf, add to the the workspace if not already there
00098    virtual void SetPdf(const RooAbsPdf& pdf) {
00099       ImportPdfInWS(pdf);
00100       SetPdf( pdf.GetName() );      
00101    }
00102 
00103    // Set the Prior Pdf, add to the the workspace if not already there
00104    virtual void SetPriorPdf(const RooAbsPdf& pdf) {
00105       ImportPdfInWS(pdf);
00106       SetPriorPdf( pdf.GetName() );      
00107    }
00108     
00109    // specify the parameters of interest in the interval
00110    virtual void SetParameters(const RooArgSet& set) {
00111       fPOIName=std::string(GetName()) + "_POI";
00112       DefineSetInWS(fPOIName.c_str(), set);
00113    }
00114    virtual void SetParametersOfInterest(const RooArgSet& set) {
00115       SetParameters(set); 
00116    }
00117     
00118    // specify the nuisance parameters (eg. the rest of the parameters)
00119    virtual void SetNuisanceParameters(const RooArgSet& set) {
00120       fNuisParamsName=std::string(GetName()) + "_NuisParams";
00121       DefineSetInWS(fNuisParamsName.c_str(), set);
00122    }
00123 
00124    // specify the constraint parameters 
00125    virtual void SetConstraintParameters(const RooArgSet& set) {
00126       fConstrParamsName=std::string(GetName()) + "_ConstrainedParams";
00127       DefineSetInWS(fConstrParamsName.c_str(), set);
00128    }
00129 
00130    // specify the observables
00131    virtual void SetObservables(const RooArgSet& set) {
00132       fObservablesName=std::string(GetName()) + "_Observables";
00133       DefineSetInWS(fObservablesName.c_str(), set);
00134    }
00135 
00136    // specify the conditional observables
00137    virtual void SetConditionalObservables(const RooArgSet& set) {
00138       fConditionalObsName=std::string(GetName()) + "_ConditionalObservables";
00139       DefineSetInWS(fConditionalObsName.c_str(), set);
00140    }
00141 
00142    // specify the conditional observables
00143    virtual void SetGlobalObservables(const RooArgSet& set) {
00144       fGlobalObsName=std::string(GetName()) + "_GlobalObservables";
00145       DefineSetInWS(fGlobalObsName.c_str(), set);
00146    }
00147 
00148    // set parameter values for a particular hypothesis if using a common PDF
00149    // by saving a snapshot in the workspace
00150    virtual void SetSnapshot(const RooArgSet& set);
00151     
00152    // specify the name of the PDF in the workspace to be used
00153    virtual void SetPdf(const char* name) {
00154       if (! GetWS() ) return;
00155 
00156       if(GetWS()->pdf(name))
00157          fPdfName = name;
00158       else
00159          coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<endl;
00160    }
00161 
00162    // specify the name of the PDF in the workspace to be used
00163    virtual void SetPriorPdf(const char* name) {
00164       if (! GetWS() ) return;
00165 
00166       if(GetWS()->pdf(name))
00167          fPriorPdfName = name;
00168       else
00169          coutE(ObjectHandling) << "pdf "<<name<< " does not exist in workspace"<<endl;
00170    }
00171 
00172 
00173    // specify the name of the dataset in the workspace to be used
00174    virtual void SetProtoData(const char* name){
00175       if (! GetWS() ) return;
00176 
00177       if(GetWS()->data(name))
00178          fProtoDataName = name;
00179       else
00180          coutE(ObjectHandling) << "dataset "<<name<< " does not exist in workspace"<<endl;
00181    }
00182 
00183 
00184    /* getter methods */
00185 
00186 
00187    /// get model PDF (return NULL if pdf has not been specified or does not exist)
00188    RooAbsPdf * GetPdf() const { return (GetWS()) ? GetWS()->pdf(fPdfName.c_str()) : 0;   }
00189 
00190    /// get RooArgSet containing the parameter of interest (return NULL if not existing) 
00191    const RooArgSet * GetParametersOfInterest() const { return (GetWS()) ? GetWS()->set(fPOIName.c_str()) : 0; }
00192 
00193    /// get RooArgSet containing the nuisance parameters (return NULL if not existing) 
00194    const RooArgSet * GetNuisanceParameters() const { return (GetWS()) ? GetWS()->set(fNuisParamsName.c_str()) : 0; }
00195 
00196    /// get RooArgSet containing the constraint parameters (return NULL if not existing) 
00197    const RooArgSet * GetConstraintParameters() const { return (GetWS()) ? GetWS()->set(fConstrParamsName.c_str()) : 0; }
00198 
00199    /// get parameters prior pdf  (return NULL if not existing) 
00200    RooAbsPdf * GetPriorPdf() const { return (GetWS()) ? GetWS()->pdf(fPriorPdfName.c_str()) : 0; }
00201 
00202    /// get RooArgSet for observables  (return NULL if not existing)
00203    const RooArgSet * GetObservables() const { return (GetWS()) ? GetWS()->set(fObservablesName.c_str()) : 0; }
00204 
00205    /// get RooArgSet for conditional observables  (return NULL if not existing)
00206    const RooArgSet * GetConditionalObservables() const { return (GetWS()) ? GetWS()->set(fConditionalObsName.c_str()) : 0; }
00207 
00208    /// get RooArgSet for global observables  (return NULL if not existing)
00209    const RooArgSet * GetGlobalObservables() const { return (GetWS()) ? GetWS()->set(fGlobalObsName.c_str()) : 0; }
00210 
00211    /// get Proto data set (return NULL if not existing) 
00212    RooAbsData * GetProtoData()  const {  return (GetWS()) ? GetWS()->data(fProtoDataName.c_str()) : 0; }
00213 
00214    /// get RooArgSet for parameters for a particular hypothesis  (return NULL if not existing) 
00215    const RooArgSet * GetSnapshot() const;
00216 
00217    void LoadSnapshot() const;
00218  
00219    RooWorkspace * GetWS() const;
00220    /// alias for GetWS()
00221    RooWorkspace * GetWorkspace() const { return GetWS(); }
00222 
00223    /// guesses Observables and ParametersOfInterest if not already set
00224    void GuessObsAndNuisance(const RooAbsData& data);
00225 
00226    // overload the print method
00227    virtual void Print(Option_t* option = "") const;
00228 
00229 protected:
00230    // helper functions to define a set in the WS
00231    void DefineSetInWS(const char* name, const RooArgSet& set);
00232     
00233    // internal function to import Pdf in WS
00234    void ImportPdfInWS(const RooAbsPdf & pdf);
00235       
00236    // internal function to import data in WS
00237    void ImportDataInWS(RooAbsData & data); 
00238     
00239    TRef fRefWS;  // WS reference used in the file
00240 
00241    std::string fWSName;  // name of the WS
00242 
00243    std::string fPdfName; // name of  PDF in workspace
00244    std::string fDataName; // name of data set in workspace
00245    std::string fPOIName; // name for RooArgSet specifying parameters of interest
00246     
00247    std::string fNuisParamsName; // name for RooArgSet specifying nuisance parameters
00248    std::string fConstrParamsName; // name for RooArgSet specifying constrained parameters
00249    std::string fPriorPdfName; // name for RooAbsPdf specifying a prior on the parameters
00250     
00251    std::string fConditionalObsName; // name for RooArgSet specifying conditional observables
00252    std::string fGlobalObsName; // name for RooArgSet specifying global observables
00253    std::string fProtoDataName; // name for RooArgSet specifying dataset that should be used as protodata
00254     
00255    std::string fSnapshotName; // name for RooArgSet that specifies a particular hypothesis
00256     
00257    std::string fObservablesName; // name for RooArgSet specifying observable parameters. 
00258     
00259    ClassDef(ModelConfig,4) // A class that holds configuration information for a model using a workspace as a store
00260       
00261 };
00262 
00263 }   // end namespace RooStats
00264 
00265 
00266 #endif

Generated on Tue Jul 5 14:26:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1