Belle II Software  release-08-01-10
directedNodeNetwork.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 <gtest/gtest.h>
10 
11 #include <tracking/trackFindingVXD/segmentNetwork/DirectedNode.h>
12 #include <tracking/trackFindingVXD/segmentNetwork/DirectedNodeNetwork.h>
13 #include <tracking/trackFindingVXD/segmentNetwork/DirectedNodeNetworkContainer.h>
14 
15 #include <vxd/geometry/SensorInfoBase.h>
16 #include <pxd/dataobjects/PXDCluster.h>
17 #include <framework/datastore/StoreArray.h>
18 #include <framework/datastore/StoreObjPtr.h>
19 #include <tracking/spacePointCreation/SpacePoint.h>
20 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
21 
22 
23 #include <array>
24 #include <iostream>
25 #include <deque>
26 
27 using namespace std;
28 using namespace Belle2;
29 
37 
38 
40  VXD::SensorInfoBase provideSensorInfo(VxdID aVxdID, double globalX = 0., double globalY = 0., double globalZ = -0.)
41  {
42  // (SensorType type, VxdID id, double width, double length, double thickness, int uCells, int vCells, double width2=-1, double splitLength=-1, int vCells2=0)
43  VXD::SensorInfoBase sensorInfoBase(VXD::SensorInfoBase::PXD, aVxdID, 2.3, 4.2, 0.3, 2, 4, -1);
44 
45  TGeoRotation r1;
46  r1.SetAngles(45, 20, 30); // rotation defined by Euler angles
47  TGeoTranslation t1(globalX, globalY, globalZ);
48  TGeoCombiTrans c1(t1, r1);
49  TGeoHMatrix transform = c1;
50  sensorInfoBase.setTransformation(transform);
51 
52  return sensorInfoBase;
53  }
54 
55 
57  PXDCluster providePXDCluster(double u, double v, VxdID aVxdID, double uError = 0.1, double vError = 0.1)
58  {
59  return PXDCluster(aVxdID, u, v, uError, vError, 0, 0, 1, 1, 1, 1, 1, 1);
60  }
61 
66  class DirectedNodeNetworkTest : public ::testing::Test {
67  protected:
68 
70  virtual void SetUp()
71  {
72  DataStore::Instance().setInitializeActive(true);
73 
74  m_spacePointData.registerInDataStore();
75  m_pxdClusterData.registerInDataStore();
76  m_spacePointTrackCandData.registerInDataStore();
77 
78  m_spacePointData.registerRelationTo(m_pxdClusterData);
79 
80  m_networkContainerInDataStore.registerInDataStore();
81 
82  DataStore::Instance().setInitializeActive(false);
83 
84  unsigned int nHits = 5;
85 
87  for (unsigned int i = 1; i <= nHits; ++i) { //
88 
89  VxdID aVxdID = VxdID(i, i, i);
90 
91  VXD::SensorInfoBase aSensorInfo = provideSensorInfo(aVxdID, (unsigned short)i, (unsigned short)i + 1., (unsigned short)i + 2.);
92 
93  const PXDCluster* pxdCluster = m_pxdClusterData.appendNew(providePXDCluster(float(i) / float(nHits), float(i) / float(nHits),
94  aVxdID));
95 
96  SpacePoint* newSP = m_spacePointData.appendNew(pxdCluster, &aSensorInfo);
97  B2DEBUG(10, " setup: new spacePoint got arrayIndex: " << newSP->getArrayIndex() << " and VxdID " << newSP->getVxdID());
98  newSP->addRelationTo(pxdCluster);
99  }
100 
101  B2DEBUG(10, "DirectedNodeNetworkTest:SetUP: created " << m_pxdClusterData.getEntries() << "/" << m_spacePointData.getEntries() <<
102  " pxdClusters/SpacePoints");
103 
105  vector<SpacePoint*> allSpacePoints;
106  for (SpacePoint& aSP : m_spacePointData) {
107  allSpacePoints.push_back(&aSP);
108  }
109 
110  vector<const SpacePoint*> sps4TC1 = { allSpacePoints.at(0), allSpacePoints.at(1)};
111  SpacePointTrackCand* aSPTC1 = m_spacePointTrackCandData.appendNew((sps4TC1)); // shares hits with no one
112  aSPTC1->setQualityIndicator(0.92);
113 
114  vector<const SpacePoint*> sps4TC2 = { allSpacePoints.at(2), allSpacePoints.at(3)};
115  SpacePointTrackCand* aSPTC2 = m_spacePointTrackCandData.appendNew((sps4TC2)); // shares a hit with tc3, tc4, tc5
116  aSPTC2->setQualityIndicator(0.9);
117 
118  vector<const SpacePoint*> sps4TC3 = { allSpacePoints.at(3), allSpacePoints.at(4)};
119  SpacePointTrackCand* aSPTC3 = m_spacePointTrackCandData.appendNew((sps4TC3)); // shares a hit with tc2, tc5
120  aSPTC3->setQualityIndicator(0.8);
121 
122  vector<const SpacePoint*> sps4TC4 = { allSpacePoints.at(4)};
123  SpacePointTrackCand* aSPTC4 = m_spacePointTrackCandData.appendNew((sps4TC4)); // shares a hit with tc3 too, but not with tc2
124  aSPTC4->setQualityIndicator(0.7);
125 
126  vector<const SpacePoint*> sps4TC5 = { allSpacePoints.at(2), allSpacePoints.at(4)};
127  SpacePointTrackCand* aSPTC5 = m_spacePointTrackCandData.appendNew((sps4TC5)); // shares a hit with tc2 and tc3
128  aSPTC5->setQualityIndicator(0.65);
129  }
130 
132  virtual void TearDown() { DataStore::Instance().reset(); }
133 
139  };
140 
141 
142 
143 
145  TEST_F(DirectedNodeNetworkTest, MockupSanityCheck)
146  {
147  EXPECT_EQ(5, m_pxdClusterData.getEntries());
148  EXPECT_EQ(5, m_spacePointData.getEntries());
149  EXPECT_EQ(m_pxdClusterData.getEntries(), m_spacePointData.getEntries());
150  EXPECT_EQ(5, m_spacePointTrackCandData.getEntries());
151  }
152 
153 
154 
160  TEST_F(DirectedNodeNetworkTest, CreateNetworkIntAndThoroughlyTestIntendedBehavior)
161  {
162  // here some tool-definitions first:
163 
165  auto nodeWasFound = [&](std::vector<DirectedNode<int, VoidMetaInfo>*>& nodes, DirectedNode<int, VoidMetaInfo>* node) -> bool {
166  for (DirectedNode<int, VoidMetaInfo>* otherNode : nodes)
167  {
168  if (node->getEntry() == otherNode->getEntry()) { return true; }
169  }
170  return false;
171  };
172 
174  auto printNodeEntries = [&](std::vector<DirectedNode<int, VoidMetaInfo>*>& nodes) -> std::string {
175  std::string output = "Nodes got the following entries: ";
176  for (DirectedNode<int, VoidMetaInfo>* node : nodes)
177  {
178  output += std::to_string(node->getEntry()) + " ";
179  }
180  return output + "\n";
181  };
182 
183  // just some input for testing:
184  std::array<int, 5> intArray = { { 2, 5, 3, 4, 99} };
185  std::array<int, 5> intArray2 = { { 144, 121, 33, 35, 31415} }; // these entries are independent of the first intArray-entries
186  std::array<int, 5> intArray3 = { { 1440, 1210, 3, 33, 3141529} }; // entry 2 crosses intArray, entry 3 crosses intArray2
187  std::deque<int> onTheFlyCreatedInts; // the user has to take care about the lifetime of the objects to be linked in the network!
188  EXPECT_EQ(5, intArray.size());
189 
191  EXPECT_EQ(0, intNetwork.size());
192  B2INFO("tests case when both nodes are new and when inner one is new, but outer one not");
193  for (unsigned int index = 1 ; index < 5; index++) {
194  B2INFO("intArray-index " << index << " of array has entry: " << intArray.at(index));
195 
196  intNetwork.addNode(intArray.at(index - 1), intArray.at(index - 1));
197  intNetwork.addNode(intArray.at(index), intArray.at(index));
198  // correct order: outerEntry, innerEntry:
199  intNetwork.linkNodes(intArray.at(index - 1), intArray.at(index));
200 
201  // innerEnd has been updated:
202  EXPECT_EQ(intArray.at(index), intNetwork.getInnerEnds().at(0)->getEntry());
203 
204  // entries are now in network:
205  EXPECT_EQ(intArray.at(index - 1), *intNetwork.getNode(intArray.at(index - 1)));
206  EXPECT_EQ(intArray.at(index), *intNetwork.getNode(intArray.at(index)));
207 
208  // get all nodes of outer node, expected: 1 inner and no outerNodes:
209  auto& innerNodes = intNetwork.getNode(intArray.at(index - 1))->getInnerNodes();
210  auto& outerNodes = intNetwork.getNode(intArray.at(index))->getOuterNodes();
211  EXPECT_EQ(1, innerNodes.size());
212  EXPECT_EQ(1, outerNodes.size());
213 
214  // array[index] is now linked as inner node of array[index-1]:
215  EXPECT_EQ(*(innerNodes.at(0)), *(intNetwork.getNode(intArray.at(index))));
216  }
217  EXPECT_EQ(0, intNetwork.getNode(intArray.at(0))->getOuterNodes().size()); // the outermost node has no outerNodes
218  EXPECT_EQ(0, intNetwork.getNode(intArray.at(4))->getInnerNodes().size()); // the innermost node has no innerNodes
219 
220  // some extra sanity checks, are inner- and outerEnds as expected?
221  EXPECT_EQ(intArray.size(), intNetwork.size());
222  std::vector<DirectedNode<int, VoidMetaInfo>*> outerEnds_before = intNetwork.getOuterEnds();
223  std::vector<DirectedNode<int, VoidMetaInfo>*> innerEnds_before = intNetwork.getInnerEnds();
224  EXPECT_EQ(1, outerEnds_before.size());
225  EXPECT_EQ(1, innerEnds_before.size());
226 
227  DirectedNode<int, VoidMetaInfo>* outermostNode = outerEnds_before.at(0);
228  EXPECT_EQ(intArray.at(0), outermostNode->getEntry());
229  EXPECT_EQ(outermostNode->getEntry(), *outermostNode);
230  EXPECT_EQ(intArray.at(1), *(outermostNode->getInnerNodes().at(0)));
231 
232  DirectedNode<int, VoidMetaInfo>* innermostNode = innerEnds_before.at(0);
233  EXPECT_EQ(intArray.at(4), innermostNode->getEntry());
234  EXPECT_EQ(innermostNode->getEntry(), *innermostNode);
235  EXPECT_EQ(intArray.at(3), *(innermostNode->getOuterNodes().at(0)));
236 
237 
238  {
239  B2INFO("building another path, which is independent of the first one:");
240  for (unsigned int index = 1 ; index < 5; index++) {
241  B2INFO("intArray2-index " << index << " of array has entry: " << intArray2.at(index));
242 
243  intNetwork.addNode(intArray2.at(index - 1), intArray2.at(index - 1));
244  intNetwork.addNode(intArray2.at(index), intArray2.at(index));
245  // correct order: outerEntry, innerEntry:
246  intNetwork.linkNodes(intArray2.at(index - 1), intArray2.at(index));
247 
248  // entries are now in network:
249  EXPECT_EQ(intArray2.at(index - 1), *intNetwork.getNode(intArray2.at(index - 1)));
250  EXPECT_EQ(intArray2.at(index), *intNetwork.getNode(intArray2.at(index)));
251 
252  // get all nodes of outer node, expected: 1 inner and no outerNodes:
253  auto& innerNodes = intNetwork.getNode(intArray2.at(index - 1))->getInnerNodes();
254  auto& outerNodes = intNetwork.getNode(intArray2.at(index))->getOuterNodes();
255  EXPECT_EQ(1, innerNodes.size());
256  EXPECT_EQ(1, outerNodes.size());
257 
258  // array[index] is now linked as inner node of array[index-1]:
259  EXPECT_TRUE(nodeWasFound(innerNodes, intNetwork.getNode(intArray2.at(index))));
260  EXPECT_EQ(*(innerNodes.at(0)), *(intNetwork.getNode(intArray2.at(index))));
261  }
262  EXPECT_EQ(0, intNetwork.getNode(intArray2.at(0))->getOuterNodes().size()); // the outermost node has no outerNodes
263  EXPECT_EQ(0, intNetwork.getNode(intArray2.at(4))->getInnerNodes().size()); // the innermost node has no innerNodes
264 
265  // some extra sanity checks, are inner- and outerEnds as expected?
266  EXPECT_EQ(10, intNetwork.size());
267  std::vector<DirectedNode<int, VoidMetaInfo>*> outerEnds = intNetwork.getOuterEnds();
268  std::vector<DirectedNode<int, VoidMetaInfo>*> innerEnds = intNetwork.getInnerEnds();
269  EXPECT_EQ(2, outerEnds.size());
270  EXPECT_EQ(2, innerEnds.size());
271  }
272 
273 
274  B2INFO("building another path into the network which crosses the other paths:"); {
275  B2INFO("tests cases: both new, outer new but inner not, inner new but outer not, both already existing:");
276  for (unsigned int index = 1 ; index < 5; index++) {
277  B2INFO("intArray3-indices " << index - 1 << "/" << index <<
278  " of array have entries: " << intArray3.at(index - 1) << "/" << intArray3.at(index) << "\n"
279  );
280 
281  intNetwork.addNode(intArray3.at(index - 1), intArray3.at(index - 1));
282  intNetwork.addNode(intArray3.at(index), intArray3.at(index));
283  // correct order: outerEntry, innerEntry:
284  intNetwork.linkNodes(intArray3.at(index - 1), intArray3.at(index));
285 
286  // entries are now in network:
287  EXPECT_EQ(intArray3.at(index - 1), *intNetwork.getNode(intArray3.at(index - 1)));
288  EXPECT_EQ(intArray3.at(index), *intNetwork.getNode(intArray3.at(index)));
289 
290  // array[index] is now linked as an inner node of array[index-1]:
291  EXPECT_TRUE(nodeWasFound(intNetwork.getNode(intArray3.at(index - 1))->getInnerNodes(),
292  intNetwork.getNode(intArray3.at(index))));
293 
294 
295  if (index > 1) continue; // the following tests do not work for paths crossing each other, therefore tests would fail
296  // innerEnd has been updated:
297  std::vector<DirectedNode<int, VoidMetaInfo>*> innerEnds = intNetwork.getInnerEnds();
298  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray3.at(index))));
299  B2INFO("innerEnds after indices " << index - 1 << "/" << index << " are: " << printNodeEntries(innerEnds));
300 
301  // get all nodes of outer node, expected: 1 inner and no outerNodes:
302  auto& innerNodes = intNetwork.getNode(intArray3.at(index - 1))->getInnerNodes();
303  auto& outerNodes = intNetwork.getNode(intArray3.at(index))->getOuterNodes();
304  EXPECT_EQ(1, innerNodes.size());
305  EXPECT_EQ(1, outerNodes.size());
306  }
307  EXPECT_EQ(0, intNetwork.getNode(intArray3.at(0))->getOuterNodes().size()); // the outermost node has no outerNodes
308  EXPECT_EQ(0, intNetwork.getNode(intArray3.at(4))->getInnerNodes().size()); // the innermost node has no innerNodes
309 
310  // some extra sanity checks, are inner- and outerEnds as expected?
311  EXPECT_EQ(13, intNetwork.size());
312  //B2INFO(" theWholeNetwork: \n" << printNodeEntries(intNetwork.getNodes()));
313  std::vector<DirectedNode<int, VoidMetaInfo>*> outerEnds = intNetwork.getOuterEnds();
314  std::vector<DirectedNode<int, VoidMetaInfo>*> innerEnds = intNetwork.getInnerEnds();
315  EXPECT_EQ(3, outerEnds.size());
316  EXPECT_EQ(3, innerEnds.size());
317  B2INFO("outerEnds are: \n" << printNodeEntries(outerEnds));
318  B2INFO("innerEnds are: \n" << printNodeEntries(innerEnds));
319  }
320 
321  B2INFO("case: when outer node is new, but inner one not: "); {
322  B2INFO(" case: inner one was outer end before: ");
323  auto* oldOuterMostNode = intNetwork.getOuterEnds().at(0);
324  int oldOuterInt = oldOuterMostNode->getEntry();
325  onTheFlyCreatedInts.push_back(42);
326  int& newInnerInt = onTheFlyCreatedInts.back();
327  EXPECT_TRUE(nullptr == intNetwork.getNode(newInnerInt));
328  intNetwork.addNode(newInnerInt, newInnerInt);
329  intNetwork.linkNodes(newInnerInt, oldOuterInt);
330  EXPECT_FALSE(nullptr == intNetwork.getNode(newInnerInt));
331  EXPECT_EQ(14, intNetwork.size());
332  EXPECT_EQ(3, intNetwork.getInnerEnds().size());
333  std::vector<DirectedNode<int, VoidMetaInfo>*> newOuterEnds = intNetwork.getOuterEnds();
334  EXPECT_EQ(3, newOuterEnds.size()); // did not change, new outermost node replaced old one
335  EXPECT_EQ(1, oldOuterMostNode->getOuterNodes().size());
336  EXPECT_EQ(newInnerInt, *(oldOuterMostNode->getOuterNodes().at(0)));
337  }
338 
339  {
340  B2INFO(" case: inner one was no outer end before: ");
341  onTheFlyCreatedInts.push_back(23);
342  int& newOuterInt = onTheFlyCreatedInts.back();
343  int& existingInt = intArray.at(1); // neither an outer nor an inner end before.
344  std::vector<DirectedNode<int, VoidMetaInfo>*> oldOuterEnds = intNetwork.getOuterEnds();
345  std::vector<DirectedNode<int, VoidMetaInfo>*> oldInnerEnds = intNetwork.getInnerEnds();
346 
347  EXPECT_EQ(3, oldOuterEnds.size());
348  EXPECT_TRUE(nullptr == intNetwork.getNode(newOuterInt));
349  unsigned int sizeB4 = intNetwork.size();
350  intNetwork.addNode(newOuterInt, newOuterInt);
351  intNetwork.linkNodes(newOuterInt, existingInt);
352  EXPECT_FALSE(nullptr == intNetwork.getNode(newOuterInt));
353  EXPECT_EQ(sizeB4 + 1, intNetwork.size());
354  EXPECT_EQ(3, intNetwork.getInnerEnds().size());
355  DirectedNode<int, VoidMetaInfo>* existingNode = intNetwork.getNode(existingInt);
356  EXPECT_EQ(1, existingNode->getInnerNodes().size());
357  EXPECT_EQ(2, existingNode->getOuterNodes().size());
358  std::vector<DirectedNode<int, VoidMetaInfo>*> newOuterEnds = intNetwork.getOuterEnds();
359  EXPECT_EQ(4, newOuterEnds.size()); // did change, new outermost node co-existing with old outermost one
360  EXPECT_EQ(2, existingNode->getOuterNodes().size());
361 
362  }
363 
364 
365  {
366  B2INFO("case: when both were there, but not linked yet: ");
367  unsigned int sizeB4 = intNetwork.size();
368  intNetwork.linkNodes(intArray.at(0), intArray.at(2));
369  EXPECT_EQ(sizeB4, intNetwork.size()); // size of network does not change
370  EXPECT_EQ(3, intNetwork.getInnerEnds().size()); // this can not change here
371  EXPECT_EQ(4, intNetwork.getOuterEnds().size());
372  std::vector<DirectedNode<int, VoidMetaInfo>*> innerEnds = intNetwork.getNode(intArray.at(0))->getInnerNodes();
373  EXPECT_EQ(2, innerEnds.size());
374  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray.at(1))));
375  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray.at(2))));
376  EXPECT_TRUE(nodeWasFound(innerEnds, innerEnds.at(1)));
377 
378 
379  B2INFO("case: when outer both were there and already linked: ");
380  EXPECT_FALSE(intNetwork.linkNodes(intArray.at(0), intArray.at(2)));
381  // nothing was added, everything the same as last case:
382  EXPECT_EQ(sizeB4, intNetwork.size());
383  EXPECT_EQ(3, intNetwork.getInnerEnds().size());
384  EXPECT_EQ(4, intNetwork.getOuterEnds().size());
385  std::vector<DirectedNode<int, VoidMetaInfo>*> moreInnerEnds = intNetwork.getNode(intArray.at(0))->getInnerNodes();
386  EXPECT_EQ(innerEnds.size(), moreInnerEnds.size());
387  EXPECT_TRUE(nodeWasFound(innerEnds, moreInnerEnds.at(0)));
388  EXPECT_TRUE(nodeWasFound(innerEnds, moreInnerEnds.at(1)));
389  }
390 
391 
392  B2INFO("testing members for filling, when (at least) one entry was already there:"); {
393  B2INFO("case: addInnerToLastOuterNode: both were there, but not linked yet: ");
394  unsigned int networkSizeB4 = intNetwork.size();
395  unsigned int nInnerEndsB4 = intNetwork.getInnerEnds().size();
396  intNetwork.addInnerToLastOuterNode(intArray.at(3));
397  EXPECT_EQ(networkSizeB4, intNetwork.size());
398  EXPECT_EQ(nInnerEndsB4, intNetwork.getInnerEnds().size());
399  std::vector<DirectedNode<int, VoidMetaInfo>*> innerEnds = intNetwork.getNode(intArray.at(0))->getInnerNodes();
400  EXPECT_EQ(3, innerEnds.size());
401 
402  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray.at(1))));
403  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray.at(2))));
404  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray.at(3))));
405  }
406 
407 
408  {
409  B2INFO("case: addInnerToLastOuterNode: both were there, but already linked (same results as before, but with an error for unintended behavior):");
410  unsigned int networkSizeB4 = intNetwork.size();
411  unsigned int nInnerEndsB4 = intNetwork.getInnerEnds().size();
412  intNetwork.addInnerToLastOuterNode(intArray.at(3));
413  EXPECT_EQ(networkSizeB4, intNetwork.size());
414  EXPECT_EQ(nInnerEndsB4, intNetwork.getInnerEnds().size());
415  std::vector<DirectedNode<int, VoidMetaInfo>*> innerEnds = intNetwork.getNode(intArray.at(0))->getInnerNodes();
416  EXPECT_EQ(3, innerEnds.size());
417 
418  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray.at(1))));
419  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray.at(2))));
420  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(intArray.at(3))));
421  }
422  /*
423  {
424  B2INFO("case: addInnerToLastOuterNode: inner was not there yet (innerEndsUpdate):");
425  onTheFlyCreatedInts.push_back(31);
426  int& lastOuterNodeInt = intNetwork.getLastOuterNode()->getEntry();
427  int& newInnerInt = onTheFlyCreatedInts.back();
428  unsigned int networkSizeB4 = intNetwork.size();
429  unsigned int nInnerEndsB4 = intNetwork.getInnerEnds().size();
430  unsigned int nInnerNodesB4 = intNetwork.getNode(lastOuterNodeInt)->getInnerNodes().size();
431  intNetwork.addInnerToLastOuterNode(newInnerInt);
432  EXPECT_EQ(networkSizeB4 + 1, intNetwork.size());
433  EXPECT_EQ(nInnerEndsB4 + 1, intNetwork.getInnerEnds().size());
434  EXPECT_EQ(nInnerNodesB4 + 1, intNetwork.getNode(lastOuterNodeInt)->getInnerNodes().size());
435 
436  EXPECT_TRUE(nodeWasFound(intNetwork.getNode(lastOuterNodeInt)->getInnerNodes(), intNetwork.getNode(newInnerInt)));
437  auto innerEnds = intNetwork.getInnerEnds();
438  EXPECT_TRUE(nodeWasFound(innerEnds, intNetwork.getNode(newInnerInt)));
439  }
440 
441  {
442  B2INFO("case: addOuterToLastInnerNode: both were there, but not linked yet:");
443  int& lastInnerNodeInt = intNetwork.getLastInnerNode()->getEntry();
444  unsigned int networkSizeB4 = intNetwork.size();
445  unsigned int nOuterEndsB4 = intNetwork.getOuterEnds().size();
446  intNetwork.addOuterToLastInnerNode(intArray2.at(1));
447  EXPECT_EQ(networkSizeB4, intNetwork.size());
448  EXPECT_EQ(nOuterEndsB4, intNetwork.getOuterEnds().size());
449  std::vector<DirectedNode<int, VoidMetaInfo>*> outerNodes = intNetwork.getNode(lastInnerNodeInt)->getOuterNodes();
450  EXPECT_EQ(2, outerNodes.size());
451  }
452 
453  {
454  B2INFO("case: addOuterToLastInnerNode: both were there, but already linked (same results as before, but with an error for unintended behavior):");
455  int& lastInnerNodeInt = intNetwork.getLastInnerNode()->getEntry();
456  unsigned int networkSizeB4 = intNetwork.size();
457  unsigned int nOuterEndsB4 = intNetwork.getOuterEnds().size();
458  intNetwork.addOuterToLastInnerNode(intArray2.at(1));
459  EXPECT_EQ(networkSizeB4, intNetwork.size());
460  EXPECT_EQ(nOuterEndsB4, intNetwork.getOuterEnds().size());
461  std::vector<DirectedNode<int, VoidMetaInfo>*> outerNodes = intNetwork.getNode(lastInnerNodeInt)->getOuterNodes();
462  EXPECT_EQ(2, outerNodes.size());
463  }
464 
465  {
466  B2INFO("case: addOuterToLastInnerNode: outer was not there yet (outerEndsUpdate):");
467  onTheFlyCreatedInts.push_back(66);
468  int& lastInnerNodeInt = intNetwork.getLastInnerNode()->getEntry();
469  int& newOuterInt = onTheFlyCreatedInts.back();
470  unsigned int networkSizeB4 = intNetwork.size();
471  unsigned int nOuterEndsB4 = intNetwork.getOuterEnds().size();
472  unsigned int nOuterNodesB4 = intNetwork.getNode(lastInnerNodeInt)->getOuterNodes().size();
473  intNetwork.addOuterToLastInnerNode(newOuterInt);
474  EXPECT_EQ(networkSizeB4 + 1, intNetwork.size());
475  EXPECT_EQ(nOuterEndsB4 + 1, intNetwork.getOuterEnds().size());
476  EXPECT_EQ(nOuterNodesB4 + 1, intNetwork.getNode(lastInnerNodeInt)->getOuterNodes().size());
477 
478  EXPECT_TRUE(nodeWasFound(intNetwork.getNode(lastInnerNodeInt)->getOuterNodes(), intNetwork.getNode(newOuterInt)));
479  auto outerEnds = intNetwork.getOuterEnds();
480  EXPECT_TRUE(nodeWasFound(outerEnds, intNetwork.getNode(newOuterInt)));
481  }
482  */
483  }
484 
485 
489  /*
490  TEST_F(DirectedNodeNetworkTest, CreateRealisticNetwork)
491  {
492  // testing to write that container now onto the datastore:
493  DirectedNodeNetworkContainer* realisticNetworkPtr = networkContainerInDataStore.appendNew();
494  DirectedNodeNetwork<TrackNode, VoidMetaInfo> hitNetwork = realisticNetworkPtr->accessHitNetwork();
495  vector<TrackNode*> trackNodes = realisticNetworkPtr->accessTrackNodes();
496 
497  const DirectedNodeNetworkContainer::StaticSectorType dummyStaticSector;
498  // const StaticSectorType * staticSectorPtr = &dummyStaticSector; // WARNING TODO warum funzt diese Konvertierung net?!?
499  ActiveSector<DirectedNodeNetworkContainer::StaticSectorType, TrackNode> dummyActiveSector(&dummyStaticSector);
500 
501  EXPECT_EQ(0, hitNetwork.size());
502 
503  unsigned nEntries = spacePointData.getEntries();
504  for (SpacePoint& aSP : spacePointData) {
505  trackNodes.push_back(new TrackNode());
506  TrackNode* node = trackNodes.back();
507  node->spacePoint = &aSP;
508  node->sector = &dummyActiveSector;
509  }
510 
511  // filling: correct usage:
512  // tests case when both nodes are new and when inner one is new, but outer one not:
513  for (unsigned int index = 1 ; index < nEntries; index++) {
514  TrackNode* outerNode = trackNodes[index - 1];
515  TrackNode* innerNode = trackNodes[index];
516  SpacePoint& outerSP = *(outerNode->spacePoint);
517  SpacePoint& innerSP = *(innerNode->spacePoint);
518 
519  B2INFO("CreateRealisticNetwork: index " << index);
520 
521  // correct order: outerEntry, innerEntry:
522  hitNetwork.linkTheseEntries(*outerNode, *innerNode);
523 
524  // innerEnd has been updated:
525  EXPECT_EQ(innerSP, *(hitNetwork.getInnerEnds().at(0)->getEntry().spacePoint));
526 
527  // entries are now in network:
528  EXPECT_EQ(outerSP, *(hitNetwork.getNode(*outerNode)->getEntry().spacePoint));
529  EXPECT_EQ(innerSP, *(hitNetwork.getNode(*innerNode)->getEntry().spacePoint));
530  EXPECT_EQ(*outerNode, *hitNetwork.getNode(*outerNode));
531  EXPECT_EQ(*innerNode, *hitNetwork.getNode(*innerNode));
532 
533  // get all nodes of outer node, expected: 1 inner and no outerNodes:
534  auto& innerNodes = hitNetwork.getNode(*outerNode)->getInnerNodes();
535  auto& outerNodes = hitNetwork.getNode(*innerNode)->getOuterNodes();
536  EXPECT_EQ(1, innerNodes.size());
537  EXPECT_EQ(1, outerNodes.size());
538 
539  // array[index] is now linked as inner node of array[index-1]:
540  EXPECT_EQ(*(innerNodes.at(0)), *(hitNetwork.getNode(*innerNode)));
541  }
542 
543  EXPECT_EQ(0, hitNetwork.getNode(*trackNodes[0])->getOuterNodes().size()); // the outermost node has no outerNodes
544  EXPECT_EQ(0, hitNetwork.getNode(*trackNodes[4])->getInnerNodes().size()); // the innermost node has no innerNodes
545 
546  // some extra sanity checks, are inner- and outerEnds as expected?
547  EXPECT_EQ(nEntries, hitNetwork.size());
548  std::vector<DirectedNode<TrackNode, VoidMetaInfo>*> outerEnds = hitNetwork.getOuterEnds();
549  std::vector<DirectedNode<TrackNode, VoidMetaInfo>*> innerEnds = hitNetwork.getInnerEnds();
550  EXPECT_EQ(1, outerEnds.size());
551  EXPECT_EQ(1, innerEnds.size());
552 
553  DirectedNode<TrackNode, VoidMetaInfo>* outermostNode = outerEnds.at(0);
554  EXPECT_EQ(*spacePointData[0], *(outermostNode->getEntry().spacePoint));
555  EXPECT_EQ(*spacePointData[1], *(outermostNode->getInnerNodes().at(0)->getEntry().spacePoint));
556 
557  DirectedNode<TrackNode, VoidMetaInfo>* innermostNode = innerEnds.at(0);
558  EXPECT_EQ(*spacePointData[4], *(innermostNode->getEntry().spacePoint));
559  EXPECT_EQ(innermostNode->getEntry(), *innermostNode);
560  EXPECT_EQ(*spacePointData[3], *(innermostNode->getOuterNodes().at(0)->getEntry().spacePoint));
561 
562 
563 
564  // preparing some extra data for testing:
565  VxdID aID;
566  VXD::SensorInfoBase aSensorInfo = provideSensorInfo(aID, 2, 4, 5);
567 
568  PXDCluster pxdCluster = providePXDCluster(2.3 , 4.2, aID);
569  SpacePoint newSP = SpacePoint(&pxdCluster, &aSensorInfo);
570  TrackNode newNode = TrackNode();
571  newNode.spacePoint = & newSP;
572  newNode.sector = &dummyActiveSector;
573 
574 
575  // testing case, when outer node is new, but inner one not:
576  TrackNode& oldNode = outermostNode->getEntry();
577  hitNetwork.linkTheseEntries(newNode, oldNode);
578  EXPECT_EQ(6, hitNetwork.size());
579 
580  std::vector<DirectedNode<TrackNode, VoidMetaInfo>*> newOuterEnds = hitNetwork.getOuterEnds();
581  EXPECT_EQ(1, newOuterEnds.size());
582  DirectedNode<TrackNode, VoidMetaInfo>* newOutermostNode = newOuterEnds.at(0);
583  EXPECT_NE(oldNode, newOutermostNode->getEntry());
584  EXPECT_EQ(newNode, newOutermostNode->getEntry());
585  EXPECT_EQ(*spacePointData[0], *(newOutermostNode->getInnerNodes().at(0)->getEntry().spacePoint));
586  EXPECT_EQ(newNode, *(outermostNode->getOuterNodes().at(0)));
587 
588 
589  // testing case, when outer both were there, but not linked yet:
590  hitNetwork.linkTheseEntries(*trackNodes[0], *trackNodes[2]);
591  EXPECT_EQ(6, hitNetwork.size()); // size of network does not change
592  std::vector<DirectedNode<TrackNode, VoidMetaInfo>*> moreInnerEnds = hitNetwork.getNode(*trackNodes[0])->getInnerNodes();
593  EXPECT_EQ(2, moreInnerEnds.size());
594  EXPECT_EQ(*trackNodes[1], *moreInnerEnds.at(0));
595  EXPECT_EQ(*trackNodes[2], *moreInnerEnds.at(1));
596 
597 
598  // testing case, when outer both were there and already linked:
599  hitNetwork.linkTheseEntries(*trackNodes[0], *trackNodes[2]);
600 
601  // nothing was added, everything the same as last case:
602  EXPECT_EQ(6, hitNetwork.size());
603  std::vector<DirectedNode<TrackNode, VoidMetaInfo>*> evenMoreInnerEnds = hitNetwork.getNode(*trackNodes[0])->getInnerNodes();
604  EXPECT_EQ(moreInnerEnds.size(), evenMoreInnerEnds.size());
605  EXPECT_EQ(*moreInnerEnds.at(0), *evenMoreInnerEnds.at(0));
606  EXPECT_EQ(*moreInnerEnds.at(1), *evenMoreInnerEnds.at(1));
607  }*/
608 } // end namespace
609 
610 
611 
Network of directed nodes of the type EntryType.
bool addInnerToLastOuterNode(NodeID innerNodeID)
to the last outerNode added, another innerNode will be attached
Node * getNode(NodeID toBeFound)
Returns pointer to the node carrying the entry which is equal to given parameter.
std::vector< Node * > getOuterEnds()
getters:
unsigned int size() const
Returns number of nodes to be found in the network.
bool linkNodes(NodeID outerNodeID, NodeID innerNodeID)
takes two entry IDs and weaves them into the network
std::vector< Node * > getInnerEnds()
returns all nodes which have no inner nodes (but outer ones) and therefore are inner ends of the netw...
bool addNode(NodeID nodeID, EntryType &newEntry)
************************* PUBLIC MEMBER FUNCTIONS *************************
The Node-Class.
Definition: DirectedNode.h:31
std::vector< DirectedNode< EntryType, MetaInfoType > * > & getOuterNodes()
Returns links to all outer nodes attached to this one.
Definition: DirectedNode.h:89
std::vector< DirectedNode< EntryType, MetaInfoType > * > & getInnerNodes()
************************* PUBLIC MEMBER FUNCTIONS *************************
Definition: DirectedNode.h:86
EntryType & getEntry()
Allows access to stored entry.
Definition: DirectedNode.h:92
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Storage for (VXD) SpacePoint-based track candidates.
void setQualityIndicator(const double newIndicator)
sets the new status of the estimated quality of this track candidate.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
Definition: SpacePoint.h:148
Base class to provide Sensor Information for PXD and SVD.
void setTransformation(const TGeoHMatrix &transform, bool reco=false)
Set the transformation matrix of the Sensor.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Test class demonstrating the behavior of TCNetworkContainer.
StoreArray< DirectedNodeNetworkContainer > m_networkContainerInDataStore
testing to store a dummy class containing DirectedNodeNetwork as member .
StoreArray< PXDCluster > m_pxdClusterData
some pxd clusters for testing.
StoreArray< SpacePoint > m_spacePointData
some spacePoints for testing.
StoreArray< SpacePointTrackCand > m_spacePointTrackCandData
some spacePointTrackCands for testing.
virtual void TearDown()
TearDown environment - clear datastore.
virtual void SetUp()
SetUp environment - prepare related storearrays of SpacePoints and PXDClusters.
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Definition: globalLabel.cc:72
Abstract base class for different kinds of events.
These tests cover the functionality of the classes: DirectedNode, DirectedNodeNetwork.