ComPWA
Common Partial-Wave-Analysis Framework
FormFactor.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 "FormFactor.hpp"
6 
7 namespace ComPWA {
8 namespace Physics {
9 namespace Dynamics {
10 
16 
17 std::shared_ptr<ComPWA::FunctionTree::TreeNode> createFunctionTree(
18  std::shared_ptr<ComPWA::FunctionTree::Value<std::vector<double>>>
19  InvMassSquaredDaughter1,
20  std::shared_ptr<ComPWA::FunctionTree::Value<std::vector<double>>>
21  InvMassSquaredDaughter2,
22  std::shared_ptr<ComPWA::FunctionTree::FitParameter> MesonRadius,
23  unsigned int L, std::shared_ptr<FormFactor> FormFactorFunctor,
24  std::shared_ptr<ComPWA::FunctionTree::Value<std::vector<double>>>
25  InvMassSquared) {
26  size_t sampleSize = InvMassSquared->values().size();
27 
28  auto ffTree = std::make_shared<TreeNode>(
29  ComPWA::FunctionTree::MDouble("", sampleSize),
30  std::make_shared<FormFactorStrategy>(FormFactorFunctor));
31  // add L and FFType as double value leaf, since there is no int leaf
32  ffTree->addNodes({FunctionTree::createLeaf((int)L, "L"),
33  FunctionTree::createLeaf(MesonRadius),
34  FunctionTree::createLeaf(InvMassSquared),
35  FunctionTree::createLeaf(InvMassSquaredDaughter1),
36  FunctionTree::createLeaf(InvMassSquaredDaughter2)});
37  ffTree->parameter();
38 
39  return ffTree;
40 }
41 
43  std::shared_ptr<Parameter> &out) {
44  if (out && checkType != out->type())
45  throw BadParameter("FormFactorStrat::execute() | Parameter type mismatch!");
46 
47 #ifndef NDEBUG
48  // Check parameter type
49  if (checkType != out->type())
50  throw(
51  WrongParType("FormFactorStrat::execute() | "
52  "Output parameter is of type " +
53  std::string(ComPWA::FunctionTree::ParNames[out->type()]) +
54  " and conflicts with expected type " +
56 
57  // How many parameters do we expect?
58  size_t check_nInt = 1;
59  size_t nInt = paras.intValues().size();
60  // MesonRadius, Daughter1Mass, Daughter2Mass
61  size_t check_nDouble = 1;
62  size_t nDouble = paras.doubleValues().size();
63  nDouble += paras.doubleParameters().size();
64  size_t check_nComplex = 0;
65  size_t nComplex = paras.complexValues().size();
66  size_t check_nMInteger = 0;
67  size_t nMInteger = paras.mIntValues().size();
68  // DataSample.mDoubleValue(pos) (mSq)
69  size_t check_nMDouble = 3;
70  size_t nMDouble = paras.mDoubleValues().size();
71  size_t check_nMComplex = 0;
72  size_t nMComplex = paras.mComplexValues().size();
73 
74  // Check size of parameter list
75  if (nInt != check_nInt)
76  throw(BadParameter("FormFactorStrat::execute() | "
77  "Number of IntParameters does not match: " +
78  std::to_string(nInt) + " given but " +
79  std::to_string(check_nInt) + " expected."));
80  if (nDouble != check_nDouble)
81  throw(BadParameter("FormFactorStrat::execute() | "
82  "Number of FitParameters does not match: " +
83  std::to_string(nDouble) + " given but " +
84  std::to_string(check_nDouble) + " expected."));
85  if (nComplex != check_nComplex)
86  throw(BadParameter("FormFactorStrat::execute() | "
87  "Number of ComplexParameters does not match: " +
88  std::to_string(nComplex) + " given but " +
89  std::to_string(check_nComplex) + " expected."));
90  if (nMInteger != check_nMInteger)
91  throw(BadParameter("FormFactorStrat::execute() | "
92  "Number of MultiInt does not match: " +
93  std::to_string(nMInteger) + " given but " +
94  std::to_string(check_nMInteger) + " expected."));
95  if (nMDouble != check_nMDouble)
96  throw(BadParameter("FormFactorStrat::execute() | "
97  "Number of MultiDoubles does not match: " +
98  std::to_string(nMDouble) + " given but " +
99  std::to_string(check_nMDouble) + " expected."));
100  if (nMComplex != check_nMComplex)
101  throw(BadParameter("FormFactorStrat::execute() | "
102  "Number of MultiComplexes does not match: " +
103  std::to_string(nMComplex) + " given but " +
104  std::to_string(check_nMComplex) + " expected."));
105 #endif
106 
107  size_t n = paras.mDoubleValue(0)->values().size();
108  if (!out)
109  out = ComPWA::FunctionTree::MDouble("", n);
110  auto par = std::static_pointer_cast<Value<std::vector<double>>>(out);
111  auto &results = par->values(); // reference
112  if (results.size() != n) {
113  results.resize(n);
114  }
115 
116  // Get parameters from ParameterList:
117  // We use the same order of the parameters as was used during tree
118  // construction.
119  unsigned int L = paras.intValue(0)->value();
120  double MesonRadius = paras.doubleParameter(0)->value();
121  auto s = paras.mDoubleValue(0)->values();
122  auto sa = paras.mDoubleValue(1)->values();
123  auto sb = paras.mDoubleValue(2)->values();
124 
125  if (sa.size() == 1 && sb.size() == 1) {
126  double ma = std::sqrt(sa.at(0));
127  double mb = std::sqrt(sb.at(0));
128  std::transform(paras.mDoubleValue(0)->values().begin(),
129  paras.mDoubleValue(0)->values().end(), results.begin(),
130  [&](double s) {
131  return FormFactorFunctor->operator()(qSquared(s, ma, mb),
132  L, MesonRadius);
133  });
134  } else if (sa.size() == 1) {
135  double ma = std::sqrt(sa.at(0));
136  for (size_t i = 0; i < s.size(); ++i) {
137  results[i] = FormFactorFunctor->operator()(
138  qSquared(s[i], ma, std::sqrt(sb[i])), L, MesonRadius);
139  }
140  } else if (sb.size() == 1) {
141  double mb = std::sqrt(sb.at(0));
142  for (size_t i = 0; i < s.size(); ++i) {
143  results[i] = FormFactorFunctor->operator()(
144  qSquared(s[i], std::sqrt(sa[i]), mb), L, MesonRadius);
145  }
146  } else {
147  for (size_t i = 0; i < s.size(); ++i) {
148  results[i] = FormFactorFunctor->operator()(
149  qSquared(s[i], std::sqrt(sa[i]), std::sqrt(sb[i])), L, MesonRadius);
150  }
151  }
152 }
153 
154 } // namespace Dynamics
155 } // namespace Physics
156 } // namespace ComPWA
virtual std::shared_ptr< Value< int > > intValue(size_t i)
Parameter not existing.
Definition: Exceptions.hpp:62
double qSquared(double S, double sqrtSA, double sqrtSB)
Calculate Break-up momentum squared.
Definition: FormFactor.hpp:24
virtual void execute(ComPWA::FunctionTree::ParameterList &paras, std::shared_ptr< ComPWA::FunctionTree::Parameter > &out)
Definition: FormFactor.cpp:42
Base class for internal parameter.
Definition: Parameter.hpp:79
std::shared_ptr< Value< std::vector< double > > > MDouble(std::string name, size_t s, double el=0.)
Definition: Value.hpp:134
virtual std::vector< std::shared_ptr< Value< std::vector< int > > > > & mIntValues()
TreeNode is the basic building block of the FunctionTree.
Definition: TreeNode.hpp:35
virtual std::vector< std::shared_ptr< Value< std::vector< double > > > > & mDoubleValues()
std::shared_ptr< FormFactor > FormFactorFunctor
Definition: FormFactor.hpp:192
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< ComPWA::FunctionTree::TreeNode > createFunctionTree(std::shared_ptr< ComPWA::FunctionTree::Value< std::vector< double >>> InvMassSquaredDaughter1, std::shared_ptr< ComPWA::FunctionTree::Value< std::vector< double >>> InvMassSquaredDaughter2, std::shared_ptr< ComPWA::FunctionTree::FitParameter > MesonRadius, unsigned int L, std::shared_ptr< FormFactor > FormFactorFunctor, std::shared_ptr< ComPWA::FunctionTree::Value< std::vector< double >>> InvMassSquared)
Definition: FormFactor.cpp:17
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 std::vector< std::shared_ptr< FitParameter > > & doubleParameters()
virtual std::vector< std::shared_ptr< Value< int > > > & intValues()
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