Belle II Software  release-08-01-10
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 using namespace Belle2;
20 
21 
22 REG_MODULE(SpacePointCreatorTest);
23 
25  Module()
26 {
27  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!");
28 
29  std::vector<std::string> containerSpacePointsName = { "SVDSpacePoints", "PXDSpacePoints" };
30 
31  // 1. Collections.
32  addParam("PXDClusters", m_pxdClustersName,
33  "PXDCluster collection name", std::string(""));
34  addParam("SVDClusters", m_svdClustersName,
35  "SVDCluster collection name", std::string(""));
36  addParam("AllSpacePointContainers", m_containerSpacePointsName,
37  "SpacePoints collection name", containerSpacePointsName);
38 
39  // 2.Modification parameters:
40  addParam("NameOfInstance", m_nameOfInstance,
41  "allows the user to set an identifier for this module. Usefull if one wants to use several instances of that module",
42  std::string(""));
43 }
44 
45 
46 
48 {
49  // prepare all store- and relationArrays:
52 
53 
54  for (auto aName : m_containerSpacePointsName) {
55  m_allSpacePointStoreArrays.push_back({/* aName,*/ StoreArray<SpacePoint>(aName) });
56  }
57 
58 
59  if (m_pxdClusters.isOptional() == true) {
60  // retrieve name again (faster than doing everything in the event):
62  }
63 
64 
65  if (m_svdClusters.isOptional() == true) {
66  // retrieve name again (faster than doing everything in the event):
68  }
69 
70 
71  B2INFO("SpacePointCreatorTestModule(" << m_nameOfInstance << ")::initialize: names found for containers:\n" <<
72  "pxdClusters: " << m_pxdClustersName <<
73  "\nsvdClusters: " << m_svdClustersName);
74 
75  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!");
76 }
77 
78 
79 
81 {
82  B2DEBUG(20, "SpacePointCreatorTestModule(" << m_nameOfInstance << " event " << StoreObjPtr<EventMetaData>("EventMetaData",
83  DataStore::c_Event)->getEvent() << ")): got " << m_pxdClusters.getEntries() << "/" << m_svdClusters.getEntries() <<
84  " pxd/SVDClusters in this event");
85 
86 
87  for (StoreArray<SpacePoint>& aStoreArrayInterface : m_allSpacePointStoreArrays) {
88  B2DEBUG(20, " Entering storeArray<SpacePoint> " << aStoreArrayInterface.getName() << " with " << aStoreArrayInterface.getEntries()
89  <<
90  " spacePoints");
91 
92  for (unsigned int i = 0; i < uint(aStoreArrayInterface.getEntries()); ++i) {
93  B2DEBUG(20, " Executing SpacePoint " << i);
94  const SpacePoint* sp = aStoreArrayInterface[i];
95 
96  std::vector<int> indices; // WARNING: nothing is happening with them yet -> write some sort of test!
97  std::string clusterContainer = "";
98 
99  if (sp->getType() == VXD::SensorInfoBase::SensorType::SVD) {
100  B2DEBUG(20, " 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(20, " 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(20, " 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(20, " 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(20, "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(20, "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(20, " executing AbsMeasurement " << i << " with detectorID(PXD = 0,SVD=1,TEL=2,VXD=-1) : " << hitOutput[i].first << ":\n");
155  point->Print();
156  B2DEBUG(20, " converted absMeasurement is of detID: " << rawPoint->getDetId() << ", hitID: " << rawPoint->getHitId());
157  }
158  }
159 
160 }
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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:29
std::string m_svdClustersName
SVDCluster collection name.
std::string m_nameOfInstance
allows the user to set an identifier for this module.
void initialize() override
Init the module.
std::vector< StoreArray< SpacePoint > > m_allSpacePointStoreArrays
a vector full of StoreArray carrying spacePoints.
StoreArray< SVDCluster > m_svdClusters
the storeArray for svdClusters as member, is faster than recreating link for each event
void event() override
eventWise jobs (e.g.
std::string m_pxdClustersName
PXDCluster collection name.
std::vector< std::string > m_containerSpacePointsName
intermediate storage for the names of the loaded storeArrays.
StoreArray< PXDCluster > m_pxdClusters
the storeArray for pxdClusters as member, is faster than recreating link for each event
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
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
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
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
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.