Belle II Software development
NeutrinoFitObject Class Reference
Inheritance diagram for NeutrinoFitObject:
ParticleFitObject BaseFitObject

Public Member Functions

 NeutrinoFitObject (double E, double theta, double phi, double DE=1, double Dtheta=0.1, double Dphi=0.1)
 
 NeutrinoFitObject (const NeutrinoFitObject &rhs)
 Copy constructor.
 
NeutrinoFitObjectoperator= (const NeutrinoFitObject &rhs)
 Assignment.
 
virtual NeutrinoFitObjectcopy () const override
 Return a new copy of itself.
 
virtual NeutrinoFitObjectassign (const BaseFitObject &source) override
 Assign from anther object, if of same type.
 
virtual const char * getParamName (int ilocal) const override
 Get name of parameter ilocal.
 
virtual bool updateParams (double p[], int idim) override
 Read values from global vector, readjust vector; return: significant change.
 
virtual double getDPx (int ilocal) const override
 Return d p_x / d par_ilocal (derivative of px w.r.t. local parameter ilocal)
 
virtual double getDPy (int ilocal) const override
 Return d p_y / d par_ilocal (derivative of py w.r.t. local parameter ilocal)
 
virtual double getDPz (int ilocal) const override
 Return d p_z / d par_ilocal (derivative of pz w.r.t. local parameter ilocal)
 
virtual double getDE (int ilocal) const override
 Return d E / d par_ilocal (derivative of E w.r.t. local parameter ilocal)
 
virtual double getFirstDerivative_Meta_Local (int iMeta, int ilocal, int metaSet) const override
 
virtual double getSecondDerivative_Meta_Local (int iMeta, int ilocal, int jlocal, int metaSet) const override
 
virtual int getNPar () const override
 Get total number of parameters of this FitObject.
 
virtual bool setMass (double mass_)
 Set mass of particle; return=success.
 
virtual double getMass () const
 Get mass of particle.
 
virtual std::ostream & print4Vector (std::ostream &os) const
 print the four-momentum (E, px, py, pz)
 
virtual FourVector getFourMomentum () const
 
virtual double getE () const
 Return E.
 
virtual double getPx () const
 Return px.
 
virtual double getPy () const
 Return py.
 
virtual double getPz () const
 Return pz.
 
virtual double getP () const
 Return p (momentum)
 
virtual double getP2 () const
 Return p (momentum) squared.
 
virtual double getPt () const
 Return pt (transverse momentum)
 
virtual double getPt2 () const
 Return pt (transverse momentum) squared.
 
virtual void getDerivatives (double der[], int idim) const override
 
virtual void addToGlobalChi2DerMatrixNum (double *M, int idim, double eps)
 Add numerically determined derivatives of chi squared to global covariance matrix.
 
virtual void addToGlobalChi2DerVectorNum (double *y, int idim, double eps)
 Add numerically determined derivatives of chi squared to global derivative vector.
 
virtual std::ostream & print (std::ostream &os) const override
 print object to ostream
 
void test1stDerivatives ()
 
void test2ndDerivatives ()
 
double num1stDerivative (int ilocal, double eps)
 Evaluates numerically the 1st derivative of chi2 w.r.t. a parameter.
 
double num2ndDerivative (int ilocal1, double eps1, int ilocal2, double eps2)
 Evaluates numerically the 2nd derivative of chi2 w.r.t. 2 parameters.
 
virtual double getChi2 () const override
 Get chi squared from measured and fitted parameters.
 
virtual bool setParam (int ilocal, double par_, bool measured_, bool fixed_=false)
 Set value and measured flag of parameter i; return: significant change.
 
virtual bool setParam (int ilocal, double par_)
 Set value of parameter ilocal; return: significant change.
 
virtual bool setMParam (int ilocal, double mpar_)
 Set measured value of parameter ilocal; return: success.
 
virtual bool setError (int ilocal, double err_)
 Set error of parameter ilocal; return: success.
 
virtual bool setCov (int ilocal, int jlocal, double cov_)
 Set covariance of parameters ilocal and jlocal; return: success.
 
virtual bool setGlobalParNum (int ilocal, int iglobal)
 Set number of parameter ilocal in global list return true signals OK.
 
virtual bool fixParam (int ilocal, bool fix=true)
 Fix a parameter (fix=true), or release it (fix=false)
 
virtual bool releaseParam (int ilocal)
 Release a parameter.
 
virtual bool isParamFixed (int ilocal) const
 Returns whether parameter is fixed.
 
virtual double getParam (int ilocal) const
 Get current value of parameter ilocal.
 
virtual const char * getName () const
 Get object's name.
 
void setName (const char *name_)
 Set object's name.
 
virtual double getMParam (int ilocal) const
 Get measured value of parameter ilocal.
 
virtual double getError (int ilocal) const
 Get error of parameter ilocal.
 
virtual double getCov (int ilocal, int jlocal) const
 Get covariance between parameters ilocal and jlocal.
 
virtual double getRho (int ilocal, int jlocal) const
 Get correlation coefficient between parameters ilocal and jlocal.
 
virtual bool isParamMeasured (int ilocal) const
 Get measured flag for parameter ilocal.
 
virtual int getGlobalParNum (int ilocal) const
 Get global parameter number of parameter ilocal.
 
virtual int getNMeasured () const
 Get number of measured parameters of this FitObject.
 
virtual int getNUnmeasured () const
 Get number of unmeasured parameters of this FitObject.
 
virtual int getNFree () const
 Get number of free parameters of this FitObject.
 
virtual int getNFixed () const
 Get number of fixed parameters of this FitObject.
 
virtual double getDChi2DParam (int ilocal) const
 Get derivative of chi squared w.r.t. parameter ilocal.
 
virtual double getD2Chi2DParam2 (int ilocal, int jlocal) const
 Get second derivative of chi squared w.r.t. parameters ilocal1 and ilocal2.
 
virtual std::ostream & printParams (std::ostream &os) const
 print the parameters and errors
 
virtual std::ostream & printRhoValues (std::ostream &os) const
 print the correlation coefficients
 
virtual std::ostream & print1stDerivatives (std::ostream &os) const
 print the 1st derivatives wrt metaSet 0 (E, px, py, pz)
 
virtual std::ostream & print2ndDerivatives (std::ostream &os) const
 print the 2nd derivatives wrt metaSet 0 (E, px, py, pz)
 
void invalidateCache () const
 invalidate any cached quantities
 
virtual void addToGlobCov (double *glcov, int idim) const
 Add covariance matrix elements to global covariance matrix of size idim x idim.
 
virtual int addToGlobalChi2DerVector (double *y, int idim) const
 Add derivatives of chi squared to global derivative vector.
 
virtual void addToGlobalChi2DerVector (double *y, int idim, double lambda, double der[], int metaSet) const
 Add derivatives of momentum vector to global derivative vector.
 
virtual void addToGlobalChi2DerMatrix (double *M, int idim) const
 Add 2nd derivatives of chi squared to global derivative matrix.
 
virtual void addTo1stDerivatives (double M[], int idim, double der[], int kglobal, int metaSet) const
 
virtual void addTo2ndDerivatives (double der2[], int idim, double factor[], int metaSet) const
 
virtual void addTo2ndDerivatives (double M[], int idim, double lambda, double der[], int metaSet) const
 
virtual void initCov ()
 
virtual double getError2 (double der[], int metaset) const
 

Protected Types

enum  { NPAR = 3 }
 

Protected Member Functions

void updateCache () const override
 
virtual bool calculateCovInv () const
 Calculate the inverse of the covariance matrix.
 

Protected Attributes

double ctheta
 
double stheta
 
double cphi
 
double sphi
 
double pt
 
double px
 
double py
 
double pz
 
double dptdE
 
double dpxdE
 
double dpydE
 
double dpxdtheta
 
double dpydtheta
 
double chi2
 
double mass
 mass of particle
 
FourVector fourMomentum
 
double paramCycl [BaseDefs::MAXPAR]
 
char * name
 
double par [BaseDefs::MAXPAR]
 fit parameters
 
