a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
ComputeObservables Class Reference

A class for providing access to the computation of observables without a Monte Carlo run. More...

#include <ComputeObservables.h>

Detailed Description

A class for providing access to the computation of observables without a Monte Carlo run.

Author
HEPfit Collaboration

This class can be used to create an object that takes a map of model parameters that need to be varied in the analysis and passes out a map of the observables that it is told to compute.

Examples
libmode_config.cpp, and libmode_header.cpp.

Definition at line 35 of file ComputeObservables.h.

Public Member Functions

void addCustomObservableType (const std::string name, boost::function< Observable *() > funct)
 A method to add a user defined observable with a user defined likelihood. More...
 
void AddObservable (std::string ObsName)
 A method to remove an observable from the list of observables. More...
 
std::map< std::string, double > compute (std::map< std::string, double > DP)
 The method used to compute observables. More...
 
 ComputeObservables (ModelFactory &ModelF, ThObsFactory &ThObsF, const std::string &ModelConf_i, const int rank_i=0)
 Constructor. More...
 
 ComputeObservables (ModelFactory &ModelF, ThObsFactory &ThObsF, const std::string &ModelName_i, std::map< std::string, double > DPars_i, std::map< std::string, std::string > DFlags_i, const int rank_i=0)
 Constructor. More...
 
StandardModelgetModel ()
 A get method return the pointer to the model. More...
 
std::map< std::string, double > getObservables ()
 A method to get the map of observables. More...
 
std::map< std::string, double > getParameters ()
 A method to get the map of parameters. More...
 
void RemoveObservable (std::string ObsName)
 A method to add an observable to the list of observables. More...
 
void setFlags (std::map< std::string, std::string > DFlags_i)
 This method sets the necessary flag for the requested model. More...
 
virtual ~ComputeObservables ()
 The default destructor. More...
 

Private Attributes

std::vector< CorrelatedGaussianObservablesCGO
 
std::vector< CorrelatedGaussianParametersCGP
 
std::map< std::string, std::string > DFlags
 Map of the model flags to be passed to Model. More...
 
std::map< std::string, double > DObs
 Map of the observables to be computed. More...
 
std::map< std::string, double > DPars
 Map of the parameters to be passed to Model. More...
 
std::map< std::string, ThObservable * > DThObs
 
StandardModelMod
 Pointer to an object of the class StandardModel. More...
 
std::string ModelName
 Name of the Model to be used. More...
 
std::vector< ModelParameterModPars
 
InputParser myInputParser
 An object of the InputParser class. More...
 
boost::ptr_vector< ObservableObs
 
std::vector< Observable2DObs2D
 
std::vector< std::string > paraNames
 The vector of allowed parameter names. More...
 
const int rank
 < Rank of the MPI process. Set to 0 for serial run. More...
 
std::vector< std::string > unknownParameters
 

Constructor & Destructor Documentation

◆ ComputeObservables() [1/2]

ComputeObservables::ComputeObservables ( ModelFactory ModelF,
ThObsFactory ThObsF,
const std::string &  ModelConf_i,
const int  rank_i = 0 
)

Constructor.

This constructor passes the name of the SomeModel.conf file. It is to be used to compute observables using of a SomeModel.conf file to initialize the mandatory parameters.

Parameters
[in]ModelF
[in]ThObsF
[in]ModelConf_ithe name of the input configuration file for the model name,
[in]rank_ithe rank of the process in a MPI run (set to 0 for serial run) the model parameters and observables to be calculated

Definition at line 14 of file ComputeObservables.cpp.

