11#include <framework/geometry/B2Vector3.h>
13#include <genfit/StateOnPlane.h>
15#include <root/TMatrixD.h>
16#include <root/TGeoMatrix.h>
18#include <Geant4/G4Transform3D.hh>
32 typedef std::pair<unsigned short, unsigned short> DetectorLevelElement;
34 typedef std::pair<std::vector<int>, TMatrixD> GlobalDerivativeSet;
36 typedef std::vector<std::pair<int, double>> Constraint;
38 typedef std::map<long, Constraint> Constraints;
59 template<
class ChildDBObjectType,
class MotherDBObjectType>
60 void insert(
unsigned short child,
unsigned short mother, TMatrixD childToMotherParamTransform)
62 auto childUID = std::make_pair(ChildDBObjectType::getGlobalUniqueID(), child);
63 auto parentUID = std::make_pair(MotherDBObjectType::getGlobalUniqueID(), mother);
65 if (
m_lookup.insert(std::make_pair(childUID, std::make_pair(parentUID, childToMotherParamTransform))).second) {
68 m_hierarchy.insert(std::make_pair(parentUID, std::vector<DetectorLevelElement>()));
75 m_lookup[childUID].second = childToMotherParamTransform;
81 static void mergeGlobals(GlobalDerivativeSet& main, GlobalDerivativeSet additional);
98 std::map<DetectorLevelElement, std::pair<DetectorLevelElement, TMatrixD>>
m_lookup;
100 std::map<DetectorLevelElement, std::vector<DetectorLevelElement>>
m_hierarchy;
117 template<
class LowestLevelDBObject>
120 if (bField.
Mag() < 1.e-10)
121 return std::make_pair(std::vector<int>(), TMatrixD());
123 DetectorLevelElement elementUID = std::make_pair(LowestLevelDBObject::getGlobalUniqueID(), sensor);
134 template<
class ChildDBObjectType,
class MotherDBObjectType>
137 insert<ChildDBObjectType, MotherDBObjectType>(child, mother, TMatrixD(1, 1).UnitMatrix());
158 template<
class LowestLevelDBObject>
161 DetectorLevelElement elementUID = std::make_pair(LowestLevelDBObject::getGlobalUniqueID(), sensor);
169 template<
class ChildDBObjectType,
class MotherDBObjectType>
170 void insertG4Transform(
unsigned short child,
unsigned short mother, G4Transform3D childToMother)
176 template<
class ChildDBObjectType,
class MotherDBObjectType>
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Class for alignment/calibration parameter hierarchy & constraints.
static void mergeGlobals(GlobalDerivativeSet &main, GlobalDerivativeSet additional)
Merge additional set into main set of global labels and derivatives TODO: move to some utilities.
void buildConstraints(Constraints &constraints)
Adds constraints from current hierarchy to a constraints vector.
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.
GlobalDerivativeSet buildGlobalDerivativesHierarchy(TMatrixD matrixChain, DetectorLevelElement child)
Recursive function which adds labels and derivatives until top element in hierarchy is found.
GlobalDerivativesHierarchy()
Constructor.
void insert(unsigned short child, unsigned short mother, TMatrixD childToMotherParamTransform)
Template function to add relation between two elements (possibly in different objects with constants)...
std::set< unsigned short > m_usedUniqueIDs
The set of unique id of each DB object used for construction For more efficient updates of hierarchy ...
virtual ~GlobalDerivativesHierarchy()
Destructor (virtual)
void printHierarchy()
print the lookup map
const std::set< unsigned short > & getUsedDBObjUniqueIDs()
Get the global unique ids of DB objects used to construct hierarchy Usefull to update hierarchy only ...
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.
1D Hierarchy for Lorentz shift correction
GlobalDerivativeSet getGlobalDerivatives(unsigned short sensor, const genfit::StateOnPlane *sop, B2Vector3D bField)
Template function to get globals for given db object and its element (and the rest of hierarchy)
std::vector< int > getElementLabels(DetectorLevelElement element) final
Label for lorentz shift parameter.
TMatrixD getLorentzShiftDerivatives(const genfit::StateOnPlane *sop, B2Vector3D bField)
Derivatives for Lorentz shift in sensor plane.
void insertRelation(unsigned short child, unsigned short mother)
Template function to insert hierarchy relation bewteen two DB objects and their elements.
LorentShiftHierarchy()
Constructor.
6D Hierarchy of rigid bodies
GlobalDerivativeSet getGlobalDerivatives(unsigned short sensor, const genfit::StateOnPlane *sop)
Get globals for given db object (and the rest of hierarchy) and its element at StateOnPlane.
TMatrixD convertTGeoToRigidBodyTransformation(TGeoHMatrix tgeo)
Conversion from G4Transform3D to 6D rigid body transformation parametrization.
void insertG4Transform(unsigned short child, unsigned short mother, G4Transform3D childToMother)
Insert hierarchy relation.
TMatrixD getRigidBodyDerivatives(const genfit::StateOnPlane *sop)
2x6 matrix of rigid body derivatives
RigidBodyHierarchy()
Constructor.
TMatrixD convertG4ToRigidBodyTransformation(G4Transform3D g4transform)
Conversion from G4Transform3D to 6D rigid body transformation parametrization.
std::vector< int > getElementLabels(DetectorLevelElement element) override
Rigid body labels.
void insertTGeoTransform(unsigned short child, unsigned short mother, TGeoHMatrix childToMother)
Insert hierarchy relation.
Abstract base class for different kinds of events.