Belle II Software development
SVDClusterQualityEstimatorModule.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/svdClusterQualityEstimator/SVDClusterQualityEstimatorModule.h>
10#include <svd/modules/svdClusterQualityEstimator/ClusterQualityHelperFunctions.h>
11#include <framework/utilities/FileSystem.h>
12
13#include <TH2F.h>
14
15using namespace std;
16using namespace Belle2;
17
18REG_MODULE(SVDClusterQualityEstimator);
19
21
22{
23 setDescription("Assignment of probability for a cluster being generated from signal hit.");
24
26
27 addParam("SVDClusters", m_svdClustersName,
28 "SVDCluster collection name", string(""));
29
30 addParam("useQualityEstimator", m_useQualityEstimator,
31 "Standard is true. If turned off clusters will not be assigned a quality.", bool(true));
32
33 addParam("inputPDF", m_inputPDF,
34 "Path containing pdf root file", std::string("/data/svd/clusterQICalibration.root"));
35
36 addParam("useLegacyNaming", m_useLegacyNaming,
37 "Use old PDF name convention?", bool(true));
38}
39
40
42{
43
44 if (m_useQualityEstimator == true) {
45 if (m_inputPDF.empty()) {
46 B2ERROR("Input PDF filename not set!");
47 } else {
48 std::string fullPath = FileSystem::findFile(m_inputPDF);
49 if (fullPath.empty()) {
50 B2ERROR("PDF file:" << m_inputPDF << "not located! Check filename input matches name of PDF file!");
51 }
52 m_inputPDF = fullPath;
53 }
54
55 m_calibrationFile = new TFile(m_inputPDF.c_str(), "READ");
56
57 if (!m_calibrationFile->IsOpen())
58 B2FATAL("Couldn't open pdf file:" << m_inputPDF);
59 }
60
61 // prepare storeArray
63
64}
65
67{
68
69 if (m_useQualityEstimator == true) {
70 for (auto& svdCluster : m_svdClusters) {
71
72 double charge = svdCluster.getCharge();
73 double time = svdCluster.getClsTime();
74
75 int pdfEntries = m_calibrationFile->GetListOfKeys()->GetSize();
76 int maxSize;
77 if (m_useLegacyNaming == 1) {
78 maxSize = floor(pdfEntries / 12); // 2(sides)*3(sensorType)*2(prob/error)=12
79 } else {
80 maxSize = floor(pdfEntries / 688); // 2(sides)*172(sensors)*2(prob/error)=688
81 }
82
83 std::string probInputName;
84 std::string errorInputName;
85
86 clusterPDFName(svdCluster.getSensorID(), svdCluster.getSize(), svdCluster.isUCluster(), maxSize, probInputName, errorInputName,
88
89 TH2F* probPDF = nullptr;
90 TH2F* errorPDF = nullptr;
91 m_calibrationFile->GetObject(probInputName.c_str(), probPDF);
92 m_calibrationFile->GetObject(errorInputName.c_str(), errorPDF);
93
94
95 int xBin = probPDF->GetXaxis()->FindFixBin(time);
96 int yBin = probPDF->GetYaxis()->FindFixBin(charge);
97
98 double signalProb = probPDF->GetBinContent(xBin, yBin);
99 double signalProbError = errorPDF->GetBinContent(xBin, yBin);
100
101 svdCluster.setQualityIndicator(signalProb);
102 svdCluster.setQualityIndicatorError(signalProbError);
103 }
104 }
105}
106
108{
109 B2INFO("SVDClusterQualityEstimatorModule::terminate");
110
111 if (m_useQualityEstimator == true) {
112 m_calibrationFile->Delete();
113 }
114}
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:151
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 m_svdClustersName
SVDCluster collection name.
virtual void initialize() override
Init the module.
StoreArray< SVDCluster > m_svdClusters
The storeArray for svdClusters.
std::string m_inputPDF
File path of root file containing pdf histograms.
bool m_useLegacyNaming
Choice between PDF naming conventions.
TFile * m_calibrationFile
Pointer to root TFile containing PDF histograms.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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 clusterPDFName(const VxdID &sensor, int size, int side, int maxClusterSize, std::string &PDFName, std::string &errorPDFName, bool useLegacyNaming)
Function to set name of PDF for cluster quality estimation.
Abstract base class for different kinds of events.
STL namespace.