Belle II Software development
VXDTFObserversTest Namespace Reference

TODO next steps: More...

Classes

class  CountAcceptedRejectedMCParticleObserver
 this observer identifies the McParticles responsible for creating underlying clusters for given spacePoints and counts how often a particle type was accepted and how often it was rejected More...
 
class  CountAcceptRejectObserver
 this observer does simply count the number of times, the attached SelectionVariable was accepted or rejected More...
 
class  CountBadCaseObserver
 this observer does simply count the number of times, the attached Filter resulted in isinf or isnan More...
 
class  CountContainer
 a container for counting accepted and rejected stuff, just delivers some interfaces to make the code more readable More...
 
class  counter
 a tiny counter class for counting stuff More...
 
class  counterMC
 a tiny counter class for counting stuff retrieved from MC-bla More...
 
class  CountUsedObserver
 this observer does simply count the number of times, the attached SelectionVariable was used More...
 
class  InfoObserver
 this observer does simply print the name of the SelectionVariable and the result of its value-function as a Warning More...
 
class  ObserversTest
 Test class for testing and developing new Observers. More...
 
class  ProvideBasicInfoObserver
 this observer combines all the easy-to-get info retrievable by observers and prints it to screen More...
 
class  VectorOfObservers
 WARNING TODO: More...
 

Functions

VXD::SensorInfoBase provideSensorInfo (VxdID aVxdID, double globalX=0., double globalY=0., double globalZ=-0.)
 this is a small helper function to create a sensorInfo to be used
 
PXDCluster providePXDCluster (double u, double v, VxdID aVxdID, double uError=0.1, double vError=0.1)
 returns a pxdCluster with given sensorID and local coordinates
 
SVDCluster provideSVDCluster (VxdID aVxdID, bool isU, double position, double error=0.1)
 returns a svdCluster with given sensorID, uType and local position
 
SpacePoint provideSpacePointDummy (unsigned short i, double X, double Y, double Z)
 when given index number for vxdID and global coordinates, a SpacePoint lying there will be returned
 
 TEST_F (ObserversTest, TestRelationSetup)
 initialize static member of variant Try2
 
 TEST_F (ObserversTest, TestMCDataAccess)
 tests possibility of accessing MCData
 
 TEST_F (ObserversTest, TestObserverFlexibility)
 presents the functionality of the SpacePoint-creating function written above
 
 TEST_F (ObserversTest, ignoreMe)
 ignore what is written in this test, is simply used as a temporary storage for currently not used code-snippets
 

Detailed Description

TODO next steps:

  • write an observer reading relevant info (like whether two clusters of a spacePoint are related to the same mcParticle)
  • implement easy container to be filled by observers
  • write an observer which fills this container
  • write all the other observers planned

Function Documentation

◆ providePXDCluster()

PXDCluster providePXDCluster ( double  u,
double  v,
VxdID  aVxdID,
double  uError = 0.1,
double  vError = 0.1 
)

returns a pxdCluster with given sensorID and local coordinates

Definition at line 69 of file observers.cc.

70 {
71 return PXDCluster(aVxdID, u, v, uError, vError, 0, 0, 1, 1, 1, 1, 1, 1);
72 }
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30

◆ provideSensorInfo()

VXD::SensorInfoBase provideSensorInfo ( VxdID  aVxdID,
double  globalX = 0.,
double  globalY = 0.,
double  globalZ = -0. 
)

this is a small helper function to create a sensorInfo to be used

Definition at line 49 of file observers.cc.

50 {
51 // (SensorType type, VxdID id, double width, double length, double thickness, int uCells, int vCells, double width2=-1, double splitLength=-1, int vCells2=0)
52 VXD::SensorInfoBase sensorInfoBase(VXD::SensorInfoBase::PXD, aVxdID, 2.3, 4.2, 0.3, 2, 4, -1);
53
54 TGeoRotation r1;
55 r1.SetAngles(45, 20, 30); // rotation defined by Euler angles
56 TGeoTranslation t1(globalX, globalY, globalZ);
57 TGeoCombiTrans c1(t1, r1);
58 TGeoHMatrix transform = c1;
59 sensorInfoBase.setTransformation(transform);
60 // also need the reco transform
61 sensorInfoBase.setTransformation(transform, true);
62
63 return sensorInfoBase;
64 }
Base class to provide Sensor Information for PXD and SVD.

◆ provideSpacePointDummy()

SpacePoint provideSpacePointDummy ( unsigned short  i,
double  X,
double  Y,
double  Z 
)

when given index number for vxdID and global coordinates, a SpacePoint lying there will be returned

Definition at line 83 of file observers.cc.

