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