double mpar [BaseDefs::MAXPAR]
 measured parameters
 
bool measured [BaseDefs::MAXPAR]
 measured flag
 
bool fixed [BaseDefs::MAXPAR]
 fixed flag
 
int globalParNum [BaseDefs::MAXPAR]
 global parameter number for each parameter
 
double cov [BaseDefs::MAXPAR][BaseDefs::MAXPAR]
 local covariance matrix
 
double covinv [BaseDefs::MAXPAR][BaseDefs::MAXPAR]
 inverse pf local covariance matrix
 
bool covinvvalid
 flag for valid inverse covariance matrix
 
bool cachevalid
 flag for valid cache
 

Static Protected Attributes

static const double eps2 = 0.0001
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const BaseFitObject &bfo)
 Prints out a BaseFitObject, using its print method.
 

Detailed Description

Definition at line 31 of file NeutrinoFitObject.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

Definition at line 75 of file NeutrinoFitObject.h.

75{NPAR = 3};

Constructor & Destructor Documentation

◆ NeutrinoFitObject() [1/2]

NeutrinoFitObject ( double  E,
double  theta,
double  phi,
double  DE = 1,
double  Dtheta = 0.1,
double  Dphi = 0.1 
)

Definition at line 38 of file NeutrinoFitObject.cc.

40 : ctheta(0), stheta(0), cphi(0), sphi(0), pt(0), px(0), py(0), pz(0), dptdE(0),
41 dpxdE(0), dpydE(0), dpxdtheta(0), dpydtheta(0), chi2(0)
42 {
43
44 assert(int(NPAR) <= int(BaseDefs::MAXPAR));
45
46 setMass(0);
47 setParam(0, E, false);
48 setParam(1, theta, false);
49 setParam(2, phi, false);
50 setError(0, DE);
51 setError(1, Dtheta);
52 setError(2, Dphi);
54 }
R E
internal precision of FFTW codelets
virtual bool setParam(int ilocal, double par_, bool measured_, bool fixed_=false)
Set value and measured flag of parameter i; return: significant change.
void invalidateCache() const
invalidate any cached quantities
virtual bool setError(int ilocal, double err_)
Set error of parameter ilocal; return: success.
virtual bool setMass(double mass_)
Set mass of particle; return=success.

◆ NeutrinoFitObject() [2/2]

Copy constructor.

Parameters
rhsright hand side

Definition at line 59 of file NeutrinoFitObject.cc.

60 : ParticleFitObject(rhs), ctheta(0), stheta(0), cphi(0), sphi(0), pt(0), px(0), py(0), pz(0), dptdE(0),
61 dpxdE(0), dpydE(0), dpxdtheta(0), dpydtheta(0), chi2(0)
62 {
64 }
virtual NeutrinoFitObject & assign(const BaseFitObject &source) override
Assign from anther object, if of same type.

Member Function Documentation

◆ addTo1stDerivatives()

void addTo1stDerivatives ( double  M[],
int  idim,
double  der[],
int  kglobal,
int  metaSet 
) const
virtualinherited

Definition at line 515 of file BaseFitObject.cc.

517 {
518 if (!cachevalid) updateCache();
519 for (int ilocal = 0; ilocal < getNPar(); ilocal++) {
520 int iglobal = globalParNum[ilocal];
521 if (iglobal >= 0) {
522 for (int j = 0; j < BaseDefs::nMetaVars[metaSet]; j++) {
523 double x = der[j] * getFirstDerivative_Meta_Local(j, ilocal, metaSet);
524 M[idim * kglobal + iglobal] += x;
525 M[idim * iglobal + kglobal] += x;
526 }
527 }
528 }
529 return;
530 }
virtual int getNPar() const =0
Get total number of parameters of this FitObject.
bool cachevalid
flag for valid cache
int globalParNum[BaseDefs::MAXPAR]
global parameter number for each parameter

◆ addTo2ndDerivatives() [1/2]

void addTo2ndDerivatives ( double  der2[],
int  idim,
double  factor[],
int  metaSet 
) const
virtualinherited

Definition at line 534 of file BaseFitObject.cc.

539 {
540 if (!cachevalid) updateCache();
541 for (int ilocal = 0; ilocal < getNPar(); ilocal++) {
542 int iglobal = getGlobalParNum(ilocal);
543 if (iglobal < 0) continue;
544 for (int jlocal = ilocal; jlocal < getNPar(); jlocal++) {
545 int jglobal = getGlobalParNum(jlocal);
546 if (jglobal < 0) continue;
547 double sum(0);
548 for (int imeta = 0; imeta < BaseDefs::nMetaVars[metaSet]; imeta++) {
549 sum += factor[imeta] * getSecondDerivative_Meta_Local(imeta, ilocal, jlocal, metaSet);
550 }
551 der2[idim * iglobal + jglobal] += sum;
552 if (iglobal != jglobal) der2[idim * jglobal + iglobal] += sum;
553 }
554 }
555 return;
556 }
virtual int getGlobalParNum(int ilocal) const
Get global parameter number of parameter ilocal.

◆ addTo2ndDerivatives() [2/2]

void addTo2ndDerivatives ( double  M[],
int  idim,
double  lambda,
double  der[],
int  metaSet 
) const
virtualinherited

Definition at line 559 of file BaseFitObject.cc.

560 {
561 double factor[BaseDefs::MAXINTERVARS];
562 for (int i = 0; i < BaseDefs::nMetaVars[metaSet]; i++) factor[i] = lambda * der[i];
563 addTo2ndDerivatives(M, idim, factor, metaSet);
564 return;
565 }

◆ addToGlobalChi2DerMatrix()

void addToGlobalChi2DerMatrix ( double *  M,
int  idim 
) const
virtualinherited

Add 2nd derivatives of chi squared to global derivative matrix.

Parameters
MGlobal derivative matrix
idimFirst dimension of global derivative matrix

Definition at line 462 of file BaseFitObject.cc.

463 {
465 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
466 if (!isParamFixed(ilocal) && isParamMeasured(ilocal)) {
467 int iglobal = getGlobalParNum(ilocal);
468 assert(iglobal >= 0 && iglobal < idim);
469 int ioffs = idim * iglobal;
470 for (int jlocal = 0; jlocal < getNPar(); ++jlocal) {
471 if (!isParamFixed(jlocal) && isParamMeasured(jlocal)) {
472 int jglobal = getGlobalParNum(jlocal);
473 assert(jglobal >= 0 && jglobal < idim);
474 M[ioffs + jglobal] += getD2Chi2DParam2(ilocal, jlocal);
475 }
476 }
477 }
478 }
479 }
bool covinvvalid
flag for valid inverse covariance matrix
virtual double getD2Chi2DParam2(int ilocal, int jlocal) const
Get second derivative of chi squared w.r.t. parameters ilocal1 and ilocal2.
virtual bool isParamFixed(int ilocal) const
Returns whether parameter is fixed.
virtual bool calculateCovInv() const
Calculate the inverse of the covariance matrix.
virtual bool isParamMeasured(int ilocal) const
Get measured flag for parameter ilocal.

◆ addToGlobalChi2DerMatrixNum()

void addToGlobalChi2DerMatrixNum ( double *  M,
int  idim,
double  eps 
)
virtualinherited

Add numerically determined derivatives of chi squared to global covariance matrix.

Parameters
MGlobal covariance matrix
idimFirst dimension of global covariance matrix
epsParameter variation

Definition at line 162 of file ParticleFitObject.cc.

163 {
164 for (int ilocal1 = 0; ilocal1 < getNPar(); ++ilocal1) {
165 int iglobal1 = getGlobalParNum(ilocal1);
166 for (int ilocal2 = ilocal1; ilocal2 < getNPar(); ++ilocal2) {
167 int iglobal2 = getGlobalParNum(ilocal2);
168 M[idim * iglobal1 + iglobal2] += num2ndDerivative(ilocal1, eps, ilocal2, eps);
169 }
170 }
171 }
double num2ndDerivative(int ilocal1, double eps1, int ilocal2, double eps2)
Evaluates numerically the 2nd derivative of chi2 w.r.t. 2 parameters.

