ComPWA
Common Partial-Wave-Analysis Framework
Flatte.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 "Flatte.hpp"
6 
7 namespace ComPWA {
8 namespace Physics {
9 namespace Dynamics {
10 
16 
17 std::shared_ptr<TreeNode> Flatte::createFunctionTree(
18  InputInfo Params,
19  std::shared_ptr<ComPWA::FunctionTree::Value<std::vector<double>>>
20  InvMassSquared) {
21  if (Params.HiddenCouplings.size() == 1)
22  Params.HiddenCouplings.push_back(Coupling(0.0, 0.0, 0.0));
23 
24  if (Params.HiddenCouplings.size() != 2)
25  throw std::runtime_error(
26  "Flatte::createFunctionTree() | Vector with "
27  "couplings has a wrong size. We expect either 2 or 3 couplings.");
28 
29  if (!Params.G)
30  throw std::runtime_error(
31  "Flatte::createFunctionTree() | Coupling to signal channel not set");
32 
33  size_t sampleSize = InvMassSquared->values().size();
34 
35  using namespace ComPWA::FunctionTree;
36  auto tr = std::make_shared<TreeNode>(
37  MComplex("", sampleSize),
38  std::make_shared<FlatteStrategy>(Params.FormFactorFunctor));
39 
40  tr->addNodes({createLeaf(Params.Mass), createLeaf(Params.G)});
41  for (unsigned int i = 0; i < Params.HiddenCouplings.size(); ++i) {
42  tr->addNodes({createLeaf(Params.HiddenCouplings.at(i).MassA),
43  createLeaf(Params.HiddenCouplings.at(i).MassB),
44  createLeaf(Params.HiddenCouplings.at(i).G)});
45  }
46  tr->addNodes({createLeaf((double)Params.L, "L"),
47  createLeaf(Params.MesonRadius), createLeaf(InvMassSquared),
48  createLeaf(Params.DaughterInvariantMasses.first),
49  createLeaf(Params.DaughterInvariantMasses.second)});
50 
51  return tr;
52 }
53 
55  std::shared_ptr<Parameter> &out) {
56  if (out && checkType != out->type())
57  throw BadParameter("FlatteStrategy::execute() | Parameter type mismatch!");
58 
59 #ifndef NDEBUG
60  // Check parameter type
61  if (checkType != out->type())
62  throw(
63  WrongParType("FlatteStrategy::execute() | "
64  "Output parameter is of type " +
65  std::string(ComPWA::FunctionTree::ParNames[out->type()]) +
66  " and conflicts with expected type " +
67  std::string(ComPWA::FunctionTree::ParNames[checkType])));
68 
69  // How many parameters do we expect?
70  size_t check_nInt = 0;
71  size_t nInt = paras.intValues().size();
72  size_t check_nDouble = 10;
73  size_t nDouble = paras.doubleValues().size();
74  nDouble += paras.doubleParameters().size();
75  size_t check_nComplex = 0;
76  size_t nComplex = paras.complexValues().size();
77  size_t check_nMInteger = 0;
78  size_t nMInteger = paras.mIntValues().size();
79  size_t check_nMDouble = 3;
80  size_t nMDouble = paras.mDoubleValues().size();
81  size_t check_nMComplex = 0;
82  size_t nMComplex = paras.mComplexValues().size();
83 
84  // Check size of parameter list
85  if (nInt != check_nInt)
86  throw(BadParameter("FlatteStrategy::execute() | "
87  "Number of IntParameters does not match: " +
88  std::to_string(nInt) + " given but " +
89  std::to_string(check_nInt) + " expected."));
90  if (nDouble != check_nDouble)
91  throw(BadParameter("FlatteStrategy::execute() | "
92  "Number of FitParameters does not match: " +
93  std::to_string(nDouble) + " given but " +
94  std::to_string(check_nDouble) + " expected."));
95  if (nComplex != check_nComplex)
96  throw(BadParameter("FlatteStrategy::execute() | "
97  "Number of ComplexParameters does not match: " +
98  std::to_string(nComplex) + " given but " +
99  std::to_string(check_nComplex) + " expected."));
100  if (nMInteger != check_nMInteger)
101  throw(BadParameter("FlatteStrategy::execute() | "
102  "Number of MultiInt does not match: " +
103  std::to_string(nMInteger) + " given but " +
104  std::to_string(check_nMInteger) + " expected."));
105  if (nMDouble != check_nMDouble)
106  throw(BadParameter("FlatteStrategy::execute() | "
107  "Number of MultiDoubles does not match: " +
108  std::to_string(nMDouble) + " given but " +
109  std::to_string(check_nMDouble) + " expected."));
110  if (nMComplex != check_nMComplex)
111  throw(BadParameter("FlatteStrategy::execute() | "
112  "Number of MultiComplexes does not match: " +
113  std::to_string(nMComplex) + " given but " +
114  std::to_string(check_nMComplex) + " expected."));
115 #endif
116 
117  size_t n = paras.mDoubleValue(0)->values().size();
118  if (!out)
119  out = ComPWA::FunctionTree::MComplex("", n);
120 
121  auto par =
122  std::static_pointer_cast<Value<std::vector<std::complex<double>>>>(out);
123  auto &results = par->values(); // reference
124  if (results.size() != n) {
125  results.resize(n);
126  }
127  // calc function for each point
128  for (size_t ele = 0; ele < n; ele++) {
129  try {
130  // Generally we need to add a factor q^{2J+1} to each channel term.
131  // But since Flatte resonances are usually J=0 we neglect it here.
132  results.at(ele) = Flatte::dynamicalFunction(
133  paras.mDoubleValue(0)->values().at(ele),
134  paras.doubleParameter(0)->value(), // mass
135  paras.doubleParameter(1)->value(), // g1_massA
136  paras.doubleParameter(2)->value(), // g1_massB
137  paras.doubleParameter(3)->value(), // g1
138  paras.doubleParameter(4)->value(), // g2_massA
139  paras.doubleParameter(5)->value(), // g2_massB
140  paras.doubleParameter(6)->value(), // g2
141  paras.doubleParameter(7)->value(), // g3_massA
142  paras.doubleParameter(8)->value(), // g3_massB
143  paras.doubleParameter(9)->value(), // g3
144  paras.doubleValue(0)->value(), // OrbitalAngularMomentum
145  paras.doubleParameter(10)->value(), // mesonRadius
146  FormFactorFunctor);
147  } catch (std::exception &ex) {
148  LOG(ERROR) << "FlatteStrategy::execute() | " << ex.what();
149  throw(std::runtime_error("FlatteStrategy::execute() | "
150  "Evaluation of dynamic function failed!"));
151  }
152  }
153 }
154 
155 } // namespace Dynamics
156 } // namespace Physics
157 } // namespace ComPWA
Parameter not existing.
Definition: Exceptions.hpp:62
std::shared_ptr< FormFactor > FormFactorFunctor
Form factor function object.
Base class for internal parameter.
Definition: Parameter.hpp:79
std::complex< double > dynamicalFunction(double mSq, double mR, double gA, std::complex< double > termA, std::complex< double > termB, std::complex< double > termC=std::complex< double >(0, 0))
Dynamical function for two coupled channel approach.
Definition: Flatte.hpp:61
virtual std::vector< std::shared_ptr< Value< std::vector< int > > > > & mIntValues()
TreeNode is the basic building block of the FunctionTree.
Definition: TreeNode.hpp:35
std::shared_ptr< ComPWA::FunctionTree::FitParameter > MesonRadius
Meson radius 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< ComPWA::FunctionTree::TreeNode > createFunctionTree(InputInfo Params, std::shared_ptr< ComPWA::FunctionTree::Value< std::vector< double >>> InvMassSquared)
Definition: Flatte.cpp:17
virtual void execute(ComPWA::FunctionTree::ParameterList &paras, std::shared_ptr< ComPWA::FunctionTree::Parameter > &out)
Definition: Flatte.cpp:54
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::vector< Coupling > HiddenCouplings
Coupling parameters and final state masses for multiple hidden channels.
Definition: Flatte.hpp:21
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
unsigned int L
Orbital Angular Momentum between two daughters in Resonance decay.
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()
std::pair< std::shared_ptr< ComPWA::FunctionTree::Value< std::vector< double > > >, std::shared_ptr< ComPWA::FunctionTree::Value< std::vector< double > > > > DaughterInvariantMasses
Invariant Masses of daughter particles.
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::shared_ptr< ComPWA::FunctionTree::FitParameter > G
Coupling to signal channel.
Definition: Flatte.hpp:19
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