Belle II Software  release-05-02-19
SpacePointCreatorTestModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler *
7  * *
8  **************************************************************************/
9 
10 #include <tracking/modules/spacePointCreator/SpacePointCreatorTestModule.h>
11 
12 #include <framework/dataobjects/EventMetaData.h>
13 
14 #include <framework/logging/Logger.h>
15 
16 #include <genfit/Track.h>
17 #include <genfit/AbsTrackRep.h>
18 #include <genfit/RKTrackRep.h>
19 
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 
25 REG_MODULE(SpacePointCreatorTest)
26 
28  Module()
29 {
30  setDescription("Tester module for the validity of the SpacePointCreatorModule. TODO: at the moment, the genfit-output can only verified visually (by checking, whether the detector types match the number of dimensions stored in the trackPoint)! when full reco chain is working, this testerModule should be extended! -> verification that input cluster(s) is/are converted to genfit-stuff shall be resilient!");
31 
32  vector<string> containerSpacePointsName = { "SVDSpacePoints", "PXDSpacePoints" };
33 
34  // 1. Collections.
35  addParam("PXDClusters", m_pxdClustersName,
36  "PXDCluster collection name", string(""));
37  addParam("SVDClusters", m_svdClustersName,
38  "SVDCluster collection name", string(""));
39  addParam("AllSpacePointContainers", m_containerSpacePointsName,
40  "SpacePoints collection name", containerSpacePointsName);
41 
42  // 2.Modification parameters:
43  addParam("NameOfInstance", m_nameOfInstance,
44  "allows the user to set an identifier for this module. Usefull if one wants to use several instances of that module", string(""));
45 }
46 
47 
48 
49 void SpacePointCreatorTestModule::initialize()
50 {
51  // prepare all store- and relationArrays:
52  m_pxdClusters.isOptional(m_pxdClustersName);
53  m_svdClusters.isOptional(m_svdClustersName);
54 
55 
56  for (auto aName : m_containerSpacePointsName) {
57  // cppcheck-suppress useStlAlgorithm
58  m_allSpacePointStoreArrays.push_back({/* aName,*/ StoreArray<SpacePoint>(aName) });
59  }
60 
61 
62  if (m_pxdClusters.isOptional() == true) {
63  // retrieve name again (faster than doing everything in the event):
64  m_pxdClustersName = m_pxdClusters.getName();
65  }
66 
67 
68  if (m_svdClusters.isOptional() == true) {
69  // retrieve name again (faster than doing everything in the event):
70  m_svdClustersName = m_svdClusters.getName();
71  }
72 
73 
74  B2INFO("SpacePointCreatorTestModule(" << m_nameOfInstance << ")::initialize: names found for containers:\n" <<
75  "pxdClusters: " << m_pxdClustersName <<
76  "\nsvdClusters: " << m_svdClustersName);
77 
78  B2WARNING("TODO: at the moment, the genfit-output can only verified visually (by checking, whether the detector types match the number of dimensions stored in the trackPoint)! when full reco chain is working, this testerModule should be extended! -> verification that input cluster(s) is/are converted to genfit-stuff shall be resilient!");
79 }
80 
81 
82 
83 void SpacePointCreatorTestModule::event()
84 {
85  B2DEBUG(1, "SpacePointCreatorTestModule(" << m_nameOfInstance << " event " << StoreObjPtr<EventMetaData>("EventMetaData",
86  DataStore::c_Event)->getEvent() << ")): got " << m_pxdClusters.getEntries() << "/" << m_svdClusters.getEntries() <<
87  " pxd/SVDClusters in this event");
88 
89 
90  for (StoreArray<SpacePoint>& aStoreArrayInterface : m_allSpacePointStoreArrays) {
91  B2DEBUG(1, " Entering storeArray<SpacePoint> " << aStoreArrayInterface.getName() << " with " << aStoreArrayInterface.getEntries() <<
92  " spacePoints");
93 
94  for (unsigned int i = 0; i < uint(aStoreArrayInterface.getEntries()); ++i) {
95  B2DEBUG(2, " Executing SpacePoint " << i);
96  const SpacePoint* sp = aStoreArrayInterface[i];
97 
98  vector<int> indices; // WARNING: nothing is happening with them yet -> write some sort of test!
99  string clusterContainer = "";
100 
101  if (sp->getType() == VXD::SensorInfoBase::SensorType::SVD) {
102  B2DEBUG(2, " SpacePoint " << i << " is attached to SVDCluster(s) of StoreArray " << sp->getArrayName());
103 
104  for (const SVDCluster& aCluster : sp->getRelationsTo<SVDCluster>()) {
105  indices.push_back(aCluster.getArrayIndex());
106  clusterContainer = aCluster.getArrayName();
107 
108  B2DEBUG(2, " SpacePoint " << i <<
109  " got pointer to SVDCluster with index " << aCluster.getArrayIndex() <<
110  " stored in Array " << aCluster.getArrayName());
111  }
112  } else if (sp->getType() == VXD::SensorInfoBase::SensorType::PXD) {
113  B2DEBUG(2, " SpacePoint " << i << " is attached to PXDCluster of StoreArray " << sp->getArrayName());
114 
115  for (const PXDCluster& aCluster : sp->getRelationsTo<PXDCluster>()) {
116 
117  indices.push_back(aCluster.getArrayIndex());
118 
119  clusterContainer = aCluster.getArrayName();
120 
121  B2DEBUG(2, " SpacePoint " << i <<
122  " got pointer to PXDCluster with index " << aCluster.getArrayIndex() <<
123  " stored in Array " << aCluster.getArrayName());
124 
125  }
126  } else { B2ERROR(" SpacePoint is of unknown type " << sp->getType()); }
127 
128 
129  B2DEBUG(1, "SpacePoint " << i <<
130  " got sensorType: " << sp->getType() <<
131  ", VxdID: " << VxdID(sp->getVxdID()) <<
132  ", storeName for Cluster(says SpacePoint): " << sp->getArrayName() <<
133  ", storeName for Cluster(says Cluster): " << clusterContainer);
134  }
135 
136  B2DEBUG(1, "testGenfitCompatibility: feed the track with spacePoints ported to genfit compatible stuff");
137  genfit::AbsTrackRep* trackRep = new genfit::RKTrackRep(211);
138  genfit::Track track(trackRep, aStoreArrayInterface[0]->getPosition(), TVector3(23., 42., 5.));
139 
140  // feed the track with spacePoints ported to genfit compatible stuff:
141  // is rather complicated since the assignment operator is protected:
142  std::vector< std::pair<VXD::SensorInfoBase::SensorType, genfit::AbsMeasurement*> > hitOutput;
143 
144  for (auto& aSP : aStoreArrayInterface) {
145  std::vector<genfit::PlanarMeasurement> tempMeasurements = aSP.getGenfitCompatible();
146 
147  for (genfit::PlanarMeasurement& measurement : tempMeasurements) {
148  // cppcheck-suppress useStlAlgorithm
149  hitOutput.push_back({aSP.getType(), measurement.clone()});
150  }
151  }
152 
153  for (unsigned i = 0; i < hitOutput.size(); i++) {
154  track.insertMeasurement(hitOutput[i].second);
155  genfit::TrackPoint* point = track.getPointWithMeasurement(i);
156  genfit::AbsMeasurement* rawPoint = point->getRawMeasurement();
157  B2DEBUG(2, " executing AbsMeasurement " << i << " with detectorID(PXD = 0,SVD=1,TEL=2,VXD=-1) : " << hitOutput[i].first << ":\n");
158  point->Print();
159  B2DEBUG(2, " converted absMeasurement is of detID: " << rawPoint->getDetId() << ", hitID: " << rawPoint->getHitId());
160  }
161  }
162 
163 }
genfit::TrackPoint
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
genfit::Track
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
Definition: Track.h:71
Belle2::RelationsInterface::getArrayName
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
Definition: RelationsObject.h:379
genfit::AbsTrackRep
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
Belle2::RelationsInterface::getRelationsTo
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Definition: RelationsObject.h:199
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
genfit::PlanarMeasurement
Measurement class implementing a planar hit geometry (1 or 2D).
Definition: PlanarMeasurement.h:44
Belle2::Module
Base class for Modules.
Definition: Module.h:74
genfit::RKTrackRep
AbsTrackRep with 5D track parameterization in plane coordinates: (q/p, u', v', u, v)
Definition: RKTrackRep.h:72
genfit::AbsMeasurement
Contains the measurement and covariance in raw detector coordinates.
Definition: AbsMeasurement.h:42
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::PXDCluster
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:41
Belle2::SpacePointCreatorTestModule
Tester module for the validity of the SpacePointCreatorModule.
Definition: SpacePointCreatorTestModule.h:43
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::StoreArray< SpacePoint >
Belle2::getPosition
ExpRunEvt getPosition(const std::vector< Evt > &events, double tEdge)
Get the exp-run-evt number from the event time [hours].
Definition: Splitter.h:344
Belle2::SpacePoint::getType
Belle2::VXD::SensorInfoBase::SensorType getType() const
Return SensorType (PXD, SVD, ...) on which the SpacePoint lives.
Definition: SpacePoint.h:155
Belle2::SpacePoint::getVxdID
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
Definition: SpacePoint.h:158