ComputeObservables Class Reference

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

#include <ComputeObservables.h>

Collaboration diagram for ComputeObservables:
[legend]

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.

Definition at line 35 of file ComputeObservables.h.

Public Member Functions

void addCustomObservableType (const std::string name, boost::function< Observable *() > funct)
 
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, const int rank_i=0)
 Constructor. 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::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...
 
InputParser myInputParser
 An object of the InputParser class. More...
 
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...
 

Constructor & Destructor Documentation

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  std::vector<ModelParameter> ModPars;
20  boost::ptr_vector<Observable> Obs;
21  std::vector<Observable2D> Obs2D;
22  std::vector<CorrelatedGaussianObservables> CGO;
23  std::vector<CorrelatedGaussianParameters> CGP;
24 
25  std::string ModelName = myInputParser.ReadParameters(ModelConf_i, rank, ModPars, Obs, Obs2D, CGO, CGP);
26  std::map<std::string, double> DP;
27  for (std::vector<ModelParameter>::iterator it = ModPars.begin(); it < ModPars.end(); it++) {
28  DP[it->getname()] = it->getave();
29  paraNames.push_back(it->getname());
30  }
31  DPars = DP;
32 
33  for (boost::ptr_vector<Observable>::iterator it = Obs.begin(); it < Obs.end(); it++) {
34  DObs.insert(std::pair<std::string, double> (it->getThname() , 0.));
35  DThObs.insert(std::pair<std::string, ThObservable*> (it->getThname() , it->getTho()));
36  }
37  for (std::vector<CorrelatedGaussianObservables>::iterator it1 = CGO.begin(); it1 < CGO.end(); it1++) {
38  std::vector<Observable> ObsInCGO = it1->getObs();
39  for (std::vector<Observable>::iterator it2 = ObsInCGO.begin(); it2 < ObsInCGO.end(); it2++) {
40  DObs.insert(std::pair<std::string, double> (it2->getThname() , 0.));
41  DThObs.insert(std::pair<std::string, ThObservable*> (it2->getThname() , it2->getTho()));
42  }
43  }
44 
46  if (!Mod->Init(DP))
47  throw std::runtime_error("ERROR: Parameter(s) missing in model initialization.\n");
48 }
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:28
InputParser myInputParser
An object of the InputParser class.
std::string ModelName
Name of the Model to be used.
std::map< std::string, double > DObs
Map of the observables to be computed.
std::map< std::string, double > DPars
Map of the parameters to be passed to Model.
virtual bool Init(const std::map< std::string, double > &DPars)
A method to initialize the model parameters.
std::map< std::string, ThObservable * > DThObs
StandardModel * Mod
Pointer to an object of the class StandardModel.
std::vector< std::string > paraNames
The vector of allowed parameter names.
const int rank
< Rank of the MPI process. Set to 0 for serial run.
StandardModel * getModel() const
A get method to access the pointer to the object of the StandardModel class.
Definition: InputParser.h:110
ComputeObservables::ComputeObservables ( ModelFactory ModelF,
ThObsFactory ThObsF,
const std::string &  ModelName_i,
std::map< std::string, double >  DPars_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 50 of file ComputeObservables.cpp.

52 : ModelName(ModelName_i),
53  myInputParser(ModelF, ThObsF),
54  rank(rank_i)
55 {
56  for (std::map<std::string, double>::iterator it = DPars_i.begin(); it != DPars_i.end(); it++) {
57  paraNames.push_back(it->first);
58  }
62  if (Mod->IsModelInitialized()) {
63  if (rank == 0) std::cout << "\nModel Initialized: " << ModelName << std::endl;
64  } else {
65  throw std::runtime_error("\nERROR: " + ModelName + " not initialized successfully.\n");
66  }
67  if (!Mod->Init(DPars_i))
68  throw std::runtime_error("\nERROR: Model cannot be initialized initialization.\n");
69 }
InputParser myInputParser
An object of the InputParser class.
StandardModel * CreateModel(const std::string &ModelName)
std::string ModelName
Name of the Model to be used.
ModelFactory & getModelFactory() const
Definition: InputParser.h:120
virtual bool InitializeModel()
A method to initialize the model.
bool IsModelInitialized() const
A method to check if the model is initialized.
Definition: Model.h:133
virtual bool Init(const std::map< std::string, double > &DPars)
A method to initialize the model parameters.
void setModelName(const std::string name)
A method to set the name of the model.
Definition: Model.h:47
StandardModel * Mod
Pointer to an object of the class StandardModel.
std::vector< std::string > paraNames
The vector of allowed parameter names.
const int rank
< Rank of the MPI process. Set to 0 for serial run.
ComputeObservables::~ComputeObservables ( )
virtual

The default destructor.

Definition at line 71 of file ComputeObservables.cpp.

72 {
73 }

Member Function Documentation

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

Definition at line 121 of file ComputeObservables.cpp.

121  {
123 }
InputParser myInputParser
An object of the InputParser class.
void addCustomObservableType(const std::string name, boost::function< Observable *() > funct)
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

Definition at line 115 of file ComputeObservables.cpp.

116 {
117  DThObs[ObsName] = myInputParser.getObsFactory().CreateThMethod(ObsName, *Mod);
118  DObs.insert(std::pair<std::string, double> (ObsName , 0.));
119 }
InputParser myInputParser
An object of the InputParser class.
const ThObsFactory & getObsFactory() const
Definition: InputParser.h:115
std::map< std::string, double > DObs
Map of the observables to be computed.
ThObservable * CreateThMethod(const std::string &name, const StandardModel &model) const
This method checks for the existence of an observable of a specific name in the map thobs and returns...
std::map< std::string, ThObservable * > DThObs
StandardModel * Mod
Pointer to an object of the class StandardModel.
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

Definition at line 90 of file ComputeObservables.cpp.

91 {
92  if (DP != DPars)
93  for (std::map<std::string, double>::iterator it = DP.begin(); it != DP.end(); it++) {
94  if(!(std::find(paraNames.begin(), paraNames.end(), it->first) != paraNames.end()))
95  throw std::runtime_error("\nERROR: Incorrect parameter name passed to ComputeObservable");
96  }
97  DPars = DP;
98  Mod->Update(DPars);
99  for (std::map<std::string, double>::iterator it = DObs.begin(); it != DObs.end(); it++) {
100  DObs[it->first] = DThObs[it->first]->computeThValue();
101  }
102  return(DObs);
103 }
virtual bool Update(const std::map< std::string, double > &DPars)
The update method for StandardModel.
std::map< std::string, double > DObs
Map of the observables to be computed.
std::map< std::string, double > DPars
Map of the parameters to be passed to Model.
std::map< std::string, ThObservable * > DThObs
StandardModel * Mod
Pointer to an object of the class StandardModel.
std::vector< std::string > paraNames
The vector of allowed parameter names.
std::map<std::string, double> ComputeObservables::getObservables ( )
inline

A method to get the map of observables.

Returns
the map of observables

Definition at line 99 of file ComputeObservables.h.

100  {
101  return (DObs);
102  };
std::map< std::string, double > DObs
Map of the observables to be computed.
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  };
std::map< std::string, double > DPars
Map of the parameters to be passed to Model.
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 105 of file ComputeObservables.cpp.

