Belle II Software  release-08-01-10
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 
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 #include <svd/dataobjects/SVDEventInfo.h>
17 
18 using namespace std;
19 using namespace Belle2;
20 
21 
22 REG_MODULE(SVDSpacePointCreator);
23 
24 SVDSpacePointCreatorModule::SVDSpacePointCreatorModule() :
25  Module()
26 {
28 
29  setDescription("Imports Clusters of the SVD detector and converts them to spacePoints.");
31 
32  // 1. Collections.
33  addParam("SVDClusters", m_svdClustersName,
34  "SVDCluster collection name", string(""));
35  addParam("SpacePoints", m_spacePointsName,
36  "SpacePoints collection name", string("SVDSpacePoints"));
37  addParam("EventLevelTrackingInfoName", m_eventLevelTrackingInfoName,
38  "EventLevelTrackingInfo collection name", string(""));
39  addParam("SVDEventInfo", m_svdEventInfoName,
40  "SVDEventInfo collection name.", string("SVDEventInfo"));
41 
42  // 2.Modification parameters:
43  addParam("NameOfInstance", m_nameOfInstance,
44  "allows the user to set an identifier for this module. Usefull if one wants to use several instances of that module", string(""));
45  addParam("OnlySingleClusterSpacePoints", m_onlySingleClusterSpacePoints,
46  "standard is false. If activated, the module will not try to find combinations of U and V clusters for the SVD any more",
47  bool(false));
48 
49  addParam("MinClusterTime", m_minClusterTime, "clusters with time below this value are not considered to make spacePoints.",
50  float(-20));
51  addParam("inputPDF", m_inputPDF,
52  "Path containing pdf root file", std::string("/data/svd/spacePointQICalibration.root"));
53  addParam("useQualityEstimator", m_useQualityEstimator,
54  "Standard is true. If turned off spacepoints will not be assigned a quality in their pairing.", bool(false));
55 
56  addParam("useLegacyNaming", m_useLegacyNaming,
57  "Use old PDF name convention?", bool(true));
58 
59  addParam("numMaxSpacePoints", m_numMaxSpacePoints,
60  "Maximum number of SpacePoints allowed in an event, above this threshold no SpacePoint will be created",
61  unsigned(m_numMaxSpacePoints));
62 
63  addParam("useSVDGroupInfoIn6Sample", m_useSVDGroupInfoIn6Sample,
64  "Use SVD group info to reject combinations from clusters belonging to different groups in 6-sample DAQ mode", bool(false));
65  addParam("useSVDGroupInfoIn3Sample", m_useSVDGroupInfoIn3Sample,
66  "Use SVD group info to reject combinations from clusters belonging to different groups in 3-sample DAQ mode", bool(false));
67  addParam("numberOfSignalGroups", m_usedParsIn6Samples.numberOfSignalGroups,
68  "Number of groups expected to contain the signal clusters.",
69  int(1));
70  addParam("formSingleSignalGroup", m_usedParsIn6Samples.formSingleSignalGroup,
71  "Form a single super-group.",
72  bool(false));
73 
74  addParam("forceGroupingFromDB", m_forceGroupingFromDB, "use SVDRecoConfiguration from DB", bool(true));
75  addParam("useParamFromDB", m_useParamFromDB, "use SVDTimeGroupingConfiguration from DB", bool(true));
76 
77  addParam("useSVDSpacePointSNRFractionFor6Samples", m_useSVDSpacePointSNRFractionFor6Samples,
78  "Use SVDSpacePointSNRFractionSelector to apply a selection on combinations of clusters in 6-sample DAQ mode", bool(false));
79  addParam("useSVDSpacePointSNRFractionFor3Samples", m_useSVDSpacePointSNRFractionFor3Samples,
80  "Use SVDSpacePointSNRFractionSelector to apply a selection on combinations of clusters in 3-sample DAQ mode", bool(false));
81 
82  addParam("useDBForSNRFraction", m_useDBForSNRFraction,
83  "if False, use configuration module parameters for SVDSPacePointSNRFractionSelector",
84  bool(true));
85 
86 
89 }
90 
91 
92 
94 {
96  if (!m_recoConfig.isValid())
97  B2FATAL("no valid configuration found for SVD reconstruction");
98  else
99  B2DEBUG(20, "SVDRecoConfiguration: from now on we are using " << m_recoConfig->get_uniqueID());
100 
101  if (m_forceGroupingFromDB) {
102  m_useSVDGroupInfoIn6Sample = m_recoConfig->isSVDGroupInfoUsedInSPCreator(6);
103  m_useSVDGroupInfoIn3Sample = m_recoConfig->isSVDGroupInfoUsedInSPCreator(3);
104  }
105 
106  if (m_useDBForSNRFraction) {
107  m_useSVDSpacePointSNRFractionFor6Samples = m_recoConfig->useSVDSpacePointSNRFraction(6);
108  m_useSVDSpacePointSNRFractionFor3Samples = m_recoConfig->useSVDSpacePointSNRFraction(3);
109  }
110  }
111 
113  B2INFO("SVDSpacePointCreator : SVDCluster groupId is used for 6-sample DAQ mode.");
114  else
115  B2INFO("SVDSpacePointCreator : SVDCluster groupId is not used for 6-sample DAQ mode.");
116 
118  B2INFO("SVDSpacePointCreator : SVDCluster groupId is used for 3-sample DAQ mode.");
119  else
120  B2INFO("SVDSpacePointCreator : SVDCluster groupId is not used for 3-sample DAQ mode.");
121 
123  B2INFO("SVDSpacePointCreator : cut on sample SNR fraction is used for 6-sample DAQ mode.");
124 
126  B2INFO("SVDSpacePointCreator : cut on sample SNR fraction is used for 3-sample DAQ mode.");
127 
129  if (!m_svdSpacePointSNRFractionSelector.isValid())
130  B2FATAL("No valid SVDSpacePointSNRFractionSelector");
131  }
132 
133  if (m_useParamFromDB &&
135 
136  if (!m_recoConfig.isValid())
137  B2FATAL("no valid configuration found for SVD reconstruction");
138  else
139  B2DEBUG(20, "SVDRecoConfiguration: from now on we are using " << m_recoConfig->get_uniqueID());
140 
141  TString timeRecoWith6SamplesAlgorithm = m_recoConfig->getTimeRecoWith6Samples();
142  TString timeRecoWith3SamplesAlgorithm = m_recoConfig->getTimeRecoWith3Samples();
143 
144  if (!m_groupingConfig.isValid())
145  B2FATAL("no valid configuration found for SVDTimeGrouping");
146  else
147  B2DEBUG(20, "SVDTimeGroupingConfiguration: from now on we are using " << m_groupingConfig->get_uniqueID());
148 
149  m_usedParsIn6Samples = m_groupingConfig->getTimeGroupingParameters(timeRecoWith6SamplesAlgorithm, 6);
150  m_usedParsIn3Samples = m_groupingConfig->getTimeGroupingParameters(timeRecoWith3SamplesAlgorithm, 3);
151  }
152 }
153 
154 
156 {
157  // prepare all store- and relationArrays:
160 
161 
162  //Relations to cluster objects only if the ancestor relations exist:
164 
165  B2DEBUG(20, "SVDSpacePointCreatorModule(" << m_nameOfInstance << ")::initialize: names set for containers:\n" <<
166  "\nsvdClusters: " << m_svdClusters.getName() <<
167  "\nspacePoints: " << m_spacePoints.getName());
168 
169  if (m_useQualityEstimator == true) {
170  if (m_inputPDF.empty()) {
171  B2ERROR("Input PDF filename not set");
172  } else {
173  std::string fullPath = FileSystem::findFile(m_inputPDF);
174  if (fullPath.empty()) {
175  B2ERROR("PDF file:" << m_inputPDF << "not located! Check filename input matches name of PDF file!");
176  }
177  m_inputPDF = fullPath;
178  }
179 
180  m_calibrationFile = new TFile(m_inputPDF.c_str(), "READ");
181  if (!m_calibrationFile->IsOpen())
182  B2FATAL("Couldn't open pdf file:" << m_inputPDF);
183  }
184 
185  // set some counters for output:
187 }
188 
189 
190 
192 {
193 
194  bool useSVDGroupInfo = m_useSVDGroupInfoIn6Sample || m_useSVDGroupInfoIn3Sample;
195  bool useSVDSpacePointSNRFraction = m_useSVDSpacePointSNRFractionFor6Samples
197  int numberOfSignalGroups;
198  bool formSingleSignalGroup;
199  if (useSVDGroupInfo || useSVDSpacePointSNRFraction) {
200  // first take Event Informations:
202  if (!temp_eventinfo.isValid())
203  m_svdEventInfoName = "SVDEventInfoSim";
205  if (!eventinfo) B2ERROR("No SVDEventInfo!");
206  int numberOfAcquiredSamples = eventinfo->getNSamples();
207  // then use the respective parameters
208  if (numberOfAcquiredSamples == 6) {
209  useSVDGroupInfo = m_useSVDGroupInfoIn6Sample;
210  numberOfSignalGroups = m_usedParsIn6Samples.numberOfSignalGroups;
211  formSingleSignalGroup = m_usedParsIn6Samples.formSingleSignalGroup;
212  useSVDSpacePointSNRFraction = m_useSVDSpacePointSNRFractionFor6Samples;
213  } else if (numberOfAcquiredSamples == 3) {
214  useSVDGroupInfo = m_useSVDGroupInfoIn3Sample;
215  numberOfSignalGroups = m_usedParsIn3Samples.numberOfSignalGroups;
216  formSingleSignalGroup = m_usedParsIn3Samples.formSingleSignalGroup;
217  useSVDSpacePointSNRFraction = m_useSVDSpacePointSNRFractionFor3Samples;
218  }
219  }
220 
221  if (m_onlySingleClusterSpacePoints == true) {
223  m_spacePoints);
224  } else {
226  m_useLegacyNaming, m_numMaxSpacePoints, m_eventLevelTrackingInfoName, useSVDGroupInfo, numberOfSignalGroups, formSingleSignalGroup,
227  m_NoiseCal, m_svdSpacePointSNRFractionSelector, useSVDSpacePointSNRFraction);
228  }
229 
230 
231  B2DEBUG(21, "SVDSpacePointCreatorModule(" << m_nameOfInstance <<
232  ")::event: spacePoints for single SVDClusters created! Size of arrays:\n" <<
233  ", svdClusters: " << m_svdClusters.getEntries() <<
234  ", spacePoints: " << m_spacePoints.getEntries());
235 
236 
237  if (LogSystem::Instance().isLevelEnabled(LogConfig::c_Debug, 10, PACKAGENAME()) == true) {
238  for (int index = 0; index < m_spacePoints.getEntries(); index++) {
239  const SpacePoint* sp = m_spacePoints[index];
240 
241  B2DEBUG(29, "SVDSpacePointCreatorModule(" << m_nameOfInstance << ")::event: spacePoint " << index <<
242  " with type " << sp->getType() <<
243  " and VxdID " << VxdID(sp->getVxdID()) <<
244  " is tied to a cluster in: " << sp->getArrayName());
245  }
246  }
247 
250 
251 }
252 
253 
254 
256 {
257  B2DEBUG(20, "SVDSpacePointCreatorModule(" << m_nameOfInstance << ")::terminate: total number of occured instances:\n" <<
258  ", svdClusters: " << m_TESTERSVDClusterCtr <<
259  ", spacePoints: " << m_TESTERSpacePointCtr);
260  if (m_useQualityEstimator == true) {
261  m_calibrationFile->Delete();
262  }
263 }
264 
265 
267 {
270 }
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:148
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:26
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:31
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
std::string m_eventLevelTrackingInfoName
Name of the EventLevelTrackingInfo.
bool m_useParamFromDB
use the configuration from SVDTimeGroupingConfiguration DB.
std::string m_svdClustersName
SVDCluster collection name.
float m_minClusterTime
clusters with time below this value are not considered to make spacePoints
std::string m_nameOfInstance
allows the user to set an identifier for this module.
SVDTimeGroupingParameters m_usedParsIn3Samples
module parameter values for 3-sample DAQ taken from SVDTimeGroupingConfiguration dbobject.
virtual void initialize() override
Init the module.
SVDHitTimeSelection m_HitTimeCut
selection based on clustr time db object
unsigned int m_numMaxSpacePoints
do not crete SPs if their number exceeds m_numMaxSpacePoints, tuned with BG19
StoreArray< SVDCluster > m_svdClusters
the storeArray for svdClusters as member, is faster than recreating link for each event
std::string m_inputPDF
File path of root file containing pdf histograms.
virtual void event() override
eventWise jobs (e.g.
void InitializeCounters()
initialize variables in constructor to avoid nondeterministic behavior
unsigned int m_TESTERSpacePointCtr
counts total number of SpacePoints occured
SVDTimeGroupingParameters m_usedParsIn6Samples
module parameter values for 6-sample DAQ taken from SVDTimeGroupingConfiguration dbobject.
SVDNoiseCalibrations m_NoiseCal
SVDNoise calibrations db object.
bool m_useSVDSpacePointSNRFractionFor6Samples
Use SVDSpacePointSNRFractionSelector to reject combinations in 6-sample DAQ mode.
virtual void terminate() override
final output with mini-feedback
StoreArray< SpacePoint > m_spacePoints
the storeArray for spacePoints as member, is faster than recreating link for each event
bool m_forceGroupingFromDB
use the configuration from SVDRecConfiguration DB.
bool m_useSVDGroupInfoIn6Sample
Use SVD group info to reject combinations in 6-sample DAQ mode.
bool m_useDBForSNRFraction
if true takes the configuration from the DB objects for SVDSpacePointSNRFractionSelector.
bool m_useLegacyNaming
Choice between PDF naming conventions.
TFile * m_calibrationFile
Pointer to root TFile containing PDF histograms.
bool m_useSVDGroupInfoIn3Sample
Use SVD group info to reject combinations in 3-sample DAQ mode.
std::string m_svdEventInfoName
Name of the collection to use for the SVDEventInfo.
std::string m_spacePointsName
SpacePoints collection name.
DBObjPtr< SVDSpacePointSNRFractionSelector > m_svdSpacePointSNRFractionSelector
Payload of selection functions and thresholds applied on SVDSpacePoint.
unsigned int m_TESTERSVDClusterCtr
counts total number of SVDCluster occured
DBObjPtr< SVDRecoConfiguration > m_recoConfig
SVD Reconstruction Configuration payload.
bool m_useSVDSpacePointSNRFractionFor3Samples
Use SVDSpacePointSNRFractionSelector to reject combinations in 3-sample DAQ mode.
DBObjPtr< SVDTimeGroupingConfiguration > m_groupingConfig
SVDTimeGrouping Configuration payload.
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 isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
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
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
void provideSVDClusterCombinations(const StoreArray< SVDCluster > &svdClusters, StoreArray< SpacePointType > &spacePoints, SVDHitTimeSelection &hitTimeCut, bool useQualityEstimator, TFile *pdfFile, bool useLegacyNaming, unsigned int numMaxSpacePoints, std::string m_eventLevelTrackingInfoName, const bool &useSVDGroupInfo, const int &numberOfSignalGroups, const bool &formSingleSignalGroup, const SVDNoiseCalibrations &noiseCal, const DBObjPtr< SVDSpacePointSNRFractionSelector > &svdSpacePointSelectionFunction, bool useSVDSpacePointSNRFractionSelector)
finds all possible combinations of U and V Clusters for SVDClusters.
void provideSVDClusterSingles(const StoreArray< SVDCluster > &svdClusters, StoreArray< SpacePointType > &spacePoints)
simply store one spacePoint for each existing SVDCluster.
Abstract base class for different kinds of events.
Bool_t formSingleSignalGroup
Assign groupID = 0 to all clusters belonging to the signal groups.
Int_t numberOfSignalGroups
Number of groups expected to contain the signal clusters.