9#include <gtest/gtest.h>
11#include <tracking/spacePointCreation/SpacePoint.h>
12#include <vxd/geometry/SensorInfoBase.h>
13#include <tracking/trackFindingVXD/filterMap/twoHitVariables/Distance3DSquared.h>
15#include <tracking/trackFindingVXD/filterMap/filterFramework/Shortcuts.h>
17#include <svd/dataobjects/SVDCluster.h>
18#include <pxd/dataobjects/PXDCluster.h>
19#include <mdst/dataobjects/MCParticle.h>
21#include <framework/datastore/StoreArray.h>
22#include <framework/gearbox/Const.h>
55 r1.SetAngles(45, 20, 30);
56 TGeoTranslation t1(globalX, globalY, globalZ);
57 TGeoCombiTrans c1(t1, r1);
58 TGeoHMatrix transform = c1;
63 return sensorInfoBase;
71 return PXDCluster(aVxdID, u, v, uError, vError, 0, 0, 1, 1, 1, 1, 1, 1);
78 return SVDCluster(aVxdID, isU, position, error, 0.1, 0.1, 1, 1, 1, 1);
88 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
116 for (
unsigned int i = 1; i < 3; ++i) {
119 aParticle->
setMomentum(
float(i),
float(i),
float(i));
129 B2DEBUG(10,
" setup: new spacePoint got arrayIndex: " << newSP->
getArrayIndex() <<
" and VxdID " << newSP->
getVxdID());
138 for (
unsigned int i = 3; i < 7; ++i) {
144 unsigned int pID = (i - 3) / 2;
151 std::vector<const SVDCluster*> clusterVector = {clusterU, clusterV};
217 typedef std::pair< bool, Particles >
Key;
252 std::sort(particles.begin(), particles.end());
253 auto newEndIterator = std::unique(particles.begin(), particles.end());
254 particles.resize(std::distance(particles.begin(), newEndIterator));
261 bool keyAlreadyExisted =
true;
264 B2DEBUG(100,
" the IDs " <<
key2str(aKey) <<
" collected haven't been found yet");
266 keyAlreadyExisted =
false;
267 }
else { B2DEBUG(100,
" the IDs " <<
key2str(aKey) <<
" collected were already there"); }
269 foundPos->second.Increase(accepted);
271 return keyAlreadyExisted;
286 return foundPos->second;
295 B2DEBUG(100,
"comparing given particles: " <<
vec2str(givenKey) <<
" with entry: " <<
vec2str(
296 aKey.first.second) <<
" with result " << (aKey.first.second == givenKey));
297 if (aKey.first.second == givenKey) {
return aKey.second; }
309 B2WARNING(
" for " << identifier <<
"-combination: " <<
311 ", combi was accepted/rejected: " <<
312 entry.second.accept <<
314 entry.second.reject);
332 if (aKey->first ==
true) { output +=
"GoodCombi: "; }
333 else { output +=
"BadCombi: "; }
335 output +=
vec2str(aKey->second);
342 template<
class Type>
static std::string
vec2str(
const vector<Type>& vec)
346 for (
const auto& entry : vec) {
347 output +=
" " + std::to_string(entry);
397 template<
class Var,
typename ... otherTypes>
413 template<
class Var,
class RangeType>
415 typename Var::variableType fResult,
416 const RangeType& range,
417 const typename Var::argumentType&,
418 const typename Var::argumentType&)
420 if (range.contains(fResult)) {
436 template<
class Var,
typename ... otherTypes>
438 typename Var::variableType fResult,
441 if (std::isinf(fResult)) {
443 }
else if (std::isnan(fResult)) {
457 template<
class Var,
class RangeType>
458 static void notify(
const Var& filterType,
459 typename Var::variableType fResult,
460 const RangeType& range,
461 const typename Var::argumentType&
outerHit,
462 const typename Var::argumentType& innerHit)
465 stringstream outputStream;
466 outputStream << filterType.name()
467 <<
" with outer-/innerhit: "
470 << innerHit.getPosition().PrintStringXYZ()
471 <<
" having indices "
474 << innerHit.getArrayIndex()
478 << innerHit.getVxdID()
482 << (range.contains(fResult) ? string(
"true") : string(
"false"))
488 if (range.contains(fResult)) {
489 B2INFO(outputStream.str());
491 B2WARNING(outputStream.str());
504 template<
class Var,
class RangeType>
506 typename Var::variableType fResult,
507 const RangeType& range,
508 const typename Var::argumentType&
outerHit,
509 const typename Var::argumentType& innerHit)
511 B2INFO(
"CountAcceptedRejectedMCParticleObserver called" << endl
512 <<
"range: ( " << range.getInf() <<
" , " << range.getSup() <<
" )" << endl
513 <<
"var = " << fResult << endl
514 <<
"outerHit: (" <<
outerHit.
X() <<
" , "
517 <<
"innerHit: (" << innerHit.X() <<
" , "
518 << innerHit.Y() <<
" , "
519 << innerHit.Z() <<
" ) (x,y,z) " << endl
544 template <
class hitType>
545 static void collectPDGs(
const hitType& aHit, vector< pair< bool, int> >& collectedPDGs)
548 std::vector<const MCParticle*> collectedParticles;
552 for (
const MCParticle* aParticle : collectedParticles) {
566 template <
class hitType>
570 std::vector<const MCParticle*> collectedParticles;
574 for (
const MCParticle* aParticle : collectedParticles) {
580 template <
class hitType>
585 vector< pair< bool, int> > collectedIDS;
597 if (collectedIDS.size() == 1) {
598 newKey.first = collectedIDS[0].first;
599 newKey.second = { collectedIDS[0].second };
603 newKey.first =
false;
605 for (
auto& entry : collectedIDS) {
606 newKey.second.push_back(entry.second);
620 template <
class hitType>
621 static void collectMCParticles(
const hitType& aHit, std::vector<const MCParticle*>& collectedParticles)
626 for (
const PXDCluster& aCluster : relatedToPXDClusters) {
628 collectedParticles.push_back(&aParticle);
632 for (
const SVDCluster& aCluster : relatedToSVDClusters) {
634 collectedParticles.push_back(&aParticle);
642 template<
class Type>
static std::string
vec2str(
const vector<Type>& vec)
646 for (
const auto& entry : vec) {
647 output +=
" " + std::to_string(entry);
659 template<
class Var,
class RangeType>
660 static void notify(
const Var& filterType,
661 typename Var::variableType fResult,
662 const RangeType& range,
663 const typename Var::argumentType&
outerHit,
664 const typename Var::argumentType& innerHit)
695 typedef std::function< void (
const FilterType&,
typename FilterType::variableType,
const typename FilterType::argumentType&,
const typename FilterType::argumentType&)>
699 using CStyleFunctionPointer = void(*)(
const typename FilterType::argumentType&,
const typename FilterType::argumentType&,
700 const FilterType&,
typename FilterType::variableType) ;
703 template<
typename range,
typename ... otherTypes>
704 static void notify(
const FilterType& filterType,
705 typename FilterType::variableType filterResult,
707 const typename FilterType::argumentType&
outerHit,
708 const typename FilterType::argumentType& innerHit,
711 B2INFO(
" Filter " << filterType.name() <<
" with Mag of outer-/innerHit " <<
outerHit.getPosition().
Mag() <<
"/" <<
712 innerHit.getPosition().Mag() <<
" got result of " << filterResult <<
" and Observer-Vector sm_collectedObservers got " <<
714 B2INFO(
" Filter " << filterType.name() <<
" with Mag of outer-/innerHit " <<
outerHit.getPosition().
Mag() <<
"/" <<
715 innerHit.getPosition().Mag() <<
" got result of " << filterResult <<
" and Observer-Vector sm_collectedObserversCSTYLE got " <<
728 template <
typename ObserverType>
732 FilterType(), std::placeholders::_3));
748 template<
typename FilterType> std::vector< typename VectorOfObservers<FilterType>::observerFunction >
751 template<
typename FilterType> std::vector< typename VectorOfObservers<FilterType>::CStyleFunctionPointer >
763 EXPECT_EQ(6, spacePointData.getEntries());
766 unsigned nullptrTrap = 0;
770 if (aParticle ==
nullptr) { nullptrTrap = 1; }
771 EXPECT_EQ(0, nullptrTrap);
774 EXPECT_EQ(aSP.getArrayIndex(), aCluster.getArrayIndex());
787 if (aParticle ==
nullptr) { nullptrTrap = 2; }
788 EXPECT_EQ(0, nullptrTrap);
791 EXPECT_EQ(aSP.getArrayIndex(), 2 + aCluster.getArrayIndex() / 2);
792 EXPECT_EQ(aSP.getArrayIndex() / 4, aParticle->
getArrayIndex());
802 EXPECT_NE(0, pxDClusters.
size() + svDClusters.
size());
819 for (
int i = 1 ; i < spacePointData.getEntries(); i++) {
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);
827 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.size());
828 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.size());
830 mcCounter.pdGacceptedRejected.PrintResults(
"pdgCode");
843 mcCounter.mcIDacceptedRejected.PrintResults(
"pID");
858 observedFilterStrict(
859 unobservedFilterStrict);
861 for (
int i = 1 ; i < spacePointData.getEntries(); i++) {
864 observedFilterStrict.accept(spA, spB);
867 EXPECT_EQ(3, mcCounter.pdGacceptedRejected.size());
868 EXPECT_EQ(3, mcCounter.mcIDacceptedRejected.size());
914 auto storeFuncVariantB = std::bind(((
VectorOfObservers<Distance3DSquared<SpacePoint>>::CStyleFunctionPointer)
916 std::placeholders::_3);
918 char* realname(
nullptr);
920 realname = abi::__cxa_demangle(
typeid(storeFuncVariantB).name(), 0, 0, &status);
921 std::string name(realname);
923 B2INFO(
"storeFuncVariantB is of type: " << name);
935 observedFilter.accept(x2, x1);
936 observedFilter.accept(x3, x1);
937 EXPECT_EQ(0, myCounter.used);
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);
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
std::string PrintStringXYZ(unsigned precision=4) const
create a string containing vector in cartesian coordinates
DataType Y() const
access variable Y (= .at(1) without boundary check)
DataType Mag() const
The magnitude (rho in spherical coordinate system).
static const ChargedStable muon
muon particle
static const ChargedStable electron
electron particle
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.
This class is used to select pairs, triplets... of objects.
A Class to store the Monte Carlo particle information.
@ c_PrimaryParticle
bit 0: Particle is primary particle.
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
ROOT::Math::XYZVector getMomentum() const
Return momentum.
void setMomentum(const ROOT::Math::XYZVector &momentum)
Set particle momentum.
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Represents a range of arithmetic types.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
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.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
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.
The most CPU efficient Observer for the VXDTF filter tools (even if useless).
Class to uniquely identify a any structure of the PXD and SVD.
this observer does simply count the number of times, the attached SelectionVariable was accepted or r...
static void notify(const Var &, typename Var::variableType fResult, const RangeType &range, const typename Var::argumentType &, const typename Var::argumentType &)
notifier counting how often a SelectionVariable was accepted/rejected
this observer identifies the McParticles responsible for creating underlying clusters for given space...
static std::string vec2str(const vector< Type > &vec)
small helper for easily printing vectors
static void collectMCParticles(const hitType &aHit, std::vector< const MCParticle * > &collectedParticles)
collects all mcParticles connected to given hit.
static void collectPDGs(const hitType &aHit, vector< pair< bool, int > > &collectedPDGs)
collects all PDGs connected to given hit.
static CountContainer::Key createKey(const hitType &hitA, const hitType &hitB, bool usePDG)
for two hits given, a key for the CountContainer is returned.
static void collectParticleIDs(const hitType &aHit, vector< pair< bool, int > > &collectedIDS)
collects all particleIDs connected to given hit.
static void notify(const Var &, typename Var::variableType fResult, const RangeType &range, const typename Var::argumentType &outerHit, const typename Var::argumentType &innerHit)
notifier producing a info message if SelectionVariable was accepted and a Warning if otherwise
this observer does simply count the number of times, the attached Filter resulted in isinf or isnan
static void notify(const Var &, typename Var::variableType fResult, otherTypes ...)
notifier counting how often a SelectionVariable was resulting in nan or inf
a container for counting accepted and rejected stuff, just delivers some interfaces to make the code ...
std::pair< bool, Particles > Key
key for the internal container of this map
std::vector< int > Particles
a vector containing IDs
static void uniqueIdentifier(ContainerType &particles)
cleans a container of double entries
static std::string vec2str(const vector< Type > &vec)
small helper for easily printing vectors
bool IncreaseCounter(Key &aKey, bool accepted)
accepts a key (first parameter) and if given key was accepted by the filter (second parameter)
unsigned int size()
size of container
static std::string key2str(const Key &aKey)
small helper for easily printing vectors
void clear()
clear container
std::map< Key, AcceptRejectPair > m_container
collects the data
AcceptRejectPair ReturnResult(const Key &givenKey)
for given key, the function returns the result found.
AcceptRejectPair ReturnResult(const Particles &givenKey)
for given key, the function returns the result found.
CountContainer()
constructor.
static std::string key2str(const Key *aKey)
small helper for easily printing vectors
void PrintResults(const string &identifier="unknown")
for easy printing of results collected so far
this observer does simply count the number of times, the attached SelectionVariable was used
static void notify(const Var &, otherTypes ...)
notifier counting how often a SelectionVariable was used
this observer does simply print the name of the SelectionVariable and the result of its value-functio...
static void notify(const Var &filterType, typename Var::variableType fResult, const RangeType &range, const typename Var::argumentType &outerHit, const typename Var::argumentType &innerHit)
notifier producing a info message if SelectionVariable was accepted and a Warning if otherwise
Test class for testing and developing new Observers.
StoreArray< PXDCluster > pxdClusterData
some pxd clusters to test RelationsInterface for observers.
virtual void TearDown()
clear datastore
StoreArray< SpacePoint > spacePointData
some spacePoints to test RelationsInterface for observers.
StoreArray< MCParticle > mcParticleData
some mcParticles to test RelationsInterface for observers.
virtual void SetUp()
prepare related storearrays of SpacePoints, SVD- and PXDClusters and MCParticles
StoreArray< SVDCluster > svdClusterData
some svd clusters to test RelationsInterface for observers.
this observer combines all the easy-to-get info retrievable by observers and prints it to screen
static void notify(const Var &filterType, typename Var::variableType fResult, const RangeType &range, const typename Var::argumentType &outerHit, const typename Var::argumentType &innerHit)
notify function is called by the filter, this one combines all the easy-to-get info retrievable by ob...
static std::vector< observerFunction > sm_collectedObservers
collects observers with std::function to be executed during notify (variant A)
static std::vector< CStyleFunctionPointer > sm_collectedObserversCSTYLE
collects observers with c-style function pointers to be executed during notify (variant B)
static void addObserver(observerFunction newObserver)
collects observers to be executed during notify (can not be used so far, but is long-term goal)
std::function< void(const FilterType &, typename FilterType::variableType, const typename FilterType::argumentType &, const typename FilterType::argumentType &)> observerFunction
a typedef to make the stuff more readable
static void notify(const FilterType &filterType, typename FilterType::variableType filterResult, const range &, const typename FilterType::argumentType &outerHit, const typename FilterType::argumentType &innerHit, otherTypes ...)
iterate over all stored Observers and execute their notify-function
void(*)(const typename FilterType::argumentType &, const typename FilterType::argumentType &, const FilterType &, typename FilterType::variableType) CStyleFunctionPointer
a typedef to make the c-style pointer more readable (can not be done with classic typedef)
a tiny counter class for counting stuff retrieved from MC-bla
static CountContainer mcIDacceptedRejected
map for pdgCodes (key: vector of pdgCodes found for given hits, sorted) storing how often it was acce...
static void resetCounter()
destructor.
counterMC()
map for mcParticleIDs (key, vector of mcParticleIDs (pair: first: true, if combination was from the s...
static CountContainer pdGacceptedRejected
counts nCases accepted/rejected for each pdgCode-combination occurred
a tiny counter class for counting stuff
static unsigned int accepted
count number of times result was accepted
static void resetCounter()
destructor.
static unsigned int wasInf
count number of times result was inf
static unsigned int used
count number of times used
static unsigned int rejected
count number of times result was rejected
static unsigned int wasNan
count number of times result was nan
B2Vector3D outerHit(0, 0, 0)
testing out of range behavior
Abstract base class for different kinds of events.
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
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
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
simple struct for counting accepted and rejected cases.
unsigned reject
counts nTimes when it was rejected
void Increase(bool accepted)
Increase respective counter if accepted or not.
unsigned accept
counts nTimes when it was accepted