9#include <gtest/gtest.h>
11#include <tracking/trackFindingVXD/segmentNetwork/DirectedNode.h>
12#include <tracking/trackFindingVXD/segmentNetwork/DirectedNodeNetwork.h>
13#include <tracking/trackFindingVXD/segmentNetwork/DirectedNodeNetworkContainer.h>
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>
46 r1.SetAngles(45, 20, 30);
47 TGeoTranslation t1(globalX, globalY, globalZ);
48 TGeoCombiTrans c1(t1, r1);
49 TGeoHMatrix transform = c1;
52 return sensorInfoBase;
59 return PXDCluster(aVxdID, u, v, uError, vError, 0, 0, 1, 1, 1, 1, 1, 1);
84 unsigned int nHits = 5;
87 for (
unsigned int i = 1; i <= nHits; ++i) {
97 B2DEBUG(10,
" setup: new spacePoint got arrayIndex: " << newSP->
getArrayIndex() <<
" and VxdID " << newSP->
getVxdID());
102 " pxdClusters/SpacePoints");
105 vector<SpacePoint*> allSpacePoints;
107 allSpacePoints.push_back(&aSP);
110 vector<const SpacePoint*> sps4TC1 = { allSpacePoints.at(0), allSpacePoints.at(1)};
114 vector<const SpacePoint*> sps4TC2 = { allSpacePoints.at(2), allSpacePoints.at(3)};
118 vector<const SpacePoint*> sps4TC3 = { allSpacePoints.at(3), allSpacePoints.at(4)};
122 vector<const SpacePoint*> sps4TC4 = { allSpacePoints.at(4)};
126 vector<const SpacePoint*> sps4TC5 = { allSpacePoints.at(2), allSpacePoints.at(4)};
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());
168 if (node->getEntry() == otherNode->getEntry()) {
return true; }
174 auto printNodeEntries = [&](std::vector<DirectedNode<int, VoidMetaInfo>*>& nodes) -> std::string {
175 std::string output =
"Nodes got the following entries: ";
178 output += std::to_string(node->getEntry()) +
" ";
180 return output +
"\n";
184 std::array<int, 5> intArray = { { 2, 5, 3, 4, 99} };
185 std::array<int, 5> intArray2 = { { 144, 121, 33, 35, 31415} };
186 std::array<int, 5> intArray3 = { { 1440, 1210, 3, 33, 3141529} };
187 std::deque<int> onTheFlyCreatedInts;
188 EXPECT_EQ(5, intArray.size());
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));
196 intNetwork.
addNode(intArray.at(index - 1), intArray.at(index - 1));
197 intNetwork.
addNode(intArray.at(index), intArray.at(index));
199 intNetwork.
linkNodes(intArray.at(index - 1), intArray.at(index));
202 EXPECT_EQ(intArray.at(index), intNetwork.
getInnerEnds().at(0)->getEntry());
205 EXPECT_EQ(intArray.at(index - 1), *intNetwork.
getNode(intArray.at(index - 1)));
206 EXPECT_EQ(intArray.at(index), *intNetwork.
getNode(intArray.at(index)));
211 EXPECT_EQ(1, innerNodes.size());
212 EXPECT_EQ(1, outerNodes.size());
215 EXPECT_EQ(*(innerNodes.at(0)), *(intNetwork.
getNode(intArray.at(index))));
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());
228 EXPECT_EQ(intArray.at(0), outermostNode->
getEntry());
229 EXPECT_EQ(outermostNode->
getEntry(), *outermostNode);
230 EXPECT_EQ(intArray.at(1), *(outermostNode->
getInnerNodes().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)));
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));
243 intNetwork.
addNode(intArray2.at(index - 1), intArray2.at(index - 1));
244 intNetwork.
addNode(intArray2.at(index), intArray2.at(index));
246 intNetwork.
linkNodes(intArray2.at(index - 1), intArray2.at(index));
249 EXPECT_EQ(intArray2.at(index - 1), *intNetwork.
getNode(intArray2.at(index - 1)));
250 EXPECT_EQ(intArray2.at(index), *intNetwork.
getNode(intArray2.at(index)));
255 EXPECT_EQ(1, innerNodes.size());
256 EXPECT_EQ(1, outerNodes.size());
259 EXPECT_TRUE(nodeWasFound(innerNodes, intNetwork.
getNode(intArray2.at(index))));
260 EXPECT_EQ(*(innerNodes.at(0)), *(intNetwork.
getNode(intArray2.at(index))));
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());
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"
281 intNetwork.
addNode(intArray3.at(index - 1), intArray3.at(index - 1));
282 intNetwork.
addNode(intArray3.at(index), intArray3.at(index));
284 intNetwork.
linkNodes(intArray3.at(index - 1), intArray3.at(index));
287 EXPECT_EQ(intArray3.at(index - 1), *intNetwork.
getNode(intArray3.at(index - 1)));
288 EXPECT_EQ(intArray3.at(index), *intNetwork.
getNode(intArray3.at(index)));
292 intNetwork.
getNode(intArray3.at(index))));
295 if (index > 1)
continue;
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));
304 EXPECT_EQ(1, innerNodes.size());
305 EXPECT_EQ(1, outerNodes.size());
311 EXPECT_EQ(13, intNetwork.
size());
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));
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());
333 std::vector<DirectedNode<int, VoidMetaInfo>*> newOuterEnds = intNetwork.
getOuterEnds();
334 EXPECT_EQ(3, newOuterEnds.size());
335 EXPECT_EQ(1, oldOuterMostNode->getOuterNodes().size());
336 EXPECT_EQ(newInnerInt, *(oldOuterMostNode->getOuterNodes().at(0)));
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);
344 std::vector<DirectedNode<int, VoidMetaInfo>*> oldOuterEnds = intNetwork.
getOuterEnds();
345 std::vector<DirectedNode<int, VoidMetaInfo>*> oldInnerEnds = intNetwork.
getInnerEnds();
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());
358 std::vector<DirectedNode<int, VoidMetaInfo>*> newOuterEnds = intNetwork.
getOuterEnds();
359 EXPECT_EQ(4, newOuterEnds.size());
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());
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)));
379 B2INFO(
"case: when outer both were there and already linked: ");
380 EXPECT_FALSE(intNetwork.
linkNodes(intArray.at(0), intArray.at(2)));
382 EXPECT_EQ(sizeB4, intNetwork.
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)));
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();
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());
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))));
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();
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());
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))));
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Network of directed nodes of the type EntryType.
Node * getNode(NodeID toBeFound)
Returns pointer to the node carrying the entry which is equal to given parameter.
std::vector< Node * > getInnerEnds()
returns all nodes which have no inner nodes (but outer ones) and therefore are inner ends of the netw...
bool addInnerToLastOuterNode(NodeID innerNodeID)
to the last outerNode added, another innerNode will be attached
unsigned int size() const
Returns number of nodes to be found in the network.
std::vector< Node * > getOuterEnds()
getters:
bool linkNodes(NodeID outerNodeID, NodeID innerNodeID)
takes two entry IDs and weaves them into the network
bool addNode(NodeID nodeID, EntryType &newEntry)
************************* PUBLIC MEMBER FUNCTIONS *************************
std::vector< DirectedNode< EntryType, MetaInfoType > * > & getInnerNodes()
************************* PUBLIC MEMBER FUNCTIONS *************************
EntryType & getEntry()
Allows access to stored entry.
std::vector< DirectedNode< EntryType, MetaInfoType > * > & getOuterNodes()
Returns links to all outer nodes attached to this one.
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
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.
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
int getEntries() const
Get the number of objects in the array.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
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.
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.
Abstract base class for different kinds of events.
These tests cover the functionality of the classes: DirectedNode, DirectedNodeNetwork.
PXDCluster providePXDCluster(double u, double v, VxdID aVxdID, double uError=0.1, double vError=0.1)
helper function: returns a pxdCluster with given sensorID and local coordinates
VXD::SensorInfoBase provideSensorInfo(VxdID aVxdID, double globalX=0., double globalY=0., double globalZ=-0.)
helper function: create a sensorInfo to be used