106 {
107  if(DObs.find(ObsName) == DObs.end())
108  throw std::runtime_error("\nERROR: Observable cannot be removed since it has not been added.\n");
109  DObs.erase(ObsName);
110  if(DThObs.find(ObsName) == DThObs.end())
111  throw std::runtime_error("\nERROR: ThObservable cannot be removed since it has not been added.\n");
112  DThObs.erase(ObsName);
113 }
std::map< std::string, double > DObs
Map of the observables to be computed.
std::map< std::string, ThObservable * > DThObs
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

Definition at line 75 of file ComputeObservables.cpp.

76 {
77  for (std::map<std::string, std::string>::iterator it = DFlags_i.begin(); it != DFlags_i.end(); it++) {
78  if (!(boost::iequals(it->second, "true")) && !(boost::iequals(it->second, "false")) && !Mod->setFlagStr(it->first, it->second)) {
79  throw std::runtime_error("ERROR: setFlagStr error for " + it->first);
80  } else if (boost::iequals(it->second, "true") && !Mod->setFlag(it->first, 1)) {
81  throw std::runtime_error("ERROR: setFlag error for " + it->first);
82  } else if (boost::iequals(it->second, "false") && !Mod->setFlag(it->first, 0)) {
83  throw std::runtime_error("ERROR: setFlag error for " + it->first);
84  } else {
85  if (rank == 0) std::cout << "set flag " << it->first << " = " << it->second << std::endl;
86  }
87  }
88 }
virtual bool setFlagStr(const std::string name, const std::string value)
A method to set a flag of StandardModel.
StandardModel * Mod
Pointer to an object of the class StandardModel.
const int rank
< Rank of the MPI process. Set to 0 for serial run.
virtual bool setFlag(const std::string name, const bool value)
A method to set a flag of StandardModel.

Member Data Documentation

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

Map of the model flags to be passed to Model.

Definition at line 122 of file ComputeObservables.h.

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

Map of the observables to be computed.

Definition at line 121 of file ComputeObservables.h.

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

Map of the parameters to be passed to Model.

Definition at line 120 of file ComputeObservables.h.

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

Definition at line 124 of file ComputeObservables.h.

StandardModel* ComputeObservables::Mod
private

Pointer to an object of the class StandardModel.

Definition at line 118 of file ComputeObservables.h.

std::string ComputeObservables::ModelName
private

Name of the Model to be used.

Definition at line 117 of file ComputeObservables.h.

InputParser ComputeObservables::myInputParser
private

An object of the InputParser class.

Definition at line 119 of file ComputeObservables.h.

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

The vector of allowed parameter names.

Definition at line 123 of file ComputeObservables.h.

const int ComputeObservables::rank
private

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

Definition at line 125 of file ComputeObservables.h.


The documentation for this class was generated from the following files: