Belle II Software development
SVDClusterQualityEstimatorCalibration.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/ClusterQualityHelperFunctions.h>
10#include <svd/modules/svdClusterQualityEstimator/SVDClusterQualityEstimatorCalibrationModule.h>
11
12#include <TFile.h>
13
14#include <vector>
15#include <math.h>
16
17using namespace std;
18using namespace Belle2;
19
20
21REG_MODULE(SVDClusterQualityEstimatorCalibration);
22
24 Module()
25{
26
27 setDescription("Generate PDFs used in assigning quality to clusterss.");
29
30 // 1. Collections.
31 addParam("SVDClusters", m_svdClustersName,
32 "SVDCluster collection name", string(""));
33
34 addParam("RecoTracks", m_recoTracksName,
35 "RecoTracks 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("binSizeCharge", m_binSizeCharge, "Number of bins in charge distribtuion.",
41 int(100));
42 addParam("binSizeTime", m_binSizeTime, "Number of bins in charge distribtuion.",
43 int(40));
44
45 addParam("maxClusterSize", m_maxClusterSize, "Max number of strips the PDF are separated into.",
46 int(5));
47
48
49 addParam("outputFileName", m_outputFileName,
50 "Name of output file containing pdfs", std::string("clusterQICalibration.root"));
51
52 addParam("useLegacyNaming", m_useLegacyNaming,
53 "Use old PDF name convention?", bool(true));
54}
55
56
57
59{
60 // prepare all store- and relationArrays:
63
64
65
67 for (auto& layers : geo.getLayers(VXD::SensorInfoBase::SVD)) {
68 for (auto& ladders : geo.getLadders(layers)) {
69 for (auto& sensors : geo.getSensors(ladders)) {
70
71 for (int side = 0; side <= 1; side++) {
72 for (int size = 1; size <= m_maxClusterSize; size++) {
73 std::string sensorName;
74 std::string errorNameString;
75
76
77 clusterPDFName(sensors, size, side, m_maxClusterSize, sensorName, errorNameString, m_useLegacyNaming);
78
79 std::string signalHistName = sensorName + "signal";
80 std::string backgroundHistName = sensorName + "background";
81
82 if (signalHistMap.count(sensorName) == 0) {
83 TH2F* sigHist = new TH2F(signalHistName.c_str(), "", m_binSizeTime, -100, 100, m_binSizeCharge, 0, 200000);
84 TH2F* bkgHist = new TH2F(backgroundHistName.c_str(), "", m_binSizeTime, -100, 100, m_binSizeCharge, 0, 200000);
85
86 signalHistMap[sensorName] = sigHist;
87 backgroundHistMap[sensorName] = bkgHist;
88 }
89 }
90 }
91 }
92 }
93 }
94
95
96
97}
98
99
100
102{
103 for (auto& track : m_recoTracks) {
104 if (track.wasFitSuccessful() == 1) {
105 if (track.hasSVDHits() == 1) {
106 for (auto& svdHit : track.getSVDHitList()) {
107 std::string pdfName;
108 std::string errorNameString;
109 clusterPDFName(svdHit->getSensorID(), svdHit->getSize(), svdHit->isUCluster(), m_maxClusterSize, pdfName, errorNameString,
111
112 auto sigHist = signalHistMap.at(pdfName);
113 sigHist->Fill(svdHit->getClsTime(), svdHit->getCharge());
114
115
116 }
117 }
118 }
119 }
120
121
122 for (auto& cluster : m_svdClusters) {
123 std::string pdfName;
124 std::string errorNameString;
125 clusterPDFName(cluster.getSensorID(), cluster.getSize(), cluster.isUCluster(), m_maxClusterSize, pdfName, errorNameString,
127
128 auto bkgHist = backgroundHistMap.at(pdfName);
129 bkgHist->Fill(cluster.getClsTime(), cluster.getCharge());
130 }
131}
132
133
134
136{
137 //Open rootfile
138 TFile* f = new TFile(m_outputFileName.c_str(), "RECREATE");
139 f->cd();
140
141 std::vector<std::string> usedSensors; //Store names to avoid double counting
142
144 for (auto& layers : geo.getLayers(VXD::SensorInfoBase::SVD)) {
145 for (auto& ladders : geo.getLadders(layers)) {
146 for (auto& sensors : geo.getSensors(ladders)) {
147 for (int side = 0; side <= 1; side++) {
148 for (int size = 1; size <= m_maxClusterSize; size++) {
149 std::string sensorName;
150 std::string errorName;
151
152 clusterPDFName(sensors, size, side, m_maxClusterSize, sensorName, errorName, m_useLegacyNaming);
153
154 if (std::find(usedSensors.begin(), usedSensors.end(), sensorName.c_str()) == usedSensors.end()) {
155 usedSensors.push_back(sensorName);
156 TH2F* probHist = new TH2F(sensorName.c_str(), "", m_binSizeTime, -100, 100, m_binSizeCharge, 0, 200000);
157 TH2F* errorHist = new TH2F(errorName.c_str(), "", m_binSizeTime, -100, 100, m_binSizeCharge, 0, 200000);
158 calculateProb(signalHistMap[sensorName], backgroundHistMap[sensorName], probHist);
159 calculateError(signalHistMap[sensorName], backgroundHistMap[sensorName], errorHist);
160
161 probHist->Write();
162 errorHist->Write();
163 }
164 }
165 }
166 }
167 }
168 }
169 f->Close();
170}
171
172
173void SVDClusterQualityEstimatorCalibrationModule::calculateProb(TH2F* signal, TH2F* background, TH2F* probability)
174{
175 signal->Divide(background);
176 probability->Add(signal);
177
178}
179void SVDClusterQualityEstimatorCalibrationModule::calculateError(TH2F* signal, TH2F* background, TH2F* error)
180{
181 int imax = signal->GetXaxis()->GetNbins();
182 int jmax = signal->GetYaxis()->GetNbins();
183 for (int i = 1; i <= imax; i++) {
184 for (int j = 1; j <= jmax; j++) {
185 int bkg = background->GetBinContent(i, j);
186 int sig = signal->GetBinContent(i, j);
187 double var = ((sig + 1) * (sig + 2)) / ((bkg + 2) * (bkg + 3)) -
188 ((sig + 1) * (sig + 1)) / ((bkg + 2) * (bkg + 2));
189 double err = sqrt(var);
190 error->SetBinContent(i, j, err);
191 }
192 }
193}
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_nameOfInstance
allows the user to set an identifier for this module.
StoreArray< SVDCluster > m_svdClusters
the storeArray for svdClusters
void calculateError(TH2F *signal, TH2F *background, TH2F *error)
compute error
std::map< std::string, TH2F * > backgroundHistMap
map to store background histograms
std::map< std::string, TH2F * > signalHistMap
map to store signal histograms
int m_maxClusterSize
Maximum cluster size the PDFs will be distributed over.
void calculateProb(TH2F *signal, TH2F *background, TH2F *probability)
compute probvability
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
const std::set< Belle2::VxdID > getLayers(SensorInfoBase::SensorType sensortype=SensorInfoBase::VXD)
Return a set of all known Layers.
Definition: GeoCache.cc:176
const std::set< Belle2::VxdID > & getSensors(Belle2::VxdID ladder) const
Return a set of all sensor IDs belonging to a given ladder.
Definition: GeoCache.cc:204
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
const std::set< Belle2::VxdID > & getLadders(Belle2::VxdID layer) const
Return a set of all ladder IDs belonging to a given layer.
Definition: GeoCache.cc:193
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
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
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.