◆ addToGlobalChi2DerVector() [1/2]

int addToGlobalChi2DerVector ( double *  y,
int  idim 
) const
virtualinherited

Add derivatives of chi squared to global derivative vector.

Parameters
yVector of chi2 derivatives
idimVector size

Definition at line 482 of file BaseFitObject.cc.

483 {
484 // This adds the dChi2/dpar piece
485 assert(getNPar() <= BaseDefs::MAXPAR);
486 if (not covinvvalid and not calculateCovInv()) return 0;
487 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
488 if (!isParamFixed(ilocal) && isParamMeasured(ilocal)) {
489 int iglobal = getGlobalParNum(ilocal);
490 assert(iglobal >= 0 && iglobal < idim);
491 y[iglobal] += getDChi2DParam(ilocal);
492 }
493 }
494 return 0;
495 }
virtual double getDChi2DParam(int ilocal) const
Get derivative of chi squared w.r.t. parameter ilocal.

◆ addToGlobalChi2DerVector() [2/2]

void addToGlobalChi2DerVector ( double *  y,
int  idim,
double  lambda,
double  der[],
int  metaSet 
) const
virtualinherited

Add derivatives of momentum vector to global derivative vector.

Parameters
yVector of chi2 derivatives
idimVector size
lambdaThe lambda value
derderivatives of constraint wrt intermediate variables (e.g. 4-vector with dg/dE, dg/dpx, dg/dpy, dg/dpz)
metaSetwhich set of intermediate variables

Definition at line 498 of file BaseFitObject.cc.

500 {
501 // This adds the lambda * dConst/dpar piece
502 if (!cachevalid) updateCache();
503 for (int ilocal = 0; ilocal < getNPar(); ilocal++) {
504 int iglobal = globalParNum[ilocal];
505 if (iglobal >= 0) {
506 assert(iglobal < idim);
507 for (int j = 0; j < BaseDefs::nMetaVars[metaSet]; j++) {
508 y[iglobal] += lambda * der[j] * getFirstDerivative_Meta_Local(j, ilocal, metaSet);
509 }
510 }
511 }
512 }

◆ addToGlobalChi2DerVectorNum()

void addToGlobalChi2DerVectorNum ( double *  y,
int  idim,
double  eps 
)
virtualinherited

Add numerically determined derivatives of chi squared to global derivative vector.

Parameters
yVector of chi2 derivatives
idimVector size
epsParameter variation

Definition at line 152 of file ParticleFitObject.cc.

153 {
154 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
155 int iglobal = getGlobalParNum(ilocal);
156 assert(iglobal >= 0 && iglobal < idim);
157 y[iglobal] += num1stDerivative(ilocal, eps);
158 }
159 }
double num1stDerivative(int ilocal, double eps)
Evaluates numerically the 1st derivative of chi2 w.r.t. a parameter.

◆ addToGlobCov()

void addToGlobCov ( double *  glcov,
int  idim 
) const
virtualinherited

Add covariance matrix elements to global covariance matrix of size idim x idim.

Parameters
glcovGlobal covariance matrix
idimFirst dimension of global derivative matrix

Definition at line 217 of file BaseFitObject.cc.

218 {
219 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
220 if (!isParamFixed(ilocal) && isParamMeasured(ilocal)) {
221 int iglobal = getGlobalParNum(ilocal);
222 assert(iglobal >= 0 && iglobal < idim);
223 int ioffs = idim * iglobal;
224 for (int jlocal = 0; jlocal < getNPar(); ++jlocal) {
225 if (!isParamFixed(jlocal) && isParamMeasured(jlocal)) {
226 int jglobal = getGlobalParNum(jlocal);
227 assert(jglobal >= 0 && jglobal < idim);
228 globCov[ioffs + jglobal] += getCov(ilocal, jlocal);
229 }
230 }
231 }
232 }
233 }
virtual double getCov(int ilocal, int jlocal) const
Get covariance between parameters ilocal and jlocal.

◆ assign()

NeutrinoFitObject & assign ( const BaseFitObject source)
overridevirtual

Assign from anther object, if of same type.

Parameters
sourceThe source object

Reimplemented from ParticleFitObject.

Definition at line 79 of file NeutrinoFitObject.cc.

80 {
81 if (const auto* psource = dynamic_cast<const NeutrinoFitObject*>(&source)) {
82 if (psource != this) {
84 // only mutable data members, need not to be copied, if cache is invalid
85 }
86 } else {
87 assert(0);
88 }
89 return *this;
90 }
virtual ParticleFitObject & assign(const BaseFitObject &source) override
Assign from anther object, if of same type.

◆ calculateCovInv()

bool calculateCovInv ( ) const
protectedvirtualinherited

Calculate the inverse of the covariance matrix.

Definition at line 235 of file BaseFitObject.cc.

236 {
237
238 // DANIEL added
239
240 int n = getNPar();
241
242 gsl_matrix* covm = gsl_matrix_alloc(n, n);
243 gsl_matrix_set_identity(covm);
244
245 for (int i = 0; i < n; ++i) {
246 if (isParamMeasured(i)) {
247 for (int j = 0; j < n; ++j) {
248 if (isParamMeasured(j)) {
249 gsl_matrix_set(covm, i, j, cov[i][j]);
250 }
251 }
252 }
253 }
254 gsl_error_handler_t* e = gsl_set_error_handler_off();
255 int result = gsl_linalg_cholesky_decomp(covm);
256 if (result == 0) result = gsl_linalg_cholesky_invert(covm);
257 gsl_set_error_handler(e);
258
259 for (int i = 0; i < n; ++i) {
260 for (int j = 0; j < i; ++j) {
261 covinv[i][j] = covinv[j][i] = gsl_matrix_get(covm, i, j);
262 }
263 covinv[i][i] = gsl_matrix_get(covm, i, i);
264 }
265
266 gsl_matrix_free(covm);
267 covinvvalid = (result == 0);
268
269 if (!covinvvalid) {
270 B2WARNING("ERROR, COULD NOT INVERT COV MATR!");
271
272 B2INFO("COV ");
273 for (int i = 0; i < n; ++i) {
274 if (isParamMeasured(i)) {
275 for (int j = 0; j < n; ++j) {
276 if (isParamMeasured(j)) {
277 B2INFO(cov[i][j] << " ");
278 }
279 }
280 }
281 }
282
283 B2INFO("CORREL ");
284 for (int i = 0; i < n; ++i) {
285 if (isParamMeasured(i)) {
286 for (int j = 0; j < n; ++j) {
287 if (isParamMeasured(j)) {
288 B2INFO(cov[i][j] / sqrt(cov[i][i]*cov[j][j]) << " ");
289 }
290 }
291 }
292 }
293
294 }
295
296 return covinvvalid;
297 }
double covinv[BaseDefs::MAXPAR][BaseDefs::MAXPAR]
inverse pf local covariance matrix
double cov[BaseDefs::MAXPAR][BaseDefs::MAXPAR]
local covariance matrix
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28

◆ copy()

NeutrinoFitObject * copy ( ) const
overridevirtual

Return a new copy of itself.

Implements BaseFitObject.

Definition at line 74 of file NeutrinoFitObject.cc.

75 {
76 return new NeutrinoFitObject(*this);
77 }

◆ fixParam()

bool fixParam ( int  ilocal,
bool  fix = true 
)
virtualinherited

Fix a parameter (fix=true), or release it (fix=false)

Parameters
ilocalLocal parameter number
fixfix if true, release if false

Definition at line 352 of file BaseFitObject.cc.

353 {
354 assert(ilocal >= 0 && ilocal < getNPar());
355 return fixed [ilocal] = fix;
356 }
bool fixed[BaseDefs::MAXPAR]
fixed flag

◆ getChi2()

double getChi2 ( ) const
overridevirtualinherited

Get chi squared from measured and fitted parameters.

Reimplemented from BaseFitObject.

Definition at line 276 of file ParticleFitObject.cc.

