Belle II Software  release-06-02-00
SVDSpacePointCreatorModule.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 <svd/modules/svdSpacePointCreator/SVDSpacePointCreatorModule.h>
10 #include <svd/modules/svdSpacePointCreator/SpacePointHelperFunctions.h>
11 
12 #include <framework/logging/Logger.h>
13 #include <framework/utilities/FileSystem.h>
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 
19 REG_MODULE(SVDSpacePointCreator)
20 
22  Module()
23 {
24  InitializeCounters();
25 
26  setDescription("Imports Clusters of the SVD detector and converts them to spacePoints.");
27  setPropertyFlags(c_ParallelProcessingCertified);
28 
29  // 1. Collections.
30  addParam("SVDClusters", m_svdClustersName,
31  "SVDCluster collection name", string(""));
32  addParam("SpacePoints", m_spacePointsName,
33  "SpacePoints collection name", string("SVDSpacePoints"));
34  addParam("EventLevelTrackingInfoName", m_eventLevelTrackingInfoName,
35  "EventLevelTrackingInfo collection name", string(""));
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", string(""));
40  addParam("OnlySingleClusterSpacePoints", m_onlySingleClusterSpacePoints,
41  "standard is false. If activated, the module will not try to find combinations of U and V clusters for the SVD any more",
42  bool(false));
43 
44  addParam("MinClusterTime", m_minClusterTime, "clusters with time below this value are not considered to make spacePoints.",
45  float(-20));
46  addParam("inputPDF", m_inputPDF,
47  "Path containing pdf root file", std::string("/data/svd/spacePointQICalibration.root"));
48  addParam("useQualityEstimator", m_useQualityEstimator,
49  "Standard is true. If turned off spacepoints will not be assigned a quality in their pairing.", bool(false));
50 
51  addParam("useLegacyNaming", m_useLegacyNaming,
52  "Use old PDF name convention?", bool(true));
53 
54  addParam("numMaxSpacePoints", m_numMaxSpacePoints,
55  "Maximum number of SpacePoints allowed in an event, above this threshold no SpacePoint will be created",
56  unsigned(m_numMaxSpacePoints));
57 
58 }
59 
60 
61 
62 void SVDSpacePointCreatorModule::initialize()
63 {
64  // prepare all store- and relationArrays:
65  m_spacePoints.registerInDataStore(m_spacePointsName, DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered);
66  m_svdClusters.isRequired(m_svdClustersName);
67 
68 
69  //Relations to cluster objects only if the ancestor relations exist:
70  m_spacePoints.registerRelationTo(m_svdClusters, DataStore::c_Event, DataStore::c_DontWriteOut);
71 
72 
73  B2DEBUG(1, "SVDSpacePointCreatorModule(" << m_nameOfInstance << ")::initialize: names set for containers:\n" <<
74  "\nsvdClusters: " << m_svdClusters.getName() <<
75  "\nspacePoints: " << m_spacePoints.getName());
76 
77  if (m_useQualityEstimator == true) {
78  if (m_inputPDF.empty()) {
79  B2ERROR("Input PDF filename not set");
80  } else {
81  std::string fullPath = FileSystem::findFile(m_inputPDF);
82  if (fullPath.empty()) {
83  B2ERROR("PDF file:" << m_inputPDF << "not located! Check filename input matches name of PDF file!");
84  }
85  m_inputPDF = fullPath;
86  }
87 
88  m_calibrationFile = new TFile(m_inputPDF.c_str(), "READ");
89  if (!m_calibrationFile->IsOpen())
90  B2FATAL("Couldn't open pdf file:" << m_inputPDF);
91  }
92 
93  // set some counters for output:
94  InitializeCounters();
95 }
96 
97 
98 
99 void SVDSpacePointCreatorModule::event()
100 {
101 
102 
103 
104  if (m_onlySingleClusterSpacePoints == true) {
105  provideSVDClusterSingles(m_svdClusters,
106  m_spacePoints);
107  } else {
108  provideSVDClusterCombinations(m_svdClusters, m_spacePoints, m_HitTimeCut, m_useQualityEstimator, m_calibrationFile,
109  m_useLegacyNaming, m_numMaxSpacePoints, m_eventLevelTrackingInfoName);
110  }
111 
112 
113  B2DEBUG(1, "SVDSpacePointCreatorModule(" << m_nameOfInstance <<
114  ")::event: spacePoints for single SVDClusters created! Size of arrays:\n" <<
115  ", svdClusters: " << m_svdClusters.getEntries() <<
116  ", spacePoints: " << m_spacePoints.getEntries());
117 
118 
119  if (LogSystem::Instance().isLevelEnabled(LogConfig::c_Debug, 10, PACKAGENAME()) == true) {
120  for (int index = 0; index < m_spacePoints.getEntries(); index++) {
121  const SpacePoint* sp = m_spacePoints[index];
122 
123  B2DEBUG(10, "SVDSpacePointCreatorModule(" << m_nameOfInstance << ")::event: spacePoint " << index <<
124  " with type " << sp->getType() <<
125  " and VxdID " << VxdID(sp->getVxdID()) <<
126  " is tied to a cluster in: " << sp->getArrayName());
127  }
128  }
129 
130  m_TESTERSVDClusterCtr += m_svdClusters.getEntries();
131  m_TESTERSpacePointCtr += m_spacePoints.getEntries();
132 
133 }
134 
135 
136 
137 void SVDSpacePointCreatorModule::terminate()
138 {
139  B2DEBUG(1, "SVDSpacePointCreatorModule(" << m_nameOfInstance << ")::terminate: total number of occured instances:\n" <<
140  ", svdClusters: " << m_TESTERSVDClusterCtr <<
141  ", spacePoints: " << m_TESTERSpacePointCtr);
142  if (m_useQualityEstimator == true) {
143  m_calibrationFile->Delete();
144  }
145 }
146 
147 
148 void SVDSpacePointCreatorModule::InitializeCounters()
149 {
150  m_TESTERSVDClusterCtr = 0;
151  m_TESTERSpacePointCtr = 0;
152 }
Base class for Modules.
Definition: Module.h:72
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
Imports Clusters of the SVD detector and converts them to spacePoints.
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
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
void provideSVDClusterSingles(const StoreArray< SVDCluster > &svdClusters, StoreArray< SpacePointType > &spacePoints)
simply store one spacePoint for each existing SVDCluster.
void provideSVDClusterCombinations(const StoreArray< SVDCluster > &svdClusters, StoreArray< SpacePointType > &spacePoints, SVDHitTimeSelection &hitTimeCut, bool useQualityEstimator, TFile *pdfFile, bool useLegacyNaming, unsigned int numMaxSpacePoints, std::string m_eventLevelTrackingInfoName)
finds all possible combinations of U and V Clusters for SVDClusters.
Abstract base class for different kinds of events.