-
Notifications
You must be signed in to change notification settings - Fork 6
/
pctEnergyAdaptiveMLPFunction.h
169 lines (129 loc) · 4.95 KB
/
pctEnergyAdaptiveMLPFunction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef __pctEnergyAdaptiveMLPFunction_h
#define __pctEnergyAdaptiveMLPFunction_h
#include "CLHEP/Units/PhysicalConstants.h"
#include "pctMostLikelyPathFunction.h"
// #include <cmath>
namespace pct
{
namespace Functor
{
namespace FlexibleMLP
{
void
GetLinearCoefficients( itk::Vector<double, 2>& ab, const double E_in, const double E_out, const double deltaU )
{
double inverseScatteringPower_in, inverseScatteringPower_out;
/** Calculate 1/T = beta^2 p^2 / Omega0^2 * X0
* 938.3 is the proton rest mass; It would be better to avoid hard coding
* the contants 13.6 and X0=36.1 actually cancel out when evaluating the MLP,
* but it is better to keep them for physics debugging.
* inverseScatteringPower is unitless.
*/
inverseScatteringPower_in = (E_in+2*938.3) * E_in / (E_in+938.3) / 13.6;
inverseScatteringPower_in *= inverseScatteringPower_in * 36.1 * CLHEP::cm;
inverseScatteringPower_out = (E_out+2*938.3) * E_out / (E_out+938.3) / 13.6;
inverseScatteringPower_out *= inverseScatteringPower_out * 36.1*CLHEP::cm;
ab[1] = inverseScatteringPower_in;
ab[0] = (inverseScatteringPower_out - inverseScatteringPower_in) / deltaU;
}
// class which calculates factor A, B, C, D as in eq. 19 in [Krah 2019, PMB]
class FactorsABCD
{
public:
static double GetA(const double uOut, itk::Vector<double, 2> ab)
{
double A = std::log(uOut*ab[0]/ab[1] + 1.) / ab[0];
return A;
}
static double GetB(const double uOut, itk::Vector<double, 2> ab)
{
double uOut_tilde = uOut*ab[0]/ab[1];
double B = (uOut_tilde - std::log(uOut_tilde + 1)) * ab[1] / std::pow(ab[0], 2);
return B;
}
static double GetC(const double uOut, itk::Vector<double, 2> ab)
{
double uOut_tilde = uOut*ab[0]/ab[1];
double C = ((uOut_tilde + 1)*std::log(uOut_tilde + 1) - uOut_tilde) * ab[1] / std::pow(ab[0], 2);
return C;
}
static double GetD(const double uOut, itk::Vector<double, 2> ab)
{
double uOut_tilde = uOut*ab[0]/ab[1];
double D = (0.5*uOut_tilde*uOut_tilde + uOut_tilde - (uOut_tilde + 1)*std::log(uOut_tilde + 1)) * std::pow(ab[1], 2) / std::pow(ab[0], 3);
return D;
}
};
class CoefficientsC
{
public:
static void GetValue(itk::Vector<double, 2>& CoefficientsC, const double uOut, const itk::Vector<double, 2> vIn, const itk::Vector<double, 2> vOut, const double A, const double B, const double C, const double D)
{
CoefficientsC[0] = (-B * (vOut[0] - vIn[0] - vIn[1] * uOut) + D * (vOut[1] - vIn[1])) / (A*D - B*C);
CoefficientsC[1] = (A * (vOut[0] - vIn[0] - vIn[1] * uOut) - C * (vOut[1] - vIn[1])) / (A*D - B*C);
}
};
} // end namespace EnergyAdaptiveMLPFunction
} // end namespace Functor
/** \class EnergyAdaptiveMLPFunction
*
* \ingroup Functions
*/
class ITK_EXPORT EnergyAdaptiveMLPFunction:
public MostLikelyPathFunction<double>
{
public:
/** Standard class typedefs. */
typedef EnergyAdaptiveMLPFunction Self;
typedef MostLikelyPathFunction<double> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Useful defines. */
typedef Superclass::VectorType VectorType;
/* Initialize the MLP estimator */
virtual void Init(const VectorType posIn, const VectorType posOut, const VectorType dirIn, const VectorType dirOut, double eIn, double eOut) override;
/* Evaluate MLP in multiple depths u */
virtual void Evaluate( std::vector<double> u, std::vector<double> &x, std::vector<double> &y ) override;
/** Evaluate the error (x,y) (equation 27) at depth z. */
void EvaluateError( const double u1, itk::Matrix<double, 2, 2> &error);
#ifdef MLP_TIMING
/** Print timing information */
virtual void PrintTiming(std::ostream& os) override;
#endif
protected:
/// Constructor
EnergyAdaptiveMLPFunction();
EnergyAdaptiveMLPFunction(const int polydeg);
/// Destructor
~EnergyAdaptiveMLPFunction(){}
private:
EnergyAdaptiveMLPFunction( const Self& ); //purposely not implemented
void operator=( const Self& ); //purposely not implemented
itk::Vector<double, 1> m_ScalarTest;
// vectors holding the linear coefficients a and b of the inverse kinematic term
itk::Vector<double, 2> m_ab;
// vectors holding the factors c0 and c1; constant per MLP
itk::Vector<double, 2> m_c_x;
itk::Vector<double, 2> m_c_y;
// regrouped coefficients for MLP calculation; constant per MLP
itk::Vector<double, 4> m_dm_x;
itk::Vector<double, 4> m_dm_y;
// Depth position at entrance and exit, only u1 is variable
double m_uOrigin;
double m_u0;
double m_u2;
// Entrance and exit parameters (equation 1)
itk::Vector<double, 2> m_x0;
itk::Vector<double, 2> m_x2;
itk::Vector<double, 2> m_y0;
itk::Vector<double, 2> m_y2;
#ifdef MLP_TIMING
itk::TimeProbe m_EvaluateProbe1;
itk::TimeProbe m_EvaluateProbe2;
#endif
};
} // end namespace pct
#include "pctEnergyAdaptiveMLPFunction.txx"
#endif