12 #include <gtest/gtest.h>
14 #include <tracking/spacePointCreation/SpacePoint.h>
15 #include <vxd/geometry/SensorInfoBase.h>
16 #include <tracking/trackFindingVXD/filterMap/twoHitVariables/Distance3DSquared.h>
18 #include <tracking/trackFindingVXD/filterMap/filterFramework/Shortcuts.h>
20 #include <svd/dataobjects/SVDCluster.h>
21 #include <pxd/dataobjects/PXDCluster.h>
22 #include <mdst/dataobjects/MCParticle.h>
24 #include <framework/datastore/StoreArray.h>
54 VXD::SensorInfoBase sensorInfoBase(VXD::SensorInfoBase::PXD, aVxdID, 2.3, 4.2, 0.3, 2, 4, -1);
57 r1.SetAngles(45, 20, 30);
58 TGeoTranslation t1(globalX, globalY, globalZ);
59 TGeoCombiTrans c1(t1, r1);
60 TGeoHMatrix transform = c1;
65 return sensorInfoBase;
73 return PXDCluster(aVxdID, u, v, uError, vError, 0, 0, 1, 1, 1, 1 , 1, 1);
80 return SVDCluster(aVxdID, isU, position, error, 0.1, 0.1, 1, 1, 1, 1);
85 SpacePoint provideSpacePointDummy(
unsigned short i,
double X,
double Y,
double Z)
90 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
104 spacePointData.registerInDataStore();
105 pxdClusterData.registerInDataStore();
106 svdClusterData.registerInDataStore();
107 mcParticleData.registerInDataStore();
109 spacePointData.registerRelationTo(pxdClusterData);
110 pxdClusterData.registerRelationTo(mcParticleData);
112 spacePointData.registerRelationTo(svdClusterData);
113 svdClusterData.registerRelationTo(mcParticleData);
115 DataStore::Instance().setInitializeActive(
false);
118 for (
unsigned int i = 1; i < 3; ++i) {
119 MCParticle* aParticle = mcParticleData.appendNew();
121 aParticle->
setMomentum(
float(i),
float(i),
float(i));
130 SpacePoint* newSP = spacePointData.appendNew(pxdCluster, &aSensorInfo);
131 B2DEBUG(10,
" setup: new spacePoint got arrayIndex: " << newSP->
getArrayIndex() <<
" and VxdID " << newSP->
getVxdID());
135 mcParticleData[0]->setPDG(11);
136 mcParticleData[1]->setPDG(13);
137 mcParticleData[1]->addStatus(MCParticle::c_PrimaryParticle);
140 for (
unsigned int i = 3; i < 7; ++i) {
146 unsigned int pID = (i - 3) / 2;
153 std::vector<const SVDCluster*> clusterVector = {clusterU, clusterV};
155 SpacePoint* newSP = spacePointData.appendNew(clusterVector, &aSensorInfo);
160 B2INFO(
"ObserversTest:SetUP: created " << mcParticleData.getEntries() <<
"/" << pxdClusterData.getEntries() <<
"/" <<
161 svdClusterData.getEntries() <<
"/" << spacePointData.getEntries() <<
" mcParticles/pxdClusters/svdClusters/SpacePoints");
169 DataStore::Instance().reset();
193 static void resetCounter()
219 typedef std::pair< bool, Particles >
Key;
244 void clear() { m_container.clear(); }
248 unsigned int size() {
return m_container.size(); }
254 std::sort(particles.begin(), particles.end());
255 auto newEndIterator = std::unique(particles.begin(), particles.end());
256 particles.resize(std::distance(particles.begin(), newEndIterator));
263 bool keyAlreadyExisted =
true;
264 auto foundPos = m_container.find(aKey);
265 if (foundPos == m_container.end()) {
266 B2DEBUG(100,
" the IDs " << key2str(aKey) <<
" collected haven't been found yet");
268 keyAlreadyExisted =
false;
269 }
else { B2DEBUG(100,
" the IDs " << key2str(aKey) <<
" collected were already there"); }
271 foundPos->second.Increase(accepted);
273 return keyAlreadyExisted;
282 auto foundPos = m_container.find(givenKey);
284 if (foundPos == m_container.end()) {
288 return foundPos->second;
296 for (
const auto& aKey : m_container) {
297 B2DEBUG(100,
"comparing given particles: " << vec2str(givenKey) <<
" with entry: " << vec2str(
298 aKey.first.second) <<
" with result " << (aKey.first.second == givenKey));
299 if (aKey.first.second == givenKey) {
return aKey.second; }
310 for (
auto& entry : m_container) {
311 B2WARNING(
" for " << identifier <<
"-combination: " <<
312 key2str(entry.first) <<
313 ", combi was accepted/rejected: " <<
314 entry.second.accept <<
316 entry.second.reject);
325 return key2str(&aKey);
334 if (aKey->first ==
true) { output +=
"GoodCombi: "; }
335 else { output +=
"BadCombi: "; }
337 output += vec2str(aKey->second);
344 template<
class Type>
static std::string
vec2str(
const vector<Type>& vec)
348 for (
const auto& entry : vec) {
349 output +=
" " + std::to_string(entry);
370 static void resetCounter()
380 template<
class T>
unsigned int counter<T>::used(0);
381 template<
class T>
unsigned int counter<T>::accepted(0);
382 template<
class T>
unsigned int counter<T>::rejected(0);
383 template<
class T>
unsigned int counter<T>::wasInf(0);
384 template<
class T>
unsigned int counter<T>::wasNan(0);
386 template<
class T> CountContainer counterMC< T >::pdGacceptedRejected =
388 template<
class T> CountContainer counterMC< T >::mcIDacceptedRejected =
399 template<
class Var,
typename ... otherTypes>
415 template<
class Var,
class RangeType>
417 typename Var::variableType fResult,
418 const RangeType& range,
419 const typename Var::argumentType&,
420 const typename Var::argumentType&)
422 if (range.contains(fResult)) {
438 template<
class Var,
typename ... otherTypes>
440 typename Var::variableType fResult,
443 if (std::isinf(fResult)) {
445 }
else if (std::isnan(fResult)) {
459 template<
class Var,
class RangeType>
460 static void notify(
const Var& filterType,
461 typename Var::variableType fResult,
462 const RangeType& range,
463 const typename Var::argumentType& outerHit,
464 const typename Var::argumentType& innerHit)
467 stringstream outputStream;
468 outputStream << filterType.name()
469 <<
" with outer-/innerhit: "
470 << outerHit.getPosition().PrintStringXYZ()
472 << innerHit.getPosition().PrintStringXYZ()
473 <<
" having indices "
474 << outerHit.getArrayIndex()
476 << innerHit.getArrayIndex()
478 << outerHit.getVxdID()
480 << innerHit.getVxdID()
484 << (range.contains(fResult) ? string(
"true") : string(
"false"))
490 if (range.contains(fResult)) {
491 B2INFO(outputStream.str());
493 B2WARNING(outputStream.str());
506 template<
class Var,
class RangeType>
508 typename Var::variableType fResult,
509 const RangeType& range,
510 const typename Var::argumentType& outerHit,
511 const typename Var::argumentType& innerHit)
513 B2INFO(
"CountAcceptedRejectedMCParticleObserver called" << endl
514 <<
"range: ( " << range.getInf() <<
" , " << range.getSup() <<
" )" << endl
515 <<
"var = " << fResult << endl
516 <<
"outerHit: (" << outerHit.X() <<
" , "
517 << outerHit.Y() <<
" , "
518 << outerHit.Z() <<
" ) (x,y,z) " << endl
519 <<
"innerHit: (" << innerHit.X() <<
" , "
520 << innerHit.Y() <<
" , "
521 << innerHit.Z() <<
" ) (x,y,z) " << endl
546 template <
class hitType>
547 static void collectPDGs(
const hitType& aHit, vector< pair< bool, int> >& collectedPDGs)
550 std::vector<const MCParticle*> collectedParticles;
552 collectMCParticles(aHit, collectedParticles);
554 for (
const MCParticle* aParticle : collectedParticles) {
555 collectedPDGs.push_back({aParticle->hasStatus(MCParticle::c_PrimaryParticle), aParticle->getPDG()});
568 template <
class hitType>
572 std::vector<const MCParticle*> collectedParticles;
574 collectMCParticles(aHit, collectedParticles);
576 for (
const MCParticle* aParticle : collectedParticles) {
577 collectedIDS.push_back({aParticle->hasStatus(MCParticle::c_PrimaryParticle), aParticle->getIndex()});
582 template <
class hitType>
587 vector< pair< bool, int> > collectedIDS;
590 collectPDGs(hitA, collectedIDS);
591 collectPDGs(hitB, collectedIDS);
593 collectParticleIDs(hitA, collectedIDS);
594 collectParticleIDs(hitB, collectedIDS);
597 CountContainer::uniqueIdentifier(collectedIDS);
599 if (collectedIDS.size() == 1) {
600 newKey.first = collectedIDS[0].first;
601 newKey.second = { collectedIDS[0].second };
605 newKey.first =
false;
607 for (
auto& entry : collectedIDS) {
608 newKey.second.push_back(entry.second);
622 template <
class hitType>
623 static void collectMCParticles(
const hitType& aHit, std::vector<const MCParticle*>& collectedParticles)
628 for (
const PXDCluster& aCluster : relatedToPXDClusters) {
630 collectedParticles.push_back(&aParticle);
634 for (
const SVDCluster& aCluster : relatedToSVDClusters) {
636 collectedParticles.push_back(&aParticle);
644 template<
class Type>
static std::string
vec2str(
const vector<Type>& vec)
648 for (
const auto& entry : vec) {
649 output +=
" " + std::to_string(entry);
661 template<
class Var,
class RangeType>
662 static void notify(
const Var& filterType,
663 typename Var::variableType fResult,
664 const RangeType& range,
665 const typename Var::argumentType& outerHit,
666 const typename Var::argumentType& innerHit)
668 CountUsedObserver::notify(filterType);
669 CountAcceptRejectObserver::notify(filterType, fResult, range, outerHit, innerHit);
670 CountBadCaseObserver::notify(filterType, fResult, range, outerHit, innerHit);
671 InfoObserver::notify(filterType, fResult, range, outerHit, innerHit);
697 typedef std::function< void (
const FilterType&,
typename FilterType::variableType,
const typename FilterType::argumentType&,
const typename FilterType::argumentType&)>
701 using CStyleFunctionPointer = void(*)(
const typename FilterType::argumentType&,
const typename FilterType::argumentType&,
702 const FilterType&,
typename FilterType::variableType) ;
705 template<
typename range,
typename ... otherTypes>
706 static void notify(
const FilterType& filterType,
707 typename FilterType::variableType filterResult,
709 const typename FilterType::argumentType& outerHit,
710 const typename FilterType::argumentType& innerHit,
713 B2INFO(
" Filter " << filterType.name() <<
" with Mag of outer-/innerHit " << outerHit.getPosition().Mag() <<
"/" <<
714 innerHit.getPosition().Mag() <<
" got result of " << filterResult <<
" and Observer-Vector sm_collectedObservers got " <<
716 B2INFO(
" Filter " << filterType.name() <<
" with Mag of outer-/innerHit " << outerHit.getPosition().Mag() <<
"/" <<
717 innerHit.getPosition().Mag() <<
" got result of " << filterResult <<
" and Observer-Vector sm_collectedObserversCSTYLE got " <<
730 template <
typename ObserverType>
734 FilterType(), std::placeholders::_3));
750 template<
typename FilterType> std::vector< typename VectorOfObservers<FilterType>::observerFunction >
753 template<
typename FilterType> std::vector< typename VectorOfObservers<FilterType>::CStyleFunctionPointer >
754 VectorOfObservers<FilterType>::sm_collectedObserversCSTYLE = {};
765 EXPECT_EQ(6, spacePointData.getEntries());
768 unsigned nullptrTrap = 0;
772 if (aParticle == NULL) { nullptrTrap = 1; }
773 EXPECT_EQ(0, nullptrTrap);
775 EXPECT_EQ(aSP.getArrayIndex(), aCluster.getArrayIndex());
787 if (aParticle == NULL) { nullptrTrap = 2; }
788 EXPECT_EQ(0, nullptrTrap);
790 EXPECT_EQ(aSP.getArrayIndex(), 2 + aCluster.getArrayIndex() / 2);
791 EXPECT_EQ(aSP.getArrayIndex() / 4, aParticle->
getArrayIndex());
800 EXPECT_NE(0, pxDClusters.size() + svDClusters.size());
817 for (
int i = 1 ; i < spacePointData.getEntries(); i++) {
820 B2DEBUG(10,
"spData-Sps got arraIndices: " << spacePointData[i]->getArrayIndex() <<
"/" << spacePointData[i - 1]->getArrayIndex() <<
821 " and VxdIDs " << spacePointData[i]->getVxdID() <<
"/" << spacePointData[i - 1]->getVxdID());
822 observedFilter.accept(spA, spB);
825 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.size());
826 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.size());
828 mcCounter.pdGacceptedRejected.PrintResults(
"pdgCode");
841 mcCounter.mcIDacceptedRejected.PrintResults(
"pID");
856 observedFilterStrict(
857 unobservedFilterStrict);
859 for (
int i = 1 ; i < spacePointData.getEntries(); i++) {
862 observedFilterStrict.accept(spA, spB);
865 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.size());
866 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.size());
901 SpacePoint x1 = provideSpacePointDummy(1, 0.0f , 0.0f, 0.0f);
902 SpacePoint x2 = provideSpacePointDummy(1, 0.5f , 0.0f, 0.0f);
903 SpacePoint x3 = provideSpacePointDummy(1, 2.0f , 0.0f, 0.0f);
905 myCounter.resetCounter();
912 auto storeFuncVariantB = std::bind(((
VectorOfObservers<Distance3DSquared<SpacePoint>>::CStyleFunctionPointer)
913 &CountUsedObserver::notify), std::placeholders::_1, std::placeholders::_2, Distance3DSquared<SpacePoint>(),
914 std::placeholders::_3);
916 char* realname(NULL);
918 realname = abi::__cxa_demangle(
typeid(storeFuncVariantB).name(), 0, 0, &status);
919 std::string name(realname);
921 B2INFO(
"storeFuncVariantB is of type: " << name);
933 observedFilter.accept(x2, x1);
934 observedFilter.accept(x3, x1);
935 EXPECT_EQ(0 , myCounter.used);
940 anotherObservedFilter.accept(x2, x1);
941 anotherObservedFilter.accept(x3, x1);
942 EXPECT_EQ(2 , myCounter.used);
943 EXPECT_EQ(1 , myCounter.accepted);
944 EXPECT_EQ(1 , myCounter.rejected);
945 EXPECT_EQ(0 , myCounter.wasInf);
946 EXPECT_EQ(0 , myCounter.wasNan);