/home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/fit/mimir/include/mimir/ParamSet.hh Source File

Ratpac-two: /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/fit/mimir/include/mimir/ParamSet.hh Source File
Ratpac-two
ParamSet.hh
1 #pragma once
2 #include <CLHEP/Units/PhysicalConstants.h>
3 #include <TVector3.h>
4 
5 #include <algorithm>
6 #include <limits>
7 #include <string>
8 #include <vector>
9 
10 namespace Mimir {
11 enum class ParamStatus { INACTIVE = 0, ACTIVE = 1, FIXED = 2 };
12 
14  std::string name;
15  double value;
16  double lower_bound = std::numeric_limits<double>::lowest();
17  double upper_bound = std::numeric_limits<double>::max();
18  double step = 0.01;
19  ParamStatus status = ParamStatus::INACTIVE;
20  bool fit_valid = false;
21 
22  bool is_active() const { return status == ParamStatus::ACTIVE; }
23  bool is_fixed() const { return status == ParamStatus::FIXED; }
24  bool is_used() const { return status != ParamStatus::INACTIVE; }
25 };
26 
27 struct ParamField {
28  std::vector<ParamComponent> components;
29  std::vector<double> active_values() const;
30  std::vector<double> used_values() const;
31  std::vector<double> active_lower_bounds() const;
32  std::vector<double> active_upper_bounds() const;
33  void set_all_lower_bounds(double value);
34  void set_all_upper_bounds(double value);
35  void set_all_status(ParamStatus status);
36  void set_all_fit_valid(bool valid);
37  void set_status(std::vector<ParamStatus> status_vector);
38  void set_values(const double* values, size_t n);
39  void set_values(std::vector<double> values);
40  void set_lower_bounds(const double* lower_bounds, size_t n);
41  void set_lower_bounds(std::vector<double> lower_bounds);
42  void set_upper_bounds(const double* upper_bouonds, size_t n);
43  void set_upper_bounds(std::vector<double> upper_bounds);
44  bool are_all_used() const {
45  return std::all_of(components.begin(), components.end(), [](const ParamComponent& comp) { return comp.is_used(); });
46  }
47  bool are_all_active() const {
48  return std::all_of(components.begin(), components.end(),
49  [](const ParamComponent& comp) { return comp.is_active(); });
50  }
51  bool are_all_fit_valid() const {
52  return std::all_of(components.begin(), components.end(), [](const ParamComponent& comp) { return comp.fit_valid; });
53  }
54 };
55 
56 struct ParamSet {
57  ParamField position_time = {.components = {{.name = "x", .value = 0.0},
58  {.name = "y", .value = 0.0},
59  {.name = "z", .value = 0.0},
60  {.name = "t", .value = 0.0}}};
61  ParamField direction = {
62  .components = {{.name = "u", .value = 0.0}, {.name = "v", .value = 0.0}, {.name = "w", .value = 0.0}}};
63  ParamField energy = {.components = {{.name = "energy", .value = 1.0, .lower_bound = 0.0}}};
64 
65  std::vector<double> to_active_vector() const;
66  std::vector<ParamComponent> to_active_components() const;
67  void update_active(const std::vector<double>& values);
68  void update_active(const double* values, size_t n);
69  void set_active_fit_valid(bool valid);
70  ParamSet from_active_vector(const std::vector<double>& values) const;
71 
72  TVector3 GetPosition() const;
73  TVector3 GetDirection() const;
74  double GetTime() const;
75  double GetEnergy() const;
76 };
77 
78 } // namespace Mimir
Definition: ParamSet.hh:13
Definition: ParamSet.hh:27
Definition: ParamSet.hh:56