ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GaussianGradHessian.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GaussianGradHessian.cpp
1 #include "GaussianGradHessian.h"
2 
3 #include <cmath>
4 #include <vector>
5 
6 using namespace std;
7 using namespace Eigen;
8 
9 namespace FitNewton
10 {
11  GaussianGradHessian::GaussianGradHessian() : FunctionGradHessian(3, 1)
12  {
13 
14  }
15 
16 
18  {
19 
20  }
21 
22 
24  {
26  clone->setFixedPar(0, fixedpars[0]);
27  return clone;
28  }
29 
30 
31  bool GaussianGradHessian::calcValGradHessian(const VectorXd& x, double& val, VectorXd& grad, MatrixXd& hessian)
32  {
33  double temp0 = (fixedpars[0] - x(1));
34  double temp1 = temp0*temp0;
35  double temp4 = 1./(x(2));
36  double temp2 = temp4*temp4;
37  temp4*=temp2;
38  double temp3 = 1./x(0);
39 
40  val = (x(0))*exp(-temp1*0.5*temp2);
41 
42  grad(0) = temp3*val;
43  grad(1) = val*temp0*temp2;
44  grad(2) = val*temp1*temp4;
45 
46  hessian(0,0) = 0.;
47  hessian(0,1) = grad(1)*temp3;
48  hessian(0,2) = grad(2)*temp3;
49  hessian(1,1) = temp2*(grad(1)*temp0 - val);
50  hessian(1,2) = temp0*(grad(2)*temp2 - 2.*temp4*val);
51  hessian(2,2) = temp1*(grad(2)*temp4 - 3.*temp2*temp2*val);
52  hessian(1,0) = hessian(0,1);
53  hessian(2,0) = hessian(0,2);
54  hessian(2,1) = hessian(1,2);
55  return true;
56  }
57 }
58 
59 
60 // f = x0*exp(-(t-x1)^2/(2*x2^2))
61 //
62 // df/dx0 = exp(-(t-x1)^2/(2*x2^2)) = f/x0
63 // df/dx1 = x0*exp(-(t-x1)^2/(2*x2^2))*(t1-x1)/(x2^2) = f*((t-x1)/x2^2)
64 // df/dx2 = x0*exp(-(t-x1)^2/(2*x2^2))*(t1-x1)^2/(x2^3) = f*(t-x1)^2/(x2^3)
65 //
66 // d^2f/dx0^2 = 0
67 // d^2f/dx0dx1 = (df/dx1)/x0
68 // d^2f/dx0dx2 = (df/dx2)/x0
69 // d^2f/dx1^2 = (df/dx1)*((t-x1)/x2^2) - f/x2^2 = (1/x2^2)*((df/dx1)*(t-x1) - f)
70 // d^2f/dx1dx2 = (df/dx2)*((t-x1)/x2^2) - 2*f*((t-x1)/x2^3)
71 // d^2f/dx2^2 = (df/dx2)*(t-x1)^2/(x2^3) - 3*f*(t-x1)^2/(x2^4)
72