Belle II Software  release-08-01-10
SoftGaussParticleConstraint.h
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 #ifndef __SOFTGAUSSPARTICLECONSTRAINT_H
18 #define __SOFTGAUSSPARTICLECONSTRAINT_H
19 
20 #include<vector>
21 #include<cassert>
22 #include "analysis/OrcaKinFit/BaseSoftConstraint.h"
23 #include "analysis/OrcaKinFit/BaseFitObject.h"
24 
25 namespace Belle2 {
31  namespace OrcaKinFit {
32 
33  class ParticleFitObject;
34 
35 // Class SoftGaussParticleConstraint:
37 
75  public:
77  explicit SoftGaussParticleConstraint(double sigma_
78  );
81 
83  virtual void setFOList(std::vector <ParticleFitObject*>* fitobjects_
84  )
85  {
86  for (int i = 0; i < (int) fitobjects_->size(); i++) {
87  fitobjects.push_back((*fitobjects_)[i]);
88  flags.push_back(1);
89  }
90  };
92  virtual void addToFOList(ParticleFitObject& fitobject, int flag = 1
93  )
94  {
95  fitobjects.push_back(&fitobject);
96  flags.push_back(flag);
97  };
99  virtual void resetFOList()
100  {
101  fitobjects.resize(0);
102  flags.resize(0);
103  };
104 
106  virtual double getValue() const override = 0;
107 
109  virtual double getChi2() const override;
110 
112  virtual double getError() const override;
113 
115  virtual double getSigma() const;
116 
118  virtual double setSigma(double sigma_
119  );
120 
123  virtual void getDerivatives(int idim,
124  double der[]
125  ) const override = 0;
127  virtual void add2ndDerivativesToMatrix(double* M,
128  int idim
129  ) const override;
130 
132  virtual void addToGlobalChi2DerVector(double* y,
133  int idim
134  ) const override;
135 
136 
138  void invalidateCache() const {}
139 
140  void test1stDerivatives();
141  void test2ndDerivatives();
142 
144  double num1stDerivative(int ifo,
145  int ilocal,
146  double eps
147  );
149  double num2ndDerivative(int ifo1,
150  int ilocal1,
151  double eps1,
152  int ifo2,
153  int ilocal2,
154  double eps2
155  );
156 
157  int getVarBasis() const;
158 
159  protected:
160 
162  virtual bool secondDerivatives(int i,
163  int j,
164  double* derivatives
165  ) const = 0;
167  virtual bool firstDerivatives(int i,
168  double* derivatives
169  ) const = 0;
170 
171 
173  typedef std::vector <ParticleFitObject*> FitObjectContainer;
175  typedef FitObjectContainer::iterator FitObjectIterator;
177  typedef FitObjectContainer::const_iterator ConstFitObjectIterator;
181  std::vector <double> derivatives;
184  std::vector <int> flags;
185 
187  double sigma;
188 
189  enum { VAR_BASIS = BaseDefs::VARBASIS_EPXYZ }; // this means that the constraint knows about E,px,py,pz
190 
191  };
192 
193  }// end OrcaKinFit namespace
195 } // end Belle2 namespace
196 
197 #endif // __SOFTGAUSSPARTICLECONSTRAINT_H
Abstract base class for soft constraints of kinematic fits.
Abstract base class for constraints of kinematic fits.
FitObjectContainer::iterator FitObjectIterator
Iterator through vector of pointers to ParticleFitObjects.
virtual double getValue() const override=0
Returns the value of the constraint function.
FitObjectContainer fitobjects
The FitObjectContainer.
virtual void add2ndDerivativesToMatrix(double *M, int idim) const override
Adds second order derivatives to global covariance matrix M.
virtual double getError() const override
Returns the error on the value of the constraint.
virtual void addToGlobalChi2DerVector(double *y, int idim) const override
Add derivatives of chi squared to global derivative matrix.
virtual bool secondDerivatives(int i, int j, double *derivatives) const =0
Second derivatives with respect to the 4-vectors of Fit objects i and j; result false if all derivati...
virtual void getDerivatives(int idim, double der[]) const override=0
Get first order derivatives.
virtual bool firstDerivatives(int i, double *derivatives) const =0
First derivatives with respect to the 4-vector of Fit objects i; result false if all derivatives are ...
virtual void addToFOList(ParticleFitObject &fitobject, int flag=1)
Adds one ParticleFitObject objects to the list.
void invalidateCache() const
Invalidates any cached values for the next event.
virtual double setSigma(double sigma_)
Sets the sigma.
std::vector< ParticleFitObject * > FitObjectContainer
Vector of pointers to ParticleFitObjects.
virtual double getSigma() const
Returns the sigma.
SoftGaussParticleConstraint(double sigma_)
Creates an empty SoftGaussParticleConstraint object.
FitObjectContainer::const_iterator ConstFitObjectIterator
Constant iterator through vector of pointers to ParticleFitObjects.
virtual void setFOList(std::vector< ParticleFitObject * > *fitobjects_)
Adds several ParticleFitObject objects to the list.
double num2ndDerivative(int ifo1, int ilocal1, double eps1, int ifo2, int ilocal2, double eps2)
Evaluates numerically the 2nd derivative w.r.t. 2 parameters.
std::vector< int > flags
The flags can be used to divide the FitObjectContainer into several subsets used for example to imple...
virtual double getChi2() const override
Returns the chi2.
double num1stDerivative(int ifo, int ilocal, double eps)
Evaluates numerically the 1st derivative w.r.t. a parameter.
virtual void resetFOList()
Resests ParticleFitObject list.
Abstract base class for different kinds of events.