Belle II Software development
ModuleAlignment.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <top/reconstruction_cpp/TOPTrack.h>
12#include <top/reconstruction_cpp/PDFConstructor.h>
13#include <framework/gearbox/Const.h>
14#include <framework/logging/Logger.h>
15#include <vector>
16#include <string>
17#include <algorithm>
18#include <TMatrixDSym.h>
19
20namespace Belle2 {
25 namespace TOP {
26
31
32 public:
38
43 void setModuleID(int moduleID) {m_moduleID = moduleID;}
44
51 void setSteps(double position, double angle, double time);
52
58 void setParameters(const std::vector<double>& parInit)
59 {
60 for (size_t i = 0; i < std::min(parInit.size(), m_parInit.size()); i++) {
61 m_parInit[i] = parInit[i];
62 }
64 }
65
70 void fixParameter(const std::string& name)
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 }
80
85 void releaseParameter(const std::string& name)
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 }
95
100 {
101 for (unsigned i = 0; i < m_fixed.size(); i++) m_fixed[i] = false;
102 }
103
110 int iterate(TOPTrack& track, const Const::ChargedStable& hypothesis);
111
115 void reset();
116
121 int getModuleID() const {return m_moduleID;}
122
127 const std::vector<std::string>& getParameterNames() const {return m_parNames;}
128
134 const std::vector<double>& getParams() const {return m_par;}
135
141 std::vector<float> getParameters() const;
142
148 std::vector<float> getErrors() const;
149
155 const TMatrixDSym& getErrorMatrix() const {return m_COV;}
156
161 int getNumTracks() const {return m_numTracks;}
162
167 int getNumUsedTracks() const {return m_numUsedTracks;}
168
173 bool isValid() const {return m_valid;}
174
179 int getNumOfPhotons() const {return m_numPhotons;}
180
181 private:
182
190 double getLogL(const std::vector<double>& par, bool& ok);
191
198 bool derivatives(std::vector<double>& first, TMatrixDSym& second);
199
204 int invertMatrixU();
205
206 int m_moduleID = 0;
209 std::vector<std::string> m_parNames;
210 std::vector<double> m_parInit;
211 std::vector<double> m_par;
212 std::vector<double> m_steps;
213 std::vector<double> m_maxDpar;
214 std::vector<bool> m_fixed;
215 TMatrixDSym m_COV;
216 int m_numTracks = 0;
218 int m_numPhotons = 0;
219 bool m_valid = false;
221 TMatrixDSym m_U;
225 };
226
227 } // namespace TOP
229} // namespace Belle2
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
static const ChargedStable muon
muon particle
Definition: Const.h:660
Alignment of a TOP module.
int m_numUsedTracks
number of tracks used
int getNumUsedTracks() const
Returns number of tracks used in current result.
TMatrixDSym m_U
matrix (neg.
const std::vector< double > & getParams() const
Returns alignment parameters.
int getNumTracks() const
Returns track counter.
void setModuleID(int moduleID)
Sets module ID.
bool derivatives(std::vector< double > &first, TMatrixDSym &second)
Calculates numerically first and second derivatives of log likelihood against the parameters.
TMatrixDSym m_COV
covariance matrix
std::vector< double > m_steps
step sizes
bool isValid() const
Checks if the results are valid.
void fixParameter(const std::string &name)
Fixes parameter with its name given as argument.
int m_numPhotons
number of photons used for log likelihood calculation
std::vector< bool > m_fixed
true if parameter is fixed
void setParameters(const std::vector< double > &parInit)
Sets initial values of parameters (overwrites current parameters!) Order is: translations in x,...
std::vector< std::string > m_parNames
parameter names
std::vector< float > getParameters() const
Returns alignment parameters.
std::vector< double > m_par
current parameter values
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...
int getModuleID() const
Returns module ID.
Const::ChargedStable m_hypothesis
particle hypothesis
const std::vector< std::string > & getParameterNames() const
Returns alignment parameter names.
bool m_valid
validity of results
void setSteps(double position, double angle, double time)
Sets steps for numerical calculation of derivatives.
const TMatrixDSym & getErrorMatrix() const
Returns error matrix of alignment parameters Order is: translations in x, y, z, rotation angles aroun...
void releaseParameter(const std::string &name)
Release fixed parameter.
int iterate(TOPTrack &track, const Const::ChargedStable &hypothesis)
Run a single alignment iteration, on success update alignment parameters.
std::vector< double > m_parInit
initial parameter values
int invertMatrixU()
Inverts matrix m_U using Cholesky decomposition.
std::vector< double > m_maxDpar
maximal parameter changes in one iteration
std::vector< float > getErrors() const
Returns errors on alignment parameters.
void reset()
Reset the object.
TOPTrack * m_track
track parameters at TOP
PDFConstructor::EPDFOption m_opt
PDF option.
void releaseAllParameters()
Release all fixed parameters.
int getNumOfPhotons() const
Returns number of photons used for log likelihood calculation.
EPDFOption
Signal PDF construction options.
@ c_Rough
no dependence on y
Reconstructed track at TOP.
Definition: TOPTrack.h:39
Abstract base class for different kinds of events.