Belle II Software  release-05-01-25
SoftGaussMomentumConstraint.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * See https://github.com/tferber/OrcaKinfit, forked from *
4  * https://github.com/iLCSoft/MarlinKinfit *
5  * *
6  * Further information about the fit engine and the user interface *
7  * provided in MarlinKinfit can be found at *
8  * https://www.desy.de/~blist/kinfit/doc/html/ *
9  * and in the LCNotes LC-TOOL-2009-001 and LC-TOOL-2009-004 available *
10  * from http://www-flc.desy.de/lcnotes/ *
11  * *
12  * Adopted by: Torben Ferber (torben.ferber@desy.de) (TF) *
13  * *
14  * This software is provided "as is" without any warranty. *
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_)
35  : SoftGaussParticleConstraint(sigma_),
36  efact(efact_),
37  pxfact(pxfact_),
38  pyfact(pyfact_),
39  pzfact(pzfact_),
40  value(value_)
41  {}
42 
43 // destructor
45 
46 // calulate 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 contraint
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
Belle2::OrcaKinFit::SoftGaussMomentumConstraint::firstDerivatives
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 ...
Definition: SoftGaussMomentumConstraint.cc:100
Belle2::OrcaKinFit::SoftGaussMomentumConstraint::getValue
virtual double getValue() const override
Returns the value of the constraint function.
Definition: SoftGaussMomentumConstraint.cc:61
Belle2::OrcaKinFit::SoftGaussParticleConstraint::fitobjects
FitObjectContainer fitobjects
The FitObjectContainer.
Definition: SoftGaussParticleConstraint.h:193
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::OrcaKinFit::SoftGaussMomentumConstraint::~SoftGaussMomentumConstraint
virtual ~SoftGaussMomentumConstraint()
Virtual destructor.
Belle2::OrcaKinFit::SoftGaussMomentumConstraint::getDerivatives
virtual void getDerivatives(int idim, double der[]) const override
Get first order derivatives.
Definition: SoftGaussMomentumConstraint.cc:81
Belle2::OrcaKinFit::SoftGaussMomentumConstraint::SoftGaussMomentumConstraint
SoftGaussMomentumConstraint(double sigma_=0, double efact_=0, double pxfact_=0, double pyfact_=0, double pzfact_=0, double value_=0)
Constructor.
Definition: SoftGaussMomentumConstraint.cc:47
Belle2::OrcaKinFit::SoftGaussMomentumConstraint::secondDerivatives
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...
Definition: SoftGaussMomentumConstraint.cc:110