Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FormFactorBase.cc
Go to the documentation of this file.
1 ///
2 /// @file FormFactorBase.cc
3 /// @brief Hammer base form factor class
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #include "Hammer/FormFactorBase.hh"
13 #include "Hammer/Math/Utils.hh"
14 #include "Hammer/Tools/Utils.hh"
15 #include "Hammer/IndexLabels.hh"
19 #include "Hammer/Math/Units.hh"
20 
21 using namespace std;
22 
23 namespace Hammer {
24 
25  namespace MD = MultiDimensional;
26 
27  FormFactorBase::FormFactorBase() :
28  _errPrefixGroup{"", ""},
29  _FFErrLabel{NONE},
30  _FFInfoList{},
31  _FFErrNames{},
32  _tensorList{},
33  _units{1.} {
34  }
35 
37  : ParticleData(other),
38  SettingsConsumer(other),
39  _errPrefixGroup(other._errPrefixGroup),
40  _FFErrLabel(other._FFErrLabel),
41  _FFInfoList{other._FFInfoList},
42  _FFErrNames(other._FFErrNames),
43  _tensorList{},
44  _units{other._units} {
45  for(auto& elem: other._tensorList) {
46  addTensor(Tensor{elem});
47  }
48  }
49 
50  // FormFactorBase& FormFactorBase::operator=(const FormFactorBase& other) {
51  // ParticleData::operator=(other);
52  // SettingsConsumer::operator=(other);
53  // _errPrefixGroup = other._errPrefixGroup;
54  // _FFErrLabel = other._FFErrLabel;
55  // _FFErrNames = other._FFErrNames;
56  // _tensorList.clear();
57  // for (auto& elem : other._tensorList) {
58  // addTensor(Tensor{elem});
59  // }
60  // return *this;
61  // }
62 
63  // FormFactorBase::~FormFactorBase() {
64  // }
65 
66  vector<double> FormFactorBase::getErrVectorFromDict(const map<std::string, double>& errDict) const {
67  vector<double> result(_FFErrNames.size() + 1);
68  result[0] = 1.;
69  for(size_t pos = 0ul; pos < _FFErrNames.size(); ++pos) {
70  auto it = errDict.find(_FFErrNames[pos]);
71  if (it != errDict.end()) {
72  result[pos+1] = it->second;
73  }
74  }
75  return result;
76  }
77 
78  vector<double> FormFactorBase::getErrVectorFromSettings(bool useDefault) const {
79  vector<double> result(_FFErrNames.size() + 1);
80  result[0] = 1.;
81  for (size_t pos = 0ul; pos < _FFErrNames.size(); ++pos) {
82  if(!useDefault) {
83  result[pos + 1] = *getSetting<double>(getFFErrPrefixGroup().get(), _FFErrNames[pos]);
84  }
85  }
86  return result;
87  }
88 
89  void FormFactorBase::updateFFErrSettings(const vector<double>& values) {
92  }
93 
94  void FormFactorBase::updateFFErrSettings(const map<std::string, double>& values) {
96  }
97 
98  void FormFactorBase::updateFFErrTensor(vector<double> values, MD::SharedTensorData& data) const {
99  ASSERT(values.size() == _FFErrNames.size()+1);
100  if (!data || data->rank() == 0) {
101  data = MD::SharedTensorData{MD::makeEmptyVector({static_cast<uint16_t>(values.size())}, {_FFInfoList[_signatureIndex].second}).release()};
102  }
103  for (IndexType i = 0; i < values.size(); ++i) {
104  data->element({i}) = values[i];
105  }
106  }
107 
108 
110  return _FFInfoList[_signatureIndex].first;
111  }
112 
113  std::pair<FFPrefixGroup, IndexLabel> FormFactorBase::getFFErrInfo() const {
115  }
116 
118  // initSettings();
119  ///@todo anything else?
120  }
121 
124  }
125 
128  }
129 
130  void FormFactorBase::setGroup(const string& name) {
131  bool reInitSettings = (_errPrefixGroup.group != name && _errPrefixGroup.group.size() > 0);
132  _errPrefixGroup.group = name;
133  for(auto& elem: _FFInfoList){
134  elem.first.group = name;
135  }
136  if(reInitSettings && getSettingsHandler() != nullptr) {
137  initSettings();
138  }
139  }
140 
141  void FormFactorBase::setPrefix(const string& name) {
142  _errPrefixGroup.prefix = name;
143  }
144 
145  const std::string& FormFactorBase::group() const {
146  return _FFInfoList[_signatureIndex].first.group;
147  }
148 
149  void FormFactorBase::setUnits(const string& name) {
150  addSetting<string>("Units", name);
151  }
152 
154  string mcunits;
155  auto mc = getSetting<string>("Hammer", "Units");
156  if (mc != nullptr){
157  mcunits = *mc;
158  } else {
159  throw Error("Hammer units not found. Mars Climate Orbiter would like a word.");
160  }
161  Units& units = Units::instance();
162  _units = units.getUnitsRescalingToMC( mcunits, *(getSetting<string>("Units")) );
163  }
164 
166  auto newdims = getTensor().dims();
167  auto newlabs = getTensor().labels();
168  auto oldsize = newdims.size();
169  newdims.reserve(2 * oldsize);
170  newlabs.reserve(2 * oldsize);
171  copy_n(newdims.begin(), oldsize, back_inserter(newdims));
172  transform_n(newlabs.begin(), oldsize, back_inserter(newlabs),
173  [](IndexLabel l) -> IndexLabel { return static_cast<IndexLabel>(-l); });
174  newlabs.push_back(INTEGRATION_INDEX);
175  newdims.push_back(static_cast<IndexType>(intPoints.size()));
176  Tensor result{"", MD::makeEmptySparse(newdims, newlabs)};
177  for (IndexType i = 0; i < intPoints.size(); ++i) {
178  evalAtPSPoint(intPoints[i]);
179  Tensor t = getTensor();
180  t.outerSquare();
181  result.addAt(t, INTEGRATION_INDEX, i);
182  }
183  return result;
184  }
185 
187  return Log::getLog("Hammer.FormFactorBase");
188  }
189 
191  _tensorList.push_back(move(tensor));
192  }
193 
194  void FormFactorBase::addProcessSignature(PdgId parent, const std::vector<PdgId>& daughters) {
195  ParticleData::addProcessSignature(parent, daughters);
196  _FFInfoList.push_back(pair<FFPrefixGroup, IndexLabel>{_errPrefixGroup, _FFErrLabel});
197  }
198 
199 } // namespace Hammer
Tensor & outerSquare()
creates a tensor with twice the rank by multiplying the tensor with its hermitean conjugate ...
Definition: Tensor.cc:162
TensorData makeEmptySparse(const IndexList &dimensions, const LabelsList &labels)
FFPrefixGroup _errPrefixGroup
Hammer base form factor class.
Base class for form factors.
Tensor & addAt(const Tensor &t, IndexLabel coord, IndexType position)
add a tensor of rank N-1 to a specific position in a specific coordinate the dimension of the tensor ...
Definition: Tensor.cc:259
std::string prefix
Definition: IndexTypes.hh:74
LabelsList labels() const
get the labels of all the indices at once
Definition: Tensor.cc:83
std::vector< std::pair< FFPrefixGroup, IndexLabel > > _FFInfoList
list of {prefix/group struct, uncertainty label} (one for each signature)
#define ASSERT(x)
Definition: Exceptions.hh:95
Non-sparse tensor data container.
Tensor indices label definitions.
std::vector< Tensor > _tensorList
list of (list of) labels for the tensor indices (one for each signature)
Log & getLog() const
logging facility
Hammer class for dealing with units.
Definition: Units.hh:38
void setUnits(const std::string &name)
set units for the FF class parameters
uint16_t IndexType
void init()
initializes the form factor (defines settings associated to this form factor, etc.)
std::pair< FFPrefixGroup, IndexLabel > getFFErrInfo() const
void updateFFErrSettings(const std::vector< double > &values)
Tensor & getTensor()
returns a reference to itself as a Tensor
Base class to access the settings repository.
std::vector< double > getErrVectorFromSettings(bool useDefault=false) const
std::shared_ptr< IContainer > SharedTensorData
static Log & getLog(const std::string &name)
Get a logger with the given name.
Definition: Logging.cc:139
Tensor getFFPSIntegrand(const EvaluationGrid &intPoints)
std::vector< double > getErrVectorFromDict(const std::map< std::string, double > &errDict) const
const std::string & group() const
_OutputIterator transform_n(_InputIterator __first, size_t __n, _OutputIterator __result, _UnaryOperation __op)
Definition: Tools/Utils.hh:69
Unit conversion factors.
Sparse tensor data container.
Order-0 tensor data container.
std::string get() const
Definition: IndexTypes.hh:76
Logging class.
Definition: Logging.hh:33
virtual void evalAtPSPoint(const std::vector< double > &point, const std::vector< double > &masses={})=0
static Units & instance()
Definition: Units.cc:30
IndexLabel
label identifiers of tensor indices they are used to determine which indices can be contracted togeth...
Definition: IndexLabels.hh:27
Multidimensional tensor class with complex numbers as elements.
Definition: Tensor.hh:33
void calcUnits()
compute unit rescaling of this class wrt MC units
Generic error class.
Definition: Exceptions.hh:23
std::vector< std::string > _FFErrNames
const FFPrefixGroup & getFFErrPrefixGroup() const
SettingsHandler * getSettingsHandler() const
provide the pointer to the repository handler
size_t _signatureIndex
the index of the current signature
void setPrefix(const std::string &name)
Sets the XtoY formal process label.
void addProcessSignature(PdgId parent, const std::vector< PdgId > &daughters)
derived from ParticleData::addProcessSignature, also populates _FFInfoList
TensorData makeEmptyVector(const IndexList &dimensions, const LabelsList &labels)
IndexList dims() const
get the dimensions of all the indices at once
Definition: Tensor.cc:79
void addProcessSignature(PdgId parent, const std::vector< PdgId > &daughters, const std::vector< PdgId > &subDaughters={})
adds a signature to the list by specifying the particles PDG codes.
Definition: ParticleData.cc:64
void addTensor(Tensor &&tensor)
adds the index labels for the form factor tensor for a specific signature to the index labels signatu...
double getUnitsRescalingToMC(std::string mcunits, std::string localunits) const
Definition: Units.cc:53
void updateVectorOfSettings(const std::vector< T > &values, const std::vector< std::string > &names, const std::string &path="", WTerm group=WTerm::COMMON)
std::vector< std::vector< double >> EvaluationGrid
Definition: Integrator.fhh:26
int PdgId
Definition: Pdg.fhh:17
void updateFFErrTensor(std::vector< double > values, MultiDimensional::SharedTensorData &data) const
void setGroup(const std::string &name)
Sets the FF parametrization scheme label.
PDG code process signature class.
Definition: ParticleData.hh:33