Belle II Software development
hierarchy.cc
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#include <alignment/Hierarchy.h>
10#include <alignment/Manager.h>
11
12#include <gtest/gtest.h>
13
14using namespace std;
15using namespace Belle2;
16using namespace alignment;
17
18namespace {
20 class TestTopLevelDBObj {
21 public:
22 static unsigned short getGlobalUniqueID() { return 10; }
23 };
24
26 class TestLevelDBObj {
27 public:
28 static unsigned short getGlobalUniqueID() { return 20; }
29 };
30
32 class HierarchyTest : public ::testing::Test {
33 protected:
34 unsigned short topElement {1};
35 unsigned short element1 = {1};
36 unsigned short element2 = {2};
37
39 virtual void SetUp()
40 {
41 auto& hierarchy = GlobalCalibrationManager::getInstance().getAlignmentHierarchy();
42
43 G4Transform3D unitTrafo;
44 hierarchy.insertG4Transform<TestLevelDBObj, TestTopLevelDBObj>(element1, topElement, unitTrafo);
45 hierarchy.insertG4Transform<TestLevelDBObj, TestTopLevelDBObj>(element2, topElement, unitTrafo);
46 }
47
49 virtual void TearDown()
50 {
51
52 }
53
54 };
55
57 TEST_F(HierarchyTest, HierarchyDerivatives)
58 {
59 auto& hierarchy = GlobalCalibrationManager::getInstance().getAlignmentHierarchy();
60
61 auto sop = new genfit::StateOnPlane(nullptr);
62 TVectorD state(5);
63 state[0] = 1.;
64 state[1] = 1.;
65 state[2] = 1.;
66 state[3] = 1.;
67 state[4] = 1.;
68 sop->setState(state);
69
70 // The du/dU derivative should be one everywhere (when we move along X, we increase residual in X by same amount)
71 EXPECT_EQ(hierarchy.getGlobalDerivatives<TestLevelDBObj>(element1, sop).second(0, 0), 1.);
72
73 }
74
76 TEST_F(HierarchyTest, HierarchyConstraints)
77 {
78 auto& hierarchy = GlobalCalibrationManager::getInstance().getAlignmentHierarchy();
79
80 Constraints constraints;
81 hierarchy.buildConstraints(constraints);
82
83 // We should have 6 constraints - one per each top level parameter
84 EXPECT_EQ(constraints.size(), 6);
85
86 // Here each child parameter exactly corresponds to mother parameter
87 // we have two children, so there should be two entries in constraint coefficients
88 for (auto checksum_constraint : constraints) {
89 auto& constraint = checksum_constraint.second;
90 EXPECT_EQ(constraint.size(), 2);
91 // ... and the coefficients should be just ones
92 EXPECT_EQ(fabs(constraint[0].second), 1.);
93 }
94
95 //HierarchyManager::getInstance().writeConstraints("constraints.txt");
96
97 }
98
99} // namespace
Abstract base class for different kinds of events.
STL namespace.