gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
subspectrum_contents.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
18 
22 
23 namespace Gambit
24 {
26  void SubSpectrumContents::addParameter(const Par::Tags tag, const std::string& name, const std::vector<int>& shape,
27  const std::string& blockname, const int blockindex)
28  {
29  parameters.emplace_back(tag,name,shape,blockname,blockindex);
30  }
31 
33  void SubSpectrumContents::setName(const std::string& name)
34  {
35  my_name = name;
36  }
37 
39  std::vector<SpectrumParameter> SubSpectrumContents::all_parameters() const
40  {
41  return parameters;
42  }
43 
45  std::vector<SpectrumParameter> SubSpectrumContents::all_parameters_with_tag(Par::Tags tag) const
46  {
47  std::vector<SpectrumParameter> search_result;
48  for( std::vector<SpectrumParameter>::const_iterator it=parameters.begin(); it!=parameters.end(); ++it )
49  {
50  if(it->tag() == tag) search_result.push_back(*it);
51  }
52  return search_result;
53  }
54 
56  std::vector<SpectrumParameter> SubSpectrumContents::all_parameters_with_tag_and_shape(Par::Tags tag, std::vector<int>& shape) const
57  {
58  std::vector<SpectrumParameter> search_result;
59  for( std::vector<SpectrumParameter>::const_iterator it=parameters.begin(); it!=parameters.end(); ++it )
60  {
61  if(it->tag() == tag and it->shape() == shape) search_result.push_back(*it);
62  }
63  return search_result;
64  }
65 
67  std::vector<SpectrumParameter> SubSpectrumContents::all_BSM_parameters() const
68  {
69  std::vector<SpectrumParameter> search_result;
70  for ( std::vector<SpectrumParameter>::const_iterator it=parameters.begin(); it!=parameters.end(); ++it)
71  {
72  if(it->blockname() != "SMINPUTS" || it->blockname() != "YUKAWA" || it->blockname() != "CKMBLOCK" || it->blockname() != "")
73  {
74  search_result.push_back(*it);
75  }
76  }
77  return search_result;
78  }
79 
80 
83  {
84  const std::vector<SpectrumParameter> required_parameters = all_parameters();
85 
86  for(std::vector<SpectrumParameter>::const_iterator it = required_parameters.begin();
87  it != required_parameters.end(); ++it)
88  {
89  const Par::Tags tag = it->tag();
90  const std::string name = it->name();
91  const std::vector<int> shape = it->shape();
92 
93  // Deal with empty shape case
94  if(shape.size()==0)
95  {
96  // ERROR, please use length 1 vector for scalar case
97  std::ostringstream errmsg;
98  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
99  errmsg << "Encountered a required parameter ("<<Par::toString.at(tag)<<", "<<name<<") with shape.size()==0. This is not allowed; if you want this parameter to be considered a scalar, please set the shape to '1', i.e. std::vector<int> shape = initVector(1). Please fix this parameter in the SubSpectrumContents class." << std::endl;
100  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
101  }
102  // Check scalar case
103  else if(shape.size()==1 and shape[0]==1)
104  {
105  if(not spec.has(tag,name))
106  {
107  // ERROR, Required parameter not found
108  std::ostringstream errmsg;
109  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
110  errmsg << "Required scalar-valued parameter ("<<Par::toString.at(tag)<<", "<<name<<") is not accessible via subspectrum->get(Par::"<<Par::toString.at(tag)<<", \""<<name<<"\"). Please fix the relevant SubSpectrum wrapper class so that this parameter can be accessed." << std::endl;
111  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
112  }
113  }
114  // Check vector case
115  else if(shape.size()==1 and shape[0]>1)
116  {
117  if(shape[0]<0)
118  {
119  // ERROR, asked for negative length vector
120  std::ostringstream errmsg;
121  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
122  errmsg << "Encountered a vector-valued required parameter ("<<Par::toString.at(tag)<<", "<<name<<") with negative required length ("<<shape[0]<<")! This is invalid; Please fix this parameter in the SubSpectrumContents class so that the required length is a positive number." << std::endl;
123  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
124  }
125  else
126  {
127  for(int i = 1; i<=shape[0]; ++i) {
128  if(not spec.has(tag,name,i))
129  {
130  // ERROR, Required parameter not found
131  std::ostringstream errmsg;
132  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
133  errmsg << "An entry of the required vector-valued parameter ("<<Par::toString.at(tag)<<", "<<name<<") with required length "<<shape[0]<<" is not accessible via subspectrum->get(Par::"<<Par::toString.at(tag)<<", \""<<name<<"\", "<<i<<"). Please fix the relevant SubSpectrum wrapper class so that this parameter can be accessed. Keep in mind that you may need to override index_offset() to align the expected indices." << std::endl;
134  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
135  }
136  }
137  }
138  }
139  // Check matrix case
140  else if(shape.size()==2)
141  {
142  if(shape[0]<0 or shape[1]<0)
143  {
144  // ERROR, asked for negative matrix dimensions
145  std::ostringstream errmsg;
146  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
147  errmsg << "Encountered a matrix-valued required parameter ("<<Par::toString.at(tag)<<", "<<name<<") with at least one negative required dimension (dims = ["<<shape[0]<<", "<<shape[1]<<"])! This is invalid; Please fix the shape settings for this parameter in the SubSpectrumContents so that they are positive numbers." << std::endl;
148  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
149  }
150  else
151  {
152  for(int i = 1; i<=shape[0]; ++i) {
153  for(int j = 1; j<=shape[0]; ++j) {
154  if(not spec.has(tag,name,i,j))
155  {
156  // ERROR, Required parameter not found
157  std::ostringstream errmsg;
158  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
159  errmsg << "An entry of the required matrix-valued parameter ("<<Par::toString.at(tag)<<", "<<name<<") with required dimensions ("<<shape[0]<<", "<<shape[1]<<") is not accessible via subspectrum->get(Par::"<<Par::toString.at(tag)<<", \""<<name<<"\", "<<i<<", "<<j<<"). Please fix the relevant SubSpectrum wrapper class so that this parameter can be accessed. Keep in mind that you may need to override index_offset() to align the expected indices." << std::endl;
160  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
161  }
162  }
163  }
164  }
165  }
166  // Deal with all other cases
167  else
168  {
169  // ERROR invalid shape
170  std::ostringstream errmsg;
171  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
172  errmsg << "The specified shape for the required parameter ("<<Par::toString.at(tag)<<", "<<name<<") is invalid. The length of the shape vector is only permitted to be 1 or 2 (received shape vector was "<<shape<<"). Please fix this parameter entry in the SubSpectrumContents class."<<std::endl;
173  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
174  }
175  }
176  // End constructor
177  }
179 
180 }
181 
Define overloadings of the stream operator for various containers.
EXPORT_SYMBOLS error & utils_error()
Utility errors.
void addParameter(const Par::Tags tag, const std::string &name, const std::vector< int > &shape=initVector(1), const std::string &blockname="", const int index=0)
Add a parameter to the Contents object.
#define LOCAL_INFO
Definition: local_info.hpp:34
void setName(const std::string &name)
Set the name of this Contents object (i.e. the name of the model to which this spectrum data applies)...
std::string my_name
Name of SubSpectrumContents class (for more helpful error messages)
void verify_contents(const SubSpectrum &spec) const
Function to verify that a SubSpectrum wrapper contains everything that this class says it should...
std::vector< SpectrumParameter > all_BSM_parameters() const
Function to retrieve all parameters whose blockName is not SMINPUTS, YUKAWA, CKMBLOCK, or empty.
std::vector< SpectrumParameter > parameters
Vector defining what parameters a wrapper must contain.
std::vector< SpectrumParameter > all_parameters_with_tag(Par::Tags tag) const
Function to retreive all parameters matching a certain tag.
Abstract class for accessing general spectrum information.
Base class for definining the required contents of SubSpectrum wrapper objects.
Virtual base class for interacting with spectrum generator output.
Definition: subspectrum.hpp:87
std::vector< SpectrumParameter > all_parameters_with_tag_and_shape(Par::Tags tag, std::vector< int > &shape) const
Function to retrieve all parameters matching a certain tag and shape.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
virtual bool has(const Par::Tags, const str &, const SpecOverrideOptions=use_overrides, const SafeBool check_antiparticle=SafeBool(true)) const =0
Getters/Setters etc.
std::vector< SpectrumParameter > all_parameters() const
Function to retreive all parameters.