16 : myInputParser(ModelF, ThObsF),
17  rank(rank_i)
18 {
19 
20  std::string ModelName = myInputParser.ReadParameters(ModelConf_i, rank, ModPars, Obs, Obs2D, CGO, CGP);
21  std::map<std::string, double> DP;
22  for (std::vector<ModelParameter>::iterator it = ModPars.begin(); it < ModPars.end(); it++) {
23  DP[it->getname()] = it->getave();
24  paraNames.push_back(it->getname());
25  }
26  DPars = DP;
27 
28  for (boost::ptr_vector<Observable>::iterator it = Obs.begin(); it < Obs.end(); it++) {
29  DObs.insert(std::pair<std::string, double> (it->getThname() , 0.));
30  DThObs.insert(std::pair<std::string, ThObservable*> (it->getThname() , it->getTho()));
31  }
32  for (std::vector<CorrelatedGaussianObservables>::iterator it1 = CGO.begin(); it1 < CGO.end(); it1++) {
33  std::vector<Observable> ObsInCGO = it1->getObs();
34  for (std::vector<Observable>::iterator it2 = ObsInCGO.begin(); it2 < ObsInCGO.end(); it2++) {
35  DObs.insert(std::pair<std::string, double> (it2->getThname() , 0.));
36  DThObs.insert(std::pair<std::string, ThObservable*> (it2->getThname() , it2->getTho()));
37  }
38  }
39 
41  if (!Mod->Init(DP)) {
42  if (myInputParser.getModel()->getmissingModelParameters().size() > 0) {
43  std::cout << "\nPlease set the following parameters in the model configuration files:\n" << std::endl;
44  for (std::vector<std::string>::iterator it = myInputParser.getModel()->getmissingModelParameters().begin(); it != myInputParser.getModel()->getmissingModelParameters().end(); it++) {
45  std::cout << "ModelParameter\t" << *it << std::endl;
46  }
47  std::cout << std::endl;
49  }
50  throw std::runtime_error("ERROR: Parameter(s) missing in model initialization.\n");
51  }
52 
54  if (unknownParameters.size() > 0 && rank == 0) {
55  std::cout << "\n" << std::endl;
56  for (std::vector<std::string>::iterator it = unknownParameters.begin(); it != unknownParameters.end(); it++)
57  std::cout << "WARNING: unknown parameter " << *it << " not added." << std::endl;
58  }
59 }

◆ ComputeObservables() [2/2]

ComputeObservables::ComputeObservables ( ModelFactory ModelF,
ThObsFactory ThObsF,
const std::string &  ModelName_i,
std::map< std::string, double >  DPars_i,
std::map< std::string, std::string >  DFlags_i,
const int  rank_i = 0 
)

Constructor.

This constructor passes the model name and model parameters. It is to be used to compute observables without the use of a SomeModel.conf file.

Parameters
[in]ModelF
[in]ThObsF
[in]ModelName_ithe name of the model being used
[in]DPars_ithe mandatory parameters of the model being used
[in]rank_ithe rank of the process in a MPI run (set to 0 for serial run)

Definition at line 61 of file ComputeObservables.cpp.

64 : ModelName(ModelName_i),
65  myInputParser(ModelF, ThObsF),
66  rank(rank_i)
67 {
68  for (std::map<std::string, double>::iterator it = DPars_i.begin(); it != DPars_i.end(); it++) {
69  paraNames.push_back(it->first);
70  }
74  if (Mod->IsModelInitialized()) {
75  if (rank == 0) std::cout << "\nModel Initialized: " << ModelName << std::endl;
76  } else {
77  throw std::runtime_error("\nERROR: " + ModelName + " not initialized successfully.\n");
78  }
79  setFlags(DFlags_i);
80  if (!Mod->Init(DPars_i)) {
81  if (myInputParser.getModel()->getmissingModelParameters().size() > 0) {
82  std::cout << "\nPlease set the following parameters in the model configuration files:\n" << std::endl;
83  for (std::vector<std::string>::iterator it = myInputParser.getModel()->getmissingModelParameters().begin(); it != myInputParser.getModel()->getmissingModelParameters().end(); it++) {
84  std::cout << "ModelParameter\t" << *it << std::endl;
85  }
86  std::cout << std::endl;
88  }
89  throw std::runtime_error("\nERROR: " + ModelName + " cannot be initialized.\n");
90  }
91 
93  if (unknownParameters.size() > 0 && rank == 0) {
94  std::cout << "\n" << std::endl;
95  for (std::vector<std::string>::iterator it = unknownParameters.begin(); it != unknownParameters.end(); it++)
96  std::cout << "WARNING: unknown parameter " << *it << " not added to MCMC" << std::endl;
97  }
98 }

◆ ~ComputeObservables()

ComputeObservables::~ComputeObservables ( )
virtual

The default destructor.

Definition at line 100 of file ComputeObservables.cpp.

101 {
102  Obs.clear();
103  boost::ptr_vector<Observable>().swap(Obs);
104  Mod = NULL;
105 }

Member Function Documentation

◆ addCustomObservableType()

void ComputeObservables::addCustomObservableType ( const std::string  name,
boost::function< Observable *() >  funct 
)

A method to add a user defined observable with a user defined likelihood.

Parameters
[in]afunction of the type observable

Definition at line 153 of file ComputeObservables.cpp.

153  {
155 }

◆ AddObservable()

void ComputeObservables::AddObservable ( std::string  ObsName)

A method to remove an observable from the list of observables.

Parameters
[in]ObsNamethe name of the observable to be removed
Examples
libmode_config.cpp, and libmode_header.cpp.

Definition at line 147 of file ComputeObservables.cpp.

148 {
149  DThObs[ObsName] = myInputParser.getObsFactory().CreateThMethod(ObsName, *Mod);
150  DObs.insert(std::pair<std::string, double> (ObsName , 0.));
151 }

◆ compute()

std::map< std::string, double > ComputeObservables::compute ( std::map< std::string, double >  DP)

The method used to compute observables.

Parameters
[in]DPthe map of parameters being varied
Examples
libmode_config.cpp, and libmode_header.cpp.

Definition at line 122 of file ComputeObservables.cpp.

123 {
124  if (DP != DPars)
125  for (std::map<std::string, double>::iterator it = DP.begin(); it != DP.end(); it++) {
126  if(!(std::find(paraNames.begin(), paraNames.end(), it->first) != paraNames.end()))
127  throw std::runtime_error("\nERROR: Incorrect parameter name " + it->first + " passed to ComputeObservable");
128  }
129  DPars = DP;
130  Mod->Update(DPars);
131  for (std::map<std::string, double>::iterator it = DObs.begin(); it != DObs.end(); it++) {
132  DObs[it->first] = DThObs[it->first]->computeThValue();
133  }
134  return(DObs);
135 }

◆ getModel()

StandardModel* ComputeObservables::getModel ( )
inline

A get method return the pointer to the model.

Returns
the pointer to the model

Definition at line 123 of file ComputeObservables.h.

124  {
125  return Mod;
126  }

◆ getObservables()

std::map<std::string, double> ComputeObservables::getObservables ( )
inline

A method to get the map of observables.

Returns
the map of observables
Examples
libmode_config.cpp, and libmode_header.cpp.

Definition at line 99 of file ComputeObservables.h.

100  {
101  return (DObs);
102  };

◆ getParameters()

std::map<std::string, double> ComputeObservables::getParameters ( )
inline

A method to get the map of parameters.

Returns
the map of parameters

Definition at line 108 of file ComputeObservables.h.

109  {
110  return (DPars);
111  };

◆ RemoveObservable()

void ComputeObservables::RemoveObservable ( std::string  ObsName)

A method to add an observable to the list of observables.

Parameters
[in]ObsNamethe name of the observable to be added

Definition at line 137 of file ComputeObservables.cpp.

138 {
139  if(DObs.find(ObsName) == DObs.end())
140  throw std::runtime_error("\nERROR: Observable cannot be removed since it has not been added.\n");
141  DObs.erase(ObsName);
142  if(DThObs.find(ObsName) == DThObs.end())
143  throw std::runtime_error("\nERROR: ThObservable cannot be removed since it has not been added.\n");
144  DThObs.erase(ObsName);
145 }

◆ setFlags()

void ComputeObservables::setFlags ( std::map< std::string, std::string >  DFlags_i)

This method sets the necessary flag for the requested model.

