9#include <alignment/Hierarchy.h>
11#include <alignment/GlobalLabel.h>
13#include <boost/crc.hpp>
27 auto parent = parent_childs.first;
28 auto childs = parent_childs.second;
38 boost::crc_32_type crc32;
41 for (
unsigned int iCon = 0; iCon < parentLabels.size(); iCon++) {
42 auto constraint = Constraint();
48 if (parentLabels[iCon] == 0)
continue;
50 for (
unsigned int j = 0; j < childs.size(); j++) {
51 auto child = childs[j];
54 for (
unsigned int iPar = 0; iPar < childLabels.size(); iPar++) {
56 if (fabs(coefficient) > 1.0e-14) {
57 auto childLabel = childLabels[iPar];
58 constraint.push_back(std::make_pair(childLabel, coefficient));
64 crc32.process_bytes(&childLabel,
sizeof(childLabel));
70 constraints.insert(std::make_pair(crc32.checksum(), constraint));
77 Belle2::alignment::DetectorLevelElement child)
81 if (loc2glo.first == std::make_pair((
unsigned short)0, (
unsigned short)0))
82 return std::make_pair(std::vector<int>(), TMatrixD());
85 TMatrixD glo2loc(loc2glo.second.Invert());
86 TMatrixD drdparent = matrixChain * glo2loc;
89 GlobalDerivativeSet retVal = std::make_pair(
getElementLabels(loc2glo.first), drdparent);
96 Belle2::alignment::GlobalDerivativeSet additional)
98 if (additional.first.empty())
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);
109 main.first.insert(main.first.end(), additional.first.begin(), additional.first.end());
111 main.second.ResizeTo(allDerivatives);
112 main.second = allDerivatives;
119 std::cout <<
"Child : " << entry.first.second << std::endl;
120 std::cout <<
"Mother :" << entry.second.first.second << std::endl;
121 entry.second.second.Print();
126 Belle2::alignment::DetectorLevelElement child)
130 return std::make_pair(std::make_pair(0, 0), TMatrixD());
132 return entry->second;
139 std::vector<int> labels;
141 label.construct(element.first, element.second, 0);
143 labels.push_back(label.setParameterId(20));
152 TMatrixD derGlobal(2, 1);
160 genfit::StateOnPlane localForce = *sop;
161 localForce.setPosMom(sop->getPos(), F_dir);
162 B2Vector3D lorentzLocal(localForce.getState()[3], localForce.getState()[4], 0);
164 derGlobal(0, 0) = lorentzLocal(0);
165 derGlobal(1, 0) = lorentzLocal(1);
174 std::vector<int> labels;
176 label.construct(element.first, element.second, 0);
178 labels.push_back(label.setParameterId(1));
179 labels.push_back(label.setParameterId(2));
180 labels.push_back(label.setParameterId(3));
181 labels.push_back(label.setParameterId(4));
182 labels.push_back(label.setParameterId(5));
183 labels.push_back(label.setParameterId(6));
205 TMatrixD derGlobal(2, 6);
208 double uSlope = sop->getState()[1];
210 double vSlope = sop->getState()[2];
212 double uPos = sop->getState()[3];
214 double vPos = sop->getState()[4];
218 derGlobal(0, 0) = 1.0;
219 derGlobal(0, 1) = 0.0;
220 derGlobal(0, 2) = - uSlope;
221 derGlobal(0, 3) = vPos * uSlope;
222 derGlobal(0, 4) = -uPos * uSlope;
223 derGlobal(0, 5) = vPos;
225 derGlobal(1, 0) = 0.0;
226 derGlobal(1, 1) = 1.0;
227 derGlobal(1, 2) = - vSlope;
228 derGlobal(1, 3) = vPos * vSlope;
229 derGlobal(1, 4) = -uPos * vSlope;
230 derGlobal(1, 5) = -uPos;
237 TMatrixD rotationT(3, 3);
238 TMatrixD offset(3, 3);
239 for (
int i = 0; i < 3; i++) {
240 for (
int j = 0; j < 3; j++) {
241 rotationT(i, j) = g4transform.getRotation()(i, j);
245 double xDet = g4transform.getTranslation()(0);
246 double yDet = g4transform.getTranslation()(1);
247 double zDet = g4transform.getTranslation()(2);
249 offset(0, 1) = - zDet;
252 offset(1, 2) = - xDet;
253 offset(2, 0) = - yDet;
256 TMatrixD loc2glo(6, 6);
258 loc2glo.SetSub(0, 0, rotationT);
259 loc2glo.SetSub(0, 3, -1. * offset * rotationT);
260 loc2glo.SetSub(3, 3, rotationT);
267 TMatrixD rotationT(3, 3);
268 TMatrixD offset(3, 3);
269 for (
int i = 0; i < 3; i++) {
270 for (
int j = 0; j < 3; j++) {
271 rotationT(i, j) = tgeo.GetRotationMatrix()[i * 3 + j];
275 double xDet = tgeo.GetTranslation()[0];
276 double yDet = tgeo.GetTranslation()[1];
277 double zDet = tgeo.GetTranslation()[2];
279 offset(0, 1) = - zDet;
282 offset(1, 2) = - xDet;
283 offset(2, 0) = - yDet;
286 TMatrixD loc2glo(6, 6);
288 loc2glo.SetSub(0, 0, rotationT);
289 loc2glo.SetSub(0, 3, -1. * offset * rotationT);
290 loc2glo.SetSub(3, 3, rotationT);
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
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.
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?
std::pair< DetectorLevelElement, TMatrixD > getChildToMotherTransform(DetectorLevelElement child)
Find the transformation in the lookup.
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.
TMatrixD convertTGeoToRigidBodyTransformation(TGeoHMatrix tgeo)
Conversion from G4Transform3D to 6D rigid body transformation parametrization.
TMatrixD getRigidBodyDerivatives(const genfit::StateOnPlane *sop)
2x6 matrix of rigid body derivatives
TMatrixD convertG4ToRigidBodyTransformation(G4Transform3D g4transform)
Conversion from G4Transform3D to 6D rigid body transformation parametrization.
std::vector< int > getElementLabels(DetectorLevelElement element) override
Rigid body labels.
Abstract base class for different kinds of events.