ComPWA
Common Partial-Wave-Analysis Framework
EvtGenIF.cpp
Go to the documentation of this file.
1 // Copyright (c) 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 
6 #include <numeric>
7 
8 #include "EvtGenIF.hpp"
9 #include "Physics/BuilderXML.hpp"
10 
11 namespace ComPWA {
12 namespace Physics {
13 namespace EvtGen {
14 
16 
17 void EvtGenIF::addResonance(const std::string &name, double m0, double g0,
18  double spin, const SubSystem &subsys) {
19  // LOG(debug) << "EvtGenIF::addResonance starts. Name: " << name << " mass: "
20  // << m0 << " width: " << g0 << " spin: " << spin;
21  EvtCyclic3::Pair pairAng;
22  EvtCyclic3::Pair pairRes;
23  LOG(DEBUG) << "EvtGenIF::addResonance num finalstate00: "
24  << subsys.getFinalStates().at(0).at(0);
25  LOG(DEBUG) << "EvtGenIF::addResonance num finalstate01: "
26  << subsys.getFinalStates().at(1).at(0);
27  switch (subsys.getFinalStates().at(0).at(0) +
28  subsys.getFinalStates().at(1).at(0)) {
29  case 3: // 12:
30  pairAng = EvtCyclic3::Pair::AB;
31  pairRes = EvtCyclic3::Pair::BC;
32  break;
33  case 4: // 13:
34  pairAng = EvtCyclic3::Pair::AC;
35  pairRes = EvtCyclic3::Pair::AB;
36  break;
37  default: // 23
38  pairAng = EvtCyclic3::Pair::BC;
39  pairRes = EvtCyclic3::Pair::AC;
40  }
41  auto evtspin = EvtSpinType::spintype::SCALAR;
42  if (spin == 1)
43  evtspin = EvtSpinType::spintype::VECTOR;
44  else if (spin == 2)
45  evtspin = EvtSpinType::spintype::TENSOR;
46  else
47  throw std::runtime_error(
48  "EvtGenIF::addResonance() | Spins higher than two are not supported.");
49 
50  LOG(DEBUG) << "EvtGenIF::addResonance: " << name;
51  LOG(DEBUG) << "EvtGenIF::addResonance mass: " << m0;
52  LOG(DEBUG) << "EvtGenIF::addResonance width: " << g0;
53  LOG(DEBUG) << "EvtGenIF::addResonance spin: " << spin;
54  EvtDalitzReso reso(name, DalitzPlot, pairAng, pairRes, evtspin, m0, g0,
55  EvtDalitzReso::NumType::RBW_ZEMACH);
56  Resos.push_back(reso);
57 
58  evtPars[std::string(name + "_mass")] =
59  std::shared_ptr<ComPWA::FunctionTree::FitParameter>(
60  new ComPWA::FunctionTree::FitParameter(name + "_mass", m0));
61  evtPars.at(std::string(name + "_mass"))->fixParameter(false);
62  evtPars[std::string(name + "_width")] =
63  std::shared_ptr<ComPWA::FunctionTree::FitParameter>(
64  new ComPWA::FunctionTree::FitParameter(name + "_width", g0));
65  evtPars.at(std::string(name + "_width"))->fixParameter(true);
66  // LOG(debug) << "EvtGenIF::addResonance finishes";
67 }
68 
69 void EvtGenIF::addHeliResonance(const boost::property_tree::ptree &pt,
70  const ComPWA::ParticleList &partL) {
71  // LOG(debug) << "EvtGenIF::addHeliResonance starts";
72  std::string resoName = pt.get<std::string>("<xmlattr>.Name", "empty");
73  std::string name = pt.get<std::string>("DecayParticle.<xmlattr>.Name");
74  auto parti = findParticle(partL, name);
75 
76  double J = parti.getQuantumNumber<double>("Spin");
77 
78  auto DecayInfo = ComPWA::Physics::extractDecayInfo(pt);
79 
80  // LOG(debug) << "EvtGenIF::addHeliResonance two-body decay";
81  // Two-body decay
82  if (DecayInfo.SubSys.getFinalStates().size() == 2) {
83  // Create WignerD object
84  // AngularDist = std::make_shared<HelicityFormalism::AmpWignerD>(
85  // J, mu, DecayHelicities.first - DecayHelicities.second);
86 
87  auto partProp = findParticle(partL, name);
88  std::string decayType = partProp.getDecayType();
89 
90  if (decayType == "stable") {
91  throw std::runtime_error(
92  "EvtGenIF::addHeliResonance() | Stable particle is "
93  "given as mother particle of a decay. Makes no "
94  "sense!");
95  } else if (decayType == "relativisticBreitWigner") {
96  LOG(DEBUG) << "EvtGenIF::addHeliResonance add resonance";
97  double width = 0.1;
98  for (const auto &v : partProp.getDecayInfo().get_child("")) {
99  if (v.first != "Parameter")
100  continue;
101  std::string type = v.second.get<std::string>("<xmlattr>.Type");
102  if (type == "Width") {
103  // SetWidthParameter(std::make_shared<FitParameter>(v.second));
104  width = v.second.get<double>("Value"); // TODO: funzt nicht
105  } else if (type == "MesonRadius") {
106  // TODO
107  }
108  }
109  addResonance(name, parti.getMass().Value, width, J, DecayInfo.SubSys);
110  // DynamicFcn = std::make_shared<DecayDynamics::RelativisticBreitWigner>(
111  // name, DecayProducts, partL);
112  } else if (decayType == "flatte") {
113  // TODO
114  // DynamicFcn = std::make_shared<DecayDynamics::AmpFlatteRes>(
115  // name, DecayProducts, partL);
116  } else {
117  throw std::runtime_error(
118  "EvtGenIF::addHeliResonance() | Unknown decay type " + decayType +
119  "!");
120  }
121  LOG(DEBUG) << "EvtGenIF::addHeliResonance finished";
122  // make sure dynamical function is created and set first
123  }
124 }
125 
126 void EvtGenIF::addResonances(const boost::property_tree::ptree &pt,
127  std::shared_ptr<DalitzKinematics> kin,
128  const ComPWA::ParticleList &partL) {
129  if (pt.get<std::string>("<xmlattr>.Class") != "Incoherent")
130  throw BadConfig("IncoherentIntensity::Factory() | Property tree seems to "
131  "not containt a configuration for an "
132  "IncoherentIntensity!");
133 
134  setPhspVolume(kin->phspVolume());
135 
136  LOG(DEBUG) << "EvtGenIF::addResoances starts";
137 
138  for (const auto &v : pt.get_child("")) {
139  if (v.first == "Intensity" &&
140  v.second.get<std::string>("<xmlattr>.Class") == "Coherent") {
141 
142  for (const auto &w : v.second.get_child("")) {
143  if (w.first == "Amplitude" &&
144  w.second.get<std::string>("<xmlattr>.Class") ==
145  "SequentialPartialAmplitude") {
146  // addAmplitude(std::make_shared<SequentialPartialAmplitude>(partL,
147  // kin, v.second));
148  std::string name = pt.get<std::string>("<xmlattr>.Name", "empty");
149 
150  std::complex<double> preFactor = std::complex<double>(1, 0);
151  for (const auto &x : w.second.get_child("")) {
152  if (x.first == "Parameter") {
153 
154  } else if (x.first == "PartialAmplitude" &&
155  x.second.get<std::string>("<xmlattr>.Class") ==
156  "HelicityDecay") {
157  LOG(DEBUG) << "EvtGenIF::addResoances add Heli-Resonance";
158  addHeliResonance(x.second, partL);
159 
160  } else if (x.first == "PreFactor") {
161  LOG(DEBUG) << "EvtGenIF::addResoances add factor";
162  double r = x.second.get<double>("<xmlattr>.Magnitude");
163  double p = x.second.get<double>("<xmlattr>.Phase");
164  preFactor = std::polar(r, p);
165  }
166  }
167  }
168  }
169  }
170  }
171 
172  LOG(DEBUG) << "EvtGenIF::addResoances finished";
173 }
174 
175 std::vector<double> EvtGenIF::evaluate(const ComPWA::DataMap &data) noexcept {
176  std::vector<double> Results;
177  for (size_t EventIndex = 0; EventIndex < data.at("mA").size(); ++EventIndex) {
178  EvtDalitzPoint pnt(data.at("mA")[EventIndex], data.at("mB")[EventIndex],
179  data.at("mC")[EventIndex], data.at("qAB")[EventIndex],
180  data.at("qBC")[EventIndex], data.at("qCA")[EventIndex]);
181  double result = 0;
182 
183  for (unsigned int i = 0; i < Resos.size(); ++i) {
184  EvtDalitzReso tmp = Resos.at(i);
185  std::string name = tmp.get_Name();
186 
187  tmp.set_Mass(evtPars.at(std::string(name + "_mass"))->value());
188  tmp.set_Gamma(evtPars.at(std::string(name + "_width"))->value());
189 
190  result += abs2(tmp.evaluate(pnt)); // * normValues.at(i);
191  }
192 
193  assert(!std::isnan(result) &&
194  "IncoherentIntensity::Intensity() | Result is NaN!");
195  assert(!std::isinf(result) &&
196  "IncoherentIntensity::Intensity() | Result is inf!");
197 
198  Results.push_back(result);
199  }
200  return Results;
201 }
202 
203 void EvtGenIF::updateParametersFrom(const std::vector<double> &Parameters) {
204  size_t counter(0);
205  for (auto i : evtPars) {
206  if (!i.second->isFixed())
207  i.second->setValue(Parameters[counter]);
208  ++counter;
209  }
210 }
211 
212 std::vector<ComPWA::Parameter> EvtGenIF::getParameters() const {
213  std::vector<ComPWA::Parameter> pars;
214  for (auto i : evtPars) {
215  pars.push_back(ComPWA::Parameter{i.second->name(), i.second->value()});
216  }
217  return pars;
218 }
219 
220 } // namespace EvtGen
221 } // namespace Physics
222 } // namespace ComPWA
void addHeliResonance(const boost::property_tree::ptree &pt, const ComPWA::ParticleList &partL)
Add EvtGen Dalitz Resonance.
Definition: EvtGenIF.cpp:69
cmplx FADDEEVA() w(cmplx z, double relerr)
Definition: Faddeeva.cc:668
void addResonances(const boost::property_tree::ptree &pt, std::shared_ptr< DalitzKinematics > kin, const ComPWA::ParticleList &partL)
Add EvtGen Dalitz Resonances from XML model.
Definition: EvtGenIF.cpp:126
std::vector< double > evaluate(const ComPWA::DataMap &data) noexcept
Definition: EvtGenIF.cpp:175
void updateParametersFrom(const std::vector< double > &Parameters) final
It is important to input the vector in the same length and order as defined in the getParameters() me...
Definition: EvtGenIF.cpp:203
const ParticleProperties & findParticle(const ParticleList &list, pid Pid)
Definition: Properties.hpp:93
void addResonance(const std::string &name, double m0, double g0, double spin, const ComPWA::Physics::SubSystem &subsys)
Add EvtGen Dalitz Resonance.
Definition: EvtGenIF.cpp:17
std::set< ParticleProperties > ParticleList
Definition: Properties.hpp:84
virtual const std::vector< std::vector< unsigned int > > & getFinalStates() const
Definition: SubSystem.cpp:48
std::vector< EvtDalitzReso > Resos
Definition: EvtGenIF.hpp:80
std::map< std::string, std::shared_ptr< ComPWA::FunctionTree::FitParameter > > evtPars
Temporary storage of the para.
Definition: EvtGenIF.hpp:77
Config is not complete.
Definition: Exceptions.hpp:50
std::vector< ComPWA::Parameter > getParameters() const final
Definition: EvtGenIF.cpp:212
std::unordered_map< std::string, std::vector< double > > DataMap
Definition: Function.hpp:15
virtual void setPhspVolume(double vol)
Definition: EvtGenIF.hpp:63
TwoBodyDecayInfo extractDecayInfo(const boost::property_tree::ptree &pt)
Definition: BuilderXML.cpp:609
Definition of a two-body decay node within a sequential decay tree.
Definition: SubSystem.hpp:31