Parameters
[in]DFlags_ithe flags for the model being used
Examples
libmode_config.cpp.

Definition at line 107 of file ComputeObservables.cpp.

108 {
109  for (std::map<std::string, std::string>::iterator it = DFlags_i.begin(); it != DFlags_i.end(); it++) {
110  if (!(boost::iequals(it->second, "true")) && !(boost::iequals(it->second, "false")) && !Mod->setFlagStr(it->first, it->second)) {
111  throw std::runtime_error("ERROR: setFlagStr error for " + it->first);
112  } else if (boost::iequals(it->second, "true") && !Mod->setFlag(it->first, 1)) {
113  throw std::runtime_error("ERROR: setFlag error for " + it->first);
114  } else if (boost::iequals(it->second, "false") && !Mod->setFlag(it->first, 0)) {
115  throw std::runtime_error("ERROR: setFlag error for " + it->first);
116  } else {
117  if (rank == 0) std::cout << "set flag " << it->first << " = " << it->second << std::endl;
118  }
119  }
120 }

Member Data Documentation

◆ CGO

std::vector<CorrelatedGaussianObservables> ComputeObservables::CGO
private

Definition at line 143 of file ComputeObservables.h.

◆ CGP

std::vector<CorrelatedGaussianParameters> ComputeObservables::CGP
private

Definition at line 144 of file ComputeObservables.h.

◆ DFlags

std::map<std::string, std::string> ComputeObservables::DFlags
private

Map of the model flags to be passed to Model.

Definition at line 135 of file ComputeObservables.h.

◆ DObs

std::map<std::string, double> ComputeObservables::DObs
private

Map of the observables to be computed.

Definition at line 134 of file ComputeObservables.h.

◆ DPars

std::map<std::string, double> ComputeObservables::DPars
private

Map of the parameters to be passed to Model.

Definition at line 133 of file ComputeObservables.h.

◆ DThObs

std::map<std::string, ThObservable*> ComputeObservables::DThObs
private

Definition at line 137 of file ComputeObservables.h.

◆ Mod

StandardModel* ComputeObservables::Mod
private

Pointer to an object of the class StandardModel.

Definition at line 131 of file ComputeObservables.h.

◆ ModelName

std::string ComputeObservables::ModelName
private

Name of the Model to be used.

Definition at line 130 of file ComputeObservables.h.

◆ ModPars

std::vector<ModelParameter> ComputeObservables::ModPars
private

Definition at line 140 of file ComputeObservables.h.

◆ myInputParser

InputParser ComputeObservables::myInputParser
private

An object of the InputParser class.

Definition at line 132 of file ComputeObservables.h.

◆ Obs

boost::ptr_vector<Observable> ComputeObservables::Obs
private

Definition at line 141 of file ComputeObservables.h.

◆ Obs2D

std::vector<Observable2D> ComputeObservables::Obs2D
private

Definition at line 142 of file ComputeObservables.h.

◆ paraNames

std::vector<std::string> ComputeObservables::paraNames
private

The vector of allowed parameter names.

Definition at line 136 of file ComputeObservables.h.

◆ rank

const int ComputeObservables::rank
private

< Rank of the MPI process. Set to 0 for serial run.

Definition at line 138 of file ComputeObservables.h.

◆ unknownParameters

std::vector<std::string> ComputeObservables::unknownParameters
private

Definition at line 139 of file ComputeObservables.h.