277 {
278 // reimplemented here to take account of cyclical variables e.g azimuthal angle phi - DJeans
279
280 if (not covinvvalid and not calculateCovInv()) return 0;
281
282 double resid[BaseDefs::MAXPAR] = {0};
283 for (int i = 0; i < getNPar(); i++) {
284 if (isParamMeasured(i) && !isParamFixed(i)) {
285 resid[i] = par[i] - mpar[i];
286 if (paramCycl[i] > 0) {
287 resid[i] = fmod(resid[i], paramCycl[i]);
288 if (resid[i] > paramCycl[i] / 2) resid[i] -= paramCycl[i];
289 if (resid[i] < -paramCycl[i] / 2) resid[i] += paramCycl[i];
290 }
291 }
292 }
293
294
295 double chi2 = 0;
296 for (int i = 0; i < getNPar(); i++) {
297 if (isParamMeasured(i) && !isParamFixed(i)) {
298 for (int j = 0; j < getNPar(); j++) {
299 if (isParamMeasured(j) && !isParamFixed(j)) {
300 chi2 += resid[i] * covinv[i][j] * resid[j];
301 // B2INFO( getName () << " === " << i << " " << j << " : " <<
302 // resid[i] << "*" << covinv[i][j] << "*" << resid[j] << " = " << resid[i]*covinv[i][j]*resid[j] << " , sum " << chi2);
303 }
304 }
305 }
306 }
307
308 // B2INFO("ParticleFitObject::getChi2 () chi2 = " << chi2 );
309 return chi2;
310 }
double par[BaseDefs::MAXPAR]
fit parameters
double mpar[BaseDefs::MAXPAR]
measured parameters

◆ getCov()

double getCov ( int  ilocal,
int  jlocal 
) const
virtualinherited

Get covariance between parameters ilocal and jlocal.

Parameters
ilocalLocal parameter number i
jlocalLocal parameter number j

Reimplemented in JetFitObject.

Definition at line 389 of file BaseFitObject.cc.

390 {
391 assert(ilocal >= 0 && ilocal < getNPar());
392 assert(jlocal >= 0 && jlocal < getNPar());
393 return cov[ilocal][jlocal];
394 }

◆ getD2Chi2DParam2()

double getD2Chi2DParam2 ( int  ilocal,
int  jlocal 
) const
virtualinherited

Get second derivative of chi squared w.r.t. parameters ilocal1 and ilocal2.

Parameters
ilocalLocal parameter number i
jlocalLocal parameter number j

Definition at line 449 of file BaseFitObject.cc.

450 {
451 assert(ilocal >= 0 && ilocal < getNPar());
452 assert(jlocal >= 0 && jlocal < getNPar());
453 if (isParamFixed(ilocal) || !isParamMeasured(ilocal) ||
454 isParamFixed(jlocal) || !isParamMeasured(jlocal))
455 return 0;
456 if (not covinvvalid and not calculateCovInv()) return 0;
457 return 2 * covinv[ilocal][jlocal]; // JL: ok in absence of soft constraints
458 }

◆ getDChi2DParam()

double getDChi2DParam ( int  ilocal) const
virtualinherited

Get derivative of chi squared w.r.t. parameter ilocal.

Parameters
ilocalLocal parameter number

Definition at line 435 of file BaseFitObject.cc.

436 {
437 assert(ilocal >= 0 && ilocal < getNPar());
438 if (isParamFixed(ilocal) || !isParamMeasured(ilocal)) return 0;
439
440 if (not covinvvalid and not calculateCovInv()) return 0;
441
442 double result = 0;
443 for (int jlocal = 0; jlocal < getNPar(); jlocal++)
444 if (!isParamFixed(jlocal) && isParamMeasured(jlocal))
445 result += covinv[ilocal][jlocal] * (par[jlocal] - mpar[jlocal]);
446 return 2 * result;
447 }

◆ getDE()

double getDE ( int  ilocal) const
overridevirtual

Return d E / d par_ilocal (derivative of E w.r.t. local parameter ilocal)

Parameters
ilocalLocal parameter number

Implements ParticleFitObject.

Definition at line 179 of file NeutrinoFitObject.cc.

180 {
181 assert(ilocal >= 0 && ilocal < NPAR);
182 switch (ilocal) {
183 case 0: return 1;
184 case 1: return 0;
185 case 2: return 0;
186 }
187 return 0;
188 }

◆ getDerivatives()

void getDerivatives ( double  der[],
int  idim 
) const
overridevirtualinherited

Implements BaseFitObject.

Definition at line 173 of file ParticleFitObject.cc.

174 {
175 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
176 assert(ilocal < idim);
177 der [4 * ilocal] = getDE(ilocal);
178 der [4 * ilocal + 1] = getDPx(ilocal);
179 der [4 * ilocal + 2] = getDPy(ilocal);
180 der [4 * ilocal + 3] = getDPz(ilocal);
181 }
182 }
virtual double getDE(int ilocal) const =0
Return d E / d par_ilocal (derivative of E w.r.t. local parameter ilocal)
virtual double getDPx(int ilocal) const =0
Return d p_x / d par_ilocal (derivative of px w.r.t. local parameter ilocal)
virtual double getDPz(int ilocal) const =0
Return d p_z / d par_ilocal (derivative of pz w.r.t. local parameter ilocal)
virtual double getDPy(int ilocal) const =0
Return d p_y / d par_ilocal (derivative of py w.r.t. local parameter ilocal)

◆ getDPx()

double getDPx ( int  ilocal) const
overridevirtual

Return d p_x / d par_ilocal (derivative of px w.r.t. local parameter ilocal)

Parameters
ilocalLocal parameter number

Implements ParticleFitObject.

Definition at line 143 of file NeutrinoFitObject.cc.

144 {
145 assert(ilocal >= 0 && ilocal < NPAR);
146 if (!cachevalid) updateCache();
147 switch (ilocal) {
148 case 0: return dpxdE;
149 case 1: return dpxdtheta;
150 case 2: return -py;
151 }
152 return 0;
153 }

◆ getDPy()

double getDPy ( int  ilocal) const
overridevirtual

Return d p_y / d par_ilocal (derivative of py w.r.t. local parameter ilocal)

Parameters
ilocalLocal parameter number

Implements ParticleFitObject.

Definition at line 155 of file NeutrinoFitObject.cc.

156 {
157 assert(ilocal >= 0 && ilocal < NPAR);
158 if (!cachevalid) updateCache();
159 switch (ilocal) {
160 case 0: return dpydE;
161 case 1: return dpydtheta;
162 case 2: return px;
163 }
164 return 0;
165 }

◆ getDPz()

double getDPz ( int  ilocal) const
overridevirtual

Return d p_z / d par_ilocal (derivative of pz w.r.t. local parameter ilocal)

Parameters
ilocalLocal parameter number

Implements ParticleFitObject.

Definition at line 167 of file NeutrinoFitObject.cc.

168 {
169 assert(ilocal >= 0 && ilocal < NPAR);
170 if (!cachevalid) updateCache();
171 switch (ilocal) {
172 case 0: return ctheta;
173 case 1: return -pt;
174 case 2: return 0;
175 }
176 return 0;
177 }

◆ getE()

double getE ( ) const
virtualinherited

Return E.

Definition at line 106 of file ParticleFitObject.cc.

107 {
108 return getFourMomentum().getE();
109 }
double getE() const
Returns the energy / 0 component.
Definition: FourVector.h:127

◆ getError()

double getError ( int  ilocal) const
virtualinherited

Get error of parameter ilocal.

Parameters
ilocalLocal parameter number

Reimplemented in JetFitObject.

Definition at line 383 of file BaseFitObject.cc.

384 {
385 assert(ilocal >= 0 && ilocal < getNPar());
386 return std::sqrt(cov[ilocal][ilocal]);
387 }

◆ getError2()

double getError2 ( double  der[],
int  metaset 
) const
virtualinherited

Definition at line 597 of file BaseFitObject.cc.

