Belle II Software development
GlobalDerivativesHierarchy Class Referenceabstract

Class for alignment/calibration parameter hierarchy & constraints. More...

#include <Hierarchy.h>

Inheritance diagram for GlobalDerivativesHierarchy:
LorentShiftHierarchy RigidBodyHierarchy

Public Member Functions

 GlobalDerivativesHierarchy ()
 Constructor.
 
virtual ~GlobalDerivativesHierarchy ()
 Destructor (virtual)
 
void buildConstraints (Constraints &constraints)
 Adds constraints from current hierarchy to a constraints vector.
 
GlobalDerivativeSet buildGlobalDerivativesHierarchy (TMatrixD matrixChain, DetectorLevelElement child)
 Recursive function which adds labels and derivatives until top element in hierarchy is found.
 
template<class ChildDBObjectType , class MotherDBObjectType >
void insert (unsigned short child, unsigned short mother, TMatrixD childToMotherParamTransform)
 Template function to add relation between two elements (possibly in different objects with constants) First object is the child object, second its hierarchy parent.
 
void printHierarchy ()
 print the lookup map
 
virtual std::vector< int > getElementLabels (DetectorLevelElement element)=0
 The only function to implement: what are the global labels for the element?
 
const std::set< unsigned short > & getUsedDBObjUniqueIDs ()
 Get the global unique ids of DB objects used to construct hierarchy Usefull to update hierarchy only when those changed.
 

Static Public Member Functions

static void mergeGlobals (GlobalDerivativeSet &main, GlobalDerivativeSet additional)
 Merge additional set into main set of global labels and derivatives TODO: move to some utilities.
 

Private Member Functions

std::pair< DetectorLevelElement, TMatrixD > getChildToMotherTransform (DetectorLevelElement child)
 Find the transformation in the lookup.
 

Private Attributes

std::map< DetectorLevelElement, std::pair< DetectorLevelElement, TMatrixD > > m_lookup
 Map with all the parameter data (child -> (mother, transform_child2mother))
 
std::map< DetectorLevelElement, std::vector< DetectorLevelElement > > m_hierarchy
 Map of hierarchy relations mother-> child.
 
std::set< unsigned short > m_usedUniqueIDs {}
 The set of unique id of each DB object used for construction For more efficient updates of hierarchy only when used objects change.
 

Detailed Description

Class for alignment/calibration parameter hierarchy & constraints.

Definition at line 41 of file Hierarchy.h.

Constructor & Destructor Documentation

◆ GlobalDerivativesHierarchy()

Constructor.

Definition at line 44 of file Hierarchy.h.

44{}

◆ ~GlobalDerivativesHierarchy()

virtual ~GlobalDerivativesHierarchy ( )
inlinevirtual

Destructor (virtual)

Definition at line 46 of file Hierarchy.h.

46{}

Member Function Documentation

◆ buildConstraints()

void buildConstraints ( Constraints &  constraints)

Adds constraints from current hierarchy to a constraints vector.

Definition at line 24 of file Hierarchy.cc.

