Belle II Software  release-05-02-19
PXDSpacePointCreatorModule.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 <pxd/modules/pxdSpacePointCreator/PXDSpacePointCreatorModule.h>
11 
12 #include <framework/logging/Logger.h>
13 
14 
15 
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 
21 REG_MODULE(PXDSpacePointCreator)
22 
24  Module()
25 {
26  InitializeCounters();
27 
28  setDescription("Imports Clusters of the PXD detector and converts them to spacePoints.");
29  setPropertyFlags(c_ParallelProcessingCertified);
30 
31  // 1. Collections.
32  addParam("PXDClusters", m_pxdClustersName,
33  "PXDCluster collection name", string(""));
34  addParam("SpacePoints", m_spacePointsName,
35  "SpacePoints collection name", string("PXDSpacePoints"));
36 
37  // 2.Modification parameters:
38  addParam("NameOfInstance", m_nameOfInstance,
39  "allows the user to set an identifier for this module. Usefull if one wants to use several instances of that module",
40  string("PXDSpacePoints"));
41 }
42 
43 
44 
45 void PXDSpacePointCreatorModule::initialize()
46 {
47  // prepare all store- and relationArrays:
48  m_spacePoints.registerInDataStore(m_spacePointsName, DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered);
49  m_pxdClusters.isRequired(m_pxdClustersName);
50 
51 
52  //Relations to cluster objects only if the ancestor relations exist:
53  m_spacePoints.registerRelationTo(m_pxdClusters, DataStore::c_Event, DataStore::c_DontWriteOut);
54 
55 
56  B2DEBUG(10, "SpacePointCreatorModule(" << m_nameOfInstance << ")::initialize: names set for containers:\n" <<
57  "pxdClusters: " << m_pxdClusters.getName() <<
58  "\nspacePoints: " << m_spacePoints.getName());
59 
60 
61  // set some counters for output:
62  InitializeCounters();
63 }
64 
65 
66 
67 void PXDSpacePointCreatorModule::event()
68 {
69 
70  for (unsigned int i = 0; i < uint(m_pxdClusters.getEntries()); ++i) {
71  const PXDCluster* currentCluster = m_pxdClusters[i];
72  SpacePoint* newSP = m_spacePoints.appendNew((currentCluster));
73  newSP->addRelationTo(currentCluster);
74  }
75 
76  B2DEBUG(1, "PXDSpacePointCreatorModule(" << m_nameOfInstance << ")::event: spacePoints created! Size of arrays:\n" <<
77  "pxdClusters: " << m_pxdClusters.getEntries() <<
78  ", spacePoints: " << m_spacePoints.getEntries());
79 
80 
81  if (LogSystem::Instance().isLevelEnabled(LogConfig::c_Debug, 10, PACKAGENAME()) == true) {
82  for (int index = 0; index < m_spacePoints.getEntries(); index++) {
83  const SpacePoint* sp = m_spacePoints[index];
84 
85  PXDCluster* relatedCluster = sp->getRelatedTo<PXDCluster>(m_pxdClusters.getName());
86 
87  B2DEBUG(10, "SpacePointCreatorModule(" << m_nameOfInstance << ")::event: spacePoint " << index <<
88  " with type " << sp->getType() <<
89  " and VxdID " << VxdID(sp->getVxdID()) <<
90  " is stored in Array: " << sp->getArrayName() <<
91  " and the related PXDCluster is in " << relatedCluster->getArrayName() <<
92  " with index " << relatedCluster->getArrayIndex());
93  }
94  }
95 
96  m_TESTERPXDClusterCtr += m_pxdClusters.getEntries();
97  m_TESTERSpacePointCtr += m_spacePoints.getEntries();
98 }
99 
100 
101 
102 void PXDSpacePointCreatorModule::terminate()
103 {
104  B2DEBUG(10, "PXDSpacePointCreatorModule(" << m_nameOfInstance << ")::terminate: total number of occured instances:\n" <<
105  "pxdClusters: " << m_TESTERPXDClusterCtr <<
106  ", spacePoints: " << m_TESTERSpacePointCtr);
107 }
108 
109 
110 void PXDSpacePointCreatorModule::InitializeCounters()
111 {
112  m_TESTERPXDClusterCtr = 0;
113  m_TESTERSpacePointCtr = 0;
114 }
115 
116 
117 
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
Belle2::PXDSpacePointCreatorModule
Imports Clusters of the pxd detector and converts them to spacePoints.
Definition: PXDSpacePointCreatorModule.h:40
Belle2::RelationsInterface::getArrayName
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
Definition: RelationsObject.h:379
Belle2::RelationsInterface::addRelationTo
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).
Definition: RelationsObject.h:144
Belle2::RelationsInterface::getRelatedTo
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
Definition: RelationsObject.h:250
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PXDCluster
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:41
Belle2::RelationsInterface::getArrayIndex
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Definition: RelationsObject.h:387
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