598 {
599 if (!cachevalid) updateCache();
600 double totError(0);
601 for (int i = 0; i < BaseDefs::nMetaVars[metaSet]; i++) {
602 for (int j = 0; j < BaseDefs::nMetaVars[metaSet]; j++) {
603 double cov_i_j = 0; // this will become the covariance of intermediate variables i and j
604 for (int k = 0; k < getNPar(); k++) {
605 for (int l = 0; l < getNPar(); l++) {
606 cov_i_j += getFirstDerivative_Meta_Local(i, k, metaSet) * cov[k][l] * getFirstDerivative_Meta_Local(j, l, metaSet);
607 }
608 }
609 totError += der[i] * der[j] * cov_i_j;
610 }
611 }
612 return totError;
613 }

◆ getFirstDerivative_Meta_Local()

double getFirstDerivative_Meta_Local ( int  iMeta,
int  ilocal,
int  metaSet 
) const
overridevirtual

Implements BaseFitObject.

Definition at line 190 of file NeutrinoFitObject.cc.

191 {
192 // iMeta = intermediate variable (i.e. E,px,py,pz)
193 // ilocal = local variable (E, theta, phi)
194 // metaSet = which set of intermediate varlables
195
196 assert(metaSet == 0); // only defined for E,px,py,pz
197
198 switch (iMeta) {
199 case 0: // E
200 return getDE(ilocal);
201 break;
202 case 1: // Px
203 return getDPx(ilocal);
204 break;
205 case 2: // Py
206 return getDPy(ilocal);
207 break;
208 case 3: // Pz
209 return getDPz(ilocal);
210 break;
211 default:
212 assert(0);
213 }
214 return -999;
215 }
virtual double getDPx(int ilocal) const override
Return d p_x / d par_ilocal (derivative of px w.r.t. local parameter ilocal)
virtual double getDPy(int ilocal) const override
Return d p_y / d par_ilocal (derivative of py w.r.t. local parameter ilocal)
virtual double getDE(int ilocal) const override
Return d E / d par_ilocal (derivative of E w.r.t. local parameter ilocal)
virtual double getDPz(int ilocal) const override
Return d p_z / d par_ilocal (derivative of pz w.r.t. local parameter ilocal)

◆ getFourMomentum()

FourVector getFourMomentum ( ) const
virtualinherited

Definition at line 101 of file ParticleFitObject.cc.

102 {
103 if (!cachevalid) updateCache();
104 return fourMomentum;
105 }

◆ getGlobalParNum()

int getGlobalParNum ( int  ilocal) const
virtualinherited

Get global parameter number of parameter ilocal.

Parameters
ilocalLocal parameter number

Definition at line 365 of file BaseFitObject.cc.

366 {
367 if (ilocal < 0 || ilocal >= getNPar()) return -1;
368 return globalParNum[ilocal];
369 }

◆ getMass()

double getMass ( ) const
virtualinherited

Get mass of particle.

Definition at line 89 of file ParticleFitObject.cc.

90 {
91 return mass;
92 }

◆ getMParam()

double getMParam ( int  ilocal) const
virtualinherited

Get measured value of parameter ilocal.

Parameters
ilocalLocal parameter number

Definition at line 377 of file BaseFitObject.cc.

378 {
379 assert(ilocal >= 0 && ilocal < getNPar());
380 return mpar[ilocal];
381 }

◆ getName()

const char * getName ( ) const
virtualinherited

Get object's name.

Definition at line 107 of file BaseFitObject.cc.

108 {
109 return name ? name : "???";
110 }

◆ getNFixed()

int getNFixed ( ) const
virtualinherited

Get number of fixed parameters of this FitObject.

Definition at line 130 of file BaseFitObject.cc.

131 {
132 int nfixed = 0;
133 for (int i = 0; i < getNPar(); ++i) if (isParamFixed(i)) ++nfixed;
134 return nfixed;
135 }

◆ getNFree()

int getNFree ( ) const
virtualinherited

Get number of free parameters of this FitObject.

Definition at line 124 of file BaseFitObject.cc.

125 {
126 int nfree = 0;
127 for (int i = 0; i < getNPar(); ++i) if (!isParamFixed(i)) ++nfree;
128 return nfree;
129 }

◆ getNMeasured()

int getNMeasured ( ) const
virtualinherited

Get number of measured parameters of this FitObject.

Definition at line 112 of file BaseFitObject.cc.

113 {
114 int nmeasured = 0;
115 for (int i = 0; i < getNPar(); ++i) if (isParamMeasured(i) && !isParamFixed(i)) ++nmeasured;
116 return nmeasured;
117 }

◆ getNPar()

virtual int getNPar ( ) const
inlineoverridevirtual

Get total number of parameters of this FitObject.

Implements BaseFitObject.

Definition at line 70 of file NeutrinoFitObject.h.

70{return NPAR;}

◆ getNUnmeasured()

int getNUnmeasured ( ) const
virtualinherited

Get number of unmeasured parameters of this FitObject.

Definition at line 118 of file BaseFitObject.cc.

119 {
120 int nunmeasrd = 0;
121 for (int i = 0; i < getNPar(); ++i) if (!isParamMeasured(i) && !isParamFixed(i)) ++nunmeasrd;
122 return nunmeasrd;
123 }

◆ getP()

double getP ( ) const
virtualinherited

Return p (momentum)

Definition at line 122 of file ParticleFitObject.cc.

123 {
124 return getFourMomentum().getP();
125 }
double getP() const
Returns the momentum / magnitude of the three vector.
Definition: FourVector.h:136

◆ getP2()

double getP2 ( ) const
virtualinherited

Return p (momentum) squared.

Definition at line 126 of file ParticleFitObject.cc.

127 {
128 return getFourMomentum().getP2();
129 }
double getP2() const
Returns the momentum squared / magnitude of the three vector squared.
Definition: FourVector.h:135

◆ getParam()

double getParam ( int  ilocal) const
virtualinherited

Get current value of parameter ilocal.

Parameters
ilocalLocal parameter number

Definition at line 371 of file BaseFitObject.cc.

372 {
373 assert(ilocal >= 0 && ilocal < getNPar());
374 return par[ilocal];
375 }

◆ getParamName()

const char * getParamName ( int  ilocal) const
overridevirtual

Get name of parameter ilocal.

Parameters
ilocalLocal parameter number

Implements BaseFitObject.

Definition at line 92 of file NeutrinoFitObject.cc.

93 {
94 switch (ilocal) {
95 case 0: return "E";
96 case 1: return "theta";
97 case 2: return "phi";
98 }
99 return "undefined";
100 }

◆ getPt()

double getPt ( ) const
virtualinherited

Return pt (transverse momentum)

Definition at line 130 of file ParticleFitObject.cc.

131 {
132 return getFourMomentum().getPt();
133 }
double getPt() const
Returns the transverse momentum / magnitude of the 1 and 2 component vector.
Definition: FourVector.h:133

◆ getPt2()

double getPt2 ( ) const
virtualinherited

Return pt (transverse momentum) squared.

Definition at line 134 of file ParticleFitObject.cc.

135 {
136 return getFourMomentum().getPt2();
137 }
double getPt2() const
Returns the transverse momentum squared / magnitude of the 1 and 2 component vector squared.
Definition: FourVector.h:132

◆ getPx()

double getPx ( ) const
virtualinherited

Return px.

Definition at line 110 of file ParticleFitObject.cc.

111 {
112 return getFourMomentum().getPx();
113 }
double getPx() const
Returns the x momentum / 1 component.
Definition: FourVector.h:128

◆ getPy()

double getPy ( ) const
virtualinherited

Return py.

Definition at line 114 of file ParticleFitObject.cc.

115 {
116 return getFourMomentum().getPy();
117 }
double getPy() const
Returns the y momentum / 2 component.
Definition: FourVector.h:129

◆ getPz()

double getPz ( ) const
virtualinherited

Return pz.

Definition at line 118 of file ParticleFitObject.cc.

119 {
120 return getFourMomentum().getPz();
121 }
double getPz() const
Returns the z momentum / 3 component.
Definition: FourVector.h:130

◆ getRho()

double getRho ( int  ilocal,
int  jlocal 
) const
virtualinherited

Get correlation coefficient between parameters ilocal and jlocal.

