Belle II Software development
ModuleAlignment Class Reference

Alignment of a TOP module. More...

#include <ModuleAlignment.h>

Public Member Functions

 ModuleAlignment (PDFConstructor::EPDFOption opt=PDFConstructor::c_Rough)
 Constructor.
 
void setModuleID (int moduleID)
 Sets module ID.
 
void setSteps (double position, double angle, double time)
 Sets steps for numerical calculation of derivatives.
 
void setParameters (const std::vector< double > &parInit)
 Sets initial values of parameters (overwrites current parameters!) Order is: translations in x, y, z, rotation angles around x, y, z, module T0.
 
void fixParameter (const std::string &name)
 Fixes parameter with its name given as argument.
 
void releaseParameter (const std::string &name)
 Release fixed parameter.
 
void releaseAllParameters ()
 Release all fixed parameters.
 
int iterate (TOPTrack &track, const Const::ChargedStable &hypothesis)
 Run a single alignment iteration, on success update alignment parameters.
 
void reset ()
 Reset the object.
 
int getModuleID () const
 Returns module ID.
 
const std::vector< std::string > & getParameterNames () const
 Returns alignment parameter names.
 
const std::vector< double > & getParams () const
 Returns alignment parameters.
 
std::vector< float > getParameters () const
 Returns alignment parameters.
 
std::vector< float > getErrors () const
 Returns errors on alignment parameters.
 
const TMatrixDSym & getErrorMatrix () const
 Returns error matrix of alignment parameters Order is: translations in x, y, z, rotation angles around x, y, z, module T0.
 
int getNumTracks () const
 Returns track counter.
 
int getNumUsedTracks () const
 Returns number of tracks used in current result.
 
bool isValid () const
 Checks if the results are valid.
 
int getNumOfPhotons () const
 Returns number of photons used for log likelihood calculation.
 

Private Member Functions

double getLogL (const std::vector< double > &par, bool &ok)
 Returns log likelihood for given parameters Note: it changes helix parameters of TOPTrack object (m_track)
 
bool derivatives (std::vector< double > &first, TMatrixDSym &second)
 Calculates numerically first and second derivatives of log likelihood against the parameters.
 
int invertMatrixU ()
 Inverts matrix m_U using Cholesky decomposition.
 

Private Attributes

int m_moduleID = 0
 module ID
 
PDFConstructor::EPDFOption m_opt = PDFConstructor::c_Rough
 PDF option.
 
std::vector< std::string > m_parNames
 parameter names
 
std::vector< double > m_parInit
 initial parameter values
 
std::vector< double > m_par
 current parameter values
 
std::vector< double > m_steps
 step sizes
 
std::vector< double > m_maxDpar
 maximal parameter changes in one iteration
 
std::vector< bool > m_fixed
 true if parameter is fixed
 
TMatrixDSym m_COV
 covariance matrix
 
int m_numTracks = 0
 track counter
 
int m_numUsedTracks = 0
 number of tracks used
 
int m_numPhotons = 0
 number of photons used for log likelihood calculation
 
bool m_valid = false
 validity of results
 
