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