Parameters
ilocalLocal parameter number i
jlocalLocal parameter number j

Definition at line 396 of file BaseFitObject.cc.

397 {
398 assert(ilocal >= 0 && ilocal < getNPar());
399 assert(jlocal >= 0 && jlocal < getNPar());
400 return cov[ilocal][jlocal] / std::sqrt(cov[ilocal][ilocal] * cov[jlocal][jlocal]);
401 }

◆ getSecondDerivative_Meta_Local()

double getSecondDerivative_Meta_Local ( int  iMeta,
int  ilocal,
int  jlocal,
int  metaSet 
) const
overridevirtual

Implements BaseFitObject.

Definition at line 218 of file NeutrinoFitObject.cc.

219 {
220 assert(metaSet == 0);
221 if (!cachevalid) updateCache();
222
223 if (jlocal < ilocal) {
224 int temp = jlocal;
225 jlocal = ilocal;
226 ilocal = temp;
227 }
228
229 // daniel hasn't checked these, copied from orig code
230 switch (iMeta) {
231
232 case 0:
233 return 0;
234 break;
235 case 1:
236 if (ilocal == 0 && jlocal == 1) return ctheta * cphi;
237 else if (ilocal == 0 && jlocal == 2) return -dpydE;
238 else if (ilocal == 1 && jlocal == 1) return -px;
239 else if (ilocal == 1 && jlocal == 2) return -dpydtheta;
240 else if (ilocal == 2 && jlocal == 2) return -px;
241 else return 0;
242 break;
243 case 2:
244 if (ilocal == 0 && jlocal == 1) return ctheta * sphi;
245 else if (ilocal == 0 && jlocal == 2) return dpxdE;
246 else if (ilocal == 1 && jlocal == 1) return -py;
247 else if (ilocal == 1 && jlocal == 2) return dpxdtheta;
248 else if (ilocal == 2 && jlocal == 2) return -py;
249 else return 0;
250 break;
251 case 3:
252 if (ilocal == 0 && jlocal == 1) return -stheta;
253 else if (ilocal == 1 && jlocal == 1) return -pz;
254 else return 0;
255 break;
256 default:
257 assert(0);
258 }
259 return -999;
260 }

◆ initCov()

void initCov ( )
virtualinherited

Definition at line 587 of file BaseFitObject.cc.

588 {
589 for (int i = 0; i < getNPar(); ++i) {
590 for (int j = 0; j < getNPar(); ++j) {
591 cov[i][j] = static_cast<double>(i == j);
592 }
593 }
594 }

◆ invalidateCache()

void invalidateCache ( ) const
inlineinherited

invalidate any cached quantities

Definition at line 241 of file BaseFitObject.h.

241{cachevalid = false;};

◆ isParamFixed()

bool isParamFixed ( int  ilocal) const
virtualinherited

Returns whether parameter is fixed.

Parameters
ilocalLocal parameter number

Definition at line 408 of file BaseFitObject.cc.

409 {
410 assert(ilocal >= 0 && ilocal < getNPar());
411 return fixed[ilocal];
412 }

◆ isParamMeasured()

bool isParamMeasured ( int  ilocal) const
virtualinherited

Get measured flag for parameter ilocal.

Parameters
ilocalLocal parameter number

Definition at line 402 of file BaseFitObject.cc.

403 {
404 assert(ilocal >= 0 && ilocal < getNPar());
405 return measured[ilocal];
406 }
bool measured[BaseDefs::MAXPAR]
measured flag

◆ num1stDerivative()

double num1stDerivative ( int  ilocal,
double  eps 
)
inherited

Evaluates numerically the 1st derivative of chi2 w.r.t. a parameter.

Parameters
ilocalLocal parameter number
epsvariation of local parameter

Definition at line 230 of file ParticleFitObject.cc.

231 {
232 double save = getParam(ilocal);
233 setParam(ilocal, save + eps);
234 double v1 = getChi2();
235 setParam(ilocal, save - eps);
236 double v2 = getChi2();
237 double result = (v1 - v2) / (2 * eps);
238 setParam(ilocal, save);
239 return result;
240 }
virtual double getParam(int ilocal) const
Get current value of parameter ilocal.
virtual double getChi2() const override
Get chi squared from measured and fitted parameters.
const std::vector< double > v2
MATLAB generated random vector.
const std::vector< double > v1
MATLAB generated random vector.

◆ num2ndDerivative()

double num2ndDerivative ( int  ilocal1,
double  eps1,
int  ilocal2,
double  eps2 
)
inherited

Evaluates numerically the 2nd derivative of chi2 w.r.t. 2 parameters.

Parameters
ilocal11st local parameter number
eps1variation of 1st local parameter
ilocal21st local parameter number
eps2variation of 2nd local parameter

Definition at line 242 of file ParticleFitObject.cc.

244 {
245 double result;
246
247 if (ilocal1 == ilocal2) {
248 double save = getParam(ilocal1);
249 double v0 = getChi2();
250 setParam(ilocal1, save + eeps1);
251 double v1 = getChi2();
252 setParam(ilocal1, save - eeps1);
253 double v2 = getChi2();
254 result = (v1 + v2 - 2 * v0) / (eeps1 * eeps1);
255 setParam(ilocal1, save);
256 } else {
257 double save1 = getParam(ilocal1);
258 double save2 = getParam(ilocal2);
259 setParam(ilocal1, save1 + eeps1);
260 setParam(ilocal2, save2 + eeps2);
261 double v11 = getChi2();
262 setParam(ilocal2, save2 - eeps2);
263 double v12 = getChi2();
264 setParam(ilocal1, save1 - eeps1);
265 double v22 = getChi2();
266 setParam(ilocal2, save2 + eeps2);
267 double v21 = getChi2();
268 result = (v11 + v22 - v12 - v21) / (4 * eeps1 * eeps2);
269 setParam(ilocal1, save1);
270 setParam(ilocal2, save2);
271 }
272 return result;
273 }

◆ operator=()

NeutrinoFitObject & operator= ( const NeutrinoFitObject rhs)

Assignment.

Parameters
rhsright hand side

Definition at line 66 of file NeutrinoFitObject.cc.

67 {
68 if (this != &rhs) {
69 assign(rhs);
70 }
71 return *this;
72 }

◆ print()

std::ostream & print ( std::ostream &  os) const
overridevirtualinherited

print object to ostream

Parameters
osThe output stream

Implements BaseFitObject.

Definition at line 140 of file ParticleFitObject.cc.

141 {
142
143 if (!cachevalid) updateCache();
144
145 printParams(os);
146 os << " => ";
147 print4Vector(os);
148 os << std::endl;
149 return os;
150 }
virtual std::ostream & printParams(std::ostream &os) const
print the parameters and errors
virtual std::ostream & print4Vector(std::ostream &os) const
print the four-momentum (E, px, py, pz)

◆ print1stDerivatives()

std::ostream & print1stDerivatives ( std::ostream &  os) const
virtualinherited

print the 1st derivatives wrt metaSet 0 (E, px, py, pz)

Parameters
osThe output stream

Definition at line 164 of file BaseFitObject.cc.

165 {
166 int metaSet = 0;
167 os << "#";
168 for (int i = 0; i < BaseDefs::nMetaVars[metaSet]; ++i) {
169 for (int j = 0; j < getNPar(); ++j) {
170 if (i > 0 && j == 0) os << ",";
171 os << " " << getFirstDerivative_Meta_Local(i, j, metaSet);
172 }
173 }
174 os << "#" << std::endl;
175 return os;
176 }

◆ print2ndDerivatives()

std::ostream & print2ndDerivatives ( std::ostream &  os) const
virtualinherited

print the 2nd derivatives wrt metaSet 0 (E, px, py, pz)

Parameters
osThe output stream

Definition at line 178 of file BaseFitObject.cc.