The documentation for this class was generated from the following files:
ComputeObservables::Obs
boost::ptr_vector< Observable > Obs
Definition: ComputeObservables.h:141
Model::getmissingModelParameters
std::vector< std::string > getmissingModelParameters()
Definition: Model.h:245
ComputeObservables::ModelName
std::string ModelName
Name of the Model to be used.
Definition: ComputeObservables.h:130
ComputeObservables::DObs
std::map< std::string, double > DObs
Map of the observables to be computed.
Definition: ComputeObservables.h:134
ComputeObservables::DPars
std::map< std::string, double > DPars
Map of the parameters to be passed to Model.
Definition: ComputeObservables.h:133
StandardModel::setFlag
virtual bool setFlag(const std::string name, const bool value)
A method to set a flag of StandardModel.
Definition: StandardModel.cpp:404
ComputeObservables::CGO
std::vector< CorrelatedGaussianObservables > CGO
Definition: ComputeObservables.h:143
InputParser::ReadParameters
std::string ReadParameters(const std::string filename_i, const int rank, std::vector< ModelParameter > &ModelPars, boost::ptr_vector< Observable > &Observables, std::vector< Observable2D > &Observables2D, std::vector< CorrelatedGaussianObservables > &CGO, std::vector< CorrelatedGaussianParameters > &CGP)
The member that parses the Observable2D directives from SomeModel.conf file.
Definition: InputParser.cpp:35
StandardModel::Init
virtual bool Init(const std::map< std::string, double > &DPars)
A method to initialize the model parameters.
Definition: StandardModel.cpp:185
ComputeObservables::setFlags
void setFlags(std::map< std::string, std::string > DFlags_i)
This method sets the necessary flag for the requested model.
Definition: ComputeObservables.cpp:107
ComputeObservables::Mod
StandardModel * Mod
Pointer to an object of the class StandardModel.
Definition: ComputeObservables.h:131
InputParser::getModel
StandardModel * getModel() const
A get method to access the pointer to the object of the StandardModel class.
Definition: InputParser.h:109
StandardModel::setFlagStr
virtual bool setFlagStr(const std::string name, const std::string value)
A method to set a flag of StandardModel.
Definition: StandardModel.cpp:444
Model::IsModelInitialized
bool IsModelInitialized() const
A method to check if the model is initialized.
Definition: Model.h:136
ComputeObservables::rank
const int rank
< Rank of the MPI process. Set to 0 for serial run.
Definition: ComputeObservables.h:138
Model::setModelName
void setModelName(const std::string name)
A method to set the name of the model.
Definition: Model.h:50
ComputeObservables::Obs2D
std::vector< Observable2D > Obs2D
Definition: ComputeObservables.h:142
StandardModel::InitializeModel
virtual bool InitializeModel()
A method to initialize the model.
Definition: StandardModel.cpp:163
InputParser::addCustomObservableType
void addCustomObservableType(const std::string name, boost::function< Observable *() > funct)
Definition: InputParser.cpp:250
ModelFactory::CreateModel
StandardModel * CreateModel(const std::string &ModelName)
Definition: ModelFactory.cpp:96
StandardModel::Update
virtual bool Update(const std::map< std::string, double > &DPars)
The update method for StandardModel.
Definition: StandardModel.cpp:209
ComputeObservables::CGP
std::vector< CorrelatedGaussianParameters > CGP
Definition: ComputeObservables.h:144
ComputeObservables::DThObs
std::map< std::string, ThObservable * > DThObs
Definition: ComputeObservables.h:137
ComputeObservables::ModPars
std::vector< ModelParameter > ModPars
Definition: ComputeObservables.h:140
ComputeObservables::unknownParameters
std::vector< std::string > unknownParameters
Definition: ComputeObservables.h:139
InputParser::getObsFactory
const ThObsFactory & getObsFactory() const
Definition: InputParser.h:114
InputParser::getModelFactory
ModelFactory & getModelFactory() const
Definition: InputParser.h:119
ComputeObservables::myInputParser
InputParser myInputParser
An object of the InputParser class.
Definition: ComputeObservables.h:132
QCD::getUnknownParameters
std::vector< std::string > getUnknownParameters()
A method to get the vector of the parameters that have been specified in the configuration file but n...
Definition: QCD.h:467
ThObsFactory::CreateThMethod
ThObservable * CreateThMethod(const std::string &name, StandardModel &model) const
This method checks for the existence of an observable of a specific name in the map thobs and returns...
Definition: ThObsFactory.cpp:4623
ComputeObservables::paraNames
std::vector< std::string > paraNames
The vector of allowed parameter names.
Definition: ComputeObservables.h:136