Belle II Software development
CDCDedxHadSat.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/CDCDedxHadSat.h>
10
11using namespace Belle2;
12
13void CDCDedxHadSat::setParameters(std::string infile)
14{
15
16 B2INFO("\n\t Hadron Saturation: Using parameters from file --> " << infile);
17
18 std::ifstream fin;
19 fin.open(infile.c_str());
20
21 if (!fin.good()) B2FATAL("\tWARNING: CANNOT FIND parameters.txt!");
22
23 fin >> m_alpha ;
24 fin >> m_gamma ;
25 fin >> m_delta ;
26 fin >> m_power ;
27 fin >> m_ratio ;
28
29 fin.close();
30}
31
33{
34
35 if (!m_DBHadronCor || m_DBHadronCor->getSize() == 0) {
36 B2FATAL("No hadron correction parameters!");
37 } else {
38 m_alpha = m_DBHadronCor->getHadronPar(0);
39 m_gamma = m_DBHadronCor->getHadronPar(1);
40 m_delta = m_DBHadronCor->getHadronPar(2);
41 m_power = m_DBHadronCor->getHadronPar(3);
42 m_ratio = m_DBHadronCor->getHadronPar(4);
43 }
44}
45
46
47// define these here to be used in other classes
48double CDCDedxHadSat::D2I(double cosTheta, double D = 1) const
49{
50
51 double absCosTheta = fabs(cosTheta);
52 double projection = pow(absCosTheta, m_power) + m_delta;
53
54 if (projection == 0) {
55 B2WARNING("Something wrong with dE/dx hadron constants!");
56 return D;
57 }
58
59 double chargeDensity = D / projection;
60 double numerator = 1 + m_alpha * chargeDensity;
61 double denominator = 1 + m_gamma * chargeDensity;
62 if (denominator == 0) {
63 B2WARNING("Something wrong with dE/dx hadron constants!");
64 return D;
65 }
66 double I = D * m_ratio * numerator / denominator;
67
68 return I;
69}
70
71double CDCDedxHadSat::I2D(double cosTheta, double I = 1) const
72{
73
74 double absCosTheta = fabs(cosTheta);
75 double projection = pow(absCosTheta, m_power) + m_delta;
76
77 if (projection == 0 || m_ratio == 0) {
78 B2WARNING("Something wrong with dE/dx hadron constants!");
79 return I;
80 }
81 double a = m_alpha / projection;
82 double b = 1 - m_gamma / projection * (I / m_ratio);
83 double c = -1.0 * I / m_ratio;
84
85 if (b == 0 && a == 0) {
86 B2WARNING("both a and b coefficients for hadron correction are 0");
87 return I;
88 }
89
90 double discr = b * b - 4.0 * a * c;
91 if (discr < 0) {
92 B2WARNING("negative discriminant; return uncorrected value");
93 return I;
94 }
95
96 double D = (a != 0) ? (-b + sqrt(discr)) / (2.0 * a) : -c / b;
97 if (D < 0) {
98 B2WARNING("D is less 0! will try another solution");
99 D = (a != 0) ? (-b - sqrt(discr)) / (2.0 * a) : -c / b;
100 if (D < 0) {
101 B2WARNING("D is still less 0! just return uncorrected value");
102 return I;
103 }
104 }
105 return D;
106}
107
108double
109CDCDedxHadSat::D2I(double cosTheta, double D, double alpha, double gamma, double delta, double power, double ratio) const
110{
111
112 double absCosTheta = fabs(cosTheta);
113 double projection = pow(absCosTheta, power) + delta;
114 if (projection == 0) {
115 B2INFO("\t HadronSaturation: D2I Something wrong with dE/dx hadron constants!");
116 return D;
117 }
118
119 double chargeDensity = D / projection;
120 double numerator = 1 + alpha * chargeDensity;
121 double denominator = 1 + gamma * chargeDensity;
122 if (denominator == 0) {
123 B2INFO("\t HadronSaturation: D2I Something wrong with dE/dx hadron constants!");
124 return D;
125 }
126
127 double I = D * ratio * numerator / denominator;
128
129 return I;
130}
131
132double
133CDCDedxHadSat::I2D(double cosTheta, double I, double alpha, double gamma, double delta, double power, double ratio) const
134{
135
136 double absCosTheta = fabs(cosTheta);
137 double projection = pow(absCosTheta, power) + delta;
138
139 if (projection == 0 || ratio == 0) {
140 B2INFO("\t HadronSaturation: I2D Something wrong with dE/dx hadron constants!");
141 return I;
142 }
143
144 double a = alpha / projection;
145 double b = 1 - (gamma / projection) * (I / ratio);
146 double c = -1.0 * I / ratio;
147
148 if (b == 0 && a == 0) {
149 B2INFO("\t HadronSaturation: both a and b coefficients for hadron correction are 0");
150 return I;
151 }
152
153 double discr = b * b - 4.0 * a * c;
154 if (discr < 0) {
155 B2INFO("negative discriminant; return uncorrected value");
156 return I;
157 }
158
159 double D = (a != 0) ? (-b + sqrt(discr)) / (2.0 * a) : -c / b;
160
161 if (D < 0) {
162 B2INFO("D is less 0! will try another solution");
163 D = (a != 0) ? (-b - sqrt(discr)) / (2.0 * a) : -c / b;
164 if (D < 0) {
165 B2INFO("D is still less 0! just return uncorrected value");
166 return I;
167 }
168 }
169
170 return D;
171}
double I2D(double cosTheta, double I) const
hadron saturation parameterization part 2
double D2I(double cosTheta, double D) const
hadron saturation parameterization part 1
void setParameters()
set the parameters
double m_delta
the delta parameter for the hadron saturation correction
Definition: CDCDedxHadSat.h:69
DBObjPtr< CDCDedxHadronCor > m_DBHadronCor
db object for dE/dx hadron saturation parameters
Definition: CDCDedxHadSat.h:73
double m_ratio
the ratio parameter for the hadron saturation correction
Definition: CDCDedxHadSat.h:71
double m_gamma
the gamma parameter for the hadron saturation correction
Definition: CDCDedxHadSat.h:68
double m_alpha
the alpha parameter for the hadron saturation correction
Definition: CDCDedxHadSat.h:67
double m_power
the power parameter for the hadron saturation correction
Definition: CDCDedxHadSat.h:70
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.