179 {
180 int metaSet = 0;
181 os << "##";
182 for (int i = 0; i < BaseDefs::nMetaVars[metaSet]; ++i) {
183 if (i > 0) os << std::endl << " ";
184 for (int j = 0; j < getNPar(); ++j) {
185 for (int k = 0; k < getNPar(); ++k) {
186// if (i>0 && k==0) os << ",";
187 os << " " << getSecondDerivative_Meta_Local(i, j, k, metaSet);
188 if (k == getNPar() - 1) os << ",";
189 }
190 }
191 }
192 os << "##" << std::endl;
193 return os;
194 }

◆ print4Vector()

std::ostream & print4Vector ( std::ostream &  os) const
virtualinherited

print the four-momentum (E, px, py, pz)

Parameters
osThe output stream

Definition at line 94 of file ParticleFitObject.cc.

95 {
96 os << "[" << getE() << ", " << getPx() << ", "
97 << getPy() << ", " << getPz() << "]";
98 return os;
99 }
virtual double getPx() const
Return px.
virtual double getPz() const
Return pz.
virtual double getPy() const
Return py.
virtual double getE() const
Return E.

◆ printParams()

std::ostream & printParams ( std::ostream &  os) const
virtualinherited

print the parameters and errors

Parameters
osThe output stream

Definition at line 137 of file BaseFitObject.cc.

138 {
139 os << "(";
140 for (int i = 0; i < getNPar(); ++i) {
141 if (i > 0) os << ", ";
142 os << " " << getParam(i);
143 if (isParamFixed(i)) os << " fix";
144// else if (getError(i)>0) os << " \261 " << getError(i);
145 else if (getError(i) > 0) os << " +- " << getError(i); // " \261 " appeared as <B1> in ASCII ... Graham
146 }
147 os << ")";
148 return os;
149 }
virtual double getError(int ilocal) const
Get error of parameter ilocal.

◆ printRhoValues()

std::ostream & printRhoValues ( std::ostream &  os) const
virtualinherited

print the correlation coefficients

Parameters
osThe output stream

Definition at line 151 of file BaseFitObject.cc.

152 {
153 os << "{";
154 for (int i = 0; i < getNPar(); ++i) {
155 for (int j = 0; j < getNPar(); ++j) {
156 if (i > 0 && j == 0) os << ",";
157 os << " " << getRho(i, j);
158 }
159 }
160 os << "}" << std::endl;
161 return os;
162 }
virtual double getRho(int ilocal, int jlocal) const
Get correlation coefficient between parameters ilocal and jlocal.

◆ releaseParam()

virtual bool releaseParam ( int  ilocal)
inlinevirtualinherited

Release a parameter.

Parameters
ilocalLocal parameter number

Definition at line 157 of file BaseFitObject.h.

159 { return fixParam(ilocal, false); }
virtual bool fixParam(int ilocal, bool fix=true)
Fix a parameter (fix=true), or release it (fix=false)

◆ setCov()

bool setCov ( int  ilocal,
int  jlocal,
double  cov_ 
)
virtualinherited

Set covariance of parameters ilocal and jlocal; return: success.

Parameters
ilocalLocal parameter number
jlocalLocal parameter number
cov_New error value

Definition at line 340 of file BaseFitObject.cc.

341 {
342 if (!isfinite(cov_)) return false;
343 assert(ilocal >= 0 && ilocal < getNPar());
344 assert(jlocal >= 0 && jlocal < getNPar());
346 covinvvalid = false;
347 cov[ilocal][jlocal] = cov[jlocal][ilocal] = cov_;
348 return true;
349 }

◆ setError()

bool setError ( int  ilocal,
double  err_ 
)
virtualinherited

Set error of parameter ilocal; return: success.

Parameters
ilocalLocal parameter number
err_New error value

Definition at line 330 of file BaseFitObject.cc.

331 {
332 if (!isfinite(err_)) return false;
333 assert(ilocal >= 0 && ilocal < getNPar());
335 covinvvalid = false;
336 cov[ilocal][ilocal] = err_ * err_;
337 return true;
338 }

◆ setGlobalParNum()

bool setGlobalParNum ( int  ilocal,
int  iglobal 
)
virtualinherited

Set number of parameter ilocal in global list return true signals OK.

Parameters
ilocalLocal parameter number
iglobalNew global parameter number

Definition at line 358 of file BaseFitObject.cc.

359 {
360 if (ilocal < 0 || ilocal >= getNPar()) return false;
361 globalParNum[ilocal] = iglobal;
362 return true;
363 }

◆ setMass()

bool setMass ( double  mass_)
virtualinherited

Set mass of particle; return=success.

Definition at line 63 of file ParticleFitObject.cc.

64 {
65 if (!isfinite(mass_)) return false;
66 if (mass == mass_) return true;
68 mass = std::abs(mass_);
69 return true;
70 }

◆ setMParam()

bool setMParam ( int  ilocal,
double  mpar_ 
)
virtualinherited

Set measured value of parameter ilocal; return: success.

Parameters
ilocalLocal parameter number
mpar_New measured parameter value

Definition at line 320 of file BaseFitObject.cc.

321 {
322 if (!isfinite(mpar_)) return false;
323 assert(ilocal >= 0 && ilocal < getNPar());
324 if (mpar[ilocal] == mpar_) return true;
326 mpar[ilocal] = mpar_;
327 return true;
328 }

◆ setName()

void setName ( const char *  name_)
inherited

Set object's name.

Definition at line 98 of file BaseFitObject.cc.

99 {
100 if (name_ == nullptr) return;
101 size_t l = strlen(name_);
102 if (name) delete[] name;
103 name = new char[l + 1];
104 strcpy(name, name_);
105 }

◆ setParam() [1/2]

bool setParam ( int  ilocal,
double  par_ 
)
virtualinherited

Set value of parameter ilocal; return: significant change.

Parameters
ilocalLocal parameter number
par_New parameter value

Definition at line 309 of file BaseFitObject.cc.

310 {
311 if (!isfinite(par_)) return true;
312 assert(ilocal >= 0 && ilocal < getNPar());
313 if (par[ilocal] == par_) return false;
315 bool result = pow((par_ - par[ilocal]), 2) > eps2 * cov[ilocal][ilocal];
316 par[ilocal] = par_;
317 return result;
318 }

◆ setParam() [2/2]

bool setParam ( int  ilocal,
double  par_,
bool  measured_,
bool  fixed_ = false 
)
virtualinherited

Set value and measured flag of parameter i; return: significant change.

Parameters
ilocalLocal parameter number
par_New parameter value
measured_New "measured" flag
fixed_New "fixed" flag

Definition at line 299 of file BaseFitObject.cc.

301 {
302 assert(ilocal >= 0 && ilocal < getNPar());
303 if (measured[ilocal] != measured_ || fixed[ilocal] != fixed_) invalidateCache();
304 measured[ilocal] = measured_;
305 fixed[ilocal] = fixed_;
306 return setParam(ilocal, par_);
307 }

◆ test1stDerivatives()

void test1stDerivatives ( )
inherited

Definition at line 184 of file ParticleFitObject.cc.

185 {
186 B2INFO("ParticleFitObject::test1stDerivatives, object " << getName() << "\n");
187 double ycalc[100], ynum[100];
188 for (int i = 0; i < 100; ++i) ycalc[i] = ynum[i] = 0;
189 addToGlobalChi2DerVector(ycalc, 100);
190 double eps = 0.00001;
191 addToGlobalChi2DerVectorNum(ynum, 100, eps);
192 for (int ilocal = 0; ilocal < getNPar(); ++ilocal) {
193 int iglobal = getGlobalParNum(ilocal);
194 double calc = ycalc[iglobal];
195 double num = ynum[iglobal];
196 B2INFO("fo: " << getName() << " par " << ilocal << "/"
197 << iglobal << " (" << getParamName(ilocal)
198 << ") calc: " << calc << " - num: " << num << " = " << calc - num);
199 }
200 }
virtual const char * getParamName(int ilocal) const =0
Get name of parameter ilocal.
virtual const char * getName() const
Get object's name.
virtual int addToGlobalChi2DerVector(double *y, int idim) const
Add derivatives of chi squared to global derivative vector.
virtual void addToGlobalChi2DerVectorNum(double *y, int idim, double eps)
Add numerically determined derivatives of chi squared to global derivative vector.