25 {
26 for (auto& parent_childs : m_hierarchy) {
27 auto parent = parent_childs.first;
28 auto childs = parent_childs.second;
29
30 // We need to check if such constraint entry already exists.
31 // For timedep parameters, some to all labels (and coefficients optionally, too) can change and
32 // in such case, we need a new constraint entry.
33 // Note the checksum for a constraint does not depend on the parent element. If parent object changes,
34 // the relative transofrmation to its children are unchanged. While if (some of) the childs change,
35 // for each time interval they are constant, there must a new constraint entry as this is an independent
36 // linear combination of parameters (because there are other parameters).
37 // Continued bellow...
38 boost::crc_32_type crc32;
39
40 auto parentLabels = getElementLabels(parent);
41 for (unsigned int iCon = 0; iCon < parentLabels.size(); iCon++) {
42 auto constraint = Constraint();
43 //auto & constraint = constraints[parentLabels[iCon]];
44
45 // No constraints if parent is global reference frame
46 // All subdetectors are actually nominally placed at constant position and rotation
47 // and rotating the detectors could only happen due cohherent movements of sub-structures (CDC layers, VXD half-shells)
48 if (parentLabels[iCon] == 0) continue;
49
50 for (unsigned int j = 0; j < childs.size(); j++) {
51 auto child = childs[j];
52 auto childLabels = getElementLabels(child);
53
54 for (unsigned int iPar = 0; iPar < childLabels.size(); iPar++) {
55 double coefficient = getChildToMotherTransform(child).second(iCon, iPar);
56 if (fabs(coefficient) > 1.0e-14) {
57 auto childLabel = childLabels[iPar];
58 constraint.push_back(std::make_pair(childLabel, coefficient));
59 // On the other hand, if the labels do not change, the checksum should not change.
60 // In future I should add second checksum and warn user if this happens. It means user has ignored the fact,
61 // that the objects already change in the input global tag. The point here is, it still might be reasonable
62 // to use the constraint coefficients we already have, as the alignment changes are usually small and do not change
63 // the constraint coefficients in first order for most use-cases. The warning should be enough -> TODO
64 crc32.process_bytes(&childLabel, sizeof(childLabel));
65 }
66 }
67 }
68
69 //constraints.insert(std::make_pair(parentLabels[iCon], constraint));
70 constraints.insert(std::make_pair(crc32.checksum(), constraint));
71
72 }
73 }
74 }
std::map< DetectorLevelElement, std::vector< DetectorLevelElement > > m_hierarchy
Map of hierarchy relations mother-> child.
Definition: Hierarchy.h:100
virtual std::vector< int > getElementLabels(DetectorLevelElement element)=0
The only function to implement: what are the global labels for the element?
std::pair< DetectorLevelElement, TMatrixD > getChildToMotherTransform(DetectorLevelElement child)
Find the transformation in the lookup.
Definition: Hierarchy.cc:125

◆ buildGlobalDerivativesHierarchy()

Belle2::alignment::GlobalDerivativeSet buildGlobalDerivativesHierarchy ( TMatrixD  matrixChain,
DetectorLevelElement  child 
)

Recursive function which adds labels and derivatives until top element in hierarchy is found.

Definition at line 76 of file Hierarchy.cc.

78 {
79 auto loc2glo = getChildToMotherTransform(child);
80
81 if (loc2glo.first == std::make_pair((unsigned short)0, (unsigned short)0))
82 return std::make_pair(std::vector<int>(), TMatrixD());
83
84
85 TMatrixD glo2loc(loc2glo.second.Invert());
86 TMatrixD drdparent = matrixChain * glo2loc;
87
88
89 GlobalDerivativeSet retVal = std::make_pair(getElementLabels(loc2glo.first), drdparent);
90 mergeGlobals(retVal, buildGlobalDerivativesHierarchy(drdparent, loc2glo.first));
91
92 return retVal;
93 }
static void mergeGlobals(GlobalDerivativeSet &main, GlobalDerivativeSet additional)
Merge additional set into main set of global labels and derivatives TODO: move to some utilities.
Definition: Hierarchy.cc:95
GlobalDerivativeSet buildGlobalDerivativesHierarchy(TMatrixD matrixChain, DetectorLevelElement child)
Recursive function which adds labels and derivatives until top element in hierarchy is found.
Definition: Hierarchy.cc:76

◆ getChildToMotherTransform()

std::pair< Belle2::alignment::DetectorLevelElement, TMatrixD > getChildToMotherTransform ( DetectorLevelElement  child)
private

Find the transformation in the lookup.

Definition at line 125 of file Hierarchy.cc.

127 {
128 auto entry = m_lookup.find(child);
129 if (entry == m_lookup.end())
130 return std::make_pair(std::make_pair(0, 0), TMatrixD());
131
132 return entry->second;
133 }
std::map< DetectorLevelElement, std::pair< DetectorLevelElement, TMatrixD > > m_lookup
Map with all the parameter data (child -> (mother, transform_child2mother))
Definition: Hierarchy.h:98

◆ getElementLabels()

virtual std::vector< int > getElementLabels ( DetectorLevelElement  element)
pure virtual

The only function to implement: what are the global labels for the element?

