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