◆ test2ndDerivatives()

void test2ndDerivatives ( )
inherited

Definition at line 202 of file ParticleFitObject.cc.

203 {
204 B2INFO("ParticleFitObject::test2ndDerivatives, object " << getName() << "\n");
205 const int idim = 100;
206 auto* Mnum = new double[idim * idim];
207 auto* Mcalc = new double[idim * idim];
208 for (int i = 0; i < idim * idim; ++i) Mnum[i] = Mcalc[i] = 0;
209 addToGlobalChi2DerMatrix(Mcalc, idim);
210 double eps = 0.0001;
211 B2INFO("eps=" << eps);
212 addToGlobalChi2DerMatrixNum(Mnum, idim, eps);
213 for (int ilocal1 = 0; ilocal1 < getNPar(); ++ilocal1) {
214 int iglobal1 = getGlobalParNum(ilocal1);
215 for (int ilocal2 = ilocal1; ilocal2 < getNPar(); ++ilocal2) {
216 int iglobal2 = getGlobalParNum(ilocal2);
217 double calc = Mcalc[idim * iglobal1 + iglobal2];
218 double num = Mnum[idim * iglobal1 + iglobal2];
219 B2INFO("fo: " << getName() << " par " << ilocal1 << "/"
220 << iglobal1 << " (" << getParamName(ilocal1)
221 << "), par " << ilocal2 << "/"
222 << iglobal2 << " (" << getParamName(ilocal2)
223 << ") calc: " << calc << " - num: " << num << " = " << calc - num);
224 }
225 }
226 delete[] Mnum;
227 delete[] Mcalc;
228 }
virtual void addToGlobalChi2DerMatrix(double *M, int idim) const
Add 2nd derivatives of chi squared to global derivative matrix.
virtual void addToGlobalChi2DerMatrixNum(double *M, int idim, double eps)
Add numerically determined derivatives of chi squared to global covariance matrix.

◆ updateCache()

void updateCache ( ) const
overrideprotectedvirtual

Implements BaseFitObject.

Definition at line 263 of file NeutrinoFitObject.cc.

264 {
265 double e = par[0];
266 double theta = par[1];
267 double phi = par[2];
268
269 ctheta = cos(theta);
270 stheta = sin(theta);
271 cphi = cos(phi);
272 sphi = sin(phi);
273
274 pt = e * stheta;
275
276 px = pt * cphi;
277 py = pt * sphi;
278 pz = e * ctheta;
279
280 fourMomentum.setValues(e, px, py, pz);
281
282 dpxdE = stheta * cphi;
283 dpydE = stheta * sphi;
284 dpxdtheta = pz * cphi;
285 dpydtheta = pz * sphi;
286
287 cachevalid = true;
288 }

◆ updateParams()

bool updateParams ( double  p[],
int  idim 
)
overridevirtual

Read values from global vector, readjust vector; return: significant change.

Parameters
pThe parameter vector
idimLength of the vector

Reimplemented from BaseFitObject.

Definition at line 103 of file NeutrinoFitObject.cc.

104 {
105
107
108 int iE = getGlobalParNum(0);
109 int ith = getGlobalParNum(1);
110 int iph = getGlobalParNum(2);
111 assert(iE >= 0 && iE < idim);
112 assert(ith >= 0 && ith < idim);
113 assert(iph >= 0 && iph < idim);
114
115 double e = pp[iE];
116 double th = pp[ith];
117 double ph = pp[iph];
118 if (e < 0) {
119 e = -e;
120 th = M_PI - th;
121 ph = M_PI + ph;
122 }
123 if (th < 0 || th > M_PI) {
124 th = M_PI - th;
125 ph = M_PI + ph;
126 }
127
128 bool result = (e - par[0]) * (e - par[0]) > eps2 * cov[0][0] ||
129 (th - par[1]) * (th - par[1]) > eps2 * cov[1][1] ||
130 (ph - par[2]) * (ph - par[2]) > eps2 * cov[2][2];
131 par[0] = e;
132 par[1] = (th >= 0 && th < M_PI) ?
133 th : std::acos(std::cos(th));
134 if (std::abs(ph) > M_PI) ph = atan2(sin(ph), cos(ph));
135 par[2] = ph;
136 pp[iE] = par[0];
137 pp[ith] = par[1];
138 pp[iph] = par[2];
139 return result;
140 }

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const BaseFitObject bfo 
)
related

Prints out a BaseFitObject, using its print method.

Parameters
osThe output stream
bfoThe object to print

Definition at line 341 of file BaseFitObject.h.

344 {
345 return bfo.print(os);
346 }

Member Data Documentation

◆ cachevalid

bool cachevalid
mutableprotectedinherited

flag for valid cache

Definition at line 333 of file BaseFitObject.h.

◆ chi2

double chi2
protected

Definition at line 80 of file NeutrinoFitObject.h.

◆ cov

double cov[BaseDefs::MAXPAR][BaseDefs::MAXPAR]
protectedinherited

local covariance matrix

Definition at line 327 of file BaseFitObject.h.

◆ covinv

double covinv[BaseDefs::MAXPAR][BaseDefs::MAXPAR]
mutableprotectedinherited

inverse pf local covariance matrix

Definition at line 329 of file BaseFitObject.h.

◆ covinvvalid

bool covinvvalid
mutableprotectedinherited

flag for valid inverse covariance matrix

Definition at line 331 of file BaseFitObject.h.

◆ cphi

double cphi
protected

Definition at line 77 of file NeutrinoFitObject.h.

◆ ctheta

double ctheta
mutableprotected

Definition at line 77 of file NeutrinoFitObject.h.

◆ dptdE

double dptdE
protected

Definition at line 78 of file NeutrinoFitObject.h.

◆ dpxdE

double dpxdE
protected

Definition at line 79 of file NeutrinoFitObject.h.

◆ dpxdtheta

double dpxdtheta
protected

Definition at line 79 of file NeutrinoFitObject.h.

◆ dpydE

double dpydE
protected

Definition at line 79 of file NeutrinoFitObject.h.

◆ dpydtheta

double dpydtheta
protected

Definition at line 79 of file NeutrinoFitObject.h.

◆ eps2

const double eps2 = 0.0001
staticprotectedinherited

Definition at line 307 of file BaseFitObject.h.

◆ fixed

bool fixed[BaseDefs::MAXPAR]
protectedinherited

fixed flag

Definition at line 323 of file BaseFitObject.h.

◆ fourMomentum

FourVector fourMomentum
mutableprotectedinherited

Definition at line 181 of file ParticleFitObject.h.

◆ globalParNum

int globalParNum[BaseDefs::MAXPAR]
protectedinherited

global parameter number for each parameter

Definition at line 325 of file BaseFitObject.h.

◆ mass

double mass
protectedinherited

mass of particle

Definition at line 179 of file ParticleFitObject.h.

◆ measured

bool measured[BaseDefs::MAXPAR]
protectedinherited

measured flag

Definition at line 321 of file BaseFitObject.h.

◆ mpar

double mpar[BaseDefs::MAXPAR]
protectedinherited

measured parameters

Definition at line 319 of file BaseFitObject.h.

◆ name

char* name
protectedinherited

Definition at line 306 of file BaseFitObject.h.

◆ par

double par[BaseDefs::MAXPAR]
protectedinherited

fit parameters

Definition at line 317 of file BaseFitObject.h.

◆ paramCycl

double paramCycl[BaseDefs::MAXPAR]
protectedinherited

Definition at line 184 of file ParticleFitObject.h.

◆ pt

double pt
protected

Definition at line 78 of file NeutrinoFitObject.h.

◆ px

double px
protected

Definition at line 78 of file NeutrinoFitObject.h.

◆ py

double py
protected

Definition at line 78 of file NeutrinoFitObject.h.

◆ pz

double pz
protected

Definition at line 78 of file NeutrinoFitObject.h.

◆ sphi

double sphi
protected

Definition at line 77 of file NeutrinoFitObject.h.

◆ stheta

double stheta
protected

Definition at line 77 of file NeutrinoFitObject.h.


The documentation for this class was generated from the following files: