Belle II Software light-2406-ragdoll
BaseFitter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * Forked from https://github.com/iLCSoft/MarlinKinfit *
6 * *
7 * Further information about the fit engine and the user interface *
8 * provided in MarlinKinfit can be found at *
9 * https://www.desy.de/~blist/kinfit/doc/html/ *
10 * and in the LCNotes LC-TOOL-2009-001 and LC-TOOL-2009-004 available *
11 * from http://www-flc.desy.de/lcnotes/ *
12 * *
13 * See git log for contributors and copyright holders. *
14 * This file is licensed under LGPL-3.0, see LICENSE.md. *
15 **************************************************************************/
16
17#include "analysis/OrcaKinFit/BaseFitter.h"
18#include "analysis/OrcaKinFit/BaseSoftConstraint.h"
19#include "analysis/OrcaKinFit/BaseHardConstraint.h"
20
21#undef NDEBUG
22#include <cassert>
23
24namespace Belle2 {
29 namespace OrcaKinFit {
30
31 BaseFitter::BaseFitter()
32 : fitobjects(FitObjectContainer()),
33 constraints(ConstraintContainer()),
34 softconstraints(SoftConstraintContainer()),
35 covDim(0), cov(nullptr), covValid(false)
36#ifndef FIT_TRACEOFF
37 , tracer(nullptr),
38 traceValues(std::map<std::string, double> ())
39#endif
40 {}
41
42 BaseFitter::~BaseFitter()
43 {
44 delete[] cov;
45 cov = nullptr;
46 }
47
48 void BaseFitter::addFitObject(BaseFitObject* fitobject_)
49 {
50 covValid = false;
51 fitobjects.push_back(fitobject_);
52 }
53
54 void BaseFitter::addFitObject(BaseFitObject& fitobject_)
55 {
56 covValid = false;
57 fitobjects.push_back(&fitobject_);
58 }
59
60 void BaseFitter::addConstraint(BaseConstraint* constraint_)
61 {
62 covValid = false;
63
64 if (auto* hc = dynamic_cast<BaseHardConstraint*>(constraint_))
65 constraints.push_back(hc);
66 else if (auto* sc = dynamic_cast<BaseSoftConstraint*>(constraint_))
67 softconstraints.push_back(sc);
68 else {
69 // illegal constraint
70 assert(0);
71 }
72 }
73
74 void BaseFitter::addConstraint(BaseConstraint& constraint_)
75 {
76 covValid = false;
77 if (auto* hc = dynamic_cast<BaseHardConstraint*>(&constraint_))
78 constraints.push_back(hc);
79 else if (auto* sc = dynamic_cast<BaseSoftConstraint*>(&constraint_))
80 softconstraints.push_back(sc);
81 }
82
83 void BaseFitter::addHardConstraint(BaseHardConstraint* constraint_)
84 {
85 covValid = false;
86 constraints.push_back(constraint_);
87 }
88
89 void BaseFitter::addHardConstraint(BaseHardConstraint& constraint_)
90 {
91 covValid = false;
92 constraints.push_back(&constraint_);
93 }
94
95 void BaseFitter::addSoftConstraint(BaseSoftConstraint* constraint_)
96 {
97 covValid = false;
98 softconstraints.push_back(constraint_);
99 }
100
101 void BaseFitter::addSoftConstraint(BaseSoftConstraint& constraint_)
102 {
103 covValid = false;
104 softconstraints.push_back(&constraint_);
105 }
106
107 std::vector<BaseFitObject*>* BaseFitter::getFitObjects()
108 {
109 return &fitobjects;
110 }
111
112 std::vector<BaseHardConstraint*>* BaseFitter::getConstraints()
113 {
114 return &constraints;
115 }
116
117 std::vector<BaseSoftConstraint*>* BaseFitter::getSoftConstraints()
118 {
119 return &softconstraints;
120 }
121
122 void BaseFitter::reset()
123 {
124 fitobjects.resize(0);
125 constraints.resize(0);
126 softconstraints.resize(0);
127 covValid = false;
128 }
129
130 BaseTracer* BaseFitter::getTracer()
131 {
132 return tracer;
133 }
134 const BaseTracer* BaseFitter::getTracer() const
135 {
136 return tracer;
137 }
138 void BaseFitter::setTracer(BaseTracer* newTracer)
139 {
140 tracer = newTracer;
141 }
142
143 void BaseFitter::setTracer(BaseTracer& newTracer)
144 {
145 tracer = &newTracer;
146 }
147
148 const double* BaseFitter::getGlobalCovarianceMatrix(int& idim) const
149 {
150 if (covValid && cov) {
151 idim = covDim;
152 return cov;
153 }
154 idim = 0;
155 return nullptr;
156 }
157
158 double* BaseFitter::getGlobalCovarianceMatrix(int& idim)
159 {
160 if (covValid && cov) {
161 idim = covDim;
162 return cov;
163 }
164 idim = 0;
165 return nullptr;
166 }
167
168 }// end OrcaKinFit namespace
170} // end Belle2 namespace
171
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.