Belle II Software development
CDCDedxSigmaPred.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 <cdc/utilities/CDCDedxSigmaPred.h>
10
11using namespace Belle2;
12
14{
15
16 // make sure the resolution parameters are reasonable
17 if (!m_DBSigmaPars || m_DBSigmaPars->getSize() == 0)
18 B2FATAL("No dE/dx sigma parameters!");
19
20 std::vector<double> sigmapar;
21 sigmapar = m_DBSigmaPars->getSigmaPars();
22 for (int i = 0; i < 2; ++i) m_dedxpars[i] = sigmapar[i];
23 for (int i = 0; i < 5; ++i) m_nhitpars[i] = sigmapar[i + 2];
24 for (int i = 0; i < 10; ++i) m_cospars[i] = sigmapar[i + 7];
25}
26
27void CDCDedxSigmaPred::setParameters(std::string infile)
28{
29
30 B2INFO("\n\tWidgetParameterization: Using parameters from file --> " << infile);
31
32 std::ifstream fin;
33 fin.open(infile.c_str());
34
35 if (!fin.good()) B2FATAL("\tWARNING: CANNOT FIND " << infile);
36
37 int par;
38
39 B2INFO("\t --> dedx parameters");
40 for (int i = 0; i < 2; ++i) {
41 fin >> par >> m_dedxpars[i];
42 B2INFO("\t\t (" << i << ")" << m_dedxpars[i]);
43 }
44
45 B2INFO("\t --> nhit parameters");
46 for (int i = 0; i <= 4; ++i) {
47 fin >> par >> m_nhitpars[i];
48 B2INFO("\t\t (" << i << ")" << m_nhitpars[i]);
49 }
50
51 B2INFO("\t --> cos parameters");
52 for (int i = 0; i < 10; ++i) { //4
53 fin >> par >> m_cospars[i];
54 B2INFO("\t\t (" << i << ")" << m_cospars[i]);
55 }
56
57 fin.close();
58}
59
60void CDCDedxSigmaPred::printParameters(std::string outfile)
61{
62
63 B2INFO("\n\tCDCDedxSigmaPred: Printing parameters to file --> " << outfile.c_str());
64
65 // write out the parameters to file
66 std::ofstream fout(outfile.c_str());
67
68 for (int i = 1; i < 3; ++i) fout << i << "\t" << m_dedxpars[i - 1] << std::endl;
69
70 fout << std::endl;
71 for (int i = 3; i < 8; ++i) fout << i << "\t" << m_nhitpars[i - 3] << std::endl;
72
73 fout << std::endl;
74 for (int i = 8; i < 18; ++i) fout << i << "\t" << m_cospars[i - 8] << std::endl;
75
76 fout << std::endl;
77
78 fout.close();
79}
80
81double CDCDedxSigmaPred::getSigma(double dedx, double nhit, double cos, double timereso)
82{
83 double correction = cosPrediction(cos) * nhitPrediction(nhit) * ionzPrediction(dedx) * timereso;
84 return correction;
85}
86
87
89{
90
91// Define minimum and maximum nhit values
92 int nhit_min = 8, nhit_max = 37;
93
94 // Define the parameter array and initialize it
95 double nhitpar[6];
96 nhitpar[0] = 2;
97 for (int i = 0; i < 5; ++i) nhitpar[i + 1] = m_nhitpars[i];
98
99 // Create an instance of the CDCDedxWidgetSigma class
101
102 // Initialize x array to pass to sigmaCurve
103 double x[1];
104
105 x[0] = nhit;
106
107 double corNHit;
108
109 if (nhit < nhit_min) {
110 x[0] = nhit_min;
111 corNHit = gs.sigmaCurve(x, std::vector<double>(nhitpar, nhitpar + 6)) * std::sqrt(nhit_min / nhit);
112 } else if (nhit > nhit_max) {
113 x[0] = nhit_max;
114 corNHit = gs.sigmaCurve(x, std::vector<double>(nhitpar, nhitpar + 6)) * std::sqrt(nhit_max / nhit);
115 } else {
116 corNHit = gs.sigmaCurve(x, std::vector<double>(nhitpar, nhitpar + 6));
117 }
118
119 return corNHit;
120}
121
123{
124 // Define the parameter array and initialize it
125 double dedxpar[3];
126 dedxpar[0] = 1;
127 for (int i = 0; i < 2; ++i) dedxpar[i + 1] = m_dedxpars[i];
128
129 // Create an instance of the CDCDedxWidgetSigma class
131
132// Initialize x array to pass to sigmaCurve
133 double x[1];
134 x[0] = dedx;
135
136 double corDedx = gs.sigmaCurve(x, std::vector<double>(dedxpar, dedxpar + 3));
137
138 return corDedx;
139}
140
142{
143 // Create an instance of the CDCDedxWidgetSigma class
145
146 // Define the parameter array and initialize it
147 double cospar[11];
148 cospar[0] = 3;
149 for (int i = 0; i < 10; ++i) cospar[i + 1] = m_cospars[i];
150
151 // Initialize x array to pass to sigmaCurve
152 double x[1];
153 x[0] = cos;
154
155 double corCos;
156 corCos = gs.sigmaCurve(x, std::vector<double>(cospar, cospar + 11));
157
158 return corCos;
159}
double ionzPrediction(double dedx)
Return sigma from the ionization parameterization.
void setParameters()
set the parameters
const DBObjPtr< CDCDedxSigmaPars > m_DBSigmaPars
db object for dE/dx resolution parameters
double getSigma(double dedx, double nhit, double cos, double timereso)
Return the predicted resolution depending on dE/dx, nhit, and cos(theta)
double cosPrediction(double cos)
Return sigma from the cos parameterization.
double m_dedxpars[2]
parameters for sigma vs.
double nhitPrediction(double nhit)
Return sigma from the nhit parameterization.
void printParameters(std::string infile)
write the parameters in file
double m_cospars[10]
parameters for sigma vs.
double m_nhitpars[5]
parameters for sigma vs.
Class to hold the beta-gamma (bg) resolution function.
double sigmaCurve(double *x, const std::vector< double > &par) const
calculate the predicted sigma value as a function of beta-gamma (bg) this is done with a different fu...
Abstract base class for different kinds of events.