ComPWA
Common Partial-Wave-Analysis Framework
Voigtian.cpp
Go to the documentation of this file.
1 // Copyright (c) 2013, 2017 The ComPWA Team.
2 // This file is part of the ComPWA framework, check
3 // https://github.com/ComPWA/ComPWA/license.txt for details.
4 
5 #include "Voigtian.hpp"
6 
7 namespace ComPWA {
8 namespace Physics {
9 namespace Dynamics {
10 
16 
17 std::shared_ptr<ComPWA::FunctionTree::TreeNode> Voigtian::createFunctionTree(
18  InputInfo Params,
19  std::shared_ptr<ComPWA::FunctionTree::Value<std::vector<double>>>
20  InvMassSquared) {
21  size_t sampleSize = InvMassSquared->values().size();
22 
23  auto tr = std::make_shared<ComPWA::FunctionTree::TreeNode>(
24  ComPWA::FunctionTree::MComplex("", sampleSize),
25  std::make_shared<VoigtianStrategy>());
26 
27  tr->addNodes({FunctionTree::createLeaf(Params.Mass),
29  FunctionTree::createLeaf(Params.Sigma, "Sigma"),
30  FunctionTree::createLeaf(InvMassSquared)});
31 
32  return tr;
33 };
34 
36  std::shared_ptr<Parameter> &out) {
37  if (out && checkType != out->type())
38  throw BadParameter("VoigtianStrat::execute() | Parameter type mismatch!");
39 
40 #ifndef NDEBUG
41  // Check parameter type
42  if (checkType != out->type())
43  throw(
44  WrongParType("VoigtianStrat::execute() | "
45  "Output parameter is of type " +
46  std::string(ComPWA::FunctionTree::ParNames[out->type()]) +
47  " and conflicts with expected type " +
49 
50  // How many parameters do we expect?
51  size_t check_nInt = 0;
52  size_t nInt = paras.intValues().size();
53  size_t check_nDouble = 3;
54  size_t nDouble = paras.doubleValues().size();
55  nDouble += paras.doubleParameters().size();
56  size_t check_nComplex = 0;
57  size_t nComplex = paras.complexValues().size();
58  size_t check_nMInteger = 0;
59  size_t nMInteger = paras.mIntValues().size();
60  size_t check_nMDouble = 1;
61  size_t nMDouble = paras.mDoubleValues().size();
62  size_t check_nMComplex = 0;
63  size_t nMComplex = paras.mComplexValues().size();
64 
65  // Check size of parameter list
66  if (nInt != check_nInt)
67  throw(BadParameter("VoigtianStrat::execute() | "
68  "Number of IntParameters does not match: " +
69  std::to_string(nInt) + " given but " +
70  std::to_string(check_nInt) + " expected."));
71  // I do not want to set sigma as fit parameter. I would like to set it as
72  // fixed parameter/argument
73  if (nDouble != check_nDouble)
74  throw(BadParameter("VoigtianStrat::execute() | "
75  "Number of FitParameters does not match: " +
76  std::to_string(nDouble) + " given but " +
77  std::to_string(check_nDouble) + " expected."));
78  if (nComplex != check_nComplex)
79  throw(BadParameter("VoigtianStrat::execute() | "
80  "Number of ComplexParameters does not match: " +
81  std::to_string(nComplex) + " given but " +
82  std::to_string(check_nComplex) + " expected."));
83  if (nMInteger != check_nMInteger)
84  throw(BadParameter("VoigtianStrat::execute() | "
85  "Number of MultiInt does not match: " +
86  std::to_string(nMInteger) + " given but " +
87  std::to_string(check_nMInteger) + " expected."));
88  if (nMDouble != check_nMDouble)
89  throw(BadParameter("VoigtianStrat::execute() | "
90  "Number of MultiDoubles does not match: " +
91  std::to_string(nMDouble) + " given but " +
92  std::to_string(check_nMDouble) + " expected."));
93  if (nMComplex != check_nMComplex)
94  throw(BadParameter("VoigtianStrat::execute() | "
95  "Number of MultiComplexes does not match: " +
96  std::to_string(nMComplex) + " given but " +
97  std::to_string(check_nMComplex) + " expected."));
98 #endif
99 
100  size_t n = paras.mDoubleValue(0)->values().size();
101  if (!out)
102  out = ComPWA::FunctionTree::MComplex("", n);
103  auto par =
104  std::static_pointer_cast<Value<std::vector<std::complex<double>>>>(out);
105  auto &results = par->values(); // reference
106  if (results.size() != n) {
107  results.resize(n);
108  }
109  // Get parameters from ParameterList:
110  // We use the same order of the parameters as was used during tree
111  // construction.
112  double m0 = paras.doubleParameter(0)->value();
113  double Gamma0 = paras.doubleParameter(1)->value();
114  double sigma = paras.doubleValue(0)->value();
115 
116  // calc function for each point
117  for (unsigned int ele = 0; ele < n; ele++) {
118  try {
119  results.at(ele) = Voigtian::dynamicalFunction(
120  paras.mDoubleValue(0)->values().at(ele), m0, Gamma0, sigma);
121  } catch (std::exception &ex) {
122  LOG(ERROR) << "VoigtianStrategy::execute() | " << ex.what();
123  throw(std::runtime_error("VoigtianStrategy::execute() | "
124  "Evaluation of dynamic function failed!"));
125  }
126  }
127 }
128 
129 } // namespace Dynamics
130 } // namespace Physics
131 } // namespace ComPWA
Parameter not existing.
Definition: Exceptions.hpp:62
This file contains the declaration of the Voigtian class, which is used the implementation of voigt f...
double Sigma
resolution: the width of gaussian function which is used to represent the resolution of mass spectrum...
Definition: Voigtian.hpp:44
Base class for internal parameter.
Definition: Parameter.hpp:79
virtual std::vector< std::shared_ptr< Value< std::vector< int > > > > & mIntValues()
std::shared_ptr< ComPWA::FunctionTree::TreeNode > createFunctionTree(InputInfo Params, std::shared_ptr< ComPWA::FunctionTree::Value< std::vector< double >>> InvMassSquared)
Definition: Voigtian.cpp:17
TreeNode is the basic building block of the FunctionTree.
Definition: TreeNode.hpp:35
std::shared_ptr< ComPWA::FunctionTree::FitParameter > Width
Decay width of resonant state.
virtual std::vector< std::shared_ptr< Value< std::vector< double > > > > & mDoubleValues()
static const char *const ParNames[7]
Names of the parameter types, should be extended if an new parameter type is added.
Definition: Parameter.hpp:46
std::shared_ptr< TreeNode > createLeaf(std::shared_ptr< Parameter > parameter)
Definition: TreeNode.cpp:156
virtual std::vector< std::shared_ptr< Value< std::complex< double > > > > & complexValues()
std::shared_ptr< Value< std::vector< std::complex< double > > > > MComplex(std::string name, size_t s, std::complex< double > el=std::complex< double >(0., 0.))
Definition: Value.hpp:120
virtual std::shared_ptr< FitParameter > doubleParameter(size_t i) const
virtual std::vector< std::shared_ptr< Value< std::vector< std::complex< double > > > > > & mComplexValues()
virtual std::vector< std::shared_ptr< Value< double > > > & doubleValues()
virtual void execute(ComPWA::FunctionTree::ParameterList &paras, std::shared_ptr< ComPWA::FunctionTree::Parameter > &out)
Definition: Voigtian.cpp:35
virtual std::vector< std::shared_ptr< FitParameter > > & doubleParameters()
virtual std::vector< std::shared_ptr< Value< int > > > & intValues()
std::shared_ptr< ComPWA::FunctionTree::FitParameter > Mass
Resonance mass.
std::complex< double > dynamicalFunction(double mSq, double mR, double wR, double sigma)
Dynamical voigt function.
Definition: Voigtian.hpp:53
virtual T & values()
Reference on the value.
Definition: Value.hpp:49
This class provides a list of parameters and values of different types.
Parameter of wrong type.
Definition: Exceptions.hpp:111
virtual std::shared_ptr< Value< std::vector< double > > > mDoubleValue(size_t i) const
virtual std::shared_ptr< Value< double > > doubleValue(size_t i) const