Belle II Software development
GlobalDerivatives Class Reference

Class for easier manipulation with global derivatives (and their labels) More...

#include <GlobalDerivatives.h>

Public Member Functions

 GlobalDerivatives (int dim=2)
 Constructor for empty derivative matrix and label vector.
 
 GlobalDerivatives (const std::pair< std::vector< int >, TMatrixD > &globals)
 Constructor from pair of the vector and the matrix.
 
 GlobalDerivatives (const std::vector< int > &labels, const TMatrixD &derivs)
 constructor from label vector and derivative matrix
 
 operator std::pair< std::vector< int >, TMatrixD > ()
 Convenient operator to allow to pass the object directly from RecoHit to globalDerivatives() WARNING: causes zero labels to be removed.
 
 operator std::vector< int > ()
 Convenient operator to pass only labels (non-zero)
 
 operator TMatrixD ()
 Covenient operator to pass only derivatives (for non-zero labels)
 
const std::vector< int > & getLabels () const
 Get stored lables (includes zeros)
 
const TMatrixD & getDerivatives () const
 Return the derivative matrix (includes columns with zero labels)
 
void add (const std::pair< std::vector< int >, TMatrixD > &globals)
 Add another set of global labels and derivatives.
 
void add (int paramLabel, std::vector< double > dResiduals_dParam)
 Add one parameter - label and the corresponding residual derivative.
 
void add (int paramLabel, double drudp)
 Add derivative of local U residual w.r.t.
 

Static Public Member Functions

static std::pair< std::vector< int >, TMatrixD > passGlobals (std::pair< std::vector< int >, TMatrixD > globals)
 Static convenient function to remove columns with zero labels (make error in Pede btw.) TODO: refactore interface: return value, params <->
 

Private Attributes

std::pair< std::vector< int >, TMatrixD > m_globals {{}, TMatrixD()}
 The global labels and derivatives matrix.
 

Detailed Description

Class for easier manipulation with global derivatives (and their labels)

Allows to simply add, merge and pass global derivatives matrix and global label vector in RecoHit. For lables = 0 removes given columns from derivative matrix (e.g. save disc space for parameters you do not want to calibrate)

Definition at line 27 of file GlobalDerivatives.h.

Constructor & Destructor Documentation

◆ GlobalDerivatives() [1/3]

GlobalDerivatives ( int  dim = 2)
inlineexplicit

Constructor for empty derivative matrix and label vector.

Parameters
dimnumber of matrix rows (number of local residuals in virtual plane) Usually 2 (also for 1 dim measurement, u/v selected via precision matrix)

Definition at line 32 of file GlobalDerivatives.h.

32{m_globals.second.ResizeTo(dim, 0);}
std::pair< std::vector< int >, TMatrixD > m_globals
The global labels and derivatives matrix.

◆ GlobalDerivatives() [2/3]

GlobalDerivatives ( const std::pair< std::vector< int >, TMatrixD > &  globals)
explicit

Constructor from pair of the vector and the matrix.

Definition at line 17 of file GlobalDerivatives.cc.

18 {
19 m_globals.second.ResizeTo(globals.second);
20 m_globals.first = globals.first;
21 m_globals.second = globals.second;
22 }

◆ GlobalDerivatives() [3/3]

GlobalDerivatives ( const std::vector< int > &  labels,
const TMatrixD &  derivs 
)

constructor from label vector and derivative matrix

Definition at line 23 of file GlobalDerivatives.cc.

24 {
25 m_globals.second.ResizeTo(derivs);
26 m_globals.first = labels;
27 m_globals.second = derivs;
28 }

Member Function Documentation

◆ add() [1/3]

void add ( const std::pair< std::vector< int >, TMatrixD > &  globals)

Add another set of global labels and derivatives.

Definition at line 29 of file GlobalDerivatives.cc.

30 {
31 if (globals.first.empty())
32 return;
33
34 auto& main = m_globals;
35
36 // Create composed matrix of derivatives
37 //TODO: check main and globals matrix has the same number of rows
38 TMatrixD allDerivatives(main.second.GetNrows(), main.second.GetNcols() + globals.second.GetNcols());
39 allDerivatives.Zero();
40 allDerivatives.SetSub(0, 0, main.second);
41 allDerivatives.SetSub(0, main.second.GetNcols(), globals.second);
42
43 // Merge labels
44 main.first.insert(main.first.end(), globals.first.begin(), globals.first.end());
45 // Update matrix
46 main.second.ResizeTo(allDerivatives);
47 main.second = allDerivatives;
48
49 }

