Belle II Software  release-05-02-19
SVDClusterQualityEstimatorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: James Webb *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <svd/modules/svdClusterQualityEstimator/SVDClusterQualityEstimatorModule.h>
12 #include <svd/modules/svdClusterQualityEstimator/ClusterQualityHelperFunctions.h>
13 #include <framework/utilities/FileSystem.h>
14 
15 #include <TH2F.h>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 REG_MODULE(SVDClusterQualityEstimator)
21 
23 
24 {
25  setDescription("Assignment of probability for a cluster being generated from signal hit.");
26 
27  setPropertyFlags(c_ParallelProcessingCertified);
28 
29  addParam("SVDClusters", m_svdClustersName,
30  "SVDCluster collection name", string(""));
31 
32  addParam("useQualityEstimator", m_useQualityEstimator,
33  "Standard is true. If turned off clusters will not be assigned a quality.", bool(true));
34 
35  addParam("inputPDF", m_inputPDF,
36  "Path containing pdf root file", std::string("/data/svd/clusterQICalibration.root"));
37 
38  addParam("useLegacyNaming", m_useLegacyNaming,
39  "Use old PDF name convention?", bool(true));
40 }
41 
42 
43 void SVDClusterQualityEstimatorModule::initialize()
44 {
45 
46  if (m_useQualityEstimator == true) {
47  if (m_inputPDF.empty()) {
48  B2ERROR("Input PDF filename not set!");
49  } else {
50  std::string fullPath = FileSystem::findFile(m_inputPDF);
51  if (fullPath.empty()) {
52  B2ERROR("PDF file:" << m_inputPDF << "not located! Check filename input matches name of PDF file!");
53  }
54  m_inputPDF = fullPath;
55  }
56 
57  m_calibrationFile = new TFile(m_inputPDF.c_str(), "READ");
58 
59  if (!m_calibrationFile->IsOpen())
60  B2FATAL("Couldn't open pdf file:" << m_inputPDF);
61  }
62 
63  // prepare storeArray
64  m_svdClusters.isRequired(m_svdClustersName);
65 
66 }
67 
68 void SVDClusterQualityEstimatorModule::event()
69 {
70 
71  if (m_useQualityEstimator == true) {
72  for (auto& svdCluster : m_svdClusters) {
73 
74  double charge = svdCluster.getCharge();
75  double time = svdCluster.getClsTime();
76 
77  int pdfEntries = m_calibrationFile->GetListOfKeys()->GetSize();
78  int maxSize;
79  if (m_useLegacyNaming == 1) {
80  maxSize = floor(pdfEntries / 12); // 2(sides)*3(sensorType)*2(prob/error)=12
81  } else {
82  maxSize = floor(pdfEntries / 688); // 2(sides)*172(sensors)*2(prob/error)=688
83  }
84 
85  std::string probInputName;
86  std::string errorInputName;
87 
88  clusterPDFName(svdCluster.getSensorID(), svdCluster.getSize(), svdCluster.isUCluster(), maxSize, probInputName, errorInputName,
89  m_useLegacyNaming);
90 
91  TH2F* probPDF = nullptr;
92  TH2F* errorPDF = nullptr;
93  m_calibrationFile->GetObject(probInputName.c_str(), probPDF);
94  m_calibrationFile->GetObject(errorInputName.c_str(), errorPDF);
95 
96 
97  int xBin = probPDF->GetXaxis()->FindFixBin(time);
98  int yBin = probPDF->GetYaxis()->FindFixBin(charge);
99 
100  double signalProb = probPDF->GetBinContent(xBin, yBin);
101  double signalProbError = errorPDF->GetBinContent(xBin, yBin);
102 
103  svdCluster.setQualityIndicator(signalProb);
104  svdCluster.setQualityIndicatorError(signalProbError);
105  }
106  }
107 }
108 
109 void SVDClusterQualityEstimatorModule::terminate()
110 {
111  B2INFO("SVDClusterQualityEstimatorModule::terminate");
112 
113  if (m_useQualityEstimator == true) {
114  m_calibrationFile->Delete();
115  }
116 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::SVDClusterQualityEstimatorModule
Calculates the probability of a cluster originating from signal hit.
Definition: SVDClusterQualityEstimatorModule.h:41
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::clusterPDFName
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.
Definition: ClusterQualityHelperFunctions.h:34