Belle II Software  release-05-02-19
hierarchy.cc
1 
2 #include <alignment/Hierarchy.h>
3 #include <alignment/Manager.h>
4 #include <alignment/PedeResult.h>
5 #include <framework/database/EventDependency.h>
6 #include <vxd/dataobjects/VxdID.h>
7 
8 #include <gtest/gtest.h>
9 
10 #include <iostream>
11 
12 using namespace std;
13 using namespace Belle2;
14 using namespace alignment;
15 
16 namespace {
18  class TestTopLevelDBObj {
19  public:
20  static unsigned short getGlobalUniqueID() { return 10; }
21  };
22 
24  class TestLevelDBObj {
25  public:
26  static unsigned short getGlobalUniqueID() { return 20; }
27  };
28 
30  class HierarchyTest : public ::testing::Test {
31  protected:
32  unsigned short topElement {1};
33  unsigned short element1 = {1};
34  unsigned short element2 = {2};
35 
37  virtual void SetUp()
38  {
39  auto& hierarchy = GlobalCalibrationManager::getInstance().getAlignmentHierarchy();
40 
41  G4Transform3D unitTrafo;
42  hierarchy.insertG4Transform<TestLevelDBObj, TestTopLevelDBObj>(element1, topElement, unitTrafo);
43  hierarchy.insertG4Transform<TestLevelDBObj, TestTopLevelDBObj>(element2, topElement, unitTrafo);
44  }
45 
47  virtual void TearDown()
48  {
49 
50  }
51 
52  };
53 
55  TEST_F(HierarchyTest, HierarchyDerivatives)
56  {
57  auto& hierarchy = GlobalCalibrationManager::getInstance().getAlignmentHierarchy();
58 
59  auto sop = new genfit::StateOnPlane(nullptr);
60  TVectorD state(5);
61  state[0] = 1.;
62  state[1] = 1.;
63  state[2] = 1.;
64  state[3] = 1.;
65  state[4] = 1.;
66  sop->setState(state);
67 
68  // The du/dU derivative should be one everywhere (when we move along X, we incerase residual in X by same amount)
69  EXPECT_EQ(hierarchy.getGlobalDerivatives<TestLevelDBObj>(element1, sop).second(0, 0), 1.);
70 
71  }
72 
74  TEST_F(HierarchyTest, HierarchyConstraints)
75  {
76  auto& hierarchy = GlobalCalibrationManager::getInstance().getAlignmentHierarchy();
77 
78  Constraints constraints;
79  hierarchy.buildConstraints(constraints);
80 
81  // We should have 6 constraints - one per each top level parameter
82  EXPECT_EQ(constraints.size(), 6);
83 
84  // Here each child parameter exactly corresponds to mother parameter
85  // we have two childs, so there should be two entries in constraint coefficients
86  for (auto checksum_constraint : constraints) {
87  auto& constraint = checksum_constraint.second;
88  EXPECT_EQ(constraint.size(), 2);
89  // ... and the coefficients should be just ones
90  EXPECT_EQ(fabs(constraint[0].second), 1.);
91  }
92 
93  //HierarchyManager::getInstance().writeConstraints("constraints.txt");
94 
95  }
96 
97 } // namespace
genfit::StateOnPlane
A state with arbitrary dimension defined in a DetPlane.
Definition: StateOnPlane.h:47
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TEST_F
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Definition: globalLabel.cc:65