84 {
85 VxdID aVxdID = VxdID(i, i, i);
86 VXD::SensorInfoBase sensorInfoBase = provideSensorInfo(aVxdID, X, Y, Z);
87
88 PXDCluster aCluster = PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
89
90 return SpacePoint(&aCluster, &sensorInfoBase);
91 }
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
VXD::SensorInfoBase provideSensorInfo(VxdID aVxdID, double globalX=0., double globalY=0., double globalZ=-0.)
this is a small helper function to create a sensorInfo to be used
Definition: observers.cc:49

◆ provideSVDCluster()

SVDCluster provideSVDCluster ( VxdID  aVxdID,
bool  isU,
double  position,
double  error = 0.1 
)

returns a svdCluster with given sensorID, uType and local position

Definition at line 76 of file observers.cc.

77 {
78 return SVDCluster(aVxdID, isU, position, error, 0.1, 0.1, 1, 1, 1, 1);
79 }
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29

◆ TEST_F() [1/4]

TEST_F ( ObserversTest  ,
ignoreMe   
)

ignore what is written in this test, is simply used as a temporary storage for currently not used code-snippets

a tiny CollectedObservers class for CollectedObservers stuff

Definition at line 956 of file observers.cc.

957 {
958 //garbage:
959 // VectorOfObservers<Distance3DSquared>::addObserver(CountUsedObserver::notify);
960 // auto storeFunc = std::bind((void(*)(const SpacePoint&, const SpacePoint&, const Belle2::Distance3DSquared&, float))&CountUsedObserver::notify, std::placeholders::_1, std::placeholders::_2, Distance3DSquared(), std::placeholders::_3);
961 // auto storeFunc1 = std::bind(void(*)(const typename Distance3DSquared::argumentType&, const typename Distance3DSquared::argumentType&, const Distance3DSquared&, typename Distance3DSquared::variableType) /*&CountUsedObserver::notify*/), std::placeholders::_1, std::placeholders::_2, Distance3DSquared(), std::placeholders::_3);
962
963// ObserverVector<Distance3DSquared>::sm_collectedObservers.push_back(storeFunc);
964 // ObserverVector<Distance3DSquared>::sm_collectedObservers.push_back(std::bind((void(*)(const SpacePoint&, const SpacePoint&, const Belle2::Distance3DSquared&, float))&CountUsedObserver::notify, std::placeholders::_1, std::placeholders::_2, Distance3DSquared(), std::placeholders::_3));
965 // std::vector< typename ObserverVector<FilterType>::observerFunction >();
966 // ObserverVector<VectorOfObservers>::sm_collectedObservers = std::vector< typename VectorOfObservers<Distance3DSquared>::observerFunction >();
967// ErrorObserver anErrorBla();
968 // WarningObserver aWarningBla();
969 // ObserverVector<Distance3DSquared>::addObserver(aWarningBla/*, filterBla*/);
970 // ObserverVector<Distance3DSquared>::addObserver(aBla/*, filterBla*/);
971 // // // // // // Distance3DSquared filterBla();
972
974// template<class FilterType> class CollectedObservers {
975// public:
976// typedef std::function< void (const typename FilterType::argumentType&, const typename FilterType::argumentType&, const FilterType&, typename FilterType::variableType)> observerFunction;
977//
978// /** collects observers to be executed during notify */
979// static std::vector< observerFunction > collectedObservers;
980// CollectedObservers() {};
981// ~CollectedObservers() {};
982// };
983
984// static void addObserver( CountUsedObserver& newObserver) {
985// // static void addObserver(observerFunction newObserver) {
986// ObserverVector<FilterType>::sm_collectedObservers.push_back(std::bind(&newObserver::notify, std::placeholders::_1, std::placeholders::_2, FilterType(), std::placeholders::_3));
987// }
988 }

◆ TEST_F() [2/4]

TEST_F ( ObserversTest  ,
TestMCDataAccess   
)

tests possibility of accessing MCData

TODO further tests!

Definition at line 811 of file observers.cc.

