Bug Summary

File:analysis/OrcaKinFit/src/BaseFitObject.cc
Warning:line 545, column 34
The left operand of '*' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name BaseFitObject.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="analysis" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ analysis/OrcaKinFit/src/BaseFitObject.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/BaseFitObject.h"
18#include <framework/logging/Logger.h>
19
20#undef NDEBUG
21#include <cassert>
22
23#include <cstring>
24#include <iostream>
25#include <cmath>
26using std::isfinite;
27
28#include <gsl/gsl_matrix.h>
29#include <gsl/gsl_linalg.h>
30
31namespace Belle2 {
32 namespace OrcaKinFit {
33
34 BaseFitObject::BaseFitObject(): name(nullptr), par{}, mpar{}, measured{}, fixed{}, globalParNum{}, cov{}, covinv{}, covinvvalid(
35 false),
36 cachevalid(false)
37 {
38 setName("???");
39 invalidateCache();
40
41 for (int ilocal = 0; ilocal < BaseDefs::MAXPAR; ++ilocal) {
42 globalParNum[ilocal] = -1;
43 fixed[ilocal] = false;
44 for (int jlocal = 0; jlocal < BaseDefs::MAXPAR; ++jlocal)
45 cov[ilocal][jlocal] = 0;
46 }
47
48 }
49
50 BaseFitObject::BaseFitObject(const BaseFitObject& rhs)
51 : name(nullptr), par{}, mpar{}, measured{}, fixed{}, globalParNum{}, cov{}, covinv{}, covinvvalid(false), cachevalid(false)
52 {
53 BaseFitObject::assign(rhs);
54 }
55
56 BaseFitObject& BaseFitObject::operator= (const BaseFitObject& rhs)
57 {
58 if (this != &rhs) {
59 assign(rhs); // calls virtual function assign of derived class
60 }
61 return *this;
62 }
63
64 BaseFitObject& BaseFitObject::assign(const BaseFitObject& source)
65 {
66 if (&source != this) {
67 name = nullptr;
68 setName(source.name);
69 for (int i = 0; i < BaseDefs::MAXPAR; ++i) {
70 par[i] = source.par[i];
71 mpar[i] = source.mpar[i];
72 measured[i] = source.measured[i];
73 fixed[i] = source.fixed[i];
74 globalParNum[i] = source.globalParNum[i];
75 for (int j = 0; j < BaseDefs::MAXPAR; ++j) {
76 cov[i][j] = source.cov[i][j];
77 covinv[i][j] = source.covinv[i][j];
78 }
79 }
80 covinvvalid = false;
81 cachevalid = false;
82 }
83 return *this;
84 }
85
86
87 BaseFitObject::~BaseFitObject()
88 {
89 delete[] name;
90 }
91
92 const double BaseFitObject::eps2 = 0.0001; // changed to 1^-4, then sqrt(eps2) corresponds to 1%
93
94 void BaseFitObject::setName(const char* name_)
95 {
96 if (name_ == nullptr) return;
97 size_t l = strlen(name_);
98 if (name) delete[] name;
99 name = new char[l + 1];
100 strcpy(name, name_);
101 }
102
103 const char* BaseFitObject::getName() const
104 {
105 return name ? name : "???";
106 }
107
108 int BaseFitObject::getNMeasured() const
109 {
110 int nmeasured = 0;
111 for (int i = 0; i < getNPar(); ++i) if (isParamMeasured(i) && !isParamFixed(i)) ++nmeasured;
112 return nmeasured;
113 }
114 int BaseFitObject::getNUnmeasured() const
115 {
116 int nunmeasrd = 0;
117 for (int i = 0; i < getNPar(); ++i) if (!isParamMeasured(i) && !isParamFixed(i)) ++nunmeasrd;
118 return nunmeasrd;
119 }
120 int BaseFitObject::getNFree() const
121 {
122 int nfree = 0;
123 for (int i = 0; i < getNPar(); ++i) if (!isParamFixed(i)) ++nfree;
124 return nfree;
125 }
126 int BaseFitObject::getNFixed() const
127 {
128 int nfixed = 0;
129 for (int i = 0; i < getNPar(); ++i) if (isParamFixed(i)) ++nfixed;
130 return nfixed;
131 }
132
133 std::ostream& BaseFitObject::printParams(std::ostream& os) const
134 {
135 os << "(";
136 for (int i = 0; i < getNPar(); ++i) {
137 if (i > 0) os << ", ";
138 os << " " << getParam(i);
139 if (isParamFixed(i)) os << " fix";
140// else if (getError(i)>0) os << " \261 " << getError(i);
141 else if (getError(i) > 0) os << " +- " << getError(i); // " \261 " appeared as <B1> in ASCII ... Graham
142 }
143 os << ")";
144 return os;
145 }
146
147 std::ostream& BaseFitObject::printRhoValues(std::ostream& os) const
148 {
149 os << "{";
150 for (int i = 0; i < getNPar(); ++i) {
151 for (int j = 0; j < getNPar(); ++j) {
152 if (i > 0 && j == 0) os << ",";
153 os << " " << getRho(i, j);
154 }
155 }
156 os << "}" << std::endl;
157 return os;
158 }
159
160 std::ostream& BaseFitObject::print1stDerivatives(std::ostream& os) const
161 {
162 int metaSet = 0;
163 os << "#";
164 for (int i = 0; i < BaseDefs::nMetaVars[metaSet]; ++i) {
165 for (int j = 0; j < getNPar(); ++j) {
166 if (i > 0 && j == 0) os << ",";
167 os << " " << getFirstDerivative_Meta_Local(i, j, metaSet);
168 }
169 }
170 os << "#" << std::endl;
171 return os;
172 }
173
174 std::ostream& BaseFitObject::print2ndDerivatives(std::ostream& os) const
175 {
176 int metaSet = 0;
177 os << "##";
178 for (int i = 0; i < BaseDefs::nMetaVars[metaSet]; ++i) {
179 if (i > 0) os << std::endl << " ";
180 for (int j = 0; j < getNPar(); ++j) {
181 for (int k = 0; k < getNPar(); ++k) {
182// if (i>0 && k==0) os << ",";
183 os << " " << getSecondDerivative_Meta_Local(i, j, k, metaSet);
184 if (k == getNPar() - 1) os << ",";
185 }
186 }
187 }
188 os << "##" << std::endl;
189 return os;
190 }
191
192 bool BaseFitObject::updateParams(double p[], int idim)
193 {
194 bool result = false;
195 invalidateCache();
196 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
197 if (!isParamFixed(ilocal)) { // daniel added this
198 int iglobal = getGlobalParNum(ilocal);
199 assert(iglobal >= 0 && iglobal < idim)(static_cast <bool> (iglobal >= 0 && iglobal
< idim) ? void (0) : __assert_fail ("iglobal >= 0 && iglobal < idim"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 199, __extension__
__PRETTY_FUNCTION__))
;
200 // result = result || setParam (ilocal, p[iglobal]); // daniel thinks this is a BUG !!! if first param is successfully updated, no further ones are
201 // result = setParam (ilocal, p[iglobal]) || result; // daniel thinks this would be OK
202 // but to makes it clearer, does the following:
203 bool thisresult = setParam(ilocal, p[iglobal]);
204 result = result || thisresult;
205 // if illegal value: read back legal value
206 if (!thisresult) // daniel added
207 p[iglobal] = getParam(ilocal);
208 }
209 }
210 return result;
211 }
212
213 void BaseFitObject::addToGlobCov(double* globCov, int idim) const
214 {
215 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
216 if (!isParamFixed(ilocal) && isParamMeasured(ilocal)) {
217 int iglobal = getGlobalParNum(ilocal);
218 assert(iglobal >= 0 && iglobal < idim)(static_cast <bool> (iglobal >= 0 && iglobal
< idim) ? void (0) : __assert_fail ("iglobal >= 0 && iglobal < idim"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 218, __extension__
__PRETTY_FUNCTION__))
;
219 int ioffs = idim * iglobal;
220 for (int jlocal = 0; jlocal < getNPar(); ++jlocal) {
221 if (!isParamFixed(jlocal) && isParamMeasured(jlocal)) {
222 int jglobal = getGlobalParNum(jlocal);
223 assert(jglobal >= 0 && jglobal < idim)(static_cast <bool> (jglobal >= 0 && jglobal
< idim) ? void (0) : __assert_fail ("jglobal >= 0 && jglobal < idim"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 223, __extension__
__PRETTY_FUNCTION__))
;
224 globCov[ioffs + jglobal] += getCov(ilocal, jlocal);
225 }
226 }
227 }
228 }
229 }
230
231 bool BaseFitObject::calculateCovInv() const
232 {
233
234 // DANIEL added
235
236 int n = getNPar();
237
238 gsl_matrix* covm = gsl_matrix_alloc(n, n);
239 gsl_matrix_set_identity(covm);
240
241 for (int i = 0; i < n; ++i) {
242 if (isParamMeasured(i)) {
243 for (int j = 0; j < n; ++j) {
244 if (isParamMeasured(j)) {
245 gsl_matrix_set(covm, i, j, cov[i][j]);
246 }
247 }
248 }
249 }
250 gsl_error_handler_t* e = gsl_set_error_handler_off();
251 int result = gsl_linalg_cholesky_decomp(covm);
252 if (result == 0) result = gsl_linalg_cholesky_invert(covm);
253 gsl_set_error_handler(e);
254
255 for (int i = 0; i < n; ++i) {
256 for (int j = 0; j < i; ++j) {
257 covinv[i][j] = covinv[j][i] = gsl_matrix_get(covm, i, j);
258 }
259 covinv[i][i] = gsl_matrix_get(covm, i, i);
260 }
261
262 gsl_matrix_free(covm);
263 covinvvalid = (result == 0);
264
265 if (!covinvvalid) {
266 B2WARNING("ERROR, COULD NOT INVERT COV MATR!")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Warning, 0, "analysis")) { { LogVariableStream varStream
; varStream << "ERROR, COULD NOT INVERT COV MATR!"; Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Warning, std::move(varStream), "analysis", __PRETTY_FUNCTION__
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 266, 0)); }; } }
while(false)
;
267
268 B2INFO("COV ")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "analysis")) { { LogVariableStream varStream
; varStream << "COV "; Belle2::LogSystem::Instance().sendMessage
(Belle2::LogMessage(Belle2::LogConfig::c_Info, std::move(varStream
), "analysis", __PRETTY_FUNCTION__, "analysis/OrcaKinFit/src/BaseFitObject.cc"
, 268, 0)); }; } } while(false)
;
269 for (int i = 0; i < n; ++i) {
270 if (isParamMeasured(i)) {
271 for (int j = 0; j < n; ++j) {
272 if (isParamMeasured(j)) {
273 B2INFO(cov[i][j] << " ")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "analysis")) { { LogVariableStream varStream
; varStream << cov[i][j] << " "; Belle2::LogSystem
::Instance().sendMessage(Belle2::LogMessage(Belle2::LogConfig
::c_Info, std::move(varStream), "analysis", __PRETTY_FUNCTION__
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 273, 0)); }; } }
while(false)
;
274 }
275 }
276 }
277 }
278
279 B2INFO("CORREL ")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "analysis")) { { LogVariableStream varStream
; varStream << "CORREL "; Belle2::LogSystem::Instance()
.sendMessage(Belle2::LogMessage(Belle2::LogConfig::c_Info, std
::move(varStream), "analysis", __PRETTY_FUNCTION__, "analysis/OrcaKinFit/src/BaseFitObject.cc"
, 279, 0)); }; } } while(false)
;
280 for (int i = 0; i < n; ++i) {
281 if (isParamMeasured(i)) {
282 for (int j = 0; j < n; ++j) {
283 if (isParamMeasured(j)) {
284 B2INFO(cov[i][j] / sqrt(cov[i][i]*cov[j][j]) << " ")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "analysis")) { { LogVariableStream varStream
; varStream << cov[i][j] / sqrt(cov[i][i]*cov[j][j]) <<
" "; Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Info, std::move(varStream), "analysis",
__PRETTY_FUNCTION__, "analysis/OrcaKinFit/src/BaseFitObject.cc"
, 284, 0)); }; } } while(false)
;
285 }
286 }
287 }
288 }
289
290 }
291
292 return covinvvalid;
293 }
294
295 bool BaseFitObject::setParam(int ilocal, double par_,
296 bool measured_, bool fixed_)
297 {
298 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 298, __extension__
__PRETTY_FUNCTION__))
;
299 if (measured[ilocal] != measured_ || fixed[ilocal] != fixed_) invalidateCache();
300 measured[ilocal] = measured_;
301 fixed[ilocal] = fixed_;
302 return setParam(ilocal, par_);
303 }
304
305 bool BaseFitObject::setParam(int ilocal, double par_)
306 {
307 if (!isfinite(par_)) return true;
308 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 308, __extension__
__PRETTY_FUNCTION__))
;
309 if (par[ilocal] == par_) return false;
310 invalidateCache();
311 bool result = pow((par_ - par[ilocal]), 2) > eps2 * cov[ilocal][ilocal];
312 par[ilocal] = par_;
313 return result;
314 }
315
316 bool BaseFitObject::setMParam(int ilocal, double mpar_)
317 {
318 if (!isfinite(mpar_)) return false;
319 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 319, __extension__
__PRETTY_FUNCTION__))
;
320 if (mpar[ilocal] == mpar_) return true;
321 invalidateCache();
322 mpar[ilocal] = mpar_;
323 return true;
324 }
325
326 bool BaseFitObject::setError(int ilocal, double err_)
327 {
328 if (!isfinite(err_)) return false;
329 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 329, __extension__
__PRETTY_FUNCTION__))
;
330 invalidateCache();
331 covinvvalid = false;
332 cov[ilocal][ilocal] = err_ * err_;
333 return true;
334 }
335
336 bool BaseFitObject::setCov(int ilocal, int jlocal, double cov_)
337 {
338 if (!isfinite(cov_)) return false;
339 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 339, __extension__
__PRETTY_FUNCTION__))
;
340 assert(jlocal >= 0 && jlocal < getNPar())(static_cast <bool> (jlocal >= 0 && jlocal <
getNPar()) ? void (0) : __assert_fail ("jlocal >= 0 && jlocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 340, __extension__
__PRETTY_FUNCTION__))
;
341 invalidateCache();
342 covinvvalid = false;
343 cov[ilocal][jlocal] = cov[jlocal][ilocal] = cov_;
344 return true;
345 }
346
347
348 bool BaseFitObject::fixParam(int ilocal, bool fix)
349 {
350 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 350, __extension__
__PRETTY_FUNCTION__))
;
351 return fixed [ilocal] = fix;
352 }
353
354 bool BaseFitObject::setGlobalParNum(int ilocal, int iglobal)
355 {
356 if (ilocal < 0 || ilocal >= getNPar()) return false;
357 globalParNum[ilocal] = iglobal;
358 return true;
359 }
360
361 int BaseFitObject::getGlobalParNum(int ilocal) const
362 {
363 if (ilocal < 0 || ilocal >= getNPar()) return -1;
364 return globalParNum[ilocal];
365 }
366
367 double BaseFitObject::getParam(int ilocal) const
368 {
369 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 369, __extension__
__PRETTY_FUNCTION__))
;
370 return par[ilocal];
371 }
372
373 double BaseFitObject::getMParam(int ilocal) const
374 {
375 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 375, __extension__
__PRETTY_FUNCTION__))
;
376 return mpar[ilocal];
377 }
378
379 double BaseFitObject::getError(int ilocal) const
380 {
381 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 381, __extension__
__PRETTY_FUNCTION__))
;
382 return std::sqrt(cov[ilocal][ilocal]);
383 }
384
385 double BaseFitObject::getCov(int ilocal, int jlocal) const
386 {
387 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 387, __extension__
__PRETTY_FUNCTION__))
;
388 assert(jlocal >= 0 && jlocal < getNPar())(static_cast <bool> (jlocal >= 0 && jlocal <
getNPar()) ? void (0) : __assert_fail ("jlocal >= 0 && jlocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 388, __extension__
__PRETTY_FUNCTION__))
;
389 return cov[ilocal][jlocal];
390 }
391
392 double BaseFitObject::getRho(int ilocal, int jlocal) const
393 {
394 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 394, __extension__
__PRETTY_FUNCTION__))
;
395 assert(jlocal >= 0 && jlocal < getNPar())(static_cast <bool> (jlocal >= 0 && jlocal <
getNPar()) ? void (0) : __assert_fail ("jlocal >= 0 && jlocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 395, __extension__
__PRETTY_FUNCTION__))
;
396 return cov[ilocal][jlocal] / std::sqrt(cov[ilocal][ilocal] * cov[jlocal][jlocal]);
397 }
398 bool BaseFitObject::isParamMeasured(int ilocal) const
399 {
400 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 400, __extension__
__PRETTY_FUNCTION__))
;
401 return measured[ilocal];
402 }
403
404 bool BaseFitObject::isParamFixed(int ilocal) const
405 {
406 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 406, __extension__
__PRETTY_FUNCTION__))
;
407 return fixed[ilocal];
408 }
409
410 double BaseFitObject::getChi2() const
411 {
412 if (not covinvvalid and not calculateCovInv()) return -1;
413 double chi2 = 0;
414 static double resid[BaseDefs::MAXPAR];
415 static bool chi2contr[BaseDefs::MAXPAR];
416 for (int i = 0; i < getNPar(); ++i) {
417 resid[i] = par[i] - mpar[i];
418
419 B2INFO(" BaseFitObject::getChi2() " << i << " " << resid[i] << " " << covinv[i][i])do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "analysis")) { { LogVariableStream varStream
; varStream << " BaseFitObject::getChi2() " << i <<
" " << resid[i] << " " << covinv[i][i]; Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Info, std::move(varStream), "analysis", __PRETTY_FUNCTION__
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 419, 0)); }; } }
while(false)
;
420
421 if ((chi2contr[i] = (isParamMeasured(i) && !isParamFixed(i)))) {
422 chi2 += resid[i] * covinv[i][i] * resid[i];
423 for (int j = 0; j < getNPar(); ++j) {
424 if (j < i && chi2contr[j]) chi2 += 2 * resid[i] * covinv[i][j] * resid[j];
425 }
426 }
427 }
428 return chi2;
429 }
430
431 double BaseFitObject::getDChi2DParam(int ilocal) const
432 {
433 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 433, __extension__
__PRETTY_FUNCTION__))
;
434 if (isParamFixed(ilocal) || !isParamMeasured(ilocal)) return 0;
435
436 if (not covinvvalid and not calculateCovInv()) return 0;
437
438 double result = 0;
439 for (int jlocal = 0; jlocal < getNPar(); jlocal++)
440 if (!isParamFixed(jlocal) && isParamMeasured(jlocal))
441 result += covinv[ilocal][jlocal] * (par[jlocal] - mpar[jlocal]);
442 return 2 * result;
443 }
444
445 double BaseFitObject::getD2Chi2DParam2(int ilocal, int jlocal) const
446 {
447 assert(ilocal >= 0 && ilocal < getNPar())(static_cast <bool> (ilocal >= 0 && ilocal <
getNPar()) ? void (0) : __assert_fail ("ilocal >= 0 && ilocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 447, __extension__
__PRETTY_FUNCTION__))
;
448 assert(jlocal >= 0 && jlocal < getNPar())(static_cast <bool> (jlocal >= 0 && jlocal <
getNPar()) ? void (0) : __assert_fail ("jlocal >= 0 && jlocal < getNPar()"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 448, __extension__
__PRETTY_FUNCTION__))
;
449 if (isParamFixed(ilocal) || !isParamMeasured(ilocal) ||
450 isParamFixed(jlocal) || !isParamMeasured(jlocal))
451 return 0;
452 if (not covinvvalid and not calculateCovInv()) return 0;
453 return 2 * covinv[ilocal][jlocal]; // JL: ok in absence of soft constraints
454 }
455
456
457
458 void BaseFitObject::addToGlobalChi2DerMatrix(double* M, int idim) const
459 {
460 if (!covinvvalid) calculateCovInv();
461 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
462 if (!isParamFixed(ilocal) && isParamMeasured(ilocal)) {
463 int iglobal = getGlobalParNum(ilocal);
464 assert(iglobal >= 0 && iglobal < idim)(static_cast <bool> (iglobal >= 0 && iglobal
< idim) ? void (0) : __assert_fail ("iglobal >= 0 && iglobal < idim"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 464, __extension__
__PRETTY_FUNCTION__))
;
465 int ioffs = idim * iglobal;
466 for (int jlocal = 0; jlocal < getNPar(); ++jlocal) {
467 if (!isParamFixed(jlocal) && isParamMeasured(jlocal)) {
468 int jglobal = getGlobalParNum(jlocal);
469 assert(jglobal >= 0 && jglobal < idim)(static_cast <bool> (jglobal >= 0 && jglobal
< idim) ? void (0) : __assert_fail ("jglobal >= 0 && jglobal < idim"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 469, __extension__
__PRETTY_FUNCTION__))
;
470 M[ioffs + jglobal] += getD2Chi2DParam2(ilocal, jlocal);
471 }
472 }
473 }
474 }
475 }
476
477
478 int BaseFitObject::addToGlobalChi2DerVector(double* y, int idim) const
479 {
480 // This adds the dChi2/dpar piece
481 assert(getNPar() <= BaseDefs::MAXPAR)(static_cast <bool> (getNPar() <= BaseDefs::MAXPAR) ?
void (0) : __assert_fail ("getNPar() <= BaseDefs::MAXPAR"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 481, __extension__
__PRETTY_FUNCTION__))
;
482 if (not covinvvalid and not calculateCovInv()) return 0;
483 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
484 if (!isParamFixed(ilocal) && isParamMeasured(ilocal)) {
485 int iglobal = getGlobalParNum(ilocal);
486 assert(iglobal >= 0 && iglobal < idim)(static_cast <bool> (iglobal >= 0 && iglobal
< idim) ? void (0) : __assert_fail ("iglobal >= 0 && iglobal < idim"
, "analysis/OrcaKinFit/src/BaseFitObject.cc", 486, __extension__
__PRETTY_FUNCTION__))
;
487 y[iglobal] += getDChi2DParam(ilocal);
488 }
489 }
490 return 0;
491 }
492
493
494 void BaseFitObject::addToGlobalChi2DerVector(double* y, int idim,
495 double lambda, double der[], int metaSet) const
496 {
497 // This adds the lambda * dConst/dpar piece
498 if (!cachevalid) updateCache();
499 for (int ilocal = 0; ilocal < getNPar(); ilocal++) {
500 int iglobal = globalParNum[ilocal];
501 if (iglobal >= 0) {
502 assert(iglobal < idim)(static_cast <bool> (iglobal < idim) ? void (0) : __assert_fail
("iglobal < idim", "analysis/OrcaKinFit/src/BaseFitObject.cc"
, 502, __extension__ __PRETTY_FUNCTION__))
;
503 for (int j = 0; j < BaseDefs::nMetaVars[metaSet]; j++) {
504 y[iglobal] += lambda * der[j] * getFirstDerivative_Meta_Local(j, ilocal, metaSet);
505 }
506 }
507 }
508 }
509
510
511 void BaseFitObject::addTo1stDerivatives(double M[], int idim,
512 double der[], int kglobal, int metaSet) const
513 {
514 if (!cachevalid) updateCache();
515 for (int ilocal = 0; ilocal < getNPar(); ilocal++) {
516 int iglobal = globalParNum[ilocal];
517 if (iglobal >= 0) {
518 for (int j = 0; j < BaseDefs::nMetaVars[metaSet]; j++) {
519 double x = der[j] * getFirstDerivative_Meta_Local(j, ilocal, metaSet);
520 M[idim * kglobal + iglobal] += x;
521 M[idim * iglobal + kglobal] += x;
522 }
523 }
524 }
525 return;
526 }
527
528
529
530 void BaseFitObject::addTo2ndDerivatives(double der2[], int idim,
531 double factor[], int metaSet
532 //double efact, double pxfact,
533 //double pyfact, double pzfact
534 ) const
535 {
536 if (!cachevalid) updateCache();
3
Assuming field 'cachevalid' is true
4
Taking false branch
537 for (int ilocal = 0; ilocal < getNPar(); ilocal++) {
5
Assuming the condition is true
6
Loop condition is true. Entering loop body
538 int iglobal = getGlobalParNum(ilocal);
539 if (iglobal < 0) continue;
7
Assuming 'iglobal' is >= 0
8
Taking false branch
540 for (int jlocal = ilocal; jlocal < getNPar(); jlocal++) {
9
Assuming the condition is true
10
Loop condition is true. Entering loop body
541 int jglobal = getGlobalParNum(jlocal);
542 if (jglobal < 0) continue;
11
Assuming 'jglobal' is >= 0
12
Taking false branch
543 double sum(0);
544 for (int imeta = 0; imeta < BaseDefs::nMetaVars[metaSet]; imeta++) {
13
'imeta' initialized to 0
14
Loop condition is true. Entering loop body
545 sum += factor[imeta] * getSecondDerivative_Meta_Local(imeta, ilocal, jlocal, metaSet);
15
The left operand of '*' is a garbage value
546 }
547 der2[idim * iglobal + jglobal] += sum;
548 if (iglobal != jglobal) der2[idim * jglobal + iglobal] += sum;
549 }
550 }
551 return;
552 }
553
554
555 void BaseFitObject::addTo2ndDerivatives(double M[], int idim, double lambda, double der[], int metaSet) const
556 {
557 double factor[BaseDefs::MAXINTERVARS];
558 for (int i = 0; i < BaseDefs::nMetaVars[metaSet]; i++) factor[i] = lambda * der[i];
1
Loop condition is false. Execution continues on line 559
559 addTo2ndDerivatives(M, idim, factor, metaSet);
2
Calling 'BaseFitObject::addTo2ndDerivatives'
560 return;
561 }
562
563// seems not used
564// void BaseFitObject::addToDerivatives (double der[], int idim,
565// double factor[], int metaSet
566// ) const {
567// // DANIEL moved to BaseFitObject
568// if (!cachevalid) updateCache();
569// for (int ilocal=0; ilocal<getNPar(); ilocal++) {
570// int iglobal = globalParNum[ilocal];
571// if ( iglobal >= 0 ) {
572// double der_sum(0);
573// for ( int iInter=0; iInter<BaseDefs::nMetaVars[metaSet]; iInter++) {
574// der_sum += factor[iInter]*getFirstDerivative( iInter , ilocal , metaSet );
575// }
576// der[iglobal] += der_sum;
577// }
578// }
579// return;
580// }
581
582
583 void BaseFitObject::initCov()
584 {
585 for (int i = 0; i < getNPar(); ++i) {
586 for (int j = 0; j < getNPar(); ++j) {
587 cov[i][j] = static_cast<double>(i == j);
588 }
589 }
590 }
591
592
593 double BaseFitObject::getError2(double der[], int metaSet) const
594 {
595 if (!cachevalid) updateCache();
596 double totError(0);
597 for (int i = 0; i < BaseDefs::nMetaVars[metaSet]; i++) {
598 for (int j = 0; j < BaseDefs::nMetaVars[metaSet]; j++) {
599 double cov_i_j = 0; // this will become the covariance of intermediate variables i and j
600 for (int k = 0; k < getNPar(); k++) {
601 for (int l = 0; l < getNPar(); l++) {
602 cov_i_j += getFirstDerivative_Meta_Local(i, k, metaSet) * cov[k][l] * getFirstDerivative_Meta_Local(j, l, metaSet);
603 }
604 }
605 totError += der[i] * der[j] * cov_i_j;
606 }
607 }
608 return totError;
609 }
610
611 }// end OrcaKinFit namespace
612} // end Belle2 namespace