◆ add() [2/3]

void add ( int  paramLabel,
double  drudp 
)

Add derivative of local U residual w.r.t.

global parameter Global derivative versus V residual is set to zero. For (u, v) measurement use add(p, {dru/dp, drv/dp}.

Definition at line 61 of file GlobalDerivatives.cc.

62 {
63 std::vector<double> dResiduals_dParam(m_globals.second.GetNrows(), 0.);
64 dResiduals_dParam.at(0) = drudp;
65 add(paramLabel, dResiduals_dParam);
66 }
void add(const std::pair< std::vector< int >, TMatrixD > &globals)
Add another set of global labels and derivatives.

◆ add() [3/3]

void add ( int  paramLabel,
std::vector< double >  dResiduals_dParam 
)

Add one parameter - label and the corresponding residual derivative.

Parameters
paramLabellabel of the global parameter to calibrate
dResiduals_dParamvector od derivatives of local residual (U, v) versus global parameter

Definition at line 50 of file GlobalDerivatives.cc.

51 {
52 int nRows = m_globals.second.GetNrows();
53 int nCols = m_globals.second.GetNcols();
54
55 m_globals.first.push_back(paramLabel);
56 m_globals.second.ResizeTo(nRows, nCols + 1);
57 for (int iRow = 0; iRow < nRows; ++iRow) {
58 m_globals.second(iRow, nCols) = dResiduals_dParam.at(iRow);
59 }
60 }

◆ getDerivatives()

const TMatrixD & getDerivatives ( ) const
inline

Return the derivative matrix (includes columns with zero labels)

Definition at line 47 of file GlobalDerivatives.h.

47{return m_globals.second;}

◆ getLabels()

const std::vector< int > & getLabels ( ) const
inline

Get stored lables (includes zeros)

Definition at line 45 of file GlobalDerivatives.h.

45{return m_globals.first;}

◆ operator std::pair< std::vector< int >, TMatrixD >()

operator std::pair< std::vector< int >, TMatrixD > ( )
inline

Convenient operator to allow to pass the object directly from RecoHit to globalDerivatives() WARNING: causes zero labels to be removed.

Definition at line 39 of file GlobalDerivatives.h.

39{return passGlobals(m_globals);}
static std::pair< std::vector< int >, TMatrixD > passGlobals(std::pair< std::vector< int >, TMatrixD > globals)
Static convenient function to remove columns with zero labels (make error in Pede btw....

◆ operator std::vector< int >()

operator std::vector< int > ( )
inline

Convenient operator to pass only labels (non-zero)

Definition at line 41 of file GlobalDerivatives.h.

41{return passGlobals(m_globals).first;}

◆ operator TMatrixD()

operator TMatrixD ( )
inline

Covenient operator to pass only derivatives (for non-zero labels)

Definition at line 43 of file GlobalDerivatives.h.

43{return passGlobals(m_globals).second;}

◆ passGlobals()

std::pair< std::vector< int >, TMatrixD > passGlobals ( std::pair< std::vector< int >, TMatrixD >  globals)
static

Static convenient function to remove columns with zero labels (make error in Pede btw.) TODO: refactore interface: return value, params <->

Definition at line 67 of file GlobalDerivatives.cc.

68 {
69 TMatrixD newMatrix(globals.second.GetNrows(), 0);
70 std::vector<int> newLabels;
71
72 for (unsigned int iOldCol = 0; iOldCol < globals.first.size(); ++iOldCol) {
73 auto label = globals.first.at(iOldCol);
74 if (label == 0)
75 continue;
76
77 newLabels.push_back(label);
78 newMatrix.ResizeTo(globals.second.GetNrows(), newMatrix.GetNcols() + 1);
79 for (int iRow = 0; iRow < globals.second.GetNrows(); ++iRow) {
80 newMatrix(iRow, newMatrix.GetNcols() - 1) = globals.second(iRow, iOldCol);
81 }
82 }
83 return {newLabels, newMatrix};
84 }

Member Data Documentation

◆ m_globals

std::pair<std::vector<int>, TMatrixD> m_globals {{}, TMatrixD()}
private

The global labels and derivatives matrix.

Definition at line 63 of file GlobalDerivatives.h.


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