Implemented in LorentShiftHierarchy, and RigidBodyHierarchy.

◆ getUsedDBObjUniqueIDs()

const std::set< unsigned short > & getUsedDBObjUniqueIDs ( )
inline

Get the global unique ids of DB objects used to construct hierarchy Usefull to update hierarchy only when those changed.

Definition at line 91 of file Hierarchy.h.

91{return m_usedUniqueIDs;}
std::set< unsigned short > m_usedUniqueIDs
The set of unique id of each DB object used for construction For more efficient updates of hierarchy ...
Definition: Hierarchy.h:104

◆ insert()

void insert ( unsigned short  child,
unsigned short  mother,
TMatrixD  childToMotherParamTransform 
)
inline

Template function to add relation between two elements (possibly in different objects with constants) First object is the child object, second its hierarchy parent.

Parameters
childis the lement numeric id in child obj
motheris the parent object
childToMotherParamTransformis the transformation matrix (placement from geometry of the detector)

Definition at line 60 of file Hierarchy.h.

61 {
62 auto childUID = std::make_pair(ChildDBObjectType::getGlobalUniqueID(), child);
63 auto parentUID = std::make_pair(MotherDBObjectType::getGlobalUniqueID(), mother);
64
65 if (m_lookup.insert(std::make_pair(childUID, std::make_pair(parentUID, childToMotherParamTransform))).second) {
66 // Just inserted an child element (so each child is inserted exactly once)
67 // Try to insert parent with empty vect (does nothing if parent already in map)
68 m_hierarchy.insert(std::make_pair(parentUID, std::vector<DetectorLevelElement>()));
69 // insert child (can happen only once, so the vect is unique)
70 m_hierarchy[parentUID].push_back(childUID);
71 m_usedUniqueIDs.insert(ChildDBObjectType::getGlobalUniqueID());
72 m_usedUniqueIDs.insert(MotherDBObjectType::getGlobalUniqueID());
73 } else {
74 // Update element transformation if inserted again
75 m_lookup[childUID].second = childToMotherParamTransform;
76 }
77 }

◆ mergeGlobals()

void mergeGlobals ( GlobalDerivativeSet &  main,
GlobalDerivativeSet  additional 
)
static

Merge additional set into main set of global labels and derivatives TODO: move to some utilities.

Definition at line 95 of file Hierarchy.cc.

97 {
98 if (additional.first.empty())
99 return;
100
101 // Create composed matrix of derivatives
102 //TODO: check main and additional matrix has the same number of rows
103 TMatrixD allDerivatives(main.second.GetNrows(), main.second.GetNcols() + additional.second.GetNcols());
104 allDerivatives.Zero();
105 allDerivatives.SetSub(0, 0, main.second);
106 allDerivatives.SetSub(0, main.second.GetNcols(), additional.second);
107
108 // Merge labels
109 main.first.insert(main.first.end(), additional.first.begin(), additional.first.end());
110 // Update matrix
111 main.second.ResizeTo(allDerivatives);
112 main.second = allDerivatives;
113
114 }

◆ printHierarchy()

void printHierarchy ( )

print the lookup map

Definition at line 116 of file Hierarchy.cc.

117 {
118 for (auto& entry : m_lookup) {
119 std::cout << "Child : " << entry.first.second << std::endl;
120 std::cout << "Mother :" << entry.second.first.second << std::endl;
121 entry.second.second.Print();
122 }
123 }

Member Data Documentation

◆ m_hierarchy

std::map<DetectorLevelElement, std::vector<DetectorLevelElement> > m_hierarchy
private

Map of hierarchy relations mother-> child.

Definition at line 100 of file Hierarchy.h.

◆ m_lookup

std::map<DetectorLevelElement, std::pair<DetectorLevelElement, TMatrixD> > m_lookup
private

Map with all the parameter data (child -> (mother, transform_child2mother))

Definition at line 98 of file Hierarchy.h.

◆ m_usedUniqueIDs

std::set<unsigned short> m_usedUniqueIDs {}
private

The set of unique id of each DB object used for construction For more efficient updates of hierarchy only when used objects change.

Definition at line 104 of file Hierarchy.h.


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