Belle II Software  release-08-01-10
SoftGaussMomentumConstraint.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/SoftGaussMomentumConstraint.h"
18 #include "analysis/OrcaKinFit/ParticleFitObject.h"
19 
20 #include<iostream>
21 #include<cmath>
22 #undef NDEBUG
23 #include<cassert>
24 
25 namespace Belle2 {
30  namespace OrcaKinFit {
31 
32 // constructor
33  SoftGaussMomentumConstraint::SoftGaussMomentumConstraint(double sigma_, double efact_, double pxfact_,
34  double pyfact_, double pzfact_, double value_)
36  efact(efact_),
37  pxfact(pxfact_),
38  pyfact(pyfact_),
39  pzfact(pzfact_),
40  value(value_)
41  {}
42 
43 // destructor
45 
46 // calculate current value of constraint function
48  {
49  double totpx = 0;
50  double totpy = 0;
51  double totpz = 0;
52  double totE = 0;
53  for (auto fitobject : fitobjects) {
54  if (pxfact != 0) totpx += fitobject->getPx();
55  if (pyfact != 0) totpy += fitobject->getPy();
56  if (pzfact != 0) totpz += fitobject->getPz();
57  if (efact != 0) totE += fitobject->getE();
58  }
59  return pxfact * totpx + pyfact * totpy + pzfact * totpz + efact * totE - value;
60  }
61 
62 // calculate vector/array of derivatives of this constraint
63 // w.r.t. to ALL parameters of all fitobjects
64 // here: d M /d par(j)
65 // = d M /d p(i) * d p(i) /d par(j)
66 // = +-1/M * p(i) * d p(i) /d par(j)
67  void SoftGaussMomentumConstraint::getDerivatives(int idim, double der[]) const
68  {
69  for (auto fitobject : fitobjects) {
70  for (int ilocal = 0; ilocal < fitobject->getNPar(); ilocal++) {
71  if (!fitobject->isParamFixed(ilocal)) {
72  int iglobal = fitobject->getGlobalParNum(ilocal);
73  assert(iglobal >= 0 && iglobal < idim);
74  double d = 0;
75  if (pxfact != 0) d += pxfact * fitobject->getDPx(ilocal);
76  if (pyfact != 0) d += pyfact * fitobject->getDPy(ilocal);
77  if (pzfact != 0) d += pzfact * fitobject->getDPz(ilocal);
78  if (efact != 0) d += efact * fitobject->getDE(ilocal);
79  der[iglobal] = d;
80  }
81  }
82  }
83  }
84 
85 
86  bool SoftGaussMomentumConstraint::firstDerivatives(int i, double* derivativesf) const
87  {
88  (void) i;
89  derivativesf[0] = efact;
90  derivativesf[1] = pxfact;
91  derivativesf[2] = pyfact;
92  derivativesf[3] = pzfact;
93  return true;
94  }
95 
96  bool SoftGaussMomentumConstraint::secondDerivatives(int i, int j, double* derivativess) const
97  {
98  (void) i;
99  (void) j;
100  (void) derivativess;
101  return false;
102  }
103 
104  }// end OrcaKinFit namespace
106 } // end Belle2 namespace
virtual void getDerivatives(int idim, double der[]) const override
Get first order derivatives.
virtual double getValue() const override
Returns the value of the constraint function.
virtual bool secondDerivatives(int i, int j, double *derivatives) const override
Second derivatives with respect to the 4-vectors of Fit objects i and j; result false if all derivati...
virtual bool firstDerivatives(int i, double *derivatives) const override
First derivatives with respect to the 4-vector of Fit objects i; result false if all derivatives are ...
virtual ~SoftGaussMomentumConstraint()
Virtual destructor.
SoftGaussMomentumConstraint(double sigma_=0, double efact_=0, double pxfact_=0, double pyfact_=0, double pzfact_=0, double value_=0)
Constructor.
Abstract base class for constraints of kinematic fits.
FitObjectContainer fitobjects
The FitObjectContainer.
Abstract base class for different kinds of events.