812 {
814 3.5));
816 unobservedFilter);
817 auto mcCounter = counterMC< Distance3DSquared<SpacePoint> >();
818
819 for (int i = 1 ; i < spacePointData.getEntries(); i++) {
820 SpacePoint& spA = *spacePointData[i];
821 SpacePoint& spB = *spacePointData[i - 1];
822 B2DEBUG(10, "spData-Sps got arraIndices: " << spacePointData[i]->getArrayIndex() << "/" << spacePointData[i - 1]->getArrayIndex() <<
823 " and VxdIDs " << spacePointData[i]->getVxdID() << "/" << spacePointData[i - 1]->getVxdID());
824 observedFilter.accept(spA, spB);
825 }
826
827 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.size());
828 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.size());
829
830 mcCounter.pdGacceptedRejected.PrintResults("pdgCode");
831
833 // the filter was too loose, everything is accepted
834 EXPECT_EQ(1, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{11}).accept);
835 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{11, 13}).accept);
836 EXPECT_EQ(1, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{13}).accept);
837 // and nothing was rejected...
838 EXPECT_EQ(0, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{11}).reject);
839 EXPECT_EQ(0, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{11, 13}).reject);
840 EXPECT_EQ(0, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{13}).reject);
841
842
843 mcCounter.mcIDacceptedRejected.PrintResults("pID");
844
845 EXPECT_EQ(1, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{1}).accept);
846 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{1, 2}).accept);
847 EXPECT_EQ(1, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{2}).accept);
848
849 EXPECT_EQ(0, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{1}).reject);
850 EXPECT_EQ(0, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{1, 2}).reject);
851 EXPECT_EQ(0, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{2}).reject);
852
853
854 // now we set the filter using values which are too strict
856 (3.1, 3.5));
857 Filter< Distance3DSquared<SpacePoint>, Range<double, double>, CountAcceptedRejectedMCParticleObserver >
858 observedFilterStrict(
859 unobservedFilterStrict);
860
861 for (int i = 1 ; i < spacePointData.getEntries(); i++) {
862 SpacePoint& spA = *spacePointData[i];
863 SpacePoint& spB = *spacePointData[i - 1];
864 observedFilterStrict.accept(spA, spB);
865 }
866
867 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.size());
868 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.size());
869
870 // first filter does write into the same container, therefore values didn't change for accepted
871 EXPECT_EQ(1, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{11}).accept);
872 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{11, 13}).accept);
873 EXPECT_EQ(1, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{13}).accept);
874
875 // second filter does reject everything:
876 EXPECT_EQ(1, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{11}).reject);
877 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{11, 13}).reject);
878 EXPECT_EQ(1, mcCounter.pdGacceptedRejected.ReturnResult(CountContainer::Particles{13}).reject);
879
880 EXPECT_EQ(1, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{1}).accept);
881 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{1, 2}).accept);
882 EXPECT_EQ(1, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{2}).accept);
883
884 EXPECT_EQ(1, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{1}).reject);
885 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{1, 2}).reject);
886 EXPECT_EQ(1, mcCounter.mcIDacceptedRejected.ReturnResult(CountContainer::Particles{2}).reject);
887
888 }
This class is used to select pairs, triplets... of objects.
Definition: Filter.h:34
Represents a range of arithmetic types.
Definition: Range.h:29
The most CPU efficient Observer for the VXDTF filter tools (even if useless).
Definition: VoidObserver.h:30
this observer identifies the McParticles responsible for creating underlying clusters for given space...
Definition: observers.cc:500
a tiny counter class for counting stuff retrieved from MC-bla
Definition: observers.cc:360

◆ TEST_F() [3/4]

TEST_F ( ObserversTest  ,
TestObserverFlexibility   
)

presents the functionality of the SpacePoint-creating function written above