TMatrixDSym m_U
 matrix (neg.
 
TOPTrackm_track = 0
 track parameters at TOP
 
Const::ChargedStable m_hypothesis = Const::muon
 particle hypothesis
 

Detailed Description

Alignment of a TOP module.

Definition at line 30 of file ModuleAlignment.h.

Constructor & Destructor Documentation

◆ ModuleAlignment()

Constructor.

Parameters
optPDF construction option

Definition at line 25 of file ModuleAlignment.cc.

25 : m_opt(opt)
26 {
27 m_parNames.push_back("x");
28 m_parNames.push_back("y");
29 m_parNames.push_back("z");
30 m_parNames.push_back("alpha");
31 m_parNames.push_back("beta");
32 m_parNames.push_back("gamma");
33 m_parNames.push_back("t0");
34 unsigned numPar = m_parNames.size();
35 m_parInit.resize(numPar, 0);
37 m_steps.resize(numPar, 0);
38 m_fixed.resize(numPar, false);
39 m_COV.ResizeTo(numPar, numPar);
40 m_U.ResizeTo(numPar, numPar);
41 setSteps(1.0, 0.01, 0.05);
42 }
TMatrixDSym m_U
matrix (neg.
TMatrixDSym m_COV
covariance matrix
std::vector< double > m_steps
step sizes
std::vector< bool > m_fixed
true if parameter is fixed
std::vector< std::string > m_parNames
parameter names
std::vector< double > m_par
current parameter values
void setSteps(double position, double angle, double time)
Sets steps for numerical calculation of derivatives.
std::vector< double > m_parInit
initial parameter values
PDFConstructor::EPDFOption m_opt
PDF option.

Member Function Documentation

◆ derivatives()

bool derivatives ( std::vector< double > &  first,
TMatrixDSym &  second 
)
private

Calculates numerically first and second derivatives of log likelihood against the parameters.

Parameters
firsta vector of first derivatives [out]
seconda matrix of second derivatives [out]
Returns
status (true on success)

Definition at line 141 of file ModuleAlignment.cc.

142 {
143 bool ok = false;
144 double f0 = getLogL(m_par, ok);
145 if (not ok) return false;
146
147 auto par = m_par;
148 for (size_t k = 0; k < par.size(); k++) {
149 if (m_fixed[k]) continue;
150
151 par[k] = m_par[k] + m_steps[k];
152 double fp = getLogL(par, ok);
153 if (not ok) return false;
154
155 par[k] = m_par[k] - m_steps[k];
156 double fm = getLogL(par, ok);
157 if (not ok) return false;
158
159 first[k] = (fp - fm) / 2 / m_steps[k];
160 second[k][k] = (fp - 2 * f0 + fm) / pow(m_steps[k], 2);
161
162 par[k] = m_par[k];
163 }
164
165 for (size_t k = 0; k < par.size(); k++) {
166 if (m_fixed[k]) continue;
167 for (size_t j = k + 1; j < par.size(); j++) {
168 if (m_fixed[j]) continue;
169
170 par[k] = m_par[k] + m_steps[k];
171 par[j] = m_par[j] + m_steps[j];
172 double fpp = getLogL(par, ok);
173 if (not ok) return false;
174
175 par[j] = m_par[j] - m_steps[j];
176 double fpm = getLogL(par, ok);
177 if (not ok) return false;
178
179 par[k] = m_par[k] - m_steps[k];
180 par[j] = m_par[j] + m_steps[j];
181 double fmp = getLogL(par, ok);
182 if (not ok) return false;
183
184 par[j] = m_par[j] - m_steps[j];
185 double fmm = getLogL(par, ok);
186 if (not ok) return false;
187
188 second[j][k] = second[k][j] = (fpp - fmp - fpm + fmm) / 4 / m_steps[k] / m_steps[j];
189
190 par[j] = m_par[j];
191 }
192 par[k] = m_par[k];
193 }
194
195 return true;
196 }
double getLogL(const std::vector< double > &par, bool &ok)
Returns log likelihood for given parameters Note: it changes helix parameters of TOPTrack object (m_t...

◆ fixParameter()

void fixParameter ( const std::string &  name)
inline

Fixes parameter with its name given as argument.

Parameters
nameparameter name

Definition at line 70 of file ModuleAlignment.h.

71 {
72 for (unsigned i = 0; i < m_parNames.size(); i++) {
73 if (name == m_parNames[i]) {
74 m_fixed[i] = true;
75 return;
76 }
77 }
78 B2ERROR("TOP::ModuleAlignment::fixParameter: invalid parameter name '" << name << "'");
79 }

◆ getErrorMatrix()

const TMatrixDSym & getErrorMatrix ( ) const
inline

Returns error matrix of alignment parameters Order is: translations in x, y, z, rotation angles around x, y, z, module T0.

Returns
error matrix

Definition at line 155 of file ModuleAlignment.h.

155{return m_COV;}

◆ getErrors()

std::vector< float > getErrors ( ) const

Returns errors on alignment parameters.

Order is: translations in x, y, z, rotation angles around x, y, z, module T0

Returns
errors in single precision

Definition at line 109 of file ModuleAlignment.cc.

110 {
111 std::vector<float> errors;
112 int numPar = m_par.size();
113 for (int i = 0; i < numPar; i++) {
114 errors.push_back(sqrt(m_COV[i][i]));
115 }
116 return errors;
117 }
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28

◆ getLogL()

double getLogL ( const std::vector< double > &  par,
bool &  ok 
)
private

Returns log likelihood for given parameters Note: it changes helix parameters of TOPTrack object (m_track)

Parameters
parparameters
okstatus [out]
Returns
log likelihood

Definition at line 119 of file ModuleAlignment.cc.

120 {
121 ROOT::Math::Translation3D t(par[0], par[1], par[2]);
122 ROOT::Math::RotationX Rx(par[3]);
123 ROOT::Math::RotationY Ry(par[4]);
124 ROOT::Math::RotationZ Rz(par[5]);
125 ROOT::Math::Transform3D T(Rz * Ry * Rx, t);
127 if (not ok) return 0;
128
129 PDFConstructor pdfConstructor(*m_track, m_hypothesis, m_opt);
130 if (not pdfConstructor.isValid()) {
131 ok = false;
132 return 0;
133 }
134
135 auto LL = pdfConstructor.getLogL(par[6]);
136 m_numPhotons = LL.numPhotons;
137
138 return LL.logL;
139 }
int m_numPhotons
number of photons used for log likelihood calculation
Const::ChargedStable m_hypothesis
particle hypothesis
TOPTrack * m_track
track parameters at TOP
bool overrideTransformation(const ROOT::Math::Transform3D &transform)
Overrides transformation from local to nominal frame, which is by default obtained from DB.
Definition: TOPTrack.h:127

◆ getModuleID()

int getModuleID ( ) const
inline

Returns module ID.

Returns
module ID

Definition at line 121 of file ModuleAlignment.h.

121{return m_moduleID;}

◆ getNumOfPhotons()

int getNumOfPhotons ( ) const
inline

Returns number of photons used for log likelihood calculation.

Returns
number of photons

Definition at line 179 of file ModuleAlignment.h.

179{return m_numPhotons;}

◆ getNumTracks()

int getNumTracks ( ) const
inline

Returns track counter.

Returns
number of tracks

Definition at line 161 of file ModuleAlignment.h.

161{return m_numTracks;}

◆ getNumUsedTracks()

int getNumUsedTracks ( ) const
inline

Returns number of tracks used in current result.

Returns
number of tracks

Definition at line 167 of file ModuleAlignment.h.

167{return m_numUsedTracks;}
int m_numUsedTracks
number of tracks used

◆ getParameterNames()

const std::vector< std::string > & getParameterNames ( ) const
inline

Returns alignment parameter names.

Returns
parameter names

Definition at line 127 of file ModuleAlignment.h.

127{return m_parNames;}

◆ getParameters()

std::vector< float > getParameters ( ) const

Returns alignment parameters.

Order is: translations in x, y, z, rotation angles around x, y, z, module T0

Returns
parameters in single precision

Definition at line 102 of file ModuleAlignment.cc.

103 {
104 std::vector<float> pars;
105 for (auto par : m_par) pars.push_back(par);
106 return pars;
107 }

◆ getParams()

const std::vector< double > & getParams ( ) const
inline

Returns alignment parameters.

Order is: translations in x, y, z, rotation angles around x, y, z, module T0

Returns
parameters in double precision

Definition at line 134 of file ModuleAlignment.h.

134{return m_par;}

◆ invertMatrixU()

int invertMatrixU ( )
private

Inverts matrix m_U using Cholesky decomposition.

Returns
error status (0 = OK, > 0 matrix not pos. definite)

Definition at line 198 of file ModuleAlignment.cc.

199 {
200 int n = 0;
201 for (auto fixed : m_fixed) {
202 if (not fixed) n++;
203 }
204
205 TMatrixDSym A(n);
206 int ii = 0;
207 for (int i = 0; i < m_U.GetNrows(); i++) {
208 if (m_fixed[i]) continue;
209 int kk = 0;
210 for (int k = 0; k < m_U.GetNrows(); k++) {
211 if (m_fixed[k]) continue;
212 A[ii][kk] = m_U[i][k];
213 kk++;
214 }
215 ii++;
216 }
217
218 TDecompChol chol(A);
219 if (not chol.Decompose()) return 1;
220 chol.Invert(A);
221
222 ii = 0;
223 for (int i = 0; i < m_U.GetNrows(); i++) {
224 if (m_fixed[i]) continue;
225 int kk = 0;
226 for (int k = 0; k < m_U.GetNrows(); k++) {
227 if (m_fixed[k]) continue;
228 m_COV[i][k] = A[ii][kk];
229 kk++;
230 }
231 ii++;
232 }
233
234 return 0;
235 }

◆ isValid()

bool isValid ( ) const
inline

Checks if the results are valid.

Returns
true if results valid

Definition at line 173 of file ModuleAlignment.h.

173{return m_valid;}
bool m_valid
validity of results

◆ iterate()

int iterate ( TOPTrack track,
const Const::ChargedStable hypothesis 
)

Run a single alignment iteration, on success update alignment parameters.

Parameters
tracktrack parameters
hypothesisparticle hypothesis
Returns
error status (0 = OK, < 0 no track hit, > 0 matrix not positive definite)

Definition at line 56 of file ModuleAlignment.cc.

57 {
58 m_numPhotons = 0;
59 if (track.getModuleID() != m_moduleID) return -2;
60
61 m_track = &track;
62 m_hypothesis = hypothesis;
63
64 std::vector<double> first(m_par.size(), 0);
65 TMatrixDSym second(m_par.size());
66 if (not derivatives(first, second)) return -1;
67
68 m_U -= second;
70
71 int ier = invertMatrixU();
72 if (ier != 0) return ier;
73
74 std::vector<double> dpar(m_par.size(), 0);
75 for (size_t i = 0; i < dpar.size(); i++) {
76 for (size_t k = 0; k < dpar.size(); k++) {
77 dpar[i] += m_COV[i][k] * first[k];
78 }
79 if (fabs(dpar[i]) > m_maxDpar[i]) return ier;
80 }
81
82 for (size_t i = 0; i < dpar.size(); i++) {
83 m_par[i] += dpar[i];
84 }
86 m_valid = true;
87
88 return 0;
89 }
bool derivatives(std::vector< double > &first, TMatrixDSym &second)
Calculates numerically first and second derivatives of log likelihood against the parameters.
int invertMatrixU()
Inverts matrix m_U using Cholesky decomposition.
std::vector< double > m_maxDpar
maximal parameter changes in one iteration

◆ releaseAllParameters()

void releaseAllParameters ( )
inline

Release all fixed parameters.

Definition at line 99 of file ModuleAlignment.h.

100 {
101 for (unsigned i = 0; i < m_fixed.size(); i++) m_fixed[i] = false;
102 }

◆ releaseParameter()

void releaseParameter ( const std::string &  name)
inline

Release fixed parameter.

Parameters
nameparameter name

Definition at line 85 of file ModuleAlignment.h.

86 {
87 for (unsigned i = 0; i < m_parNames.size(); i++) {
88 if (name == m_parNames[i]) {
89 m_fixed[i] = false;
90 return;
91 }
92 }
93 B2ERROR("TOP::ModuleAlignment::releaseParameter: invalid parameter name '" << name << "'");
94 }

◆ reset()

void reset ( )

Reset the object.

Definition at line 91 of file ModuleAlignment.cc.

92 {
94 m_COV.Zero();
95 m_U.Zero();
96 m_numTracks = 0;
98 m_valid = false;
99 m_numPhotons = 0;
100 }

◆ setModuleID()

void setModuleID ( int  moduleID)
inline

Sets module ID.

Parameters
moduleIDmodule ID

Definition at line 43 of file ModuleAlignment.h.

43{m_moduleID = moduleID;}

◆ setParameters()

void setParameters ( const std::vector< double > &  parInit)
inline

Sets initial values of parameters (overwrites current parameters!) Order is: translations in x, y, z, rotation angles around x, y, z, module T0.

Parameters
parInitinitial values

Definition at line 58 of file ModuleAlignment.h.

59 {
60 for (size_t i = 0; i < std::min(parInit.size(), m_parInit.size()); i++) {
61 m_parInit[i] = parInit[i];
62 }
64 }

◆ setSteps()

void setSteps ( double  position,
double  angle,
double  time 
)

Sets steps for numerical calculation of derivatives.

Parameters
positionstep size for translations [cm]
anglestep size for rotations [radians]
timestep size for module T0 [ns]

Definition at line 44 of file ModuleAlignment.cc.

45 {
46 m_steps[0] = position;
47 m_steps[1] = position;
48 m_steps[2] = position;
49 m_steps[3] = angle;
50 m_steps[4] = angle;
51 m_steps[5] = angle;
52 m_steps[6] = time;
54 }

Member Data Documentation

◆ m_COV

TMatrixDSym m_COV
private

covariance matrix

Definition at line 215 of file ModuleAlignment.h.

◆ m_fixed

std::vector<bool> m_fixed
private

true if parameter is fixed

Definition at line 214 of file ModuleAlignment.h.

◆ m_hypothesis

Const::ChargedStable m_hypothesis = Const::muon
private

particle hypothesis

Definition at line 223 of file ModuleAlignment.h.

◆ m_maxDpar

std::vector<double> m_maxDpar
private

maximal parameter changes in one iteration

Definition at line 213 of file ModuleAlignment.h.

◆ m_moduleID

int m_moduleID = 0
private

module ID

Definition at line 206 of file ModuleAlignment.h.

◆ m_numPhotons

int m_numPhotons = 0
private

number of photons used for log likelihood calculation

Definition at line 218 of file ModuleAlignment.h.

◆ m_numTracks

int m_numTracks = 0
private

track counter

Definition at line 216 of file ModuleAlignment.h.

◆ m_numUsedTracks

int m_numUsedTracks = 0
private

number of tracks used

Definition at line 217 of file ModuleAlignment.h.

◆ m_opt

PDF option.

Definition at line 207 of file ModuleAlignment.h.

◆ m_par

std::vector<double> m_par
private

current parameter values

Definition at line 211 of file ModuleAlignment.h.

◆ m_parInit

std::vector<double> m_parInit
private

initial parameter values

Definition at line 210 of file ModuleAlignment.h.

◆ m_parNames

std::vector<std::string> m_parNames
private

parameter names

Definition at line 209 of file ModuleAlignment.h.

◆ m_steps

std::vector<double> m_steps
private

step sizes

Definition at line 212 of file ModuleAlignment.h.

◆ m_track

TOPTrack* m_track = 0
private

track parameters at TOP

Definition at line 222 of file ModuleAlignment.h.

◆ m_U

TMatrixDSym m_U
private

matrix (neg.

sum of second derivatives)

Definition at line 221 of file ModuleAlignment.h.

◆ m_valid

bool m_valid = false
private

validity of results

Definition at line 219 of file ModuleAlignment.h.


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