ComPWA
Common Partial-Wave-Analysis Framework
UpdatePTreeParameter.cpp
Go to the documentation of this file.
2 
3 namespace ComPWA {
4 namespace Tools {
5 
6 void updateParameterRangeByType(boost::property_tree::ptree &Tree,
7  const std::string &ParameterType, double Min,
8  double Max) {
9  updateParameter(Tree, "Type", ParameterType,
10  // dummy args real args not update update
11  0, false, Min, Max, false, false, true);
12 }
13 
14 void updateParameterRangeByName(boost::property_tree::ptree &Tree,
15  const std::string &ParameterName, double Min,
16  double Max) {
17  updateParameter(Tree, "Name", ParameterName,
18  // dummy args real args not--update update
19  0, false, Min, Max, false, false, true);
20 }
21 
22 void updateParameterValue(boost::property_tree::ptree &Tree,
23  const std::string ParameterName, double Value) {
24  updateParameter(Tree, "Name", ParameterName,
25  // real dummy ------ args, update not---update
26  Value, false, -999, -999, true, false, false);
27 }
28 
29 void fixParameter(boost::property_tree::ptree &Tree,
30  const std::string ParameterName, double Value) {
31  if ((int)Value == -999) {
32  updateParameter(Tree, "Name", ParameterName,
33  // dummy real, dummy args, notup update not-update
34  -999, true, -999, -999, false, true, false);
35  } else {
36  updateParameter(Tree, "Name", ParameterName,
37  // real args, dummy args, up----date not-update
38  Value, true, -999, -999, true, true, false);
39  }
40 }
41 
42 void releaseParameter(boost::property_tree::ptree &Tree,
43  const std::string ParameterName, double Value) {
44  if ((int)Value == -999) {
45  updateParameter(Tree, "Name", ParameterName,
46  // dummy real, dummy args, not-up update not-up
47  -999, false, -999, -999, false, true, false);
48  } else {
49  updateParameter(Tree, "Name", ParameterName,
50  // real args, dummy args, not-up update not-up
51  Value, false, -999, -999, false, true, false);
52  }
53 }
54 
55 void updateParameter(boost::property_tree::ptree &Tree,
56  const std::string &KeyType, const std::string &KeyValue,
57  double Value, bool Fix, double Min, double Max,
58  bool UpdateValue, bool UpdateFix, bool UpdateRange) {
59 
60  for (auto &Node : Tree.get_child("")) {
61  // If not not a parameter node, recursively update this node.
62  if (Node.first != "Parameter") {
63  if (Node.first != "DecayParticle" && Node.first != "DecayProducts" &&
64  Node.first != "CanonicalSum") {
65  updateParameter(Node.second, KeyType, KeyValue, Value, Fix, Min, Max,
66  UpdateValue, UpdateFix, UpdateRange);
67  }
68  continue;
69  }
70  // If it is a parameter node, and it's target parameter,
71  // update parameter properties.
72  if (KeyValue != Node.second.get<std::string>("<xmlattr>." + KeyType)) {
73  continue;
74  }
75  if (UpdateValue)
76  Node.second.put("Value", Value);
77  if (UpdateFix)
78  Node.second.put("Fix", Fix);
79  if (UpdateRange) {
80  Node.second.put("Min", Min);
81  Node.second.put("Max", Max);
82  }
83  }
84 }
85 
86 void updateParameter(boost::property_tree::ptree &Tree,
87  const FitParameterList &FitParameters) {
88  for (const auto &FitPar : FitParameters) {
89  updateParameter(Tree, "Name", FitPar.Name, FitPar.Value, FitPar.IsFixed,
90  FitPar.Bounds.first, FitPar.Bounds.second, true, true,
91  FitPar.HasBounds);
92  }
93 }
94 
95 } // end namespace Tools
96 } // end namespace ComPWA
void updateParameterRangeByName(boost::property_tree::ptree &Tree, const std::string &ParameterName, double Min, double Max)
Update range of specified parameters of a ptree.
This file contains functions which will update parameters&#39; value, range etc.
void updateParameter(boost::property_tree::ptree &Tree, const std::string &KeyType, const std::string &KeyValue, double Value, bool Fix, double Min, double Max, bool UpdateValue, bool UpdateFix, bool UpdateRange)
Update specified parameters of a ptree.
std::vector< FitParameter< double > > FitParameterList
void fixParameter(boost::property_tree::ptree &Tree, const std::string ParameterName, double Value)
Fix specified parameters of a ptree.
void updateParameterValue(boost::property_tree::ptree &Tree, const std::string ParameterName, double Value)
Update value of specified parameters of a ptree.
void updateParameterRangeByType(boost::property_tree::ptree &Tree, const std::string &ParameterType, double Min, double Max)
Update range of specified parameters of a ptree.
void releaseParameter(boost::property_tree::ptree &Tree, const std::string ParameterName, double Value)
Release specified parameters of a ptree.