variant A (doesn't work, because of static function(?)):

variant B:

doesn't work, different type, additionally static_cast doesn't work too (reinterpret_casat too dangerous, didn't try):

long-term goal, something comparable to this:

Definition at line 895 of file observers.cc.

896 {
897 // Very verbose declaration, see below for convenient shortcuts
899 1.));
900
901 // Filter< Distance3DSquared<SpacePoint>, Range<double, double>, VectorOfObservers<Distance3DSquared> > filter(unobservedFilter);
903 SpacePoint x1 = provideSpacePointDummy(1, 0.0f, 0.0f, 0.0f);
904 SpacePoint x2 = provideSpacePointDummy(1, 0.5f, 0.0f, 0.0f);
905 SpacePoint x3 = provideSpacePointDummy(1, 2.0f, 0.0f, 0.0f);
906 auto myCounter = counter<Distance3DSquared<SpacePoint>>();
907 myCounter.resetCounter();
908
910// auto storeFuncVariantA = std::bind( ((VectorOfObservers<Distance3DSquared>::observerFunction) &CountingObserver::notify), std::placeholders::_1, std::placeholders::_2, Distance3DSquared(), std::placeholders::_3);
911 // VectorOfObservers<Distance3DSquared>::sm_collectedObservers.push_back(storeFuncVariantA);
912
914 auto storeFuncVariantB = std::bind(((VectorOfObservers<Distance3DSquared<SpacePoint>>::CStyleFunctionPointer)
915 &CountUsedObserver::notify), std::placeholders::_1, std::placeholders::_2, Distance3DSquared<SpacePoint>(),
916 std::placeholders::_3);
917
918 char* realname(nullptr);
919 int status(0);
920 realname = abi::__cxa_demangle(typeid(storeFuncVariantB).name(), 0, 0, &status);
921 std::string name(realname);
922 free(realname);
923 B2INFO("storeFuncVariantB is of type: " << name);
924
925// VectorOfObservers<Distance3DSquared>::sm_collectedObserversTry2.push_back(storeFuncVariantB);
926
927
929// VectorOfObservers<Distance3DSquared>::sm_collectedObserversCSTYLE.push_back(storeFuncVariantB);
930
932 // VectorOfObservers<Distance3DSquared>::addObserver(CountUsedObserver);
933 // VectorOfObservers<Distance3DSquared>::addObserver(WarningObserver);
934
935 observedFilter.accept(x2, x1);
936 observedFilter.accept(x3, x1);
937 EXPECT_EQ(0, myCounter.used);
938
940 unobservedFilter);
941
942 anotherObservedFilter.accept(x2, x1);
943 anotherObservedFilter.accept(x3, x1);
944 EXPECT_EQ(2, myCounter.used);
945 EXPECT_EQ(1, myCounter.accepted);
946 EXPECT_EQ(1, myCounter.rejected);
947 EXPECT_EQ(0, myCounter.wasInf);
948 EXPECT_EQ(0, myCounter.wasNan);
949 }
this observer does simply print the name of the SelectionVariable and the result of its value-functio...
Definition: observers.cc:454
this observer combines all the easy-to-get info retrievable by observers and prints it to screen
Definition: observers.cc:656
a tiny counter class for counting stuff
Definition: observers.cc:182
static void resetCounter()
destructor.
Definition: observers.cc:191

◆ TEST_F() [4/4]

TEST_F ( ObserversTest  ,
TestRelationSetup   
)

initialize static member of variant Try2

tests whether the setup of relations is doing what it is supposed to do

Definition at line 761 of file observers.cc.

762 {
763 EXPECT_EQ(6, spacePointData.getEntries());
764
765 for (SpacePoint& aSP : spacePointData) {
766 unsigned nullptrTrap = 0;
767 RelationVector<PXDCluster> pxDClusters = aSP.getRelationsTo<PXDCluster>();
768 for (PXDCluster& aCluster : pxDClusters) {
769 MCParticle* aParticle = aCluster.getRelatedTo<MCParticle>();
770 if (aParticle == nullptr) { nullptrTrap = 1; }
771 EXPECT_EQ(0, nullptrTrap);
772
773 if (aParticle) {
774 EXPECT_EQ(aSP.getArrayIndex(), aCluster.getArrayIndex());
775 EXPECT_EQ(aSP.getArrayIndex(), aParticle->getArrayIndex());
776 EXPECT_EQ(int(aParticle->getMomentum().X()), aParticle->getArrayIndex() + 1);
777 EXPECT_EQ(int(aParticle->getMomentum().Y()), aParticle->getArrayIndex() + 1);
778 EXPECT_EQ(int(aParticle->getMomentum().Z()), aParticle->getArrayIndex() + 1);
779 }
780
781 nullptrTrap = 0;
782 }
783
784 RelationVector<SVDCluster> svDClusters = aSP.getRelationsTo<SVDCluster>();
785 for (SVDCluster& aCluster : svDClusters) {
786 MCParticle* aParticle = aCluster.getRelatedTo<MCParticle>();
787 if (aParticle == nullptr) { nullptrTrap = 2; }
788 EXPECT_EQ(0, nullptrTrap);
789
790 if (aParticle) {
791 EXPECT_EQ(aSP.getArrayIndex(), 2 + aCluster.getArrayIndex() / 2);
792 EXPECT_EQ(aSP.getArrayIndex() / 4, aParticle->getArrayIndex());
793 EXPECT_EQ(int(aParticle->getMomentum().X()), aParticle->getArrayIndex() + 1);
794 EXPECT_EQ(int(aParticle->getMomentum().Y()), aParticle->getArrayIndex() + 1);
795 EXPECT_EQ(int(aParticle->getMomentum().Z()), aParticle->getArrayIndex() + 1);
796 }
797
798 nullptrTrap = 0;
799 }
800
801 // at least one cluster type has to be connected to given spacePoint!
802 EXPECT_NE(0, pxDClusters.size() + svDClusters.size());
803 }
804 }
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:244
ROOT::Math::XYZVector getMomentum() const
Return momentum.
Definition: MCParticle.h:198
Class for type safe access to objects that are referred to in relations.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.