Belle II Software development
SoftBWParticleConstraint.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#ifdef MARLIN_USE_ROOT
18
19#ifndef __SOFTBWPARTICLECONSTRAINT_H
20#define __SOFTBWPARTICLECONSTRAINT_H
21
22#include "analysis/OrcaKinFit/BaseSoftConstraint.h"
23#include "analysis/OrcaKinFit/BaseFitObject.h"
24
25#include<vector>
26#include<cassert>
27#include<limits>
28
29namespace Belle2 {
34 namespace OrcaKinFit {
35
36 class ParticleFitObject;
37
38// Class SoftBWParticleConstraint:
40
77 class SoftBWParticleConstraint: public BaseSoftConstraint {
78 public:
80 SoftBWParticleConstraint(double gamma_,
81 double emin_ = -std::numeric_limits<double>::infinity(),
82 double emax_ = std::numeric_limits<double>::infinity()
83 );
85 virtual ~SoftBWParticleConstraint() {};
86
88 virtual void setFOList(std::vector <ParticleFitObject*>* fitobjects_
89 )
90 {
91 for (int i = 0; i < (int) fitobjects_->size(); i++) {
92 fitobjects.push_back((*fitobjects_)[i]);
93 flags.push_back(1);
94 }
95 };
97 virtual void addToFOList(ParticleFitObject& fitobject, int flag = 1
98 )
99 {
100 fitobjects.push_back(&fitobject);
101 flags.push_back(flag);
102 };
103
105 virtual double getValue() const override = 0;
106
108 virtual double getChi2() const override;
109
111 virtual double getError() const override;
112
114 virtual double getGamma() const;
115
117 virtual double setGamma(double gamma_
118 );
119
122 virtual void getDerivatives(int idim,
123 double der[]
124 ) const override = 0;
126 virtual void add2ndDerivativesToMatrix(double* M,
127 int idim
128 ) const override;
129
131 virtual void addToGlobalChi2DerVector(double* y,
132 int idim
133 ) const override;
134
135
137 void invalidateCache() const;
138
140 virtual void updateCache() const;
141
143 virtual bool cacheValid() const;
144
145 void test1stDerivatives();
146 void test2ndDerivatives();
147
149 double num1stDerivative(int ifo,
150 int ilocal,
151 double eps
152 );
154 double num2ndDerivative(int ifo1,
155 int ilocal1,
156 double eps1,
157 int ifo2,
158 int ilocal2,
159 double eps2
160 );
161
162
164
168 static double erfinv(double x);
169
170 static double normal_quantile(double x);
171 static double normal_quantile_1stderiv(double x);
172 static double normal_quantile_2ndderiv(double x);
173 static double normal_pdf(double x);
174 static double normal_pdf_deriv(double x);
175
177 double penalty(double e) const;
179 double penalty1stder(double e) const;
181 double penalty2ndder(double e) const;
182
183 int getVarBasis() const;
184
185 protected:
186
188 virtual bool secondDerivatives(int i,
189 int j,
190 double* derivatives
191 ) const = 0;
193 virtual bool firstDerivatives(int i,
194 double* derivatives
195 ) const = 0;
196
197
199 typedef std::vector <ParticleFitObject*> FitObjectContainer;
201 typedef FitObjectContainer::iterator FitObjectIterator;
203 typedef FitObjectContainer::const_iterator ConstFitObjectIterator;
205 FitObjectContainer fitobjects;
207 std::vector <double> derivatives;
210 std::vector <int> flags;
211
213 double gamma;
214 double emin;
215 double emax;
216
217 mutable bool cachevalid;
218 mutable double atanxmin;
219 mutable double atanxmax;
220 mutable double diffatanx;
221
222 enum { VAR_BASIS = BaseDefs::VARBASIS_EPXYZ }; // this means that the constraint knows about E,px,py,pz
223
224 };
225
226 }// end OrcaKinFit namespace
228} // end Belle2 namespace
229
230
231#endif // __SOFTBWPARTICLECONSTRAINT_H
232
233#endif // MARLIN_USE_ROOT
Abstract base class for different kinds of events.